Search in sources :

Example 11 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project camel by apache.

the class JdbcMessageIdRepositoryTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    dataSource = context.getRegistry().lookupByNameAndType("dataSource", DataSource.class);
    jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.afterPropertiesSet();
}
Also used : JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) DataSource(javax.sql.DataSource) Before(org.junit.Before)

Example 12 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project camel by apache.

the class JdbcAggregateStoreAsText method postProcessTest.

@Override
public void postProcessTest() throws Exception {
    super.postProcessTest();
    repo = applicationContext.getBean("repo3", JdbcAggregationRepository.class);
    dataSource = context.getRegistry().lookupByNameAndType("dataSource3", DataSource.class);
    jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.afterPropertiesSet();
}
Also used : JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) DataSource(javax.sql.DataSource)

Example 13 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project musiccabinet by hakko.

the class JdbcDatabaseAdministrationDao method setDataSource.

// Spring setters
public void setDataSource(DataSource dataSource) {
    this.jdbcTemplate = new JdbcTemplate(dataSource);
    parseJDBCURL();
}
Also used : JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Example 14 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project musiccabinet by hakko.

the class PostgreSQLUtil method truncateTables.

public static void truncateTables(JdbcTemplateDao dao) throws ApplicationException {
    JdbcTemplate jdbcTemplate = dao.getJdbcTemplate();
    jdbcTemplate.execute("truncate music.artist cascade");
    jdbcTemplate.execute("truncate library.directory cascade");
    jdbcTemplate.execute("truncate music.tag cascade");
    jdbcTemplate.execute("truncate music.lastfmuser cascade");
/*
		 * If we really wanted to truncate all tables, we could do: 
		 * loadFunction(dao, PostgreSQLFunction.TRUNCATE_ALL_TABLES);
		 * jdbcTemplate.execute("select util.truncate_all_tables()");
		 * 
		 * Truncating music.artist and library.file reaches pretty much
		 * everything and is by far faster, though.
		 */
}
Also used : JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Example 15 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project musiccabinet by hakko.

the class JdbcWebserviceHistoryDaoTest method oldInvocationsAreIgnored.

@Test
public void oldInvocationsAreIgnored() {
    Calltype SIMILAR = Calltype.TRACK_GET_SIMILAR;
    Track track = new Track("Red Sparowes", "Finally, As That Blazing Sun Shone Down Upon Us, Did We Know That True Enemy Was the Voice of Blind Idolatry; and Only Then Did We Begin to Think for Ourselves.");
    WebserviceInvocation similarTrack = new WebserviceInvocation(SIMILAR, track);
    deleteWebserviceInvocations();
    assertTrue(dao.isWebserviceInvocationAllowed(similarTrack));
    dao.logWebserviceInvocation(similarTrack);
    assertFalse(dao.isWebserviceInvocationAllowed(similarTrack));
    // make the invocation age in database, by updating it.
    DateTime dateTime = new DateTime();
    JdbcTemplate jdbcTemplate = dao.getJdbcTemplate();
    for (int days = 1; days <= 14; days++) {
        jdbcTemplate.update("update library.webservice_history set invocation_time = ?", new Object[] { dateTime.minusDays(days).toDate() });
        boolean isAllowed = dao.isWebserviceInvocationAllowed(similarTrack);
        boolean cacheIsInvalid = days > SIMILAR.getDaysToCache();
        assertTrue(isAllowed == cacheIsInvalid);
    }
}
Also used : Calltype(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Track(com.github.hakko.musiccabinet.domain.model.music.Track) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)124 Test (org.junit.Test)46 DataSource (javax.sql.DataSource)37 Before (org.junit.Before)19 SQLException (java.sql.SQLException)11 EmbeddedDatabaseBuilder (org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder)11 BaseDbTest (com.alibaba.otter.node.etl.BaseDbTest)6 DbDialect (com.alibaba.otter.node.etl.common.db.dialect.DbDialect)6 DbMediaSource (com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource)6 Connection (java.sql.Connection)6 JdbcOperations (org.springframework.jdbc.core.JdbcOperations)6 TransactionStatus (org.springframework.transaction.TransactionStatus)6 Test (org.testng.annotations.Test)6 SqlTemplate (com.alibaba.otter.node.etl.common.db.dialect.SqlTemplate)5 PreparedStatement (java.sql.PreparedStatement)5 Table (org.apache.ddlutils.model.Table)5 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)5 DataAccessException (org.springframework.dao.DataAccessException)5 AbstractDriverBasedDataSource (org.springframework.jdbc.datasource.AbstractDriverBasedDataSource)5 TransactionCallback (org.springframework.transaction.support.TransactionCallback)5