001: /*-
002: * See the file LICENSE for redistribution information.
003: *
004: * Copyright (c) 2002,2008 Oracle. All rights reserved.
005: *
006: * $Id: Enhanced1.java,v 1.7.2.3 2008/01/07 15:14:35 cwl Exp $
007: */
008:
009: package com.sleepycat.persist.test;
010:
011: import static com.sleepycat.persist.model.Relationship.MANY_TO_ONE;
012:
013: import com.sleepycat.persist.impl.Enhanced;
014: import com.sleepycat.persist.impl.EnhancedAccessor;
015: import com.sleepycat.persist.impl.EntityInput;
016: import com.sleepycat.persist.impl.EntityOutput;
017: import com.sleepycat.persist.impl.Format;
018: import com.sleepycat.persist.model.Entity;
019: import com.sleepycat.persist.model.PrimaryKey;
020: import com.sleepycat.persist.model.SecondaryKey;
021:
022: /**
023: * For running ASMifier -- adds minimal enhancements.
024: */
025: @Entity
026: class Enhanced1 implements Enhanced {
027:
028: @PrimaryKey
029: private String f1;
030:
031: @SecondaryKey(relate=MANY_TO_ONE)
032: private int f2;
033: @SecondaryKey(relate=MANY_TO_ONE)
034: private String f3;
035: @SecondaryKey(relate=MANY_TO_ONE)
036: private String f4;
037:
038: private int f5;
039: private String f6;
040: private String f7;
041: private int f8;
042: private int f9;
043: private int f10;
044: private int f11;
045: private int f12;
046:
047: static {
048: EnhancedAccessor.registerClass(null, new Enhanced1());
049: }
050:
051: public Object bdbNewInstance() {
052: return new Enhanced1();
053: }
054:
055: public Object bdbNewArray(int len) {
056: return new Enhanced1[len];
057: }
058:
059: public boolean bdbIsPriKeyFieldNullOrZero() {
060: return f1 == null;
061: }
062:
063: public void bdbWritePriKeyField(EntityOutput output, Format format) {
064: output.writeKeyObject(f1, format);
065: }
066:
067: public void bdbReadPriKeyField(EntityInput input, Format format) {
068: f1 = (String) input.readKeyObject(format);
069: }
070:
071: public void bdbWriteSecKeyFields(EntityOutput output) {
072: /* If primary key is an object: */
073: output.registerPriKeyObject(f1);
074: /* Always: */
075: output.writeInt(f2);
076: output.writeObject(f3, null);
077: output.writeObject(f4, null);
078: }
079:
080: public void bdbReadSecKeyFields(EntityInput input, int startField,
081: int endField, int super Level) {
082: /* If primary key is an object: */
083: input.registerPriKeyObject(f1);
084:
085: if (super Level <= 0) {
086: switch (startField) {
087: case 0:
088: f2 = input.readInt();
089: if (endField == 0)
090: break;
091: case 1:
092: f3 = (String) input.readObject();
093: if (endField == 1)
094: break;
095: case 2:
096: f4 = (String) input.readObject();
097: }
098: }
099: }
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, int startField,
113: int endField, int super Level) {
114: if (super Level <= 0) {
115: switch (startField) {
116: case 0:
117: f5 = input.readInt();
118: if (endField == 0)
119: break;
120: case 1:
121: f6 = (String) input.readObject();
122: if (endField == 1)
123: break;
124: case 2:
125: f7 = (String) input.readObject();
126: if (endField == 2)
127: break;
128: case 3:
129: f8 = input.readInt();
130: if (endField == 3)
131: break;
132: case 4:
133: f9 = input.readInt();
134: if (endField == 4)
135: break;
136: case 5:
137: f10 = input.readInt();
138: if (endField == 5)
139: break;
140: case 6:
141: f11 = input.readInt();
142: if (endField == 6)
143: break;
144: case 7:
145: f12 = input.readInt();
146: }
147: }
148: }
149:
150: public boolean bdbNullifyKeyField(Object o, int field,
151: int super Level, boolean isSecField, Object keyElement) {
152: if (super Level > 0) {
153: return false;
154: } else if (isSecField) {
155: switch (field) {
156: case 1:
157: if (f3 != null) {
158: f3 = null;
159: return true;
160: } else {
161: return false;
162: }
163: case 2:
164: if (f4 != null) {
165: f4 = null;
166: return true;
167: } else {
168: return false;
169: }
170: default:
171: return false;
172: }
173: } else {
174: switch (field) {
175: case 1:
176: if (f6 != null) {
177: f6 = null;
178: return true;
179: } else {
180: return false;
181: }
182: case 2:
183: if (f7 != null) {
184: f7 = null;
185: return true;
186: } else {
187: return false;
188: }
189: default:
190: return false;
191: }
192: }
193: }
194:
195: public Object bdbGetField(Object o, int field, int super Level,
196: boolean isSecField) {
197: if (super Level > 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, int field, int super Level,
221: boolean isSecField, Object value) {
222: if (super Level > 0) {
223: } else if (isSecField) {
224: switch (field) {
225: case 0:
226: f2 = ((Integer) value).intValue();
227: return;
228: case 1:
229: f3 = (String) value;
230: return;
231: case 2:
232: f4 = (String) value;
233: return;
234: }
235: } else {
236: switch (field) {
237: case 0:
238: f5 = ((Integer) value).intValue();
239: return;
240: case 1:
241: f6 = (String) value;
242: return;
243: case 2:
244: f7 = (String) value;
245: return;
246: }
247: }
248: }
249: }
|