Skip to content

Commit caf778f

Browse files
Add type parameters for all EntityInfo<T> usage.
1 parent f1adf61 commit caf778f

File tree

6 files changed

+17
-16
lines changed

6 files changed

+17
-16
lines changed

objectbox-java/src/main/java/io/objectbox/Box.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class Box<T> {
5656

5757
private final IdGetter<T> idGetter;
5858

59-
private EntityInfo entityInfo;
59+
private EntityInfo<T> entityInfo;
6060
private volatile Field boxStoreField;
6161

6262
Box(BoxStore store, Class<T> entityClass) {
@@ -560,7 +560,7 @@ public BoxStore getStore() {
560560
return store;
561561
}
562562

563-
public synchronized EntityInfo getEntityInfo() {
563+
public synchronized EntityInfo<T> getEntityInfo() {
564564
if (entityInfo == null) {
565565
Cursor<T> reader = getReader();
566566
try {

objectbox-java/src/main/java/io/objectbox/BoxStore.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public static boolean isObjectBrowserAvailable() {
166166
private final long handle;
167167
private final Map<Class, String> dbNameByClass = new HashMap<>();
168168
private final Map<Class, Integer> entityTypeIdByClass = new HashMap<>();
169-
private final Map<Class, EntityInfo> propertiesByClass = new HashMap<>();
169+
private final Map<Class<?>, EntityInfo<?>> propertiesByClass = new HashMap<>();
170170
private final LongHashMap<Class> classByEntityTypeId = new LongHashMap<>();
171171
private final int[] allEntityTypeIds;
172172
private final Map<Class, Box> boxes = new ConcurrentHashMap<>();
@@ -213,7 +213,7 @@ public static boolean isObjectBrowserAvailable() {
213213
}
214214
debugRelations = builder.debugRelations;
215215

216-
for (EntityInfo entityInfo : builder.entityInfoList) {
216+
for (EntityInfo<?> entityInfo : builder.entityInfoList) {
217217
try {
218218
dbNameByClass.put(entityInfo.getEntityClass(), entityInfo.getDbName());
219219
int entityId = nativeRegisterEntityClass(handle, entityInfo.getDbName(), entityInfo.getEntityClass());
@@ -368,9 +368,10 @@ Class getEntityClassOrThrow(int entityTypeId) {
368368
return clazz;
369369
}
370370

371+
@SuppressWarnings("unchecked") // Shortcut to implementing a Map<Class<? extends B>, B>.
371372
@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);
374375
}
375376

376377
/**

objectbox-java/src/main/java/io/objectbox/BoxStoreBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public class BoxStoreBuilder {
9292

9393
TxCallback failedReadTxAttemptCallback;
9494

95-
final List<EntityInfo> entityInfoList = new ArrayList<>();
95+
final List<EntityInfo<?>> entityInfoList = new ArrayList<>();
9696
private Factory<InputStream> initialDbFileFactory;
9797

9898
/** Not for application use. */
@@ -274,7 +274,7 @@ public BoxStoreBuilder maxReaders(int maxReaders) {
274274
}
275275

276276
@Internal
277-
public void entity(EntityInfo entityInfo) {
277+
public void entity(EntityInfo<?> entityInfo) {
278278
entityInfoList.add(entityInfo);
279279
}
280280

objectbox-java/src/main/java/io/objectbox/Cursor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@ protected static native long collect004000(long cursor, long keyIfComplete, int
126126

127127
protected final Transaction tx;
128128
protected final long cursor;
129-
protected final EntityInfo entityInfo;
129+
protected final EntityInfo<T> entityInfo;
130130
protected final BoxStore boxStoreForEntities;
131131

132132
protected final boolean readOnly;
133133
protected boolean closed;
134134

135135
private final Throwable creationThrowable;
136136

137-
protected Cursor(Transaction tx, long cursor, EntityInfo entityInfo, BoxStore boxStore) {
137+
protected Cursor(Transaction tx, long cursor, EntityInfo<T> entityInfo, BoxStore boxStore) {
138138
if (tx == null) {
139139
throw new IllegalArgumentException("Transaction is null");
140140
}
@@ -181,7 +181,7 @@ protected void finalize() throws Throwable {
181181

182182
public abstract long put(T entity);
183183

184-
public EntityInfo getEntityInfo() {
184+
public EntityInfo<T> getEntityInfo() {
185185
return entityInfo;
186186
}
187187

@@ -262,7 +262,7 @@ public boolean isClosed() {
262262
* Thus, use it only locally and don't store it long term.
263263
*/
264264
protected <TARGET> Cursor<TARGET> getRelationTargetCursor(Class<TARGET> targetClass) {
265-
EntityInfo entityInfo = boxStoreForEntities.getEntityInfo(targetClass);
265+
EntityInfo<TARGET> entityInfo = boxStoreForEntities.getEntityInfo(targetClass);
266266
long cursorHandle = nativeGetCursorFor(cursor, entityInfo.getEntityId());
267267
CursorFactory<TARGET> factory = entityInfo.getCursorFactory();
268268
return factory.createCursor(tx, cursorHandle, boxStoreForEntities);

objectbox-java/src/main/java/io/objectbox/Transaction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public KeyValueCursor createKeyValueCursor() {
180180

181181
public <T> Cursor<T> createCursor(Class<T> entityClass) {
182182
checkOpen();
183-
EntityInfo entityInfo = store.getEntityInfo(entityClass);
183+
EntityInfo<T> entityInfo = store.getEntityInfo(entityClass);
184184
CursorFactory<T> factory = entityInfo.getCursorFactory();
185185
long cursorHandle = nativeCreateCursor(transaction, entityInfo.getDbName(), entityClass);
186186
return factory.createCursor(this, cursorHandle, store);

objectbox-java/src/main/java/io/objectbox/query/QueryBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,12 @@ public QueryBuilder<T> parameterAlias(String alias) {
325325
*/
326326
public <TARGET> QueryBuilder<TARGET> link(RelationInfo<?, TARGET> relationInfo) {
327327
boolean backlink = relationInfo.isBacklink();
328-
EntityInfo relationOwner = backlink ? relationInfo.targetInfo : relationInfo.sourceInfo;
328+
EntityInfo<?> relationOwner = backlink ? relationInfo.targetInfo : relationInfo.sourceInfo;
329329
return link(relationInfo, relationOwner, relationInfo.targetInfo, backlink);
330330
}
331331

332-
private <TARGET> QueryBuilder<TARGET> link(RelationInfo relationInfo, EntityInfo relationOwner, EntityInfo target,
333-
boolean backlink) {
332+
private <TARGET> QueryBuilder<TARGET> link(RelationInfo<?, ?> relationInfo, EntityInfo<?> relationOwner,
333+
EntityInfo<?> target, boolean backlink) {
334334
int propertyId = relationInfo.targetIdProperty != null ? relationInfo.targetIdProperty.id : 0;
335335
int relationId = relationInfo.targetRelationId != 0 ? relationInfo.targetRelationId : relationInfo.relationId;
336336
long linkQBHandle = nativeLink(handle, storeHandle, relationOwner.getEntityId(), target.getEntityId(),

0 commit comments

Comments
 (0)