public final class JDBCDataStore extends ContentDataStore implements GmlObjectStore
This class is not intended to be subclassed on a per database basis. Instead the notion of a "dialect" is used.
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 using setSQLDialect(SQLDialect)
.
DataSource
. A datastore
must be specified using setDataSource(DataSource)
.
setDatabaseSchema(String)
.
FilterCapabilities
instance. This is specified using #setFilterCapabilities(FilterCapabilities)
.Modifier and Type | Field and Description |
---|---|
protected HashMap<Class<? extends FeatureVisitor>,String> |
aggregateFunctions
Feature visitor to aggregate function name
|
protected boolean |
associations
flag controlling if the datastore is supporting feature and geometry relationships with
associations
|
protected int |
batchInsertSize
The number of features to bufferize while inserting in order to do batch inserts.
|
protected JDBCCallbackFactory |
callbackFactory |
protected HashMap<Class<?>,Integer> |
classToSqlTypeMappings
java class to sql type mappings;
|
protected List<ConnectionLifecycleListener> |
connectionLifecycleListeners
The listeners that are allowed to handle the connection lifecycle
|
protected String |
databaseSchema
The database schema.
|
protected DataSource |
dataSource
data source
|
SQLDialect |
dialect
the dialect of sql
|
protected static ReferencedEnvelope |
EMPTY_ENVELOPE
The envelope returned when bounds is called against a geometryless feature type
|
protected boolean |
exposePrimaryKeyColumns
flag controlling whether primary key columns of a table are exposed via the feature type.
|
protected static String |
FEATURE_ASSOCIATION_TABLE
name of table to use to store feature associations when
associations is set. |
protected static String |
FEATURE_RELATIONSHIP_TABLE
name of table to use to store feature relationships (information about associations) when
associations is set. |
int |
fetchSize
The fetch size for this datastore, defaulting to 1000.
|
protected static String |
GEOMETRY_ASSOCIATION_TABLE
name of table to use to store geometry associations when
associations is set. |
protected static String |
GEOMETRY_TABLE
name of table to use to store geometries when
associations is set. |
static String |
JDBC_COLUMN_ALIAS
Used to specify the column alias to use when encoding a column in a select
|
static String |
JDBC_NATIVE_SRID
The native SRID associated to a certain descriptor TODO: qualify this key with
'org.geotools.jdbc'
|
static String |
JDBC_NATIVE_TYPE
The key for attribute descriptor user data which specifies the original database column data
type, as a
Types value. |
static String |
JDBC_NATIVE_TYPENAME
The key for attribute descriptor user data which specifies the original database column data
type.
|
static String |
JDBC_PRIMARY_KEY_COLUMN
Boolean marker stating whether an attribute is part of the primary key
|
static String |
JDBC_READ_ONLY
Boolean marker stating whether the feature type is to be considered read only
|
static int |
MAX_IDS_IN_FILTER
Max number of ids to use for the optimized locks checking filter.
|
protected static String |
MULTI_GEOMETRY_TABLE
name of table to use to store multi geometries made up of non-multi geometries when
associations is set. |
protected PrimaryKeyFinder |
primaryKeyFinder
Finds the primary key definitions (instantiated here because the finders might keep state)
|
protected HashMap<String,Class<?>> |
sqlTypeNameToClassMappings
sql type name to java class mappings
|
protected HashMap<Integer,Class<?>> |
sqlTypeToClassMappings
sql type to java class mappings
|
protected HashMap<Integer,String> |
sqlTypeToSqlTypeNameOverrides
sql type to sql type name overrides
|
protected HashMap<String,String> |
supportedFunctions
java supported filter function mappings to dialect name;
|
protected static Boolean |
TRACE_ENABLED
When true, record a stack trace documenting who disposed the JDBCDataStore.
|
protected Map<String,VirtualTable> |
virtualTables
Contains the SQL definition of the various virtual tables
|
dataStoreFactory, entries, featureFactory, filterFactory, geometryFactory, JOINED_FEATURE_TYPE, lockingManager, LOGGER, namespaceURI, typeFactory, WRITER_ADD, WRITER_COMMIT, WRITER_UPDATE
Constructor and Description |
---|
JDBCDataStore() |
Modifier and Type | Method and Description |
---|---|
void |
addVirtualTable(VirtualTable vtable)
Deprecated.
Use createVirtualTable instead
|
void |
applyLimitOffset(StringBuffer sql,
Query query)
Applies the limit/offset elements to the query if they are specified and if the dialect
supports them
|
Transaction |
buildTransaction(Connection cx)
Builds a transaction object around a user provided connection.
|
void |
closeSafe(Connection cx)
Utility method for closing a connection.
|
void |
closeSafe(ResultSet rs)
Utility method for closing a result set.
|
void |
closeSafe(Statement st)
Utility method for closing a statement.
|
protected String |
createAssociationTableSQL(Connection cx)
Creates the sql for the association table.
|
protected Connection |
createConnection()
Creates a new connection.
|
protected ContentState |
createContentState(ContentEntry entry)
Creates an instanceof
JDBCState . |
protected ContentFeatureSource |
createFeatureSource(ContentEntry entry)
Creates a new instance of
JDBCFeatureStore . |
FilterToSQL |
createFilterToSQL(SimpleFeatureType featureType)
Creates a new instance of a filter to sql encoder.
|
protected String |
createGeometryAssociationTableSQL(Connection cx)
Creates the sql for the geometry association table.
|
protected String |
createGeometryTableSQL(Connection cx)
Creates the sql for the geometry table.
|
void |
createIndex(Index index)
Creates a new database index
|
protected String |
createMultiGeometryTableSQL(Connection cx)
Creates the sql for the multi_geometry table.
|
PreparedFilterToSQL |
createPreparedFilterToSQL(SimpleFeatureType featureType)
Creates a new instance of a filter to sql encoder to be used in a prepared statement.
|
protected String |
createRelationshipTableSQL(Connection cx)
Creates the sql for the relationship table.
|
void |
createSchema(SimpleFeatureType featureType)
Creates a table in the underlying database from the specified table.
|
protected String |
createTableSQL(SimpleFeatureType featureType,
Connection cx)
Generates a 'CREATE TABLE' sql statement.
|
protected List |
createTypeNames()
Generates the list of type names provided by the database.
|
void |
createVirtualTable(VirtualTable vtable)
Adds a virtual table to the data store.
|
protected static List<Object> |
decodeFID(PrimaryKey key,
String FID,
boolean strict)
Decodes a fid into its components based on a primary key.
|
protected void |
delete(SimpleFeatureType featureType,
Filter filter,
Connection cx)
Deletes an existing feature(s) in the database for a particular feature type / table.
|
protected void |
delete(SimpleFeatureType featureType,
String fid,
Connection cx)
Deletes an existing feature in the database for a particular feature type / fid.
|
protected String |
deleteSQL(SimpleFeatureType featureType,
Filter filter)
Generates a 'DELETE FROM' sql statement.
|
protected PreparedStatement |
deleteSQLPS(SimpleFeatureType featureType,
Filter filter,
Connection cx)
Generates a 'DELETE FROM' prepared statement.
|
void |
dispose()
Disposes of this data store and releases any resource that it is using.
|
void |
dropIndex(String typeName,
String indexName)
Creates a new database index
|
protected String |
dropTableSQL(SimpleFeatureType featureType,
Connection cx)
Generates a 'DROP TABLE' sql statement.
|
VirtualTable |
dropVirtualTable(String name)
Removes and returns the specified virtual table
|
void |
encodeAliasedTableName(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 name
|
protected static String |
encodeFID(List<Object> keyValues) |
protected String |
encodeFID(PrimaryKey pkey,
ResultSet rs)
Calls through to:
encodeFID(pkey, rs, 0);
|
protected String |
encodeFID(PrimaryKey pkey,
ResultSet rs,
int offset)
Encodes a feature id from a primary key and result set values.
|
protected void |
encodeFunction(String function,
Expression expression,
StringBuffer sql,
FilterToSQL filterToSQL) |
void |
encodeGeometryColumn(GeometryDescriptor gatt,
StringBuffer sql,
Hints hints)
Encoding a geometry column with respect to hints Supported Hints are provided by
SQLDialect.addSupportedHints(Set) |
protected void |
encodeGeometryColumn(GeometryDescriptor gatt,
String prefix,
StringBuffer sql,
Hints hints) |
protected void |
encodeGroupByStatement(List<Expression> groupByExpressions,
StringBuffer sql,
FilterToSQL filterToSQL,
boolean aggregateOnExpression)
Helper method that adds a group by statement to the SQL query.
|
protected void |
encodeTableJoin(SimpleFeatureType featureType,
JoinInfo join,
Query query,
StringBuffer sql)
Helper method to encode the join clause(s) of a query.
|
void |
encodeTableName(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 void |
ensureAssociationTablesExist(Connection cx)
Helper method for creating geometry association table if it does not exist.
|
protected void |
ensureAuthorization(SimpleFeatureType featureType,
Filter filter,
Transaction tx,
Connection cx)
Ensures that that the specified transaction has access to features specified by a filter.
|
String |
escapeNamePattern(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.GroupByRawResult |
extractValuesFromResultSet(ResultSet resultSet,
int numberOfGroupByAttributes)
Helper method that translate the result set to the appropriate group by visitor result format
|
protected void |
finalize() |
protected String |
findPrimaryKeyColumnName(SimpleFeatureType featureType) |
JDBCFeatureSource |
getAbsoluteFeatureSource(String typeName) |
Map<Class<? extends FeatureVisitor>,String> |
getAggregateFunctions()
Returns the supported aggregate functions and the visitors they map to.
|
protected Object |
getAggregateValue(FeatureVisitor visitor,
SimpleFeatureType featureType,
Query query,
Connection cx)
Results the value of an aggregate function over a query.
|
int |
getBatchInsertSize() |
protected ReferencedEnvelope |
getBounds(SimpleFeatureType featureType,
Query query,
Connection cx)
Returns the bounds of the features for a particular feature type / table.
|
JDBCCallbackFactory |
getCallbackFactory() |
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 Class |
getColumnType(DatabaseMetaData metaData,
String databaseSchema2,
String tableName,
String columnName)
Returns the type of the column by inspecting the metadata, with the collaboration of the
dialect
|
protected Connection |
getConnection(JDBCState state)
Gets a database connection for the specified feature store.
|
Connection |
getConnection(Transaction t)
Returns a JDBC Connection to the underlying database for the specified GeoTools
Transaction . |
List<ConnectionLifecycleListener> |
getConnectionLifecycleListeners()
Returns a modifiable list of connection lifecycle listeners
|
protected int |
getCount(SimpleFeatureType featureType,
Query query,
Connection cx)
Returns the count of the features for a particular feature type / table.
|
String |
getDatabaseSchema()
The schema from which this datastore is serving tables from.
|
DataSource |
getDataSource()
The data source the datastore uses to obtain connections to the underlying database.
|
protected int |
getDescriptorDimension(AttributeDescriptor descriptor)
Extracts the eventual native dimension user property from the descriptor, returns -1 if not
found
|
protected int |
getDescriptorSRID(AttributeDescriptor descriptor)
Extracts the eventual native SRID user property from the descriptor, returns -1 if not found
|
int |
getFetchSize()
The current fetch size.
|
FilterCapabilities |
getFilterCapabilities()
The filter capabilities which reports which spatial operations the underlying database can
handle natively.
|
protected int |
getGeometryDimension(Geometry g,
AttributeDescriptor descriptor)
Looks up the geometry dimension by trying a number of heuristics.
|
protected int |
getGeometrySRID(Geometry g,
AttributeDescriptor descriptor)
Looks up the geometry srs by trying a number of heuristics.
|
Object |
getGmlObject(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 type
|
Integer |
getMapping(Class<?> clazz)
Returns the sql type mapped to the specified java type.
|
Class<?> |
getMapping(int sqlType)
Returns the java type mapped to the specified sql type.
|
Class<?> |
getMapping(String sqlTypeName)
Returns the java type mapped to the specified sql type name.
|
protected PrimaryKey |
getPrimaryKey(ContentEntry entry)
Returns the primary key object for a particular entry, deriving it from the underlying
database metadata.
|
PrimaryKey |
getPrimaryKey(SimpleFeatureType featureType)
Returns the primary key object for a particular feature type / table, deriving it from the
underlying database metadata.
|
PrimaryKeyFinder |
getPrimaryKeyFinder()
Returns the finder used to build
PrimaryKey representations |
protected String |
getPropertyName(SimpleFeatureType featureType,
PropertyName propertyName)
Helper method for executing a property name against a feature type.
|
SQLDialect |
getSQLDialect()
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 (from
Types ) to
database type names. |
Map<String,String> |
getSupportedFunctions()
Returns the supported functions and the dialect name they map to.
|
Map<String,VirtualTable> |
getVirtualTables()
Returns a live, immutable view of the virtual tables map (from name to definition)
|
protected <F extends FilterToSQL> |
initializeFilterToSQL(F toSQL,
SimpleFeatureType featureType)
Helper method to initialize a filter encoder instance.
|
protected void |
insert(Collection<? extends SimpleFeature> features,
SimpleFeatureType featureType,
Connection cx)
Inserts a collection of new features into the database for a particular feature type / table.
|
protected void |
insert(SimpleFeature feature,
SimpleFeatureType featureType,
Connection cx)
Inserts a new feature into the database for a particular feature type / table.
|
protected String |
insertSQL(SimpleFeatureType featureType,
SimpleFeature feature,
KeysFetcher keysFetcher,
Connection cx)
Generates a 'INSERT INFO' sql statement.
|
boolean |
isAssociations()
Flag controlling if the datastore is supporting feature and geometry relationships with
associations
|
protected boolean |
isCountVisitor(FeatureVisitor visitor) |
boolean |
isExposePrimaryKeyColumns()
Determines if the datastore creates feature types which include those columns / attributes
which compose the primary key.
|
protected boolean |
isExposePrimaryKeyColumns(SimpleFeatureType featureType)
Returns the expose primary key columns flag for the specified feature type
|
protected boolean |
isGeneralizationRequired(Hints hints,
GeometryDescriptor gatt)
Checks if geometry generalization required and makes sense
|
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.
|
protected boolean |
isGeometryReduceRequired(Hints hints,
GeometryDescriptor gatt,
Hints.Key param)
Checks if reduction required and makes sense
|
protected boolean |
isGroupByVisitor(FeatureVisitor visitor)
Helper method the checks if a feature visitor is a group by visitor,
|
protected boolean |
isSimplificationRequired(Hints hints,
GeometryDescriptor gatt)
Checks if geometry simplification required and makes sense
|
protected String |
matchAggregateFunction(FeatureVisitor visitor)
Helper method that will try to match a feature visitor with an aggregate function.
|
protected void |
releaseConnection(Connection cx,
JDBCState state)
Releases an existing connection (paying special attention to
Transaction.AUTO_COMMIT . |
void |
removeSchema(Name typeName)
Used to permanently remove a schema from the underlying storage
This functionality is similar to an "drop table" statement in SQL.
|
void |
removeSchema(String typeName)
Used to permanently remove a schema from the underlying storage
This functionality is similar to an "drop table" statement in SQL.
|
VirtualTable |
removeVirtualTable(String name)
Deprecated.
Use dropVirtualTable instead
|
protected String |
selectAggregateSQL(String function,
Expression att,
List<Expression> groupByExpressions,
SimpleFeatureType featureType,
Query query,
LimitingVisitor visitor) |
protected PreparedStatement |
selectAggregateSQLPS(String function,
Expression att,
List<Expression> groupByExpressions,
SimpleFeatureType featureType,
Query query,
LimitingVisitor visitor,
Connection cx) |
protected String |
selectAssociationSQL(String fid)
Creates the sql for the association table.
|
protected PreparedStatement |
selectAssociationSQLPS(String fid,
Connection cx)
Creates the prepared statement for the association table.
|
protected String |
selectBoundsSQL(SimpleFeatureType featureType,
Query query)
Generates a 'SELECT' sql statement which selects bounds.
|
protected PreparedStatement |
selectBoundsSQLPS(SimpleFeatureType featureType,
Query query,
Connection cx)
Generates a 'SELECT' prepared statement which selects bounds.
|
protected String |
selectGeometryAssociationSQL(String fid,
String gid,
String gname)
Creates the sql for a select from the geometry association table.
|
protected PreparedStatement |
selectGeometryAssociationSQLPS(String fid,
String gid,
String gname,
Connection cx)
Creates the prepared statement for a select from the geometry association table.
|
protected String |
selectGeometrySQL(String gid)
Creates the sql for a select from the geometry table.
|
protected PreparedStatement |
selectGeometrySQLPS(String gid,
Connection cx)
Creates the prepared for a select from the geometry table.
|
protected String |
selectJoinSQL(SimpleFeatureType featureType,
JoinInfo join,
Query query) |
protected PreparedStatement |
selectJoinSQLPS(SimpleFeatureType featureType,
JoinInfo join,
Query query,
Connection cx) |
protected String |
selectMultiGeometrySQL(String gid)
Creates the sql for a select from the multi geometry table.
|
protected PreparedStatement |
selectMultiGeometrySQLPS(String gid,
Connection cx)
Creates the prepared statement for a select from the multi geometry table.
|
protected String |
selectRelationshipSQL(String table,
String column)
Creates the sql for the relationship table.
|
protected PreparedStatement |
selectRelationshipSQLPS(String table,
String column,
Connection cx)
Creates the prepared statement for a query against the relationship table.
|
protected String |
selectSQL(SimpleFeatureType featureType,
Query query)
Generates a 'SELECT p1, p2, ...
|
protected PreparedStatement |
selectSQLPS(SimpleFeatureType featureType,
Query query,
Connection cx)
Generates a 'SELECT p1, p2, ...
|
void |
setAssociations(boolean foreignKeyGeometries)
Sets the flag controlling if the datastore is supporting feature and geometry relationships
with associations
|
void |
setBatchInsertSize(int batchInsertSize)
Set the number of features to bufferize while inserting in order to do batch inserts.
|
void |
setCallbackFactory(JDBCCallbackFactory factory) |
void |
setDatabaseSchema(String databaseSchema)
Set the database schema for the datastore.
|
void |
setDataSource(DataSource dataSource)
Sets the data source the datastore uses to obtain connections to the underlying database.
|
void |
setExposePrimaryKeyColumns(boolean exposePrimaryKeyColumns)
Sets the flag controlling if the datastore creates feature types which include those columns
/ attributes which compose the primary key.
|
void |
setFetchSize(int fetchSize)
Changes the fetch size.
|
protected void |
setGmlProperties(Geometry g,
String gid,
String name,
String description)
Helper method for setting the gml:id of a geometry as user data.
|
protected void |
setPreparedFilterValues(PreparedStatement ps,
List toSQLs,
Connection cx)
Helper method for setting the values of the WHERE class of a prepared statement from a list
of PreparedFilterToSQL.
|
void |
setPreparedFilterValues(PreparedStatement ps,
PreparedFilterToSQL toSQL,
int offset,
Connection cx)
Helper method for setting the values of the WHERE class of a prepared statement.
|
void |
setPrimaryKeyFinder(PrimaryKeyFinder primaryKeyFinder)
Sets the finder used to build
PrimaryKey representations |
void |
setSQLDialect(SQLDialect dialect)
Sets the dialect the datastore uses to generate sql statements in order to communicate with
the underlying database.
|
protected void |
update(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 void |
update(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 String |
updateSQL(SimpleFeatureType featureType,
AttributeDescriptor[] attributes,
Object[] values,
Filter filter,
Set<String> pkColumnNames)
Generates an 'UPDATE' sql statement.
|
protected PreparedStatement |
updateSQLPS(SimpleFeatureType featureType,
AttributeDescriptor[] attributes,
Object[] values,
Filter filter,
Set<String> pkColumnNames,
Connection cx)
Generates an 'UPDATE' prepared statement.
|
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
protected static final Boolean TRACE_ENABLED
public static final String JDBC_NATIVE_SRID
public static final String JDBC_READ_ONLY
public static final String JDBC_PRIMARY_KEY_COLUMN
public static final String JDBC_NATIVE_TYPENAME
public static final String JDBC_NATIVE_TYPE
Types
value.public static final String JDBC_COLUMN_ALIAS
protected static final String GEOMETRY_TABLE
associations
is set.protected static final String MULTI_GEOMETRY_TABLE
associations
is set.protected static final String GEOMETRY_ASSOCIATION_TABLE
associations
is set.protected static final String FEATURE_RELATIONSHIP_TABLE
associations
is set.protected static final String FEATURE_ASSOCIATION_TABLE
associations
is set.protected static final ReferencedEnvelope EMPTY_ENVELOPE
public static final int MAX_IDS_IN_FILTER
protected DataSource dataSource
public SQLDialect dialect
protected String databaseSchema
protected HashMap<Integer,Class<?>> sqlTypeToClassMappings
protected HashMap<String,Class<?>> sqlTypeNameToClassMappings
protected HashMap<Class<?>,Integer> classToSqlTypeMappings
protected HashMap<Integer,String> sqlTypeToSqlTypeNameOverrides
protected HashMap<Class<? extends FeatureVisitor>,String> aggregateFunctions
protected HashMap<String,String> supportedFunctions
protected boolean associations
public int fetchSize
protected int batchInsertSize
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.
protected boolean exposePrimaryKeyColumns
protected PrimaryKeyFinder primaryKeyFinder
protected Map<String,VirtualTable> virtualTables
protected List<ConnectionLifecycleListener> connectionLifecycleListeners
protected JDBCCallbackFactory callbackFactory
public void setCallbackFactory(JDBCCallbackFactory factory)
public JDBCCallbackFactory getCallbackFactory()
public JDBCFeatureSource getAbsoluteFeatureSource(String typeName) throws IOException
IOException
public void addVirtualTable(VirtualTable vtable) throws IOException
IOException
- If the view definition is not validpublic void createVirtualTable(VirtualTable vtable) throws IOException
IOException
- If the view definition is not validpublic List<ConnectionLifecycleListener> getConnectionLifecycleListeners()
public VirtualTable removeVirtualTable(String name)
name
- public VirtualTable dropVirtualTable(String name)
name
- public Map<String,VirtualTable> getVirtualTables()
public PrimaryKeyFinder getPrimaryKeyFinder()
PrimaryKey
representationspublic void setPrimaryKeyFinder(PrimaryKeyFinder primaryKeyFinder)
PrimaryKey
representationsprimaryKeyFinder
- public int getFetchSize()
public void setFetchSize(int fetchSize)
fetchSize
- public int getBatchInsertSize()
public void setBatchInsertSize(int batchInsertSize)
Warning: when changing this value from its default of 1, the behavior of the JDBCInsertFeatureWriter
is 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.
batchInsertSize
- public boolean isExposePrimaryKeyColumns()
public void setExposePrimaryKeyColumns(boolean exposePrimaryKeyColumns)
public SQLDialect getSQLDialect()
null
.public void setSQLDialect(SQLDialect dialect)
dialect
- The dialect, never null
.public DataSource getDataSource()
null
.public void setDataSource(DataSource dataSource)
dataSource
- The data source, never null
.public String getDatabaseSchema()
null
if non specified.public void setDatabaseSchema(String databaseSchema)
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 null
to specify no particular schema.
databaseSchema
- The schema, may be null
.public FilterCapabilities getFilterCapabilities()
null
.public boolean isAssociations()
public void setAssociations(boolean foreignKeyGeometries)
public Map<Integer,Class<?>> getSqlTypeToClassMappings()
These mappings are derived from SQLDialect.registerSqlTypeToClassMappings(java.util.Map)
null
.public Map<String,Class<?>> getSqlTypeNameToClassMappings()
These mappings are derived from SQLDialect.registerSqlTypeNameToClassMappings(Map)
null.
public Map<Class<?>,Integer> getClassToSqlTypeMappings()
These mappings are derived from SQLDialect.registerClassToSqlMappings(Map)
null
.public Map<Integer,String> getSqlTypeToSqlTypeNameOverrides()
Types
) to
database type names.
This method will return an empty map when there are no overrides.
public Map<Class<? extends FeatureVisitor>,String> getAggregateFunctions()
public Map<String,String> getSupportedFunctions()
public Class<?> getMapping(int sqlType)
If there is no such type mapped to sqlType, null
is returned.
sqlType
- The integer constant for the sql type from Types
.null
. if no such mapping exists.public Class<?> getMapping(String sqlTypeName)
If there is no such type mapped to sqlTypeName, null
is returned.
sqlTypeName
- The name of the sql type.null
. if no such mapping exists.public Integer getMapping(Class<?> clazz)
If there is no such type mapped to clazz, Types.OTHER
is returned.
clazz
- The java class.Types
, Types.OTHER if no such mapping exists.public void createSchema(SimpleFeatureType featureType) throws IOException
This method will map the classes of the attributes of featureType to sql types and generate a 'CREATE TABLE' statement against the underlying database.
createSchema
in interface DataAccess<SimpleFeatureType,SimpleFeature>
createSchema
in class ContentDataStore
featureType
- FetureType to add to DataStoreIllegalArgumentException
- If the table already exists.IOException
- If the table cannot be created due to an error.DataStore#createSchema(SimpleFeatureType)
public void removeSchema(String typeName) throws IOException
DataStore
This functionality is similar to an "drop table" statement in SQL. Implementation is optional; it may not be supported by all servers or files.
removeSchema
in interface DataStore
removeSchema
in class ContentDataStore
IOException
- if the operation failedDataStore.removeSchema(String)
public void removeSchema(Name typeName) throws IOException
DataAccess
This functionality is similar to an "drop table" statement in SQL. Implementation is optional; it may not be supported by all servers or files.
removeSchema
in interface DataAccess<SimpleFeatureType,SimpleFeature>
removeSchema
in class ContentDataStore
IOException
- if the operation failedDataAccess.removeSchema(Name)
public Object getGmlObject(GmlObjectId id, Hints hints) throws IOException
GmlObjectStore
This method returns null
if no such object exists.
getGmlObject
in interface GmlObjectStore
id
- The id of the object, must not be null
.hints
- Any hints to use when looking up the gml object, this value may be null
.null
if one could not be found matching the specified
id.IOException
- Any I/O errors that occur.protected ContentFeatureSource createFeatureSource(ContentEntry entry) throws IOException
JDBCFeatureStore
.createFeatureSource
in class ContentDataStore
entry
- The entry.ContentFeatureSource
for the entry.IOException
ContentDataStore.createFeatureSource(ContentEntry)
protected ContentState createContentState(ContentEntry entry)
JDBCState
.createContentState
in class ContentDataStore
entry
- The entry.ContentState
for the entry.ContentDataStore.createContentState(ContentEntry)
protected List createTypeNames() throws IOException
The list is generated from the underlying database metadata.
createTypeNames
in class ContentDataStore
Name
.IOException
- Any errors occuring connecting to data.protected PrimaryKey getPrimaryKey(ContentEntry entry) throws IOException
IOException
protected Class getColumnType(DatabaseMetaData metaData, String databaseSchema2, String tableName, String columnName) throws SQLException
SQLException
public PrimaryKey getPrimaryKey(SimpleFeatureType featureType) throws IOException
IOException
protected boolean isExposePrimaryKeyColumns(SimpleFeatureType featureType) throws IOException
featureType
- IOException
protected ReferencedEnvelope getBounds(SimpleFeatureType featureType, Query query, Connection cx) throws IOException
featureType
- The feature type / table.query
- Specifies rows to include in bounds calculation, as well as how many features
and the offset if neededIOException
protected int getCount(SimpleFeatureType featureType, Query query, Connection cx) throws IOException
IOException
protected Object getAggregateValue(FeatureVisitor visitor, SimpleFeatureType featureType, Query query, Connection cx) throws IOException
IOException
protected boolean isCountVisitor(FeatureVisitor visitor)
protected boolean isGroupByVisitor(FeatureVisitor visitor)
visitor
- the feature visitorprotected String matchAggregateFunction(FeatureVisitor visitor)
visitor
- the feature visitorprotected List<Expression> extractGroupByExpressions(FeatureVisitor visitor)
visitor
- the feature visitorprotected GroupByVisitor.GroupByRawResult extractValuesFromResultSet(ResultSet resultSet, int numberOfGroupByAttributes) throws SQLException
SQLException
protected void insert(SimpleFeature feature, SimpleFeatureType featureType, Connection cx) throws IOException
IOException
protected void insert(Collection<? extends SimpleFeature> features, SimpleFeatureType featureType, Connection cx) throws IOException
IOException
protected void update(SimpleFeatureType featureType, List<AttributeDescriptor> attributes, List<Object> values, Filter filter, Connection cx) throws IOException, SQLException
IOException
SQLException
protected void update(SimpleFeatureType featureType, AttributeDescriptor[] attributes, Object[] values, Filter filter, Connection cx) throws IOException, SQLException
IOException
SQLException
protected void delete(SimpleFeatureType featureType, String fid, Connection cx) throws IOException
IOException
protected void delete(SimpleFeatureType featureType, Filter filter, Connection cx) throws IOException
IOException
public Connection getConnection(Transaction t) throws IOException
Transaction
. This has two main use cases:
JDBCDataStore
Transaction.AUTO_COMMIT
or if the transaction is not
shared with this data store and originating FeatureStore
objects 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
Transaction
facilities to do so instead
t
- The GeoTools transaction. Can be null
, in that case a new connection will be
returned (as if Transaction.AUTO_COMMIT
was provided)IOException
protected final Connection getConnection(JDBCState state) throws IOException
IOException
protected final Connection createConnection()
Callers of this method should close the connection when done with it. .
protected final void releaseConnection(Connection cx, JDBCState state)
Transaction.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.
protected String encodeFID(PrimaryKey pkey, ResultSet rs) throws SQLException, IOException
encodeFID(pkey, rs, 0);
SQLException
IOException
protected String encodeFID(PrimaryKey pkey, ResultSet rs, int offset) throws SQLException, IOException
offset specifies where in the result set to start from when reading values for the primary key.
SQLException
IOException
protected static List<Object> decodeFID(PrimaryKey key, String FID, boolean strict)
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.protected boolean isGenerated(PrimaryKey pkey)
protected String createTableSQL(SimpleFeatureType featureType, Connection cx) throws Exception
Exception
protected String findPrimaryKeyColumnName(SimpleFeatureType featureType)
protected String dropTableSQL(SimpleFeatureType featureType, Connection cx) throws Exception
Exception
protected void ensureAuthorization(SimpleFeatureType featureType, Filter filter, Transaction tx, Connection cx) throws IOException, SQLException
If any features matching the filter are locked, and the transaction does not have authorization with respect to the lock, an exception is thrown.
featureType
- The feature type / table.filter
- The filters.tx
- The transaction.cx
- The database connection.IOException
SQLException
protected void ensureAssociationTablesExist(Connection cx) throws IOException, SQLException
IOException
SQLException
protected String createRelationshipTableSQL(Connection cx) throws SQLException
This method is only called when isAssociations()
is true.
SQLException
protected String createAssociationTableSQL(Connection cx) throws SQLException
This method is only called when isAssociations()
is true.
SQLException
protected String createGeometryTableSQL(Connection cx) throws SQLException
This method is only called when isAssociations()
is true.
SQLException
protected String createMultiGeometryTableSQL(Connection cx) throws SQLException
This method is only called when isAssociations()
is true.
SQLException
protected String selectRelationshipSQL(String table, String column) throws SQLException
This method is only called when isAssociations()
is true.
table
- The table of the associationcolumn
- The column of the associationSQLException
protected PreparedStatement selectRelationshipSQLPS(String table, String column, Connection cx) throws SQLException
This method is only called when isAssociations()
is true.
table
- The table of the associationcolumn
- The column of the associationSQLException
protected String selectAssociationSQL(String fid) throws SQLException
This method is only called when isAssociations()
is true.
fid
- The feature id of the associationSQLException
protected PreparedStatement selectAssociationSQLPS(String fid, Connection cx) throws SQLException
This method is only called when isAssociations()
is true.
fid
- The feature id of the associationSQLException
protected String selectGeometrySQL(String gid) throws SQLException
This method is only called when isAssociations()
is true.
gid
- The geometry id to select for, may be null
SQLException
protected PreparedStatement selectGeometrySQLPS(String gid, Connection cx) throws SQLException
This method is only called when isAssociations()
is true.
gid
- The geometry id to select for, may be null
SQLException
protected String selectMultiGeometrySQL(String gid) throws SQLException
This method is only called when isAssociations()
is true.
gid
- The geometry id to select for, may be null
.SQLException
protected PreparedStatement selectMultiGeometrySQLPS(String gid, Connection cx) throws SQLException
This method is only called when isAssociations()
is true.
gid
- The geometry id to select for, may be null
.SQLException
protected String createGeometryAssociationTableSQL(Connection cx) throws SQLException
This method is only called when isAssociations()
is true.
SQLException
protected String selectGeometryAssociationSQL(String fid, String gid, String gname) throws SQLException
fid
- The fid to select for, may be null
gid
- The geometry id to select for, may be null
gname
- The geometry name to select for, may be null
SQLException
protected PreparedStatement selectGeometryAssociationSQLPS(String fid, String gid, String gname, Connection cx) throws SQLException
fid
- The fid to select for, may be null
gid
- The geometry id to select for, may be null
gname
- The geometry name to select for, may be null
SQLException
protected String selectSQL(SimpleFeatureType featureType, Query query) throws IOException, SQLException
featureType
- the feature type that the query must return (may contain less attributes
than the native one)attributes
- the properties queried, or Query.ALL_NAMES
to gather all of themquery
- 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 typesort
- sort conditionsIOException
SQLException
protected String selectJoinSQL(SimpleFeatureType featureType, JoinInfo join, Query query) throws IOException, SQLException
IOException
SQLException
protected PreparedStatement selectSQLPS(SimpleFeatureType featureType, Query query, Connection cx) throws SQLException, IOException
featureType
- the feature type that the query must return (may contain less attributes
than the native one)attributes
- the properties queried, or Query.ALL_NAMES
to gather all of themquery
- 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 statementSQLException
IOException
protected PreparedStatement selectJoinSQLPS(SimpleFeatureType featureType, JoinInfo join, Query query, Connection cx) throws SQLException, IOException
SQLException
IOException
protected void setPreparedFilterValues(PreparedStatement ps, List toSQLs, Connection cx) throws SQLException
SQLException
public void setPreparedFilterValues(PreparedStatement ps, PreparedFilterToSQL toSQL, int offset, Connection cx) throws SQLException
SQLException
protected String getPropertyName(SimpleFeatureType featureType, PropertyName propertyName)
This method will fall back on PropertyName.getPropertyName()
if it does not
evaulate against the feature type.
protected String selectBoundsSQL(SimpleFeatureType featureType, Query query) throws SQLException
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)SQLException
protected PreparedStatement selectBoundsSQLPS(SimpleFeatureType featureType, Query query, Connection cx) throws SQLException
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.SQLException
protected String selectAggregateSQL(String function, Expression att, List<Expression> groupByExpressions, SimpleFeatureType featureType, Query query, LimitingVisitor visitor) throws SQLException, IOException
SQLException
IOException
protected PreparedStatement selectAggregateSQLPS(String function, Expression att, List<Expression> groupByExpressions, SimpleFeatureType featureType, Query query, LimitingVisitor visitor, Connection cx) throws SQLException, IOException
SQLException
IOException
protected void encodeGroupByStatement(List<Expression> groupByExpressions, StringBuffer sql, FilterToSQL filterToSQL, boolean aggregateOnExpression)
attributes
- the group by attributes to be encodedsql
- the sql query bufferprotected void encodeFunction(String function, Expression expression, StringBuffer sql, FilterToSQL filterToSQL)
protected String deleteSQL(SimpleFeatureType featureType, Filter filter) throws SQLException
SQLException
protected PreparedStatement deleteSQLPS(SimpleFeatureType featureType, Filter filter, Connection cx) throws SQLException
SQLException
protected String insertSQL(SimpleFeatureType featureType, SimpleFeature feature, KeysFetcher keysFetcher, Connection cx) throws SQLException, IOException
IOException
SQLException
protected static LinkedHashSet<String> getColumnNames(PrimaryKey key)
protected int getGeometrySRID(Geometry g, AttributeDescriptor descriptor) throws IOException
IOException
protected int getGeometryDimension(Geometry g, AttributeDescriptor descriptor) throws IOException
IOException
protected int getDescriptorSRID(AttributeDescriptor descriptor)
descriptor
- protected int getDescriptorDimension(AttributeDescriptor descriptor)
descriptor
- protected String updateSQL(SimpleFeatureType featureType, AttributeDescriptor[] attributes, Object[] values, Filter filter, Set<String> pkColumnNames) throws IOException, SQLException
IOException
SQLException
protected PreparedStatement updateSQLPS(SimpleFeatureType featureType, AttributeDescriptor[] attributes, Object[] values, Filter filter, Set<String> pkColumnNames, Connection cx) throws IOException, SQLException
IOException
SQLException
public FilterToSQL createFilterToSQL(SimpleFeatureType featureType)
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.
public PreparedFilterToSQL createPreparedFilterToSQL(SimpleFeatureType featureType)
protected <F extends FilterToSQL> F initializeFilterToSQL(F toSQL, SimpleFeatureType featureType)
public void encodeTableName(String tableName, StringBuffer sql, Hints hints) throws SQLException
SQLException
public void encodeAliasedTableName(String tableName, StringBuffer sql, Hints hints, String alias) throws SQLException
SQLException
protected void encodeTableJoin(SimpleFeatureType featureType, JoinInfo join, Query query, StringBuffer sql) throws SQLException
SQLException
protected List<FilterToSQL> encodeWhereJoin(SimpleFeatureType featureType, JoinInfo join, StringBuffer sql) throws IOException
IOException
protected void setGmlProperties(Geometry g, String gid, String name, String description)
public void applyLimitOffset(StringBuffer sql, Query query)
sql
- The sql to be modifiedthe
- query that holds the limit and offset parameterspublic void closeSafe(ResultSet rs)
This method closed the result set "safely" in that it never throws an exception. Any
exceptions that do occur are logged at Level.FINER
.
rs
- The result set to close.public void closeSafe(Statement st)
This method closed the statement"safely" in that it never throws an exception. Any
exceptions that do occur are logged at Level.FINER
.
st
- The statement to close.public void closeSafe(Connection cx)
This method closed the connection "safely" in that it never throws an exception. Any
exceptions that do occur are logged at Level.FINER
.
cx
- The connection to close.protected void finalize() throws Throwable
public void dispose()
DataAccess
A DataStore
cannot be used after dispose
has been called,
neither can any data access object it helped create, such as FeatureReader
, FeatureSource
or FeatureCollection
.
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.
dispose
in interface DataAccess<SimpleFeatureType,SimpleFeature>
dispose
in class ContentDataStore
protected boolean isGeneralizationRequired(Hints hints, GeometryDescriptor gatt)
hints
- hints hints passed ingatt
- Geometry attribute descriptorprotected boolean isSimplificationRequired(Hints hints, GeometryDescriptor gatt)
hints
- hints hints passed ingatt
- Geometry attribute descriptorprotected boolean isGeometryReduceRequired(Hints hints, GeometryDescriptor gatt, Hints.Key param)
hints
- hints passed ingatt
- Geometry attribute descriptorparam
- Hints.GEOMETRY_GENERALIZATION
or Hints.GEOMETRY_SIMPLIFICATION
public void encodeGeometryColumn(GeometryDescriptor gatt, StringBuffer sql, Hints hints)
SQLDialect.addSupportedHints(Set)
gatt
- sql
- hints
- , may be nullprotected void encodeGeometryColumn(GeometryDescriptor gatt, String prefix, StringBuffer sql, Hints hints)
public Transaction buildTransaction(Connection cx)
JDBCDataStore
.
Calls to Transaction.commit()
, Transaction.rollback()
and Transaction.close()
will not result in corresponding calls to the provided Connection
object.
conn
- The externally managed connectionpublic void createIndex(Index index) throws IOException
index
- IOException
public void dropIndex(String typeName, String indexName) throws IOException
index
- IOException
public List<Index> getIndexes(String typeName) throws IOException
typeName
- Name of the type for which indexes are searched. It's mandatoryIOException
public String escapeNamePattern(DatabaseMetaData metaData, String name) throws SQLException
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.
SQLException
Copyright © 1996–2019 Geotools. All rights reserved.