Class JDBCSyncDestination
- java.lang.Object
-
- com.unboundid.directory.sdk.sync.api.JDBCSyncDestination
-
- All Implemented Interfaces:
Configurable
,ExampleUsageProvider
,UnboundIDExtension
@Extensible @SynchronizationServerExtension(appliesToLocalContent=false, appliesToSynchronizedContent=true) public abstract class JDBCSyncDestination extends java.lang.Object implements UnboundIDExtension, Configurable, ExampleUsageProvider
This class defines an API that must be implemented by extensions in order to synchronize data into a relational database. Since the Ping Identity Data Sync 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:- Detect change at the synchronization source
- Fetch full source entry
- Perform any mappings and compute the equivalent destination entry
- Fetch full destination entry
- Diff the computed destination entry and actual destination entry
- Apply the minimal set of changes at the destination to bring it in sync
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 how the method returns. If a method call returns successfully, then the transaction will be committed. If an exception is thrown, then the transaction will be rolled back. In rare situations, it might be necessary for an implementation to perform its own commit or rollback of transactions by calling methods onTransactionContext
.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. For these reasons implementers should refrain from handling or wrapping anySQLException
and instead let it be handled by the calling code.
Configuring JDBC Sync Destinations
In order to configure a JDBC sync destination based on this API and written in Java, use a command like:dsconfig create-sync-destination \ --destination-name "{destination-name}" \ --type third-party-jdbc \ --set "server:{server-name}" \ --set "extension-class:{class-name}" \ --set "extension-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 Java 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 extension-argument:{name=value}
" option should be provided multiple times.
-
-
Constructor Summary
Constructors Constructor Description JDBCSyncDestination()
Creates a new instance of this JDBC Sync Destination.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
createEntry(TransactionContext ctx, Entry entryToCreate, SyncOperation operation)
Creates a full database "entry", corresponding to the LDAPEntry
that is passed in.void
defineConfigArguments(ArgumentParser parser)
Updates the provided argument parser to define any configuration arguments which may be used by this extension.abstract void
deleteEntry(TransactionContext ctx, Entry fetchedDestEntry, SyncOperation operation)
Delete a full "entry" from the database, corresponding to the LDAPEntry
that is passed in.abstract Entry
fetchEntry(TransactionContext ctx, Entry destEntryMappedFromSrc, SyncOperation operation)
Return a full destination entry (in LDAP form) from the database, corresponding to the sourceEntry
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.java.util.Map<java.util.List<java.lang.String>,java.lang.String>
getExamplesArgumentSets()
Retrieves a map containing examples of configurations that may be used for this extension.abstract java.lang.String[]
getExtensionDescription()
Retrieves a human-readable description for this extension.abstract java.lang.String
getExtensionName()
Retrieves a human-readable name for this extension.void
initializeJDBCSyncDestination(TransactionContext ctx, SyncServerContext serverContext, JDBCSyncDestinationConfig config, 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, Entry fetchedDestEntry, java.util.List<Modification> modsToApply, SyncOperation operation)
Modify an "entry" in the database, corresponding to the LDAPEntry
that is passed in.
-
-
-
Constructor Detail
-
JDBCSyncDestination
public JDBCSyncDestination()
Creates a new instance of this JDBC Sync Destination. All sync destination implementations must include a default constructor, but any initialization should generally be done in theinitializeJDBCSyncDestination(com.unboundid.directory.sdk.sync.types.TransactionContext, com.unboundid.directory.sdk.sync.types.SyncServerContext, com.unboundid.directory.sdk.sync.config.JDBCSyncDestinationConfig, com.unboundid.util.args.ArgumentParser)
method.
-
-
Method Detail
-
getExtensionName
public abstract java.lang.String getExtensionName()
Retrieves a human-readable name for this extension.- Specified by:
getExtensionName
in interfaceUnboundIDExtension
- Returns:
- A human-readable name for this extension.
-
getExtensionDescription
public abstract java.lang.String[] getExtensionDescription()
Retrieves a human-readable description for this extension. Each element of the array that is returned will be considered a separate paragraph in generated documentation.- Specified by:
getExtensionDescription
in interfaceUnboundIDExtension
- Returns:
- A human-readable description for this extension, or
null
or an empty array if no description should be available.
-
getExamplesArgumentSets
public java.util.Map<java.util.List<java.lang.String>,java.lang.String> getExamplesArgumentSets()
Retrieves a map containing examples of configurations that may be used for this extension. The map key should be a list of sample arguments, and the corresponding value should be a description of the behavior that will be exhibited by the extension when used with that configuration.- Specified by:
getExamplesArgumentSets
in interfaceExampleUsageProvider
- Returns:
- A map containing examples of configurations that may be used for
this extension. It may be
null
or empty if there should not be any example argument sets.
-
defineConfigArguments
public void defineConfigArguments(ArgumentParser parser) throws 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 interfaceConfigurable
- Parameters:
parser
- The argument parser to be updated with the configuration arguments which may be used by this extension.- Throws:
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, ArgumentParser parser)
This hook is called when a Sync Pipe first starts up, or when the resync process first starts up. Any initialization of this sync destination should be performed here. This method should generally store theSyncServerContext
in a class member so that it can be used elsewhere in the implementation.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. See the class level documentation for warnings and additional details.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 of this sync destination 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 Data Sync Server will always commit or rollback the transaction automatically, depending on whether this method returns normally or throws an exception. See the class level documentation for warnings and additional details.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 Entry fetchEntry(TransactionContext ctx, Entry destEntryMappedFromSrc, SyncOperation operation) throws java.sql.SQLException
Return a full destination entry (in LDAP form) from the database, corresponding to the sourceEntry
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()
), thedestEntryMappedFromSrc
will have the new DN; the old DN can be obtained by callingSyncOperation.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. See the class level documentation for warnings and additional details.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 fetchoperation
- 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, Entry entryToCreate, SyncOperation operation) throws java.sql.SQLException
Creates a full database "entry", corresponding to the LDAPEntry
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. See the class level documentation for warnings and additional details.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 createoperation
- 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, Entry fetchedDestEntry, java.util.List<Modification> modsToApply, SyncOperation operation) throws java.sql.SQLException
Modify an "entry" in the database, corresponding to the LDAPEntry
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()
), thefetchedDestEntry
will have the old DN; the new DN can be obtained by callingSyncOperation.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. See the class level documentation for warnings and additional details.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 modifymodsToApply
- a list of Modification objects which should be appliedoperation
- 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, Entry fetchedDestEntry, SyncOperation operation) throws java.sql.SQLException
Delete a full "entry" from the database, corresponding to the LDAPEntry
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. See the class level documentation for warnings and additional details.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 deleteoperation
- the sync operation for this change- Throws:
java.sql.SQLException
- if there is an error deleting the entry
-
-