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 final class MemoryCoalescedStatementCacheKey extends StatementCacheKey 32 { 33 final static Coalescer keyCoalescer = CoalescerFactory.createCoalescer( true, false ); 36 37 static StatementCacheKey _find( Connection pcon, Method stmtProducingMethod, Object [] args ) 38 { 39 String stmtText = (String ) args[0]; 41 boolean is_callable = stmtProducingMethod.getName().equals("prepareCall"); 42 int result_set_type; 43 int result_set_concurrency; 44 45 int[] columnIndexes; 46 String [] columnNames; 47 Integer autogeneratedKeys; 48 Integer resultSetHoldability; 49 50 if (args.length == 1) 51 { 52 result_set_type = ResultSet.TYPE_FORWARD_ONLY; 53 result_set_concurrency = ResultSet.CONCUR_READ_ONLY; 54 columnIndexes = null; 55 columnNames = null; 56 autogeneratedKeys = null; 57 resultSetHoldability = null; 58 } 59 else if (args.length == 2) 60 { 61 Class [] argTypes = stmtProducingMethod.getParameterTypes(); 62 if (argTypes[1].isArray()) 63 { 64 Class baseType = argTypes[1].getComponentType(); 65 if (baseType == int.class) { 67 result_set_type = ResultSet.TYPE_FORWARD_ONLY; 68 result_set_concurrency = ResultSet.CONCUR_READ_ONLY; 69 columnIndexes = (int[]) args[1]; 70 columnNames = null; 71 autogeneratedKeys = null; 72 resultSetHoldability = null; 73 } 74 else if (baseType == String .class) 75 { 76 result_set_type = ResultSet.TYPE_FORWARD_ONLY; 77 result_set_concurrency = ResultSet.CONCUR_READ_ONLY; 78 columnIndexes = null; 79 columnNames = (String []) args[1]; 80 autogeneratedKeys = null; 81 resultSetHoldability = null; 82 } 83 else 84 throw new IllegalArgumentException ("c3p0 probably needs to be updated for some new " + 85 "JDBC spec! As of JDBC3, we expect two arg statement " + 86 "producing methods where the second arg is either " + 87 "an int, int array, or String array."); 88 } 89 else { 91 result_set_type = ResultSet.TYPE_FORWARD_ONLY; 92 result_set_concurrency = ResultSet.CONCUR_READ_ONLY; 93 columnIndexes = null; 94 columnNames = null; 95 autogeneratedKeys = (Integer ) args[1]; 96 resultSetHoldability = null; 97 } 98 } 99 else if (args.length == 3) 100 { 101 result_set_type = ((Integer ) args[1]).intValue(); 102 result_set_concurrency = ((Integer ) args[2]).intValue(); 103 columnIndexes = null; 104 columnNames = null; 105 autogeneratedKeys = null; 106 resultSetHoldability = null; 107 } 108 else if (args.length == 4) 109 { 110 result_set_type = ((Integer ) args[1]).intValue(); 111 result_set_concurrency = ((Integer ) args[2]).intValue(); 112 columnIndexes = null; 113 columnNames = null; 114 autogeneratedKeys = null; 115 resultSetHoldability = (Integer ) args[3]; 116 } 117 else 118 throw new IllegalArgumentException ("Unexpected number of args to " + 119 stmtProducingMethod.getName() ); 120 122 123 StatementCacheKey uncanonical 124 = new MemoryCoalescedStatementCacheKey( pcon, 125 stmtText, 126 is_callable, 127 result_set_type, 128 result_set_concurrency, 129 columnIndexes, 130 columnNames, 131 autogeneratedKeys, 132 resultSetHoldability ); 133 return (StatementCacheKey) keyCoalescer.coalesce( uncanonical ); 134 } 135 136 MemoryCoalescedStatementCacheKey( Connection physicalConnection, 137 String stmtText, 138 boolean is_callable, 139 int result_set_type, 140 int result_set_concurrency, 141 int[] columnIndexes, 142 String [] columnNames, 143 Integer autogeneratedKeys, 144 Integer resultSetHoldability ) 145 { 146 super( physicalConnection, 147 stmtText, 148 is_callable, 149 result_set_type, 150 result_set_concurrency, 151 columnIndexes, 152 columnNames, 153 autogeneratedKeys, 154 resultSetHoldability ); 155 } 156 157 public boolean equals( Object o ) 158 { return StatementCacheKey.equals( this, o ); } 159 160 public int hashCode() 161 { return StatementCacheKey.hashCode( this ); } 162 } 163 164 165 166 | Popular Tags |