Debian Codegraph @

lang/java/src/com/sleepycat/persist/impl/Accessor.java

raw
1 /*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2002, 2013 Oracle and/or its affiliates. All rights reserved.
5 *
6 */
7
8 package com.sleepycat.persist.impl;
9
10 /**
11 * Field binding operations implemented via reflection (ReflectionAccessor) or
12 * bytecode enhancement (EnhancedAccessor).
13 *
14 * <p>Normally we read the set of all secondary key fields first and then the
15 * set of all non-key fields, reading each set in order of field name. But
16 * when reading an old format record we must account for the following
17 * class evolution conversions:</p>
18 * <ul>
19 * <li>Convert a field: pass value thru converter</li>
20 * <li>Widen a field type: pass value thru widener</li>
21 * <li>Add a field: don't read the new field</li>
22 * <li>Delete a field: skip the deleted field</li>
23 * <li>Rename a field: read field in a different order</li>
24 * </ul>
25 * <p>To support these operations, the methods for reading fields allow reading
26 * specific ranges of fields as well as all fields. For example, all fields
27 * up to a deleted field could be read, and then all fields from the following
28 * field onward.</p>
29 *
30 * @author Mark Hayes
31 */
32 interface Accessor {
33
34 /**
35 * A large field value to use instead of Integer.MAX_VALUE, to work around
36 * Java JIT compiler bug when doing an (X <= Integer.MAX_VALUE) as would be
37 * done in readXxxKeyFields methods.
38 */
39 final int MAX_FIELD_NUM = Integer.MAX_VALUE - 1;
40
41 /**
42 * Creates a new instance of the target class using its default
43 * constructor.
44 */
45 Object newInstance();
46
47 /**
48 * Creates a new one dimensional array of the given length, having the
49 * target class as its component type.
50 *
51 * <p>Using a special method for a one dimensional array, which can be
52 * implemented by bytecode generation, is a compromise. We use reflection
53 * to create multidimensional arrays. We could in the future generate code
54 * to create arrays as they are encountered, if there is a need to avoid
55 * reflection for multidimensional arrays.</p>
56 */
57 Object newArray(int len);
58
59 /**
60 * Returns whether the primary key field is null (for a reference type) or
61 * zero (for a primitive integer type). Null and zero are used as an
62 * indication that the key should be assigned from a sequence.
63 */
64 boolean isPriKeyFieldNullOrZero(Object o);
65
66 /**
67 * Writes the primary key field value to the given EntityOutput.
68 *
69 * <p>To write a primary key with a reference type, this method must call
70 * EntityOutput.writeKeyObject.</p>
71 *
72 * @param o is the object whose primary key field is to be written.
73 *
74 * @param output the output data to write to.
75 */
76 void writePriKeyField(Object o, EntityOutput output)
77 throws RefreshException;
78
79 /**
80 * Reads the primary key field value from the given EntityInput.
81 *
82 * <p>To read a primary key with a reference type, this method must call
83 * EntityInput.readKeyObject.</p>
84 *
85 * @param o is the object whose primary key field is to be read.
86 *
87 * @param input the input data to read from.
88 */
89 void readPriKeyField(Object o, EntityInput input)
90 throws RefreshException;
91
92 /**
93 * Writes all secondary key field values to the given EntityOutput,
94 * writing fields in super classes first and in name order within class.
95 *
96 * @param o is the object whose secondary key fields are to be written.
97 *
98 * <p>If the primary key has a reference type, this method must call
99 * EntityOutput.registerPriKeyObject before writing any other fields.</p>
100 *
101 * @param output the output data to write to.
102 */
103 void writeSecKeyFields(Object o, EntityOutput output)
104 throws RefreshException;
105
106 /**
107 * Reads a range of secondary key field values from the given EntityInput,
108 * reading fields in super classes first and in name order within class.
109 *
110 * <p>If the primary key has a reference type, this method must call
111 * EntityInput.registerPriKeyObject before reading any other fields.</p>
112 *
113 * <p>To read all fields, pass -1 for superLevel, zero for startField and
114 * MAX_FIELD_NUM for endField. Fields from super classes are read
115 * first.</p>
116 *
117 * <p>To read a specific range of fields, pass a non-negative number for
118 * superLevel and the specific indices of the field range to be read in the
119 * class at that level.</p>
120 *
121 * @param o is the object whose secondary key fields are to be read.
122 *
123 * @param input the input data to read from.
124 *
125 * @param startField the starting field index in the range of fields to
126 * read. To read all fields, the startField should be zero.
127 *
128 * @param endField the ending field index in the range of fields to read.
129 * To read all fields, the endField should be MAX_FIELD_NUM.
130 *
131 * @param superLevel is a non-negative number to read the fields of the
132 * class that is the Nth super instance; or a negative number to read
133 * fields in all classes.
134 */
135 void readSecKeyFields(Object o,
136 EntityInput input,
137 int startField,
138 int endField,
139 int superLevel)
140 throws RefreshException;
141
142 /**
143 * Writes all non-key field values to the given EntityOutput, writing
144 * fields in super classes first and in name order within class.
145 *
146 * @param o is the object whose non-key fields are to be written.
147 *
148 * @param output the output data to write to.
149 */
150 void writeNonKeyFields(Object o, EntityOutput output)
151 throws RefreshException;
152
153 /**
154 * Reads a range of non-key field values from the given EntityInput,
155 * reading fields in super classes first and in name order within class.
156 *
157 * <p>To read all fields, pass -1 for superLevel, zero for startField and
158 * MAX_FIELD_NUM for endField. Fields from super classes are read
159 * first.</p>
160 *
161 * <p>To read a specific range of fields, pass a non-negative number for
162 * superLevel and the specific indices of the field range to be read in the
163 * class at that level.</p>
164 *
165 * @param o is the object whose non-key fields are to be read.
166 *
167 * @param input the input data to read from.
168 *
169 * @param startField the starting field index in the range of fields to
170 * read. To read all fields, the startField should be zero.
171 *
172 * @param endField the ending field index in the range of fields to read.
173 * To read all fields, the endField should be MAX_FIELD_NUM.
174 *
175 * @param superLevel is a non-negative number to read the fields of the
176 * class that is the Nth super instance; or a negative number to read
177 * fields in all classes.
178 */
179 void readNonKeyFields(Object o,
180 EntityInput input,
181 int startField,
182 int endField,
183 int superLevel)
184 throws RefreshException;
185
186 /**
187 * Writes all composite key field values to the given EntityOutput, writing
188 * in declared field number order.
189 *
190 * @param o the composite key object whose fields are to be written.
191 *
192 * @param output the output data to write to.
193 */
194 void writeCompositeKeyFields(Object o, EntityOutput output)
195 throws RefreshException;
196
197 /**
198 * Reads all composite key field values from the given EntityInput,
199 * reading in declared field number order.
200 *
201 * @param o the composite key object whose fields are to be read.
202 *
203 * @param input the input data to read from.
204 */
205 void readCompositeKeyFields(Object o, EntityInput input)
206 throws RefreshException;
207
208 /**
209 * Returns the value of a given field, representing primitives as primitive
210 * wrapper objects.
211 *
212 * @param o is the object containing the key field.
213 *
214 * @param field is the field index.
215 *
216 * @param superLevel is a positive number to identify the field of the
217 * class that is the Nth super instance; or zero to identify the field in
218 * this class.
219 *
220 * @param isSecField is true for a secondary key field or false for a
221 * non-key field.
222 *
223 * @return the current field value, or null for a reference type field
224 * that is null.
225 */
226 Object getField(Object o,
227 int field,
228 int superLevel,
229 boolean isSecField);
230
231 /**
232 * Changes the value of a given field, representing primitives as primitive
233 * wrapper objects.
234 *
235 * @param o is the object containing the key field.
236 *
237 * @param field is the field index.
238 *
239 * @param superLevel is a positive number to identify the field of the
240 * class that is the Nth super instance; or zero to identify the field in
241 * this class.
242 *
243 * @param isSecField is true for a secondary key field or false for a
244 * non-key field.
245 *
246 * @param value is the new value of the field, or null to set a reference
247 * type field to null.
248 */
249 void setField(Object o,
250 int field,
251 int superLevel,
252 boolean isSecField,
253 Object value);
254
255 /**
256 * Changes the value of the primary key field, representing primitives as
257 * primitive wrapper objects.
258 *
259 * @param o is the object containing the primary key field.
260 *
261 * @param field is the field index.
262 *
263 * @param superLevel is a positive number to identify the field of the
264 * class that is the Nth super instance; or zero to identify the field in
265 * this class.
266 *
267 * @param value is the new value of the field, or null to set a reference
268 * type field to null.
269 */
270 void setPriField(Object o, Object value);
271 }