aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/DataStore.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/DataStore.java')
-rw-r--r--main/src/cgeo/geocaching/DataStore.java148
1 files changed, 56 insertions, 92 deletions
diff --git a/main/src/cgeo/geocaching/DataStore.java b/main/src/cgeo/geocaching/DataStore.java
index e404b22..e4c5739 100644
--- a/main/src/cgeo/geocaching/DataStore.java
+++ b/main/src/cgeo/geocaching/DataStore.java
@@ -58,6 +58,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
+import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
@@ -111,35 +112,32 @@ public class DataStore {
"cg_caches.direction," + // 16
"cg_caches.distance," + // 17
"cg_caches.terrain," + // 18
- "cg_caches.latlon," + // 19
- "cg_caches.location," + // 20
- "cg_caches.personal_note," + // 21
- "cg_caches.shortdesc," + // 22
- "cg_caches.favourite_cnt," + // 23
- "cg_caches.rating," + // 24
- "cg_caches.votes," + // 25
- "cg_caches.myvote," + // 26
- "cg_caches.disabled," + // 27
- "cg_caches.archived," + // 28
- "cg_caches.members," + // 29
- "cg_caches.found," + // 30
- "cg_caches.favourite," + // 31
- "cg_caches.inventoryunknown," + // 32
- "cg_caches.onWatchlist," + // 33
- "cg_caches.reliable_latlon," + // 34
- "cg_caches.coordsChanged," + // 35
- "cg_caches.latitude," + // 36
- "cg_caches.longitude," + // 37
- "cg_caches.finalDefined," + // 38
- "cg_caches._id," + // 39
- "cg_caches.inventorycoins," + // 40
- "cg_caches.inventorytags," + // 41
- "cg_caches.logPasswordRequired"; // 42
-
- //TODO: remove "latlon" field from cache table
+ "cg_caches.location," + // 19
+ "cg_caches.personal_note," + // 20
+ "cg_caches.shortdesc," + // 21
+ "cg_caches.favourite_cnt," + // 22
+ "cg_caches.rating," + // 23
+ "cg_caches.votes," + // 24
+ "cg_caches.myvote," + // 25
+ "cg_caches.disabled," + // 26
+ "cg_caches.archived," + // 27
+ "cg_caches.members," + // 28
+ "cg_caches.found," + // 29
+ "cg_caches.favourite," + // 30
+ "cg_caches.inventoryunknown," + // 31
+ "cg_caches.onWatchlist," + // 32
+ "cg_caches.reliable_latlon," + // 33
+ "cg_caches.coordsChanged," + // 34
+ "cg_caches.latitude," + // 35
+ "cg_caches.longitude," + // 36
+ "cg_caches.finalDefined," + // 37
+ "cg_caches._id," + // 38
+ "cg_caches.inventorycoins," + // 39
+ "cg_caches.inventorytags," + // 40
+ "cg_caches.logPasswordRequired"; // 41
/** The list of fields needed for mapping. */
- private static final String[] WAYPOINT_COLUMNS = new String[] { "_id", "geocode", "updated", "type", "prefix", "lookup", "name", "latlon", "latitude", "longitude", "note", "own", "visited" };
+ private static final String[] WAYPOINT_COLUMNS = new String[] { "_id", "geocode", "updated", "type", "prefix", "lookup", "name", "latitude", "longitude", "note", "own", "visited" };
/** Number of days (as ms) after temporarily saved caches are deleted */
private final static long DAYS_AFTER_CACHE_IS_DELETED = 3 * 24 * 60 * 60 * 1000;
@@ -183,7 +181,6 @@ public class DataStore {
+ "size text, "
+ "difficulty float, "
+ "terrain float, "
- + "latlon text, "
+ "location text, "
+ "direction double, "
+ "distance double, "
@@ -214,9 +211,7 @@ public class DataStore {
+ "create table " + dbTableLists + " ("
+ "_id integer primary key autoincrement, "
+ "title text not null, "
- + "updated long not null, "
- + "latitude double, "
- + "longitude double "
+ + "updated long not null"
+ "); ";
private static final String dbCreateAttributes = ""
+ "create table " + dbTableAttributes + " ("
@@ -235,7 +230,6 @@ public class DataStore {
+ "prefix text, "
+ "lookup text, "
+ "name text, "
- + "latlon text, "
+ "latitude double, "
+ "longitude double, "
+ "note text, "
@@ -638,7 +632,6 @@ public class DataStore {
+ "size text, "
+ "difficulty float, "
+ "terrain float, "
- + "latlon text, "
+ "location text, "
+ "direction double, "
+ "distance double, "
@@ -665,7 +658,7 @@ public class DataStore {
db.execSQL(dbCreateCachesTemp);
db.execSQL("insert into " + dbTableCachesTemp + " select _id,updated,detailed,detailedupdate,visiteddate,geocode,reason,cacheid,guid,type,name,own,owner,owner_real," +
- "hidden,hint,size,difficulty,terrain,latlon,location,direction,distance,latitude,longitude, 0," +
+ "hidden,hint,size,difficulty,terrain,location,direction,distance,latitude,longitude, 0," +
"personal_note,shortdesc,description,favourite_cnt,rating,votes,myvote,disabled,archived,members,found,favourite,inventorycoins," +
"inventorytags,inventoryunknown,onWatchlist from " + dbTableCaches);
db.execSQL("drop table " + dbTableCaches);
@@ -681,13 +674,12 @@ public class DataStore {
+ "prefix text, "
+ "lookup text, "
+ "name text, "
- + "latlon text, "
+ "latitude double, "
+ "longitude double, "
+ "note text "
+ "); ";
db.execSQL(dbCreateWaypointsTemp);
- db.execSQL("insert into " + dbTableWaypointsTemp + " select _id, geocode, updated, type, prefix, lookup, name, latlon, latitude, longitude, note from " + dbTableWaypoints);
+ db.execSQL("insert into " + dbTableWaypointsTemp + " select _id, geocode, updated, type, prefix, lookup, name, latitude, longitude, note from " + dbTableWaypoints);
db.execSQL("drop table " + dbTableWaypoints);
db.execSQL("alter table " + dbTableWaypointsTemp + " rename to " + dbTableWaypoints);
@@ -1009,9 +1001,9 @@ public class DataStore {
}
synchronized (listId) {
listId.bindString(1, value);
- return listId.simpleQueryForLong() != StoredList.TEMPORARY_LIST_ID;
+ return listId.simpleQueryForLong() != StoredList.TEMPORARY_LIST.id;
}
- } catch (final SQLiteDoneException e) {
+ } catch (final SQLiteDoneException ignored) {
// Do nothing, it only means we have no information on the cache
} catch (final Exception e) {
Log.e("DataStore.isOffline", e);
@@ -1032,7 +1024,7 @@ public class DataStore {
description.bindString(1, guid);
return description.simpleQueryForString();
}
- } catch (final SQLiteDoneException e) {
+ } catch (final SQLiteDoneException ignored) {
// Do nothing, it only means we have no information on the cache
} catch (final Exception e) {
Log.e("DataStore.getGeocodeForGuid", e);
@@ -1041,27 +1033,6 @@ public class DataStore {
return null;
}
- public static String getCacheidForGeocode(final String geocode) {
- if (StringUtils.isBlank(geocode)) {
- return null;
- }
- init();
-
- try {
- final SQLiteStatement description = PreparedStatements.getCacheIdOfGeocode();
- synchronized (description) {
- description.bindString(1, geocode);
- return description.simpleQueryForString();
- }
- } catch (final SQLiteDoneException e) {
- // Do nothing, it only means we have no information on the cache
- } catch (final Exception e) {
- Log.e("DataStore.getCacheidForGeocode", e);
- }
-
- return null;
- }
-
/**
* Save/store a cache to the CacheCache
*
@@ -1070,7 +1041,7 @@ public class DataStore {
* @param saveFlags
*
*/
- public static void saveCache(final Geocache cache, final EnumSet<LoadFlags.SaveFlag> saveFlags) {
+ public static void saveCache(final Geocache cache, final Set<LoadFlags.SaveFlag> saveFlags) {
saveCaches(Collections.singletonList(cache), saveFlags);
}
@@ -1082,7 +1053,7 @@ public class DataStore {
* @param saveFlags
*
*/
- public static void saveCaches(final Collection<Geocache> caches, final EnumSet<LoadFlags.SaveFlag> saveFlags) {
+ public static void saveCaches(final Collection<Geocache> caches, final Set<LoadFlags.SaveFlag> saveFlags) {
if (CollectionUtils.isEmpty(caches)) {
return;
}
@@ -1294,7 +1265,6 @@ public class DataStore {
values.put("prefix", oneWaypoint.getPrefix());
values.put("lookup", oneWaypoint.getLookup());
values.put("name", oneWaypoint.getName());
- values.put("latlon", oneWaypoint.getLatlon());
putCoords(values, oneWaypoint.getCoords());
values.put("note", oneWaypoint.getNote());
values.put("own", oneWaypoint.isUserDefined() ? 1 : 0);
@@ -1373,7 +1343,6 @@ public class DataStore {
values.put("prefix", waypoint.getPrefix());
values.put("lookup", waypoint.getLookup());
values.put("name", waypoint.getName());
- values.put("latlon", waypoint.getLatlon());
putCoords(values, waypoint.getCoords());
values.put("note", waypoint.getNote());
values.put("own", waypoint.isUserDefined() ? 1 : 0);
@@ -1562,7 +1531,7 @@ public class DataStore {
return new HashSet<>();
}
- final Set<Geocache> result = new HashSet<>();
+ final Set<Geocache> result = new HashSet<>(geocodes.size());
final Set<String> remaining = new HashSet<>(geocodes);
if (loadFlags.contains(LoadFlag.CACHE_BEFORE)) {
@@ -1640,7 +1609,7 @@ public class DataStore {
int logIndex = -1;
while (cursor.moveToNext()) {
- final Geocache cache = DataStore.createCacheFromDatabaseContent(cursor);
+ final Geocache cache = createCacheFromDatabaseContent(cursor);
if (loadFlags.contains(LoadFlag.ATTRIBUTES)) {
cache.setAttributes(loadAttributes(cache.getGeocode()));
@@ -1750,25 +1719,25 @@ public class DataStore {
}
cache.setTerrain(cursor.getFloat(18));
// do not set cache.location
- cache.setCoords(getCoords(cursor, 36, 37));
- cache.setPersonalNote(cursor.getString(21));
+ cache.setPersonalNote(cursor.getString(20));
// do not set cache.shortdesc
// do not set cache.description
- cache.setFavoritePoints(cursor.getInt(23));
- cache.setRating(cursor.getFloat(24));
- cache.setVotes(cursor.getInt(25));
- cache.setMyVote(cursor.getFloat(26));
- cache.setDisabled(cursor.getInt(27) == 1);
- cache.setArchived(cursor.getInt(28) == 1);
- cache.setPremiumMembersOnly(cursor.getInt(29) == 1);
- cache.setFound(cursor.getInt(30) == 1);
- cache.setFavorite(cursor.getInt(31) == 1);
- cache.setInventoryItems(cursor.getInt(32));
- cache.setOnWatchlist(cursor.getInt(33) == 1);
- cache.setReliableLatLon(cursor.getInt(34) > 0);
- cache.setUserModifiedCoords(cursor.getInt(35) > 0);
- cache.setFinalDefined(cursor.getInt(38) > 0);
- cache.setLogPasswordRequired(cursor.getInt(42) > 0);
+ cache.setFavoritePoints(cursor.getInt(22));
+ cache.setRating(cursor.getFloat(23));
+ cache.setVotes(cursor.getInt(24));
+ cache.setMyVote(cursor.getFloat(25));
+ cache.setDisabled(cursor.getInt(26) == 1);
+ cache.setArchived(cursor.getInt(27) == 1);
+ cache.setPremiumMembersOnly(cursor.getInt(28) == 1);
+ cache.setFound(cursor.getInt(29) == 1);
+ cache.setFavorite(cursor.getInt(30) == 1);
+ cache.setInventoryItems(cursor.getInt(31));
+ cache.setOnWatchlist(cursor.getInt(32) == 1);
+ cache.setReliableLatLon(cursor.getInt(33) > 0);
+ cache.setUserModifiedCoords(cursor.getInt(34) > 0);
+ cache.setCoords(getCoords(cursor, 35, 36));
+ cache.setFinalDefined(cursor.getInt(37) > 0);
+ cache.setLogPasswordRequired(cursor.getInt(41) > 0);
Log.d("Loading " + cache.toString() + " (" + cache.getListId() + ") from DB");
@@ -1850,7 +1819,6 @@ public class DataStore {
waypoint.setGeocode(cursor.getString(cursor.getColumnIndex("geocode")));
waypoint.setPrefix(cursor.getString(cursor.getColumnIndex("prefix")));
waypoint.setLookup(cursor.getString(cursor.getColumnIndex("lookup")));
- waypoint.setLatlon(cursor.getString(cursor.getColumnIndex("latlon")));
waypoint.setCoords(getCoords(cursor, cursor.getColumnIndex("latitude"), cursor.getColumnIndex("longitude")));
waypoint.setNote(cursor.getString(cursor.getColumnIndex("note")));
@@ -1970,7 +1938,7 @@ public class DataStore {
init();
- final Map<LogType, Integer> logCounts = new HashMap<>();
+ final Map<LogType, Integer> logCounts = new EnumMap<>(LogType.class);
final Cursor cursor = database.query(
dbTableLogCount,
@@ -2835,7 +2803,7 @@ public class DataStore {
}
cursor.close();
- } catch (final SQLiteDoneException e) {
+ } catch (final SQLiteDoneException ignored) {
// Do nothing, it only means we have no information on the cache
} catch (final Exception e) {
Log.e("DataStore.getCacheDescription", e);
@@ -2866,7 +2834,7 @@ public class DataStore {
final StringBuilder whereExpr = new StringBuilder("geocode in (");
final Iterator<String> iterator = geocodes.iterator();
while (true) {
- whereExpr.append(DatabaseUtils.sqlEscapeString(StringUtils.upperCase(iterator.next())));
+ DatabaseUtils.appendEscapedSQLString(whereExpr, StringUtils.upperCase(iterator.next()));
if (!iterator.hasNext()) {
break;
}
@@ -3003,10 +2971,6 @@ public class DataStore {
return getStatement("listFromGeocode", "SELECT reason FROM " + dbTableCaches + " WHERE guid = ?");
}
- private static SQLiteStatement getCacheIdOfGeocode() {
- return getStatement("cacheIdFromGeocode", "SELECT cacheid FROM " + dbTableCaches + " WHERE geocode = ?");
- }
-
private static SQLiteStatement getGeocodeOfGuid() {
return getStatement("geocodeFromGuid", "SELECT geocode FROM " + dbTableCaches + " WHERE guid = ?");
}
@@ -3018,7 +2982,7 @@ public class DataStore {
}
public static void markDropped(final List<Geocache> caches) {
- moveToList(caches, StoredList.TEMPORARY_LIST_ID);
+ moveToList(caches, StoredList.TEMPORARY_LIST.id);
}
public static Viewport getBounds(final String geocode) {