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 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,
String userName,
String password)
Returns an adaptor channel with the given username and password.
|
static EOAdaptorChannel |
adaptorChannelWithUserAndPassword(String adaptorName,
NSDictionary originalConnectionDictionary,
String userName,
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 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 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,
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,
String sql)
Shortcut to java.sql.Statement.executeUpdate(..) that operates on an
EOAdaptorChannel.
|
static int |
executeUpdate(EOAdaptorChannel channel,
String sql,
boolean autoCommit)
Shortcut to java.sql.Statement.executeUpdate(..) that operates on an
EOAdaptorChannel.
|
static int |
executeUpdateScript(EOAdaptorChannel channel,
NSArray<String> sqlStatements)
Splits the given sqlscript and executes each of the statements in a
single transaction
|
static int |
executeUpdateScript(EOAdaptorChannel channel,
NSArray<String> sqlStatements,
boolean ignoreFailures)
Splits the given sqlscript and executes each of the statements in a
single transaction
|
static int |
executeUpdateScript(EOAdaptorChannel channel,
String sqlScript)
Splits the given sqlscript and executes each of the statements in a
single transaction
|
static int |
executeUpdateScript(EOAdaptorChannel channel,
String sqlScript,
boolean ignoreFailures)
Splits the given sqlscript and executes each of the statements in a
single transaction
|
static int |
executeUpdateScriptFromResourceNamed(EOAdaptorChannel channel,
String resourceName,
String frameworkName)
Executes a SQL script that is stored as a resource.
|
static CachedRowSet |
fetchRowSet(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(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,
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 NSTimestampFormatter TIMESTAMP_FORMATTER
public static 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, String userName, String password)
model
- the model to base this connection off ofuserName
- the new usernamepassword
- the new passwordpublic static 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(EOAdaptorChannel channel, String sql) throws SQLException
channel
- the JDBCChannel to work withsql
- the sql to executeSQLException
- if there is a problempublic static int executeUpdate(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(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(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(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(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(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(EOAdaptorChannel channel, 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(EOAdaptorChannel channel, NSArray<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(EOAdaptorChannel channel, EOModel model) throws SQLException
channel
- the channel to use for executionmodel
- the model to create tables forSQLException
- if something failspublic static void createTablesForEntities(EOAdaptorChannel channel, NSArray<EOEntity> entities) throws SQLException
channel
- the channel to use for executionentities
- the entities to create tables forSQLException
- if something failspublic static String databaseProductName(EOAdaptorChannel channel)
channel
- the channelpublic static String databaseProductName(EOModel model)
model
- the EOModelpublic static void processConnection(EOAdaptorChannel adaptorChannel, ERXJDBCUtilities.IConnectionDelegate delegate) throws Exception
adaptorChannel
- the adaptor channeldelegate
- the connection delegateException
- if something goes wrongpublic static void executeQuery(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(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(EOAdaptorChannel adaptorChannel, String query) throws Exception
adaptorChannel
- the adaptor channelquery
- the query to executeException
- if something goes wrongCopyright © 2002 – 2024 Project Wonder.