Skip to content

Instantly share code, notes, and snippets.

@tobyweston
Created August 15, 2012 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobyweston/3362116 to your computer and use it in GitHub Desktop.
Save tobyweston/3362116 to your computer and use it in GitHub Desktop.
c3p0 configuration settings
class ProductionHibernateConfiguration implements HibernateConfiguration {
@Override
public Properties getProperties(String connectionUrl, String userName, String password) {
Properties properties = new Properties();
properties.setProperty("hibernate.connection.driver_class", "net.bull.javamelody.JdbcDriver");
properties.setProperty("hibernate.connection.driver", "oracle.jdbc.driver.OracleDriver");
properties.setProperty("hibernate.connection.url", connectionUrl);
properties.setProperty("hibernate.connection.username", userName);
properties.setProperty("hibernate.connection.password", password);
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
properties.setProperty("hibernate.current_session_context_class", "thread");
properties.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.NoCacheProvider");
properties.setProperty("hibernate.show_sql", "false");
properties.setProperty("hibernate.connection.provider_class", "org.hibernate.connection.C3P0ConnectionProvider");
properties.setProperty("hibernate.c3p0.min_size", "2"); // aka c3p0.minPoolSize
properties.setProperty("hibernate.c3p0.max_size", "25"); // aka c3p0.maxPoolSize
properties.setProperty("hibernate.c3p0.acquire_increment", "2"); // aka c3p0.acquireIncrement
properties.setProperty("hibernate.c3p0.timeout", inSeconds(minutes(30))); // aka c3p0.maxIdleTime
properties.setProperty("hibernate.c3p0.max_statements", "100"); // aka c3p0.maxStatements, guide is num of prepared statements * maxPoolSize
properties.setProperty("hibernate.c3p0.idle_test_period", inSeconds(minutes(5))); // only makes sense if smaller than c3p0 timeout value, aka c3p0.idleConnectionTestPeriod
properties.setProperty("c3p0.testConnectionOnCheckin", "true");
properties.setProperty("c3p0.preferredTestQuery", "select * from dual;");
return properties;
}
public String inSeconds(Duration duration) {
return String.valueOf(duration.inSeconds());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment