Class PreparedStatementSQLDialect
- Object
-
- SQLDialect
-
- PreparedStatementSQLDialect
-
- Direct Known Subclasses:
DB2SQLDialectPrepared
,GeoPkgDialect
,H2DialectPrepared
,H2GISPSDialect
,HanaDialect
,MySQLDialectPrepared
,OracleDialect
,PostGISPSDialect
,TeradataDialect
public abstract class PreparedStatementSQLDialect extends SQLDialect
SQL dialect which uses prepared statements for database interaction.- Author:
- Justin Deoliveira, OpenGEO
-
-
Field Summary
-
Fields inherited from class SQLDialect
BASE_DBMS_CAPABILITIES, dataStore, forceLongitudeFirst, LOGGER, UNWRAPPER_NOT_FOUND, uwMap
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
PreparedStatementSQLDialect(JDBCDataStore dataStore)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected <T> T
convert(Object value, Class<T> binding)
protected Object
convertArrayElement(Object value, Class<?> target)
Converts a given array element to the desired type, throws an exception in case conversion failedprotected Array
convertToArray(Object value, String componentTypeName, Class componentType, Connection connection)
Converts a given array value into aArray
PreparedFilterToSQL
createPreparedFilterToSQL()
protected String
getArrayComponentTypeName(AttributeDescriptor att)
Given the full information about the attribute being transformed, figure out the native SQL Type Name to use when creating a SQL Array object· The default implementation just scansJDBCDataStore.getSqlTypeNameToClassMappings()
backwards, and will fail in case there are ambiguities.void
onDelete(PreparedStatement delete, Connection cx, SimpleFeatureType featureType)
Callback invoked before a DELETE statement is executed against the database.void
onInsert(PreparedStatement insert, Connection cx, SimpleFeatureType featureType)
Callback invoked before an INSERT statement is executed against the database.void
onSelect(PreparedStatement select, Connection cx, SimpleFeatureType featureType)
Callback invoked before a SELECT statement is executed against the database.void
onUpdate(PreparedStatement update, Connection cx, SimpleFeatureType featureType)
Callback invoked before an UPDATE statement is executed against the database.void
prepareFunctionArgument(Class clazz, StringBuffer sql)
Prepares a function argument for a prepared statement.void
prepareGeometryValue(Class<? extends Geometry> gClass, int dimension, int srid, Class binding, StringBuffer sql)
Prepares the geometry value for a prepared statement.void
prepareGeometryValue(Geometry g, int dimension, int srid, Class binding, StringBuffer sql)
Prepares the geometry value for a prepared statement.void
setArrayValue(Object value, AttributeDescriptor att, PreparedStatement ps, int i, Connection cx)
Sets a value in a prepared statement, for the specific case ofArray
abstract void
setGeometryValue(Geometry g, int dimension, int srid, Class binding, PreparedStatement ps, int column)
Sets the geometry value into the prepared statement.void
setValue(Object value, Class binding, PreparedStatement ps, int column, Connection cx)
Sets a value in a prepared statement, for "basic types" (non-geometry).-
Methods inherited from class SQLDialect
addSupportedHints, applyHintsOnVirtualTables, applyLimitOffset, canGroupOnGeometry, canSimplifyPoints, convertValue, createCRS, createIndex, decodeGeometryEnvelope, decodeGeometryValue, decodeGeometryValue, dropIndex, encodeColumnAlias, encodeColumnName, encodeColumnType, encodeCreateTable, encodeGeometryColumn, encodeGeometryColumnGeneralized, encodeGeometryColumnSimplified, encodeGeometryEnvelope, encodeJoin, encodeNextSequenceValue, encodePostColumnCreateTable, encodePostCreateTable, encodePostSelect, encodePrimaryKey, encodeSchemaName, encodeTableAlias, encodeTableName, escapeName, getAggregateConverter, getDefaultVarcharSize, getDesiredTablesType, getGeometryDimension, getGeometrySRID, getGeometryTypeName, getIndexes, getLastAutoGeneratedValue, getLastAutoGeneratedValue, getMapping, getMapping, getNameEscape, getNextAutoGeneratedValue, getNextSequenceValue, getOptimizedBounds, getPkColumnValue, getPrimaryKey, getRestrictions, getResultTypes, getSequenceForColumn, getSQLType, handleSelectHints, handleUserDefinedType, includeTable, initializeConnection, isAggregatedSortSupported, isArray, isAutoCommitQuery, isGroupBySupported, isLimitOffsetSupported, lookupGeneratedValuesPostInsert, ne, postCreateAttribute, postCreateFeatureType, postCreateTable, postDropTable, preDropTable, registerAggregateFunctions, registerClassToSqlMappings, registerSqlTypeNameToClassMappings, registerSqlTypeToClassMappings, registerSqlTypeToSqlTypeNameOverrides, splitFilter, supportsSchemaForIndex, unwrapConnection
-
-
-
-
Constructor Detail
-
PreparedStatementSQLDialect
protected PreparedStatementSQLDialect(JDBCDataStore dataStore)
-
-
Method Detail
-
prepareGeometryValue
public void prepareGeometryValue(Class<? extends Geometry> gClass, int dimension, int srid, Class binding, StringBuffer sql)
Prepares the geometry value for a prepared statement.This method should be overridden if the implementation needs to wrap the geometry placeholder in the function. The default implementationg just appends the default placeholder: '?'.
- Parameters:
gClass
- The geometry class.srid
- The spatial reference system of the geometry, or -1 if unknowndimension
- The dimensions (2,3,4) of the coordinates, or -1 if unknownbinding
- The class of the geometry.sql
- The prepared sql statement buffer.
-
prepareGeometryValue
public final void prepareGeometryValue(Geometry g, int dimension, int srid, Class binding, StringBuffer sql)
Prepares the geometry value for a prepared statement.This method should be overridden if the implementation needs to wrap the geometry placeholder in the function. The default implementationg just appends the default placeholder: '?'.
- Parameters:
g
- The geometry value.srid
- The spatial reference system of the geometry, or -1 if unknowndimension
- The dimensions (2,3,4) of the coordinates, or -1 if unknownbinding
- The class of the geometry.sql
- The prepared sql statement buffer.
-
prepareFunctionArgument
public void prepareFunctionArgument(Class clazz, StringBuffer sql)
Prepares a function argument for a prepared statement.- Parameters:
clazz
- The mapped class of the argument.sql
- The prepared sql statement buffer
-
setGeometryValue
public abstract void setGeometryValue(Geometry g, int dimension, int srid, Class binding, PreparedStatement ps, int column) throws SQLException
Sets the geometry value into the prepared statement.- Parameters:
g
- The geometrysrid
- the geometry native srid (should be forced into the encoded geometry)binding
- the geometry typeps
- the prepared statementcolumn
- the column index where the geometry is to be set- Throws:
SQLException
-
setValue
public void setValue(Object value, Class binding, PreparedStatement ps, int column, Connection cx) throws SQLException
Sets a value in a prepared statement, for "basic types" (non-geometry).Subclasses should override this method if they need to do something custom or they wish to support non-standard types.
- Parameters:
value
- the value.binding
- The class of the value.ps
- The prepared statement.column
- The column the value maps to.cx
- The database connection.- Throws:
SQLException
-
setArrayValue
public void setArrayValue(Object value, AttributeDescriptor att, PreparedStatement ps, int i, Connection cx) throws SQLException
Sets a value in a prepared statement, for the specific case ofArray
This method uses the standard SQL Array handling, subclasses can override to add special behavior
- Parameters:
value
- the value.att
- The full attribute descriptionps
- The prepared statement.i
- The column the value maps to.cx
- The database connection.- Throws:
SQLException
-
getArrayComponentTypeName
protected String getArrayComponentTypeName(AttributeDescriptor att) throws SQLException
Given the full information about the attribute being transformed, figure out the native SQL Type Name to use when creating a SQL Array object· The default implementation just scansJDBCDataStore.getSqlTypeNameToClassMappings()
backwards, and will fail in case there are ambiguities. Subclasses can implement their own logic and eventually use information contained in the attribute'sPropertyDescriptor.getUserData()
, stored at attribute creation time.- Throws:
SQLException
-
convertToArray
protected Array convertToArray(Object value, String componentTypeName, Class componentType, Connection connection) throws SQLException
Converts a given array value into aArray
- Parameters:
value
- The non null value to be convertedcomponentType
- The attribute binding (of array type)connection
- The connection used to create anArray
- Returns:
- The converted array
- Throws:
SQLException
-
convertArrayElement
protected Object convertArrayElement(Object value, Class<?> target) throws SQLException
Converts a given array element to the desired type, throws an exception in case conversion failed- Parameters:
value
- The value to be converted. Must be non null.target
- The target class- Returns:
- The converted value
- Throws:
SQLException
- In case the conversion failed.
-
createPreparedFilterToSQL
public PreparedFilterToSQL createPreparedFilterToSQL()
-
onSelect
public void onSelect(PreparedStatement select, Connection cx, SimpleFeatureType featureType) throws SQLException
Callback invoked before a SELECT statement is executed against the database.The callback is provided with both the statement being executed and the database connection. Neither should be closed. Any statements created from the connection however in this method should be closed.
- Parameters:
select
- The select statement being executedcx
- The database connectionfeatureType
- The feature type the select is executing against.- Throws:
SQLException
-
onDelete
public void onDelete(PreparedStatement delete, Connection cx, SimpleFeatureType featureType) throws SQLException
Callback invoked before a DELETE statement is executed against the database.The callback is provided with both the statement being executed and the database connection. Neither should be closed. Any statements created from the connection however in this method should be closed.
- Parameters:
delete
- The delete statement being executedcx
- The database connectionfeatureType
- The feature type the delete is executing against.- Throws:
SQLException
-
onInsert
public void onInsert(PreparedStatement insert, Connection cx, SimpleFeatureType featureType) throws SQLException
Callback invoked before an INSERT statement is executed against the database.The callback is provided with both the statement being executed and the database connection. Neither should be closed. Any statements created from the connection however in this method should be closed.
- Parameters:
insert
- The delete statement being executedcx
- The database connectionfeatureType
- The feature type the insert is executing against.- Throws:
SQLException
-
onUpdate
public void onUpdate(PreparedStatement update, Connection cx, SimpleFeatureType featureType) throws SQLException
Callback invoked before an UPDATE statement is executed against the database.The callback is provided with both the statement being executed and the database connection. Neither should be closed. Any statements created from the connection however in this method should be closed.
- Parameters:
update
- The delete statement being executedcx
- The database connectionfeatureType
- The feature type the update is executing against.- Throws:
SQLException
-
-