Revision 41037 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc/JDBCHelper.java

View differences:

JDBCHelper.java
29 29
import java.sql.ResultSetMetaData;
30 30
import java.sql.SQLException;
31 31
import java.sql.Statement;
32
import java.sql.Time;
32 33
import java.util.ArrayList;
33 34
import java.util.Arrays;
35
import java.util.Date;
34 36
import java.util.List;
35 37

  
36 38
import org.cresques.cts.IProjection;
37
import org.slf4j.Logger;
38
import org.slf4j.LoggerFactory;
39

  
40 39
import org.gvsig.fmap.dal.DALLocator;
41 40
import org.gvsig.fmap.dal.DataTypes;
42 41
import org.gvsig.fmap.dal.NewDataStoreParameters;
......
74 73
import org.gvsig.fmap.geom.primitive.Envelope;
75 74
import org.gvsig.tools.dispose.impl.AbstractDisposable;
76 75
import org.gvsig.tools.exception.BaseException;
76
import org.slf4j.Logger;
77
import org.slf4j.LoggerFactory;
77 78

  
78 79
/**
79 80
 * @author jmvivo
......
760 761
		return quote + field + quote;
761 762
	}
762 763

  
764
	public class DalValueToJDBCException extends WriteException {
765

  
766
		/**
767
		 * 
768
		 */
769
		private static final long serialVersionUID = -3608973505723097889L;
770
		private final static String MESSAGE_FORMAT = "Can't convert value of attribute '%(attributeName)' to JDBC type (attribute type '%(attributeType)', value class '%(valueClass)').";
771
		private final static String MESSAGE_KEY = "_Cant_convert_value_of_attribute_XattributeNameX_to_JDBC_type_attribute_type_XattributeTypeX_value_class_XvalueClassX";
772

  
773
		public DalValueToJDBCException(FeatureAttributeDescriptor attributeDescriptor, Object object, Throwable cause) {
774
			super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
775
			if( attributeDescriptor != null ) {
776
				setValue("attributeName",attributeDescriptor.getName());
777
				setValue("attributetype",attributeDescriptor.getDataTypeName());
778
			} else {
779
				setValue("attributeName","unknown");
780
				setValue("attributetype","unknown");
781
			}
782
			if( object!=null ) {
783
				setValue("valueClass", object.getClass().getName());
784
			} else {
785
				setValue("valueClass", "null");
786
			}
787
		}
788

  
789
	}
790

  
763 791
	public Object dalValueToJDBC(
764 792
			FeatureAttributeDescriptor attributeDescriptor, Object object)
765 793
			throws WriteException {
766
		if (object == null) {
767
			return null;
768
		}
769

  
770
		if (attributeDescriptor.getType() != DataTypes.GEOMETRY) {
771
			return object;
772
		}
773 794
		try {
795
			if (object == null) {
796
				return null;
797
			}
798
	
799
			if (attributeDescriptor.getType() == DataTypes.TIME) {
800
			    return new Time(((Date)object).getTime());
801
			}
802
			if (attributeDescriptor.getType() != DataTypes.GEOMETRY) {
803
				return object;
804
			}
774 805
			byte[] wkb = null;
775 806
			Geometry geom = (Geometry) object;
776 807
			IProjection srs = attributeDescriptor.getSRS();
......
781 812
			}
782 813
			return wkb;
783 814
		} catch (Exception e) {
784
			throw new WriteException(this.name, e);
815
			throw new DalValueToJDBCException(attributeDescriptor, object,e);
785 816
		}
786 817
	}
787 818

  
......
911 942
		return strb.toString();
912 943
	}
913 944

  
945
	/**
946
	 * @deprecated use getDefaultFieldValueString this has a type writer error.
947
	 */
914 948
	protected String getDefaltFieldValueString(FeatureAttributeDescriptor attr)
915 949
			throws WriteException {
950
		return getDefaultFieldValueString(attr);
951
	}
952

  
953
	protected String getDefaultFieldValueString(FeatureAttributeDescriptor attr)
954
			throws WriteException {
916 955
		return dalValueToJDBC(attr, attr.getDefaultValue()).toString();
917 956
	}
918 957

  

Also available in: Unified diff