ERXJDBCUtilities Class Reference

Collaboration diagram for ERXJDBCUtilities:

Collaboration graph
[legend]

List of all members.

Classes

class  CopyTask
interface  IConnectionDelegate
interface  IResultSetDelegate

Static Public Member Functions

static void _copyDatabaseDefinedByEOModelAndConnectionDictionaryToDatabaseWithConnectionDictionary (EOModelGroup modelGroup, NSDictionary sourceDict, NSDictionary destDict)
static void _copyDatabaseDefinedByEOModelAndConnectionDictionaryToDatabaseWithConnectionDictionary (EOModel m, NSDictionary sourceDict, NSDictionary destDict)
static EOAdaptorChannel adaptorChannelWithUserAndPassword (String adaptorName, NSDictionary originalConnectionDictionary, String userName, String password)
static EOAdaptorChannel adaptorChannelWithUserAndPassword (EOModel model, String userName, String password)
static void createTablesForEntities (EOAdaptorChannel channel, NSArray< EOEntity > entities) throws SQLException
static void createTablesForModel (EOAdaptorChannel channel, EOModel model) throws SQLException
static String databaseProductName (EOModel model)
static String databaseProductName (EOAdaptorChannel channel)
static void dropTablesForEntities (EOAdaptorChannel channel, NSArray< EOEntity > entities, boolean ignoreFailures) throws SQLException
static void dropTablesForModel (EOAdaptorChannel channel, EOModel model, boolean ignoreFailures) throws SQLException
static void executeQuery (EOAdaptorChannel adaptorChannel, final String query, final IResultSetDelegate delegate) throws Exception
static int executeUpdate (EOAdaptorChannel channel, String sql, boolean autoCommit) throws SQLException
static int executeUpdate (EOAdaptorChannel channel, String sql) throws SQLException
static int executeUpdateScript (EOAdaptorChannel channel, NSArray< String > sqlStatements, boolean ignoreFailures) throws SQLException
static int executeUpdateScript (EOAdaptorChannel channel, NSArray< String > sqlStatements) throws SQLException
static int executeUpdateScript (EOAdaptorChannel channel, String sqlScript, boolean ignoreFailures) throws SQLException
static int executeUpdateScript (EOAdaptorChannel channel, String sqlScript) throws SQLException
static int executeUpdateScriptFromResourceNamed (EOAdaptorChannel channel, String resourceName, String frameworkName) throws SQLException, IOException
static int executeUpdateScriptIgnoringErrors (EOAdaptorChannel channel, String script) throws SQLException
static CachedRowSet fetchRowSet (EOAdaptorChannel adaptorChannel, String query) throws Exception
static String jdbcTimestamp (NSTimestamp t)
static void processConnection (EOAdaptorChannel adaptorChannel, IConnectionDelegate delegate) throws Exception
static void processResultSetRows (EOAdaptorChannel adaptorChannel, String query, final IResultSetDelegate delegate) throws Exception

Static Public Attributes

static final Logger log = Logger.getLogger(ERXJDBCUtilities.class)
static final NSTimestampFormatter TIMESTAMP_FORMATTER = new NSTimestampFormatter("%Y-%m-%d %H:%M:%S.%F")


Member Function Documentation

static void _copyDatabaseDefinedByEOModelAndConnectionDictionaryToDatabaseWithConnectionDictionary ( EOModelGroup  modelGroup,
NSDictionary  sourceDict,
NSDictionary  destDict 
) [static]

See also:
ERXJDBCUtilities._copyDatabaseDefinedByEOModelAndConnectionDictionaryToDatabaseWithConnectionDictionary(EOModel, NSDictionary, NSDictionary)
Parameters:
modelGroup the model group to copy
sourceDict the source connection dictionary
destDict the destination connection dictionary

static void _copyDatabaseDefinedByEOModelAndConnectionDictionaryToDatabaseWithConnectionDictionary ( EOModel  m,
NSDictionary  sourceDict,
NSDictionary  destDict 
) [static]

Copies all rows from one database to another database. The tables must exist before calling this method.

Example:

 NSMutableDictionary sourceDict = new NSMutableDictionary();
 sourceDict.setObjectForKey("YourPassword", "password");
 sourceDict.setObjectForKey("YourUserName", "username");
 sourceDict.setObjectForKey("jdbc:FrontBase://127.0.0.1/YourSourceDatabase", "URL");
 sourceDict.setObjectForKey("com.frontbase.jdbc.FBJDriver", "driver");
 sourceDict.setObjectForKey(Boolean.FALSE.toString(), "autoCommit");
 sourceDict.setObjectForKey(Boolean.TRUE.toString(), "readOnly");
 sourceDict.setObjectForKey(Boolean.TRUE.toString(), "quote");

 NSMutableDictionary destDict = sourceDict.mutableClone();
 destDict.setObjectForKey("jdbc:postgresql://localhost/YourDestinationDatabase", "URL");
 destDict.setObjectForKey("YourPassword", "password");
 destDict.setObjectForKey("YourUserName", "username");
 destDict.setObjectForKey("org.postgresql.Driver", "driver");
 destDict.setObjectForKey(Boolean.FALSE.toString(), "autoCommit");
 destDict.setObjectForKey(Boolean.FALSE.toString(), "readOnly");
 destDict.setObjectForKey(Boolean.FALSE.toString(), "quote");

 EOModel model = EOModelGroup.defaultGroup().modelNamed("YourModelName");
 ERXJDBCUtilities._copyDatabaseDefinedByEOModelAndConnectionDictionaryToDatabaseWithConnectionDictionary(model, sourceDict, destDict);
 
Parameters:
m the model that defines the database to copy
sourceDict a NSDictionary containing the following keys for the source database:
  1. username, the username for the connection
  2. password, the password for the connection
  3. url, the JDBC URL for the connection, for FrontBase its jdbc:FrontBase://host/database , for PostgreSQL its jdbc:postgresql://host/database
  4. driver, the full class name of the driver, for FrontBase its com.frontbase.jdbc.FBJDriver , for PostgreSQL its org.postgresql.Driver
  5. autoCommit, a Boolean defining if autoCommit should be on or off, default is true
  6. readOnly, a Boolean defining if the Connection is readOnly or not, default is false. Its a good
  7. quote, a Boolean defining if the table and field names should be "quoted" idea to make the sourceDict readOnly, because one does not write.
destDict same as sourceDict just used for the destination database.

static EOAdaptorChannel adaptorChannelWithUserAndPassword ( String  adaptorName,
NSDictionary  originalConnectionDictionary,
String  userName,
String  password 
) [static]

Returns an adaptor channel with the given username and password.

Parameters:
adaptorName the name of the adaptor to user
originalConnectionDictionary the original connection dictionary
userName the new username
password the new password
Returns:
a new adaptor channel

static EOAdaptorChannel adaptorChannelWithUserAndPassword ( EOModel  model,
String  userName,
String  password 
) [static]

Returns an adaptor channel with the given username and password.

Parameters:
model the model to base this connection off of
userName the new username
password the new password
Returns:
a new adaptor channel

static void createTablesForEntities ( EOAdaptorChannel  channel,
NSArray< EOEntity >  entities 
) throws SQLException [static]

Creates tables, primary keys, and foreign keys for the given list of entities. This is useful in your Migration #0 class.

Parameters:
channel the channel to use for execution
entities the entities to create tables for
Exceptions:
SQLException if something fails

static void createTablesForModel ( EOAdaptorChannel  channel,
EOModel  model 
) throws SQLException [static]

Creates tables, primary keys, and foreign keys for the tables in the given model. This is useful in your Migration #0 class.

Parameters:
channel the channel to use for execution
model the model to create tables for
Exceptions:
SQLException if something fails

static String databaseProductName ( EOModel  model  )  [static]

Returns the name of the database product for the given an eomodel (handy when loading database-vendor-specific sql scripts in migrations).

Parameters:
model the EOModel
Returns:
the database the database product name ("FrontBase", "PostgreSQL")

static String databaseProductName ( EOAdaptorChannel  channel  )  [static]

Returns the name of the database product for the given channel (handy when loading database-vendor-specific sql scripts in migrations).

Parameters:
channel the channel
Returns:
the database the database product name ("FrontBase", "PostgreSQL")

static void dropTablesForEntities ( EOAdaptorChannel  channel,
NSArray< EOEntity >  entities,
boolean  ignoreFailures 
) throws SQLException [static]

Drops tables, primary keys, and foreign keys for the given list of entities. This is useful in your Migration #0 class.

Parameters:
channel the channel to use for execution
entities the entities to drop tables for
ignoreFailures if true, failures in a particular statement are ignored
Exceptions:
SQLException if something fails

static void dropTablesForModel ( EOAdaptorChannel  channel,
EOModel  model,
boolean  ignoreFailures 
) throws SQLException [static]

Drops tables, primary keys, and foreign keys for the tables in the given model.

Parameters:
channel the channel to use for execution
model the model to drop tables for
ignoreFailures if true, failures in a particular statement are ignored
Exceptions:
SQLException if something fails

static void executeQuery ( EOAdaptorChannel  adaptorChannel,
final String  query,
final IResultSetDelegate  delegate 
) throws Exception [static]

Using the backing connection from the adaptor context, executes the given query and calls delegate.processResultSet(rs) once for the ResultSet. This handles properly closing all the underlying JDBC resources.

Parameters:
adaptorChannel the adaptor channel
query the query to execute
delegate the processor delegate
Exceptions:
Exception if something goes wrong

static int executeUpdate ( EOAdaptorChannel  channel,
String  sql,
boolean  autoCommit 
) throws SQLException [static]

Shortcut to java.sql.Statement.executeUpdate(..) that operates on an EOAdaptorChannel. and optionally commits.

Parameters:
channel the JDBCChannel to work with
sql the sql to execute
autoCommit if true, autocommit the connection after executing
Returns:
the number of rows updated
Exceptions:
SQLException if there is a problem

static int executeUpdate ( EOAdaptorChannel  channel,
String  sql 
) throws SQLException [static]

Shortcut to java.sql.Statement.executeUpdate(..) that operates on an EOAdaptorChannel.

Parameters:
channel the JDBCChannel to work with
sql the sql to execute
Returns:
the number of rows updated
Exceptions:
SQLException if there is a problem

static int executeUpdateScript ( EOAdaptorChannel  channel,
NSArray< String sqlStatements,
boolean  ignoreFailures 
) throws SQLException [static]

Splits the given sqlscript and executes each of the statements in a single transaction

Parameters:
channel the JDBCChannel to work with
sqlStatements the array of sql scripts to execute
ignoreFailures if true, failures in a particular statement are ignored
Returns:
the number of rows updated
Exceptions:
SQLException if there is a problem

static int executeUpdateScript ( EOAdaptorChannel  channel,
NSArray< String sqlStatements 
) throws SQLException [static]

Splits the given sqlscript and executes each of the statements in a single transaction

Parameters:
channel the JDBCChannel to work with
sqlStatements the array of sql scripts to execute
Returns:
the number of rows updated
Exceptions:
SQLException if there is a problem

static int executeUpdateScript ( EOAdaptorChannel  channel,
String  sqlScript,
boolean  ignoreFailures 
) throws SQLException [static]

Splits the given sqlscript and executes each of the statements in a single transaction

Parameters:
channel the JDBCChannel to work with
sqlScript the sql script to execute
ignoreFailures if true, failures in a particular statement are ignored
Returns:
the number of rows updated
Exceptions:
SQLException if there is a problem

static int executeUpdateScript ( EOAdaptorChannel  channel,
String  sqlScript 
) throws SQLException [static]

Splits the given sqlscript and executes each of the statements in a single transaction

Parameters:
channel the JDBCChannel to work with
sqlScript the sql script to execute
Returns:
the number of rows updated
Exceptions:
SQLException if there is a problem

static int executeUpdateScriptFromResourceNamed ( EOAdaptorChannel  channel,
String  resourceName,
String  frameworkName 
) throws SQLException, IOException [static]

Executes a SQL script that is stored as a resource.

Parameters:
channel the channel to execute the scripts within
resourceName the name of the SQL script resource
frameworkName the name of the framework that contains the resource
Returns:
the number of rows updated
Exceptions:
SQLException if a SQL error occurs
IOException if an error occurs reading the script

static int executeUpdateScriptIgnoringErrors ( EOAdaptorChannel  channel,
String  script 
) throws SQLException [static]

Runs a given sql script and executes each of the statements in a one transaction.

Parameters:
channel the JDBCChannel to work with
script the array of sql scripts to execute
Returns:
the number of rows updated
Exceptions:
SQLException if there is a problem
Deprecated:
use executeUpdateScript with the boolean param

static CachedRowSet fetchRowSet ( EOAdaptorChannel  adaptorChannel,
String  query 
) throws Exception [static]

Using the backing connection from the adaptor context, executes the given query and returns a CachedRowSet of the results. This can be useful for more complicated migrations. This handles properly closing all the underlying JDBC resources.

Parameters:
adaptorChannel the adaptor channel
query the query to execute
Returns:
a CachedRowSet of the results
Exceptions:
Exception if something goes wrong

static String jdbcTimestamp ( NSTimestamp  t  )  [static]

static void processConnection ( EOAdaptorChannel  adaptorChannel,
IConnectionDelegate  delegate 
) throws Exception [static]

Using the backing connection from the adaptor context, executes the given query and calls delegate.processConnection(conn) for the Connection. This handles properly closing all the underlying JDBC resources.

Parameters:
adaptorChannel the adaptor channel
delegate the connection delegate
Exceptions:
Exception if something goes wrong

static void processResultSetRows ( EOAdaptorChannel  adaptorChannel,
String  query,
final IResultSetDelegate  delegate 
) throws Exception [static]

Using the backing connection from the adaptor context, executes the given query and calls processor.process(rs) for each row of the ResultSet. This handles properly closing all the underlying JDBC resources.

Parameters:
adaptorChannel the adaptor channel
query the query to execute
delegate the processor delegate
Exceptions:
Exception if something goes wrong


Member Data Documentation

final Logger log = Logger.getLogger(ERXJDBCUtilities.class) [static]

final NSTimestampFormatter TIMESTAMP_FORMATTER = new NSTimestampFormatter("%Y-%m-%d %H:%M:%S.%F") [static]


The documentation for this class was generated from the following file:

Generated on Sat May 26 06:43:15 2012 for Project Wonder by  doxygen 1.5.8