List of utility methods to do DataSource
Connection | getConnection(final DataSource ds, final boolean autoCommit) get Connection final Connection conn = ds.getConnection(); if (conn.getAutoCommit() != autoCommit) { conn.setAutoCommit(autoCommit); return conn; |
Connection | getConnectionFromDataSource(DataSource ds) Creates a connection to the database from a Data Source Connection conn = ds.getConnection();
conn.setAutoCommit(false);
return conn;
|
String | getDatabaseName(DataSource dataSource) get Database Name Connection con = null; try { con = dataSource.getConnection(); if (con == null) { throw new RuntimeException("Connection returned by DataSource [" + dataSource + "] was null"); DatabaseMetaData metaData = con.getMetaData(); if (metaData == null) { ... |
DataSource | getDataSource(String jndi) get Data Source javax.naming.Context initContext; try { initContext = new javax.naming.InitialContext(); return (DataSource) initContext.lookup("java:comp/env/" + jndi); } catch (Exception ex) { try { initContext = new javax.naming.InitialContext(); return (DataSource) initContext.lookup(jndi); ... |
DataSource | getDataSource(String jndiName) get Data Source Context ctx = new InitialContext(); if (ctx == null) { throw new Exception("No Context available"); return (DataSource) ctx.lookup(jndiName); |
DataSource | getDataSource(String service) get Data Source Context ctx; try { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "org.mortbay.naming.InitialContextFactory"); env.put(Context.PROVIDER_URL, "localhost:1099"); ctx = new InitialContext(env); } catch (Exception e) { logger.severe("Error configuring initial context " + e); ... |
DataSource | getDataSourceCache(String hostName) get Data Source Cache return dataSourceMap.get(hostName);
|
Connection | getDBConnection(DataSource dataSource) get DB Connection Connection dbConnection = dataSource.getConnection(); dbConnection.setAutoCommit(false); if (dbConnection.getTransactionIsolation() != Connection.TRANSACTION_READ_COMMITTED) { dbConnection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); return dbConnection; |
String | getGlobalVariable(DataSource dataSource, String variable) Get global variable value. try (Connection conn = dataSource.getConnection()) { try (Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(String.format("show global variables like '%s'", variable));) { if (rs.next()) { return rs.getString(2); } else { return ""; |
String | getJdbcUrlFromDataSource(DataSource dataSource) get Jdbc Url From Data Source Connection connection = null; try { connection = dataSource.getConnection(); if (connection == null) { throw new IllegalStateException("Connection returned by DataSource [" + dataSource + "] was null"); return connection.getMetaData().getURL(); } catch (SQLException e) { ... |