Class JDBCDataStore
- Object
-
- ContentDataStore
-
- JDBCDataStore
-
- All Implemented Interfaces:
DataAccess<SimpleFeatureType,SimpleFeature>,DataStore,GmlObjectStore
public final class JDBCDataStore extends ContentDataStore implements GmlObjectStore
Datastore implementation for jdbc based relational databases.This class is not intended to be subclassed on a per database basis. Instead the notion of a "dialect" is used.
Dialects
A dialect (SQLDialect) encapsulates all the operations that are database specific. Therefore to implement a jdbc based datastore one must extend SQLDialect. The specific dialect to use is set usingsetSQLDialect(SQLDialect).Database Connections
Connections to the underlying database are obtained through aDataSource. A datastore must be specified usingsetDataSource(DataSource).Schemas
This datastore supports the notion of database schemas, which is more or less just a grouping of tables. When a schema is specified, only those tables which are part of the schema are provided by the datastore. The schema is specified usingsetDatabaseSchema(String).Spatial Functions
The set of spatial operations or functions that are supported by the specific database are reported with aFilterCapabilitiesinstance. This is specified using#setFilterCapabilities(FilterCapabilities).- Author:
- Justin Deoliveira, The Open Planning Project
-
-
Field Summary
Fields Modifier and Type Field Description protected HashMap<Class<? extends FeatureVisitor>,String>aggregateFunctionsFeature visitor to aggregate function nameprotected booleanassociationsflag controlling if the datastore is supporting feature and geometry relationships with associationsprotected intbatchInsertSizeThe number of features to bufferize while inserting in order to do batch inserts.protected JDBCCallbackFactorycallbackFactoryprotected HashMap<Class<?>,Integer>classToSqlTypeMappingsjava class to sql type mappings;protected List<ConnectionLifecycleListener>connectionLifecycleListenersThe listeners that are allowed to handle the connection lifecycleprotected StringdatabaseSchemaThe database schema.protected DataSourcedataSourcedata sourceprotected ConcurrentHashMap<Integer,String>dBsqlTypesCachecache of sqltypes found in databaseSQLDialectdialectthe dialect of sqlprotected static ReferencedEnvelopeEMPTY_ENVELOPEThe envelope returned when bounds is called against a geometryless feature typeprotected booleanexposePrimaryKeyColumnsflag controlling whether primary key columns of a table are exposed via the feature type.protected static StringFEATURE_ASSOCIATION_TABLEname of table to use to store feature associations whenassociationsis set.protected static StringFEATURE_RELATIONSHIP_TABLEname of table to use to store feature relationships (information about associations) whenassociationsis set.intfetchSizeThe fetch size for this datastore, defaulting to 1000.protected static StringGEOMETRY_ASSOCIATION_TABLEname of table to use to store geometry associations whenassociationsis set.protected static StringGEOMETRY_TABLEname of table to use to store geometries whenassociationsis set.static StringJDBC_COLUMN_ALIASUsed to specify the column alias to use when encoding a column in a selectstatic StringJDBC_ENUM_MAPContains aEnumMappingto support enumsstatic StringJDBC_NATIVE_SRIDThe native SRID associated to a certain descriptor TODO: qualify this key with 'org.geotools.jdbc'static StringJDBC_NATIVE_TYPEThe key for attribute descriptor user data which specifies the original database column data type, as aTypesvalue.static StringJDBC_NATIVE_TYPENAMEThe key for attribute descriptor user data which specifies the original database column data type.static StringJDBC_PRIMARY_KEY_COLUMNBoolean marker stating whether an attribute is part of the primary keystatic StringJDBC_READ_ONLYBoolean marker stating whether the feature type is to be considered read onlystatic intMAX_IDS_IN_FILTERMax number of ids to use for the optimized locks checking filter.protected static StringMULTI_GEOMETRY_TABLEname of table to use to store multi geometries made up of non-multi geometries whenassociationsis set.protected PrimaryKeyFinderprimaryKeyFinderFinds the primary key definitions (instantiated here because the finders might keep state)protected HashMap<String,Class<?>>sqlTypeNameToClassMappingssql type name to java class mappingsprotected HashMap<Integer,Class<?>>sqlTypeToClassMappingssql type to java class mappingsprotected HashMap<Integer,String>sqlTypeToSqlTypeNameOverridessql type to sql type name overridesprotected HashMap<String,String>supportedFunctionsjava supported filter function mappings to dialect name;protected static BooleanTRACE_ENABLEDWhen true, record a stack trace documenting who disposed the JDBCDataStore.protected Map<String,VirtualTable>virtualTablesContains the SQL definition of the various virtual tables-
Fields inherited from class ContentDataStore
dataStoreFactory, entries, featureFactory, filterFactory, geometryFactory, JOINED_FEATURE_TYPE, lockingManager, LOGGER, namespaceURI, typeFactory, WRITER_ADD, WRITER_COMMIT, WRITER_UPDATE
-
-
Constructor Summary
Constructors Constructor Description JDBCDataStore()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapplyLimitOffset(StringBuffer sql, Query query)Applies the limit/offset elements to the query if they are specified and if the dialect supports themTransactionbuildTransaction(Connection cx)Builds a transaction object around a user provided connection.voidcloseSafe(Connection cx)Utility method for closing a connection.voidcloseSafe(ResultSet rs)Utility method for closing a result set.voidcloseSafe(Statement st)Utility method for closing a statement.protected StringcreateAssociationTableSQL(Connection cx)Creates the sql for the association table.protected ConnectioncreateConnection()Creates a new connection.protected ContentStatecreateContentState(ContentEntry entry)Creates an instanceofJDBCState.protected ContentFeatureSourcecreateFeatureSource(ContentEntry entry)Creates a new instance ofJDBCFeatureStore.FilterToSQLcreateFilterToSQL(SimpleFeatureType featureType)Creates a new instance of a filter to sql encoder.protected StringcreateGeometryAssociationTableSQL(Connection cx)Creates the sql for the geometry association table.protected StringcreateGeometryTableSQL(Connection cx)Creates the sql for the geometry table.voidcreateIndex(Index index)Creates a new database indexprotected StringcreateMultiGeometryTableSQL(Connection cx)Creates the sql for the multi_geometry table.PreparedFilterToSQLcreatePreparedFilterToSQL(SimpleFeatureType featureType)Creates a new instance of a filter to sql encoder to be used in a prepared statement.protected StringcreateRelationshipTableSQL(Connection cx)Creates the sql for the relationship table.voidcreateSchema(SimpleFeatureType featureType)Creates a table in the underlying database from the specified table.protected StringcreateTableSQL(SimpleFeatureType featureType, Connection cx)Generates a 'CREATE TABLE' sql statement.protected List<Name>createTypeNames()Generates the list of type names provided by the database.voidcreateVirtualTable(VirtualTable vtable)Adds a virtual table to the data store.static List<Object>decodeFID(PrimaryKey key, String FID, boolean strict)Decodes a fid into its components based on a primary key.protected voiddelete(SimpleFeatureType featureType, String fid, Connection cx)Deletes an existing feature in the database for a particular feature type / fid.protected voiddelete(SimpleFeatureType featureType, Filter filter, Connection cx)Deletes an existing feature(s) in the database for a particular feature type / table.protected StringdeleteSQL(SimpleFeatureType featureType, Filter filter)Generates a 'DELETE FROM' sql statement.protected PreparedStatementdeleteSQLPS(SimpleFeatureType featureType, Filter filter, Connection cx)Generates a 'DELETE FROM' prepared statement.voiddispose()Disposes of this data store and releases any resource that it is using.voiddropIndex(String typeName, String indexName)Creates a new database indexprotected StringdropTableSQL(SimpleFeatureType featureType, Connection cx)Generates a 'DROP TABLE' sql statement.VirtualTabledropVirtualTable(String name)Removes and returns the specified virtual tablevoidencodeAliasedTableName(String tableName, StringBuffer sql, Hints hints, String alias)Helper method to encode table name which checks if a schema is set and prefixes the table name with it, with the addition of an alias to the nameprotected static StringencodeFID(List<Object> keyValues)protected StringencodeFID(PrimaryKey pkey, ResultSet rs)Calls through to:protected StringencodeFID(PrimaryKey pkey, ResultSet rs, int offset)Encodes a feature id from a primary key and result set values.protected voidencodeFunction(String function, List<Expression> expressions, StringBuffer sql, FilterToSQL filterToSQL)protected voidencodeFunction(String function, Expression expression, StringBuffer sql, FilterToSQL filterToSQL)voidencodeGeometryColumn(GeometryDescriptor gatt, StringBuffer sql, Hints hints)Encoding a geometry column with respect to hints Supported Hints are provided bySQLDialect.addSupportedHints(Set)protected voidencodeGeometryColumn(GeometryDescriptor gatt, String prefix, StringBuffer sql, Hints hints)protected voidencodeGroupByStatement(List<Expression> groupByExpressions, StringBuffer sql, FilterToSQL filterToSQL, boolean aggregateOnExpression)Helper method that adds a group by statement to the SQL query.protected voidencodeTableJoin(SimpleFeatureType featureType, JoinInfo join, Query query, StringBuffer sql)Helper method to encode the join clause(s) of a query.voidencodeTableName(String tableName, StringBuffer sql, Hints hints)Helper method to encode table name which checks if a schema is set and prefixes the table name with it.protected List<FilterToSQL>encodeWhereJoin(SimpleFeatureType featureType, JoinInfo join, StringBuffer sql)protected voidensureAssociationTablesExist(Connection cx)Helper method for creating geometry association table if it does not exist.protected voidensureAuthorization(SimpleFeatureType featureType, Filter filter, Transaction tx, Connection cx)Ensures that that the specified transaction has access to features specified by a filter.StringescapeNamePattern(DatabaseMetaData metaData, String name)Escapes a name pattern used in e.g.protected List<Expression>extractGroupByExpressions(FeatureVisitor visitor)Helper method that extracts a list of group by attributes from a group by visitor.protected GroupByVisitor.GroupByRawResultextractValuesFromResultSet(Connection cx, SimpleFeatureType featureType, ResultSet resultSet, List<Expression> groupBy, Function<Object,Object> converter, Hints hints)Helper method that translate the result set to the appropriate group by visitor result formatprotected voidfinalize()protected StringfindPrimaryKeyColumnName(SimpleFeatureType featureType)JDBCFeatureSourcegetAbsoluteFeatureSource(String typeName)Map<Class<? extends FeatureVisitor>,String>getAggregateFunctions()Returns the supported aggregate functions and the visitors they map to.protected ObjectgetAggregateValue(FeatureVisitor visitor, SimpleFeatureType featureType, Query query, Connection cx)Results the value of an aggregate function over a query.intgetBatchInsertSize()protected ReferencedEnvelopegetBounds(SimpleFeatureType featureType, Query query, Connection cx)Returns the bounds of the features for a particular feature type / table.JDBCCallbackFactorygetCallbackFactory()Map<Class<?>,Integer>getClassToSqlTypeMappings()The java type to sql type mappings that the datastore uses when reading and writing objects to and from the database.protected static LinkedHashSet<String>getColumnNames(PrimaryKey key)Returns the set of the primary key column names.protected ClassgetColumnType(DatabaseMetaData metaData, String databaseSchema2, String tableName, String columnName)Returns the type of the column by inspecting the metadata, with the collaboration of the dialectConnectiongetConnection(Transaction t)Returns a JDBC Connection to the underlying database for the specified GeoToolsTransaction.protected ConnectiongetConnection(JDBCState state)Gets a database connection for the specified feature store.List<ConnectionLifecycleListener>getConnectionLifecycleListeners()Returns a modifiable list of connection lifecycle listenersprotected intgetCount(SimpleFeatureType featureType, Query query, Connection cx)Returns the count of the features for a particular feature type / table.StringgetDatabaseSchema()The schema from which this datastore is serving tables from.DataSourcegetDataSource()The data source the datastore uses to obtain connections to the underlying database.ConcurrentHashMap<Integer,String>getDBsqlTypesCache()Returns a map integer constants for database types (fromTypes) to database type names.protected intgetDescriptorDimension(AttributeDescriptor descriptor)Extracts the eventual native dimension user property from the descriptor, returns -1 if not foundprotected intgetDescriptorSRID(AttributeDescriptor descriptor)Extracts the eventual native SRID user property from the descriptor, returns -1 if not foundintgetFetchSize()The current fetch size.FilterCapabilitiesgetFilterCapabilities()The filter capabilities which reports which spatial operations the underlying database can handle natively.protected intgetGeometryDimension(Geometry g, AttributeDescriptor descriptor)Looks up the geometry dimension by trying a number of heuristics.protected intgetGeometrySRID(Geometry g, AttributeDescriptor descriptor)Looks up the geometry srs by trying a number of heuristics.ObjectgetGmlObject(GmlObjectId id, Hints hints)Looks up an object by its gml id.List<Index>getIndexes(String typeName)Lists all indexes associated to the given feature typeClass<?>getMapping(int sqlType)Returns the java type mapped to the specified sql type.IntegergetMapping(Class<?> clazz)Returns the sql type mapped to the specified java type.IntegergetMapping(Class<?> binding, AttributeDescriptor d)Returns the sqlType of the given attribute, if present.Class<?>getMapping(String sqlTypeName)Returns the java type mapped to the specified sql type name.PrimaryKeygetPrimaryKey(SimpleFeatureType featureType)Returns the primary key object for a particular feature type / table, deriving it from the underlying database metadata.protected PrimaryKeygetPrimaryKey(ContentEntry entry)Returns the primary key object for a particular entry, deriving it from the underlying database metadata.PrimaryKeyFindergetPrimaryKeyFinder()Returns the finder used to buildPrimaryKeyrepresentationsprotected StringgetPropertyName(SimpleFeatureType featureType, PropertyName propertyName)Helper method for executing a property name against a feature type.SQLDialectgetSQLDialect()The dialect the datastore uses to generate sql statements in order to communicate with the underlying database.Map<String,Class<?>>getSqlTypeNameToClassMappings()The sql type name to java type mappings that the dialect uses when reading and writing objects to and from the database.Map<Integer,Class<?>>getSqlTypeToClassMappings()The sql type to java type mappings that the datastore uses when reading and writing objects to and from the database.Map<Integer,String>getSqlTypeToSqlTypeNameOverrides()Returns any ovverides which map integer constants for database types (fromTypes) to database type names.Map<String,VirtualTable>getVirtualTables()Returns a live, immutable view of the virtual tables map (from name to definition)protected <F extends FilterToSQL>
FinitializeFilterToSQL(F toSQL, SimpleFeatureType featureType)Helper method to initialize a filter encoder instance.protected voidinsert(Collection<? extends SimpleFeature> features, SimpleFeatureType featureType, Connection cx)Inserts a collection of new features into the database for a particular feature type / table.protected voidinsert(SimpleFeature feature, SimpleFeatureType featureType, Connection cx)Inserts a new feature into the database for a particular feature type / table.protected StringinsertSQL(SimpleFeatureType featureType, SimpleFeature feature, KeysFetcher keysFetcher, Connection cx)Generates a 'INSERT INFO' sql statement.booleanisAssociations()Flag controlling if the datastore is supporting feature and geometry relationships with associationsprotected booleanisCountVisitor(FeatureVisitor visitor)booleanisExposePrimaryKeyColumns()Determines if the datastore creates feature types which include those columns / attributes which compose the primary key.protected booleanisExposePrimaryKeyColumns(SimpleFeatureType featureType)Returns the expose primary key columns flag for the specified feature typeprotected booleanisGeneralizationRequired(Hints hints, GeometryDescriptor gatt)Checks if geometry generalization required and makes senseprotected booleanisGenerated(PrimaryKey pkey)Determines if a primary key is made up entirely of column which are generated via an auto-generating column or a sequence.protected booleanisGeometryReduceRequired(Hints hints, GeometryDescriptor gatt, Hints.Key param)Checks if reduction required and makes senseprotected booleanisGroupByVisitor(FeatureVisitor visitor)Helper method the checks if a feature visitor is a group by visitor,protected booleanisSimplificationRequired(Hints hints, GeometryDescriptor gatt)Checks if geometry simplification required and makes senseprotected StringmatchAggregateFunction(FeatureVisitor visitor)Helper method that will try to match a feature visitor with an aggregate function.protected voidreleaseConnection(Connection cx, JDBCState state)Releases an existing connection (paying special attention toTransaction.AUTO_COMMIT.voidremoveSchema(String typeName)Used to permanently remove a schema from the underlying storagevoidremoveSchema(Name typeName)Used to permanently remove a schema from the underlying storageprotected StringselectAggregateSQL(String function, List<Expression> attributes, List<Expression> groupByExpressions, SimpleFeatureType featureType, Query query, LimitingVisitor visitor)protected PreparedStatementselectAggregateSQLPS(String function, List<Expression> attributes, List<Expression> groupByExpressions, SimpleFeatureType featureType, Query query, LimitingVisitor visitor, Connection cx)protected StringselectAssociationSQL(String fid)Creates the sql for the association table.protected PreparedStatementselectAssociationSQLPS(String fid, Connection cx)Creates the prepared statement for the association table.protected StringselectBoundsSQL(SimpleFeatureType featureType, Query query)Generates a 'SELECT' sql statement which selects bounds.protected PreparedStatementselectBoundsSQLPS(SimpleFeatureType featureType, Query query, Connection cx)Generates a 'SELECT' prepared statement which selects bounds.protected StringselectGeometryAssociationSQL(String fid, String gid, String gname)Creates the sql for a select from the geometry association table.protected PreparedStatementselectGeometryAssociationSQLPS(String fid, String gid, String gname, Connection cx)Creates the prepared statement for a select from the geometry association table.protected StringselectGeometrySQL(String gid)Creates the sql for a select from the geometry table.protected PreparedStatementselectGeometrySQLPS(String gid, Connection cx)Creates the prepared for a select from the geometry table.protected StringselectJoinSQL(SimpleFeatureType featureType, JoinInfo join, Query query)protected PreparedStatementselectJoinSQLPS(SimpleFeatureType featureType, JoinInfo join, Query query, Connection cx)protected StringselectMultiGeometrySQL(String gid)Creates the sql for a select from the multi geometry table.protected PreparedStatementselectMultiGeometrySQLPS(String gid, Connection cx)Creates the prepared statement for a select from the multi geometry table.protected StringselectRelationshipSQL(String table, String column)Creates the sql for the relationship table.protected PreparedStatementselectRelationshipSQLPS(String table, String column, Connection cx)Creates the prepared statement for a query against the relationship table.protected StringselectSQL(SimpleFeatureType featureType, Query query)Generates a 'SELECT p1, p2, ...protected PreparedStatementselectSQLPS(SimpleFeatureType featureType, Query query, Connection cx)Generates a 'SELECT p1, p2, ...voidsetAssociations(boolean foreignKeyGeometries)Sets the flag controlling if the datastore is supporting feature and geometry relationships with associationsvoidsetBatchInsertSize(int batchInsertSize)Set the number of features to bufferize while inserting in order to do batch inserts.voidsetCallbackFactory(JDBCCallbackFactory factory)voidsetDatabaseSchema(String databaseSchema)Set the database schema for the datastore.voidsetDataSource(DataSource dataSource)Sets the data source the datastore uses to obtain connections to the underlying database.voidsetExposePrimaryKeyColumns(boolean exposePrimaryKeyColumns)Sets the flag controlling if the datastore creates feature types which include those columns / attributes which compose the primary key.voidsetFetchSize(int fetchSize)Changes the fetch size.protected voidsetGmlProperties(Geometry g, String gid, String name, String description)Helper method for setting the gml:id of a geometry as user data.protected voidsetPreparedFilterValues(PreparedStatement ps, List<FilterToSQL> toSQLs, Connection cx)Helper method for setting the values of the WHERE class of a prepared statement from a list of PreparedFilterToSQL.voidsetPreparedFilterValues(PreparedStatement ps, PreparedFilterToSQL toSQL, int offset, Connection cx)Helper method for setting the values of the WHERE class of a prepared statement.voidsetPrimaryKeyFinder(PrimaryKeyFinder primaryKeyFinder)Sets the finder used to buildPrimaryKeyrepresentationsvoidsetSQLDialect(SQLDialect dialect)Sets the dialect the datastore uses to generate sql statements in order to communicate with the underlying database.protected voidupdate(SimpleFeatureType featureType, List<AttributeDescriptor> attributes, List<Object> values, Filter filter, Connection cx)Updates an existing feature(s) in the database for a particular feature type / table.protected voidupdate(SimpleFeatureType featureType, AttributeDescriptor[] attributes, Object[] values, Filter filter, Connection cx)Updates an existing feature(s) in the database for a particular feature type / table.protected StringupdateSQL(SimpleFeatureType featureType, AttributeDescriptor[] attributes, Object[] values, Filter filter, Set<String> pkColumnNames)Generates an 'UPDATE' sql statement.protected PreparedStatementupdateSQLPS(SimpleFeatureType featureType, AttributeDescriptor[] attributes, Object[] values, Filter filter, Set<String> pkColumnNames, Connection cx)Generates an 'UPDATE' prepared statement.-
Methods inherited from class ContentDataStore
ensureEntry, ensureFeatureStore, entry, getDataStoreFactory, getEntry, getFeatureFactory, getFeatureReader, getFeatureSource, getFeatureSource, getFeatureSource, getFeatureSource, getFeatureTypeFactory, getFeatureWriter, getFeatureWriter, getFeatureWriterAppend, getFilterFactory, getGeometryFactory, getInfo, getLockingManager, getLogger, getNames, getNamespaceURI, getSchema, getSchema, getTypeNames, name, removeEntry, setDataStoreFactory, setFeatureFactory, setFeatureTypeFactory, setFilterFactory, setGeometryFactory, setNamespaceURI, updateSchema, updateSchema
-
-
-
-
Field Detail
-
TRACE_ENABLED
protected static final Boolean TRACE_ENABLED
When true, record a stack trace documenting who disposed the JDBCDataStore. If dispose() is called a second time we can identify the offending parties.
-
JDBC_NATIVE_SRID
public static final String JDBC_NATIVE_SRID
The native SRID associated to a certain descriptor TODO: qualify this key with 'org.geotools.jdbc'- See Also:
- Constant Field Values
-
JDBC_READ_ONLY
public static final String JDBC_READ_ONLY
Boolean marker stating whether the feature type is to be considered read only- See Also:
- Constant Field Values
-
JDBC_PRIMARY_KEY_COLUMN
public static final String JDBC_PRIMARY_KEY_COLUMN
Boolean marker stating whether an attribute is part of the primary key- See Also:
- Constant Field Values
-
JDBC_NATIVE_TYPENAME
public static final String JDBC_NATIVE_TYPENAME
The key for attribute descriptor user data which specifies the original database column data type.- See Also:
- Constant Field Values
-
JDBC_NATIVE_TYPE
public static final String JDBC_NATIVE_TYPE
The key for attribute descriptor user data which specifies the original database column data type, as aTypesvalue.- See Also:
- Constant Field Values
-
JDBC_COLUMN_ALIAS
public static final String JDBC_COLUMN_ALIAS
Used to specify the column alias to use when encoding a column in a select- See Also:
- Constant Field Values
-
JDBC_ENUM_MAP
public static final String JDBC_ENUM_MAP
Contains aEnumMappingto support enums- See Also:
- Constant Field Values
-
GEOMETRY_TABLE
protected static final String GEOMETRY_TABLE
name of table to use to store geometries whenassociationsis set.- See Also:
- Constant Field Values
-
MULTI_GEOMETRY_TABLE
protected static final String MULTI_GEOMETRY_TABLE
name of table to use to store multi geometries made up of non-multi geometries whenassociationsis set.- See Also:
- Constant Field Values
-
GEOMETRY_ASSOCIATION_TABLE
protected static final String GEOMETRY_ASSOCIATION_TABLE
name of table to use to store geometry associations whenassociationsis set.- See Also:
- Constant Field Values
-
FEATURE_RELATIONSHIP_TABLE
protected static final String FEATURE_RELATIONSHIP_TABLE
name of table to use to store feature relationships (information about associations) whenassociationsis set.- See Also:
- Constant Field Values
-
FEATURE_ASSOCIATION_TABLE
protected static final String FEATURE_ASSOCIATION_TABLE
name of table to use to store feature associations whenassociationsis set.- See Also:
- Constant Field Values
-
EMPTY_ENVELOPE
protected static final ReferencedEnvelope EMPTY_ENVELOPE
The envelope returned when bounds is called against a geometryless feature type
-
MAX_IDS_IN_FILTER
public static final int MAX_IDS_IN_FILTER
Max number of ids to use for the optimized locks checking filter.- See Also:
- Constant Field Values
-
dataSource
protected DataSource dataSource
data source
-
dialect
public SQLDialect dialect
the dialect of sql
-
databaseSchema
protected String databaseSchema
The database schema.
-
sqlTypeToClassMappings
protected HashMap<Integer,Class<?>> sqlTypeToClassMappings
sql type to java class mappings
-
sqlTypeNameToClassMappings
protected HashMap<String,Class<?>> sqlTypeNameToClassMappings
sql type name to java class mappings
-
classToSqlTypeMappings
protected HashMap<Class<?>,Integer> classToSqlTypeMappings
java class to sql type mappings;
-
sqlTypeToSqlTypeNameOverrides
protected HashMap<Integer,String> sqlTypeToSqlTypeNameOverrides
sql type to sql type name overrides
-
dBsqlTypesCache
protected ConcurrentHashMap<Integer,String> dBsqlTypesCache
cache of sqltypes found in database
-
aggregateFunctions
protected HashMap<Class<? extends FeatureVisitor>,String> aggregateFunctions
Feature visitor to aggregate function name
-
supportedFunctions
protected HashMap<String,String> supportedFunctions
java supported filter function mappings to dialect name;
-
associations
protected boolean associations
flag controlling if the datastore is supporting feature and geometry relationships with associations
-
fetchSize
public int fetchSize
The fetch size for this datastore, defaulting to 1000. Set to a value less or equal to 0 to disable fetch size limit and grab all the records in one shot.
-
batchInsertSize
protected int batchInsertSize
The number of features to bufferize while inserting in order to do batch inserts.By default 1 to avoid backward compatibility with badly written code that forgets to close the JDBCInsertFeatureWriter or does it after closing the DB connection.
-
exposePrimaryKeyColumns
protected boolean exposePrimaryKeyColumns
flag controlling whether primary key columns of a table are exposed via the feature type.
-
primaryKeyFinder
protected PrimaryKeyFinder primaryKeyFinder
Finds the primary key definitions (instantiated here because the finders might keep state)
-
virtualTables
protected Map<String,VirtualTable> virtualTables
Contains the SQL definition of the various virtual tables
-
connectionLifecycleListeners
protected List<ConnectionLifecycleListener> connectionLifecycleListeners
The listeners that are allowed to handle the connection lifecycle
-
callbackFactory
protected JDBCCallbackFactory callbackFactory
-
-
Method Detail
-
setCallbackFactory
public void setCallbackFactory(JDBCCallbackFactory factory)
-
getCallbackFactory
public JDBCCallbackFactory getCallbackFactory()
-
getAbsoluteFeatureSource
public JDBCFeatureSource getAbsoluteFeatureSource(String typeName) throws IOException
- Throws:
IOException
-
createVirtualTable
public void createVirtualTable(VirtualTable vtable) throws IOException
Adds a virtual table to the data store. If a virtual table with the same name was registered- Throws:
IOException- If the view definition is not valid
-
getConnectionLifecycleListeners
public List<ConnectionLifecycleListener> getConnectionLifecycleListeners()
Returns a modifiable list of connection lifecycle listeners
-
dropVirtualTable
public VirtualTable dropVirtualTable(String name)
Removes and returns the specified virtual table
-
getVirtualTables
public Map<String,VirtualTable> getVirtualTables()
Returns a live, immutable view of the virtual tables map (from name to definition)
-
getPrimaryKeyFinder
public PrimaryKeyFinder getPrimaryKeyFinder()
Returns the finder used to buildPrimaryKeyrepresentations
-
setPrimaryKeyFinder
public void setPrimaryKeyFinder(PrimaryKeyFinder primaryKeyFinder)
Sets the finder used to buildPrimaryKeyrepresentations
-
getFetchSize
public int getFetchSize()
The current fetch size. The fetch size influences how many records are read from the dbms at a time. If set to a value less or equal than zero, all the records will be read in one shot, severily increasing the memory requirements to read a big number of features.
-
setFetchSize
public void setFetchSize(int fetchSize)
Changes the fetch size.
-
getBatchInsertSize
public int getBatchInsertSize()
- Returns:
- the number of features to bufferize while inserting in order to do batch inserts.
-
setBatchInsertSize
public void setBatchInsertSize(int batchInsertSize)
Set the number of features to bufferize while inserting in order to do batch inserts.Warning: when changing this value from its default of 1, the behavior of the
JDBCInsertFeatureWriteris changed in non backward compatible ways. If your code closes the writer before closing the connection, you are fine. Plus, the feature added events will be delayed until a batch is actually inserted.
-
isExposePrimaryKeyColumns
public boolean isExposePrimaryKeyColumns()
Determines if the datastore creates feature types which include those columns / attributes which compose the primary key.
-
setExposePrimaryKeyColumns
public void setExposePrimaryKeyColumns(boolean exposePrimaryKeyColumns)
Sets the flag controlling if the datastore creates feature types which include those columns / attributes which compose the primary key.
-
getSQLDialect
public SQLDialect getSQLDialect()
The dialect the datastore uses to generate sql statements in order to communicate with the underlying database.- Returns:
- The dialect, never
null.
-
setSQLDialect
public void setSQLDialect(SQLDialect dialect)
Sets the dialect the datastore uses to generate sql statements in order to communicate with the underlying database.- Parameters:
dialect- The dialect, nevernull.
-
getDataSource
public DataSource getDataSource()
The data source the datastore uses to obtain connections to the underlying database.- Returns:
- The data source, never
null.
-
setDataSource
public void setDataSource(DataSource dataSource)
Sets the data source the datastore uses to obtain connections to the underlying database.- Parameters:
dataSource- The data source, nevernull.
-
getDatabaseSchema
public String getDatabaseSchema()
The schema from which this datastore is serving tables from.- Returns:
- the schema, or
nullif non specified.
-
setDatabaseSchema
public void setDatabaseSchema(String databaseSchema)
Set the database schema for the datastore.When this value is set only those tables which are part of the schema are served through the datastore. This value can be set to
nullto specify no particular schema.- Parameters:
databaseSchema- The schema, may benull.
-
getFilterCapabilities
public FilterCapabilities getFilterCapabilities()
The filter capabilities which reports which spatial operations the underlying database can handle natively.- Returns:
- The filter capabilities, never
null.
-
isAssociations
public boolean isAssociations()
Flag controlling if the datastore is supporting feature and geometry relationships with associations
-
setAssociations
public void setAssociations(boolean foreignKeyGeometries)
Sets the flag controlling if the datastore is supporting feature and geometry relationships with associations
-
getSqlTypeToClassMappings
public Map<Integer,Class<?>> getSqlTypeToClassMappings()
The sql type to java type mappings that the datastore uses when reading and writing objects to and from the database.These mappings are derived from
SQLDialect.registerSqlTypeToClassMappings(java.util.Map)- Returns:
- The mappings, never
null.
-
getSqlTypeNameToClassMappings
public Map<String,Class<?>> getSqlTypeNameToClassMappings()
The sql type name to java type mappings that the dialect uses when reading and writing objects to and from the database.These mappings are derived from
SQLDialect.registerSqlTypeNameToClassMappings(Map)- Returns:
- The mappings, never
null.
-
getClassToSqlTypeMappings
public Map<Class<?>,Integer> getClassToSqlTypeMappings()
The java type to sql type mappings that the datastore uses when reading and writing objects to and from the database.These mappings are derived from
SQLDialect.registerClassToSqlMappings(Map)- Returns:
- The mappings, never
null.
-
getSqlTypeToSqlTypeNameOverrides
public Map<Integer,String> getSqlTypeToSqlTypeNameOverrides()
Returns any ovverides which map integer constants for database types (fromTypes) to database type names.This method will return an empty map when there are no overrides.
-
getDBsqlTypesCache
public ConcurrentHashMap<Integer,String> getDBsqlTypesCache()
Returns a map integer constants for database types (fromTypes) to database type names.This method will return an empty map when there are no overrides.
-
getAggregateFunctions
public Map<Class<? extends FeatureVisitor>,String> getAggregateFunctions()
Returns the supported aggregate functions and the visitors they map to.
-
getMapping
public Class<?> getMapping(int sqlType)
Returns the java type mapped to the specified sql type.If there is no such type mapped to sqlType,
nullis returned.- Parameters:
sqlType- The integer constant for the sql type fromTypes.- Returns:
- The mapped java class, or
null. if no such mapping exists.
-
getMapping
public Class<?> getMapping(String sqlTypeName)
Returns the java type mapped to the specified sql type name.If there is no such type mapped to sqlTypeName,
nullis returned.- Parameters:
sqlTypeName- The name of the sql type.- Returns:
- The mapped java class, or
null. if no such mapping exists.
-
getMapping
public Integer getMapping(Class<?> binding, AttributeDescriptor d)
Returns the sqlType of the given attribute, if present. Falls back to sqlType of class. Considering the specific attribute first, enables binding multiple sqlTypes to a single class.- Parameters:
binding-d- optional descriptor- Returns:
- sqlType or Types.OTHER if no such mapping exists.
-
getMapping
public Integer getMapping(Class<?> clazz)
Returns the sql type mapped to the specified java type.If there is no such type mapped to clazz,
Types.OTHERis returned.- Parameters:
clazz- The java class.- Returns:
- The mapped sql type from
Types, Types.OTHER if no such mapping exists.
-
createSchema
public void createSchema(SimpleFeatureType featureType) throws IOException
Creates a table in the underlying database from the specified table.This method will map the classes of the attributes of featureType to sql types and generate a 'CREATE TABLE' statement against the underlying database.
- Specified by:
createSchemain interfaceDataAccess<SimpleFeatureType,SimpleFeature>- Overrides:
createSchemain classContentDataStore- Parameters:
featureType- FetureType to add to DataStore- Throws:
IllegalArgumentException- If the table already exists.IOException- If the table cannot be created due to an error.- See Also:
DataStore#createSchema(SimpleFeatureType)
-
removeSchema
public void removeSchema(String typeName) throws IOException
Description copied from interface:DataStoreUsed to permanently remove a schema from the underlying storageThis functionality is similar to an "drop table" statement in SQL. Implementation is optional; it may not be supported by all servers or files.
- Specified by:
removeSchemain interfaceDataStore- Overrides:
removeSchemain classContentDataStore- Throws:
IOException- if the operation failed- See Also:
DataStore.removeSchema(String)
-
removeSchema
public void removeSchema(Name typeName) throws IOException
Description copied from interface:DataAccessUsed to permanently remove a schema from the underlying storageThis functionality is similar to an "drop table" statement in SQL. Implementation is optional; it may not be supported by all servers or files.
- Specified by:
removeSchemain interfaceDataAccess<SimpleFeatureType,SimpleFeature>- Overrides:
removeSchemain classContentDataStore- Throws:
IOException- if the operation failed- See Also:
DataAccess.removeSchema(Name)
-
getGmlObject
public Object getGmlObject(GmlObjectId id, Hints hints) throws IOException
Description copied from interface:GmlObjectStoreLooks up an object by its gml id.This method returns
nullif no such object exists.- Specified by:
getGmlObjectin interfaceGmlObjectStore- Parameters:
id- The id of the object, must not benull.hints- Any hints to use when looking up the gml object, this value may benull.- Returns:
- The gml object, or
nullif one could not be found matching the specified id. - Throws:
IOException- Any I/O errors that occur.
-
createFeatureSource
protected ContentFeatureSource createFeatureSource(ContentEntry entry) throws IOException
Creates a new instance ofJDBCFeatureStore.- Specified by:
createFeatureSourcein classContentDataStore- Parameters:
entry- The entry.- Returns:
- An new instance of
ContentFeatureSourcefor the entry. - Throws:
IOException- See Also:
ContentDataStore.createFeatureSource(ContentEntry)
-
createContentState
protected ContentState createContentState(ContentEntry entry)
Creates an instanceofJDBCState.- Overrides:
createContentStatein classContentDataStore- Parameters:
entry- The entry.- Returns:
- A new instance of
ContentStatefor the entry. - See Also:
ContentDataStore.createContentState(ContentEntry)
-
createTypeNames
protected List<Name> createTypeNames() throws IOException
Generates the list of type names provided by the database.The list is generated from the underlying database metadata.
- Specified by:
createTypeNamesin classContentDataStore- Returns:
- A list of
Name. - Throws:
IOException- Any errors occuring connecting to data.
-
getPrimaryKey
protected PrimaryKey getPrimaryKey(ContentEntry entry) throws IOException
Returns the primary key object for a particular entry, deriving it from the underlying database metadata.- Throws:
IOException
-
getColumnType
protected Class getColumnType(DatabaseMetaData metaData, String databaseSchema2, String tableName, String columnName) throws SQLException
Returns the type of the column by inspecting the metadata, with the collaboration of the dialect- Throws:
SQLException
-
getPrimaryKey
public PrimaryKey getPrimaryKey(SimpleFeatureType featureType) throws IOException
Returns the primary key object for a particular feature type / table, deriving it from the underlying database metadata.- Throws:
IOException
-
isExposePrimaryKeyColumns
protected boolean isExposePrimaryKeyColumns(SimpleFeatureType featureType) throws IOException
Returns the expose primary key columns flag for the specified feature type- Throws:
IOException
-
getBounds
protected ReferencedEnvelope getBounds(SimpleFeatureType featureType, Query query, Connection cx) throws IOException
Returns the bounds of the features for a particular feature type / table.- Parameters:
featureType- The feature type / table.query- Specifies rows to include in bounds calculation, as well as how many features and the offset if needed- Throws:
IOException
-
getCount
protected int getCount(SimpleFeatureType featureType, Query query, Connection cx) throws IOException
Returns the count of the features for a particular feature type / table.- Throws:
IOException
-
getAggregateValue
protected Object getAggregateValue(FeatureVisitor visitor, SimpleFeatureType featureType, Query query, Connection cx) throws IOException
Results the value of an aggregate function over a query.- Returns:
- generated result, or null if unsupported
- Throws:
IOException
-
isCountVisitor
protected boolean isCountVisitor(FeatureVisitor visitor)
-
isGroupByVisitor
protected boolean isGroupByVisitor(FeatureVisitor visitor)
Helper method the checks if a feature visitor is a group by visitor,- Parameters:
visitor- the feature visitor- Returns:
- TRUE if the visitor is a group by visitor otherwise FALSE
-
matchAggregateFunction
protected String matchAggregateFunction(FeatureVisitor visitor)
Helper method that will try to match a feature visitor with an aggregate function. If no aggregate function machs the visitor NULL will be returned.- Parameters:
visitor- the feature visitor- Returns:
- the match aggregate function name, or NULL if no match
-
extractGroupByExpressions
protected List<Expression> extractGroupByExpressions(FeatureVisitor visitor)
Helper method that extracts a list of group by attributes from a group by visitor. If the visitor is not a group by visitor an empty list will be returned.- Parameters:
visitor- the feature visitor- Returns:
- the list of the group by attributes or an empty list
-
extractValuesFromResultSet
protected GroupByVisitor.GroupByRawResult extractValuesFromResultSet(Connection cx, SimpleFeatureType featureType, ResultSet resultSet, List<Expression> groupBy, Function<Object,Object> converter, Hints hints) throws SQLException, IOException
Helper method that translate the result set to the appropriate group by visitor result format- Throws:
SQLExceptionIOException
-
insert
protected void insert(SimpleFeature feature, SimpleFeatureType featureType, Connection cx) throws IOException
Inserts a new feature into the database for a particular feature type / table.- Throws:
IOException
-
insert
protected void insert(Collection<? extends SimpleFeature> features, SimpleFeatureType featureType, Connection cx) throws IOException
Inserts a collection of new features into the database for a particular feature type / table.- Throws:
IOException
-
update
protected void update(SimpleFeatureType featureType, List<AttributeDescriptor> attributes, List<Object> values, Filter filter, Connection cx) throws IOException, SQLException
Updates an existing feature(s) in the database for a particular feature type / table.- Throws:
IOExceptionSQLException
-
update
protected void update(SimpleFeatureType featureType, AttributeDescriptor[] attributes, Object[] values, Filter filter, Connection cx) throws IOException, SQLException
Updates an existing feature(s) in the database for a particular feature type / table.- Throws:
IOExceptionSQLException
-
delete
protected void delete(SimpleFeatureType featureType, String fid, Connection cx) throws IOException
Deletes an existing feature in the database for a particular feature type / fid.- Throws:
IOException
-
delete
protected void delete(SimpleFeatureType featureType, Filter filter, Connection cx) throws IOException
Deletes an existing feature(s) in the database for a particular feature type / table.- Throws:
IOException
-
getConnection
public Connection getConnection(Transaction t) throws IOException
Returns a JDBC Connection to the underlying database for the specified GeoToolsTransaction. This has two main use cases:- Independently accessing the underlying database directly reusing the connection pool contained in the
JDBCDataStore - Performing some direct access to the database in the same JDBC transaction as the Geotools code
- If the transaction is
Transaction.AUTO_COMMITor if the transaction is not shared with this data store and originatingFeatureStoreobjects it is the duty of the caller to properly close the connection after usage, failure to do so will result in the connection pool loose one available connection permanently - If the transaction is on the other side a valid transaction is shared with Geotools the client code should
refrain from closing the connection, committing or rolling back, and use the
Transactionfacilities to do so instead
- Parameters:
t- The GeoTools transaction, can not be null- Throws:
IOException
- Independently accessing the underlying database directly reusing the connection pool contained in the
-
getConnection
protected final Connection getConnection(JDBCState state) throws IOException
Gets a database connection for the specified feature store.- Throws:
IOException
-
createConnection
protected final Connection createConnection()
Creates a new connection.Callers of this method should close the connection when done with it. .
-
releaseConnection
protected final void releaseConnection(Connection cx, JDBCState state)
Releases an existing connection (paying special attention toTransaction.AUTO_COMMIT.If the state is based off the AUTO_COMMIT transaction - close using
closeSafe(Connection). Otherwise wait until the transaction itself is closed to close the connection.
-
encodeFID
protected String encodeFID(PrimaryKey pkey, ResultSet rs) throws SQLException, IOException
Calls through to:encodeFID(pkey, rs, 0);
- Throws:
SQLExceptionIOException
-
encodeFID
protected String encodeFID(PrimaryKey pkey, ResultSet rs, int offset) throws SQLException, IOException
Encodes a feature id from a primary key and result set values.offset specifies where in the result set to start from when reading values for the primary key.
- Throws:
SQLExceptionIOException
-
decodeFID
public static List<Object> decodeFID(PrimaryKey key, String FID, boolean strict)
Decodes a fid into its components based on a primary key.- Parameters:
strict- If set to true the value of the fid will be validated against the type of the key columns. If a conversion can not be made, an exception will be thrown.
-
isGenerated
protected boolean isGenerated(PrimaryKey pkey)
Determines if a primary key is made up entirely of column which are generated via an auto-generating column or a sequence.
-
createTableSQL
protected String createTableSQL(SimpleFeatureType featureType, Connection cx) throws Exception
Generates a 'CREATE TABLE' sql statement.- Throws:
Exception
-
findPrimaryKeyColumnName
protected String findPrimaryKeyColumnName(SimpleFeatureType featureType)
-
dropTableSQL
protected String dropTableSQL(SimpleFeatureType featureType, Connection cx) throws Exception
Generates a 'DROP TABLE' sql statement.- Throws:
Exception
-
ensureAuthorization
protected void ensureAuthorization(SimpleFeatureType featureType, Filter filter, Transaction tx, Connection cx) throws IOException, SQLException
Ensures that that the specified transaction has access to features specified by a filter.If any features matching the filter are locked, and the transaction does not have authorization with respect to the lock, an exception is thrown.
- Parameters:
featureType- The feature type / table.filter- The filters.tx- The transaction.cx- The database connection.- Throws:
IOExceptionSQLException
-
ensureAssociationTablesExist
protected void ensureAssociationTablesExist(Connection cx) throws IOException, SQLException
Helper method for creating geometry association table if it does not exist.- Throws:
IOExceptionSQLException
-
createRelationshipTableSQL
protected String createRelationshipTableSQL(Connection cx) throws SQLException
Creates the sql for the relationship table.This method is only called when
isAssociations()is true.- Throws:
SQLException
-
createAssociationTableSQL
protected String createAssociationTableSQL(Connection cx) throws SQLException
Creates the sql for the association table.This method is only called when
isAssociations()is true.- Throws:
SQLException
-
createGeometryTableSQL
protected String createGeometryTableSQL(Connection cx) throws SQLException
Creates the sql for the geometry table.This method is only called when
isAssociations()is true.- Throws:
SQLException
-
createMultiGeometryTableSQL
protected String createMultiGeometryTableSQL(Connection cx) throws SQLException
Creates the sql for the multi_geometry table.This method is only called when
isAssociations()is true.- Throws:
SQLException
-
selectRelationshipSQL
protected String selectRelationshipSQL(String table, String column) throws SQLException
Creates the sql for the relationship table.This method is only called when
isAssociations()is true.- Parameters:
table- The table of the associationcolumn- The column of the association- Throws:
SQLException
-
selectRelationshipSQLPS
protected PreparedStatement selectRelationshipSQLPS(String table, String column, Connection cx) throws SQLException
Creates the prepared statement for a query against the relationship table.This method is only called when
isAssociations()is true.- Parameters:
table- The table of the associationcolumn- The column of the association- Throws:
SQLException
-
selectAssociationSQL
protected String selectAssociationSQL(String fid) throws SQLException
Creates the sql for the association table.This method is only called when
isAssociations()is true.- Parameters:
fid- The feature id of the association- Throws:
SQLException
-
selectAssociationSQLPS
protected PreparedStatement selectAssociationSQLPS(String fid, Connection cx) throws SQLException
Creates the prepared statement for the association table.This method is only called when
isAssociations()is true.- Parameters:
fid- The feature id of the association- Throws:
SQLException
-
selectGeometrySQL
protected String selectGeometrySQL(String gid) throws SQLException
Creates the sql for a select from the geometry table.This method is only called when
isAssociations()is true.- Parameters:
gid- The geometry id to select for, may benull- Throws:
SQLException
-
selectGeometrySQLPS
protected PreparedStatement selectGeometrySQLPS(String gid, Connection cx) throws SQLException
Creates the prepared for a select from the geometry table.This method is only called when
isAssociations()is true.- Parameters:
gid- The geometry id to select for, may benull- Throws:
SQLException
-
selectMultiGeometrySQL
protected String selectMultiGeometrySQL(String gid) throws SQLException
Creates the sql for a select from the multi geometry table.This method is only called when
isAssociations()is true.- Parameters:
gid- The geometry id to select for, may benull.- Throws:
SQLException
-
selectMultiGeometrySQLPS
protected PreparedStatement selectMultiGeometrySQLPS(String gid, Connection cx) throws SQLException
Creates the prepared statement for a select from the multi geometry table.This method is only called when
isAssociations()is true.- Parameters:
gid- The geometry id to select for, may benull.- Throws:
SQLException
-
createGeometryAssociationTableSQL
protected String createGeometryAssociationTableSQL(Connection cx) throws SQLException
Creates the sql for the geometry association table.This method is only called when
isAssociations()is true.- Throws:
SQLException
-
selectGeometryAssociationSQL
protected String selectGeometryAssociationSQL(String fid, String gid, String gname) throws SQLException
Creates the sql for a select from the geometry association table.- Parameters:
fid- The fid to select for, may benullgid- The geometry id to select for, may benullgname- The geometry name to select for, may benull- Throws:
SQLException
-
selectGeometryAssociationSQLPS
protected PreparedStatement selectGeometryAssociationSQLPS(String fid, String gid, String gname, Connection cx) throws SQLException
Creates the prepared statement for a select from the geometry association table.- Parameters:
fid- The fid to select for, may benullgid- The geometry id to select for, may benullgname- The geometry name to select for, may benull- Throws:
SQLException
-
selectSQL
protected String selectSQL(SimpleFeatureType featureType, Query query) throws IOException, SQLException
Generates a 'SELECT p1, p2, ... FROM ... WHERE ...' statement.- Parameters:
featureType- the feature type that the query must return (may contain less attributes than the native one)query- the query to be run. The type name and property will be ignored, as they are supposed to have been already embedded into the provided feature type- Throws:
IOExceptionSQLException
-
selectJoinSQL
protected String selectJoinSQL(SimpleFeatureType featureType, JoinInfo join, Query query) throws IOException, SQLException
- Throws:
IOExceptionSQLException
-
selectSQLPS
protected PreparedStatement selectSQLPS(SimpleFeatureType featureType, Query query, Connection cx) throws SQLException, IOException
Generates a 'SELECT p1, p2, ... FROM ... WHERE ...' prepared statement.- Parameters:
featureType- the feature type that the query must return (may contain less attributes than the native one)query- the query to be run. The type name and property will be ignored, as they are supposed to have been already embedded into the provided feature typecx- The database connection to be used to create the prepared statement- Throws:
SQLExceptionIOException
-
selectJoinSQLPS
protected PreparedStatement selectJoinSQLPS(SimpleFeatureType featureType, JoinInfo join, Query query, Connection cx) throws SQLException, IOException
- Throws:
SQLExceptionIOException
-
setPreparedFilterValues
protected void setPreparedFilterValues(PreparedStatement ps, List<FilterToSQL> toSQLs, Connection cx) throws SQLException
Helper method for setting the values of the WHERE class of a prepared statement from a list of PreparedFilterToSQL.- Throws:
SQLException
-
setPreparedFilterValues
public void setPreparedFilterValues(PreparedStatement ps, PreparedFilterToSQL toSQL, int offset, Connection cx) throws SQLException
Helper method for setting the values of the WHERE class of a prepared statement.- Throws:
SQLException
-
getPropertyName
protected String getPropertyName(SimpleFeatureType featureType, PropertyName propertyName)
Helper method for executing a property name against a feature type.This method will fall back on
PropertyName.getPropertyName()if it does not evaulate against the feature type.
-
selectBoundsSQL
protected String selectBoundsSQL(SimpleFeatureType featureType, Query query) throws SQLException, IOException
Generates a 'SELECT' sql statement which selects bounds.- Parameters:
featureType- The feature type / table.query- Specifies which features are to be used for the bounds computation (and in particular uses filter, start index and max features)- Throws:
SQLExceptionIOException
-
selectBoundsSQLPS
protected PreparedStatement selectBoundsSQLPS(SimpleFeatureType featureType, Query query, Connection cx) throws SQLException
Generates a 'SELECT' prepared statement which selects bounds.- Parameters:
featureType- The feature type / table.query- Specifies which features are to be used for the bounds computation (and in particular uses filter, start index and max features)cx- A database connection.- Throws:
SQLException
-
selectAggregateSQL
protected String selectAggregateSQL(String function, List<Expression> attributes, List<Expression> groupByExpressions, SimpleFeatureType featureType, Query query, LimitingVisitor visitor) throws SQLException, IOException
- Throws:
SQLExceptionIOException
-
selectAggregateSQLPS
protected PreparedStatement selectAggregateSQLPS(String function, List<Expression> attributes, List<Expression> groupByExpressions, SimpleFeatureType featureType, Query query, LimitingVisitor visitor, Connection cx) throws SQLException, IOException
- Throws:
SQLExceptionIOException
-
encodeGroupByStatement
protected void encodeGroupByStatement(List<Expression> groupByExpressions, StringBuffer sql, FilterToSQL filterToSQL, boolean aggregateOnExpression)
Helper method that adds a group by statement to the SQL query. If the list of group by attributes is empty or NULL no group by statement is add.- Parameters:
groupByExpressions- the group by attributes to be encodedsql- the sql query buffer
-
encodeFunction
protected void encodeFunction(String function, Expression expression, StringBuffer sql, FilterToSQL filterToSQL)
-
encodeFunction
protected void encodeFunction(String function, List<Expression> expressions, StringBuffer sql, FilterToSQL filterToSQL)
-
deleteSQL
protected String deleteSQL(SimpleFeatureType featureType, Filter filter) throws SQLException
Generates a 'DELETE FROM' sql statement.- Throws:
SQLException
-
deleteSQLPS
protected PreparedStatement deleteSQLPS(SimpleFeatureType featureType, Filter filter, Connection cx) throws SQLException
Generates a 'DELETE FROM' prepared statement.- Throws:
SQLException
-
insertSQL
protected String insertSQL(SimpleFeatureType featureType, SimpleFeature feature, KeysFetcher keysFetcher, Connection cx) throws SQLException, IOException
Generates a 'INSERT INFO' sql statement.- Throws:
SQLExceptionIOException
-
getColumnNames
protected static LinkedHashSet<String> getColumnNames(PrimaryKey key)
Returns the set of the primary key column names. The set is guaranteed to have the same iteration order as the primary key.
-
getGeometrySRID
protected int getGeometrySRID(Geometry g, AttributeDescriptor descriptor) throws IOException
Looks up the geometry srs by trying a number of heuristics. Returns -1 if all attempts at guessing the srid failed.- Throws:
IOException
-
getGeometryDimension
protected int getGeometryDimension(Geometry g, AttributeDescriptor descriptor) throws IOException
Looks up the geometry dimension by trying a number of heuristics. Returns 2 if all attempts at guessing the dimension failed.- Throws:
IOException
-
getDescriptorSRID
protected int getDescriptorSRID(AttributeDescriptor descriptor)
Extracts the eventual native SRID user property from the descriptor, returns -1 if not found
-
getDescriptorDimension
protected int getDescriptorDimension(AttributeDescriptor descriptor)
Extracts the eventual native dimension user property from the descriptor, returns -1 if not found
-
updateSQL
protected String updateSQL(SimpleFeatureType featureType, AttributeDescriptor[] attributes, Object[] values, Filter filter, Set<String> pkColumnNames) throws IOException, SQLException
Generates an 'UPDATE' sql statement.- Throws:
IOExceptionSQLException
-
updateSQLPS
protected PreparedStatement updateSQLPS(SimpleFeatureType featureType, AttributeDescriptor[] attributes, Object[] values, Filter filter, Set<String> pkColumnNames, Connection cx) throws IOException, SQLException
Generates an 'UPDATE' prepared statement.- Throws:
IOExceptionSQLException
-
createFilterToSQL
public FilterToSQL createFilterToSQL(SimpleFeatureType featureType)
Creates a new instance of a filter to sql encoder.The featureType may be null but it is not recommended. Such a case where this may neccessary is when a literal needs to be encoded in isolation.
-
createPreparedFilterToSQL
public PreparedFilterToSQL createPreparedFilterToSQL(SimpleFeatureType featureType)
Creates a new instance of a filter to sql encoder to be used in a prepared statement.
-
initializeFilterToSQL
protected <F extends FilterToSQL> F initializeFilterToSQL(F toSQL, SimpleFeatureType featureType)
Helper method to initialize a filter encoder instance.
-
encodeTableName
public void encodeTableName(String tableName, StringBuffer sql, Hints hints) throws SQLException
Helper method to encode table name which checks if a schema is set and prefixes the table name with it.- Throws:
SQLException
-
encodeAliasedTableName
public void encodeAliasedTableName(String tableName, StringBuffer sql, Hints hints, String alias) throws SQLException
Helper method to encode table name which checks if a schema is set and prefixes the table name with it, with the addition of an alias to the name- Throws:
SQLException
-
encodeTableJoin
protected void encodeTableJoin(SimpleFeatureType featureType, JoinInfo join, Query query, StringBuffer sql) throws SQLException
Helper method to encode the join clause(s) of a query.- Throws:
SQLException
-
encodeWhereJoin
protected List<FilterToSQL> encodeWhereJoin(SimpleFeatureType featureType, JoinInfo join, StringBuffer sql) throws IOException
- Throws:
IOException
-
setGmlProperties
protected void setGmlProperties(Geometry g, String gid, String name, String description)
Helper method for setting the gml:id of a geometry as user data.
-
applyLimitOffset
public void applyLimitOffset(StringBuffer sql, Query query)
Applies the limit/offset elements to the query if they are specified and if the dialect supports them- Parameters:
sql- The sql to be modifiedquery- the query that holds the limit and offset parameters
-
closeSafe
public void closeSafe(ResultSet rs)
Utility method for closing a result set.This method closed the result set "safely" in that it never throws an exception. Any exceptions that do occur are logged at
Level.FINER.- Parameters:
rs- The result set to close.
-
closeSafe
public void closeSafe(Statement st)
Utility method for closing a statement.This method closed the statement"safely" in that it never throws an exception. Any exceptions that do occur are logged at
Level.FINER.- Parameters:
st- The statement to close.
-
closeSafe
public void closeSafe(Connection cx)
Utility method for closing a connection.This method closed the connection "safely" in that it never throws an exception. Any exceptions that do occur are logged at
Level.FINER.- Parameters:
cx- The connection to close.
-
finalize
protected void finalize() throws Throwable
-
dispose
public void dispose()
Description copied from interface:DataAccessDisposes of this data store and releases any resource that it is using.A
DataStorecannot be used afterdisposehas been called, neither can any data access object it helped create, such asFeatureReader,FeatureSourceorFeatureCollection.This operation can be called more than once without side effects.
There is no thread safety assurance associated with this method. For example, client code will have to make sure this method is not called while retrieving/saving data from/to the storage, or be prepared for the consequences.
- Specified by:
disposein interfaceDataAccess<SimpleFeatureType,SimpleFeature>- Overrides:
disposein classContentDataStore
-
isGeneralizationRequired
protected boolean isGeneralizationRequired(Hints hints, GeometryDescriptor gatt)
Checks if geometry generalization required and makes sense- Parameters:
hints- hints hints passed ingatt- Geometry attribute descriptor- Returns:
- true to indicate generalization
-
isSimplificationRequired
protected boolean isSimplificationRequired(Hints hints, GeometryDescriptor gatt)
Checks if geometry simplification required and makes sense- Parameters:
hints- hints hints passed ingatt- Geometry attribute descriptor- Returns:
- true to indicate simplification
-
isGeometryReduceRequired
protected boolean isGeometryReduceRequired(Hints hints, GeometryDescriptor gatt, Hints.Key param)
Checks if reduction required and makes sense- Parameters:
hints- hints passed ingatt- Geometry attribute descriptorparam-Hints.GEOMETRY_GENERALIZATIONorHints.GEOMETRY_SIMPLIFICATION- Returns:
- true to indicate reducing the geometry, false otherwise
-
encodeGeometryColumn
public void encodeGeometryColumn(GeometryDescriptor gatt, StringBuffer sql, Hints hints)
Encoding a geometry column with respect to hints Supported Hints are provided bySQLDialect.addSupportedHints(Set)- Parameters:
hints- , may be null
-
encodeGeometryColumn
protected void encodeGeometryColumn(GeometryDescriptor gatt, String prefix, StringBuffer sql, Hints hints)
-
buildTransaction
public Transaction buildTransaction(Connection cx)
Builds a transaction object around a user provided connection. The returned transaction allows the store to work against an externally managed transaction, such as in J2EE enviroments. It is the duty of the caller to ensure the connection is to the same database managed by thisJDBCDataStore.Calls to
Transaction.commit(),Transaction.rollback()andTransaction.close()will not result in corresponding calls to the providedConnectionobject.- Parameters:
cx- The externally managed connection
-
createIndex
public void createIndex(Index index) throws IOException
Creates a new database index- Throws:
IOException
-
dropIndex
public void dropIndex(String typeName, String indexName) throws IOException
Creates a new database index- Throws:
IOException
-
getIndexes
public List<Index> getIndexes(String typeName) throws IOException
Lists all indexes associated to the given feature type- Parameters:
typeName- Name of the type for which indexes are searched. It's mandatory- Throws:
IOException
-
escapeNamePattern
public String escapeNamePattern(DatabaseMetaData metaData, String name) throws SQLException
Escapes a name pattern used in e.g.DatabaseMetaData.getColumns(String, String, String, String)when passed in argument is an exact name and not a pattern.When a table name or column name contains underscore (or percen, but this is rare) the underscore is treated as a placeholder and not an actual character. So if our intention is to match an exact name, we must escape such characters.
- Throws:
SQLException
-
-