1 28 29 package com.caucho.amber.query; 30 31 34 public class CachedQueryKey { 35 private String _sql; 36 private Object []_parameters; 37 private int _parameterCount; 38 39 public CachedQueryKey() 40 { 41 } 42 43 public CachedQueryKey(String sql, Object []parameters, int count) 44 { 45 _sql = sql; 46 _parameterCount = count; 47 48 if (count > 0) { 49 _parameters = new Object [count]; 50 51 for (int i = 0; i < count; i++) { 52 _parameters[i] = parameters[i]; 53 } 54 } 55 } 56 57 void init(String sql, Object []parameters, int count) 58 { 59 _sql = sql; 60 _parameters = parameters; 61 _parameterCount = count; 62 } 63 64 67 public String getSQL() 68 { 69 return _sql; 70 } 71 72 75 public int hashCode() 76 { 77 int hash = _sql.hashCode(); 78 79 for (int i = _parameterCount - 1; i >= 0; i--) { 80 Object o = _parameters[i]; 81 82 if (o != null) 83 hash = 65521 * hash + o.hashCode(); 84 else 85 hash = 65521 * hash; 86 } 87 88 return hash; 89 } 90 91 94 public boolean equals(Object o) 95 { 96 if (! (o instanceof CachedQueryKey)) 97 return false; 98 99 CachedQueryKey key = (CachedQueryKey) o; 100 101 if (! _sql.equals(key._sql)) 102 return false; 103 if (_parameterCount != key._parameterCount) 104 return false; 105 106 for (int i = _parameterCount - 1; i >= 0; i--) { 107 Object paramA = _parameters[i]; 108 Object paramB = key._parameters[i]; 109 110 if (paramA != paramB && (paramA == null || ! paramA.equals(paramB))) 111 return false; 112 } 113 114 return true; 115 } 116 } 117 | Popular Tags |