Android Open Source - savemypics C Account






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 a va2  s  . c  om
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 CAccount
{
    public final static String TABLE = "account";
    public final static String _ID = "_id";
    private final static String TYPE = "atype";
    private final static String NAME = "aname";

    private final static String TABLE_CREATE =
        "create table "+TABLE+"("+
        _ID+" integer primary key,"+
        TYPE+" text not null,"+
        NAME+" text not null,"+
        "unique ("+TYPE+","+NAME+"))";

    private final static String SELECT_BY_TYPE_NAME =
        "select "+_ID+" from "+TABLE+
        " where "+TYPE+"=? and "+NAME+"=?";

    public final static CAccount findOrAdd
        (SQLiteDatabase db, String atype, String name)
    {
        CAccount ret = find(db, atype, name);
        if (ret != null) { return ret; }

        ContentValues cv = new ContentValues();
        cv.put(TYPE, atype);
        cv.put(NAME, name);

        long id = db.insertWithOnConflict
            (TABLE, null, cv, SQLiteDatabase.CONFLICT_REPLACE);
        if (id <= 0) { return null; }
        return cache(id, atype, name);
    }

    public final static CAccount find
        (SQLiteDatabase db, String atype, String name)
    {
        String key = makeKey(atype, name);
        CAccount ret;
        synchronized (s_cache) {
            ret = s_cache.get(key);
        }
        if (ret != null) { return ret; }

        Cursor c = db.rawQuery
            (SELECT_BY_TYPE_NAME, new String[]{atype, name});
        try {
            if (c.moveToNext()) {
                return cache(c.getLong(0), atype, name);
            }
            else {
                return null;
            }
        }
        finally {
            CDb.close(c);
        }
    }

    private final static CAccount cache(long id, String atype, String name)
    {
        CAccount ret = new CAccount(id, atype, name);
        String k = makeKey(atype, name);
        synchronized (s_cache) {
            s_cache.put(k, ret);
        }
        return ret;
    }

    private final static String makeKey(String atype, String name)
    { return atype+"^"+name; }

    private CAccount(long id, String atype, String name)
    {
        m_id = id;
        m_atype = atype;
        m_name = name;
    }
    public long getId()
    { return m_id; }
    public String getType()
    { return m_atype; }
    public String getName()
    { return m_name; }
    public String toString()
    { return "CAccount["+m_id+","+m_atype+","+m_name+"]"; }

    private final long m_id;
    private final String m_atype;
    private final String m_name;

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

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




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