Class JdbcPersistorImpl
- All Implemented Interfaces:
Persistor
A basic JDBC Implementation of a Persistor. This implementation expects the user to provide the following configuration in Transformers persistence.conf configuration file
persistence.conf
persistence-classid com/caplin/transformer/persistence/JdbcPersistorImpl
add-database-params
init-string <jdbc url>
driver-name <jdbc driver - must be explicitly added to transformers jvm-global-classpath>
username <db user>
password <db password>
extra-params <timeout in seconds for Connection.isValid()> <timeout in seconds for queryTimeout(), -1 to use driver defaults>
end-database-params
java.conf
jvm-global-classpath <path_to_jdbc_driver>
end-database-params
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCall a stored procedure in the database.intDelete one or more rows from a tableonQuery(String table, String query, QueryParams params) Query the database for results.voidCalled when transformer shuts down to close open connections and release acquired resourcesintImplement this method to handle update or insert callbacks.
-
Constructor Details
-
JdbcPersistorImpl
- Throws:
Exception
-
-
Method Details
-
onUpsert
Description copied from interface:PersistorImplement this method to handle update or insert callbacks. This method is expected to update an existing row or insert a new one if the update did not affect any rows
This method should attempt to update an existing row first by setting all the values given in data and using the entries of this map where the key matches
keyanded together in the where clause like:"key1=value1 and key2=value2". If the update did not affect any rows, then an insert should be executed with the data given- Specified by:
onUpsertin interfacePersistor- Parameters:
table- The table to be modifiedkeys- Map containing column/value pairs to be used in the where clause for updates. If no row matches the criteria, a combination ofkeysanddatais used as data for the rows, where entries indatatake precedence over entries inkeysdata- Map containing column/value pairs to be set in the row identified bykeys- Returns:
- -1 on error or >=0 affected rows on success
-
onQuery
Description copied from interface:PersistorQuery the database for results.
Queries the database with
querybeing a valid sql selection andargsbeing a list of arguments that get bound to ? in the query string- Specified by:
onQueryin interfacePersistor- Parameters:
table- The table name to execute the query on.query- a valid sql where clause or an empty string for all rows.params-QueryParamsto be used for the query- Returns:
- null on error, an empty array if there were no results or an array holding all the rows returned by the query.
-
onDelete
Description copied from interface:PersistorDelete one or more rows from a table
Delete rows where the all the columns specified in selector match their specified values
-
onCall
Description copied from interface:PersistorCall a stored procedure in the database.
Calls a stored procedure in the database with
procedureNamebeing a valid procedure name within the database andargsbeing a list of arguments to pass to the stored procedure. -
onShutdown
public void onShutdown()Description copied from interface:PersistorCalled when transformer shuts down to close open connections and release acquired resources
- Specified by:
onShutdownin interfacePersistor
-