1 8 9 package com.sleepycat.persist.test; 10 11 import static com.sleepycat.persist.model.Relationship.MANY_TO_ONE; 12 13 import com.sleepycat.persist.impl.Enhanced; 14 import com.sleepycat.persist.impl.EnhancedAccessor; 15 import com.sleepycat.persist.impl.EntityInput; 16 import com.sleepycat.persist.impl.EntityOutput; 17 import com.sleepycat.persist.impl.Format; 18 import com.sleepycat.persist.model.Entity; 19 import com.sleepycat.persist.model.PrimaryKey; 20 import com.sleepycat.persist.model.SecondaryKey; 21 22 25 @Entity 26 class Enhanced1 implements Enhanced { 27 28 @PrimaryKey 29 private String f1; 30 31 @SecondaryKey(relate=MANY_TO_ONE) 32 private int f2; 33 @SecondaryKey(relate=MANY_TO_ONE) 34 private String f3; 35 @SecondaryKey(relate=MANY_TO_ONE) 36 private String f4; 37 38 private int f5; 39 private String f6; 40 private String f7; 41 private int f8; 42 private int f9; 43 private int f10; 44 private int f11; 45 private int f12; 46 47 static { 48 EnhancedAccessor.registerClass(null, new Enhanced1()); 49 } 50 51 public Object bdbNewInstance() { 52 return new Enhanced1(); 53 } 54 55 public Object bdbNewArray(int len) { 56 return new Enhanced1[len]; 57 } 58 59 public boolean bdbIsPriKeyFieldNullOrZero() { 60 return f1 == null; 61 } 62 63 public void bdbWritePriKeyField(EntityOutput output, Format format) { 64 output.writeKeyObject(f1, format); 65 } 66 67 public void bdbReadPriKeyField(EntityInput input, Format format) { 68 f1 = (String ) input.readKeyObject(format); 69 } 70 71 public void bdbWriteSecKeyFields(EntityOutput output) { 72 73 output.registerPriKeyObject(f1); 74 75 output.writeInt(f2); 76 output.writeObject(f3, null); 77 output.writeObject(f4, null); 78 } 79 80 public void bdbReadSecKeyFields(EntityInput input, 81 int startField, 82 int endField, 83 int superLevel) { 84 85 input.registerPriKeyObject(f1); 86 87 if (superLevel <= 0) { 88 switch (startField) { 89 case 0: 90 f2 = input.readInt(); 91 if (endField == 0) break; 92 case 1: 93 f3 = (String ) input.readObject(); 94 if (endField == 1) break; 95 case 2: 96 f4 = (String ) input.readObject(); 97 } 98 } 99 } 100 101 public void bdbWriteNonKeyFields(EntityOutput output) { 102 output.writeInt(f5); 103 output.writeObject(f6, null); 104 output.writeObject(f7, null); 105 output.writeInt(f8); 106 output.writeInt(f9); 107 output.writeInt(f10); 108 output.writeInt(f11); 109 output.writeInt(f12); 110 } 111 112 public void bdbReadNonKeyFields(EntityInput input, 113 int startField, 114 int endField, 115 int superLevel) { 116 if (superLevel <= 0) { 117 switch (startField) { 118 case 0: 119 f5 = input.readInt(); 120 if (endField == 0) break; 121 case 1: 122 f6 = (String ) input.readObject(); 123 if (endField == 1) break; 124 case 2: 125 f7 = (String ) input.readObject(); 126 if (endField == 2) break; 127 case 3: 128 f8 = input.readInt(); 129 if (endField == 3) break; 130 case 4: 131 f9 = input.readInt(); 132 if (endField == 4) break; 133 case 5: 134 f10 = input.readInt(); 135 if (endField == 5) break; 136 case 6: 137 f11 = input.readInt(); 138 if (endField == 6) break; 139 case 7: 140 f12 = input.readInt(); 141 } 142 } 143 } 144 145 public boolean bdbNullifyKeyField(Object o, 146 int field, 147 int superLevel, 148 boolean isSecField, 149 Object keyElement) { 150 if (superLevel > 0) { 151 return false; 152 } else if (isSecField) { 153 switch (field) { 154 case 1: 155 if (f3 != null) { 156 f3 = null; 157 return true; 158 } else { 159 return false; 160 } 161 case 2: 162 if (f4 != null) { 163 f4 = null; 164 return true; 165 } else { 166 return false; 167 } 168 default: 169 return false; 170 } 171 } else { 172 switch (field) { 173 case 1: 174 if (f6 != null) { 175 f6 = null; 176 return true; 177 } else { 178 return false; 179 } 180 case 2: 181 if (f7 != null) { 182 f7 = null; 183 return true; 184 } else { 185 return false; 186 } 187 default: 188 return false; 189 } 190 } 191 } 192 193 public Object bdbGetField(Object o, 194 int field, 195 int superLevel, 196 boolean isSecField) { 197 if (superLevel > 0) { 198 } else if (isSecField) { 199 switch (field) { 200 case 0: 201 return Integer.valueOf(f2); 202 case 1: 203 return f3; 204 case 2: 205 return f4; 206 } 207 } else { 208 switch (field) { 209 case 0: 210 return Integer.valueOf(f5); 211 case 1: 212 return f6; 213 case 2: 214 return f7; 215 } 216 } 217 return null; 218 } 219 220 public void bdbSetField(Object o, 221 int field, 222 int superLevel, 223 boolean isSecField, 224 Object value) { 225 if (superLevel > 0) { 226 } else if (isSecField) { 227 switch (field) { 228 case 0: 229 f2 = ((Integer ) value).intValue(); 230 return; 231 case 1: 232 f3 = (String ) value; 233 return; 234 case 2: 235 f4 = (String ) value; 236 return; 237 } 238 } else { 239 switch (field) { 240 case 0: 241 f5 = ((Integer ) value).intValue(); 242 return; 243 case 1: 244 f6 = (String ) value; 245 return; 246 case 2: 247 f7 = (String ) value; 248 return; 249 } 250 } 251 } 252 } 253 | Popular Tags |