1 10 11 package com.triactive.jdo.store; 12 13 import java.util.Arrays ; 14 15 16 class RequestIdentifier 17 { 18 private final ClassBaseTable table; 19 private final int[] fields; 20 private final Type type; 21 private final int hashCode; 22 23 24 public RequestIdentifier(ClassBaseTable table, int[] fields, Type type) 25 { 26 this.table = table; 27 this.type = type; 28 29 if (fields == null) 30 this.fields = null; 31 else 32 { 33 this.fields = new int[fields.length]; 34 System.arraycopy(fields, 0, this.fields, 0, fields.length); 35 36 Arrays.sort(this.fields); 38 } 39 40 44 int h = table.hashCode() ^ type.hashCode(); 45 46 if (this.fields != null) 47 { 48 for (int i = 0; i < this.fields.length; ++i) 49 h ^= this.fields[i]; 50 } 51 52 hashCode = h; 53 } 54 55 56 public int hashCode() 57 { 58 return hashCode; 59 } 60 61 62 public boolean equals(Object o) 63 { 64 if (o == this) 65 return true; 66 67 if (!(o instanceof RequestIdentifier)) 68 return false; 69 70 RequestIdentifier ri = (RequestIdentifier)o; 71 72 if (hashCode != ri.hashCode) 73 return false; 74 75 return table.equals(ri.table) 76 && type.equals(ri.type) 77 && Arrays.equals(fields, ri.fields); 78 } 79 80 81 public static class Type 82 { 83 private int typeId; 84 85 public static final Type INSERT = new Type(0); 86 public static final Type LOOKUP = new Type(1); 87 public static final Type FETCH = new Type(2); 88 public static final Type UPDATE = new Type(3); 89 public static final Type DELETE = new Type(4); 90 91 private static final String [] typeNames = 92 { 93 "Insert", 94 "Lookup", 95 "Fetch", 96 "Update", 97 "Delete" 98 }; 99 100 private Type(int typeId) 101 { 102 this.typeId = typeId; 103 } 104 105 public String toString() 106 { 107 return typeNames[typeId]; 108 } 109 } 110 } 111 | Popular Tags |