@@ -136,11 +136,11 @@ public static String getVersionNative() {
136
136
137
137
/** @return entity ID */
138
138
// TODO only use ids once we have them in Java
139
- static native int nativeRegisterEntityClass (long store , String entityName , Class entityClass );
139
+ static native int nativeRegisterEntityClass (long store , String entityName , Class <?> entityClass );
140
140
141
141
// TODO only use ids once we have them in Java
142
142
static native void nativeRegisterCustomType (long store , int entityId , int propertyId , String propertyName ,
143
- Class <? extends PropertyConverter > converterClass , Class customType );
143
+ Class <? extends PropertyConverter > converterClass , Class <?> customType );
144
144
145
145
static native String nativeDiagnose (long store );
146
146
@@ -164,12 +164,12 @@ public static boolean isObjectBrowserAvailable() {
164
164
private final File directory ;
165
165
private final String canonicalPath ;
166
166
private final long handle ;
167
- private final Map <Class , String > dbNameByClass = new HashMap <>();
168
- private final Map <Class , Integer > entityTypeIdByClass = new HashMap <>();
169
- private final Map <Class , EntityInfo > propertiesByClass = new HashMap <>();
170
- private final LongHashMap <Class > classByEntityTypeId = new LongHashMap <>();
167
+ private final Map <Class <?> , String > dbNameByClass = new HashMap <>();
168
+ private final Map <Class <?> , Integer > entityTypeIdByClass = new HashMap <>();
169
+ private final Map <Class <?> , EntityInfo <?> > propertiesByClass = new HashMap <>();
170
+ private final LongHashMap <Class <?> > classByEntityTypeId = new LongHashMap <>();
171
171
private final int [] allEntityTypeIds ;
172
- private final Map <Class , Box > boxes = new ConcurrentHashMap <>();
172
+ private final Map <Class <?> , Box <?> > boxes = new ConcurrentHashMap <>();
173
173
private final Set <Transaction > transactions = Collections .newSetFromMap (new WeakHashMap <>());
174
174
private final ExecutorService threadPool = new ObjectBoxThreadPool (this );
175
175
private final ObjectClassPublisher objectClassPublisher ;
@@ -191,7 +191,7 @@ public static boolean isObjectBrowserAvailable() {
191
191
192
192
private final int queryAttempts ;
193
193
194
- private final TxCallback failedReadTxAttemptCallback ;
194
+ private final TxCallback <?> failedReadTxAttemptCallback ;
195
195
196
196
BoxStore (BoxStoreBuilder builder ) {
197
197
context = builder .context ;
@@ -213,14 +213,14 @@ public static boolean isObjectBrowserAvailable() {
213
213
}
214
214
debugRelations = builder .debugRelations ;
215
215
216
- for (EntityInfo entityInfo : builder .entityInfoList ) {
216
+ for (EntityInfo <?> entityInfo : builder .entityInfoList ) {
217
217
try {
218
218
dbNameByClass .put (entityInfo .getEntityClass (), entityInfo .getDbName ());
219
219
int entityId = nativeRegisterEntityClass (handle , entityInfo .getDbName (), entityInfo .getEntityClass ());
220
220
entityTypeIdByClass .put (entityInfo .getEntityClass (), entityId );
221
221
classByEntityTypeId .put (entityId , entityInfo .getEntityClass ());
222
222
propertiesByClass .put (entityInfo .getEntityClass (), entityInfo );
223
- for (Property property : entityInfo .getAllProperties ()) {
223
+ for (Property <?> property : entityInfo .getAllProperties ()) {
224
224
if (property .customType != null ) {
225
225
if (property .converterClass == null ) {
226
226
throw new RuntimeException ("No converter class for custom type of " + property );
@@ -333,24 +333,24 @@ private void checkOpen() {
333
333
}
334
334
}
335
335
336
- String getDbName (Class entityClass ) {
336
+ String getDbName (Class <?> entityClass ) {
337
337
return dbNameByClass .get (entityClass );
338
338
}
339
339
340
- Integer getEntityTypeId (Class entityClass ) {
340
+ Integer getEntityTypeId (Class <?> entityClass ) {
341
341
return entityTypeIdByClass .get (entityClass );
342
342
}
343
343
344
344
@ Internal
345
- public int getEntityTypeIdOrThrow (Class entityClass ) {
345
+ public int getEntityTypeIdOrThrow (Class <?> entityClass ) {
346
346
Integer id = entityTypeIdByClass .get (entityClass );
347
347
if (id == null ) {
348
348
throw new DbSchemaException ("No entity registered for " + entityClass );
349
349
}
350
350
return id ;
351
351
}
352
352
353
- public Collection <Class > getAllEntityClasses () {
353
+ public Collection <Class <?> > getAllEntityClasses () {
354
354
return dbNameByClass .keySet ();
355
355
}
356
356
@@ -360,17 +360,18 @@ int[] getAllEntityTypeIds() {
360
360
}
361
361
362
362
@ Internal
363
- Class getEntityClassOrThrow (int entityTypeId ) {
364
- Class clazz = classByEntityTypeId .get (entityTypeId );
363
+ Class <?> getEntityClassOrThrow (int entityTypeId ) {
364
+ Class <?> clazz = classByEntityTypeId .get (entityTypeId );
365
365
if (clazz == null ) {
366
366
throw new DbSchemaException ("No entity registered for type ID " + entityTypeId );
367
367
}
368
368
return clazz ;
369
369
}
370
370
371
+ @ SuppressWarnings ("unchecked" ) // Casting is easier than writing a custom Map.
371
372
@ Internal
372
- EntityInfo getEntityInfo (Class entityClass ) {
373
- return propertiesByClass .get (entityClass );
373
+ < T > EntityInfo < T > getEntityInfo (Class < T > entityClass ) {
374
+ return ( EntityInfo < T >) propertiesByClass .get (entityClass );
374
375
}
375
376
376
377
/**
@@ -608,7 +609,7 @@ void txCommitted(Transaction tx, @Nullable int[] entityTypeIdsAffected) {
608
609
}
609
610
}
610
611
611
- for (Box box : boxes .values ()) {
612
+ for (Box <?> box : boxes .values ()) {
612
613
box .txCommitted (tx );
613
614
}
614
615
@@ -622,17 +623,17 @@ void txCommitted(Transaction tx, @Nullable int[] entityTypeIdsAffected) {
622
623
* <p>
623
624
* Creates a Box only once and then always returns the cached instance.
624
625
*/
625
- @ SuppressWarnings ("unchecked" )
626
+ @ SuppressWarnings ("unchecked" ) // Casting is easier than writing a custom Map.
626
627
public <T > Box <T > boxFor (Class <T > entityClass ) {
627
- Box box = boxes .get (entityClass );
628
+ Box < T > box = ( Box < T >) boxes .get (entityClass );
628
629
if (box == null ) {
629
630
if (!dbNameByClass .containsKey (entityClass )) {
630
631
throw new IllegalArgumentException (entityClass +
631
632
" is not a known entity. Please add it and trigger generation again." );
632
633
}
633
634
// Ensure a box is created just once
634
635
synchronized (boxes ) {
635
- box = boxes .get (entityClass );
636
+ box = ( Box < T >) boxes .get (entityClass );
636
637
if (box == null ) {
637
638
box = new Box <>(this , entityClass );
638
639
boxes .put (entityClass , box );
@@ -688,7 +689,7 @@ public void runInReadTx(Runnable runnable) {
688
689
689
690
// TODO That's rather a quick fix, replace with a more general solution
690
691
// (that could maybe be a TX listener with abort callback?)
691
- for (Box box : boxes .values ()) {
692
+ for (Box <?> box : boxes .values ()) {
692
693
box .readTxFinished (tx );
693
694
}
694
695
@@ -732,7 +733,6 @@ public <T> T callInReadTxWithRetry(Callable<T> callable, int attempts, int initi
732
733
cleanStaleReadTransactions ();
733
734
}
734
735
if (failedReadTxAttemptCallback != null ) {
735
- //noinspection unchecked
736
736
failedReadTxAttemptCallback .txFinished (null , new DbException (message + " \n " + diagnose , e ));
737
737
}
738
738
try {
@@ -772,7 +772,7 @@ public <T> T callInReadTx(Callable<T> callable) {
772
772
773
773
// TODO That's rather a quick fix, replace with a more general solution
774
774
// (that could maybe be a TX listener with abort callback?)
775
- for (Box box : boxes .values ()) {
775
+ for (Box <?> box : boxes .values ()) {
776
776
box .readTxFinished (tx );
777
777
}
778
778
@@ -885,7 +885,7 @@ public int cleanStaleReadTransactions() {
885
885
* {@link Box#closeThreadResources()} for all initiated boxes ({@link #boxFor(Class)}).
886
886
*/
887
887
public void closeThreadResources () {
888
- for (Box box : boxes .values ()) {
888
+ for (Box <?> box : boxes .values ()) {
889
889
box .closeThreadResources ();
890
890
}
891
891
// activeTx is cleaned up in finally blocks, so do not free them here
@@ -972,7 +972,7 @@ public <T> SubscriptionBuilder<Class<T>> subscribe(Class<T> forClass) {
972
972
}
973
973
974
974
@ Internal
975
- public Future internalScheduleThread (Runnable runnable ) {
975
+ public Future <?> internalScheduleThread (Runnable runnable ) {
976
976
return threadPool .submit (runnable );
977
977
}
978
978
@@ -992,7 +992,7 @@ public int internalQueryAttempts() {
992
992
}
993
993
994
994
@ Internal
995
- public TxCallback internalFailedReadTxAttemptCallback () {
995
+ public TxCallback <?> internalFailedReadTxAttemptCallback () {
996
996
return failedReadTxAttemptCallback ;
997
997
}
998
998
0 commit comments