📄 jdbcproxygenerator.java
字号:
super.generateExtraDeclarations( intfcl, genclass, iw ); iw.println(); // concurrent-access-debug only! if (CONCURRENT_ACCESS_DEBUG) { iw.println("com.mchange.v2.debug.ThreadNameStackTraceRecorder concurrentAccessRecorder"); iw.upIndent(); iw.println("= new com.mchange.v2.debug.ThreadNameStackTraceRecorder(\042Concurrent Access Recorder\042);"); iw.downIndent(); } // end concurrent-access-debug only! iw.println("boolean is_cached;"); iw.println("NewProxyConnection creatorProxy;"); iw.println(); iw.print( CodegenUtils.fqcnLastElement( genclass ) ); iw.println("( " + CodegenUtils.simpleClassName( intfcl ) + " inner, NewPooledConnection parentPooledConnection, boolean cached, NewProxyConnection cProxy )"); iw.println("{"); iw.upIndent(); iw.println("this( inner, parentPooledConnection );"); iw.println("this.is_cached = cached;"); iw.println("this.creatorProxy = cProxy;"); iw.downIndent(); iw.println("}"); iw.println(); iw.println("public Object rawStatementOperation(Method m, Object target, Object[] args) " + "throws IllegalAccessException, InvocationTargetException, SQLException"); iw.println("{"); iw.upIndent(); iw.println("maybeDirtyTransaction();"); iw.println(); iw.println("if (target == C3P0ProxyStatement.RAW_STATEMENT) target = inner;"); iw.println("for (int i = 0, len = args.length; i < len; ++i)"); iw.upIndent(); iw.println("if (args[i] == C3P0ProxyStatement.RAW_STATEMENT) args[i] = inner;"); iw.downIndent(); iw.println("Object out = m.invoke(target, args);"); iw.println("if (out instanceof ResultSet)"); iw.println("{"); iw.upIndent(); iw.println("ResultSet innerResultSet = (ResultSet) out;"); iw.println("parentPooledConnection.markActiveResultSetForStatement( inner, innerResultSet );"); iw.println("out = new NewProxyResultSet( innerResultSet, parentPooledConnection, inner, this );"); iw.downIndent(); iw.println("}"); iw.println(); iw.println("return out;"); iw.downIndent(); iw.println("}"); iw.println(); iw.println("void maybeDirtyTransaction()"); iw.println("{ creatorProxy.maybeDirtyTransaction(); }"); } protected void generateExtraImports( IndentedWriter iw ) throws IOException { super.generateExtraImports( iw ); iw.println("import java.lang.reflect.InvocationTargetException;"); } }// protected void generateExtraDeclarations( Class intfcl, String genclass, IndentedWriter iw ) throws IOException// {// super.generateExtraDeclarations( intfcl, genclass, iw );// iw.println();// iw.println("Statement creatingStatement;");// iw.println();// iw.print( CodegenUtils.fqcnLastElement( genclass ) );// iw.println("( " + CodegenUtils.simpleClassName( intfcl.getClass() ) + " inner, NewPooledConnection parentPooledConnection, Statement stmt )");// iw.println("{");// iw.upIndent();// iw.println("this( inner, parentPooledConnection );");// iw.println("this.creatingStatement = stmt;");// iw.downIndent();// iw.println("}");// } static final class NewProxyConnectionGenerator extends JdbcProxyGenerator { String getInnerTypeName() { return "Connection"; } { this.setMethodModifiers( Modifier.PUBLIC | Modifier.SYNCHRONIZED ); this.setExtraInterfaces( new Class[] { C3P0ProxyConnection.class } ); } protected void generateDelegateCode( Class intfcl, String genclass, Method method, IndentedWriter iw ) throws IOException { String mname = method.getName(); if (mname.equals("createStatement")) { iw.println("txn_known_resolved = false;"); iw.println(); iw.println("Statement innerStmt = inner." + CodegenUtils.methodCall( method ) + ";"); iw.println("parentPooledConnection.markActiveUncachedStatement( innerStmt );"); iw.println("return new NewProxyStatement( innerStmt, parentPooledConnection, false, this );"); } else if (mname.equals("prepareStatement")) { iw.println("txn_known_resolved = false;"); iw.println(); iw.println("PreparedStatement innerStmt;"); iw.println(); iw.println("if ( parentPooledConnection.isStatementCaching() )"); iw.println("{"); iw.upIndent(); generateFindMethodAndArgs( method, iw ); iw.println("innerStmt = (PreparedStatement) parentPooledConnection.checkoutStatement( method, args );"); iw.println("return new NewProxyPreparedStatement( innerStmt, parentPooledConnection, true, this );"); iw.downIndent(); iw.println("}"); iw.println("else"); iw.println("{"); iw.upIndent(); iw.println("innerStmt = inner." + CodegenUtils.methodCall( method ) + ";"); iw.println("parentPooledConnection.markActiveUncachedStatement( innerStmt );"); iw.println("return new NewProxyPreparedStatement( innerStmt, parentPooledConnection, false, this );"); iw.downIndent(); iw.println("}"); } else if (mname.equals("prepareCall")) { iw.println("txn_known_resolved = false;"); iw.println(); iw.println("CallableStatement innerStmt;"); iw.println(); iw.println("if ( parentPooledConnection.isStatementCaching() )"); iw.println("{"); iw.upIndent(); generateFindMethodAndArgs( method, iw ); iw.println("innerStmt = (CallableStatement) parentPooledConnection.checkoutStatement( method, args );"); iw.println("return new NewProxyCallableStatement( innerStmt, parentPooledConnection, true, this );"); iw.downIndent(); iw.println("}"); iw.println("else"); iw.println("{"); iw.upIndent(); iw.println("innerStmt = inner." + CodegenUtils.methodCall( method ) + ";"); iw.println("parentPooledConnection.markActiveUncachedStatement( innerStmt );"); iw.println("return new NewProxyCallableStatement( innerStmt, parentPooledConnection, false, this );"); iw.downIndent(); iw.println("}"); } else if (mname.equals("getMetaData")) { iw.println("txn_known_resolved = false;"); iw.println(); iw.println("if (this.metaData == null)"); iw.println("{"); iw.upIndent(); iw.println("DatabaseMetaData innerMetaData = inner." + CodegenUtils.methodCall( method ) + ";"); iw.println("this.metaData = new NewProxyDatabaseMetaData( innerMetaData, parentPooledConnection, this );"); iw.downIndent(); iw.println("}"); iw.println("return this.metaData;"); } else if ( mname.equals("setTransactionIsolation") ) { //do nothing with txn_known_resolved super.generateDelegateCode( intfcl, genclass, method, iw ); iw.println( "parentPooledConnection.markNewTxnIsolation( " + CodegenUtils.generatedArgumentName( 0 ) + " );"); } else if ( mname.equals("setCatalog") ) { //do nothing with txn_known_resolved super.generateDelegateCode( intfcl, genclass, method, iw ); iw.println( "parentPooledConnection.markNewCatalog( " + CodegenUtils.generatedArgumentName( 0 ) + " );"); } else if ( mname.equals("setHoldability") ) { //do nothing with txn_known_resolved super.generateDelegateCode( intfcl, genclass, method, iw ); iw.println( "parentPooledConnection.markNewHoldability( " + CodegenUtils.generatedArgumentName( 0 ) + " );"); } else if ( mname.equals("setReadOnly") ) { //do nothing with txn_known_resolved super.generateDelegateCode( intfcl, genclass, method, iw ); iw.println( "parentPooledConnection.markNewReadOnly( " + CodegenUtils.generatedArgumentName( 0 ) + " );"); } else if ( mname.equals("setTypeMap") ) { //do nothing with txn_known_resolved super.generateDelegateCode( intfcl, genclass, method, iw ); iw.println( "parentPooledConnection.markNewTypeMap( " + CodegenUtils.generatedArgumentName( 0 ) + " );"); } else if ( mname.equals("close") ) { iw.println("if (! this.isDetached())"); iw.println("{"); iw.upIndent(); iw.println("NewPooledConnection npc = parentPooledConnection;"); iw.println("this.detach();"); iw.println("npc.markClosedProxyConnection( this, txn_known_resolved );"); iw.println("this.inner = null;"); iw.downIndent(); iw.println("}"); iw.println("else if (Debug.DEBUG && logger.isLoggable( MLevel.FINE ))"); iw.println("{"); iw.upIndent(); iw.println("logger.log( MLevel.FINE, this + \042: close() called more than once.\042 );"); // premature-detach-debug-debug only! if (PREMATURE_DETACH_DEBUG) { iw.println("prematureDetachRecorder.record();"); iw.println("logger.warning( prematureDetachRecorder.getDump(\042Apparent multiple close of " + getInnerTypeName() + ".\042) );"); } // end-premature-detach-debug-only! iw.downIndent(); iw.println("}"); } else if ( mname.equals("isClosed") ) { iw.println("return this.isDetached();"); } else { iw.println("txn_known_resolved = " + ( mname.equals("commit") || mname.equals( "rollback" ) || mname.equals( "setAutoCommit" ) ) + ';'); iw.println(); super.generateDelegateCode( intfcl, genclass, method, iw ); } } protected void generateExtraDeclarations( Class intfcl, String genclass, IndentedWriter iw ) throws IOException { iw.println("boolean txn_known_resolved = true;"); iw.println(); iw.println("DatabaseMetaData metaData = null;"); iw.println(); iw.println("public Object rawConnectionOperation(Method m, Object target, Object[] args)"); iw.upIndent(); iw.println("throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, SQLException"); iw.downIndent(); iw.println("{"); iw.upIndent(); iw.println("maybeDirtyTransaction();"); iw.println(); iw.println("if (inner == null)"); iw.upIndent(); iw.println("throw new SQLException(\"You cannot operate on a closed Connection!\");"); iw.downIndent(); iw.println("if ( target == C3P0ProxyConnection.RAW_CONNECTION)"); iw.upIndent(); iw.println("target = inner;"); iw.downIndent(); iw.println("for (int i = 0, len = args.length; i < len; ++i)"); iw.upIndent(); iw.println("if (args[i] == C3P0ProxyConnection.RAW_CONNECTION)"); iw.upIndent(); iw.println("args[i] = inner;"); iw.downIndent(); iw.downIndent(); iw.println("Object out = m.invoke( target, args );"); iw.println(); iw.println("// we never cache Statements generated by an operation on the raw Connection"); iw.println("if (out instanceof CallableStatement)"); iw.println("{"); iw.upIndent(); iw.println("CallableStatement innerStmt = (CallableStatement) out;"); iw.println("parentPooledConnection.markActiveUncachedStatement( innerStmt );"); iw.println("out = new NewProxyCallableStatement( innerStmt, parentPooledConnection, false, this );"); iw.downIndent(); iw.println("}"); iw.println("else if (out instanceof PreparedStatement)"); iw.println("{"); iw.upIndent(); iw.println("PreparedStatement innerStmt = (PreparedStatement) out;"); iw.println("parentPooledConnection.markActiveUncachedStatement( innerStmt );"); iw.println("out = new NewProxyPreparedStatement( innerStmt, parentPooledConnection, false, this );"); iw.downIndent(); iw.println("}"); iw.println("else if (out instanceof Statement)"); iw.println("{"); iw.upIndent(); iw.println("Statement innerStmt = (Statement) out;"); iw.println("parentPooledConnection.markActiveUncachedStatement( innerStmt );"); iw.println("out = new NewProxyStatement( innerStmt, parentPooledConnection, false, this );"); iw.downIndent(); iw.println("}"); iw.println("else if (out instanceof ResultSet)"); iw.println("{"); iw.upIndent(); iw.println("ResultSet innerRs = (ResultSet) out;"); iw.println("parentPooledConnection.markActiveRawConnectionResultSet( innerRs );"); iw.println("out = new NewProxyResultSet( innerRs, parentPooledConnection, inner, this );"); iw.downIndent(); iw.println("}"); iw.println("else if (out instanceof DatabaseMetaData)"); iw.upIndent();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -