public static boolean storeIntoDatabase(final Geocache cache) {
        return withAccessLock(() -> {
            cache.addStorageLocation(StorageLocation.DATABASE);
            cacheCache.putCacheInCache(cache);
            Log.d("Saving " + cache + " (" + cache.getLists() + ") to DB");

            final ContentValues values = new ContentValues();

            if (cache.getUpdated() == 0) {
                values.put("updated", System.currentTimeMillis());
            } else {
                values.put("updated", cache.getUpdated());
            }
            values.put("reason", StoredList.STANDARD_LIST_ID);
            values.put("detailed", cache.isDetailed() ? 1 : 0);
            values.put("detailedupdate", cache.getDetailedUpdate());
            values.put("visiteddate", cache.getVisitedDate());
            values.put("geocode", cache.getGeocode());
            values.put("cacheid", cache.getCacheId());
            values.put("guid", cache.getGuid());
            values.put("type", cache.getType().id);
            values.put("name", cache.getName());
            values.put("owner", cache.getOwnerDisplayName());
            values.put("owner_real", cache.getOwnerUserId());
            final Date hiddenDate = cache.getHiddenDate();
            if (hiddenDate == null) {
                values.put("hidden", 0);
            } else {
                values.put("hidden", hiddenDate.getTime());
            }
            values.put("hint", cache.getHint());
            values.put("size", cache.getSize().id);
            values.put("difficulty", cache.getDifficulty());
            values.put("terrain", cache.getTerrain());
            values.put("location", cache.getLocation());
            values.put("distance", cache.getDistance());
            values.put("direction", cache.getDirection());
            putCoords(values, "", cache.getCoords());
            values.put("reliable_latlon", 0);          // Todo: refactor - remove column
            values.put("shortdesc", cache.getShortDescription());
            values.put("personal_note", cache.getPersonalNote());
            values.put("description", cache.getDescription());
            values.put("favourite_cnt", cache.getFavoritePoints());
            values.put("rating", cache.getRating());
            values.put("votes", cache.getVotes());
            values.put("myvote", cache.getMyVote());
            values.put("disabled", cache.isDisabled() ? 1 : 0);
            values.put("archived", cache.isArchived() ? 1 : 0);
            values.put("members", cache.isPremiumMembersOnly() ? 1 : 0);
            values.put("found", cache.isFound() ? 1 : cache.isDNF() ? -1 : 0);
            values.put("favourite", cache.isFavorite() ? 1 : 0);
            values.put("inventoryunknown", cache.getInventoryItems());
            values.put("onWatchlist", cache.isOnWatchlist() ? 1 : 0);
            values.put("coordsChanged", cache.hasUserModifiedCoords() ? 1 : 0);
            values.put("finalDefined", cache.hasFinalDefined() ? 1 : 0);
            values.put("logPasswordRequired", cache.isLogPasswordRequired() ? 1 : 0);
            values.put("watchlistCount", cache.getWatchlistCount());
            values.put("preventWaypointsFromNote", cache.isPreventWaypointsFromNote() ? 1 : 0);
            values.put("owner_guid", cache.getOwnerGuid());
            values.put("emoji", cache.getAssignedEmoji());
            values.put("alcMode", cache.getAlcMode());
            values.put("tier", cache.getTier() == null ? null : cache.getTier().getRaw());

            init();

            // try to update record else insert fresh..
            database.beginTransaction();

            try {
                saveAttributesWithoutTransaction(cache);
                saveCategoriesWithoutTransaction(cache);
                saveWaypointsWithoutTransaction(cache);
                saveSpoilersWithoutTransaction(cache);
                saveLogCountsWithoutTransaction(cache);
                saveInventoryWithoutTransaction(cache.getGeocode(), cache.getInventory());
                saveListsWithoutTransaction(cache);

                final int rows = database.update(dbTableCaches, values, "geocode = ?", new String[]{cache.getGeocode()});
                if (rows == 0) {
                    // cache is not in the DB, insert it
                    /* long id = */
                    database.insert(dbTableCaches, null, values);
                }
                database.setTransactionSuccessful();
                return true;
            } catch (final Exception e) {
                Log.e("SaveCache", e);
            } finally {
                database.endTransaction();
            }

            return false;
        });
    }
Save/store a cache to the CacheCache

@param caches the caches to save in the CacheCache/DB
main/src/main/java/cgeo/geocaching/storage/DataStore.java