com.sibvisions.rad.persist.jdbc
Class MySQLDBAccess

java.lang.Object
  extended by com.sibvisions.rad.persist.jdbc.DBAccess
      extended by com.sibvisions.rad.persist.jdbc.MySQLDBAccess
All Implemented Interfaces:
IDBAccess, ICloseable

public class MySQLDBAccess
extends DBAccess

The MySQLDBAccess is the implementation for MySQL databases.

See Also:
DBAccess

Nested Class Summary
 
Nested classes/interfaces inherited from class com.sibvisions.rad.persist.jdbc.DBAccess
DBAccess.BlobFileHandle, DBAccess.ParameterizedStatement
 
Field Summary
static int TYPE_ENUM
          the enum datatype.
static int TYPE_SET
          the set datatype.
 
Fields inherited from class com.sibvisions.rad.persist.jdbc.DBAccess
BFILE, LONGNVARCHAR, NCHAR, NCLOB, NVARCHAR, QUOTE, SQLXML, TIMESTAMPWITHLOCALTIMEZONE, TIMESTAMPWITHTIMEZONE
 
Constructor Summary
MySQLDBAccess()
          Constructs a new MySQLDBAccess Object.
 
Method Summary
protected  int calculateAdditionalFetchRowCount(int pFetchedRowCount, long pFetchTimeInMilliSeconds)
          Calculates the amount of rows to fetch additionally to an already happened fetch.
protected  java.lang.String[] extractValues(java.lang.String pTypeDefinition)
          Extracts the values from a valuelist, separated with ,.
 java.util.List<java.lang.Object[]> fetch(ServerMetaData pServerMetaData, java.lang.String pBeforeQueryColumns, java.lang.String[] pQueryColumns, java.lang.String pFromClause, ICondition pFilter, java.lang.String pWhereCondition, java.lang.String pAfterWhereClause, SortDefinition pSort, java.lang.String pOrderByClause, int pFromRow, int pMinimumRowCount, boolean pAllowLazyFetch)
          Mostly same as DBAccess.fetch(ServerMetaData, String, String[], String, ICondition, String, String, SortDefinition, int, int).
protected  java.util.Hashtable<java.lang.String,com.sibvisions.rad.persist.jdbc.MySQLDBAccess.ColumnInfo> getColumnInfo(java.lang.String pTableName)
          Get detailed column information for the given table.
protected  ServerColumnMetaData[] getColumnMetaDataIntern(java.lang.String pFromClause, java.lang.String[] pQueryColumns, java.lang.String pBeforeQueryColumns, java.lang.String pWhereClause, java.lang.String pAfterWhereClause)
          Returns the meta data information for the specified query, and configures all columns with defaults.
static int getDefaultMaximumAdditionalFetchAmount()
          Gets the default maximum amount of additional rows to fetch.
protected  java.util.Map<java.lang.String,java.lang.Object> getDefaultValuesIntern(java.lang.String pCatalog, java.lang.String pSchema, java.lang.String pTable)
          Gets all default column values of a specific table.
protected  int getDiscardRowCount(int pFromRow, int pMinimumRowCount)
          Gets how many rows should be discarded based on the given values.
protected  java.util.List<ForeignKey> getForeignKeysIntern(java.lang.String pCatalog, java.lang.String pSchema, java.lang.String pTable)
          Returns all Foreign Keys for the specified table.
 int getMaximumAdditionalFetchAmount()
          Gets the maximum amount of additional rows to fetch.
 DBAccess.ParameterizedStatement getParameterizedSelectStatement(ServerMetaData pServerMetaData, java.lang.String pBeforeQueryColumns, java.lang.String[] pQueryColumns, java.lang.String pFromClause, ICondition pFilter, java.lang.String pWhereClause, java.lang.String pAfterWhereClause, SortDefinition pSort, java.lang.String pOrderByClause, int pFromRow, int pMinimumRowCount)
          Creates the DBAccess.ParameterizedStatement and returns it.
protected  Key getPrimaryKeyIntern(java.lang.String pCatalog, java.lang.String pSchema, java.lang.String pTable)
          It's gets all Primary Key columns and return it as String[].
protected  TableInfo getTableInfoIntern(java.lang.String pWriteBackTable)
          Returns the meta data information for the specified query, and configures all columns with defaults.
protected  java.util.List<Key> getUniqueKeysIntern(java.lang.String pCatalog, java.lang.String pSchema, java.lang.String pTable)
          It gets all columns for each Unique Key and return it.
 boolean isAutoQuote(java.lang.String pName)
          It returns true if this name should be automated quoted.
 void open()
          It opens the database and stores the Connection object.
static void setDefaultMaximumAdditionalFetchAmount(int pDefaultMaximumAdditionalFetchAmount)
          Sets the default maximum amount of additional rows to fetch.
 void setMaximumAdditionalFetchAmount(int pMaximumAdditionalFetchAmount)
          Sets the maximum amount of additional rows to fetch.
 void setUsername(java.lang.String pUsername)
          Sets the user name to connect with.
 
Methods inherited from class com.sibvisions.rad.persist.jdbc.DBAccess
clearMetaData, clearMetaData, close, commit, commitOrRollbackBeforeClose, convertDatabaseSpecificObjectToValue, convertValueToDatabaseSpecificObject, createIdentifier, createReplace, createServerColumnMetaData, createWhereColumn, createWhereParam, debug, delete, detectModified, error, eventConfigureConnection, eventUnconfigureConnection, executeFunction, executeFunction, executeProcedure, executeQuery, executeSql, executeSqlMulti, executeStatement, fetch, fetch, fetch, findAndCreateReducedCondition, findNamedParameters, fireEventConfigureConnection, fireEventUnconfigureConnection, formatSQLException, formatSQLException, getAllowedValues, getAllowedValuesIntern, getAutomaticLinkColumnNameTranslation, getCloseQuoteCharacter, getColumnMetaData, getColumnMetaDataCreator, getColumnName, getConnection, getConnectionIntern, getConnectionPool, getDatabaseSpecificLockStatement, getDBAccess, getDBAccess, getDBAccess, getDBAccess, getDBAccess, getDBProperties, getDBProperty, getDefaultAllowedValues, getDefaultCursorCacheTimeout, getDefaultLargeObjectLimit, getDefaultSchema, getDefaultValues, getDriver, getForeignKeys, getIdentifier, getLargeObjectLimit, getMaxColumnLength, getMaxTime, getMetaDataCacheOption, getMetaDataWhereClause, getObjectFromResultSet, getObjectFromResultSet, getOpenQuoteCharacter, getParameter, getParameter, getPassword, getPreparedStatement, getPreparedStatement, getPrimaryKey, getQueryTimeout, getRealQueryColumnName, getSelectStatement, getSelectStatement, getSQL, getTableForSynonym, getTableForSynonymIntern, getTableInfo, getTransactionTimeout, getUniqueKeys, getUrl, getUsername, getWhereClause, info, initializeColumnMetaData, initializeDataType, initializeServerColumnMetaData, insert, insertAnsiSQL, insertDatabaseSpecific, isAutoCommit, isConnectionPoolEnabled, isJdbc, isLogEnabled, isMetaDataCacheEnabled, isModified, isOpen, isReleaseConnectionPending, isTypeEqual, lockRow, lockRowInternal, prepareConnection, quote, quoteAllways, registerDBAccessClass, releaseConnection, releaseConnectionIntern, removeDBSpecificQuotes, removeQuotes, rollback, setAutoCommit, setAutomaticLinkColumnNameTranslation, setColumnMetaDataCreator, setColumnMetaDataCreator, setColumnsToStore, setConnection, setConnectionPool, setConnectionPoolEnabled, setDBProperties, setDBProperty, setDefaultCursorCacheTimeout, setDefaultLargeObjectLimit, setDefaultSchema, setDriver, setLargeObjectLimit, setMaxTime, setMetaDataCacheOption, setModified, setPassword, setQueryTimeout, setQuoteCharacters, setTransactionTimeout, setUrl, splitSchemaTable, supportsGetGeneratedKeys, toString, translateDefaultValue, translateQuotes, translateValue, update, updateAnsiSQL, updateDatabaseSpecific
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_ENUM

public static final int TYPE_ENUM
the enum datatype.

See Also:
Constant Field Values

TYPE_SET

public static final int TYPE_SET
the set datatype.

See Also:
Constant Field Values
Constructor Detail

MySQLDBAccess

public MySQLDBAccess()
Constructs a new MySQLDBAccess Object.

Method Detail

open

public void open()
          throws DataSourceException
It opens the database and stores the Connection object.

Overrides:
open in class DBAccess
Throws:
DataSourceException - if the database couldn't opened

isAutoQuote

public boolean isAutoQuote(java.lang.String pName)
Description copied from class: DBAccess
It returns true if this name should be automated quoted. e.g. in Oracle default all isUppercase(), so if the name has one loweCase character, then AutoQuote is true to quote this name.

Overrides:
isAutoQuote in class DBAccess
Parameters:
pName - the name to quote.
Returns:
true if this name should be automated quoted.

getColumnMetaDataIntern

protected ServerColumnMetaData[] getColumnMetaDataIntern(java.lang.String pFromClause,
                                                         java.lang.String[] pQueryColumns,
                                                         java.lang.String pBeforeQueryColumns,
                                                         java.lang.String pWhereClause,
                                                         java.lang.String pAfterWhereClause)
                                                  throws DataSourceException
Description copied from class: DBAccess
Returns the meta data information for the specified query, and configures all columns with defaults.

Overrides:
getColumnMetaDataIntern in class DBAccess
Parameters:
pFromClause - the from clause with query tables and join definitions
pQueryColumns - the query columns
pBeforeQueryColumns - the before query columns
pWhereClause - the last where condition in query
pAfterWhereClause - the after where clause in query
Returns:
the meta data for the specified query, and initials all columns.
Throws:
DataSourceException - if an Exception occur during getting the meta data or if the storage is not opened or if one columns SQL type is not supported

getTableInfoIntern

protected TableInfo getTableInfoIntern(java.lang.String pWriteBackTable)
                                throws DataSourceException
Returns the meta data information for the specified query, and configures all columns with defaults.

Overrides:
getTableInfoIntern in class DBAccess
Parameters:
pWriteBackTable - the write back table to use for the isWriteable() state (Optional)
Returns:
the meta data for the specified query, and initials all columns.
Throws:
DataSourceException - if an Exception occur during getting the meta data or if the storage is not opened or if one columns SQL type is not supported

getPrimaryKeyIntern

protected Key getPrimaryKeyIntern(java.lang.String pCatalog,
                                  java.lang.String pSchema,
                                  java.lang.String pTable)
                           throws DataSourceException
It's gets all Primary Key columns and return it as String[]. Gets all Primary Key columns and return it as list of Strings.

Overrides:
getPrimaryKeyIntern in class DBAccess
Parameters:
pCatalog - the catalog to use
pSchema - the schema to use
pTable - the table to use
Returns:
all Primary Key columns and return it as String[].
Throws:
DataSourceException - if an error occur during PK search process.

getForeignKeysIntern

protected java.util.List<ForeignKey> getForeignKeysIntern(java.lang.String pCatalog,
                                                          java.lang.String pSchema,
                                                          java.lang.String pTable)
                                                   throws DataSourceException
Returns all Foreign Keys for the specified table.

Overrides:
getForeignKeysIntern in class DBAccess
Parameters:
pCatalog - the catalog to use
pSchema - the schema to use
pTable - the table to use as base table.
Returns:
all Foreign Keys for the specified table.
Throws:
DataSourceException - if an error occur in determining the ForeignKeys.

getUniqueKeysIntern

protected java.util.List<Key> getUniqueKeysIntern(java.lang.String pCatalog,
                                                  java.lang.String pSchema,
                                                  java.lang.String pTable)
                                           throws DataSourceException
It gets all columns for each Unique Key and return it.

Overrides:
getUniqueKeysIntern in class DBAccess
Parameters:
pCatalog - the catalog to use
pSchema - the schema to use
pTable - the table to use
Returns:
all columns for each Unique Key.
Throws:
DataSourceException - if an error occur during UK search process.

getDefaultValuesIntern

protected java.util.Map<java.lang.String,java.lang.Object> getDefaultValuesIntern(java.lang.String pCatalog,
                                                                                  java.lang.String pSchema,
                                                                                  java.lang.String pTable)
                                                                           throws DataSourceException
Gets all default column values of a specific table.

Overrides:
getDefaultValuesIntern in class DBAccess
Parameters:
pCatalog - the catalog name
pSchema - the schema name
pTable - the table name
Returns:
a Hashtable with the column name as key and the default value as value. It only contains columns with a default value
Throws:
DataSourceException - if the database access throws an exception

setUsername

public void setUsername(java.lang.String pUsername)
Description copied from class: DBAccess
Sets the user name to connect with.

Overrides:
setUsername in class DBAccess
Parameters:
pUsername - the user name

fetch

public java.util.List<java.lang.Object[]> fetch(ServerMetaData pServerMetaData,
                                                java.lang.String pBeforeQueryColumns,
                                                java.lang.String[] pQueryColumns,
                                                java.lang.String pFromClause,
                                                ICondition pFilter,
                                                java.lang.String pWhereCondition,
                                                java.lang.String pAfterWhereClause,
                                                SortDefinition pSort,
                                                java.lang.String pOrderByClause,
                                                int pFromRow,
                                                int pMinimumRowCount,
                                                boolean pAllowLazyFetch)
                                         throws DataSourceException
Mostly same as DBAccess.fetch(ServerMetaData, String, String[], String, ICondition, String, String, SortDefinition, int, int). This fetch does accept an additional order by clause which will be used if the given default sort is null.

Overrides:
fetch in class DBAccess
Parameters:
pServerMetaData - the MetaDataColumn array to use.
pBeforeQueryColumns - the before query columns
pQueryColumns - the query columns
pFromClause - the from clause with query tables and join definitions
pFilter - the filter to use
pWhereCondition - the last where condition in query
pAfterWhereClause - the after where clause in query
pSort - the sort order to use
pOrderByClause - the order by clause
pFromRow - the row index from to fetch
pMinimumRowCount - the minimum count row to fetch
pAllowLazyFetch - if lazy fetch should be allowed.
Returns:
the List of fetched rows (as List of Object[]) for the specified query tables and parameters.
Throws:
DataSourceException - if the fetch fails.

getParameterizedSelectStatement

public DBAccess.ParameterizedStatement getParameterizedSelectStatement(ServerMetaData pServerMetaData,
                                                                       java.lang.String pBeforeQueryColumns,
                                                                       java.lang.String[] pQueryColumns,
                                                                       java.lang.String pFromClause,
                                                                       ICondition pFilter,
                                                                       java.lang.String pWhereClause,
                                                                       java.lang.String pAfterWhereClause,
                                                                       SortDefinition pSort,
                                                                       java.lang.String pOrderByClause,
                                                                       int pFromRow,
                                                                       int pMinimumRowCount)
                                                                throws DataSourceException
Creates the DBAccess.ParameterizedStatement and returns it.

Note that this function is subject to be changed in a future version, and can there for not be considered stable.

Overrides:
getParameterizedSelectStatement in class DBAccess
Parameters:
pServerMetaData - the MetaDataColumn array to use.
pBeforeQueryColumns - the string to place in the SELECT statement between the SELECT and the first query column.
pQueryColumns - the list of query columns to use in the SELECT statement.
pFromClause - the list of query tables to use in the SELECT statement.
pFilter - the Filter to use
pWhereClause - the string to place in the SELECT statement after the last WHERE condition from the Filter or MasterReference (Master-Detail Condition).
pAfterWhereClause - the string to place in the SELECT statement after the WHERE clause and before the ORDER BY clause.
pSort - the sort definition.
pOrderByClause - the order by clause.
pFromRow - the row index from to fetch
pMinimumRowCount - the minimum count row to fetch
Returns:
the SELECT statement as String.
Throws:
DataSourceException - if it's not possible to build the select statement in fact of missing elements

getDiscardRowCount

protected int getDiscardRowCount(int pFromRow,
                                 int pMinimumRowCount)
Gets how many rows should be discarded based on the given values.

Overrides:
getDiscardRowCount in class DBAccess
Parameters:
pFromRow - the row index from to fetch
pMinimumRowCount - the minimum count row to fetch
Returns:
the amount of rows to discard.

getDefaultMaximumAdditionalFetchAmount

public static int getDefaultMaximumAdditionalFetchAmount()
Gets the default maximum amount of additional rows to fetch.

Returns:
the default maximum amount of additional rows to fetch.
See Also:
setMaximumAdditionalFetchAmount(int)

setDefaultMaximumAdditionalFetchAmount

public static void setDefaultMaximumAdditionalFetchAmount(int pDefaultMaximumAdditionalFetchAmount)
Sets the default maximum amount of additional rows to fetch.

If a fetch took less than DBAccess.getMaxTime(), there will be a second, additional fetch issues to fetch more data. This allows to set an upper limit on that second, additional fetch.

When set to 0, no additional data will be fetched. When set to -1 or less, there will be no limit imposed.

Parameters:
pDefaultMaximumAdditionalFetchAmount - the default maximum amount for the additional fetch to fetch.
See Also:
getMaximumAdditionalFetchAmount()

getMaximumAdditionalFetchAmount

public int getMaximumAdditionalFetchAmount()
Gets the maximum amount of additional rows to fetch.

Returns:
the maximum amount of additional rows to fetch.
See Also:
setMaximumAdditionalFetchAmount(int)

setMaximumAdditionalFetchAmount

public void setMaximumAdditionalFetchAmount(int pMaximumAdditionalFetchAmount)
Sets the maximum amount of additional rows to fetch.

If a fetch took less than DBAccess.getMaxTime(), there will be a second, additional fetch issues to fetch more data. This allows to set an upper limit on that second, additional fetch.

When set to 0, no additional data will be fetched. When set to -1 or less, there will be no limit imposed.

Parameters:
pMaximumAdditionalFetchAmount - the maximum amount for the additional fetch to fetch.
See Also:
getMaximumAdditionalFetchAmount()

getColumnInfo

protected java.util.Hashtable<java.lang.String,com.sibvisions.rad.persist.jdbc.MySQLDBAccess.ColumnInfo> getColumnInfo(java.lang.String pTableName)
Get detailed column information for the given table. The column details contains the real data type and not the JDBC data type.

Parameters:
pTableName - the name of the table
Returns:
the information per column

extractValues

protected java.lang.String[] extractValues(java.lang.String pTypeDefinition)
Extracts the values from a valuelist, separated with ,.

Parameters:
pTypeDefinition - the data type definition e.g. enum ('y', 'n')
Returns:
an array with values

calculateAdditionalFetchRowCount

protected int calculateAdditionalFetchRowCount(int pFetchedRowCount,
                                               long pFetchTimeInMilliSeconds)
Calculates the amount of rows to fetch additionally to an already happened fetch.

Parameters:
pFetchedRowCount - the already fetched row count.
pFetchTimeInMilliSeconds - the time the fetch took, in milliseconds.
Returns:
the amount of rows to additionally fetch. Can be zero or less to fetch nothing.


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.