Search in sources :

Example 6 with JdbcConnection

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

Example 7 with JdbcConnection

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

Example 8 with JdbcConnection

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

Example 9 with JdbcConnection

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

Example 10 with JdbcConnection

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

Aggregations

JdbcConnection (com.adaptris.core.jdbc.JdbcConnection)30 TimeInterval (com.adaptris.util.TimeInterval)6 Test (org.junit.Test)6 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)4 BinaryStreamStatementParameter (com.adaptris.core.services.jdbc.BinaryStreamStatementParameter)3 BytePayloadStatementParameter (com.adaptris.core.services.jdbc.BytePayloadStatementParameter)3 CharacterStreamStatementParameter (com.adaptris.core.services.jdbc.CharacterStreamStatementParameter)3 DateStatementParameter (com.adaptris.core.services.jdbc.DateStatementParameter)3 StatementParameter (com.adaptris.core.services.jdbc.StatementParameter)3 TimeStatementParameter (com.adaptris.core.services.jdbc.TimeStatementParameter)3 TimestampStatementParameter (com.adaptris.core.services.jdbc.TimestampStatementParameter)3 SimpleDateFormat (java.text.SimpleDateFormat)3 ServiceException (com.adaptris.core.ServiceException)2 JdbcService (com.adaptris.core.jdbc.JdbcService)2 KeyValuePair (com.adaptris.util.KeyValuePair)2 KeyValuePairSet (com.adaptris.util.KeyValuePairSet)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 CoreException (com.adaptris.core.CoreException)1 XStreamMarshaller (com.adaptris.core.XStreamMarshaller)1