use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class JdbcServiceExample method applyDefaultConfig.
public static DatabaseConnection applyDefaultConfig(DatabaseConnection connection) {
connection.setConnectionAttempts(2);
connection.setUsername("my_db_username");
connection.setPassword("plain or encoded password");
connection.setConnectionRetryInterval(new TimeInterval(3L, "SECONDS"));
KeyValuePairSet connectionProps = new KeyValuePairSet();
connectionProps.add(new KeyValuePair("dontTrackOpenResources", "true"));
connectionProps.add(new KeyValuePair("autoReconnect", "true"));
connection.setConnectionProperties(connectionProps);
return connection;
}
use of com.adaptris.util.TimeInterval 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.util.TimeInterval in project interlok by adaptris.
the class SequenceNumberCase method testAutoCreateDatabase_WithTimeout.
@Test
public void testAutoCreateDatabase_WithTimeout() throws Exception {
Connection c = createConnection();
dropDatabase(c);
JdbcUtil.closeQuietly(c);
AbstractJdbcSequenceNumberService service = createServiceForTests();
service.setStatementTimeout(new TimeInterval(1L, TimeUnit.MINUTES));
service.setCreateDatabase(true);
AdaptrisMessage msg = createMessageForTests();
execute(service, msg);
assertTrue(msg.containsKey(DEFAULT_METADATA_KEY));
assertEquals("000000001", msg.getMetadataValue(DEFAULT_METADATA_KEY));
assertEquals(2, getCurrentSequenceNumber(DEFAULT_ID));
}
use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class StaticIdentitySequenceNumberServiceTest method retrieveObjectForSampleConfig.
@Override
protected StaticIdentitySequenceNumberService retrieveObjectForSampleConfig() {
JdbcConnection connection = new JdbcConnection();
connection.setConnectUrl("jdbc:mysql://localhost:3306/mydatabase");
connection.setConnectionAttempts(2);
connection.setConnectionRetryInterval(new TimeInterval(3L, "SECONDS"));
StaticIdentitySequenceNumberService service = new StaticIdentitySequenceNumberService();
service.setIdentity("adaptrismsg");
service.setMetadataKey("sequence_no");
service.setNumberFormat(DEFAULT_NUMBER_FORMAT);
service.setConnection(connection);
service.setOverflowBehaviour(AbstractJdbcSequenceNumberService.OverflowBehaviour.Continue);
return service;
}
use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class JdbcRawDataCaptureServiceTest method retrieveObjectForSampleConfig.
@Override
protected JdbcRawDataCaptureService retrieveObjectForSampleConfig() {
JdbcRawDataCaptureService service = createService();
JdbcConnection connection = new JdbcConnection();
connection.setConnectUrl("jdbc:mysql://localhost:3306/mydatabase");
connection.setConnectionAttempts(2);
connection.setConnectionRetryInterval(new TimeInterval(3L, "SECONDS"));
service.setConnection(connection);
return service;
}
Aggregations