List of usage examples for java.sql Connection getClientInfo
Properties getClientInfo() throws SQLException;
From source file:com.adaptris.jdbc.connection.FailoverDatasourceTest.java
@Test public void testClientInfo() throws Exception { Connection conn = new MyProxy(); try {//from ww w .ja va 2 s. c o m try { conn.setClientInfo(conn.getClientInfo()); } catch (SQLException e) { } try { conn.setClientInfo("hello", "world"); conn.getClientInfo("hello"); } catch (SQLException e) { } } finally { JdbcUtil.closeQuietly(conn); } conn = new FailingProxy(); try { try { conn.setClientInfo(conn.getClientInfo()); } catch (SQLException e) { } try { conn.setClientInfo("hello", "world"); conn.getClientInfo("hello"); } catch (SQLException e) { } } finally { JdbcUtil.closeQuietly(conn); } }
From source file:com.evolveum.midpoint.repo.sql.SqlRepositoryServiceImpl.java
private void readDetailsFromConnection(RepositoryDiag diag, final SqlRepositoryConfiguration config) { final List<LabeledString> details = diag.getAdditionalDetails(); Session session = getSessionFactory().openSession(); try {/*from w w w .j a v a 2 s . co m*/ session.beginTransaction(); session.doWork(new Work() { @Override public void execute(Connection connection) throws SQLException { details.add(new LabeledString(DETAILS_TRANSACTION_ISOLATION, getTransactionIsolation(connection, config))); Properties info = connection.getClientInfo(); if (info == null) { return; } for (String name : info.stringPropertyNames()) { details.add(new LabeledString(DETAILS_CLIENT_INFO + name, info.getProperty(name))); } } }); session.getTransaction().commit(); if (!(getSessionFactory() instanceof SessionFactoryImpl)) { return; } SessionFactoryImpl factory = (SessionFactoryImpl) getSessionFactory(); // we try to override configuration which was read from sql repo configuration with // real configuration from session factory String dialect = factory.getDialect() != null ? factory.getDialect().getClass().getName() : null; details.add(new LabeledString(DETAILS_HIBERNATE_DIALECT, dialect)); } catch (Throwable th) { //nowhere to report error (no operation result available) session.getTransaction().rollback(); } finally { cleanupSessionAndResult(session, null); } }
From source file:org.apache.phoenix.query.BaseTest.java
private static void deletePriorTables(long ts, Connection globalConn, String url) throws Exception { DatabaseMetaData dbmd = globalConn.getMetaData(); // Drop VIEWs first, as we don't allow a TABLE with views to be dropped // Tables are sorted by TENANT_ID List<String[]> tableTypesList = Arrays.asList(new String[] { PTableType.VIEW.toString() }, new String[] { PTableType.TABLE.toString() }); for (String[] tableTypes : tableTypesList) { ResultSet rs = dbmd.getTables(null, null, null, tableTypes); String lastTenantId = null; Connection conn = globalConn; while (rs.next()) { String fullTableName = SchemaUtil.getEscapedTableName( rs.getString(PhoenixDatabaseMetaData.TABLE_SCHEM), rs.getString(PhoenixDatabaseMetaData.TABLE_NAME)); String ddl = "DROP " + rs.getString(PhoenixDatabaseMetaData.TABLE_TYPE) + " " + fullTableName; String tenantId = rs.getString(1); if (tenantId != null && !tenantId.equals(lastTenantId)) { if (lastTenantId != null) { conn.close();//from w w w . j ava 2 s. com } // Open tenant-specific connection when we find a new one Properties props = PropertiesUtil.deepCopy(globalConn.getClientInfo()); props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId); conn = DriverManager.getConnection(url, props); lastTenantId = tenantId; } try { conn.createStatement().executeUpdate(ddl); } catch (NewerTableAlreadyExistsException ex) { logger.info("Newer table " + fullTableName + " or its delete marker exists. Ignore current deletion"); } catch (TableNotFoundException ex) { logger.info("Table " + fullTableName + " is already deleted."); } } rs.close(); if (lastTenantId != null) { conn.close(); } } }
From source file:org.apache.phoenix.query.BaseTest.java
private static void deletePriorSequences(long ts, Connection globalConn) throws Exception { // TODO: drop tenant-specific sequences too ResultSet rs = globalConn.createStatement() .executeQuery("SELECT " + PhoenixDatabaseMetaData.TENANT_ID + "," + PhoenixDatabaseMetaData.SEQUENCE_SCHEMA + "," + PhoenixDatabaseMetaData.SEQUENCE_NAME + " FROM " + PhoenixDatabaseMetaData.SYSTEM_SEQUENCE); String lastTenantId = null;// w w w .j a v a 2 s . co m Connection conn = globalConn; while (rs.next()) { String tenantId = rs.getString(1); if (tenantId != null && !tenantId.equals(lastTenantId)) { if (lastTenantId != null) { conn.close(); } // Open tenant-specific connection when we find a new one Properties props = new Properties(globalConn.getClientInfo()); props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId); conn = DriverManager.getConnection(url, props); lastTenantId = tenantId; } logger.info("DROP SEQUENCE STATEMENT: DROP SEQUENCE " + SchemaUtil.getEscapedTableName(rs.getString(2), rs.getString(3))); conn.createStatement() .execute("DROP SEQUENCE " + SchemaUtil.getEscapedTableName(rs.getString(2), rs.getString(3))); } rs.close(); }