aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2013-03-02 12:13:56 +0100
committerBananeweizen <bananeweizen@gmx.de>2013-03-02 12:13:56 +0100
commit40765f11f49f15dd9a0a040b631228b45c7211a5 (patch)
treedb22f59bda51b27e18222c02ab288819d8add13d /main/src
parentc05fb9699b70ec7d9800bf1e7264235dcf621294 (diff)
downloadcgeo-40765f11f49f15dd9a0a040b631228b45c7211a5.zip
cgeo-40765f11f49f15dd9a0a040b631228b45c7211a5.tar.gz
cgeo-40765f11f49f15dd9a0a040b631228b45c7211a5.tar.bz2
fix #2534: Updating a OC.de cache doubles the cache description
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/Geocache.java28
-rw-r--r--main/src/cgeo/geocaching/cgData.java30
2 files changed, 47 insertions, 11 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java
index 18a315c..e672ca8 100644
--- a/main/src/cgeo/geocaching/Geocache.java
+++ b/main/src/cgeo/geocaching/Geocache.java
@@ -618,15 +618,27 @@ public class Geocache implements ICache, IWaypoint {
@Override
public String getHint() {
initializeCacheTexts();
+ assertTextNotNull(hint, "Hint");
return hint;
}
/**
+ * After lazy loading the lazily loaded field must be non {@code null}.
+ *
+ */
+ private static void assertTextNotNull(final String field, final String name) throws InternalError {
+ if (field == null) {
+ throw new InternalError(name + " field is not allowed to be null here");
+ }
+ }
+
+ /**
* Attention, calling this method may trigger a database access for the cache!
*/
@Override
public String getDescription() {
initializeCacheTexts();
+ assertTextNotNull(description, "Description");
return description;
}
@@ -635,7 +647,19 @@ public class Geocache implements ICache, IWaypoint {
*/
private void initializeCacheTexts() {
if (description == null || shortdesc == null || hint == null || location == null) {
- cgData.loadCacheTexts(this);
+ Geocache partial = cgData.loadCacheTexts(this.getGeocode());
+ if (description == null) {
+ setDescription(partial.getDescription());
+ }
+ if (shortdesc == null) {
+ setShortDescription(partial.getShortDescription());
+ }
+ if (hint == null) {
+ setHint(partial.getHint());
+ }
+ if (location == null) {
+ setLocation(partial.getLocation());
+ }
}
}
@@ -645,6 +669,7 @@ public class Geocache implements ICache, IWaypoint {
@Override
public String getShortDescription() {
initializeCacheTexts();
+ assertTextNotNull(shortdesc, "Short description");
return shortdesc;
}
@@ -673,6 +698,7 @@ public class Geocache implements ICache, IWaypoint {
@Override
public String getLocation() {
initializeCacheTexts();
+ assertTextNotNull(location, "Location");
return location;
}
diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java
index f83ba87..770a28f 100644
--- a/main/src/cgeo/geocaching/cgData.java
+++ b/main/src/cgeo/geocaching/cgData.java
@@ -2660,11 +2660,21 @@ public class cgData {
return result;
}
- public static String loadCacheTexts(final Geocache cache) {
- final String geocode = cache.getGeocode();
- if (StringUtils.isBlank(geocode)) {
- return null;
- }
+ /**
+ * Load the lazily initialized fields of a cache and return them as partial cache (all other fields unset).
+ *
+ * @param geocode
+ * @return
+ */
+ public static Geocache loadCacheTexts(final String geocode) {
+ final Geocache partial = new Geocache();
+
+ // in case of database issues, we still need to return a result to avoid endless loops
+ partial.setDescription(StringUtils.EMPTY);
+ partial.setShortDescription(StringUtils.EMPTY);
+ partial.setHint(StringUtils.EMPTY);
+ partial.setLocation(StringUtils.EMPTY);
+
init();
try {
@@ -2679,10 +2689,10 @@ public class cgData {
"1");
if (cursor.moveToFirst()) {
- cache.setDescription(StringUtils.defaultString(cursor.getString(0)));
- cache.setShortDescription(StringUtils.defaultString(cursor.getString(1)));
- cache.setHint(StringUtils.defaultString(cursor.getString(2)));
- cache.setLocation(StringUtils.defaultString(cursor.getString(3)));
+ partial.setDescription(StringUtils.defaultString(cursor.getString(0)));
+ partial.setShortDescription(StringUtils.defaultString(cursor.getString(1)));
+ partial.setHint(StringUtils.defaultString(cursor.getString(2)));
+ partial.setLocation(StringUtils.defaultString(cursor.getString(3)));
}
cursor.close();
@@ -2692,7 +2702,7 @@ public class cgData {
Log.e("cgData.getCacheDescription", e);
}
- return null;
+ return partial;
}
/**