java.sql.Connection#toString ( )源码实例Demo

下面列出了java.sql.Connection#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: das   文件: AbstractConnectionListener.java
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) {
    }
}
 
源代码2 项目: das   文件: AbstractConnectionListener.java
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) {
    }
}
 
源代码3 项目: spliceengine   文件: DataSourceTest.java
/**
 * 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));
}
 
源代码4 项目: mybatis   文件: PooledDataSourceTest.java
@Test
public void shouldNotFailCallingToStringOverAnInvalidConnection() throws Exception {
  PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
  Connection c = ds.getConnection();
  c.close();
  c.toString();
}
 
@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;
}
 
@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;
}
 
源代码7 项目: gemfirexd-oss   文件: JdbcSupport.java
/**
     * 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);
        }
    }
 
源代码8 项目: gemfirexd-oss   文件: JdbcSupport.java
/**
 * 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);
    }
}
 
源代码9 项目: gemfirexd-oss   文件: DataSourceTest.java
/**
 * 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);
}
 
源代码10 项目: gemfirexd-oss   文件: DataSourceTest.java
/**
 * 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));
}
 
源代码11 项目: gemfirexd-oss   文件: J2EEDataSourceTest.java
/**
 * 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);
}
 
源代码12 项目: gemfirexd-oss   文件: J2EEDataSourceTest.java
/**
 * 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));
}
 
源代码13 项目: dal   文件: DalTransaction.java
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);
}
 
源代码14 项目: mybaties   文件: PooledDataSourceTest.java
@Test
public void shouldNotFailCallingToStringOverAnInvalidConnection() throws Exception {
  PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
  Connection c = ds.getConnection();
  c.close();
  c.toString();
}
 
源代码15 项目: gemfirexd-oss   文件: JdbcSupport.java
/**
     * 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);
        }
    }
 
源代码16 项目: spliceengine   文件: J2EEDataSourceTest.java
/**
 * 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));
}
 
源代码17 项目: gemfirexd-oss   文件: DataSourceTest.java
/**
 * 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);
}
 
源代码18 项目: gemfirexd-oss   文件: DataSourceTest.java
/**
 * 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));
}
 
源代码19 项目: gemfirexd-oss   文件: J2EEDataSourceTest.java
/**
 * 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);
}
 
源代码20 项目: gemfirexd-oss   文件: J2EEDataSourceTest.java
/**
 * 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));
}