|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.opensubsystems.core.persist.db.DatabaseImpl
org.opensubsystems.core.persist.db.mysql.MySQLDatabaseImpl
public class MySQLDatabaseImpl
Management layer for My SQL database (www.mysql.com) TODO: Improve: Consider storing all data in UTF-8 See http://uwstopia.nl/blog/2007/01/simple-utf-8-and-mysql-how-to - Make sure you append CHARACTER SET 'UTF8' to each CREATE TABLE statement. Example: CREATE TABLE test (id SERIAL PRIMARY KEY, somefield VARCHAR(4)) CHARACTER SET 'UTF8';. This can be done at the database level as well (when using CREATE DATABASE), but most of the times this is done for you by an external party (hoster, sysadmins, ...) - Issue the following query immediately after you established a database connection (most likely somewhere in your initialization routines): SET NAMES='UTF8'
| Field Summary |
|---|
| Fields inherited from class org.opensubsystems.core.persist.db.DatabaseImpl |
|---|
m_bDatabaseSchemaInitialized, m_bDatabaseStarted, m_bDatabaseStartInProgress, m_vdsSchema, MAX_SAFE_LENGTH |
| Constructor Summary | |
|---|---|
MySQLDatabaseImpl()
Default constructor for empty database. |
|
| Method Summary | |
|---|---|
void |
createDatabaseInstance()
Method for creating database instance. |
protected void |
createUser(java.sql.Connection cntAdminDBConnection)
Create database user which will be used by connection pool to access the database. |
java.lang.String |
getCurrentTimestampFunctionCall()
Get string which can be used in SQL queries to retrieve timestamp representing current time. |
int |
getDatabaseType()
Returns the type of database currently in use. |
java.lang.String |
getDatabaseTypeIdentifier()
Returns the identifier for the type of database currently in use which can be used to construct package and class names. |
java.lang.Object[] |
getSQLAnalyzeFunctionCall(java.util.Map mapTableNames)
Get DB specific SQL queries for analyzing tables or updating statistics on the tables (it is good for performance). |
java.lang.String |
getSQLCountFunctionCall()
Get string which can be used in SQL queries to retrieve record count. |
boolean |
hasSelectListRangeSupport()
Find out if database allows us to support rows limitation. This means that database has to provide a way how to construct EFFICIENT SQL which allows us to retrieve items starting from row X and ending at row Y. |
void |
insertAndFetchGeneratedValues(java.sql.Connection dbConnection,
java.sql.PreparedStatement insertStatement,
boolean bIsInDomain,
java.lang.String strTableName,
int iIndex,
BasicDataObject data)
Insert the data, fetch from the database id and generated creation and optionally modification timestamps for the newly created data object. |
boolean |
isCallableStatement(java.lang.String strQuery)
Test if the specified query invokes stored procedure or if it is just a regular prepared statement. |
boolean |
preferCountToLast()
Find out if when trying to find out size of the result set we should use rather count(*)/count(1)/count(id) instead of using hasAbsolutePositioningSupport. |
void |
startDatabaseServer()
Method for starting database instance. |
void |
stop()
Stop the database. After the database is stopped, no more requests can be issued until the database is started again. |
void |
updatedAndFetchGeneratedValues(java.lang.String strDataName,
java.sql.Connection dbConnection,
java.sql.PreparedStatement updateStatement,
boolean bIsInDomain,
java.lang.String strTableName,
int iIndex,
ModifiableDataObject data)
Update the data, check for errors and fetch from the database generated modification timestamps for the updated data object. |
| Methods inherited from class org.opensubsystems.core.persist.db.DatabaseImpl |
|---|
add, add, getAdminConnection, getConnectionTestStatement, getInstance, getInstanceIfStarted, getSelectListResultSetConcurrency, getSelectListResultSetType, getTransactionIsolation, hasAbsolutePositioningSupport, isStarted, setInstance, start |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MySQLDatabaseImpl()
throws OSSException
OSSException - - problem connecting to database| Method Detail |
|---|
protected void createUser(java.sql.Connection cntAdminDBConnection)
throws OSSException
createUser in class DatabaseImplcntAdminDBConnection - - connection with rights to create users
OSSException - - cannot create user
public void startDatabaseServer()
throws OSSException
startDatabaseServer in class DatabaseImplOSSException - - problem starting the server
public void createDatabaseInstance()
throws OSSException
createDatabaseInstance in class DatabaseImplOSSException - - problem creating the database instance
public void stop()
throws OSSException
stop in interface Databasestop in class DatabaseImplOSSException - - problems stopping the databasepublic int getDatabaseType()
public java.lang.String getDatabaseTypeIdentifier()
public boolean preferCountToLast()
preferCountToLast in interface DatabasepreferCountToLast in class DatabaseImplpublic java.lang.String getCurrentTimestampFunctionCall()
public java.lang.String getSQLCountFunctionCall()
public boolean hasSelectListRangeSupport()
hasSelectListRangeSupport in interface DatabasehasSelectListRangeSupport in class DatabaseImplpublic java.lang.Object[] getSQLAnalyzeFunctionCall(java.util.Map mapTableNames)
mapTableNames - - map of table names the update statistics will be
processed on. Key is the data object data of which
are stored in the table and value is te name of the
table
public boolean isCallableStatement(java.lang.String strQuery)
strQuery - - query to test
public void insertAndFetchGeneratedValues(java.sql.Connection dbConnection,
java.sql.PreparedStatement insertStatement,
boolean bIsInDomain,
java.lang.String strTableName,
int iIndex,
BasicDataObject data)
throws java.sql.SQLException,
OSSException
dbConnection - - connection to use to access the databaseinsertStatement - - statement used to insert the data. This can be
CallableStatement if stored procedure is used.bIsInDomain - - are the data objects maintained in domainsstrTableName - - name of the table where the data are being insertediIndex - - 1 based index of the next parameter value of which can be
set on the statement (last parameter set by caller + 1)data - - data object to update with the fetched values
java.sql.SQLException - - an error has occured
OSSException - - an error has occured
public void updatedAndFetchGeneratedValues(java.lang.String strDataName,
java.sql.Connection dbConnection,
java.sql.PreparedStatement updateStatement,
boolean bIsInDomain,
java.lang.String strTableName,
int iIndex,
ModifiableDataObject data)
throws java.sql.SQLException,
OSSException
strDataName - - name of the data objectdbConnection - - connection to use to access the datavaseupdateStatement - - statement to update data in the database. This
can be CallableStatement if stored procedure is
used.bIsInDomain - - are the data objects maintained in domainsstrTableName - - name of the tableiIndex - - 1 based index of the next parameter value of which can be
set on the statement (last parameter set by caller + 1)data - - data object to update
java.sql.SQLException - - an error has occured
OSSException - - an error has occured
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||