Search in sources :

Example 66 with ComboPooledDataSource

use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project JavaForFun by gumartinm.

the class RawJDBCLambdaExample method getDataSource.

/**
 * Just for fun, programmatic configuration.
 * @return
 * @throws PropertyVetoException
 */
private static DataSource getDataSource() throws PropertyVetoException {
    final ComboPooledDataSource pool = new ComboPooledDataSource();
    pool.setUser("root");
    pool.setPassword("");
    // We are going to use JDBC driver
    pool.setDriverClass("com.mysql.jdbc.Driver");
    pool.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/n2a?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8");
    pool.setInitialPoolSize(5);
    pool.setMaxPoolSize(35);
    pool.setMinPoolSize(10);
    pool.setAcquireIncrement(1);
    pool.setAcquireRetryAttempts(5);
    pool.setAcquireRetryDelay(1000);
    pool.setAutomaticTestTable("con_test");
    pool.setCheckoutTimeout(5000);
    return pool;
}
Also used : ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource)

Example 67 with ComboPooledDataSource

use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project JavaForFun by gumartinm.

the class RawJDBCPoolExample method getDataSource.

/**
 * Just for fun, programmatic configuration.
 * @return
 * @throws PropertyVetoException
 */
private static DataSource getDataSource() throws PropertyVetoException {
    final ComboPooledDataSource pool = new ComboPooledDataSource();
    pool.setUser("root");
    pool.setPassword("");
    // We are going to use JDBC driver
    pool.setDriverClass("com.mysql.jdbc.Driver");
    pool.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/n2a?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8");
    pool.setInitialPoolSize(5);
    pool.setMaxPoolSize(35);
    pool.setMinPoolSize(10);
    pool.setAcquireIncrement(1);
    pool.setAcquireRetryAttempts(5);
    pool.setAcquireRetryDelay(1000);
    pool.setAutomaticTestTable("con_test");
    pool.setCheckoutTimeout(5000);
    return pool;
}
Also used : ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource)

Example 68 with ComboPooledDataSource

use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project JavaForFun by gumartinm.

the class RawSpringJDBCWithPoolExample method main.

public static void main(final String[] args) throws PropertyVetoException {
    // Just for fun, programmatic configuration.
    final DataSource dataSource = getDataSource();
    final Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("AD_ID", 1);
    // 3. Using Spring JdbcTemplate
    final JdbcOperations jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.execute("SELECT * FROM AD");
    // 4. Using SimpleJdbcTemplate
    final SimpleJdbcOperations simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
    final int deprecatedResult = simpleJdbcTemplate.queryForInt("SELECT * FROM AD", parameters);
    logger.info("Deprecated result: " + deprecatedResult);
    // 5. Using NamedParameterJdbcTemplate
    final NamedParameterJdbcOperations namedParameterJdbcOperations = new NamedParameterJdbcTemplate(dataSource);
    final int namedResult = namedParameterJdbcOperations.queryForInt("SELECT * FROM AD", parameters);
    logger.info("Named result: " + namedResult);
    // 6. Using Spring SimpleJdbcInsert
    final SimpleJdbcInsertOperations simpleJdbcInsert = new SimpleJdbcInsert(dataSource);
    simpleJdbcInsert.withTableName("ad");
    simpleJdbcInsert.execute(parameters);
    // 7. Using Spring SimpleJdbcCall
    final SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(dataSource);
    // Now we close the whole pool :)
    ((ComboPooledDataSource) dataSource).close();
}
Also used : HashMap(java.util.HashMap) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) JdbcOperations(org.springframework.jdbc.core.JdbcOperations) NamedParameterJdbcOperations(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations) SimpleJdbcOperations(org.springframework.jdbc.core.simple.SimpleJdbcOperations) SimpleJdbcTemplate(org.springframework.jdbc.core.simple.SimpleJdbcTemplate) SimpleJdbcOperations(org.springframework.jdbc.core.simple.SimpleJdbcOperations) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) SimpleJdbcTemplate(org.springframework.jdbc.core.simple.SimpleJdbcTemplate) SimpleJdbcCall(org.springframework.jdbc.core.simple.SimpleJdbcCall) ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) DataSource(javax.sql.DataSource) NamedParameterJdbcOperations(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations) ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) SimpleJdbcInsertOperations(org.springframework.jdbc.core.simple.SimpleJdbcInsertOperations) SimpleJdbcInsert(org.springframework.jdbc.core.simple.SimpleJdbcInsert)

Example 69 with ComboPooledDataSource

use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project JavaForFun by gumartinm.

the class RawSpringJDBCWithPoolExample method getDataSource.

/**
 * Just for fun, programmatic configuration.
 * @return
 * @throws PropertyVetoException
 */
private static DataSource getDataSource() throws PropertyVetoException {
    final ComboPooledDataSource pool = new ComboPooledDataSource();
    pool.setUser("root");
    pool.setPassword("");
    // We are going to use the JDBC driver
    pool.setDriverClass("com.mysql.jdbc.Driver");
    pool.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/n2a?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8");
    pool.setInitialPoolSize(5);
    pool.setMaxPoolSize(35);
    pool.setMinPoolSize(10);
    pool.setAcquireIncrement(1);
    pool.setAcquireRetryAttempts(5);
    pool.setAcquireRetryDelay(1000);
    pool.setAutomaticTestTable("con_test");
    pool.setCheckoutTimeout(5000);
    return pool;
}
Also used : ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource)

Example 70 with ComboPooledDataSource

use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project druid by alibaba.

the class TestPSCache method f_test_c3p0.

public void f_test_c3p0() throws Exception {
    ComboPooledDataSource ds = new ComboPooledDataSource();
    ds.setJdbcUrl("jdbc:mock:test");
    ds.setMaxPoolSize(10);
    ds.setMinPoolSize(0);
    ds.setMaxStatements(10);
    for (int i = 0; i < 10; ++i) {
        f(ds, 5);
        System.out.println("--------------------------------------------");
    }
}
Also used : ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource)

Aggregations

ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)69 PropertyVetoException (java.beans.PropertyVetoException)16 SQLException (java.sql.SQLException)13 Connection (java.sql.Connection)7 Test (org.junit.Test)7 Bean (org.springframework.context.annotation.Bean)7 Properties (java.util.Properties)5 DataSource (javax.sql.DataSource)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ComboPooledDataSource (com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource)4 ResultSet (java.sql.ResultSet)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 DbRuntimeException (cn.hutool.db.DbRuntimeException)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)2 Duration (de.invesdwin.util.time.duration.Duration)2 PreparedStatement (java.sql.PreparedStatement)2 EntityManagerFactory (javax.persistence.EntityManagerFactory)2