Cache cursor constructor

pull/189/head
Alex Baker 12 years ago
parent 2faf52f3b4
commit 4ce3a66071

@ -32,6 +32,7 @@ public class DatabaseDao<TYPE extends AbstractModel> {
private static final Logger log = LoggerFactory.getLogger(DatabaseDao.class); private static final Logger log = LoggerFactory.getLogger(DatabaseDao.class);
private final Class<TYPE> modelClass; private final Class<TYPE> modelClass;
private final Constructor<TYPE> cursorConstructor;
private Table table; private Table table;
@ -39,6 +40,11 @@ public class DatabaseDao<TYPE extends AbstractModel> {
public DatabaseDao(Class<TYPE> modelClass) { public DatabaseDao(Class<TYPE> modelClass) {
this.modelClass = modelClass; this.modelClass = modelClass;
try {
this.cursorConstructor = modelClass.getConstructor(TodorooCursor.class);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
} }
/** Gets table associated with this DAO */ /** Gets table associated with this DAO */
@ -107,9 +113,8 @@ public class DatabaseDao<TYPE extends AbstractModel> {
if (cursor.getCount() == 0) { if (cursor.getCount() == 0) {
return null; return null;
} }
Constructor<TYPE> constructor = modelClass.getConstructor(TodorooCursor.class); return cursorConstructor.newInstance(cursor);
return constructor.newInstance(cursor); } catch (InvocationTargetException | InstantiationException | IllegalAccessException e) {
} catch (SecurityException | InvocationTargetException | IllegalAccessException | InstantiationException | IllegalArgumentException | NoSuchMethodException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally { } finally {
cursor.close(); cursor.close();

Loading…
Cancel
Save