1
0
mirror of https://github.com/bspeice/itcs4180 synced 2025-08-02 13:35:25 -04:00

Refactor existing API to use the new DatabaseHelper

This commit is contained in:
Bradlee Speice
2014-04-15 21:42:40 -04:00
parent d701c2bcb2
commit 385d53a23a
4 changed files with 14 additions and 42 deletions

View File

@ -1,33 +0,0 @@
package edu.uncc.scavenger.database;
import java.util.List;
import edu.uncc.scavenger.rest.RestLocation;
public class LocationDatabaseClient {
/*
* Super high-level API for working with locations.
* Also helpful for just drawing out skeletons of code.
*/
public List<RestLocation> getAllLocations() {
// TODO: Implement method to get all locations that exist in the database
return null;
}
public void persistLocation(RestLocation location) {
// TODO: Save a location to the database
}
public void persistLocation(List<RestLocation> locations) {
for (RestLocation l: locations) {
persistLocation(l);
}
}
public void synchronizeLocations(List<RestLocation> locations) {
// TODO: Implement method to save all values in locations, and remove values that aren't there.
}
}

View File

@ -3,6 +3,7 @@ package edu.uncc.scavenger.database;
// Design pattern from: http://www.androiddesignpatterns.com/2012/05/correctly-managing-your-sqlite-database.html
import java.util.ArrayList;
import java.util.List;
import edu.uncc.scavenger.rest.RestLocation;
import android.content.ContentValues;
@ -32,7 +33,7 @@ public class LocationDatabaseHelper extends SQLiteOpenHelper {
super(ctx, DATABASE_NAME, null, DATABASE_VERSION);
}
public LocationDatabaseHelper getInstance(Context ctx) {
public static LocationDatabaseHelper getInstance(Context ctx) {
if (helper == null) {
helper = new LocationDatabaseHelper(ctx.getApplicationContext());
}
@ -104,5 +105,9 @@ public class LocationDatabaseHelper extends SQLiteOpenHelper {
helper.getWritableDatabase().insert(TABLE_NAME, null, values);
}
public void persistAll(List<RestLocation> locs) {
for (RestLocation l : locs) {
persist(l);
}
}
}