com.unboundid.directory.sdk.sync.scripting
Class ScriptedJDBCSyncDestination

java.lang.Object
  extended by com.unboundid.directory.sdk.sync.scripting.ScriptedJDBCSyncDestination
All Implemented Interfaces:
Configurable

@Extensible
@SynchronizationServerExtension(appliesToLocalContent=false,
                                appliesToSynchronizedContent=true)
public abstract class ScriptedJDBCSyncDestination
extends java.lang.Object
implements Configurable

This class defines an API that must be implemented by scripted extensions in order to synchronize data into a relational database. Since the UnboundID Synchronization Server is LDAP-centric, this API allows you to take LDAP entries and split them out into database content and make the appropriate updates. The lifecycle of a sync operation is as follows:

  1. Detect change at the synchronization source
  2. Fetch full source entry
  3. Perform any mappings and compute the equivalent destination entry
  4. Fetch full destination entry
  5. Diff the computed destination entry and actual destination entry
  6. Apply the minimal set of changes at the destination to bring it in sync
This implies that the 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 Synchronization 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 Synchronization 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.

Configuring Groovy-Scripted JDBC Sync Destinations

In order to configure a scripted JDBC sync destination based on this API and written in the Groovy scripting language, use a command like:
      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 Summary
ScriptedJDBCSyncDestination()
           
 
Method Summary
abstract  void createEntry(TransactionContext ctx, com.unboundid.ldap.sdk.Entry entryToCreate, SyncOperation operation)
          Creates a full database "entry", corresponding to the 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 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 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 the LDAP Entry that is passed in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScriptedJDBCSyncDestination

public ScriptedJDBCSyncDestination()
Method Detail

defineConfigArguments

public void defineConfigArguments(com.unboundid.util.args.ArgumentParser parser)
                           throws com.unboundid.util.args.ArgumentException
Updates the provided argument parser to define any configuration arguments which may be used by this extension. The argument parser may also be updated to define relationships between arguments (e.g., to specify required, exclusive, or dependent argument sets).

Specified by:
defineConfigArguments in interface Configurable
Parameters:
parser - The argument parser to be updated with the configuration arguments which may be used by this extension.
Throws:
com.unboundid.util.args.ArgumentException - If a problem is encountered while updating the provided argument parser.

initializeJDBCSyncDestination

@ThreadSafety(level=METHOD_NOT_THREADSAFE)
public 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. Any initialization should be performed here.

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 Synchronization 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.

Parameters:
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.

finalizeJDBCSyncDestination

@ThreadSafety(level=METHOD_NOT_THREADSAFE)
public void finalizeJDBCSyncDestination(TransactionContext ctx)
This hook is called when a Sync Pipe shuts down, or when the Resync process shuts down. Any clean-up should be performed here.

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 Synchronization 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.

Parameters:
ctx - a TransactionContext which provides a valid JDBC connection to the database.

fetchEntry

@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
Return a full destination entry (in LDAP form) from the database, corresponding to the the source 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 Synchronization 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.

Parameters:
ctx - a TransactionContext which provides a valid JDBC connection to the database.
destEntryMappedFromSrc - the LDAP entry which corresponds to the database "entry" to fetch
operation - the sync operation for this change
Returns:
a full LDAP Entry, or null if no such entry exists.
Throws:
java.sql.SQLException - if there is an error fetching the entry

createEntry

@ThreadSafety(level=METHOD_THREADSAFE)
public abstract void createEntry(TransactionContext ctx,
                                              com.unboundid.ldap.sdk.Entry entryToCreate,
                                              SyncOperation operation)
                          throws java.sql.SQLException
Creates a full database "entry", corresponding to the the LDAP 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 Synchronization 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.

Parameters:
ctx - a TransactionContext which provides a valid JDBC connection to the database.
entryToCreate - the LDAP entry which corresponds to the database "entry" to create
operation - the sync operation for this change
Throws:
java.sql.SQLException - if there is an error creating the entry

modifyEntry

@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
Modify an "entry" in the database, corresponding to the the LDAP 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 Synchronization 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.

Parameters:
ctx - a TransactionContext which provides a valid JDBC connection to the database.
fetchedDestEntry - the LDAP entry which corresponds to the database "entry" to modify
modsToApply - a list of Modification objects which should be applied
operation - the sync operation for this change
Throws:
java.sql.SQLException - if there is an error modifying the entry

deleteEntry

@ThreadSafety(level=METHOD_THREADSAFE)
public abstract void deleteEntry(TransactionContext ctx,
                                              com.unboundid.ldap.sdk.Entry fetchedDestEntry,
                                              SyncOperation operation)
                          throws java.sql.SQLException
Delete a full "entry" from the database, corresponding to the the LDAP 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 Synchronization 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.

Parameters:
ctx - a TransactionContext which provides a valid JDBC connection to the database.
fetchedDestEntry - the LDAP entry which corresponds to the database "entry" to delete
operation - the sync operation for this change
Throws:
java.sql.SQLException - if there is an error deleting the entry