Class DBMSHandlerMSSQL

java.lang.Object
org.apache.empire.dbms.DBMSHandlerBase
org.apache.empire.dbms.sqlserver.DBMSHandlerMSSQL
All Implemented Interfaces:
DBMSHandler

public class DBMSHandlerMSSQL extends DBMSHandlerBase
This class provides support for the Microsoft SQL-Server database system.
  • Field Details

    • MSSQL_SQL_KEYWORDS

      protected static final String[] MSSQL_SQL_KEYWORDS
    • ddlGenerator

      protected DBDDLGenerator<?> ddlGenerator
  • Constructor Details

    • DBMSHandlerMSSQL

      public DBMSHandlerMSSQL()
      Constructor for the MSSQL database dbms.
  • Method Details

    • getDatabaseName

      public String getDatabaseName()
    • setDatabaseName

      public void setDatabaseName(String databaseName)
    • getObjectOwner

      public String getObjectOwner()
    • setObjectOwner

      public void setObjectOwner(String objectOwner)
    • 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

      public String getSequenceTableName()
      returns the name of the sequence table
      Returns:
      the name of the table used for sequence number generation
    • setSequenceTableName

      public void setSequenceTableName(String sequenceTableName)
      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

      public boolean checkExists(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 table
      Specified by:
      checkExists in interface DBMSHandler
      Overrides:
      checkExists in class DBMSHandlerBase
      Parameters:
      db - the database
      conn - the Jdbc connection
      Returns:
      true if the database exists or false otherwise
    • attachDatabase

      public void attachDatabase(DBDatabase db, Connection conn)
      Called when a database is opened
      Specified by:
      attachDatabase in interface DBMSHandler
      Overrides:
      attachDatabase in class DBMSHandlerBase
      Parameters:
      db - the database
      conn - the Jdbc connection
    • createCommand

      public DBCommand createCommand(boolean autoPrepareStmt)
      Creates a new Microsoft SQL-Server command object.
      Specified by:
      createCommand in interface DBMSHandler
      Overrides:
      createCommand in class DBMSHandlerBase
      Parameters:
      autoPrepareStmt - flag whether to automatically provide literal values as prepared statement params
      Returns:
      the new DBCommand object
    • createSQLBuilder

      public DBSQLBuilder createSQLBuilder()
      Creates a new Microsoft SQL-Server SQL-Builder.
      Specified by:
      createSQLBuilder in interface DBMSHandler
      Overrides:
      createSQLBuilder in class DBMSHandlerBase
      Returns:
      the new DBSQLBuilder object
    • isSupported

      public boolean isSupported(DBMSFeature type)
      Returns whether or not a particular feature is supported by this dbms
      Specified by:
      isSupported in interface DBMSHandler
      Specified by:
      isSupported in class DBMSHandlerBase
      Parameters:
      type - type of requested feature. @see DBMSFeature
      Returns:
      true if the features is supported or false otherwise
    • getSQLPhrase

      public String getSQLPhrase(DBSqlPhrase phrase)
      Gets an sql phrase template for this database system.
      Parameters:
      phrase - the identifier of the phrase
      Returns:
      the phrase template
      See Also:
    • getConvertPhrase

      public String getConvertPhrase(DataType destType, DataType srcType, Object format)
      Description copied from interface: DBMSHandler
      Returns 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 type
      srcType - the source data type
      format - additional formatting information (optional)
      Returns:
      the data conversion phrase template
      See Also:
    • getNextSequenceValue

      public Object getNextSequenceValue(DBDatabase db, String seqName, int minValue, Connection conn)
      Description copied from class: DBMSHandlerBase
      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).
      Specified by:
      getNextSequenceValue in class DBMSHandlerBase
      Parameters:
      db - the database
      seqName - the name of the sequence
      minValue - the minimum value of the sequence
      conn - a valid database connection
      Returns:
      a new unique sequence value or null if an error occurred
      See Also:
    • getNextSequenceValueExpr

      public DBColumnExpr getNextSequenceValueExpr(DBTableColumn column)
      Description copied from class: DBMSHandlerBase
      Returns an expression for creating a sequence value. This is intended for the use with INSERT INTO statements where many records are affected.
      Specified by:
      getNextSequenceValueExpr in class DBMSHandlerBase
      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

      public Timestamp getUpdateTimestamp(Connection conn)
      Overridden. Returns a timestamp that is used for record updates created by the database server.
      Specified by:
      getUpdateTimestamp in interface DBMSHandler
      Overrides:
      getUpdateTimestamp in class DBMSHandlerBase
      Parameters:
      conn - the connection that might be used
      Returns:
      the current date and time of the database server.
    • getColumnAutoValue

      public Object getColumnAutoValue(DBDatabase db, DBTableColumn column, Connection conn)
      Returns an auto-generated value for a particular column
      Specified by:
      getColumnAutoValue in interface DBMSHandler
      Overrides:
      getColumnAutoValue in class DBMSHandlerBase
      Parameters:
      db - the database
      column - the column for which a value is required
      conn - 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:
      addStatementParam in class DBMSHandlerBase
      Parameters:
      pstmt - the prepared statement
      paramIndex - the parameter index
      value - the parameter value
      Throws:
      SQLException - thrown if a database access error occurs
    • getDDLScript

      public void getDDLScript(DBDDLGenerator.DDLActionType type, DBObject dbo, DBSQLScript script)
      Description copied from interface: DBMSHandler
      Appends 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

      public void appendEnableRelationStmt(DBRelation r, boolean enable, DBSQLScript script)
      Description copied from class: DBMSHandlerBase
      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.
      Specified by:
      appendEnableRelationStmt in interface DBMSHandler
      Overrides:
      appendEnableRelationStmt in class DBMSHandlerBase
      Parameters:
      r - the foreign key relation which should be enabled or disabled
      enable - true to enable the relation or false to disable
      script - the script to which to add the DDL command(s)
      See Also:
    • createModelParser

      public DBModelParser createModelParser(String catalog, String schema)
      Creates a DataModelChecker instance of this DBMSHandler
      Specified by:
      createModelParser in interface DBMSHandler
      Overrides:
      createModelParser in class DBMSHandlerBase
      Parameters:
      catalog - the database catalog
      schema - the database schema
      Returns:
    • createModelChecker

      public DBModelChecker createModelChecker(DBDatabase db)
      Description copied from class: DBMSHandlerBase
      Creates a DataModelChecker instance of this DBMSHandler
      Specified by:
      createModelChecker in interface DBMSHandler
      Overrides:
      createModelChecker in class DBMSHandlerBase
      Parameters:
      db - the database
      Returns:
      the model checker