Android Open Source - Metascan-Online My S Q Lite D B






From Project

Back to project page Metascan-Online.

License

The source code is released under:

Apache License

If you think the Android project Metascan-Online 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.opswat.metascan;
/*from ww  w  .  j  a va  2s .  c o m*/
import java.util.ArrayList;
import java.util.HashMap;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

//Class for Database implemented using Singleton programming pattern
public class MySQLiteDB extends SQLiteOpenHelper{

  private static final int version = 1;
  private static final String name = "FileDB";

  // table name
  private static final String TABLE_SCANDATA = "scandata";

  // Table Columns names
  private static final String KEY_ID = "id";
  private static final String KEY_NAME = "name";
  private static final String KEY_DATAID = "dataid";
  private static final String KEY_STATUS = "status";

    
  private static final String[] COLUMNS = {KEY_ID,KEY_NAME,KEY_DATAID,KEY_STATUS};

    private static MySQLiteDB mysqlite = null;
    
    private static SQLiteDatabase db = null;


  private MySQLiteDB(Context context) {
    super(context, name, null, version);
    // TODO Auto-generated constructor stub
    mysqlite = this;
  }

  @Override
  public void onCreate(SQLiteDatabase database) {
    DBTable.onCreate(database);
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // Drop older table if existed
    DBTable.onUpgrade(db, oldVersion, newVersion);
  }
  
    // will return a singleton object of this class will as well open the connection for convenient

    public static MySQLiteDB getInstance(Context context){
        if(mysqlite==null){
          mysqlite = new MySQLiteDB(context);
           openConnection();
          }
         return mysqlite;
      }
     // will be called only once when singleton is created
 
    private static void openConnection(){
          if ( db == null ){
                db = mysqlite.getWritableDatabase();
            }
      }
    //call when application is closed by some means most likely

     public synchronized void closeConnecion() {
          if(mysqlite!=null){
            mysqlite.close();
                 db.close(); 
                 mysqlite = null;
                db = null;
            }
        }
     

     
     //Methods for scanning files data
     public void getAll(){
       String selectQuery = "SELECT * FROM scandata";
     Cursor cursor = db.rawQuery(selectQuery, null);
     ArrayList<HashMap<String, String>> maplist = new ArrayList<HashMap<String, String>>();
     // looping through all rows and adding to list

     if (cursor.moveToFirst()) {
         do {
             HashMap<String, String> map = new HashMap<String, String>();
             for(int i=0; i<cursor.getColumnCount();i++)
             {
                 map.put(cursor.getColumnName(i), cursor.getString(i));
             Log.d("main", cursor.getColumnName(i) + " "+ cursor.getString(i));

             }

             maplist.add(map);
         } while (cursor.moveToNext());
     }
     db.close();
     // return contact list
     //return maplist;
     }
     //Method for adding a file result to database
  public void addFile(String name,String dataid, String status){
    ContentValues values = new ContentValues();
    values.put(KEY_NAME, name);
    values.put(KEY_DATAID, dataid);
    values.put(KEY_STATUS, status);
    Log.d("main", name);
    db.insert(TABLE_SCANDATA, null, values);
  }
  //Checking the file status
  public String[] fileStatus(String name){

    Cursor cursor = db.query(TABLE_SCANDATA, COLUMNS, "name = ?", new String[] { String.valueOf(name) } , null, null, null, null);
    if (cursor != null)
          cursor.moveToFirst();
    else return null;
    if(cursor.getCount()!=0){
    String[] res = {cursor.getString(0),cursor.getString(1),cursor.getString(2),cursor.getString(3)};
    return res;
    }
    else return null;
  }
  //Updating the file status when fileobserver finds modifications
  public void updateFile(String name, String dataid, String status){
    ContentValues values = new ContentValues();
    values.put(KEY_DATAID, dataid);
    values.put(KEY_STATUS, status);
    db.update(TABLE_SCANDATA, values, KEY_NAME+" =?", new String[] { String.valueOf(name) });
  }
  //Deleting
  public void deleteFile(String name){
    db.delete(TABLE_SCANDATA, KEY_NAME+" =?", new String[] { String.valueOf(name) });
  }


}




Java Source Code List

com.opswat.metascan.DBTable.java
com.opswat.metascan.DirectoryChooserDialog.java
com.opswat.metascan.DownloadListener.java
com.opswat.metascan.FolderScan.java
com.opswat.metascan.HttpPostReceive.java
com.opswat.metascan.MainActivity.java
com.opswat.metascan.MySQLiteDB.java
com.opswat.metascan.ObserverService.java
com.opswat.metascan.ParseJSON.java
com.opswat.metascan.PostDataAsyncTask.java
com.opswat.metascan.RecursiveFileObserver.java
com.opswat.metascan.Results.java
com.opswat.metascan.Scan.java
com.opswat.metascan.Settings.java
com.opswat.metascan.TabAdapter.java
processing.files.SelectActivity.java
processing.files.SelectMode.java