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 java.util.Arrays ; 30 import com.mchange.v1.util.ArrayUtils; 31 import com.mchange.v2.lang.ObjectUtils; 32 33 abstract class StatementCacheKey 34 { 35 static final int SIMPLE = 0; 36 static final int MEMORY_COALESCED = 1; 37 static final int VALUE_IDENTITY = 2; 38 39 public synchronized static StatementCacheKey find( Connection pcon, Method stmtProducingMethod, Object [] args ) 41 { 42 switch ( VALUE_IDENTITY ) 43 { 44 case SIMPLE: 45 return SimpleStatementCacheKey._find( pcon, stmtProducingMethod, args ); 46 case MEMORY_COALESCED: 47 return MemoryCoalescedStatementCacheKey._find( pcon, stmtProducingMethod, args ); 48 case VALUE_IDENTITY: 49 return ValueIdentityStatementCacheKey._find( pcon, stmtProducingMethod, args ); 50 default: 51 throw new InternalError ("StatementCacheKey.find() is misconfigured."); 52 } 53 } 54 55 Connection physicalConnection; 63 String stmtText; 64 boolean is_callable; 65 int result_set_type; 66 int result_set_concurrency; 67 68 int[] columnIndexes; String [] columnNames; 71 Integer autogeneratedKeys; Integer resultSetHoldability; 74 StatementCacheKey() 75 {} 76 77 StatementCacheKey( Connection physicalConnection, 78 String stmtText, 79 boolean is_callable, 80 int result_set_type, 81 int result_set_concurrency, 82 int[] columnIndexes, 83 String [] columnNames, 84 Integer autogeneratedKeys, 85 Integer resultSetHoldability ) 86 { 87 init( physicalConnection, 88 stmtText, 89 is_callable, 90 result_set_type, 91 result_set_concurrency, 92 columnIndexes, 93 columnNames, 94 autogeneratedKeys, 95 resultSetHoldability 96 ); 97 } 98 99 void init( Connection physicalConnection, 100 String stmtText, 101 boolean is_callable, 102 int result_set_type, 103 int result_set_concurrency, 104 int[] columnIndexes, String [] columnNames, Integer autogeneratedKeys, Integer resultSetHoldability) { 109 this.physicalConnection = physicalConnection; 110 this.stmtText = stmtText; 111 this.is_callable = is_callable; 112 this.result_set_type = result_set_type; 113 this.result_set_concurrency = result_set_concurrency; 114 this.columnIndexes = columnIndexes; 115 this.columnNames = columnNames; 116 this.autogeneratedKeys = autogeneratedKeys; 117 this.resultSetHoldability = resultSetHoldability; 118 } 119 120 static boolean equals(StatementCacheKey _this, Object o) 121 { 122 124 if ( _this == o ) 125 return true; 126 if (o instanceof StatementCacheKey) 127 { 128 StatementCacheKey sck = (StatementCacheKey) o; 129 130 134 return 135 sck.physicalConnection.equals(_this.physicalConnection) && 136 sck.stmtText.equals(_this.stmtText) && 137 sck.is_callable == _this.is_callable && 138 sck.result_set_type == _this.result_set_type && 139 sck.result_set_concurrency == _this.result_set_concurrency && 140 Arrays.equals( sck.columnIndexes, _this.columnIndexes ) && 141 Arrays.equals( sck.columnNames, _this.columnNames ) && 142 ObjectUtils.eqOrBothNull( sck.autogeneratedKeys, _this.autogeneratedKeys ) && 143 ObjectUtils.eqOrBothNull( sck.resultSetHoldability, _this.resultSetHoldability ); 144 } 145 else 146 return false; 147 } 148 149 static int hashCode(StatementCacheKey _this) 150 { 151 return 152 _this.physicalConnection.hashCode() ^ 153 _this.stmtText.hashCode() ^ 154 (_this.is_callable ? 1 : 0) ^ 155 _this.result_set_type ^ 156 _this.result_set_concurrency ^ 157 ArrayUtils.hashOrZeroArray( _this.columnIndexes ) ^ 158 ArrayUtils.hashOrZeroArray( _this.columnNames ) ^ 159 ObjectUtils.hashOrZero( _this.autogeneratedKeys ) ^ ObjectUtils.hashOrZero( _this.resultSetHoldability ); } 162 163 public String toString() 164 { 165 StringBuffer out = new StringBuffer (128); 166 out.append("[" + this.getClass().getName() + ": "); 167 out.append("physicalConnection->" + physicalConnection); 168 out.append(", stmtText->" + stmtText); 169 out.append(", is_callable->" + is_callable); 170 out.append(", result_set_type->" + result_set_type); 171 out.append(", result_set_concurrency->" + result_set_concurrency); 172 out.append(", columnIndexes->" + columnIndexes); 173 out.append(", columnNames->" + columnNames); 174 out.append(", autogeneratedKeys->" + autogeneratedKeys); 175 out.append(", resultSetHoldability->" + resultSetHoldability); 176 out.append(']'); 177 return out.toString(); 178 } 179 } 180 181 182 | Popular Tags |