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
-
Method Summary
Modifier and TypeMethodDescriptionCall a stored procedure in the database.int
Delete one or more rows from a tableonQuery
(String table, String query, QueryParams params) Query the database for results.void
Called when transformer shuts down to close open connections and release acquired resourcesint
Implement this method to handle update or insert callbacks.
-
Constructor Details
-
JdbcPersistorImpl
- Throws:
Exception
-
-
Method Details
-
onUpsert
Description copied from interface:Persistor
Implement 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
key
anded 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:
onUpsert
in 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 ofkeys
anddata
is used as data for the rows, where entries indata
take precedence over entries inkeys
data
- 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:Persistor
Query the database for results.
Queries the database with
query
being a valid sql selection andargs
being a list of arguments that get bound to ? in the query string- Specified by:
onQuery
in 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
-QueryParams
to 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:Persistor
Delete 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:Persistor
Call a stored procedure in the database.
Calls a stored procedure in the database with
procedureName
being a valid procedure name within the database andargs
being a list of arguments to pass to the stored procedure. -
onShutdown
public void onShutdown()Description copied from interface:Persistor
Called when transformer shuts down to close open connections and release acquired resources
- Specified by:
onShutdown
in interfacePersistor
-