org.apache.empire.db.mysql
Class DBDatabaseDriverMySQL

java.lang.Object
  extended by org.apache.empire.commons.ErrorObject
      extended by org.apache.empire.db.DBDatabaseDriver
          extended by org.apache.empire.db.mysql.DBDatabaseDriverMySQL
All Implemented Interfaces:
ErrorInfo

public class DBDatabaseDriverMySQL
extends DBDatabaseDriver

This class provides support for the MySQL database system.


Nested Class Summary
static class DBDatabaseDriverMySQL.DBCommandMySQL
          Defines the MySQL command type.
 
Nested classes/interfaces inherited from class org.apache.empire.db.DBDatabaseDriver
DBDatabaseDriver.DBSeqTable
 
Field Summary
 
Fields inherited from class org.apache.empire.db.DBDatabaseDriver
SQL_BOOLEAN_FALSE, SQL_BOOLEAN_TRUE, SQL_CONCAT_EXPR, SQL_CURRENT_DATE, SQL_CURRENT_DATETIME, SQL_DATABASE_LINK, SQL_DATE_PATTERN, SQL_DATE_TEMPLATE, SQL_DATETIME_PATTERN, SQL_DATETIME_TEMPLATE, SQL_FUNC_ABS, SQL_FUNC_AVG, SQL_FUNC_CEILING, SQL_FUNC_COALESCE, SQL_FUNC_DAY, SQL_FUNC_DECODE, SQL_FUNC_DECODE_ELSE, SQL_FUNC_DECODE_PART, SQL_FUNC_DECODE_SEP, SQL_FUNC_ESCAPE, SQL_FUNC_FLOOR, SQL_FUNC_LENGTH, SQL_FUNC_LOWER, SQL_FUNC_LTRIM, SQL_FUNC_MAX, SQL_FUNC_MIN, SQL_FUNC_MONTH, SQL_FUNC_REPLACE, SQL_FUNC_REVERSE, SQL_FUNC_ROUND, SQL_FUNC_RTRIM, SQL_FUNC_STRINDEX, SQL_FUNC_STRINDEXFROM, SQL_FUNC_SUBSTRING, SQL_FUNC_SUBSTRINGEX, SQL_FUNC_SUM, SQL_FUNC_TRIM, SQL_FUNC_TRUNC, SQL_FUNC_UPPER, SQL_FUNC_YEAR, SQL_NULL_VALUE, SQL_PARAMETER, SQL_QUOTES_CLOSE, SQL_QUOTES_OPEN, SQL_RENAME_COLUMN, SQL_RENAME_TABLE
 
Constructor Summary
DBDatabaseDriverMySQL()
          Constructor for the MySQL database driver.
 
Method Summary
 boolean attachDatabase(DBDatabase db, java.sql.Connection conn)
          Called when a database is opened
 DBCommand createCommand(DBDatabase db)
          Creates a new MySQL command object.
 java.lang.String getConvertPhrase(DataType destType, DataType srcType, java.lang.Object format)
          Returns a data type convertion phrase template for this driver
The returned template must contain a '?'
 java.lang.String getDatabaseName()
          returns the name for the database / schema
 boolean getDDLScript(DBCmdType type, DBObject dbo, DBSQLScript script)
          gets an SQL command for creating, modifying or deleting objects in the database (tables, columns, constraints, etc.)
 java.lang.Object getNextSequenceValue(DBDatabase db, java.lang.String seqName, int minValue, java.sql.Connection conn)
          Returns the next value of a named sequence The numbers are used for fields of type DBExpr.DT_AUTOINC.
 java.lang.Object getPostInsertAutoIncValue(DBDatabase db, java.sql.Connection conn)
          Returns the value of an AutoIncrement field for the last inserted record.
 java.lang.String getSequenceTableName()
          returns the name of the sequence table
 java.lang.String getSQLPhrase(int phrase)
          Gets an sql phrase template for this database system.
 java.sql.Timestamp getUpdateTimestamp(java.sql.Connection conn)
          Overridden.
 boolean isSupported(DBDriverFeature type)
          Returns whether or not a particular feature is supported by this driver
 boolean isUseSequenceTable()
          returns whether a sequence table is used for record identiy management.
 void setDatabaseName(java.lang.String databaseName)
          Sets the name for the database / schema
This names is required for creating a database.
 void setSequenceTableName(java.lang.String sequenceTableName)
          Sets the name of the sequence table.
 void setUseSequenceTable(boolean useSequenceTable)
          If set to true a special table is used for sequence number generation.
 
Methods inherited from class org.apache.empire.db.DBDatabaseDriver
appendElementName, appendElementName, checkDatabase, executeQuery, executeSQL, extractErrorMessage, getResultValue, getValueString, isDDLColumnDefaults, setDDLColumnDefaults
 
Methods inherited from class org.apache.empire.commons.ErrorObject
clearError, getErrorMessage, getErrorParams, getErrorSource, getErrorType, getMessage, hasError, isExceptionsEnabled, setExceptionsEnabled
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBDatabaseDriverMySQL

public DBDatabaseDriverMySQL()
Constructor for the MySQL database driver.

Method Detail

getDatabaseName

public java.lang.String getDatabaseName()
returns the name for the database / schema

Returns:
the database / schema name

setDatabaseName

public void setDatabaseName(java.lang.String databaseName)
Sets the name for the database / schema
This names is required for creating a database.
When a name is set, the driver will automatically execute 'USE dbname' when the database is opened.

Parameters:
databaseName - the name of the database

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 java.lang.String getSequenceTableName()
returns the name of the sequence table

Returns:
the name of the table used for sequence number generation

setSequenceTableName

public void setSequenceTableName(java.lang.String sequenceTableName)
Sets the name of the sequence table. Only applicable if useSequenceTable is set to true.

Parameters:
sequenceTableName - the name of the table used for sequence number generation

attachDatabase

public boolean attachDatabase(DBDatabase db,
                              java.sql.Connection conn)
Description copied from class: DBDatabaseDriver
Called when a database is opened


createCommand

public DBCommand createCommand(DBDatabase db)
Creates a new MySQL command object.

Specified by:
createCommand in class DBDatabaseDriver
Parameters:
db - the database for which to create a command object for
Returns:
the new DBCommandMySQL object

isSupported

public boolean isSupported(DBDriverFeature type)
Returns whether or not a particular feature is supported by this driver

Specified by:
isSupported in class DBDatabaseDriver
Parameters:
type - type of requrested feature. @see DBDriverFeature
Returns:
true if the features is supported or false otherwise

getSQLPhrase

public java.lang.String getSQLPhrase(int phrase)
Gets an sql phrase template for this database system.

Specified by:
getSQLPhrase in class DBDatabaseDriver
Parameters:
phrase - the identifier of the phrase
Returns:
the phrase template
See Also:
DBDatabaseDriver.getSQLPhrase(int)

getConvertPhrase

public java.lang.String getConvertPhrase(DataType destType,
                                         DataType srcType,
                                         java.lang.Object format)
Description copied from class: DBDatabaseDriver
Returns a data type convertion phrase template for this driver
The returned template must contain a '?' which will be replaced by a column expression.

Specified by:
getConvertPhrase in class DBDatabaseDriver
Parameters:
destType - the target data type
srcType - the source data type
format - additional formatting information (optional)
Returns:
the data conversion phrase template
See Also:
DBDatabaseDriver.getConvertPhrase(DataType, DataType, Object)

getNextSequenceValue

public java.lang.Object getNextSequenceValue(DBDatabase db,
                                             java.lang.String seqName,
                                             int minValue,
                                             java.sql.Connection conn)
Description copied from class: DBDatabaseDriver
Returns the next value of a named sequence The numbers are used for fields of type DBExpr.DT_AUTOINC.
If a driver supports this function it must return true for isSupported(DBDriverFeature.SEQUENCES).

Specified by:
getNextSequenceValue in class DBDatabaseDriver
Parameters:
db - the database
seqName - the name of the sequence
minValue - the minmum value of the sequence
conn - a valid database connection
Returns:
a new unique sequence value or null if an error occurred
See Also:
DBDatabaseDriver.getNextSequenceValue(DBDatabase, String, int, Connection)

getPostInsertAutoIncValue

public java.lang.Object getPostInsertAutoIncValue(DBDatabase db,
                                                  java.sql.Connection conn)
Description copied from class: DBDatabaseDriver
Returns the value of an AutoIncrement field for the last inserted record.
This function is only used for databases that do not support sequences.
Hence getNextSequenceValue() must return 'null'

Overrides:
getPostInsertAutoIncValue in class DBDatabaseDriver
Parameters:
db - the database
conn - a valid database connection
Returns:
the id of the last inserted record null if this feature is not supported

getDDLScript

public boolean getDDLScript(DBCmdType type,
                            DBObject dbo,
                            DBSQLScript script)
Description copied from class: DBDatabaseDriver
gets an SQL command for creating, modifying or deleting objects in the database (tables, columns, constraints, etc.)

Overrides:
getDDLScript in class DBDatabaseDriver
See Also:
DBDatabaseDriver.getDDLScript(DBCmdType, DBObject, DBSQLScript)

getUpdateTimestamp

public java.sql.Timestamp getUpdateTimestamp(java.sql.Connection conn)
Overridden. Returns a timestamp that is used for record updates created by the database server.

Overrides:
getUpdateTimestamp in class DBDatabaseDriver
Returns:
the current date and time of the database server.