Created
December 31, 2014 21:39
-
-
Save tylertreat/3b2ecff2895ac64ae348 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public <T> T createFromCursor(Cursor cursor, Class<T> modelClass) throws ModelConfigurationException, InfinitumRuntimeException { | |
return createFromCursorRec(cursor, modelClass); | |
} | |
@SuppressWarnings("unchecked") | |
private <T> T createFromCursorRec(Cursor cursor, Class<T> modelClass) throws ModelConfigurationException, InfinitumRuntimeException { | |
SqliteResult result = new SqliteResult(cursor); | |
T ret = (T) mClassReflector.getClassInstance(modelClass); | |
List<Field> fields = mPersistencePolicy.getPersistentFields(modelClass); | |
for (Field field : fields) { | |
if (!mPersistencePolicy.isRelationship(field)) { | |
SqliteTypeAdapter<?> resolver = mMapper.resolveType(field.getType()); | |
int index = result.getColumnIndex(mPersistencePolicy.getFieldColumnName(field)); | |
try { | |
resolver.mapToObject(result, index, field, ret); | |
} catch (IllegalArgumentException e) { | |
throw new InfinitumRuntimeException("Could not map '" + field.getType().getName() + "'"); | |
} catch (IllegalAccessException e) { | |
throw new InfinitumRuntimeException("Could not map '" + field.getType().getName() + "'"); | |
} | |
} | |
} | |
int objHash = mPersistencePolicy.computeModelHash(ret); | |
if (mSession.checkCache(objHash)) | |
return (T) mSession.searchCache(objHash); | |
mSession.cache(objHash, ret); | |
loadRelationships(ret); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment