diff -r a802a45383bb modules/unsupported/jdbc-ng/jdbc-core/src/main/java/org/geotools/jdbc/JDBCDataStore.java --- a/modules/unsupported/jdbc-ng/jdbc-core/src/main/java/org/geotools/jdbc/JDBCDataStore.java Fri Jun 26 07:25:55 2009 +0800 +++ b/modules/unsupported/jdbc-ng/jdbc-core/src/main/java/org/geotools/jdbc/JDBCDataStore.java Sun Jun 28 16:06:51 2009 +0800 @@ -125,10 +125,17 @@ /** * The native SRID associated to a certain descriptor + * TODO: qualify this key with 'org.geotools.jdbc' */ public static final String JDBC_NATIVE_SRID = "nativeSRID"; /** + * The key for attribute descriptor user data which specifies the original database column data + * type. + */ + public static final String JDBC_NATIVE_TYPENAME = "org.geotools.jdbc.nativeTypeName"; + + /** * name of table to use to store geometries when {@link #associations} * is set. */ diff -r a802a45383bb modules/unsupported/jdbc-ng/jdbc-core/src/main/java/org/geotools/jdbc/JDBCFeatureSource.java --- a/modules/unsupported/jdbc-ng/jdbc-core/src/main/java/org/geotools/jdbc/JDBCFeatureSource.java Fri Jun 26 07:25:55 2009 +0800 +++ b/modules/unsupported/jdbc-ng/jdbc-core/src/main/java/org/geotools/jdbc/JDBCFeatureSource.java Sun Jun 28 16:06:51 2009 +0800 @@ -50,6 +50,7 @@ import org.opengis.feature.Association; import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; +import org.opengis.feature.type.AttributeDescriptor; import org.opengis.filter.Filter; import org.opengis.referencing.crs.CoordinateReferenceSystem; @@ -230,7 +231,8 @@ } //figure out the type mapping - + String nativeTypeName = columns.getString("TYPE_NAME"); + //first ask the dialect Class binding = dialect.getMapping(columns, cx); @@ -242,8 +244,7 @@ if (binding == null) { //determine from type name mappings - String typeName = columns.getString("TYPE_NAME"); - binding = getDataStore().getMapping(typeName); + binding = getDataStore().getMapping(nativeTypeName); } //if still not found, resort to Object @@ -251,6 +252,9 @@ getDataStore().getLogger().warning("Could not find mapping for:" + name); binding = Object.class; } + + //store the native database type in the attribute descriptor user data + ab.addUserData(JDBCDataStore.JDBC_NATIVE_TYPENAME, nativeTypeName); //nullability if ( "NO".equalsIgnoreCase( columns.getString( "IS_NULLABLE" ) ) ) { @@ -258,6 +262,8 @@ ab.minOccurs(1); } + AttributeDescriptor att = null; + //determine if this attribute is a geometry or not if (Geometry.class.isAssignableFrom(binding)) { //add the attribute as a geometry, try to figure out @@ -279,16 +285,25 @@ ab.setCRS(crs); if(srid != null) ab.addUserData(JDBCDataStore.JDBC_NATIVE_SRID, srid); - tb.add(ab.buildDescriptor(name, ab.buildGeometryType())); + att = ab.buildDescriptor(name, ab.buildGeometryType()); } else { //add the attribute ab.setName(name); ab.setBinding(binding); - tb.add(ab.buildDescriptor(name, ab.buildType())); + att = ab.buildDescriptor(name, ab.buildType()); } + + //call dialect callback + dialect.postCreateAttribute( att, columns, tableName, databaseSchema, cx); + tb.add(att); } - return tb.buildFeatureType(); + //build the final type + SimpleFeatureType ft = tb.buildFeatureType(); + + //call dialect callback + dialect.postCreateFeatureType(ft, metaData, databaseSchema, cx); + return ft; } finally { getDataStore().closeSafe(columns); } diff -r a802a45383bb modules/unsupported/jdbc-ng/jdbc-core/src/main/java/org/geotools/jdbc/SQLDialect.java --- a/modules/unsupported/jdbc-ng/jdbc-core/src/main/java/org/geotools/jdbc/SQLDialect.java Fri Jun 26 07:25:55 2009 +0800 +++ b/modules/unsupported/jdbc-ng/jdbc-core/src/main/java/org/geotools/jdbc/SQLDialect.java Sun Jun 28 16:06:51 2009 +0800 @@ -719,6 +719,42 @@ public void postCreateTable(String schemaName, SimpleFeatureType featureType, Connection cx) throws SQLException { } + + /** + * Callback which executes after an attribute descriptor has been built from a table column. + *

+ * The result set columnMetadata should not be modified in any way (including scrolling) + * , it should only be read from. + *

+ *

+ * This base implementation does nothing, subclasses should override as need be. + *

+ * @param att The built attribute descriptor. + * @param columnMetadata The database metadata about the column. + * @param tableName The name of the table containing the column + * @param schemaName The name of the database scheam containing the table containing the column + * @param cx The database connection. + */ + public void postCreateAttribute(AttributeDescriptor att, ResultSet columnMetadata, String tableName, + String schemaName, Connection cx ) throws SQLException { + + } + + /** + * Callback which executes after a feature type has been built from a database table. + *

+ * This base implementation does nothing, subclasses should override as need be. + *

+ * @param featureType The build feature type. + * @param metadata The database metadata. + * @param schemaName The name of the database scheam containing the table containing the column + * @param cx The database connection. + */ + public void postCreateFeatureType(SimpleFeatureType featureType, DatabaseMetaData metadata, + String schemaName, Connection cx) + throws SQLException { + + } /** * Obtains the next value of the primary key of a column.