Java Code Examples for java.sql.Connection#hashCode()

The following examples show how to use java.sql.Connection#hashCode() . 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: PooledConnection.java    From ZhihuSpider with MIT License 5 votes vote down vote up
public PooledConnection(Connection connection, PooledDataSource dataSource) {
	this.hashCode = connection.hashCode();
	this.realConnection = connection;
	this.dataSource = dataSource;
	this.createdTimestamp = System.currentTimeMillis();
	this.lastUsedTimestamp = System.currentTimeMillis();
	this.valid = true;
	this.proxyConnection = (Connection) Proxy.newProxyInstance(Connection.class.getClassLoader(), IFACES, this);
}
 
Example 2
Source File: PooledConnection.java    From mybaties with Apache License 2.0 5 votes vote down vote up
public PooledConnection(Connection connection, PooledDataSource dataSource) {
  this.hashCode = connection.hashCode();
  this.realConnection = connection;
  this.dataSource = dataSource;
  this.createdTimestamp = System.currentTimeMillis();
  this.lastUsedTimestamp = System.currentTimeMillis();
  this.valid = true;
  this.proxyConnection = (Connection) Proxy.newProxyInstance(Connection.class.getClassLoader(), IFACES, this);
}
 
Example 3
Source File: PooledConnection.java    From mybatis with Apache License 2.0 5 votes vote down vote up
public PooledConnection(Connection connection, PooledDataSource dataSource) {
  this.hashCode = connection.hashCode();
  this.realConnection = connection;
  this.dataSource = dataSource;
  this.createdTimestamp = System.currentTimeMillis();
  this.lastUsedTimestamp = System.currentTimeMillis();
  this.valid = true;
  this.proxyConnection = (Connection) Proxy.newProxyInstance(Connection.class.getClassLoader(), IFACES, this);
}
 
Example 4
Source File: ServerLoginActionSql.java    From aceql-http with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static String getConnectionId(Connection connection) {
return "" + connection.hashCode();
   }
 
Example 5
Source File: TestJdbcWrapper.java    From javamelody with Apache License 2.0 4 votes vote down vote up
/** Test.
 * @throws SQLException e
 * @throws IllegalAccessException e */
@Test
public void testCreateConnectionProxy() throws SQLException, IllegalAccessException {
	DriverManager.registerDriver(driver);
	final int usedConnectionCount = JdbcWrapper.getUsedConnectionCount();
	// nécessite la dépendance vers la base de données H2
	Connection connection = DriverManager.getConnection(H2_DATABASE_URL);
	assertEquals("getUsedConnectionCount1", usedConnectionCount,
			JdbcWrapper.getUsedConnectionCount());
	try {
		jdbcWrapper.rewrapConnection(connection);
		connection = jdbcWrapper.createConnectionProxy(connection);
		assertEquals("getUsedConnectionCount1", usedConnectionCount + 1,
				JdbcWrapper.getUsedConnectionCount());
		assertNotNull("createConnectionProxy", connection);
		assertEquals(EQUALS, connection, connection);
		connection.hashCode();

		final int activeConnectionCount = JdbcWrapper.getActiveConnectionCount();

		connection.prepareStatement("select 1").close();
		connection.prepareCall("select 2").close();

		assertEquals("getActiveConnectionCount", activeConnectionCount,
				JdbcWrapper.getActiveConnectionCount());

		connection.rollback();

		jdbcWrapper.getSqlCounter().setDisplayed(false);
		connection = jdbcWrapper.createConnectionProxy(connection);
		assertEquals("getUsedConnectionCount2", usedConnectionCount + 1,
				JdbcWrapper.getUsedConnectionCount());
		jdbcWrapper.getSqlCounter().setDisplayed(true);
		Utils.setProperty(Parameter.DISABLED, "true");
		try {
			connection = jdbcWrapper.createConnectionProxy(connection);
			assertEquals("getUsedConnectionCount3", usedConnectionCount + 1,
					JdbcWrapper.getUsedConnectionCount());
		} finally {
			Utils.setProperty(Parameter.DISABLED, "false");
		}

		// il peut arriver que getConnectionInformationsList retourne une liste vide
		// si la classe JdbcWrapper a été initialisée alors que system-actions-enabled=false
		// ou que no-database=true ce est le cas vu l'ordre des tests dans le script ant
		assertNotNull("getConnectionInformationsList",
				JdbcWrapper.getConnectionInformationsList());
	} finally {
		connection.close();
	}
	assertEquals("getUsedConnectionCount4", usedConnectionCount,
			JdbcWrapper.getUsedConnectionCount());
	connection = DriverManager.getConnection(H2_DATABASE_URL + "?driver=org.h2.Driver");
	try {
		assertEquals("getUsedConnectionCount1", usedConnectionCount + 1,
				JdbcWrapper.getUsedConnectionCount());
	} finally {
		connection.close();
	}

	assertEquals("proxy of proxy", connection, jdbcWrapper.createConnectionProxy(connection));

	final InvocationHandler dummy = new InvocationHandler() {
		@Override
		public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
			return null;
		}
	};
	final List<Class<?>> interfaces = Arrays.asList(new Class<?>[] { Connection.class });
	connection = DriverManager.getConnection(H2_DATABASE_URL);
	try {
		assertNotNull("createProxy", JdbcWrapper.createProxy(connection, dummy, interfaces));
	} finally {
		connection.close();
	}

	JdbcWrapper.getActiveThreadCount();
}