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 import com.mchange.v2.coalesce.*; 30 31 import java.sql.Connection ; 32 import java.sql.ResultSet ; 33 import java.lang.reflect.Method ; 34 import com.mchange.v2.coalesce.*; 35 36 final class ValueIdentityStatementCacheKey extends StatementCacheKey 37 { 38 final static Coalescer keyCoalescer; 41 42 static ValueIdentityStatementCacheKey spare = new ValueIdentityStatementCacheKey(); 44 45 static 46 { 47 CoalesceChecker cc = new CoalesceChecker() 48 { 49 public boolean checkCoalesce( Object a, Object b ) 50 { return StatementCacheKey.equals( (StatementCacheKey) a, b ); } 51 52 public int coalesceHash( Object a ) 53 { return ((ValueIdentityStatementCacheKey) a).cached_hash; } 54 }; 55 56 keyCoalescer = CoalescerFactory.createCoalescer( cc, true, false ); 58 } 59 60 static StatementCacheKey _find( Connection pcon, Method stmtProducingMethod, Object [] args ) 61 { 62 String stmtText = (String ) args[0]; 64 boolean is_callable = stmtProducingMethod.getName().equals("prepareCall"); 65 int result_set_type; 66 int result_set_concurrency; 67 68 int[] columnIndexes; 69 String [] columnNames; 70 Integer autogeneratedKeys; 71 Integer resultSetHoldability; 72 73 if (args.length == 1) 74 { 75 result_set_type = ResultSet.TYPE_FORWARD_ONLY; 76 result_set_concurrency = ResultSet.CONCUR_READ_ONLY; 77 columnIndexes = null; 78 columnNames = null; 79 autogeneratedKeys = null; 80 resultSetHoldability = null; 81 } 82 else if (args.length == 2) 83 { 84 Class [] argTypes = stmtProducingMethod.getParameterTypes(); 85 if (argTypes[1].isArray()) 86 { 87 Class baseType = argTypes[1].getComponentType(); 88 if (baseType == int.class) { 90 result_set_type = ResultSet.TYPE_FORWARD_ONLY; 91 result_set_concurrency = ResultSet.CONCUR_READ_ONLY; 92 columnIndexes = (int[]) args[1]; 93 columnNames = null; 94 autogeneratedKeys = null; 95 resultSetHoldability = null; 96 } 97 else if (baseType == String .class) 98 { 99 result_set_type = ResultSet.TYPE_FORWARD_ONLY; 100 result_set_concurrency = ResultSet.CONCUR_READ_ONLY; 101 columnIndexes = null; 102 columnNames = (String []) args[1]; 103 autogeneratedKeys = null; 104 resultSetHoldability = null; 105 } 106 else 107 throw new IllegalArgumentException ("c3p0 probably needs to be updated for some new " + 108 "JDBC spec! As of JDBC3, we expect two arg statement " + 109 "producing methods where the second arg is either " + 110 "an int, int array, or String array."); 111 } 112 else { 114 result_set_type = ResultSet.TYPE_FORWARD_ONLY; 115 result_set_concurrency = ResultSet.CONCUR_READ_ONLY; 116 columnIndexes = null; 117 columnNames = null; 118 autogeneratedKeys = (Integer ) args[1]; 119 resultSetHoldability = null; 120 } 121 } 122 else if (args.length == 3) 123 { 124 result_set_type = ((Integer ) args[1]).intValue(); 125 result_set_concurrency = ((Integer ) args[2]).intValue(); 126 columnIndexes = null; 127 columnNames = null; 128 autogeneratedKeys = null; 129 resultSetHoldability = null; 130 } 131 else if (args.length == 4) 132 { 133 result_set_type = ((Integer ) args[1]).intValue(); 134 result_set_concurrency = ((Integer ) args[2]).intValue(); 135 columnIndexes = null; 136 columnNames = null; 137 autogeneratedKeys = null; 138 resultSetHoldability = (Integer ) args[3]; 139 } 140 else 141 throw new IllegalArgumentException ("Unexpected number of args to " + 142 stmtProducingMethod.getName() ); 143 145 146 spare.init( pcon, 151 stmtText, 152 is_callable, 153 result_set_type, 154 result_set_concurrency, 155 columnIndexes, 156 columnNames, 157 autogeneratedKeys, 158 resultSetHoldability ); 159 160 StatementCacheKey out = (StatementCacheKey) keyCoalescer.coalesce( spare ); 161 162 166 if (out == spare) 167 spare = new ValueIdentityStatementCacheKey(); 168 return out; 169 } 170 171 void init( Connection physicalConnection, 172 String stmtText, 173 boolean is_callable, 174 int result_set_type, 175 int result_set_concurrency, 176 int[] columnIndexes, 177 String [] columnNames, 178 Integer autogeneratedKeys, 179 Integer resultSetHoldability ) 180 { 181 super.init( physicalConnection, 182 stmtText, 183 is_callable, 184 result_set_type, 185 result_set_concurrency, 186 columnIndexes, 187 columnNames, 188 autogeneratedKeys, 189 resultSetHoldability ); 190 this.cached_hash = StatementCacheKey.hashCode( this ); 191 } 192 193 int cached_hash; 195 196 } 200 201 202 203 | Popular Tags |