protected void generateDelegateCode( Class intfcl, String genclass, Method method, IndentedWriter iw) throws IOException { String mname = method.getName(); if (jdbc4WrapperMethod(mname)) { generateWrapperDelegateCode(intfcl, genclass, method, iw); return; } Class retType = method.getReturnType(); iw.println("if (proxyConn != null) proxyConn.maybeDirtyTransaction();"); iw.println(); if (mname.equals("close")) { iw.println("if (! this.isDetached())"); iw.println("{"); iw.upIndent(); iw.println("if (creator instanceof Statement)"); iw.upIndent(); iw.println( "parentPooledConnection.markInactiveResultSetForStatement( (Statement) creator, inner );"); iw.downIndent(); iw.println("else if (creator instanceof DatabaseMetaData)"); iw.upIndent(); iw.println("parentPooledConnection.markInactiveMetaDataResultSet( inner );"); iw.downIndent(); iw.println("else if (creator instanceof Connection)"); iw.upIndent(); iw.println("parentPooledConnection.markInactiveRawConnectionResultSet( inner );"); iw.downIndent(); iw.println( "else throw new InternalError(\042Must be Statement or DatabaseMetaData -- Bad Creator: \042 + creator);"); iw.println( "if (creatorProxy instanceof ProxyResultSetDetachable) ((ProxyResultSetDetachable) creatorProxy).detachProxyResultSet( this );"); iw.println("this.detach();"); iw.println("inner.close();"); iw.println("this.inner = null;"); iw.downIndent(); iw.println("}"); } else if (mname.equals("getStatement")) { iw.println("if (creator instanceof Statement)"); iw.upIndent(); iw.println("return (Statement) creatorProxy;"); iw.downIndent(); iw.println("else if (creator instanceof DatabaseMetaData)"); iw.upIndent(); iw.println("return null;"); iw.downIndent(); iw.println( "else throw new InternalError(\042Must be Statement or DatabaseMetaData -- Bad Creator: \042 + creator);"); } else if (mname.equals("isClosed")) { iw.println("return this.isDetached();"); } else super.generateDelegateCode(intfcl, genclass, method, iw); }
protected void generateDelegateCode( Class intfcl, String genclass, Method method, IndentedWriter iw) throws IOException { String mname = method.getName(); if (jdbc4WrapperMethod(mname)) { generateWrapperDelegateCode(intfcl, genclass, method, iw); return; } Class retType = method.getReturnType(); if (ResultSet.class.isAssignableFrom(retType)) { iw.println("ResultSet innerResultSet = inner." + CodegenUtils.methodCall(method) + ";"); iw.println("if (innerResultSet == null) return null;"); iw.println( "return new NewProxyResultSet( innerResultSet, parentPooledConnection, inner, this );"); } else if (mname.equals("getConnection")) { iw.println("return this.proxyCon;"); } else super.generateDelegateCode(intfcl, genclass, method, iw); }
protected void generateDelegateCode( Class intfcl, String genclass, Method method, IndentedWriter iw) throws IOException { String mname = method.getName(); if (jdbc4WrapperMethod(mname)) { generateWrapperDelegateCode(intfcl, genclass, method, iw); return; } Class retType = method.getReturnType(); iw.println("maybeDirtyTransaction();"); iw.println(); if (ResultSet.class.isAssignableFrom(retType)) { iw.println("ResultSet innerResultSet = inner." + CodegenUtils.methodCall(method) + ";"); iw.println("if (innerResultSet == null) return null;"); iw.println( "parentPooledConnection.markActiveResultSetForStatement( inner, innerResultSet );"); iw.println( "NewProxyResultSet out = new NewProxyResultSet( innerResultSet, parentPooledConnection, inner, this );"); iw.println("synchronized ( myProxyResultSets ) { myProxyResultSets.add( out ); }"); iw.println("return out;"); } else if (mname.equals("getConnection")) { iw.println("if (! this.isDetached())"); iw.upIndent(); iw.println("return creatorProxy;"); iw.downIndent(); iw.println("else"); iw.upIndent(); iw.println("throw new SQLException(\"You cannot operate on a closed Statement!\");"); iw.downIndent(); } else if (mname.equals("close")) { iw.println("if (! this.isDetached())"); iw.println("{"); iw.upIndent(); // iw.println("System.err.println(\042Closing proxy Statement: \042 + this);"); iw.println("synchronized ( myProxyResultSets )"); iw.println("{"); iw.upIndent(); iw.println("for( Iterator ii = myProxyResultSets.iterator(); ii.hasNext(); )"); iw.println("{"); iw.upIndent(); iw.println("ResultSet closeMe = (ResultSet) ii.next();"); iw.println("ii.remove();"); iw.println(); iw.println("try { closeMe.close(); }"); iw.println("catch (SQLException e)"); iw.println("{"); iw.upIndent(); iw.println("if (logger.isLoggable( MLevel.WARNING ))"); iw.upIndent(); iw.println( "logger.log( MLevel.WARNING, \042Exception on close of apparently orphaned ResultSet.\042, e);"); iw.downIndent(); iw.downIndent(); iw.println("}"); iw.println("if (logger.isLoggable( MLevel.FINE ))"); iw.upIndent(); iw.println( "logger.log( MLevel.FINE, this + \042 closed orphaned ResultSet: \042 +closeMe);"); iw.downIndent(); iw.downIndent(); iw.println("}"); iw.downIndent(); iw.println("}"); iw.println(); iw.println("if ( is_cached )"); iw.upIndent(); iw.println("parentPooledConnection.checkinStatement( inner );"); iw.downIndent(); iw.println("else"); iw.println("{"); iw.upIndent(); iw.println("parentPooledConnection.markInactiveUncachedStatement( inner );"); iw.println("try{ inner.close(); }"); iw.println("catch (Exception e )"); iw.println("{"); iw.upIndent(); iw.println("if (logger.isLoggable( MLevel.WARNING ))"); iw.upIndent(); iw.println( "logger.log( MLevel.WARNING, \042Exception on close of inner statement.\042, e);"); iw.downIndent(); iw.println("SQLException sqle = SqlUtils.toSQLException( e );"); iw.println("throw sqle;"); iw.downIndent(); iw.println("}"); iw.downIndent(); iw.println("}"); iw.println(); iw.println("this.detach();"); iw.println("this.inner = null;"); iw.println("this.creatorProxy = null;"); iw.downIndent(); iw.println("}"); } else if (mname.equals("isClosed")) { iw.println("return this.isDetached();"); } else super.generateDelegateCode(intfcl, genclass, method, iw); }
/** * Getting all the alerts in the NMS Alert table and using the alerts, forming the array of * CompositeData.Using the CompositeData forming the TabularData and returning the TabularData */ TabularData getTable() { if (!agentName.initAlert()) return null; TabularData td = null; OpenMBeanParameterInfo[] parameterInfo = new OpenMBeanParameterInfo[names.length]; String returnType = null; try { Class entryClassName = Class.forName(instrClassName); for (int i = 0; i < names.length; i++) { String methodName = "get" + names[i]; // No I18N Method method = entryClassName.getMethod(methodName, null); returnType = method.getReturnType().getName(); parameterInfo[i] = new OpenMBeanParameterInfo(names[i], returnType, null, null, null); } } catch (Exception e) { agentName.agentErr.fail("Exception in getTable(): ", e); // No I18N return null; } try { int numalerts = agentName.alertAPI.getTotalAlertCount(); CompositeData[] comps = new CompositeData[numalerts]; int count = 0; Alert alert = null; String entity = ""; // No I18N String ownerName = ""; // No I18N while (true) { if (alert == null) { try { /** * getting the oldest/first alert in the database which has the least recent mod time */ alert = agentName.alertAPI.getOldestModifiedAlert(); } catch (Exception e) { agentName.agentErr.fail("exception ", e); // No I18N } } else { try { entity = alert.getEntity(); ownerName = alert.getOwnerName(); /** getting the next alert from the database using the modified time as criteria */ if (ownerName != null) alert = agentName.alertAPI.getNextAlertBasedOnModtime( entity + "\t" + ownerName); // No I18N else alert = agentName.alertAPI.getNextAlertBasedOnModtime(entity); } catch (Exception e) { agentName.agentErr.fail("exception", e); // No I18N } } if (alert == null) break; comps[count++] = makeComData(alert); if (count == numalerts) break; } // end of while TabularParameterInfo tinfo = new TabularParameterInfo(null, null, null, null, null, parameterInfo, indexNames); td = new TabularData(tinfo, comps); } catch (Exception e) { agentName.agentErr.fail(" Exception in getTable(): ", e); // No I18N } return td; } // end of getTable