public class ERXJDBCUtilities
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
ERXJDBCUtilities.CopyTask |
static interface |
ERXJDBCUtilities.IConnectionDelegate
IConnectionDelegate is like a closure for connection operations.
|
static interface |
ERXJDBCUtilities.IResultSetDelegate
IResultSetDelegate is like a closure for ResultSet operations.
|
| Modifier and Type | Field and Description |
|---|---|
static org.apache.log4j.Logger |
log |
static NSTimestampFormatter |
TIMESTAMP_FORMATTER |
| Constructor and Description |
|---|
ERXJDBCUtilities() |
| Modifier and Type | Method and Description |
|---|---|
static void |
_copyDatabaseDefinedByEOModelAndConnectionDictionaryToDatabaseWithConnectionDictionary(EOModelGroup modelGroup,
NSDictionary sourceDict,
NSDictionary destDict) |
static void |
_copyDatabaseDefinedByEOModelAndConnectionDictionaryToDatabaseWithConnectionDictionary(EOModel m,
NSDictionary sourceDict,
NSDictionary destDict)
Copies all rows from one database to another database.
|
static EOAdaptorChannel |
adaptorChannelWithUserAndPassword(EOModel model,
java.lang.String userName,
java.lang.String password)
Returns an adaptor channel with the given username and password.
|
static EOAdaptorChannel |
adaptorChannelWithUserAndPassword(java.lang.String adaptorName,
NSDictionary originalConnectionDictionary,
java.lang.String userName,
java.lang.String password)
Returns an adaptor channel with the given username and password.
|
static void |
createTablesForEntities(EOAdaptorChannel channel,
NSArray<EOEntity> entities)
Creates tables, primary keys, and foreign keys for the given list of
entities.
|
static void |
createTablesForModel(EOAdaptorChannel channel,
EOModel model)
Creates tables, primary keys, and foreign keys for the tables in the
given model.
|
static java.lang.String |
databaseProductName(EOAdaptorChannel channel)
Returns the name of the database product for the given channel (handy
when loading database-vendor-specific sql scripts in migrations).
|
static java.lang.String |
databaseProductName(EOModel model)
Returns the name of the database product for the given an eomodel (handy
when loading database-vendor-specific sql scripts in migrations).
|
static void |
dropTablesForEntities(EOAdaptorChannel channel,
NSArray<EOEntity> entities,
boolean ignoreFailures)
Drops tables, primary keys, and foreign keys for the given list of
entities.
|
static void |
dropTablesForModel(EOAdaptorChannel channel,
EOModel model,
boolean ignoreFailures)
Drops tables, primary keys, and foreign keys for the tables in the
given model.
|
static void |
executeQuery(EOAdaptorChannel adaptorChannel,
java.lang.String query,
ERXJDBCUtilities.IResultSetDelegate delegate)
Using the backing connection from the adaptor context, executes the given
query and calls delegate.processResultSet(rs) once for the ResultSet.
|
static int |
executeUpdate(EOAdaptorChannel channel,
java.lang.String sql)
Shortcut to java.sql.Statement.executeUpdate(..) that operates on an
EOAdaptorChannel.
|
static int |
executeUpdate(EOAdaptorChannel channel,
java.lang.String sql,
boolean autoCommit)
Shortcut to java.sql.Statement.executeUpdate(..) that operates on an
EOAdaptorChannel.
|
static int |
executeUpdateScript(EOAdaptorChannel channel,
NSArray<java.lang.String> sqlStatements)
Splits the given sqlscript and executes each of the statements in a
single transaction
|
static int |
executeUpdateScript(EOAdaptorChannel channel,
NSArray<java.lang.String> sqlStatements,
boolean ignoreFailures)
Splits the given sqlscript and executes each of the statements in a
single transaction
|
static int |
executeUpdateScript(EOAdaptorChannel channel,
java.lang.String sqlScript)
Splits the given sqlscript and executes each of the statements in a
single transaction
|
static int |
executeUpdateScript(EOAdaptorChannel channel,
java.lang.String sqlScript,
boolean ignoreFailures)
Splits the given sqlscript and executes each of the statements in a
single transaction
|
static int |
executeUpdateScriptFromResourceNamed(EOAdaptorChannel channel,
java.lang.String resourceName,
java.lang.String frameworkName)
Executes a SQL script that is stored as a resource.
|
static int |
executeUpdateScriptIgnoringErrors(EOAdaptorChannel channel,
java.lang.String script)
Deprecated.
|
static javax.sql.rowset.CachedRowSet |
fetchRowSet(EOAdaptorChannel adaptorChannel,
java.lang.String query)
Using the backing connection from the adaptor context, executes the given
query and returns a CachedRowSet of the results.
|
static java.lang.String |
jdbcTimestamp(NSTimestamp t) |
static void |
processConnection(EOAdaptorChannel adaptorChannel,
ERXJDBCUtilities.IConnectionDelegate delegate)
Using the backing connection from the adaptor context, executes the given
query and calls delegate.processConnection(conn) for the Connection.
|
static void |
processResultSetRows(EOAdaptorChannel adaptorChannel,
java.lang.String query,
ERXJDBCUtilities.IResultSetDelegate delegate)
Using the backing connection from the adaptor context, executes the given
query and calls processor.process(rs) for each row of the ResultSet.
|
public static final org.apache.log4j.Logger log
public static final NSTimestampFormatter TIMESTAMP_FORMATTER
public static java.lang.String jdbcTimestamp(NSTimestamp t)
public static void _copyDatabaseDefinedByEOModelAndConnectionDictionaryToDatabaseWithConnectionDictionary(EOModel m, NSDictionary sourceDict, NSDictionary destDict)
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);
m - the model that defines the database to copysourceDict - a NSDictionary containing the following keys for the source
database:
jdbc:FrontBase://host/database , for PostgreSQL
its jdbc:postgresql://host/database
com.frontbase.jdbc.FBJDriver , for
PostgreSQL its org.postgresql.Driver
destDict - same as sourceDict just used for the destination database.public static void _copyDatabaseDefinedByEOModelAndConnectionDictionaryToDatabaseWithConnectionDictionary(EOModelGroup modelGroup, NSDictionary sourceDict, NSDictionary destDict)
modelGroup - the model group to copysourceDict - the source connection dictionarydestDict - the destination connection dictionary_copyDatabaseDefinedByEOModelAndConnectionDictionaryToDatabaseWithConnectionDictionary(EOModel, NSDictionary, NSDictionary)public static EOAdaptorChannel adaptorChannelWithUserAndPassword(EOModel model, java.lang.String userName, java.lang.String password)
model - the model to base this connection off ofuserName - the new usernamepassword - the new passwordpublic static EOAdaptorChannel adaptorChannelWithUserAndPassword(java.lang.String adaptorName, NSDictionary originalConnectionDictionary, java.lang.String userName, java.lang.String password)
adaptorName - the name of the adaptor to useroriginalConnectionDictionary - the original connection dictionaryuserName - the new usernamepassword - the new passwordpublic static int executeUpdate(EOAdaptorChannel channel, java.lang.String sql) throws java.sql.SQLException
channel - the JDBCChannel to work withsql - the sql to executejava.sql.SQLException - if there is a problempublic static int executeUpdate(EOAdaptorChannel channel, java.lang.String sql, boolean autoCommit) throws java.sql.SQLException
channel - the JDBCChannel to work withsql - the sql to executeautoCommit - if true, autocommit the connection after executingjava.sql.SQLException - if there is a problempublic static int executeUpdateScript(EOAdaptorChannel channel, java.lang.String sqlScript) throws java.sql.SQLException
channel - the JDBCChannel to work withsqlScript - the sql script to executejava.sql.SQLException - if there is a problempublic static int executeUpdateScript(EOAdaptorChannel channel, java.lang.String sqlScript, boolean ignoreFailures) throws java.sql.SQLException
channel - the JDBCChannel to work withsqlScript - the sql script to executeignoreFailures - if true, failures in a particular statement are ignoredjava.sql.SQLException - if there is a problempublic static int executeUpdateScript(EOAdaptorChannel channel, NSArray<java.lang.String> sqlStatements) throws java.sql.SQLException
channel - the JDBCChannel to work withsqlStatements - the array of sql scripts to executejava.sql.SQLException - if there is a problempublic static int executeUpdateScript(EOAdaptorChannel channel, NSArray<java.lang.String> sqlStatements, boolean ignoreFailures) throws java.sql.SQLException
channel - the JDBCChannel to work withsqlStatements - the array of sql scripts to executeignoreFailures - if true, failures in a particular statement are ignoredjava.sql.SQLException - if there is a problem@Deprecated public static int executeUpdateScriptIgnoringErrors(EOAdaptorChannel channel, java.lang.String script) throws java.sql.SQLException
executeUpdateScript(EOAdaptorChannel, String, boolean)channel - the JDBCChannel to work withscript - the array of sql scripts to executejava.sql.SQLException - if there is a problempublic static int executeUpdateScriptFromResourceNamed(EOAdaptorChannel channel, java.lang.String resourceName, java.lang.String frameworkName) throws java.sql.SQLException, java.io.IOException
channel - the channel to execute the scripts withinresourceName - the name of the SQL script resourceframeworkName - the name of the framework that contains the resourcejava.sql.SQLException - if a SQL error occursjava.io.IOException - if an error occurs reading the scriptpublic static void dropTablesForModel(EOAdaptorChannel channel, EOModel model, boolean ignoreFailures) throws java.sql.SQLException
channel - the channel to use for executionmodel - the model to drop tables forignoreFailures - if true, failures in a particular statement are ignoredjava.sql.SQLException - if something failspublic static void dropTablesForEntities(EOAdaptorChannel channel, NSArray<EOEntity> entities, boolean ignoreFailures) throws java.sql.SQLException
channel - the channel to use for executionentities - the entities to drop tables forignoreFailures - if true, failures in a particular statement are ignoredjava.sql.SQLException - if something failspublic static void createTablesForModel(EOAdaptorChannel channel, EOModel model) throws java.sql.SQLException
channel - the channel to use for executionmodel - the model to create tables forjava.sql.SQLException - if something failspublic static void createTablesForEntities(EOAdaptorChannel channel, NSArray<EOEntity> entities) throws java.sql.SQLException
channel - the channel to use for executionentities - the entities to create tables forjava.sql.SQLException - if something failspublic static java.lang.String databaseProductName(EOAdaptorChannel channel)
channel - the channelpublic static java.lang.String databaseProductName(EOModel model)
model - the EOModelpublic static void processConnection(EOAdaptorChannel adaptorChannel, ERXJDBCUtilities.IConnectionDelegate delegate) throws java.lang.Exception
adaptorChannel - the adaptor channeldelegate - the connection delegatejava.lang.Exception - if something goes wrongpublic static void executeQuery(EOAdaptorChannel adaptorChannel, java.lang.String query, ERXJDBCUtilities.IResultSetDelegate delegate) throws java.lang.Exception
adaptorChannel - the adaptor channelquery - the query to executedelegate - the processor delegatejava.lang.Exception - if something goes wrongpublic static void processResultSetRows(EOAdaptorChannel adaptorChannel, java.lang.String query, ERXJDBCUtilities.IResultSetDelegate delegate) throws java.lang.Exception
adaptorChannel - the adaptor channelquery - the query to executedelegate - the processor delegatejava.lang.Exception - if something goes wrongpublic static javax.sql.rowset.CachedRowSet fetchRowSet(EOAdaptorChannel adaptorChannel, java.lang.String query) throws java.lang.Exception
adaptorChannel - the adaptor channelquery - the query to executejava.lang.Exception - if something goes wrongCopyright © 2002 – 2022 Project Wonder.