Android Open Source - proximo Database






From Project

Back to project page proximo.

License

The source code is released under:

Copyright (c) 2010 Evan Martin. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: *...

If you think the Android project proximo 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

// Copyright (c) 2010 Evan Martin.  All rights reserved.
// Use of this source code is governed by a BSD-style license that can
// be found in the LICENSE file.
//  w ww .  j a  v a 2  s . c om
package org.neugierig.proximo;

import android.content.*;
import android.database.*;
import android.database.sqlite.*;
import android.util.Log;

public class Database {
  private static final String TAG = "proxmio Database";
  private static final String FILE = "queries.db";
  private static final String TABLE = "queries";
  private static final int VERSION = 1;

  private static class Helper extends SQLiteOpenHelper {
    Helper(Context context) {
      super(context, FILE, null, VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
      db.execSQL("CREATE TABLE " + TABLE
               + "( query STRING PRIMARY KEY"
               + ", json STRING"
            // + ", lastfetch INTEGER"
               + ")");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
            + newVersion + ", which will destroy all old data");
      db.execSQL("DROP TABLE IF EXISTS " + TABLE);
      onCreate(db);
    }
  }

  Database(Context context) {
    mHelper = new Helper(context);
  }

  String get(String query) {
    SQLiteDatabase db = mHelper.getReadableDatabase();
    Cursor cur = db.query(TABLE, new String[] {"json"},
                          "query = ?", new String[] { query },
                          null, null, null);
    if (!cur.moveToFirst())
      return null;
    return cur.getString(0);
  }

  void put(String query, String json) {
    SQLiteDatabase db = mHelper.getWritableDatabase();
    ContentValues args = new ContentValues();
    args.put("query", query);
    args.put("json", json);
    db.replace(TABLE, "query", args);
  }

  private Helper mHelper;
}




Java Source Code List

org.neugierig.proximo.AsyncBackendHelper.java
org.neugierig.proximo.AsyncBackend.java
org.neugierig.proximo.Backend.java
org.neugierig.proximo.Database.java
org.neugierig.proximo.ProximoBus.java
org.neugierig.proximo.Route.java
org.neugierig.proximo.Routes.java
org.neugierig.proximo.SplitListAdapter.java
org.neugierig.proximo.StarDBAdapter.java
org.neugierig.proximo.Stop.java
org.neugierig.proximo.Stops.java
org.neugierig.proximo.UpdateService.java
org.neugierig.proximo.ViewState.java