1 22 23 24 package com.mchange.v2.c3p0.stmt; 25 26 import java.sql.Connection ; 27 import java.sql.ResultSet ; 28 import java.lang.reflect.Method ; 29 30 final class SimpleStatementCacheKey extends StatementCacheKey 31 { 32 static StatementCacheKey _find( Connection pcon, Method stmtProducingMethod, Object [] args ) 33 { 34 String stmtText = (String ) args[0]; 36 boolean is_callable = stmtProducingMethod.getName().equals("prepareCall"); 37 int result_set_type; 38 int result_set_concurrency; 39 40 int[] columnIndexes; 41 String [] columnNames; 42 Integer autogeneratedKeys; 43 Integer resultSetHoldability; 44 45 if (args.length == 1) 46 { 47 result_set_type = ResultSet.TYPE_FORWARD_ONLY; 48 result_set_concurrency = ResultSet.CONCUR_READ_ONLY; 49 columnIndexes = null; 50 columnNames = null; 51 autogeneratedKeys = null; 52 resultSetHoldability = null; 53 } 54 else if (args.length == 2) 55 { 56 Class [] argTypes = stmtProducingMethod.getParameterTypes(); 57 if (argTypes[1].isArray()) 58 { 59 Class baseType = argTypes[1].getComponentType(); 60 if (baseType == int.class) { 62 result_set_type = ResultSet.TYPE_FORWARD_ONLY; 63 result_set_concurrency = ResultSet.CONCUR_READ_ONLY; 64 columnIndexes = (int[]) args[1]; 65 columnNames = null; 66 autogeneratedKeys = null; 67 resultSetHoldability = null; 68 } 69 else if (baseType == String .class) 70 { 71 result_set_type = ResultSet.TYPE_FORWARD_ONLY; 72 result_set_concurrency = ResultSet.CONCUR_READ_ONLY; 73 columnIndexes = null; 74 columnNames = (String []) args[1]; 75 autogeneratedKeys = null; 76 resultSetHoldability = null; 77 } 78 else 79 throw new IllegalArgumentException ("c3p0 probably needs to be updated for some new " + 80 "JDBC spec! As of JDBC3, we expect two arg statement " + 81 "producing methods where the second arg is either " + 82 "an int, int array, or String array."); 83 } 84 else { 86 result_set_type = ResultSet.TYPE_FORWARD_ONLY; 87 result_set_concurrency = ResultSet.CONCUR_READ_ONLY; 88 columnIndexes = null; 89 columnNames = null; 90 autogeneratedKeys = (Integer ) args[1]; 91 resultSetHoldability = null; 92 } 93 } 94 else if (args.length == 3) 95 { 96 result_set_type = ((Integer ) args[1]).intValue(); 97 result_set_concurrency = ((Integer ) args[2]).intValue(); 98 columnIndexes = null; 99 columnNames = null; 100 autogeneratedKeys = null; 101 resultSetHoldability = null; 102 } 103 else if (args.length == 4) 104 { 105 result_set_type = ((Integer ) args[1]).intValue(); 106 result_set_concurrency = ((Integer ) args[2]).intValue(); 107 columnIndexes = null; 108 columnNames = null; 109 autogeneratedKeys = null; 110 resultSetHoldability = (Integer ) args[3]; 111 } 112 else 113 throw new IllegalArgumentException ("Unexpected number of args to " + 114 stmtProducingMethod.getName() ); 115 117 118 return new SimpleStatementCacheKey( pcon, 119 stmtText, 120 is_callable, 121 result_set_type, 122 result_set_concurrency, 123 columnIndexes, 124 columnNames, 125 autogeneratedKeys, 126 resultSetHoldability ); 127 } 128 129 SimpleStatementCacheKey( Connection physicalConnection, 130 String stmtText, 131 boolean is_callable, 132 int result_set_type, 133 int result_set_concurrency, 134 int[] columnIndexes, 135 String [] columnNames, 136 Integer autogeneratedKeys, 137 Integer resultSetHoldability ) 138 { 139 super( physicalConnection, 140 stmtText, 141 is_callable, 142 result_set_type, 143 result_set_concurrency, 144 columnIndexes, 145 columnNames, 146 autogeneratedKeys, 147 resultSetHoldability ); 148 } 149 150 public boolean equals( Object o ) 151 { return StatementCacheKey.equals( this, o ); } 152 153 public int hashCode() 154 { return StatementCacheKey.hashCode( this ); } 155 } 156 | Popular Tags |