From: Juergen H. <jho...@us...> - 2006-04-21 00:14:23
|
Update of /cvsroot/springframework/spring/src/org/springframework/jdbc/support/nativejdbc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19629/src/org/springframework/jdbc/support/nativejdbc Modified Files: Tag: mbranch-1-2 NativeJdbcExtractorAdapter.java SimpleNativeJdbcExtractor.java Log Message: backported fixes and enhancements from 2.0 M4 (HEAD) Index: SimpleNativeJdbcExtractor.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/jdbc/support/nativejdbc/SimpleNativeJdbcExtractor.java,v retrieving revision 1.12 retrieving revision 1.12.4.1 diff -C2 -d -r1.12 -r1.12.4.1 *** SimpleNativeJdbcExtractor.java 17 Sep 2005 17:05:29 -0000 1.12 --- SimpleNativeJdbcExtractor.java 21 Apr 2006 00:13:49 -0000 1.12.4.1 *************** *** 1,11 **** /* ! * Copyright 2002-2005 the original author or authors. ! * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at ! * * http://www.apache.org/licenses/LICENSE-2.0 ! * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, --- 1,11 ---- /* ! * Copyright 2002-2006 the original author or authors. ! * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at ! * * http://www.apache.org/licenses/LICENSE-2.0 ! * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, *************** *** 33,43 **** * and will also work with any plain JDBC driver. Note that a pool can still wrap * Statements, PreparedStatements, etc: The only requirement of this extractor is ! * that java.sql.DatabaseMetaData does not get wrapped, returning the native ! * Connection of the JDBC driver on <code>metaData.getConnection()</code>. * * <p>Customize this extractor by setting the "nativeConnectionNecessaryForXxx" * flags accordingly: If Statements, PreparedStatements, and/or CallableStatements * are wrapped by your pool, set the corresponding "nativeConnectionNecessaryForXxx" ! * flags to true. If none of the statement types is wrapped - or you solely need * Connection unwrapping in the first place -, the defaults are fine. * --- 33,43 ---- * and will also work with any plain JDBC driver. Note that a pool can still wrap * Statements, PreparedStatements, etc: The only requirement of this extractor is ! * that <code>java.sql.DatabaseMetaData</code> does not get wrapped, returning the ! * native Connection of the JDBC driver on <code>metaData.getConnection()</code>. * * <p>Customize this extractor by setting the "nativeConnectionNecessaryForXxx" * flags accordingly: If Statements, PreparedStatements, and/or CallableStatements * are wrapped by your pool, set the corresponding "nativeConnectionNecessaryForXxx" ! * flags to "true". If none of the statement types is wrapped - or you solely need * Connection unwrapping in the first place -, the defaults are fine. * *************** *** 60,64 **** * Statement objects are wrapped, therefore no special unwrapping is necessary). * <li>Use a SimpleNativeJdbcExtractor with all "nativeConnectionNecessaryForXxx" ! * flags set to true for OC4J and C3P0 (all JDBC Statement objects are wrapped, * but none of the wrappers allow for unwrapping). * <li>Use a CommonsDbcpNativeJdbcExtractor for Jakarta Commons DBCP respectively --- 60,64 ---- * Statement objects are wrapped, therefore no special unwrapping is necessary). * <li>Use a SimpleNativeJdbcExtractor with all "nativeConnectionNecessaryForXxx" ! * flags set to "true" for OC4J and C3P0 (all JDBC Statement objects are wrapped, * but none of the wrappers allow for unwrapping). * <li>Use a CommonsDbcpNativeJdbcExtractor for Jakarta Commons DBCP respectively *************** *** 81,86 **** public class SimpleNativeJdbcExtractor extends NativeJdbcExtractorAdapter { - protected final Log logger = LogFactory.getLog(getClass()); - private boolean nativeConnectionNecessaryForNativeStatements = false; --- 81,84 ---- *************** *** 150,166 **** } - - /** - * Retrieve the Connection via the DatabaseMetaData object, which will - * result in the native JDBC Connection with many connection pools. - * @see java.sql.DatabaseMetaData#getConnection - */ - protected Connection doGetNativeConnection(Connection con) throws SQLException { - Connection nativeCon = con.getMetaData().getConnection(); - if (logger.isDebugEnabled()) { - logger.debug("Returning native Connection [" + nativeCon + "] for given Connection handle [" + con + "]"); - } - return nativeCon; - } - } --- 148,150 ---- Index: NativeJdbcExtractorAdapter.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/jdbc/support/nativejdbc/NativeJdbcExtractorAdapter.java,v retrieving revision 1.6 retrieving revision 1.6.4.1 diff -C2 -d -r1.6 -r1.6.4.1 *** NativeJdbcExtractorAdapter.java 22 Sep 2005 22:05:48 -0000 1.6 --- NativeJdbcExtractorAdapter.java 21 Apr 2006 00:13:49 -0000 1.6.4.1 *************** *** 1,11 **** /* ! * Copyright 2002-2005 the original author or authors. ! * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at ! * * http://www.apache.org/licenses/LICENSE-2.0 ! * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, --- 1,11 ---- /* ! * Copyright 2002-2006 the original author or authors. ! * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at ! * * http://www.apache.org/licenses/LICENSE-2.0 ! * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, *************** *** 19,22 **** --- 19,23 ---- import java.sql.CallableStatement; import java.sql.Connection; + import java.sql.DatabaseMetaData; import java.sql.PreparedStatement; import java.sql.ResultSet; *************** *** 29,33 **** * Abstract adapter class for the NativeJdbcExtractor interface, * for simplified implementation of basic extractors. ! * Returns the passed-in JDBC objects on all methods. * * <p><code>getNativeConnection</code> checks for a ConnectionProxy chain, --- 30,34 ---- * Abstract adapter class for the NativeJdbcExtractor interface, * for simplified implementation of basic extractors. ! * Basically returns the passed-in JDBC objects on all methods. * * <p><code>getNativeConnection</code> checks for a ConnectionProxy chain, *************** *** 37,40 **** --- 38,49 ---- * recommended to participate in ConnectionProxy unwrapping. * + * <p><code>getNativeConnection</code> also applies a fallback if the first + * native extraction process failed, that is, returned the same Connection as + * passed in. It assumes that some additional proxying is going in this case: + * Hence, it retrieves the underlying native Connection from the DatabaseMetaData + * via <code>conHandle.getMetaData().getConnection()</code> and retries the native + * extraction process based on that Connection handle. This works, for example, + * for the Connection proxies exposed by Hibernate 3.1's <code>Session.connection()</code>. + * * <p>The <code>getNativeConnectionFromStatement</code> method is implemented * to simply delegate to <code>getNativeConnection</code> with the Statement's *************** *** 84,89 **** */ public Connection getNativeConnection(Connection con) throws SQLException { ! Connection conToUse = DataSourceUtils.getTargetConnection(con); ! return doGetNativeConnection(conToUse); } --- 93,115 ---- */ public Connection getNativeConnection(Connection con) throws SQLException { ! 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 != targetCon) { ! // We've received a different Connection there: ! // Let's retry the native extraction process with it. ! nativeCon = doGetNativeConnection(metaCon); ! } ! } ! } ! return nativeCon; } |