Package org.apache.empire.dbms.sqlserver
Class DBMSHandlerMSSQL
java.lang.Object
org.apache.empire.dbms.DBMSHandlerBase
org.apache.empire.dbms.sqlserver.DBMSHandlerMSSQL
- All Implemented Interfaces:
DBMSHandler
This class provides support for the Microsoft SQL-Server database system.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classProvides a DBCommand implementation for Microsoft SQL-Serverstatic classProvides a DBSQLBuilder implementation for Microsoft SQL-ServerNested classes/interfaces inherited from class org.apache.empire.dbms.DBMSHandlerBase
DBMSHandlerBase.DBMSBuilder, DBMSHandlerBase.DBMSCommand, DBMSHandlerBase.DBSeqTableNested classes/interfaces inherited from interface org.apache.empire.dbms.DBMSHandler
DBMSHandler.DBSetGenKeys -
Field Summary
FieldsFields inherited from class org.apache.empire.dbms.DBMSHandlerBase
GENERAL_SQL_KEYWORDS, ILLEGAL_NAME_CHARS, reservedSQLKeywords, SEQUENCE_NAME_SUFFIX -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddStatementParam(PreparedStatement pstmt, int paramIndex, Object value) Adds special behaviour for Timestamp columns with are declared as DATETIMEvoidappendEnableRelationStmt(DBRelation r, boolean enable, DBSQLScript script) Appends a statement to enable or disable a foreign key relation.
The default is to drop or create the relation Override this method to provide different behavior for your database.voidattachDatabase(DBDatabase db, Connection conn) Called when a database is openedbooleancheckExists(DBDatabase db, Connection conn) checks if the database exists The default implementation performs a simple count query on the first table or view SELECT count(*) FROM tablecreateCommand(boolean autoPrepareStmt) Creates a new Microsoft SQL-Server command object.Creates a DataModelChecker instance of this DBMSHandlercreateModelParser(String catalog, String schema) Creates a DataModelChecker instance of this DBMSHandlerCreates a new Microsoft SQL-Server SQL-Builder.getColumnAutoValue(DBDatabase db, DBTableColumn column, Connection conn) Returns an auto-generated value for a particular columngetConvertPhrase(DataType destType, DataType srcType, Object format) Returns a data type convertion phrase template for this dbms
The returned template must contain a '?'voidgetDDLScript(DBDDLGenerator.DDLActionType type, DBObject dbo, DBSQLScript script) Appends the required DLL commands to create, drop or alter an object to the supplied DBDQLScript.getNextSequenceValue(DBDatabase db, String seqName, int minValue, Connection conn) Returns the next value of a named sequence The numbers are used for fields of type DBExpr.DT_AUTOINC.
If a dbms supports this function it must return true for isSupported(DBMSFeature.SEQUENCES).Returns an expression for creating a sequence value.returns the name of the sequence tablegetSQLPhrase(DBSqlPhrase phrase) Gets an sql phrase template for this database system.getUpdateTimestamp(Connection conn) Overridden.booleanisSupported(DBMSFeature type) Returns whether or not a particular feature is supported by this dbmsbooleanreturns whether the DATETIME2 datatype is used for timestamps (instead of DATETIME)booleanreturns whether a sequence table is used for record identiy management.
Default is false.booleanIndicates whether or not a Unicode Prefix (N) is prepended to all text valuesvoidsetDatabaseName(String databaseName) voidsetObjectOwner(String objectOwner) voidsetSequenceTableName(String sequenceTableName) Sets the name of the sequence table.voidsetUseDateTime2(boolean useDateTime2) Sets whether or not to use the DATETIME2 datatype instead of DATETIME for timestamps Default is true (set to false for existing databases using DATETIME!)voidsetUseSequenceTable(boolean useSequenceTable) If set to true a special table is used for sequence number generation.
Otherwise the AutoIncrement feature of MySQL is used identiy fields.voidsetUseUnicodePrefix(boolean useUnicodePrefix) Sets whether or not to use a Unicode Prefix (N) for all text values Default is trueMethods inherited from class org.apache.empire.dbms.DBMSHandlerBase
addSQLKeyword, appendObjectName, closeResultSet, closeStatement, createCombinedCommand, detachDatabase, detectQuoteName, executeBatch, executeQuery, executeSQL, extractErrorMessage, getColumnSequenceName, getIgnoreCaseExpr, getResultValue, prepareStatement, querySingleValue
-
Field Details
-
MSSQL_SQL_KEYWORDS
-
ddlGenerator
-
-
Constructor Details
-
DBMSHandlerMSSQL
public DBMSHandlerMSSQL()Constructor for the MSSQL database dbms.
-
-
Method Details
-
getDatabaseName
-
setDatabaseName
-
getObjectOwner
-
setObjectOwner
-
isUseSequenceTable
public boolean isUseSequenceTable()returns whether a sequence table is used for record identiy management.
Default is false. In this case the AutoIncrement feature of MySQL is used.- Returns:
- true if a sequence table is used instead of identity columns.
-
setUseSequenceTable
public void setUseSequenceTable(boolean useSequenceTable) If set to true a special table is used for sequence number generation.
Otherwise the AutoIncrement feature of MySQL is used identiy fields.- Parameters:
useSequenceTable- true to use a sequence table or false otherwise.
-
getSequenceTableName
returns the name of the sequence table- Returns:
- the name of the table used for sequence number generation
-
setSequenceTableName
Sets the name of the sequence table.- Parameters:
sequenceTableName- the name of the table used for sequence number generation
-
isUseUnicodePrefix
public boolean isUseUnicodePrefix()Indicates whether or not a Unicode Prefix (N) is prepended to all text values -
setUseUnicodePrefix
public void setUseUnicodePrefix(boolean useUnicodePrefix) Sets whether or not to use a Unicode Prefix (N) for all text values Default is true- Parameters:
useUnicodePrefix- true if a Unicode Prefix (N) should be used for text values
-
isUseDateTime2
public boolean isUseDateTime2()returns whether the DATETIME2 datatype is used for timestamps (instead of DATETIME) -
setUseDateTime2
public void setUseDateTime2(boolean useDateTime2) Sets whether or not to use the DATETIME2 datatype instead of DATETIME for timestamps Default is true (set to false for existing databases using DATETIME!)- Parameters:
useDateTime2- true if DATETIME2 or false if DATETIME is used
-
checkExists
checks if the database exists The default implementation performs a simple count query on the first table or view SELECT count(*) FROM table- Specified by:
checkExistsin interfaceDBMSHandler- Overrides:
checkExistsin classDBMSHandlerBase- Parameters:
db- the databaseconn- the Jdbc connection- Returns:
- true if the database exists or false otherwise
-
attachDatabase
Called when a database is opened- Specified by:
attachDatabasein interfaceDBMSHandler- Overrides:
attachDatabasein classDBMSHandlerBase- Parameters:
db- the databaseconn- the Jdbc connection
-
createCommand
Creates a new Microsoft SQL-Server command object.- Specified by:
createCommandin interfaceDBMSHandler- Overrides:
createCommandin classDBMSHandlerBase- Parameters:
autoPrepareStmt- flag whether to automatically provide literal values as prepared statement params- Returns:
- the new DBCommand object
-
createSQLBuilder
Creates a new Microsoft SQL-Server SQL-Builder.- Specified by:
createSQLBuilderin interfaceDBMSHandler- Overrides:
createSQLBuilderin classDBMSHandlerBase- Returns:
- the new DBSQLBuilder object
-
isSupported
Returns whether or not a particular feature is supported by this dbms- Specified by:
isSupportedin interfaceDBMSHandler- Specified by:
isSupportedin classDBMSHandlerBase- Parameters:
type- type of requested feature. @see DBMSFeature- Returns:
- true if the features is supported or false otherwise
-
getSQLPhrase
Gets an sql phrase template for this database system.- Parameters:
phrase- the identifier of the phrase- Returns:
- the phrase template
- See Also:
-
getConvertPhrase
Description copied from interface:DBMSHandlerReturns a data type convertion phrase template for this dbms
The returned template must contain a '?' which will be replaced by a column expression.- Parameters:
destType- the target data typesrcType- the source data typeformat- additional formatting information (optional)- Returns:
- the data conversion phrase template
- See Also:
-
getNextSequenceValue
Description copied from class:DBMSHandlerBaseReturns the next value of a named sequence The numbers are used for fields of type DBExpr.DT_AUTOINC.
If a dbms supports this function it must return true for isSupported(DBMSFeature.SEQUENCES).- Specified by:
getNextSequenceValuein classDBMSHandlerBase- Parameters:
db- the databaseseqName- the name of the sequenceminValue- the minimum value of the sequenceconn- a valid database connection- Returns:
- a new unique sequence value or null if an error occurred
- See Also:
-
getNextSequenceValueExpr
Description copied from class:DBMSHandlerBaseReturns an expression for creating a sequence value. This is intended for the use with INSERT INTO statements where many records are affected.- Specified by:
getNextSequenceValueExprin classDBMSHandlerBase- Parameters:
column- the column for which to obtain an expression providing the next sequence value- Returns:
- an expression for the next sequence value
- See Also:
-
getUpdateTimestamp
Overridden. Returns a timestamp that is used for record updates created by the database server.- Specified by:
getUpdateTimestampin interfaceDBMSHandler- Overrides:
getUpdateTimestampin classDBMSHandlerBase- Parameters:
conn- the connection that might be used- Returns:
- the current date and time of the database server.
-
getColumnAutoValue
Returns an auto-generated value for a particular column- Specified by:
getColumnAutoValuein interfaceDBMSHandler- Overrides:
getColumnAutoValuein classDBMSHandlerBase- Parameters:
db- the databasecolumn- the column for which a value is requiredconn- a valid database connection- Returns:
- the auto-generated value
-
addStatementParam
protected void addStatementParam(PreparedStatement pstmt, int paramIndex, Object value) throws SQLException Adds special behaviour for Timestamp columns with are declared as DATETIME- Overrides:
addStatementParamin classDBMSHandlerBase- Parameters:
pstmt- the prepared statementparamIndex- the parameter indexvalue- the parameter value- Throws:
SQLException- thrown if a database access error occurs
-
getDDLScript
Description copied from interface:DBMSHandlerAppends the required DLL commands to create, drop or alter an object to the supplied DBDQLScript.- Parameters:
type- operation to perform (CREATE, DROP, ALTER)dbo- the object for which to perform the operation (DBDatabase, DBTable, DBView, DBColumn, DBRelation)script- the script to which to add the DDL command(s)- See Also:
-
appendEnableRelationStmt
Description copied from class:DBMSHandlerBaseAppends a statement to enable or disable a foreign key relation.
The default is to drop or create the relation Override this method to provide different behavior for your database.- Specified by:
appendEnableRelationStmtin interfaceDBMSHandler- Overrides:
appendEnableRelationStmtin classDBMSHandlerBase- Parameters:
r- the foreign key relation which should be enabled or disabledenable- true to enable the relation or false to disablescript- the script to which to add the DDL command(s)- See Also:
-
createModelParser
Creates a DataModelChecker instance of this DBMSHandler- Specified by:
createModelParserin interfaceDBMSHandler- Overrides:
createModelParserin classDBMSHandlerBase- Parameters:
catalog- the database catalogschema- the database schema- Returns:
-
createModelChecker
Description copied from class:DBMSHandlerBaseCreates a DataModelChecker instance of this DBMSHandler- Specified by:
createModelCheckerin interfaceDBMSHandler- Overrides:
createModelCheckerin classDBMSHandlerBase- Parameters:
db- the database- Returns:
- the model checker
-