Search in sources :

Example 16 with JdbcConnection

use of com.adaptris.core.jdbc.JdbcConnection in project interlok by adaptris.

the class JdbcServiceCase method testBackReferences.

protected <T extends JdbcService> void testBackReferences(T testObject) throws Exception {
    JdbcConnection conn = new JdbcConnection();
    conn.setConnectUrl("jdbc:derby:memory:" + GUID.safeUUID() + ";create=true");
    conn.setDriverImp("org.apache.derby.jdbc.EmbeddedDriver");
    testObject.setConnection(conn);
    // redmineID #4536, exception listener is set in .init()
    testObject.init();
    assertEquals(conn, testObject.getConnection());
    assertEquals(1, conn.retrieveExceptionListeners().size());
    assertTrue(testObject == conn.retrieveExceptionListeners().toArray()[0]);
    testObject.start();
    testObject.stop();
    testObject.close();
    // Now marshall and see if it's the same.
    XStreamMarshaller m = new XStreamMarshaller();
    String xml = m.marshal(testObject);
    @SuppressWarnings("unchecked") T testObject2 = (T) m.unmarshal(xml);
    // redmineID #4536, exception listener now must simply be set in .init()
    testObject2.init();
    // If the setter has been used, then these two will be "true"
    assertNotNull(testObject2.getConnection());
    assertEquals(1, testObject2.getConnection().retrieveExceptionListeners().size());
    assertTrue(testObject2 == testObject2.getConnection().retrieveExceptionListeners().toArray()[0]);
    testObject2.start();
    testObject2.stop();
    testObject2.close();
}
Also used : JdbcConnection(com.adaptris.core.jdbc.JdbcConnection) XStreamMarshaller(com.adaptris.core.XStreamMarshaller)

Example 17 with JdbcConnection

use of com.adaptris.core.jdbc.JdbcConnection in project interlok by adaptris.

the class JdbcStoredProcedureTest method setUp.

@Before
public void setUp() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    jdbcConnection = new JdbcConnection(PROPERTIES.getProperty(JDBC_URL), PROPERTIES.getProperty(JDBC_DRIVER));
    jdbcConnection.setUsername(PROPERTIES.getProperty(JDBC_USER));
    jdbcConnection.setPassword(PROPERTIES.getProperty(JDBC_PASSWORD));
    LifecycleHelper.initAndStart(jdbcConnection);
    if (PROPERTIES.getProperty(JDBC_VENDOR).equals("mysql"))
        statementCreator = new MysqlStatementCreator();
    else if (PROPERTIES.getProperty(JDBC_VENDOR).equals("sqlserver"))
        statementCreator = new SqlServerStatementCreator();
    else
        fail("Vendor for JDBC tests unknown: " + PROPERTIES.getProperty(JDBC_VENDOR));
    connection = jdbcConnection.connect();
    storedProcedure = new StoredProcedure();
    storedProcedure.setConnection(connection);
    storedProcedure.setStatementCreator(statementCreator);
    storedProcedure.setStatementExecutor(new ExecuteCallableStatementExecutor());
}
Also used : JdbcConnection(com.adaptris.core.jdbc.JdbcConnection) Before(org.junit.Before)

Example 18 with JdbcConnection

use of com.adaptris.core.jdbc.JdbcConnection in project interlok by adaptris.

the class FirstRowMetadataTranslatorTest method testDateStatementParameter.

@Test
public void testDateStatementParameter() throws Exception {
    createDatabase();
    Date yesterday = yesterday();
    List<AdapterTypeVersion> dbItems = generate(10, yesterday);
    AdapterTypeVersion entry = dbItems.get(0);
    entry.setDate(new Date());
    populateDatabase(dbItems, true);
    JdbcDataQueryService service = new JdbcDataQueryService();
    service.setConnection(new JdbcConnection(PROPERTIES.getProperty(JDBC_QUERYSERVICE_URL), PROPERTIES.getProperty(JDBC_QUERYSERVICE_DRIVER)));
    service.setStatementCreator(new ConfiguredSQLStatement(DATE_QUERY_SQL));
    DateStatementParameter tsp = new DateStatementParameter();
    tsp.setDateFormat(DATE_FORMAT);
    tsp.setQueryType(StatementParameter.QueryType.metadata);
    tsp.setQueryString(METADATA_KEY_DATE);
    service.setStatementParameters(new StatementParameterList(Arrays.asList(new JdbcStatementParameter[] { tsp })));
    FirstRowMetadataTranslator t = new FirstRowMetadataTranslator();
    service.setResultSetTranslator(t);
    AdaptrisMessage msg = createMessage(entry);
    msg.addMetadata(METADATA_KEY_DATE, dateToString(yesterday));
    execute(service, msg);
    assertEquals(XML_PAYLOAD_PREFIX + entry.getUniqueId() + XML_PAYLOAD_SUFFIX, msg.getContent());
    assertTrue(msg.containsKey(t.getMetadataKeyPrefix() + t.getSeparator() + COLUMN_VERSION));
    assertEquals(entry.getVersion(), msg.getMetadataValue(t.getMetadataKeyPrefix() + t.getSeparator() + COLUMN_VERSION));
    assertTrue(msg.containsKey(t.getMetadataKeyPrefix() + t.getSeparator() + COLUMN_TYPE));
    assertEquals(entry.getTranslatorType(), msg.getMetadataValue(t.getMetadataKeyPrefix() + t.getSeparator() + COLUMN_TYPE));
    assertFalse(msg.containsKey(JdbcDataQueryService.class.getCanonicalName()));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) JdbcConnection(com.adaptris.core.jdbc.JdbcConnection) Date(java.util.Date) Test(org.junit.Test)

Example 19 with JdbcConnection

use of com.adaptris.core.jdbc.JdbcConnection in project interlok by adaptris.

the class ServiceFromDatabaseTest method testNotFound.

@Test(expected = ServiceException.class)
public void testNotFound() throws Exception {
    DatabaseEntry entry = new DatabaseEntry("mySourcePartner", "myDestinationPartner");
    createDatabase(Arrays.asList(entry));
    JdbcConnection jdbcConn = configure(new JdbcConnection());
    ServiceFromDatabase extractor = new ServiceFromDatabase().withQuery(SELECT_STMT).withConnection(jdbcConn);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.addMetadata("source", "anotherSourcePartner");
    msg.addMetadata("destination", "anotherDestinationPartner");
    try {
        LifecycleHelper.initAndStart(extractor);
        // Since there's no resultSet.next(), should throw a ServiceException.
        InputStream in = extractor.getInputStream(msg);
    } finally {
        LifecycleHelper.stopAndClose(extractor);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) InputStream(java.io.InputStream) JdbcConnection(com.adaptris.core.jdbc.JdbcConnection) Test(org.junit.Test)

Example 20 with JdbcConnection

use of com.adaptris.core.jdbc.JdbcConnection in project interlok by adaptris.

the class JdbcQueryServiceCase method createMultiService.

protected static JdbcDataQueryService createMultiService() {
    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_MULTI_RESULT));
    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