aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/cgData.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/cgData.java')
-rw-r--r--main/src/cgeo/geocaching/cgData.java52
1 files changed, 35 insertions, 17 deletions
diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java
index 28485a5..2ef5b27 100644
--- a/main/src/cgeo/geocaching/cgData.java
+++ b/main/src/cgeo/geocaching/cgData.java
@@ -33,6 +33,7 @@ import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.EnumSet;
@@ -85,7 +86,7 @@ public class cgData {
private static int[] cacheColumnIndex;
private static CacheCache cacheCache = new CacheCache();
private static SQLiteDatabase database = null;
- private static final int dbVersion = 66;
+ private static final int dbVersion = 67;
public static final int customListIdOffset = 10;
private static final String dbName = "data";
private static final String dbTableCaches = "cg_caches";
@@ -107,7 +108,7 @@ public class cgData {
+ "detailedupdate long, "
+ "visiteddate long, "
+ "geocode text unique not null, "
- + "reason integer not null default 0, " // cached, favourite...
+ + "reason integer not null default 0, " // cached, favorite...
+ "cacheid text, "
+ "guid text, "
+ "type text, "
@@ -674,6 +675,16 @@ public class cgData {
}
}
+ // issue2662 OC: Leichtes Klettern / Easy climbing
+ if (oldVersion < 67) {
+ try {
+ db.execSQL("update " + dbTableAttributes + " set attribute = 'easy_climbing_yes' where geocode like 'OC%' and attribute = 'climbing_yes'");
+ db.execSQL("update " + dbTableAttributes + " set attribute = 'easy_climbing_no' where geocode like 'OC%' and attribute = 'climbing_no'");
+ } catch (Exception e) {
+ Log.e("Failed to upgrade to ver. 67", e);
+
+ }
+ }
}
db.setTransactionSuccessful();
@@ -962,25 +973,32 @@ public class cgData {
throw new IllegalArgumentException("cache must not be null");
}
- // merge always with data already stored in the CacheCache or DB
- if (saveFlags.contains(SaveFlag.SAVE_CACHE)) {
- cache.gatherMissingFrom(cacheCache.getCacheFromCache(cache.getGeocode()));
- cacheCache.putCacheInCache(cache);
- }
+ // Merge with the data already stored in the CacheCache or in the database if
+ // the cache had not been loaded before, and update the CacheCache.
+ // Also, a DB update is required if the merge data comes from the CacheCache
+ // (as it may be more recent than the version in the database), or if the
+ // version coming from the database is different than the version we are entering
+ // into the cache (that includes absence from the database).
+ final String geocode = cache.getGeocode();
+ final Geocache cacheFromCache = cacheCache.getCacheFromCache(geocode);
+ final boolean dbUpdateRequired =
+ !cache.gatherMissingFrom(cacheFromCache != null ?
+ cacheFromCache :
+ loadCache(geocode, LoadFlags.LOAD_ALL_DB_ONLY)) ||
+ cacheFromCache != null;
+ cache.addStorageLocation(StorageLocation.CACHE);
+ cacheCache.putCacheInCache(cache);
+ // Only save the cache in the database if it is requested by the caller and
+ // the cache contains detailed information.
if (!saveFlags.contains(SaveFlag.SAVE_DB)) {
return true;
}
- boolean updateRequired = !cache.gatherMissingFrom(loadCache(cache.getGeocode(), LoadFlags.LOAD_ALL_DB_ONLY));
- // only save a cache to the database if
- // - the cache is detailed
- // - there are changes
- // - the cache is only stored in the CacheCache so far
- if ((!updateRequired || !cache.isDetailed()) && cache.getStorageLocation().contains(StorageLocation.DATABASE)) {
- return false;
- }
+ return cache.isDetailed() && dbUpdateRequired && storeIntoDatabase(cache);
+ }
+ private static boolean storeIntoDatabase(final Geocache cache) {
cache.addStorageLocation(StorageLocation.DATABASE);
cacheCache.putCacheInCache(cache);
Log.d("Saving " + cache.toString() + " (" + cache.getListId() + ") to DB");
@@ -1396,7 +1414,7 @@ public class cgData {
* @param geocodes
* @return Set of loaded caches. Never null.
*/
- public static Set<Geocache> loadCaches(final Set<String> geocodes, final EnumSet<LoadFlag> loadFlags) {
+ public static Set<Geocache> loadCaches(final Collection<String> geocodes, final EnumSet<LoadFlag> loadFlags) {
if (CollectionUtils.isEmpty(geocodes)) {
return new HashSet<Geocache>();
}
@@ -1440,7 +1458,7 @@ public class cgData {
}
if (remaining.size() >= 1) {
- Log.i("cgData.loadCaches(" + remaining.toString() + ") failed");
+ Log.d("cgData.loadCaches(" + remaining.toString() + ") returned no results");
}
return result;
}