Package ru.curs.celesta.dbutils.adaptors
Class DBAdaptor
java.lang.Object
ru.curs.celesta.dbutils.adaptors.DBAdaptor
- All Implemented Interfaces:
StaticDataAdaptor,QueryBuildingHelper
- Direct Known Subclasses:
FirebirdAdaptor,MSSQLAdaptor,OpenSourceDbAdaptor,OraAdaptor
Adaptor for connection to the database.
-
Method Summary
Modifier and TypeMethodDescriptionvoidalterSequence(Connection conn, SequenceElement s) Alters sequence in the database.intcompareStrings(String left, String right) Compare strings using database according to current collation rules.final voidcreateColumn(Connection conn, Column<?> c) Adds a new column to the table.final voidcreateFK(Connection conn, ForeignKey fk) Creates a foreign key in the DB.final voidcreateIndex(Connection conn, Index index) Creates a table index in the DB.final voidfinal voidcreatePK(Connection conn, TableElement t) Creates primary key on a table.final voidCreates DB schema with the specified name if such didn't exist before.voidcreateSequence(Connection conn, SequenceElement s) Creates a sequence in the database.voidcreateSysObjects(Connection conn, String sysSchemaName) Creates or recreates other system objects (stored procedures, functions) needed for Celesta functioning on current RDBMS.voidcreateTable(Connection conn, TableElement te) Creates a table "from scratch" in the database.final voidfinal voidcreateView(Connection conn, View v) Creates a view in the DB based on metadata.abstract PreparedStatementdeleteRecordSetStatement(Connection conn, TableElement t, String where) Creates a PreparedStatement object for a DELETE statement for deleting a set of records that satisfy a condition.voiddropFK(Connection conn, String schemaName, String tableName, String fkName) Drops a foreign key from the database.final voiddropIndex(Grain g, DbIndexInfo dBIndexInfo) Removes table index in the grain.voiddropParameterizedView(Connection conn, String schemaName, String viewName) Drops parameterized view from the database.voiddropPk(Connection conn, TableElement t, String pkName) Drops primary key from the table by using known name of the primary key.voiddropSequence(Connection conn, SequenceElement s) Drops sequence from the database.final voiddropTable(Connection conn, TableElement t) Deletes table from RDBMS.final voidfinal voiddropTrigger(Connection conn, TriggerQuery query) Drops a trigger from DB.voiddropView(Connection conn, String schemaName, String viewName) Drops view.final voidexecuteNative(Connection conn, String sql) Prepares a function call expression.abstract DbColumnInfogetColumnInfo(Connection conn, Column<?> c) Returns information on a column.getColumns(Connection conn, TableElement t) Returns a set of column names for a specific table.abstract intgetCurrentIdent(Connection conn, BasicTable t) Returns current identity value for the table.abstract intgetDBPid(Connection conn) Returns process id of current database connection.abstract PreparedStatementgetDeleteRecordStatement(Connection conn, TableElement t, String where) Creates a PreparedStatement object for a DELETE statement for deleting a set of records that satisfy a condition.getFKInfo(Connection conn, Grain g) Returns information on the foreign keys from grain.abstract Map<String, DbIndexInfo> getIndices(Connection conn, Grain g) Returns a set of indices referring to tables specified in the indicated grain.abstract PreparedStatementgetInsertRecordStatement(Connection conn, BasicTable t, boolean[] nullsMask, List<ParameterSetter> program) Creates a PreparedStatement object for an INSERT statement to insert a record into a table.abstract PreparedStatementgetNavigationStatement(Connection conn, FromClause from, String orderBy, String navigationWhereClause, Set<String> fields, long offset) Returns navigable PreparedStatement by a filtered set of records.abstract PreparedStatementgetOneFieldStatement(Connection conn, Column<?> c, String where) Creates a PreparedStatement object for a SELECT statement of a single column containing at most one record.abstract PreparedStatementgetOneRecordStatement(Connection conn, TableElement t, String where, Set<String> fields) Creates a PreparedStatement object for a SELECT statement containing at most one record.getParameterizedViewList(Connection conn, Grain g) Get names of existing parameterized views.abstract DbPkInfogetPKInfo(Connection conn, TableElement t) Returns information on the primary key of a table.final PreparedStatementgetRecordSetStatement(Connection conn, FromClause from, String whereClause, String orderBy, long offset, long rowCount, Set<String> fields) ReturnsPreparedStatementcontaining a filtered set of entries.abstract DbSequenceInfogetSequenceInfo(Connection conn, SequenceElement s) Returns information on a sequence.final PreparedStatementgetSetCountStatement(Connection conn, FromClause from, String whereClause) Builds a SELECT COUNT statement.getTriggerBody(Connection conn, TriggerQuery query) Returns body of the trigger existing in the database.abstract DBTypegetType()Returns current database type.final PreparedStatementgetUpdateRecordStatement(Connection conn, BasicTable t, boolean[] equalsMask, boolean[] nullsMask, List<ParameterSetter> program, String where) Builds prepared statement for records UPDATE.
equalsMask[columnIndex]should containtruefor the column with index equal tocolumnIndexto take part in the evaluation.
IfnullsMask[columnIndex]containstrueIS NULLcheck has a priority aboveprogram[columnIndex]check -column = ?.getViewList(Connection conn, Grain g) Returns list of view names in the grain.final SQLGeneratorReturns SQL generator for Celesta views/complex filters.voidInitializes data for a newly crated materialized view.booleanisValidConnection(Connection conn, int timeout) Checking for connection validity.abstract longnextSequenceValue(Connection conn, SequenceElement s) Retrieves next value from the sequence.pkConstraintString(TableElement tableElement) Returns DB specific PK constraint name for a table element.selectStaticStrings(List<String> data, String columnName, String orderByDirection) Returned strings ordered by the database according to the current collation.abstract booleansequenceExists(Connection conn, String schema, String name) Checks if sequence exists in the DB.sequenceString(String schemaName, String sequenceName) Returns template by sequence name.booleanWhether DB supports cortege comparing.abstract booleantableExists(Connection conn, String schema, String name) Checks if table exists in the DB.tableString(String schemaName, String tableName) Returns template by table name.translateDate(String date) Translates Celesta date literal to the one from specific database.abstract booleantriggerExists(Connection conn, TriggerQuery query) Checks if trigger exists in the DB.voidupdateColumn(Connection conn, Column<?> c, DbColumnInfo actual) Updates a table column.final voidfinal booleanReturnstruein that and only that case if DB contains user tables (i.e.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ru.curs.celesta.dbutils.QueryBuildingHelper
getInFilterClause, nullsFirst
-
Method Details
-
dropTable
Deletes table from RDBMS.- Parameters:
conn- Connection to use.t- TableElement metadata of deleting table provided by Celesta.
-
userTablesExist
public final boolean userTablesExist()Returnstruein that and only that case if DB contains user tables (i.e. DB is not empty). -
createSchemaIfNotExists
Creates DB schema with the specified name if such didn't exist before.- Parameters:
name- schema name.
-
createColumn
Adds a new column to the table.- Parameters:
conn- DB connectionc- column
-
getUpdateRecordStatement
public final PreparedStatement getUpdateRecordStatement(Connection conn, BasicTable t, boolean[] equalsMask, boolean[] nullsMask, List<ParameterSetter> program, String where) Builds prepared statement for records UPDATE.
equalsMask[columnIndex]should containtruefor the column with index equal tocolumnIndexto take part in the evaluation.
IfnullsMask[columnIndex]containstrueIS NULLcheck has a priority aboveprogram[columnIndex]check -column = ?.- Parameters:
conn- DB connectiont- updatable tableequalsMask- equals masknullsMask- nulls maskprogram- collects parameter predicateswhere- WHERE clause
-
createIndex
Creates a table index in the DB.- Parameters:
conn- DB connectionindex- table index
-
createFK
Creates a foreign key in the DB.- Parameters:
conn- DB connectionfk- foreign key
-
dropIndex
Removes table index in the grain.- Parameters:
g- GraindBIndexInfo- Information on index
-
getRecordSetStatement
public final PreparedStatement getRecordSetStatement(Connection conn, FromClause from, String whereClause, String orderBy, long offset, long rowCount, Set<String> fields) ReturnsPreparedStatementcontaining a filtered set of entries.- Parameters:
conn- Connectionfrom- Object for forming FROM part of the querywhereClause- Where clauseorderBy- Sort orderoffset- Number of entries to skiprowCount- Number of entries to return (limit filter)fields- Requested columns. If none are provided all columns are requested
-
getSetCountStatement
public final PreparedStatement getSetCountStatement(Connection conn, FromClause from, String whereClause) Builds a SELECT COUNT statement.- Parameters:
conn- Connectionfrom- From clausewhereClause- Where clause
-
dropTrigger
Drops a trigger from DB.- Parameters:
conn- Connectionquery- Trigger query
-
updateVersioningTrigger
-
createPK
Creates primary key on a table.- Parameters:
conn- DB connectiont- table
-
getViewSQLGenerator
Description copied from interface:QueryBuildingHelperReturns SQL generator for Celesta views/complex filters.- Specified by:
getViewSQLGeneratorin interfaceQueryBuildingHelper
-
createView
Creates a view in the DB based on metadata.- Parameters:
conn- DB connectionv- View
-
createParameterizedView
-
dropTableTriggersForMaterializedViews
-
createTableTriggersForMaterializedViews
-
executeNative
-
isValidConnection
Checking for connection validity.- Parameters:
conn- connectiontimeout- time-out- Returns:
trueif connection is valid, otherwisefalse
-
tableString
Returns template by table name.- Parameters:
schemaName- schema nametableName- table name
-
sequenceString
Returns template by sequence name.- Parameters:
schemaName- schema namesequenceName- sequence name
-
pkConstraintString
Returns DB specific PK constraint name for a table element.- Parameters:
tableElement- table element
-
createTable
Creates a table "from scratch" in the database.- Parameters:
conn- Connectionte- Table for creation. tables also in case if such table exists.
-
getColumns
Returns a set of column names for a specific table.- Parameters:
conn- DB connectiont- Table to look the columns in.
-
dropFK
Drops a foreign key from the database.- Parameters:
conn- DB connectionschemaName- schema nametableName- table possessing the foreign keyfkName- name of foreign key
-
dropParameterizedView
Drops parameterized view from the database.- Parameters:
conn- DB connectionschemaName- schema nameviewName- view name
-
getViewList
Returns list of view names in the grain.- Parameters:
conn- DB connectiong- Grain for which the list of view names have to be returned.
-
getCallFunctionSql
Prepares a function call expression.- Parameters:
pv- current parameterized view
-
createSequence
Creates a sequence in the database.- Parameters:
conn- DB connections- sequence element
-
alterSequence
Alters sequence in the database.- Parameters:
conn- DB connections- sequence element
-
dropSequence
Drops sequence from the database.- Parameters:
conn- DB connections- sequence element
-
dropView
Drops view.- Parameters:
conn- DB connectionschemaName- grain nameviewName- view name
-
createSysObjects
Creates or recreates other system objects (stored procedures, functions) needed for Celesta functioning on current RDBMS.- Parameters:
conn- DB connectionsysSchemaName- system schema name
-
translateDate
Translates Celesta date literal to the one from specific database.- Specified by:
translateDatein interfaceQueryBuildingHelper- Parameters:
date- Date literal
-
getTriggerBody
Returns body of the trigger existing in the database.- Parameters:
conn- Connectionquery- Trigger query- Returns:
- Trigger body or empty optional if not exists.
-
initDataForMaterializedView
Initializes data for a newly crated materialized view.- Parameters:
conn- connectionmv- current materialized view
-
selectStaticStrings
public List<String> selectStaticStrings(List<String> data, String columnName, String orderByDirection) Returned strings ordered by the database according to the current collation. This method is required for operations that depend on collation rules.- Specified by:
selectStaticStringsin interfaceStaticDataAdaptor- Parameters:
data- List of String to selectcolumnName- name of result columnorderByDirection- expression to concatenate after "ORDER BY" (ASC or DESC)- Returns:
- list of strings sorted according to the current collation rule.
-
compareStrings
Compare strings using database according to current collation rules.- Specified by:
compareStringsin interfaceStaticDataAdaptor- Parameters:
left- left stringright- right string- Returns:
- result of comparison
-
supportsCortegeComparing
public boolean supportsCortegeComparing()Whether DB supports cortege comparing.- Specified by:
supportsCortegeComparingin interfaceQueryBuildingHelper- Returns:
-
dropPk
Drops primary key from the table by using known name of the primary key.- Parameters:
conn- DB connectiont- TablepkName- name of the primary key
-
updateColumn
Updates a table column.- Parameters:
conn- DB connectionc- Column to updateactual- Actual column info
-
prepareZonedDateTimeForParameterSetter
- Specified by:
prepareZonedDateTimeForParameterSetterin interfaceQueryBuildingHelper
-
tableExists
Checks if table exists in the DB.- Parameters:
conn- DB connectionschema- schema namename- table name
-
triggerExists
Checks if trigger exists in the DB.- Parameters:
conn- DB connection.query- trigger query parameters- Throws:
SQLException- thrown if resulting query fails
-
getOneRecordStatement
public abstract PreparedStatement getOneRecordStatement(Connection conn, TableElement t, String where, Set<String> fields) Creates a PreparedStatement object for a SELECT statement containing at most one record.- Parameters:
conn- DB connectiont- tablewhere- WHERE conditionfields- fields of selection
-
getOneFieldStatement
Creates a PreparedStatement object for a SELECT statement of a single column containing at most one record.- Parameters:
conn- DB connectionc- column to selectwhere- WHERE condition
-
deleteRecordSetStatement
public abstract PreparedStatement deleteRecordSetStatement(Connection conn, TableElement t, String where) Creates a PreparedStatement object for a DELETE statement for deleting a set of records that satisfy a condition.- Parameters:
conn- DB connectiont- tablewhere- condition
-
getInsertRecordStatement
public abstract PreparedStatement getInsertRecordStatement(Connection conn, BasicTable t, boolean[] nullsMask, List<ParameterSetter> program) Creates a PreparedStatement object for an INSERT statement to insert a record into a table.- Parameters:
conn- DB connectiont- tablenullsMask- null-flags (if set the corresponding field at n-th position becomesnull)program- collects parameters that can be set with the query
-
getCurrentIdent
Returns current identity value for the table.- Parameters:
conn- DB connectiont- table
-
getDeleteRecordStatement
public abstract PreparedStatement getDeleteRecordStatement(Connection conn, TableElement t, String where) Creates a PreparedStatement object for a DELETE statement for deleting a set of records that satisfy a condition.- Parameters:
conn- DB connectiont- tablewhere- condition (can benull)
-
getColumnInfo
Returns information on a column.- Parameters:
conn- DB connectionc- column
-
getPKInfo
Returns information on the primary key of a table.- Parameters:
conn- DB connectiont- Table that the information on the primary key has to be returned from
-
getFKInfo
Returns information on the foreign keys from grain.- Parameters:
conn- DB connectiong- grain name- Returns:
- list where each item contain information on a separate foreign key
-
getIndices
Returns a set of indices referring to tables specified in the indicated grain.- Parameters:
conn- DB connectiong- Grain the tables of which have to be traversed for the indices.
-
getParameterizedViewList
Get names of existing parameterized views.- Parameters:
conn- connectiong- current grain
-
getDBPid
Returns process id of current database connection.- Parameters:
conn- DB connection
-
getType
Returns current database type. E.g. H2, POSTGRESQL etc. -
nextSequenceValue
Retrieves next value from the sequence.- Parameters:
conn- DB connections- sequence
-
sequenceExists
Checks if sequence exists in the DB.- Parameters:
conn- DB connectionschema- schema namename- sequence name
-
getSequenceInfo
Returns information on a sequence.- Parameters:
conn- DB connections- sequence
-