protected void generateExtraDeclarations(Class intfcl, String genclass, IndentedWriter iw) throws IOException { super.generateExtraDeclarations(intfcl, genclass, iw); iw.println(); iw.println("NewProxyConnection proxyCon;"); iw.println(); iw.print(CodegenUtils.fqcnLastElement(genclass)); iw.println( "( " + CodegenUtils.simpleClassName(intfcl) + " inner, NewPooledConnection parentPooledConnection, NewProxyConnection proxyCon )"); iw.println("{"); iw.upIndent(); iw.println("this( inner, parentPooledConnection );"); iw.println("this.proxyCon = proxyCon;"); iw.downIndent(); iw.println("}"); }
void generateFindMethodAndArgs(Method method, IndentedWriter iw) throws IOException { iw.println("Class[] argTypes = "); iw.println("{"); iw.upIndent(); Class[] argTypes = method.getParameterTypes(); for (int i = 0, len = argTypes.length; i < len; ++i) { if (i != 0) iw.println(","); iw.print(CodegenUtils.simpleClassName(argTypes[i]) + ".class"); } iw.println(); iw.downIndent(); iw.println("};"); iw.println( "Method method = Connection.class.getMethod( \042" + method.getName() + "\042 , argTypes );"); iw.println(); iw.println("Object[] args = "); iw.println("{"); iw.upIndent(); for (int i = 0, len = argTypes.length; i < len; ++i) { if (i != 0) iw.println(","); String argName = CodegenUtils.generatedArgumentName(i); Class argType = argTypes[i]; if (argType.isPrimitive()) { if (argType == boolean.class) iw.print("Boolean.valueOf( " + argName + " )"); else if (argType == byte.class) iw.print("new Byte( " + argName + " )"); else if (argType == char.class) iw.print("new Character( " + argName + " )"); else if (argType == short.class) iw.print("new Short( " + argName + " )"); else if (argType == int.class) iw.print("new Integer( " + argName + " )"); else if (argType == long.class) iw.print("new Long( " + argName + " )"); else if (argType == float.class) iw.print("new Float( " + argName + " )"); else if (argType == double.class) iw.print("new Double( " + argName + " )"); } else iw.print(argName); } iw.downIndent(); iw.println("};"); }
protected void generateExtraDeclarations(Class intfcl, String genclass, IndentedWriter iw) throws IOException { super.generateExtraDeclarations(intfcl, genclass, iw); iw.println(); iw.println("Object creator;"); iw.println("Object creatorProxy;"); iw.println("NewProxyConnection proxyConn;"); iw.println(); iw.print(CodegenUtils.fqcnLastElement(genclass)); iw.println( "( " + CodegenUtils.simpleClassName(intfcl) + " inner, NewPooledConnection parentPooledConnection, Object c, Object cProxy )"); iw.println("{"); iw.upIndent(); iw.println("this( inner, parentPooledConnection );"); iw.println("this.creator = c;"); iw.println("this.creatorProxy = cProxy;"); iw.println( "if (creatorProxy instanceof NewProxyConnection) this.proxyConn = (NewProxyConnection) cProxy;"); iw.downIndent(); iw.println("}"); }
protected void generateExtraDeclarations(Class intfcl, String genclass, IndentedWriter iw) throws IOException { // premature-detach-debug-debug only! if (PREMATURE_DETACH_DEBUG) { iw.println("com.mchange.v2.debug.ThreadNameStackTraceRecorder prematureDetachRecorder"); iw.upIndent(); iw.println( "= new com.mchange.v2.debug.ThreadNameStackTraceRecorder(\042Premature Detach Recorder\042);"); iw.downIndent(); } // end-premature-detach-debug-only! iw.println("private final static MLogger logger = MLog.getLogger( \042" + genclass + "\042 );"); iw.println(); iw.println("volatile NewPooledConnection parentPooledConnection;"); iw.println(); iw.println("ConnectionEventListener cel = new ConnectionEventListener()"); iw.println("{"); iw.upIndent(); iw.println("public void connectionErrorOccurred(ConnectionEvent evt)"); iw.println( "{ /* DON'T detach()... IGNORE -- this could be an ordinary error. Leave it to the PooledConnection to test, but leave proxies intact */ }"); // BAD puppy -- iw.println("{ detach(); }"); iw.println(); iw.println("public void connectionClosed(ConnectionEvent evt)"); iw.println("{ detach(); }"); iw.downIndent(); iw.println("};"); iw.println(); iw.println("void attach( NewPooledConnection parentPooledConnection )"); iw.println("{"); iw.upIndent(); // iw.println("System.err.println( \"attach( \" + parentPooledConnection + \" )\" );"); iw.println("this.parentPooledConnection = parentPooledConnection;"); iw.println("parentPooledConnection.addConnectionEventListener( cel );"); iw.downIndent(); iw.println("}"); iw.println(); iw.println("private void detach()"); iw.println("{"); iw.upIndent(); // factored out so we could define debug versions... writeDetachBody(iw); iw.downIndent(); iw.println("}"); iw.println(); iw.print(CodegenUtils.fqcnLastElement(genclass)); iw.println( "( " + CodegenUtils.simpleClassName(intfcl) + " inner, NewPooledConnection parentPooledConnection )"); iw.println("{"); iw.upIndent(); iw.println("this( inner );"); iw.println("attach( parentPooledConnection );"); generateExtraConstructorCode(intfcl, genclass, iw); iw.downIndent(); iw.println("}"); iw.println(); iw.println("boolean isDetached()"); iw.println("{ return (this.parentPooledConnection == null); }"); iw.println(); iw.println( "public String toString() { return super.toString() + \042 [wrapping: \042 + inner + \042]\042; }"); /* // Support JDBC4 Wrapper interface String wrappedLiteral = intfcl.getName() + ".class"; iw.println(); iw.println("public boolean isWrapperFor(Class<?> iface) throws SQLException"); iw.println("{"); iw.upIndent(); iw.println("return ( " + wrappedLiteral + "== iface || " + wrappedLiteral + ".isAssignableFrom( iface ) );" ); iw.downIndent(); iw.println("}"); iw.println(); iw.println("public <T> T unwrap(Class<T> iface) throws SQLException"); iw.println("{"); iw.upIndent(); iw.println("if (this.isWrapperFor( iface )) return inner;"); iw.println("else throw new SQLException( this + \042 is not a wrapper for \042 + iface.getName());"); iw.downIndent(); iw.println("}"); */ iw.println(); generateIsWrapperHelperMethods(intfcl, iw); }
protected void generateExtraDeclarations(Class intfcl, String genclass, IndentedWriter iw) throws IOException { 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.println("// Although formally unnecessary, we sync access to myProxyResultSets on"); iw.println("// that set's own lock, in case clients (illegally but not uncommonly) close()"); iw.println("// the Statement from a Thread other than the one they use in general"); iw.println("// with the Statement"); iw.println("HashSet myProxyResultSets = new HashSet();"); iw.println(); iw.println("public void detachProxyResultSet( ResultSet prs )"); iw.println("{"); iw.upIndent(); // iw.println("System.err.println(\042detachProxyResultSet\042);"); iw.println("synchronized (myProxyResultSets) { myProxyResultSets.remove( prs ); }"); iw.downIndent(); iw.println("}"); 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("{ if (creatorProxy != null) creatorProxy.maybeDirtyTransaction(); }"); }