org.opensubsystems.core.persist.db.mysql
Class MySQLDataUtils

java.lang.Object
  extended by org.opensubsystems.core.persist.db.mysql.MySQLDataUtils

public final class MySQLDataUtils
extends java.lang.Object

This class collects code fragments which are reusable for managing data in MySQL.

Version:
$Id: MySQLDataUtils.java,v 1.4 2007/01/07 06:14:27 bastafidli Exp $
Author:
Julo Legeny
Code reviewer:
Miro Halas
Code reviewed:
1.2 2006/02/11 00:26:39 jlegeny

Nested Class Summary
static class MySQLDataUtils.CachedInsertStatements
          Class used to encapsulate and hold cached statements between method calls.
static class MySQLDataUtils.CachedUpdateStatements
          Class used to encapsulate and hold cached statements between method calls.
 
Method Summary
static MySQLDataUtils.CachedInsertStatements cacheStatementsForInsert(java.sql.Connection dbConnection, boolean bIsInDomain, java.lang.String strTableName, boolean bModifiable)
          Cache the statements required by subsequent calls to this class.
static MySQLDataUtils.CachedUpdateStatements cacheStatementsForUpdate(java.sql.Connection dbConnection, boolean bIsInDomain, java.lang.String strTableName)
          Cache the statements required by subsequent calls to this class.
static void closeStatements(MySQLDataUtils.CachedInsertStatements cache)
          Release the statements cached by cacheStatementsForXXX.
static void closeStatements(MySQLDataUtils.CachedUpdateStatements cache)
          Release the statements cached by cacheStatementsForXXX.
static void fetchModifiedTimestamps(MySQLDataUtils.CachedUpdateStatements cache, ModifiableDataObject data)
          Check errors and fetch from the database generated modification timestamps for the updated data object.
static void insertAndFetchGeneratedValues(java.sql.Connection dbConnection, java.sql.PreparedStatement insertStatement, boolean bIsInDomain, java.lang.String strTableName, BasicDataObject data)
          Insert the data, fetch from the database id and generated creation and modification timestamps for the newly created data object.
static void insertAndFetchGeneratedValues(java.sql.PreparedStatement insertStatement, MySQLDataUtils.CachedInsertStatements cache, BasicDataObject data)
          Insert the data, fetch from the database id and generated creation and modification timestamps for the newly created data object.
static void updatedAndFetchGeneratedValues(java.lang.String strDataName, java.sql.Connection dbConnection, java.sql.PreparedStatement updateStatement, boolean bIsInDomain, java.lang.String strTableName, 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

insertAndFetchGeneratedValues

public static void insertAndFetchGeneratedValues(java.sql.Connection dbConnection,
                                                 java.sql.PreparedStatement insertStatement,
                                                 boolean bIsInDomain,
                                                 java.lang.String strTableName,
                                                 BasicDataObject data)
                                          throws java.sql.SQLException,
                                                 OSSException
Insert the data, fetch from the database id and generated creation and modification timestamps for the newly created data object. Note: Since the caller created the prepared statement, the caller is responsible for its closing.

Parameters:
dbConnection - - connection to use to access the database
insertStatement - - statement used to insert the data
bIsInDomain - - are the data objects maintained in domains
strTableName - - name of the table
data - - data object to update
Throws:
java.sql.SQLException - - an error has occured
OSSException - - an error has occured

insertAndFetchGeneratedValues

public static void insertAndFetchGeneratedValues(java.sql.PreparedStatement insertStatement,
                                                 MySQLDataUtils.CachedInsertStatements cache,
                                                 BasicDataObject data)
                                          throws OSSException,
                                                 java.sql.SQLException
Insert the data, fetch from the database id and generated creation and modification timestamps for the newly created data object. Note: Since the caller created the prepared statement, the caller is responsible for its closing.

Parameters:
insertStatement - - statement used to insert the data
cache - - cached jdbc statements
data - - data object to update
Throws:
OSSException - - an error accessing database
java.sql.SQLException - - an error while inserting data

cacheStatementsForInsert

public static MySQLDataUtils.CachedInsertStatements cacheStatementsForInsert(java.sql.Connection dbConnection,
                                                                             boolean bIsInDomain,
                                                                             java.lang.String strTableName,
                                                                             boolean bModifiable)
                                                                      throws OSSException
Cache the statements required by subsequent calls to this class. You must call closeGeneratedValuesStatements in finally to properly free resources.

Parameters:
dbConnection - - connection to use to access the datavase
bIsInDomain - - are the data objects maintained in domains
strTableName - - name of the table
bModifiable - - is the data object modifiable
Returns:
CachedInsertStatements - cached jdbc statements
Throws:
OSSException - - an error accessing the database

closeStatements

public static void closeStatements(MySQLDataUtils.CachedInsertStatements cache)
Release the statements cached by cacheStatementsForXXX.

Parameters:
cache - - cache to release

updatedAndFetchGeneratedValues

public static void updatedAndFetchGeneratedValues(java.lang.String strDataName,
                                                  java.sql.Connection dbConnection,
                                                  java.sql.PreparedStatement updateStatement,
                                                  boolean bIsInDomain,
                                                  java.lang.String strTableName,
                                                  ModifiableDataObject data)
                                           throws java.sql.SQLException,
                                                  OSSException
Update the data, check for errors and fetch from the database generated modification timestamps for the updated data object. Note: Since the caller created the prepared statement, the caller is responsible for its closing.

Parameters:
strDataName - - name of the data object
dbConnection - - connection to use to access the datavase
updateStatement - - statement to update data in the database
bIsInDomain - - are the data objects maintained in domains
strTableName - - name of the table
data - - data object to update
Throws:
java.sql.SQLException - - an error has occured
OSSException - - an error has occured

fetchModifiedTimestamps

public static void fetchModifiedTimestamps(MySQLDataUtils.CachedUpdateStatements cache,
                                           ModifiableDataObject data)
                                    throws OSSException
Check errors and fetch from the database generated modification timestamps for the updated data object.

Parameters:
cache - - cached jdbc statements
data - - data object to update
Throws:
OSSException - - an error has occured

cacheStatementsForUpdate

public static MySQLDataUtils.CachedUpdateStatements cacheStatementsForUpdate(java.sql.Connection dbConnection,
                                                                             boolean bIsInDomain,
                                                                             java.lang.String strTableName)
                                                                      throws OSSException
Cache the statements required by subsequent calls to this class. You must call closeGeneratedValuesStatements in finally to properly free resources.

Parameters:
dbConnection - - connection to the database to use
bIsInDomain - - are the data objects maintained in domains
strTableName - - name of the table
Returns:
CachedInsertStatements
Throws:
OSSException - - an error accessing the database

closeStatements

public static void closeStatements(MySQLDataUtils.CachedUpdateStatements cache)
Release the statements cached by cacheStatementsForXXX.

Parameters:
cache - - cached jdbc statements


Copyright © 2003 - 2006 OpenSubsystems s.r.o.