Java Code Examples for java.sql.DatabaseMetaData#getConnection()
The following examples show how to use
java.sql.DatabaseMetaData#getConnection() .
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: OracleTableMetaDataProvider.java From spring-analysis-note with MIT License | 6 votes |
@Nullable private static String lookupDefaultSchema(DatabaseMetaData databaseMetaData) { try { CallableStatement cstmt = null; try { Connection con = databaseMetaData.getConnection(); if (con == null) { logger.debug("Cannot check default schema - no Connection from DatabaseMetaData"); return null; } cstmt = con.prepareCall("{? = call sys_context('USERENV', 'CURRENT_SCHEMA')}"); cstmt.registerOutParameter(1, Types.VARCHAR); cstmt.execute(); return cstmt.getString(1); } finally { if (cstmt != null) { cstmt.close(); } } } catch (SQLException ex) { logger.debug("Exception encountered during default schema lookup", ex); return null; } }
Example 2
Source File: OracleTableMetaDataProvider.java From java-technology-stack with MIT License | 6 votes |
@Nullable private static String lookupDefaultSchema(DatabaseMetaData databaseMetaData) { try { CallableStatement cstmt = null; try { Connection con = databaseMetaData.getConnection(); if (con == null) { logger.debug("Cannot check default schema - no Connection from DatabaseMetaData"); return null; } cstmt = con.prepareCall("{? = call sys_context('USERENV', 'CURRENT_SCHEMA')}"); cstmt.registerOutParameter(1, Types.VARCHAR); cstmt.execute(); return cstmt.getString(1); } finally { if (cstmt != null) { cstmt.close(); } } } catch (SQLException ex) { logger.debug("Exception encountered during default schema lookup", ex); return null; } }
Example 3
Source File: NativeJdbcExtractorAdapter.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Check for a ConnectionProxy chain, then delegate to doGetNativeConnection. * <p>ConnectionProxy is used by Spring's TransactionAwareDataSourceProxy * and LazyConnectionDataSourceProxy. The target connection behind it is * typically one from a local connection pool, to be unwrapped by the * doGetNativeConnection implementation of a concrete subclass. * @see #doGetNativeConnection * @see org.springframework.jdbc.datasource.ConnectionProxy * @see org.springframework.jdbc.datasource.DataSourceUtils#getTargetConnection * @see org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy * @see org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy */ @Override public Connection getNativeConnection(Connection con) throws SQLException { if (con == null) { return null; } Connection targetCon = DataSourceUtils.getTargetConnection(con); Connection nativeCon = doGetNativeConnection(targetCon); if (nativeCon == targetCon) { // We haven't received a different Connection, so we'll assume that there's // some additional proxying going on. Let's check whether we get something // different back from the DatabaseMetaData.getConnection() call. DatabaseMetaData metaData = targetCon.getMetaData(); // The following check is only really there for mock Connections // which might not carry a DatabaseMetaData instance. if (metaData != null) { Connection metaCon = metaData.getConnection(); if (metaCon != null && metaCon != targetCon) { // We've received a different Connection there: // Let's retry the native extraction process with it. nativeCon = doGetNativeConnection(metaCon); } } } return nativeCon; }
Example 4
Source File: NativeJdbcExtractorAdapter.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Check for a ConnectionProxy chain, then delegate to doGetNativeConnection. * <p>ConnectionProxy is used by Spring's TransactionAwareDataSourceProxy * and LazyConnectionDataSourceProxy. The target connection behind it is * typically one from a local connection pool, to be unwrapped by the * doGetNativeConnection implementation of a concrete subclass. * @see #doGetNativeConnection * @see org.springframework.jdbc.datasource.ConnectionProxy * @see org.springframework.jdbc.datasource.DataSourceUtils#getTargetConnection * @see org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy * @see org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy */ @Override public Connection getNativeConnection(Connection con) throws SQLException { if (con == null) { return null; } Connection targetCon = DataSourceUtils.getTargetConnection(con); Connection nativeCon = doGetNativeConnection(targetCon); if (nativeCon == targetCon) { // We haven't received a different Connection, so we'll assume that there's // some additional proxying going on. Let's check whether we get something // different back from the DatabaseMetaData.getConnection() call. DatabaseMetaData metaData = targetCon.getMetaData(); // The following check is only really there for mock Connections // which might not carry a DatabaseMetaData instance. if (metaData != null) { Connection metaCon = metaData.getConnection(); if (metaCon != null && metaCon != targetCon) { // We've received a different Connection there: // Let's retry the native extraction process with it. nativeCon = doGetNativeConnection(metaCon); } } } return nativeCon; }
Example 5
Source File: NativeJdbcExtractorAdapter.java From effectivejava with Apache License 2.0 | 6 votes |
/** * Check for a ConnectionProxy chain, then delegate to doGetNativeConnection. * <p>ConnectionProxy is used by Spring's TransactionAwareDataSourceProxy * and LazyConnectionDataSourceProxy. The target connection behind it is * typically one from a local connection pool, to be unwrapped by the * doGetNativeConnection implementation of a concrete subclass. * @see #doGetNativeConnection * @see org.springframework.jdbc.datasource.ConnectionProxy * @see org.springframework.jdbc.datasource.DataSourceUtils#getTargetConnection * @see org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy * @see org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy */ @Override public Connection getNativeConnection(Connection con) throws SQLException { if (con == null) { return null; } Connection targetCon = DataSourceUtils.getTargetConnection(con); Connection nativeCon = doGetNativeConnection(targetCon); if (nativeCon == targetCon) { // We haven't received a different Connection, so we'll assume that there's // some additional proxying going on. Let's check whether we get something // different back from the DatabaseMetaData.getConnection() call. DatabaseMetaData metaData = targetCon.getMetaData(); // The following check is only really there for mock Connections // which might not carry a DatabaseMetaData instance. if (metaData != null) { Connection metaCon = metaData.getConnection(); if (metaCon != null && metaCon != targetCon) { // We've received a different Connection there: // Let's retry the native extraction process with it. nativeCon = doGetNativeConnection(metaCon); } } } return nativeCon; }
Example 6
Source File: OracleReverseEngineeringStrategy.java From MogwaiERDesignerNG with GNU General Public License v3.0 | 5 votes |
@Override protected void reverseEngineerIndexAttribute(DatabaseMetaData aMetaData, TableEntry aTableEntry, Table aTable, ReverseEngineeringNotifier aNotifier, Index aIndex, String aColumnName, short aPosition, String aAscOrDesc) throws SQLException, ReverseEngineeringException { // This needs only to be checked if it is a function based index if (!aColumnName.endsWith("$")) { super.reverseEngineerIndexAttribute(aMetaData, aTableEntry, aTable, aNotifier, aIndex, aColumnName, aPosition, aAscOrDesc); return; } Connection theConnection = aMetaData.getConnection(); PreparedStatement theStatement = theConnection.prepareStatement("SELECT * FROM USER_IND_EXPRESSIONS WHERE INDEX_NAME = ? AND TABLE_NAME = ? AND COLUMN_POSITION = ?"); theStatement.setString(1, aIndex.getOriginalName()); theStatement.setString(2, aTable.getOriginalName()); theStatement.setShort(3, aPosition); ResultSet theResult = theStatement.executeQuery(); boolean found = false; while (theResult.next()) { found = true; String theColumnExpression = theResult.getString("COLUMN_EXPRESSION"); aIndex.getExpressions().addExpressionFor(theColumnExpression); } theResult.close(); theStatement.close(); if (!found) { throw new ReverseEngineeringException("Cannot find index column information for " + aColumnName + " index " + aIndex.getName() + " table " + aTable.getName()); } }