Skip to content

Commit

Permalink
Fixed remaining annotated id issue
Browse files Browse the repository at this point in the history
Closes #254
References #185
References #215
References #243

Thanks @jivimberg for the pull request!
  • Loading branch information
whoshuu committed Apr 7, 2015
1 parent 0fdc4dd commit 1f49d7c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions library/src/main/java/com/orm/SugarRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static <T> List<T> findWithQuery(Class<T> type, String query, String... a
try {
while (c.moveToNext()) {
entity = type.getDeclaredConstructor().newInstance();
SugarRecord.inflate(c, entity);
SugarRecord.inflate(c, entity, getSugarContext().getEntitiesMap());
toRet.add(entity);
}
} catch (Exception e) {
Expand All @@ -191,7 +191,7 @@ public static <T> List<T> find(Class<T> type, String whereClause, String[] where
try {
while (c.moveToNext()) {
entity = type.getDeclaredConstructor().newInstance();
SugarRecord.inflate(c, entity);
SugarRecord.inflate(c, entity, getSugarContext().getEntitiesMap());
toRet.add(entity);
}
} catch (Exception e) {
Expand Down Expand Up @@ -287,8 +287,11 @@ public static boolean isSugarEntity(Class<?> objectClass) {
return objectClass.isAnnotationPresent(Table.class) || SugarRecord.class.isAssignableFrom(objectClass);
}

private static void inflate(Cursor cursor, Object object) {
private static void inflate(Cursor cursor, Object object, Map<Object, Long> entitiesMap) {
List<Field> columns = ReflectionUtil.getTableFields(object.getClass());
if (!entitiesMap.containsKey(object)) {
entitiesMap.put(object, cursor.getLong(cursor.getColumnIndex(("ID"))));
}

for (Field field : columns) {
field.setAccessible(true);
Expand Down Expand Up @@ -355,7 +358,7 @@ public long save() {

@SuppressWarnings("unchecked")
void inflate(Cursor cursor) {
inflate(cursor, this);
inflate(cursor, this, getSugarContext().getEntitiesMap());
}

public Long getId() {
Expand Down Expand Up @@ -393,7 +396,7 @@ public E next() {

try {
entity = type.getDeclaredConstructor().newInstance();
SugarRecord.inflate(cursor, entity);
SugarRecord.inflate(cursor, entity, getSugarContext().getEntitiesMap());
} catch (Exception e) {
e.printStackTrace();
} finally {
Expand Down

0 comments on commit 1f49d7c

Please sign in to comment.