@ -49,14 +49,6 @@ public class SQLiteScoreList extends ScoreList
@NonNull
@NonNull
private final SQLiteUtils < ScoreRecord > sqlite ;
private final SQLiteUtils < ScoreRecord > sqlite ;
@NonNull
private final SQLiteStatement invalidateStatement ;
@NonNull
private final SQLiteStatement addStatement ;
private final SQLiteDatabase db ;
@Nullable
@Nullable
private CachedData cache = null ;
private CachedData cache = null ;
@ -69,25 +61,23 @@ public class SQLiteScoreList extends ScoreList
{
{
super ( habit ) ;
super ( habit ) ;
sqlite = new SQLiteUtils < > ( ScoreRecord . class ) ;
sqlite = new SQLiteUtils < > ( ScoreRecord . class ) ;
db = Cache . openDatabase ( ) ;
addStatement = db . compileStatement ( ADD_QUERY ) ;
invalidateStatement = db . compileStatement ( INVALIDATE_QUERY ) ;
}
}
@Override
@Override
public void add ( List < Score > scores )
public void add ( List < Score > scores )
{
{
check ( habit . getId ( ) ) ;
check ( habit . getId ( ) ) ;
SQLiteDatabase db = Cache . openDatabase ( ) ;
SQLiteStatement statement = db . compileStatement ( ADD_QUERY ) ;
db . beginTransaction ( ) ;
db . beginTransaction ( ) ;
try
try
{
{
for ( Score s : scores )
for ( Score s : scores )
{
{
addS tatement. bindLong ( 1 , habit . getId ( ) ) ;
s tatement. bindLong ( 1 , habit . getId ( ) ) ;
addS tatement. bindLong ( 2 , s . getTimestamp ( ) ) ;
s tatement. bindLong ( 2 , s . getTimestamp ( ) ) ;
addS tatement. bindLong ( 3 , s . getValue ( ) ) ;
s tatement. bindLong ( 3 , s . getValue ( ) ) ;
addS tatement. execute ( ) ;
s tatement. execute ( ) ;
}
}
db . setTransactionSuccessful ( ) ;
db . setTransactionSuccessful ( ) ;
@ -150,9 +140,11 @@ public class SQLiteScoreList extends ScoreList
public synchronized void invalidateNewerThan ( long timestamp )
public synchronized void invalidateNewerThan ( long timestamp )
{
{
cache = null ;
cache = null ;
invalidateStatement . bindLong ( 1 , habit . getId ( ) ) ;
SQLiteDatabase db = Cache . openDatabase ( ) ;
invalidateStatement . bindLong ( 2 , timestamp ) ;
SQLiteStatement statement = db . compileStatement ( INVALIDATE_QUERY ) ;
invalidateStatement . execute ( ) ;
statement . bindLong ( 1 , habit . getId ( ) ) ;
statement . bindLong ( 2 , timestamp ) ;
statement . execute ( ) ;
getObservable ( ) . notifyListeners ( ) ;
getObservable ( ) . notifyListeners ( ) ;
}
}