public class ERXJDBCUtilities extends 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 com.webobjects.foundation.NSTimestampFormatter |
TIMESTAMP_FORMATTER |
Constructor and Description |
---|
ERXJDBCUtilities() |
Modifier and Type | Method and Description |
---|---|
static void |
_copyDatabaseDefinedByEOModelAndConnectionDictionaryToDatabaseWithConnectionDictionary(com.webobjects.eoaccess.EOModelGroup modelGroup,
NSDictionary sourceDict,
NSDictionary destDict) |
static void |
_copyDatabaseDefinedByEOModelAndConnectionDictionaryToDatabaseWithConnectionDictionary(com.webobjects.eoaccess.EOModel m,
NSDictionary sourceDict,
NSDictionary destDict)
Copies all rows from one database to another database.
|
static com.webobjects.eoaccess.EOAdaptorChannel |
adaptorChannelWithUserAndPassword(com.webobjects.eoaccess.EOModel model,
String userName,
String password)
Returns an adaptor channel with the given username and password.
|
static com.webobjects.eoaccess.EOAdaptorChannel |
adaptorChannelWithUserAndPassword(String adaptorName,
NSDictionary originalConnectionDictionary,
String userName,
String password)
Returns an adaptor channel with the given username and password.
|
static void |
createTablesForEntities(com.webobjects.eoaccess.EOAdaptorChannel channel,
NSArray<com.webobjects.eoaccess.EOEntity> entities)
Creates tables, primary keys, and foreign keys for the given list of
entities.
|
static void |
createTablesForModel(com.webobjects.eoaccess.EOAdaptorChannel channel,
com.webobjects.eoaccess.EOModel model)
Creates tables, primary keys, and foreign keys for the tables in the
given model.
|
static String |
databaseProductName(com.webobjects.eoaccess.EOAdaptorChannel channel)
Returns the name of the database product for the given channel (handy
when loading database-vendor-specific sql scripts in migrations).
|
static String |
databaseProductName(com.webobjects.eoaccess.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(com.webobjects.eoaccess.EOAdaptorChannel channel,
NSArray<com.webobjects.eoaccess.EOEntity> entities,
boolean ignoreFailures)
Drops tables, primary keys, and foreign keys for the given list of
entities.
|
static void |
dropTablesForModel(com.webobjects.eoaccess.EOAdaptorChannel channel,
com.webobjects.eoaccess.EOModel model,
boolean ignoreFailures)
Drops tables, primary keys, and foreign keys for the tables in the
given model.
|
static void |
executeQuery(com.webobjects.eoaccess.EOAdaptorChannel adaptorChannel,
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(com.webobjects.eoaccess.EOAdaptorChannel channel,
String sql)
Shortcut to java.sql.Statement.executeUpdate(..) that operates on an
EOAdaptorChannel.
|
static int |
executeUpdate(com.webobjects.eoaccess.EOAdaptorChannel channel,
String sql,
boolean autoCommit)
Shortcut to java.sql.Statement.executeUpdate(..) that operates on an
EOAdaptorChannel.
|
static int |
executeUpdateScript(com.webobjects.eoaccess.EOAdaptorChannel channel,
NSArray<String> sqlStatements)
Splits the given sqlscript and executes each of the statements in a
single transaction
|
static int |
executeUpdateScript(com.webobjects.eoaccess.EOAdaptorChannel channel,
NSArray<String> sqlStatements,
boolean ignoreFailures)
Splits the given sqlscript and executes each of the statements in a
single transaction
|
static int |
executeUpdateScript(com.webobjects.eoaccess.EOAdaptorChannel channel,
String sqlScript)
Splits the given sqlscript and executes each of the statements in a
single transaction
|
static int |
executeUpdateScript(com.webobjects.eoaccess.EOAdaptorChannel channel,
String sqlScript,
boolean ignoreFailures)
Splits the given sqlscript and executes each of the statements in a
single transaction
|
static int |
executeUpdateScriptFromResourceNamed(com.webobjects.eoaccess.EOAdaptorChannel channel,
String resourceName,
String frameworkName)
Executes a SQL script that is stored as a resource.
|
static CachedRowSet |
fetchRowSet(com.webobjects.eoaccess.EOAdaptorChannel adaptorChannel,
String query)
Using the backing connection from the adaptor context, executes the given
query and returns a CachedRowSet of the results.
|
static String |
jdbcTimestamp(com.webobjects.foundation.NSTimestamp t) |
static void |
processConnection(com.webobjects.eoaccess.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(com.webobjects.eoaccess.EOAdaptorChannel adaptorChannel,
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 com.webobjects.foundation.NSTimestampFormatter TIMESTAMP_FORMATTER
public static String jdbcTimestamp(com.webobjects.foundation.NSTimestamp t)
public static void _copyDatabaseDefinedByEOModelAndConnectionDictionaryToDatabaseWithConnectionDictionary(com.webobjects.eoaccess.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(com.webobjects.eoaccess.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 com.webobjects.eoaccess.EOAdaptorChannel adaptorChannelWithUserAndPassword(com.webobjects.eoaccess.EOModel model, String userName, String password)
model
- the model to base this connection off ofuserName
- the new usernamepassword
- the new passwordpublic static com.webobjects.eoaccess.EOAdaptorChannel adaptorChannelWithUserAndPassword(String adaptorName, NSDictionary originalConnectionDictionary, String userName, String password)
adaptorName
- the name of the adaptor to useroriginalConnectionDictionary
- the original connection dictionaryuserName
- the new usernamepassword
- the new passwordpublic static int executeUpdate(com.webobjects.eoaccess.EOAdaptorChannel channel, String sql) throws SQLException
channel
- the JDBCChannel to work withsql
- the sql to executeSQLException
- if there is a problempublic static int executeUpdate(com.webobjects.eoaccess.EOAdaptorChannel channel, String sql, boolean autoCommit) throws SQLException
channel
- the JDBCChannel to work withsql
- the sql to executeautoCommit
- if true, autocommit the connection after executingSQLException
- if there is a problempublic static int executeUpdateScript(com.webobjects.eoaccess.EOAdaptorChannel channel, String sqlScript) throws SQLException
channel
- the JDBCChannel to work withsqlScript
- the sql script to executeSQLException
- if there is a problempublic static int executeUpdateScript(com.webobjects.eoaccess.EOAdaptorChannel channel, String sqlScript, boolean ignoreFailures) throws SQLException
channel
- the JDBCChannel to work withsqlScript
- the sql script to executeignoreFailures
- if true, failures in a particular statement are ignoredSQLException
- if there is a problempublic static int executeUpdateScript(com.webobjects.eoaccess.EOAdaptorChannel channel, NSArray<String> sqlStatements) throws SQLException
channel
- the JDBCChannel to work withsqlStatements
- the array of sql scripts to executeSQLException
- if there is a problempublic static int executeUpdateScript(com.webobjects.eoaccess.EOAdaptorChannel channel, NSArray<String> sqlStatements, boolean ignoreFailures) throws SQLException
channel
- the JDBCChannel to work withsqlStatements
- the array of sql scripts to executeignoreFailures
- if true, failures in a particular statement are ignoredSQLException
- if there is a problempublic static int executeUpdateScriptFromResourceNamed(com.webobjects.eoaccess.EOAdaptorChannel channel, String resourceName, String frameworkName) throws SQLException, IOException
channel
- the channel to execute the scripts withinresourceName
- the name of the SQL script resourceframeworkName
- the name of the framework that contains the resourceSQLException
- if a SQL error occursIOException
- if an error occurs reading the scriptpublic static void dropTablesForModel(com.webobjects.eoaccess.EOAdaptorChannel channel, com.webobjects.eoaccess.EOModel model, boolean ignoreFailures) throws SQLException
channel
- the channel to use for executionmodel
- the model to drop tables forignoreFailures
- if true, failures in a particular statement are ignoredSQLException
- if something failspublic static void dropTablesForEntities(com.webobjects.eoaccess.EOAdaptorChannel channel, NSArray<com.webobjects.eoaccess.EOEntity> entities, boolean ignoreFailures) throws SQLException
channel
- the channel to use for executionentities
- the entities to drop tables forignoreFailures
- if true, failures in a particular statement are ignoredSQLException
- if something failspublic static void createTablesForModel(com.webobjects.eoaccess.EOAdaptorChannel channel, com.webobjects.eoaccess.EOModel model) throws SQLException
channel
- the channel to use for executionmodel
- the model to create tables forSQLException
- if something failspublic static void createTablesForEntities(com.webobjects.eoaccess.EOAdaptorChannel channel, NSArray<com.webobjects.eoaccess.EOEntity> entities) throws SQLException
channel
- the channel to use for executionentities
- the entities to create tables forSQLException
- if something failspublic static String databaseProductName(com.webobjects.eoaccess.EOAdaptorChannel channel)
channel
- the channelpublic static String databaseProductName(com.webobjects.eoaccess.EOModel model)
model
- the EOModelpublic static void processConnection(com.webobjects.eoaccess.EOAdaptorChannel adaptorChannel, ERXJDBCUtilities.IConnectionDelegate delegate) throws Exception
adaptorChannel
- the adaptor channeldelegate
- the connection delegateException
- if something goes wrongpublic static void executeQuery(com.webobjects.eoaccess.EOAdaptorChannel adaptorChannel, String query, ERXJDBCUtilities.IResultSetDelegate delegate) throws Exception
adaptorChannel
- the adaptor channelquery
- the query to executedelegate
- the processor delegateException
- if something goes wrongpublic static void processResultSetRows(com.webobjects.eoaccess.EOAdaptorChannel adaptorChannel, String query, ERXJDBCUtilities.IResultSetDelegate delegate) throws Exception
adaptorChannel
- the adaptor channelquery
- the query to executedelegate
- the processor delegateException
- if something goes wrongpublic static CachedRowSet fetchRowSet(com.webobjects.eoaccess.EOAdaptorChannel adaptorChannel, String query) throws Exception
adaptorChannel
- the adaptor channelquery
- the query to executeException
- if something goes wrongCopyright © 2002 – 2020 Project Wonder.