1 22 23 24 package com.mchange.v2.c3p0.test; 25 26 import java.lang.reflect.Method ; 27 28 import com.mchange.v2.c3p0.ComboPooledDataSource; 29 import com.mchange.v2.c3p0.C3P0ProxyConnection; 30 import com.mchange.v2.c3p0.C3P0ProxyStatement; 31 import com.mchange.v2.c3p0.util.TestUtils; 32 33 public final class RawConnectionOpTest 34 { 35 public static void main(String [] argv) 36 { 37 try 38 { 39 String jdbc_url = null; 40 String username = null; 41 String password = null; 42 43 if (argv.length == 3) 44 { 45 jdbc_url = argv[0]; 46 username = argv[1]; 47 password = argv[2]; 48 } 49 else if (argv.length == 1) 50 { 51 jdbc_url = argv[0]; 52 username = null; 53 password = null; 54 } 55 else 56 usage(); 57 58 if (! jdbc_url.startsWith("jdbc:") ) 59 usage(); 60 61 ComboPooledDataSource cpds = new ComboPooledDataSource(); 62 cpds.setJdbcUrl( jdbc_url ); 63 cpds.setUser( username ); 64 cpds.setPassword( password ); 65 cpds.setMaxPoolSize( 10 ); 66 68 C3P0ProxyConnection conn = (C3P0ProxyConnection) cpds.getConnection(); 69 Method toStringMethod = Object .class.getMethod("toString", new Class []{}); 70 Method identityHashCodeMethod = System .class.getMethod("identityHashCode", new Class [] {Object .class}); 71 System.out.println("rawConnection.toString() -> " + 72 conn.rawConnectionOperation(toStringMethod, C3P0ProxyConnection.RAW_CONNECTION, new Object []{})); 73 Integer ihc = (Integer ) conn.rawConnectionOperation(identityHashCodeMethod, null, new Object []{C3P0ProxyConnection.RAW_CONNECTION}); 74 System.out.println("System.identityHashCode( rawConnection ) -> " + Integer.toHexString( ihc.intValue() )); 75 76 C3P0ProxyStatement stmt = (C3P0ProxyStatement) conn.createStatement(); 77 System.out.println("rawStatement.toString() -> " + 78 stmt.rawStatementOperation(toStringMethod, C3P0ProxyStatement.RAW_STATEMENT, new Object []{})); 79 Integer ihc2 = (Integer ) stmt.rawStatementOperation(identityHashCodeMethod, null, new Object []{C3P0ProxyStatement.RAW_STATEMENT}); 80 System.out.println("System.identityHashCode( rawStatement ) -> " + Integer.toHexString( ihc2.intValue() )); 81 82 conn.close(); 83 84 for (int i = 0; i < 10; ++i) 85 { 86 C3P0ProxyConnection check = null; 87 try 88 { 89 check = (C3P0ProxyConnection) cpds.getConnection(); 90 System.err.println( TestUtils.physicalConnectionIdentityHashCode( check ) == ihc.intValue() ); 92 } 93 finally 94 { } 95 } 96 } 97 catch (Exception e) 98 { e.printStackTrace(); } 99 } 100 101 private static void usage() 102 { 103 System.err.println("java " + RawConnectionOpTest.class.getName() + " \\"); 104 System.err.println("\t<jdbc_driver_class> \\"); 105 System.err.println("\t<jdbc_url> [<username> <password>]"); 106 System.exit(-1); 107 } 108 } 109 | Popular Tags |