Skip to content

Instantly share code, notes, and snippets.

@vegaasen
Created April 23, 2014 10:32
Show Gist options
  • Save vegaasen/11210168 to your computer and use it in GitHub Desktop.
Save vegaasen/11210168 to your computer and use it in GitHub Desktop.
c3p0 connectionCustomizer implementation example
..
..
..
dataSource = new ComboPooledDataSource();
dataSource.setConnectionCustomizerClassName(SchemaConnectionCustomizer.class.getSimpleName());
..
..
..
public class SchemaConnectionCustomizer extends AbstractConnectionCustomizer {
private static final Logger LOG = LoggerFactory.getLogger(SchemaConnectionCustomizer.class);
private static final String SCHEMA_LOCATION = "ALTER SESSION SET CURRENT_SCHEMA = <<schema>>";
@Override
public void onAcquire(final Connection c, final String parentDataSourceIdentityToken) throws Exception {
try (Statement statement = c.createStatement()) {
statement.executeUpdate(SCHEMA_LOCATION);
} finally {
LOG.info("Schema now configured");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment