Android Open Source - savemypics C Map






From Project

Back to project page savemypics.

License

The source code is released under:

Copyright (c) 2014, KB Sriram All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. R...

If you think the Android project savemypics listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.savemypics.android.db;
//  w  ww.  j  ava2  s . c o m
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import java.util.LinkedHashMap;
import java.util.Map;

@SuppressWarnings("serial")
public final class CMap
{
    private final static String TABLE = "map";
    private final static String ACCOUNT_ID = "account_id";
    private final static String KEY = "mkey";
    private final static String VALUE = "mvalue";

    private final static String TABLE_CREATE =
        "create table "+TABLE+"("+
        ACCOUNT_ID+" integer not null,"+
        KEY+" text not null,"+
        VALUE+" text not null,"+
        "primary key ("+ACCOUNT_ID+","+KEY+"),"+
        "foreign key ("+ACCOUNT_ID+") references "+
        CAccount.TABLE+"("+CAccount._ID+"))";

    private final static String SELECT_BY_ACCOUNT_KEY =
        "select "+VALUE+" from "+TABLE+" where "+ACCOUNT_ID+"=? and "+KEY+"=?";

    public final static long optLong
        (SQLiteDatabase db, long aid, String key, long dflt)
    {
        String value = get(db, aid, key);
        if ((value == null) || (value.length() == 0)) { return dflt; }
        return Long.parseLong(value);
    }

    public final static String optString
        (SQLiteDatabase db, long aid, String key, String dflt)
    {
        String value = get(db, aid, key);
        if ((value == null) || (value.length() == 0)) { return dflt; }
        else { return value; }
    }

    public final static String get(SQLiteDatabase db, long aid, String key)
    {
        String k = makeKey(aid, key);
        String ret;
        synchronized (s_cache) {
            ret = s_cache.get(k);
        }
        if (ret != null) { return ret; }

        Cursor result = db.rawQuery
            (SELECT_BY_ACCOUNT_KEY, new String[] {String.valueOf(aid), key});
        try {
            if (result.moveToNext()) { return cache(k, result.getString(0)); }
            else { return null; }
        }
        finally {
            CDb.close(result);
        }
    }

    // return true if the insert worked.
    public final static boolean put
        (SQLiteDatabase db, long aid, String key, String value)
    {
        String k = makeKey(aid, key);
        ContentValues cv = new ContentValues();
        cv.put(ACCOUNT_ID, aid);
        cv.put(KEY, key);
        cv.put(VALUE, value);
        boolean ret = db.insertWithOnConflict
            (TABLE, null, cv, SQLiteDatabase.CONFLICT_REPLACE) > 0;
        if (ret) { cache(k, value); }
        else { cache(k, null); }
        return ret;
    }

    final static void makeSchema(SQLiteDatabase db)
    {
        db.execSQL(TABLE_CREATE);
    }

    private final static String makeKey(long id, String k)
    { return id+"^"+k; }

    private final static String cache(String k, String v)
    {
        synchronized (s_cache) {
            if (v != null) { s_cache.put(k, v); }
            else { s_cache.remove(k); }
        }
        return v;
    }

    private final static Map<String, String> s_cache =
        (new LinkedHashMap<String, String>() {
            @Override protected boolean removeEldestEntry(Map.Entry e) {
                return size() > 25;
            }
        });
}




Java Source Code List

android.util.Base64.java
org.savemypics.android.activity.AActivity.java
org.savemypics.android.activity.ABaseSettingsActivity.java
org.savemypics.android.activity.CAccountInfoListAdapter.java
org.savemypics.android.activity.CFlickrSettingsActivity.java
org.savemypics.android.activity.CSnapfishSettingsActivity.java
org.savemypics.android.activity.CStartActivity.java
org.savemypics.android.authenticator.AAuthenticatorActivity.java
org.savemypics.android.authenticator.CAuthenticationService.java
org.savemypics.android.authenticator.CAuthenticator.java
org.savemypics.android.authenticator.CFlickrLoginHookActivity.java
org.savemypics.android.authenticator.CFlickrWebActivity.java
org.savemypics.android.authenticator.CSelectProviderActivity.java
org.savemypics.android.authenticator.CSnapfishLoginActivity.java
org.savemypics.android.db.CAccount.java
org.savemypics.android.db.CDb.java
org.savemypics.android.db.CLocalImage.java
org.savemypics.android.db.CMap.java
org.savemypics.android.db.CRemoteImage.java
org.savemypics.android.event.AEvent.java
org.savemypics.android.event.CEventBus.java
org.savemypics.android.event.CExceptionEvent.java
org.savemypics.android.glue.ABaseGlue.java
org.savemypics.android.glue.CFlickrGlue.java
org.savemypics.android.glue.CSnapfishGlue.java
org.savemypics.android.receiver.CNetworkChangeReceiver.java
org.savemypics.android.service.CTaskQueue.java
org.savemypics.android.sync.CMediaUtils.java
org.savemypics.android.sync.CSyncAdapter.java
org.savemypics.android.sync.CSyncService.java
org.savemypics.android.sync.CSyncUtils.java
org.savemypics.android.util.CBitmapUtils.java
org.savemypics.android.util.CFileCache.java
org.savemypics.android.util.CLruCache.java
org.savemypics.android.util.CUtils.java
org.savemypics.android.util.CUtils.java
org.savemypics.android.view.CMaximumWidthLayout.java
org.savemypics.android.view.CModularLayout.java
org.savemypics.android.view.CRefreshButton.java
org.savemypics.android.view.CRoundedBitmapView.java
org.savemypics.android.view.CStatusCounterView.java
org.savemypics.plugin.CIOUtils.java
org.savemypics.plugin.CPlugin.java
org.savemypics.plugin.flickr.CFlickrAlbum.java
org.savemypics.plugin.flickr.CFlickrUtils.java
org.savemypics.plugin.snapfish.CSnapfishAlbum.java
org.savemypics.plugin.snapfish.CSnapfishFeed.java
org.savemypics.plugin.snapfish.CSnapfishUser.java
org.savemypics.plugin.snapfish.CSnapfishUtils.java