| 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 |
* Interface implemented by a persistent class via bytecode enhancement. |
| 12 |
* |
| 13 |
* <p>See {@link Accessor} for method documentation. {@link EnhancedAccessor} |
| 14 |
* implements Accessor and forwards all calls to methods in the Enhanced |
| 15 |
* class.</p> |
| 16 |
* |
| 17 |
* <p>Each class that implements this interface (including its subclasses and |
| 18 |
* superclasses except for Object) must also implement a static block that |
| 19 |
* registers a prototype instance by calling |
| 20 |
* EnhancedAccessor.registerPrototype. Other instances are created from the |
| 21 |
* protype instance using {@link #bdbNewInstance}.</p> |
| 22 |
* |
| 23 |
* <pre>static { EnhancedAccessor.registerPrototype(new Xxx()); }</pre> |
| 24 |
* |
| 25 |
* <p>An example of the generated code for reading and writing fields is shown |
| 26 |
* below.</p> |
| 27 |
* |
| 28 |
* <pre> |
| 29 |
* private int f1; |
| 30 |
* private String f2; |
| 31 |
* private MyClass f3; |
| 32 |
* |
| 33 |
* public void bdbWriteNonKeyFields(EntityOutput output) { |
| 34 |
* |
| 35 |
* super.bdbWriteNonKeyFields(output); |
| 36 |
* |
| 37 |
* output.writeInt(f1); |
| 38 |
* output.writeObject(f2, null); |
| 39 |
* output.writeObject(f3, null); |
| 40 |
* } |
| 41 |
* |
| 42 |
* public void bdbReadNonKeyFields(EntityInput input, |
| 43 |
* int startField, |
| 44 |
* int endField, |
| 45 |
* int superLevel) { |
| 46 |
* |
| 47 |
* if (superLevel != 0) { |
| 48 |
* super.bdbReadNonKeyFields(input, startField, endField, |
| 49 |
* superLevel - 1); |
| 50 |
* } |
| 51 |
* if (superLevel <= 0) { |
| 52 |
* switch (startField) { |
| 53 |
* case 0: |
| 54 |
* f1 = input.readInt(); |
| 55 |
* if (endField == 0) break; |
| 56 |
* case 1: |
| 57 |
* f2 = (String) input.readObject(); |
| 58 |
* if (endField == 1) break; |
| 59 |
* case 2: |
| 60 |
* f3 = (MyClass) input.readObject(); |
| 61 |
* } |
| 62 |
* } |
| 63 |
* } |
| 64 |
* </pre> |
| 65 |
* |
| 66 |
* @author Mark Hayes |
| 67 |
*/ |
| 68 |
public interface Enhanced { |
| 69 |
|
| 70 |
/** |
| 71 |
* @see Accessor#newInstance |
| 72 |
*/ |
| 73 |
Object bdbNewInstance(); |
| 74 |
|
| 75 |
/** |
| 76 |
* @see Accessor#newArray |
| 77 |
*/ |
| 78 |
Object bdbNewArray(int len); |
| 79 |
|
| 80 |
/** |
| 81 |
* Calls the super class method if this class does not contain the primary |
| 82 |
* key field. |
| 83 |
* |
| 84 |
* @see Accessor#isPriKeyFieldNullOrZero |
| 85 |
*/ |
| 86 |
boolean bdbIsPriKeyFieldNullOrZero(); |
| 87 |
|
| 88 |
/** |
| 89 |
* Calls the super class method if this class does not contain the primary |
| 90 |
* key field. |
| 91 |
* |
| 92 |
* @see Accessor#writePriKeyField |
| 93 |
*/ |
| 94 |
void bdbWritePriKeyField(EntityOutput output, Format format) |
| 95 |
throws RefreshException; |
| 96 |
|
| 97 |
/** |
| 98 |
* Calls the super class method if this class does not contain the primary |
| 99 |
* key field. |
| 100 |
* |
| 101 |
* @see Accessor#readPriKeyField |
| 102 |
*/ |
| 103 |
void bdbReadPriKeyField(EntityInput input, Format format) |
| 104 |
throws RefreshException; |
| 105 |
|
| 106 |
/** |
| 107 |
* @see Accessor#writeSecKeyFields |
| 108 |
*/ |
| 109 |
void bdbWriteSecKeyFields(EntityOutput output) |
| 110 |
throws RefreshException; |
| 111 |
|
| 112 |
/** |
| 113 |
* @see Accessor#readSecKeyFields |
| 114 |
*/ |
| 115 |
void bdbReadSecKeyFields(EntityInput input, |
| 116 |
int startField, |
| 117 |
int endField, |
| 118 |
int superLevel) |
| 119 |
throws RefreshException; |
| 120 |
|
| 121 |
/** |
| 122 |
* @see Accessor#writeNonKeyFields |
| 123 |
*/ |
| 124 |
void bdbWriteNonKeyFields(EntityOutput output) |
| 125 |
throws RefreshException; |
| 126 |
|
| 127 |
/** |
| 128 |
* @see Accessor#readNonKeyFields |
| 129 |
*/ |
| 130 |
void bdbReadNonKeyFields(EntityInput input, |
| 131 |
int startField, |
| 132 |
int endField, |
| 133 |
int superLevel) |
| 134 |
throws RefreshException; |
| 135 |
|
| 136 |
/** |
| 137 |
* @see Accessor#writeCompositeKeyFields |
| 138 |
*/ |
| 139 |
void bdbWriteCompositeKeyFields(EntityOutput output, Format[] formats) |
| 140 |
throws RefreshException; |
| 141 |
|
| 142 |
/** |
| 143 |
* @see Accessor#readCompositeKeyFields |
| 144 |
*/ |
| 145 |
void bdbReadCompositeKeyFields(EntityInput input, Format[] formats) |
| 146 |
throws RefreshException; |
| 147 |
|
| 148 |
/** |
| 149 |
* @see Accessor#getField |
| 150 |
*/ |
| 151 |
Object bdbGetField(Object o, |
| 152 |
int field, |
| 153 |
int superLevel, |
| 154 |
boolean isSecField); |
| 155 |
|
| 156 |
/** |
| 157 |
* @see Accessor#setField |
| 158 |
*/ |
| 159 |
void bdbSetField(Object o, |
| 160 |
int field, |
| 161 |
int superLevel, |
| 162 |
boolean isSecField, |
| 163 |
Object value); |
| 164 |
|
| 165 |
/** |
| 166 |
* @see Accessor#setPriField |
| 167 |
*/ |
| 168 |
void bdbSetPriField(Object o, Object value); |
| 169 |
} |