Created
April 23, 2014 10:32
-
-
Save vegaasen/11210168 to your computer and use it in GitHub Desktop.
c3p0 connectionCustomizer implementation example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.. | |
.. | |
.. | |
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