diff options
Diffstat (limited to 'main/src')
| -rw-r--r-- | main/src/cgeo/geocaching/DataStore.java | 10 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/Geocache.java | 8 |
2 files changed, 11 insertions, 7 deletions
diff --git a/main/src/cgeo/geocaching/DataStore.java b/main/src/cgeo/geocaching/DataStore.java index 662ce8b..4543451 100644 --- a/main/src/cgeo/geocaching/DataStore.java +++ b/main/src/cgeo/geocaching/DataStore.java @@ -1162,15 +1162,19 @@ public class DataStore { } private static void saveAttributesWithoutTransaction(final Geocache cache) { - String geocode = cache.getGeocode(); + final String geocode = cache.getGeocode(); + + // The attributes must be fetched first because lazy loading may load + // a null set otherwise. + final List<String> attributes = cache.getAttributes(); database.delete(dbTableAttributes, "geocode = ?", new String[]{geocode}); - if (cache.getAttributes().isEmpty()) { + if (attributes.isEmpty()) { return; } SQLiteStatement statement = PreparedStatements.getInsertAttribute(); final long timestamp = System.currentTimeMillis(); - for (String attribute : cache.getAttributes()) { + for (final String attribute : attributes) { statement.bindString(1, geocode); statement.bindLong(2, timestamp); statement.bindString(3, attribute); diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java index 840e5de..a8662a2 100644 --- a/main/src/cgeo/geocaching/Geocache.java +++ b/main/src/cgeo/geocaching/Geocache.java @@ -117,13 +117,13 @@ public class Geocache implements ICache, IWaypoint { private int votes = 0; private float myVote = 0; // valid ratings are larger than zero private int inventoryItems = 0; - private final List<String> attributes = new LazyInitializedList<String>() { + private final LazyInitializedList<String> attributes = new LazyInitializedList<String>() { @Override public List<String> call() { return DataStore.loadAttributes(geocode); } }; - private final List<Waypoint> waypoints = new LazyInitializedList<Waypoint>() { + private final LazyInitializedList<Waypoint> waypoints = new LazyInitializedList<Waypoint>() { @Override public List<Waypoint> call() { return DataStore.loadWaypoints(geocode); @@ -766,7 +766,7 @@ public class Geocache implements ICache, IWaypoint { @Override public List<String> getAttributes() { - return attributes; + return attributes.getUnderlyingList(); } @Override @@ -989,7 +989,7 @@ public class Geocache implements ICache, IWaypoint { * @return always non <code>null</code> */ public List<Waypoint> getWaypoints() { - return waypoints; + return waypoints.getUnderlyingList(); } /** |
