Search in sources :

Example 71 with TimeInterval

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;
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) KeyValuePair(com.adaptris.util.KeyValuePair) KeyValuePairSet(com.adaptris.util.KeyValuePairSet)

Example 72 with TimeInterval

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;
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) JdbcService(com.adaptris.core.jdbc.JdbcService) ArrayList(java.util.ArrayList) JdbcConnection(com.adaptris.core.jdbc.JdbcConnection)

Example 73 with TimeInterval

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));
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) DatabaseConnection(com.adaptris.core.jdbc.DatabaseConnection) Connection(java.sql.Connection) Test(org.junit.Test)

Example 74 with TimeInterval

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;
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) JdbcConnection(com.adaptris.core.jdbc.JdbcConnection)

Example 75 with TimeInterval

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;
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) JdbcConnection(com.adaptris.core.jdbc.JdbcConnection)

Aggregations

TimeInterval (com.adaptris.util.TimeInterval)310 Test (org.junit.Test)249 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)86 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)49 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)42 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)40 FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)38 Channel (com.adaptris.core.Channel)36 MockChannel (com.adaptris.core.stubs.MockChannel)32 File (java.io.File)28 StandardWorkflow (com.adaptris.core.StandardWorkflow)27 Adapter (com.adaptris.core.Adapter)26 GuidGenerator (com.adaptris.util.GuidGenerator)25 FilenameFilter (java.io.FilenameFilter)24 Perl5FilenameFilter (org.apache.oro.io.Perl5FilenameFilter)24 StandaloneProducer (com.adaptris.core.StandaloneProducer)23 CoreException (com.adaptris.core.CoreException)22 WaitService (com.adaptris.core.services.WaitService)22 RandomAccessFile (java.io.RandomAccessFile)21 ObjectName (javax.management.ObjectName)21