Android Open Source - Alfred4Android D B Helper






From Project

Back to project page Alfred4Android.

License

The source code is released under:

Apache License

If you think the Android project Alfred4Android 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 com.toraleap.collimator.dal;
/*from  w w w .  j  a  va 2  s.  c  o  m*/
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DBHelper extends SQLiteOpenHelper {
  private static final int DB_VERSION = 2;
  private static final String DB_NAME = "collimator.db";

  public DBHelper(Context context) {
    super(context, DB_NAME, null, DB_VERSION);
  }
  
    @Override
    public synchronized SQLiteDatabase getWritableDatabase() {
        SQLiteDatabase db = super.getWritableDatabase();
        return db;
    }
    
  @Override
  public void onCreate(SQLiteDatabase db) {
    db.execSQL(String.format("CREATE TABLE %s (%s INTEGER PRIMARY KEY AUTOINCREMENT, %s TEXT UNIQUE, %s INTEGER)", 
        DBColumns.TagTable, DBColumns.TagId, DBColumns.TagName, DBColumns.Type));
    db.execSQL(String.format("CREATE TABLE %s (%s INTEGER PRIMARY KEY AUTOINCREMENT, %s TEXT, %s TEXT, %s INTEGER, %s INTEGER)", 
        DBColumns.FileTable, DBColumns.FileId, DBColumns.Name, DBColumns.Path, DBColumns.Size, DBColumns.LastModified));
    db.execSQL(String.format("CREATE TABLE %s (%s INTEGER PRIMARY KEY AUTOINCREMENT, %s INTEGER REFERENCES %s(%s), %s INTEGER REFERENCES %s(%s))", 
        DBColumns.LinkTable, DBColumns.LinkId, DBColumns.FileId, DBColumns.FileTable, DBColumns.FileId, DBColumns.TagId, DBColumns.TagTable, DBColumns.TagId));
    db.execSQL(String.format("CREATE VIEW %s AS SELECT f.%s, f.%s, f.%s, f.%s, f.%s, t.%s, t.%s, t.%s FROM %s f INNER JOIN %s l ON f.%s = l.%s INNER JOIN %s t ON l.%s = t.%s", 
        DBColumns.ViewTable,  DBColumns.FileId, DBColumns.Name, DBColumns.Path, DBColumns.Size, DBColumns.LastModified, DBColumns.TagId, DBColumns.TagName, DBColumns.Type, DBColumns.FileTable,
        DBColumns.LinkTable, DBColumns.FileId, DBColumns.FileId, DBColumns.TagTable, DBColumns.TagId, DBColumns.TagId));
    db.execSQL(String.format("CREATE INDEX tag_name_index ON %s (%s)", DBColumns.TagTable, DBColumns.TagName));
    Log.e("COLLIMATOR", "DB_CREATED");
    //db.execSQL(String.format("CREATE VIEW view_tag AS SELECT (SELECT %s )", TagColumns.Name))
//    db.execSQL(String.format("CREATE INDEX filetag_file_index ON filetag (%s)", FileTagColumns.FileId));
//    db.execSQL(String.format("CREATE INDEX filetag_tag_index ON filetag (%s)", FileTagColumns.TagId));
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL(String.format("DROP TABLE IF EXISTS %s", DBColumns.TagTable));
    db.execSQL(String.format("DROP TABLE IF EXISTS %s", DBColumns.FileTable));
    db.execSQL(String.format("DROP TABLE IF EXISTS %s", DBColumns.LinkTable));
      onCreate(db);
  }

}




Java Source Code List

android.media.MediaMetadataRetriever.java
com.toraleap.collimator.AppSearchActivity.java
com.toraleap.collimator.GlobalContext.java
com.toraleap.collimator.HelpActivity.java
com.toraleap.collimator.PrefsActivity.java
com.toraleap.collimator.SearchActivity.java
com.toraleap.collimator.ShortcutActivity.java
com.toraleap.collimator.bll.FileScannerService.java
com.toraleap.collimator.bll.TagGenerator.java
com.toraleap.collimator.dal.DBColumns.java
com.toraleap.collimator.dal.DBHelper.java
com.toraleap.collimator.dal.DBOperation.java
com.toraleap.collimator.data.Expression.java
com.toraleap.collimator.data.IndexData.java
com.toraleap.collimator.data.IndexLoader.java
com.toraleap.collimator.data.Index.java
com.toraleap.collimator.data.Match.java
com.toraleap.collimator.data.Matcher.java
com.toraleap.collimator.data.Sorter.java
com.toraleap.collimator.ext.GlobalProvider.java
com.toraleap.collimator.ext.Playlist.java
com.toraleap.collimator.model.BaseTag.java
com.toraleap.collimator.ui.FloatingDialog.java
com.toraleap.collimator.ui.MatchAdapter.java
com.toraleap.collimator.util.DigestUtil.java
com.toraleap.collimator.util.FileInfo.java
com.toraleap.collimator.util.MimeTypeMap.java
com.toraleap.collimator.util.RecursiveFileObserver.java
com.toraleap.collimator.util.ShortcutHelper.java
com.toraleap.collimator.util.SoftCache.java
com.toraleap.collimator.util.ThumbnailUtil.java
com.toraleap.collimator.util.Unicode2Alpha.java