1
1
package com .aerospike .mapper .tools ;
2
2
3
- import java .lang .annotation .Annotation ;
4
- import java .lang .reflect .Constructor ;
5
- import java .lang .reflect .Field ;
6
- import java .lang .reflect .Method ;
7
- import java .lang .reflect .Modifier ;
8
- import java .lang .reflect .Parameter ;
9
- import java .util .ArrayList ;
10
- import java .util .Arrays ;
11
- import java .util .HashMap ;
12
- import java .util .HashSet ;
13
- import java .util .List ;
14
- import java .util .Map ;
15
- import java .util .Set ;
16
- import java .util .TreeMap ;
17
-
18
- import javax .validation .constraints .NotNull ;
19
-
20
- import org .apache .commons .lang3 .StringUtils ;
21
-
22
3
import com .aerospike .client .AerospikeException ;
23
4
import com .aerospike .client .Bin ;
24
5
import com .aerospike .client .Key ;
30
11
import com .aerospike .client .policy .QueryPolicy ;
31
12
import com .aerospike .client .policy .ScanPolicy ;
32
13
import com .aerospike .client .policy .WritePolicy ;
33
- import com .aerospike .mapper .annotations .AerospikeBin ;
34
- import com .aerospike .mapper .annotations .AerospikeConstructor ;
35
- import com .aerospike .mapper .annotations .AerospikeExclude ;
36
- import com .aerospike .mapper .annotations .AerospikeGetter ;
37
- import com .aerospike .mapper .annotations .AerospikeKey ;
38
- import com .aerospike .mapper .annotations .AerospikeOrdinal ;
39
- import com .aerospike .mapper .annotations .AerospikeRecord ;
40
- import com .aerospike .mapper .annotations .AerospikeSetter ;
41
- import com .aerospike .mapper .annotations .ParamFrom ;
14
+ import com .aerospike .mapper .annotations .*;
42
15
import com .aerospike .mapper .exceptions .NotAnnotatedClass ;
43
16
import com .aerospike .mapper .tools .configuration .BinConfig ;
44
17
import com .aerospike .mapper .tools .configuration .ClassConfig ;
45
18
import com .aerospike .mapper .tools .configuration .KeyConfig ;
46
19
import com .aerospike .mapper .tools .utils .ParserUtils ;
47
20
import com .aerospike .mapper .tools .utils .TypeUtils ;
48
21
import com .aerospike .mapper .tools .utils .TypeUtils .AnnotatedType ;
22
+ import org .apache .commons .lang3 .StringUtils ;
23
+
24
+ import javax .validation .constraints .NotNull ;
25
+ import java .lang .annotation .Annotation ;
26
+ import java .lang .reflect .Constructor ;
27
+ import java .lang .reflect .Field ;
28
+ import java .lang .reflect .Method ;
29
+ import java .lang .reflect .Modifier ;
30
+ import java .lang .reflect .Parameter ;
31
+ import java .util .*;
49
32
50
33
public class ClassCacheEntry <T > {
51
34
@@ -104,7 +87,7 @@ private enum FactoryMethodType {
104
87
private volatile boolean constructed ;
105
88
106
89
// package visibility only.
107
- ClassCacheEntry (@ NotNull Class <T > clazz , IBaseAeroMapper mapper , ClassConfig config ,
90
+ ClassCacheEntry (@ NotNull Class <T > clazz , IBaseAeroMapper mapper , ClassConfig config , boolean requireRecord ,
108
91
@ NotNull Policy readPolicy , @ NotNull WritePolicy writePolicy ,
109
92
@ NotNull BatchPolicy batchPolicy , @ NotNull QueryPolicy queryPolicy ,
110
93
@ NotNull ScanPolicy scanPolicy ) {
@@ -118,8 +101,9 @@ private enum FactoryMethodType {
118
101
this .queryPolicy = queryPolicy ;
119
102
120
103
AerospikeRecord recordDescription = clazz .getAnnotation (AerospikeRecord .class );
121
- if (recordDescription == null && config == null ) {
122
- throw new NotAnnotatedClass ("Class " + clazz .getName () + " is not augmented by the @AerospikeRecord annotation" );
104
+ if (requireRecord && recordDescription == null && config == null ) {
105
+ throw new NotAnnotatedClass (String .format ("Class %s is not augmented by the @AerospikeRecord annotation" ,
106
+ clazz .getName ()));
123
107
} else if (recordDescription != null ) {
124
108
this .namespace = ParserUtils .getInstance ().get (recordDescription .namespace ());
125
109
this .setName = ParserUtils .getInstance ().get (recordDescription .set ());
@@ -143,10 +127,11 @@ public ClassCacheEntry<T> construct() {
143
127
144
128
this .loadFieldsFromClass ();
145
129
this .loadPropertiesFromClass ();
146
- this .superClazz = ClassCache .getInstance ().loadClass (this .clazz .getSuperclass (), this .mapper );
130
+ this .superClazz = ClassCache .getInstance ().loadClass (this .clazz .getSuperclass (), this .mapper , ! this . mapAll );
147
131
this .binCount = this .values .size () + (superClazz != null ? superClazz .binCount : 0 );
148
132
if (this .binCount == 0 ) {
149
- throw new AerospikeException ("Class " + clazz .getSimpleName () + " has no values defined to be stored in the database" );
133
+ throw new AerospikeException (String .format ("Class %s has no values defined to be stored in the database" ,
134
+ clazz .getSimpleName ()));
150
135
}
151
136
this .formOrdinalsFromValues ();
152
137
Method factoryConstructorMethod = findConstructorFactoryMethod ();
@@ -240,7 +225,7 @@ public boolean isChildClass() {
240
225
241
226
private void checkRecordSettingsAgainstSuperClasses () {
242
227
if (!StringUtils .isBlank (this .namespace ) && !StringUtils .isBlank (this .setName )) {
243
- // This class defines it's own namespace + set, it is only a child class if it's closest named superclass is the same as ours.
228
+ // This class defines its own namespace + set, it is only a child class if its closest named superclass is the same as ours.
244
229
this .isChildClass = false ;
245
230
ClassCacheEntry <?> thisEntry = this .superClazz ;
246
231
while (thisEntry != null ) {
0 commit comments