Search in sources :

Example 1 with JdbcService

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

Example 2 with JdbcService

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

Example 3 with JdbcService

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

Aggregations

JdbcService (com.adaptris.core.jdbc.JdbcService)3 ArrayList (java.util.ArrayList)3 JdbcConnection (com.adaptris.core.jdbc.JdbcConnection)2 TimeInterval (com.adaptris.util.TimeInterval)2 CoreException (com.adaptris.core.CoreException)1 ServiceException (com.adaptris.core.ServiceException)1 KeyValuePair (com.adaptris.util.KeyValuePair)1 KeyValuePairSet (com.adaptris.util.KeyValuePairSet)1 SQLException (java.sql.SQLException)1