Esempio n. 1
0
 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("}");
 }
Esempio n. 2
0
 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("}");
 }
Esempio n. 3
0
    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();

      //          We've nothing to do with preferredTestQuery here... the stuff below was
      // unnecessary

      //          iw.println("String preferredTestQuery = null;");
      //          iw.println();
      //          iw.print( CodegenUtils.fqcnLastElement( genclass ) );
      //          iw.println("( " + CodegenUtils.simpleClassName( intfcl ) + " inner,
      // NewPooledConnection parentPooledConnection, String preferredTestQuery )");
      //          iw.println("{");
      //          iw.upIndent();
      //          iw.println("this( inner, parentPooledConnection );");
      //          iw.println("this.preferredTestQuery = preferredTestQuery;");
      //          iw.downIndent();
      //          iw.println("}");
      //          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();
      iw.println(
          "out = new NewProxyDatabaseMetaData( (DatabaseMetaData) out, parentPooledConnection );");
      iw.downIndent();
      iw.println("return out;");
      iw.downIndent();
      iw.println("}");
      iw.println();
      iw.println("synchronized void maybeDirtyTransaction()");
      iw.println("{ txn_known_resolved = false; }");

      super.generateExtraDeclarations(intfcl, genclass, iw);
    }
Esempio n. 4
0
    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(); }");
    }