Accessing Database Servers (JDBC)¶
Driver support plugins will require access to the target database table on which its selected tasks will be run as part of a masking
job. The extensible driver support framework allows driver supports to access database servers using JDBC connections, utilizing the
existing masking web API. The same connection that is built during the test connection endpoint
(POST /database-connectors/{connector_id}/test
) on the masking engine is the same connection that will be returned by the service
provider's getTargetConnection method.
Example Driver Support Task¶
public class DisableTriggers implements Task {
...
private Connection targetConnection;
...
@Override
public String getTaskName() {
return "Disable Triggers";
}
@Override
public void setup(ComponentService serviceProvider) {
this.jobInfo = serviceProvider.getJobInfo();
this.targetConnection = serviceProvider.getTargetConnection();
this.logService = serviceProvider.getLogService();
}
...
@Override
public void preJobExecute() throws MaskingException {
long start = System.currentTimeMillis();
this.triggersOnMaskedTables = findEnabledTriggersOnMaskedTables();
try (Statement statement = targetConnection.createStatement()) {
for (Map.Entry<String, String> entry : triggersOnMaskedTables.entrySet()) {
String triggerName = entry.getKey();
String tableName = entry.getValue();
String disableTriggersStatement =
String.format(MODIFY_TRIGGERS_SQL, "DISABLE", triggerName, tableName);
try {
statement.execute(disableTriggersStatement);
} catch (SQLException e) {
String errorMessage = ...;
logService.error(errorMessage + e);
throw new MaskingException(errorMessage, e);
}
}
} catch (SQLException e) {
String errorMessage = "Error creating a statement on target connection.";
logService.error(errorMessage + e);
throw new MaskingException(errorMessage, e);
}
}
}
Some methods have been omitted for brevity.