static void genclass(DelegatorGenerator dg, Class intfcl, String fqcn, File srcroot) throws IOException { File genDir = new File(srcroot, dirForFqcn(fqcn)); if (!genDir.exists()) { System.err.println( JdbcProxyGenerator.class.getName() + " -- creating directory: " + genDir.getAbsolutePath()); genDir.mkdirs(); } String fileName = CodegenUtils.fqcnLastElement(fqcn) + ".java"; Writer w = null; try { w = new BufferedWriter(new FileWriter(new File(genDir, fileName))); dg.writeDelegator(intfcl, fqcn, w); w.flush(); System.err.println("Generated " + fileName); } finally { try { if (w != null) w.close(); } catch (Exception e) { e.printStackTrace(); } } }
public static void main(String[] argv) { try { if (argv.length != 1) { System.err.println( "java " + JdbcProxyGenerator.class.getName() + " <source-root-directory>"); return; } File srcroot = new File(argv[0]); if (!srcroot.exists() || !srcroot.canWrite()) { System.err.println( JdbcProxyGenerator.class.getName() + " -- sourceroot: " + argv[0] + " must exist and be writable"); return; } DelegatorGenerator mdgen = new NewProxyMetaDataGenerator(); DelegatorGenerator rsgen = new NewProxyResultSetGenerator(); DelegatorGenerator stgen = new NewProxyAnyStatementGenerator(); DelegatorGenerator cngen = new NewProxyConnectionGenerator(); /* * Eliminating for c3p0-0.9.5 // Usually stgen can be used for all three Statement types. However, we have temporarily // implemented some very partial JDBC4 methods to maintain Hibernate support, prior to full JDBC4 // support in a future version. To do this, we'll need to force some methods into the PreparedStatement // (and therefore CallableStatement) interfaces, methods that don't exist in the current JDBC3 build. // We should be able to get rid of psgen (in favor of stgen above) when we are actually building against // JDBC4 (so we don't need to artificially inject methods). //DelegatorGenerator psgen = new NewProxyAnyStatementGenerator(); //psgen.setReflectiveDelegateMethods( JDBC4TemporaryPreparedStatementMethods.class.getMethods() ); */ genclass(cngen, Connection.class, "com.mchange.v2.c3p0.impl.NewProxyConnection", srcroot); genclass(stgen, Statement.class, "com.mchange.v2.c3p0.impl.NewProxyStatement", srcroot); // genclass( psgen, PreparedStatement.class, // "com.mchange.v2.c3p0.impl.NewProxyPreparedStatement", srcroot ); // genclass( psgen, CallableStatement.class, // "com.mchange.v2.c3p0.impl.NewProxyCallableStatement", srcroot ); genclass( stgen, PreparedStatement.class, "com.mchange.v2.c3p0.impl.NewProxyPreparedStatement", srcroot); genclass( stgen, CallableStatement.class, "com.mchange.v2.c3p0.impl.NewProxyCallableStatement", srcroot); genclass(rsgen, ResultSet.class, "com.mchange.v2.c3p0.impl.NewProxyResultSet", srcroot); genclass( mdgen, DatabaseMetaData.class, "com.mchange.v2.c3p0.impl.NewProxyDatabaseMetaData", srcroot); } catch (Exception e) { e.printStackTrace(); } }