Java Code Examples for java.sql.Connection#toString()
The following examples show how to use
java.sql.Connection#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractConnectionListener.java From das with Apache License 2.0 | 7 votes |
private void putConnectionUrlToCache(Connection connection) { if (connection == null) { return; } try { String connectionId = connection.toString(); String url = simpleUrl(connection.getMetaData().getURL()); if (url == null || url.isEmpty()) { return; } connectionUrlCache.put(connectionId, url); LOGGER.info(String.format("%s put to url cache.", connectionId)); } catch (Throwable e) { } }
Example 2
Source File: J2EEDataSourceTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Make sure this connection's string is unique (DERBY-243) */ private static void assertToString(Connection conn) throws Exception { assertStringFormat(conn); String str = conn.toString(); if ( conns.containsKey(str)) { throw new Exception("ERROR: Connection toString() is not unique: " + str); } conns.put(str, conn); }
Example 3
Source File: J2EEDataSourceTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Check the format of the connection string. This is the default test * to run if this is not a BrokeredConnection class */ private static void assertStringFormat(Connection conn) //throws Exception { assertStringPrefix(conn); String str = conn.toString(); assertTrue("\nexpected format:\n " + CONNSTRING_FORMAT + "\nactual value:\n " + str, str.matches(CONNSTRING_FORMAT)); }
Example 4
Source File: J2EEDataSourceTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Make sure this connection's string is unique (DERBY-243) */ private static void assertToString(Connection conn) throws Exception { assertStringFormat(conn); String str = conn.toString(); if ( conns.containsKey(str)) { throw new Exception("ERROR: Connection toString() is not unique: " + str); } conns.put(str, conn); }
Example 5
Source File: DataSourceTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Check the format of the connection string. This is the default test * to run if this is not a BrokeredConnection class */ private static void assertStringFormat(Connection conn) //throws Exception { assertStringPrefix(conn); String str = conn.toString(); // matches is not a supported method with JSR169 if (!JDBC.vmSupportsJSR169()) assertTrue("\nexpected format:\n " + CONNSTRING_FORMAT + "\nactual value:\n " + str, str.matches(CONNSTRING_FORMAT)); }
Example 6
Source File: DataSourceTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Make sure this connection's string is unique (DERBY-243) */ private static void assertToString(Connection conn) throws Exception { assertStringFormat(conn); String str = conn.toString(); if ( conns.containsKey(str)) { throw new Exception("ERROR: Connection toString() is not unique: " + str); } conns.put(str, conn); }
Example 7
Source File: J2EEDataSourceTest.java From spliceengine with GNU Affero General Public License v3.0 | 6 votes |
/** * Check the format of the connection string. This is the default test * to run if this is not a BrokeredConnection class */ private static void assertStringFormat(Connection conn) //throws Exception { assertStringPrefix(conn); String str = conn.toString(); assertTrue("\nexpected format:\n " + CONNSTRING_FORMAT + "\nactual value:\n " + str, str.matches(CONNSTRING_FORMAT)); }
Example 8
Source File: JdbcSupport.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Returns a (new) JDBC connection from the data source. * * @return The connection */ public Connection borrowConnection() throws DatabaseOperationException { try { Connection connection = null; if (_username == null) { connection = getDataSource().getConnection(); } else { connection = getDataSource().getConnection(_username, _password); } if (_log.isDebugEnabled()) { String connName = connection.toString(); _log.debug("Borrowed connection "+connName+" from data source"); _openConnectionNames.add(connName); } // GemStone changes BEGIN // set the isolation level if required if (_isolationLevel >= 0 && connection.getTransactionIsolation() != _isolationLevel) { connection.setTransactionIsolation(_isolationLevel); } // GemStone changes END return connection; } catch (SQLException ex) { throw new DatabaseOperationException("Could not get a connection from the datasource", ex); } }
Example 9
Source File: PooledDataSourceTest.java From mybaties with Apache License 2.0 | 6 votes |
@Test public void shouldNotFailCallingToStringOverAnInvalidConnection() throws Exception { PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES); Connection c = ds.getConnection(); c.close(); c.toString(); }
Example 10
Source File: DalTransaction.java From dal with Apache License 2.0 | 6 votes |
private String getRollbackOnlyMessage(int level) { String dbName = logicDbName == null ? "" : logicDbName; String connectionId = ""; if (connHolder != null) { Connection con = connHolder.getConn(); if (con != null) { connectionId = con.toString(); } } return String.format("LogicDbName:%s, Level:%s, ConnectionId:%s", dbName, level, connectionId); }
Example 11
Source File: J2EEDataSourceTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Check the format of the connection string. This is the default test * to run if this is not a BrokeredConnection class */ private static void assertStringFormat(Connection conn) //throws Exception { assertStringPrefix(conn); String str = conn.toString(); assertTrue("\nexpected format:\n " + CONNSTRING_FORMAT + "\nactual value:\n " + str, str.matches(CONNSTRING_FORMAT)); }
Example 12
Source File: DataSourceTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Check the format of the connection string. This is the default test * to run if this is not a BrokeredConnection class */ private static void assertStringFormat(Connection conn) //throws Exception { assertStringPrefix(conn); String str = conn.toString(); // matches is not a supported method with JSR169 if (!JDBC.vmSupportsJSR169()) assertTrue("\nexpected format:\n " + CONNSTRING_FORMAT + "\nactual value:\n " + str, str.matches(CONNSTRING_FORMAT)); }
Example 13
Source File: DataSourceTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Make sure this connection's string is unique (DERBY-243) */ private static void assertToString(Connection conn) throws Exception { assertStringFormat(conn); String str = conn.toString(); if ( conns.containsKey(str)) { throw new Exception("ERROR: Connection toString() is not unique: " + str); } conns.put(str, conn); }
Example 14
Source File: JdbcSupport.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Closes the given JDBC connection (returns it back to the pool if the datasource is poolable). * * @param connection The connection */ public void returnConnection(Connection connection) { try { if ((connection != null) && !connection.isClosed()) { if (_log.isDebugEnabled()) { String connName = connection.toString(); _openConnectionNames.remove(connName); StringBuilder logMsg = new StringBuilder(); logMsg.append("Returning connection "); logMsg.append(connName); logMsg.append(" to data source.\nRemaining connections:"); if (_openConnectionNames.isEmpty()) { logMsg.append(" None"); } else { for (Iterator it = _openConnectionNames.iterator(); it.hasNext();) { logMsg.append("\n "); logMsg.append(it.next().toString()); } } _log.debug(logMsg.toString()); } connection.close(); } } catch (Exception e) { _log.warn("Caught exception while returning connection to pool", e); } }
Example 15
Source File: JdbcSupport.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Returns a (new) JDBC connection from the data source. * * @return The connection */ public Connection borrowConnection() throws DatabaseOperationException { try { Connection connection = null; if (_username == null) { connection = getDataSource().getConnection(); } else { connection = getDataSource().getConnection(_username, _password); } if (_log.isDebugEnabled()) { String connName = connection.toString(); _log.debug("Borrowed connection "+connName+" from data source"); _openConnectionNames.add(connName); } // GemStone changes BEGIN // set the isolation level if required if (_isolationLevel >= 0 && connection.getTransactionIsolation() != _isolationLevel) { connection.setTransactionIsolation(_isolationLevel); } // GemStone changes END return connection; } catch (SQLException ex) { throw new DatabaseOperationException("Could not get a connection from the datasource", ex); } }
Example 16
Source File: StoredProcedureTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public Map<String, ?> createMap(Connection con) throws SQLException { Map<String, Object> inParms = new HashMap<String, Object>(); String testValue = con.toString(); inParms.put("in", testValue); return inParms; }
Example 17
Source File: PooledDataSourceTest.java From mybatis with Apache License 2.0 | 6 votes |
@Test public void shouldNotFailCallingToStringOverAnInvalidConnection() throws Exception { PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES); Connection c = ds.getConnection(); c.close(); c.toString(); }
Example 18
Source File: DataSourceTest.java From spliceengine with GNU Affero General Public License v3.0 | 6 votes |
/** * Check the format of the connection string. This is the default test * to run if this is not a BrokeredConnection class */ private static void assertStringFormat(Connection conn) //throws Exception { assertStringPrefix(conn); String str = conn.toString(); // matches is not a supported method with JSR169 if (!JDBC.vmSupportsJSR169()) assertTrue("\nexpected format:\n " + CONNSTRING_FORMAT + "\nactual value:\n " + str, str.matches(CONNSTRING_FORMAT)); }
Example 19
Source File: AbstractConnectionListener.java From das with Apache License 2.0 | 6 votes |
private void removeConnectionUrlFromCache(Connection connection) { if (connection == null) { return; } try { String connectionId = connection.toString(); connectionUrlCache.remove(connectionId); LOGGER.info(String.format("%s removed from url cache.", connectionId)); } catch (Throwable e) { } }
Example 20
Source File: StoredProcedureTests.java From java-technology-stack with MIT License | 5 votes |
@Override public Map<String, ?> createMap(Connection con) throws SQLException { Map<String, Object> inParms = new HashMap<>(); String testValue = con.toString(); inParms.put("in", testValue); return inParms; }