Back to project page EnterpriseShow.
The source code is released under:
This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...
If you think the Android project EnterpriseShow listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.ruixinyuan.producttrainingfinal.utils.download; /*from ww w. j av a 2 s . c o m*/ import java.util.HashMap; import java.util.Map; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import com.ruixinyuan.producttrainingfinal.db.DBConstants; import com.ruixinyuan.producttrainingfinal.db.DownloadDBOpenHelper; /* *@user vicentliu *@time 2013-6-19????9:45:52 *@package com.ruixinyuan.producttrainingfinal.utils.download */ public class FileService { private DownloadDBOpenHelper openHelper; public FileService(Context context) { openHelper = new DownloadDBOpenHelper(context); } private static final String sql = "select thread_id,downlength from " + DBConstants.DOWNLOAD_TABLE_NAME + " where path=?"; /** * ????????????????????? * @param path * @return */ public Map<Integer, Integer> getData(String path) { SQLiteDatabase db = openHelper.getReadableDatabase(); Cursor cursor = db.rawQuery(sql, new String[]{path}); Map<Integer, Integer> data = new HashMap<Integer, Integer>(); try { while(cursor.moveToNext()) { data.put(cursor.getInt(0), cursor.getInt(1)); } } finally { cursor.close(); db.close(); } return data; } /** * ????????????????????? * @param path * @param map */ public void update( String path , Map<Integer, Integer> map) { SQLiteDatabase db = openHelper.getWritableDatabase(); db.beginTransaction(); try { for(Map.Entry<Integer, Integer>entry : map.entrySet()) { db.execSQL("update " + DBConstants.DOWNLOAD_TABLE_NAME + " set downlength=? " + "where path=? and thread_id=?", new Object[]{entry.getValue(),path,entry.getKey()}); } db.setTransactionSuccessful(); } finally { db.endTransaction(); db.close(); } } /** * ???????????????????? * @param path * @param map */ public void save( String path , Map<Integer, Integer> map) { SQLiteDatabase db = openHelper.getWritableDatabase(); db.beginTransaction(); try { for(Map.Entry<Integer, Integer>entry : map.entrySet()) { db.execSQL("insert into " + DBConstants.DOWNLOAD_TABLE_NAME + " (path,thread_id,downlength)" + " values(?,?,?)", new Object[]{entry.getValue(),path,entry.getKey()}); } db.setTransactionSuccessful(); } finally { db.endTransaction(); db.close(); } } /** * ????????????????????? * @param path */ public void delete(String path) { SQLiteDatabase db = openHelper.getWritableDatabase(); try { db.execSQL("delete from " + DBConstants.DOWNLOAD_TABLE_NAME + " where path=?", new Object[]{path}); } finally { db.close(); } } }