use of com.adaptris.core.jdbc.JdbcConnection 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.JdbcConnection in project interlok by adaptris.
the class JdbcDataCaptureServiceCase method createJdbcConnection.
protected JdbcConnection createJdbcConnection() {
JdbcConnection connection = new JdbcConnection();
connection.setConnectUrl(PROPERTIES.getProperty(JDBC_CAPTURE_SERVICE_URL));
connection.setDriverImp(PROPERTIES.getProperty(JDBC_CAPTURE_SERVICE_DRIVER));
connection.setAutoCommit(true);
return connection;
}
use of com.adaptris.core.jdbc.JdbcConnection in project interlok by adaptris.
the class JdbcDataCaptureServiceCase method createIteratesService.
protected JdbcDataCaptureService createIteratesService(boolean useStatementParam) throws Exception {
JdbcDataCaptureService service = new JdbcDataCaptureService();
JdbcConnection connection = new JdbcConnection();
service.setConnection(createJdbcConnection());
service.setIterates(true);
service.setIterationXpath(XPATH_ITERATE);
service.addStatementParameter(new StatementParameter(null, String.class, QueryType.payload));
if (useStatementParam) {
service.addStatementParameter(new StatementParameter(XPATH_ITERATE_RELATIVE, String.class, QueryType.xpath));
} else {
service.addStatementParameter(new StringStatementParameter(XPATH_ITERATE_RELATIVE, QueryType.xpath, null, null));
}
service.setStatement("insert into jdbc_data_capture_iteration (payload_value, xpath_value) values (?, ?)");
return service;
}
use of com.adaptris.core.jdbc.JdbcConnection in project interlok by adaptris.
the class JdbcQueryServiceCase method createMetadataService.
protected static JdbcDataQueryService createMetadataService(boolean createConnection) {
JdbcDataQueryService service = new JdbcDataQueryService();
if (createConnection) {
JdbcConnection connection = new JdbcConnection(PROPERTIES.getProperty(JDBC_QUERYSERVICE_URL), PROPERTIES.getProperty(JDBC_QUERYSERVICE_DRIVER));
service.setConnection(connection);
}
service.setStatementCreator(new ConfiguredSQLStatement(QUERY_SQL));
StatementParameter sp = new StatementParameter();
sp.setQueryClass("java.lang.String");
sp.setQueryType(StatementParameter.QueryType.metadata);
sp.setQueryString(ADAPTER_ID_KEY);
service.addStatementParameter(sp);
return service;
}
use of com.adaptris.core.jdbc.JdbcConnection in project interlok by adaptris.
the class JdbcQueryServiceCase method createXmlService.
protected static JdbcDataQueryService createXmlService() {
JdbcDataQueryService service = new JdbcDataQueryService();
JdbcConnection connection = new JdbcConnection(PROPERTIES.getProperty(JDBC_QUERYSERVICE_URL), PROPERTIES.getProperty(JDBC_QUERYSERVICE_DRIVER));
service.setConnection(connection);
service.setStatementCreator(new ConfiguredSQLStatement(QUERY_SQL));
StatementParameter sp = new StatementParameter();
sp.setQueryClass("java.lang.String");
sp.setQueryType(StatementParameter.QueryType.xpath);
sp.setQueryString("/root/document");
service.addStatementParameter(sp);
return service;
}
Aggregations