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

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

源代码1 项目: ZhihuSpider   文件: PooledConnection.java

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);
}
 
源代码2 项目: mybaties   文件: PooledConnection.java

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);
}
 
源代码3 项目: mybatis   文件: PooledConnection.java

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);
}
 
源代码4 项目: aceql-http   文件: ServerLoginActionSql.java

public static String getConnectionId(Connection connection) {
return "" + connection.hashCode();
   }
 
源代码5 项目: javamelody   文件: TestJdbcWrapper.java

/** 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();
}