use of com.adaptris.core.jdbc.JdbcService in project interlok by adaptris.
the class JdbcDataCaptureServiceCase method buildExamples.
@Override
protected List<JdbcService> buildExamples() {
List<JdbcService> returnedObjects = new ArrayList<>();
JdbcIteratingDataCaptureServiceImpl service = newService();
JdbcConnection connection = new JdbcConnection();
connection.setConnectUrl("jdbc:mysql://localhost:3306/mydatabase");
connection.setConnectionAttempts(2);
connection.setConnectionRetryInterval(new TimeInterval(3L, "SECONDS"));
service.setConnection(connection);
service.setIterates(true);
service.setIterationXpath("/xpath/to/repeating/element");
String columns = "";
String values = "";
for (CaptureClassesForSamples qc : CaptureClassesForSamples.values()) {
service.addStatementParameter(qc.create());
columns += qc.name() + ", ";
values += "?, ";
}
columns = columns.substring(0, columns.lastIndexOf(','));
values = values.substring(0, values.lastIndexOf(','));
service.setStatement("insert into mytable (" + columns + ") values (" + values + ");");
JdbcIteratingDataCaptureServiceImpl service2 = newService();
JdbcConnection connection2 = new JdbcConnection();
connection2.setConnectUrl("jdbc:mysql://localhost:3306/mydatabase");
connection2.setConnectionAttempts(2);
connection2.setConnectionRetryInterval(new TimeInterval(3L, "SECONDS"));
service2.setConnection(connection2);
service2.setIterates(true);
service2.setIterationXpath("/xpath/to/repeating/element");
service2.setParameterApplicator(new NamedParameterApplicator());
String columns2 = "";
String values2 = "";
int paramCount = 0;
for (CaptureClassesForSamples qc : CaptureClassesForSamples.values()) {
paramCount++;
NamedStatementParameter jdbcStatementParameter = (NamedStatementParameter) qc.create();
jdbcStatementParameter.setName("param" + paramCount);
service2.addStatementParameter(jdbcStatementParameter);
columns2 += qc.name() + ", ";
values2 += "#param" + paramCount + ", ";
}
columns2 = columns2.substring(0, columns2.lastIndexOf(','));
values2 = values2.substring(0, values2.lastIndexOf(','));
service2.setStatement("insert into mytable (" + columns2 + ") values (" + values2 + ");");
returnedObjects.add(service);
returnedObjects.add(service2);
return returnedObjects;
}
use of com.adaptris.core.jdbc.JdbcService in project interlok by adaptris.
the class JdbcQueryServiceCase method buildExamples.
@Override
protected List<JdbcService> buildExamples() {
ArrayList<JdbcService> objects = new ArrayList<>();
JdbcDataQueryService service = new JdbcDataQueryService();
try {
JdbcConnection connection = new JdbcConnection("jdbc:mysql://localhost:3306/mydatabase", "com.mysql.jdbc.Driver");
KeyValuePairSet connectionProperties = new KeyValuePairSet();
connectionProperties.add(new KeyValuePair("useCompression", "true"));
connection.setConnectionProperties(connectionProperties);
connection.setConnectionAttempts(2);
connection.setConnectionRetryInterval(new TimeInterval(3L, "SECONDS"));
service.setConnection(connection);
service.setResultSetTranslator(configureForExample(createTranslatorForConfig()));
String additionalParams = "";
boolean first = true;
for (QueryClasses qc : QueryClasses.values()) {
service.addStatementParameter(qc.create());
if (first) {
additionalParams += qc.name() + "=?";
first = false;
} else {
additionalParams += " AND " + qc.name() + "=?";
}
}
service.setStatementCreator(new ConfiguredSQLStatement("SELECT StringColumn1, DateColumn2, IntegerColumn3, BlobColumn, ClobColumn FROM tablename WHERE " + additionalParams));
} catch (Exception e) {
throw new RuntimeException(e);
}
objects.add(service);
return objects;
}
use of com.adaptris.core.jdbc.JdbcService in project interlok by adaptris.
the class JdbcServiceExample method retrieveObjectsForSampleConfig.
@Override
protected final List retrieveObjectsForSampleConfig() {
ArrayList result = new ArrayList();
List<JdbcService> services = buildExamples();
if (services.size() == 0) {
for (ConnectionBuilder connectionBuilder : ConnectionBuilder.values()) {
JdbcService s = (JdbcService) retrieveObjectForSampleConfig();
s.setConnection(connectionBuilder.build());
result.add(s);
}
} else {
for (JdbcService s : services) {
for (ConnectionBuilder connectionBuilder : ConnectionBuilder.values()) {
JdbcService copy = roundTrip(s);
copy.setConnection(connectionBuilder.build());
result.add(copy);
}
}
}
return result;
}
Aggregations