@Extensible @SynchronizationServerExtension(appliesToLocalContent=false, appliesToSynchronizedContent=true) public abstract class ScriptedJDBCSyncDestination extends java.lang.Object implements Configurable
fetchEntry(TransactionContext, Entry,
SyncOperation)
method will
always be called once prior to any of the other methods in this class.
In several places a TransactionContext
is provided, which allows
controlled access to the target database. By default, methods in this class
are always provided with a fresh connection (i.e. a new transaction), and the
Data Sync Server will always commit or rollback the transaction
automatically, depending on whether the method returned normally or threw an
exception. Implementers may optionally perform their own transaction
management within these methods if necessary.
Several of these methods throw SQLException
, which should be used in
the case of any database access error. For other types of errors, runtime
exceptions may be used (IllegalStateException, NullPointerException, etc.).
The Data Sync Server will automatically retry operations that fail,
up to a configurable amount of attempts. The exception to this rule is if a
SQLException is thrown with a SQL state string beginning with "08"; this
indicates a connection error, and in this case the operation is retried
indefinitely.
dsconfig create-sync-destination \ --destination-name "{destination-name}" \ --type groovy-scripted-jdbc \ --set "server:{server-name}" \ --set "script-class:{class-name}" \ --set "script-argument:{name=value}"where "{destination-name}" is the name to use for the JDBC sync destination instance, "{server-name}" is the name of the JDBC external server that will be used as the sync destination, "{class-name}" is the fully-qualified name of the Groovy class written using this API, and "{name=value}" represents name-value pairs for any arguments to provide to the JDBC sync destination. If multiple arguments should be provided to the JDBC sync destination, then the "
--set script-argument:{name=value}
" option should be
provided multiple times.Constructor and Description |
---|
ScriptedJDBCSyncDestination() |
Modifier and Type | Method and Description |
---|---|
abstract void |
createEntry(TransactionContext ctx,
com.unboundid.ldap.sdk.Entry entryToCreate,
SyncOperation operation)
Creates a full database "entry", corresponding to the LDAP
Entry that is passed in. |
void |
defineConfigArguments(com.unboundid.util.args.ArgumentParser parser)
Updates the provided argument parser to define any configuration arguments
which may be used by this extension.
|
abstract void |
deleteEntry(TransactionContext ctx,
com.unboundid.ldap.sdk.Entry fetchedDestEntry,
SyncOperation operation)
Delete a full "entry" from the database, corresponding to the LDAP
Entry that is passed in. |
abstract com.unboundid.ldap.sdk.Entry |
fetchEntry(TransactionContext ctx,
com.unboundid.ldap.sdk.Entry destEntryMappedFromSrc,
SyncOperation operation)
Return a full destination entry (in LDAP form) from the database,
corresponding to the source
Entry that is passed in. |
void |
finalizeJDBCSyncDestination(TransactionContext ctx)
This hook is called when a Sync Pipe shuts down, or when the Resync process
shuts down.
|
void |
initializeJDBCSyncDestination(TransactionContext ctx,
SyncServerContext serverContext,
JDBCSyncDestinationConfig config,
com.unboundid.util.args.ArgumentParser parser)
This hook is called when a Sync Pipe first starts up, or when the Resync
process first starts up.
|
abstract void |
modifyEntry(TransactionContext ctx,
com.unboundid.ldap.sdk.Entry fetchedDestEntry,
java.util.List<com.unboundid.ldap.sdk.Modification> modsToApply,
SyncOperation operation)
Modify an "entry" in the database, corresponding to the LDAP
Entry that is passed in. |
public ScriptedJDBCSyncDestination()
public void defineConfigArguments(com.unboundid.util.args.ArgumentParser parser) throws com.unboundid.util.args.ArgumentException
defineConfigArguments
in interface Configurable
parser
- The argument parser to be updated with the configuration
arguments which may be used by this extension.com.unboundid.util.args.ArgumentException
- If a problem is encountered while updating the
provided argument parser.@ThreadSafety(level=METHOD_NOT_THREADSAFE) public void initializeJDBCSyncDestination(TransactionContext ctx, SyncServerContext serverContext, JDBCSyncDestinationConfig config, com.unboundid.util.args.ArgumentParser parser)
A TransactionContext
is provided, which allows
controlled access to the target database. The context will contain a fresh
fresh connection (i.e. a new transaction), and the Data Sync Server
will always commit or rollback the transaction automatically, depending on
whether this method returns normally or throws an exception. Implementers
may optionally perform their own transaction management within this method
if necessary.
The default implementation is empty.
ctx
- a TransactionContext which provides a valid JDBC connection to the
database.serverContext
- A handle to the server context for the server in
which this extension is running.config
- The general configuration for this sync destination.parser
- The argument parser which has been initialized from
the configuration for this JDBC sync destination.@ThreadSafety(level=METHOD_NOT_THREADSAFE) public void finalizeJDBCSyncDestination(TransactionContext ctx)
A TransactionContext
is provided, which allows
controlled access to the target database. The context will contain a fresh
fresh connection (i.e. a new transaction), and the Data Sync Server
will always commit or rollback the transaction automatically, depending on
whether this method returns normally or throws an exception. Implementers
may optionally perform their own transaction management within this method
if necessary.
The default implementation is empty.
ctx
- a TransactionContext which provides a valid JDBC connection to the
database.@ThreadSafety(level=METHOD_THREADSAFE) public abstract com.unboundid.ldap.sdk.Entry fetchEntry(TransactionContext ctx, com.unboundid.ldap.sdk.Entry destEntryMappedFromSrc, SyncOperation operation) throws java.sql.SQLException
Entry
that is passed in. This
method should perform any queries necessary to gather the latest values for
all the attributes to be synchronized and return them in an Entry.
Note that the if the source entry was renamed (see
SyncOperation.isModifyDN()
), the destEntryMappedFromSrc
will have the new DN; the old DN can be obtained by calling
SyncOperation.getDestinationEntryBeforeChange()
and getting the DN
from there. This method should return the entry in its existing form
(i.e. with the old DN, before it is changed).
A TransactionContext
is provided, which allows
controlled access to the target database. The context will contain a fresh
fresh connection (i.e. a new transaction), and the Data Sync Server
will always commit or rollback the transaction automatically, depending on
whether this method returns normally or throws an exception. Implementers
may optionally perform their own transaction management within this method
if necessary.
This method must be thread safe, as it will be called repeatedly and concurrently by each of the Sync Pipe worker threads as they process entries.
ctx
- a TransactionContext which provides a valid JDBC connection to the
database.destEntryMappedFromSrc
- the LDAP entry which corresponds to the database
"entry" to fetchoperation
- the sync operation for this changejava.sql.SQLException
- if there is an error fetching the entry@ThreadSafety(level=METHOD_THREADSAFE) public abstract void createEntry(TransactionContext ctx, com.unboundid.ldap.sdk.Entry entryToCreate, SyncOperation operation) throws java.sql.SQLException
Entry
that is passed in. This method should perform any inserts and
updates necessary to make sure the entry is fully created on the database.
A TransactionContext
is provided, which allows
controlled access to the target database. The context will contain a fresh
fresh connection (i.e. a new transaction), and the Data Sync Server
will always commit or rollback the transaction automatically, depending on
whether this method returns normally or throws an exception. Implementers
may optionally perform their own transaction management within this method
if necessary.
This method must be thread safe, as it will be called repeatedly and concurrently by the Sync Pipe worker threads as they process CREATE operations.
ctx
- a TransactionContext which provides a valid JDBC connection to the
database.entryToCreate
- the LDAP entry which corresponds to the database "entry" to createoperation
- the sync operation for this changejava.sql.SQLException
- if there is an error creating the entry@ThreadSafety(level=METHOD_THREADSAFE) public abstract void modifyEntry(TransactionContext ctx, com.unboundid.ldap.sdk.Entry fetchedDestEntry, java.util.List<com.unboundid.ldap.sdk.Modification> modsToApply, SyncOperation operation) throws java.sql.SQLException
Entry
that is passed in. This method may perform multiple updates
(including inserting or deleting rows) in order to fully synchronize the
entire entry on the database.
Note that the if the source entry was renamed (see
SyncOperation.isModifyDN()
), the
fetchedDestEntry
will have the old DN; the new DN can
be obtained by calling
SyncOperation.getDestinationEntryAfterChange()
and getting the DN
from there.
A TransactionContext
is provided, which allows
controlled access to the target database. The context will contain a fresh
fresh connection (i.e. a new transaction), and the Data Sync Server
will always commit or rollback the transaction automatically, depending on
whether this method returns normally or throws an exception. Implementers
may optionally perform their own transaction management within this method
if necessary.
This method must be thread safe, as it will be called repeatedly and concurrently by the Sync Pipe worker threads as they process MODIFY operations.
ctx
- a TransactionContext which provides a valid JDBC connection to the
database.fetchedDestEntry
- the LDAP entry which corresponds to the database "entry" to modifymodsToApply
- a list of Modification objects which should be appliedoperation
- the sync operation for this changejava.sql.SQLException
- if there is an error modifying the entry@ThreadSafety(level=METHOD_THREADSAFE) public abstract void deleteEntry(TransactionContext ctx, com.unboundid.ldap.sdk.Entry fetchedDestEntry, SyncOperation operation) throws java.sql.SQLException
Entry
that is passed in. This method may perform multiple deletes
or updates if necessary to fully delete the entry from the database.
A TransactionContext
is provided, which allows
controlled access to the target database. The context will contain a fresh
fresh connection (i.e. a new transaction), and the Data Sync Server
will always commit or rollback the transaction automatically, depending on
whether this method returns normally or throws an exception. Implementers
may optionally perform their own transaction management within this method
if necessary.
This method must be thread safe, as it will be called repeatedly and concurrently by the Sync Pipe worker threads as they process DELETE operations.
ctx
- a TransactionContext which provides a valid JDBC connection to the
database.fetchedDestEntry
- the LDAP entry which corresponds to the database "entry" to deleteoperation
- the sync operation for this changejava.sql.SQLException
- if there is an error deleting the entry