文档详情

说明案例导入java util hashmap mapfileservice.pdf

发布:2025-03-02约4.29千字共4页下载文档
文本预览下载声明

packagecom.mobilesafe.db.dao;

importjava.util.HashMap;

importjava.util.Map;

importandroid.content.Context;

importandroid.database.Cursor;

importandroid.database.sqlite.SQLiteDatabase;

importcom.mobilesafe.db.DBOpenHelper;

/**

*bean

*

*/

publicclassFileService{

privateDBOpenHelperopenHelper;

publicFileService(Contextcontext){

openHelper=newDBOpenHelper(context);

}

/**

*ÿ

*@parampath

*@return

*/

publicMapInteger,IntegergetData(Stringpath){

SQLiteDatabasedb=openHelper.getReadableDatabase();

Cursorcursor=db.rawQuery(selectthreadid,downlengthfromfiledownlogwhere

downpath=?,newString[]{path});

MapInteger,Integerdata=newHashMapInteger,Integer();

while(cursor.moveToNext()){

data.put(cursor.getInt(0),cursor.getInt(1));

}

cursor.close();

db.close();

returndata;

}

/**

*ÿ

*@parampath

*@parammap

*/

publicvoidsave(Stringpath,MapInteger,Integermap){//intthreadid,int

position

SQLiteDatabasedb=openHelper.getWritableDatabase();

db.beginTransaction();

try{

for(Map.EntryInteger,Integerentry:map.entrySet()){

db.execSQL(insertintofiledownlog(downpath,threadid,downlength)

values(?,?,?),

newObject[]{path,entry.getKey(),entry.getValue()});

}

db.setTransactionSuccessful();

}finally{

db.endTransaction();

}

db.close();

}

/**

*ÿ

*@parampath

*@parammap

*/

publicvoidupdate(Stringpath,MapInteger,Integermap){

SQLiteDatabasedb=openHelper.getWritableDatabase();

db.beginTransaction();

try{

for(Map.EntryInteger,Integerentry:map.entrySet()){

db.execSQL(updatefiledownlogsetdownlength=?wheredownpath=?and

thread

显示全部
相似文档