Back to project page KeepMySecret.
The source code is released under:
GNU General Public License
If you think the Android project KeepMySecret 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 keepmysecretapp.app.com.keepmysecretapp.dao; /*www . ja va2 s . com*/ import android.content.ContentValues; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import java.util.ArrayList; import keepmysecretapp.app.com.keepmysecretapp.db.DbContext; import keepmysecretapp.app.com.keepmysecretapp.db.EntryType; import keepmysecretapp.app.com.keepmysecretapp.other.Tools; import keepmysecretapp.app.com.keepmysecretapp.tables.DataTable; import keepmysecretapp.app.com.keepmysecretapp.tables.GroupTable; import keepmysecretapp.app.com.keepmysecretapp.types.ListEntry; public class EntryDao extends Dao { private int groupID; public EntryDao(DbContext inContext, int groupID) { super(inContext); this.groupID = groupID; } @Override public void create(Object obj) { ListEntry entry = (ListEntry) obj; SQLiteDatabase db = this.dbContext.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(DataTable.KEY_ENTRY_NAME, entry.getName()); values.put(DataTable.KEY_ENTRY_DESCRIBE, entry.getDescribe()); values.put(DataTable.KEY_ENTRY_PASSWORD, entry.getPassword()); values.put(DataTable.KEY_ENTRY_GROUP_ID, entry.getGroupID()); db.insert(EntryType.DATA.getName(), null, values); db.close(); } @Override public void delete(Object obj) { ListEntry entry = (ListEntry) obj; SQLiteDatabase db = this.dbContext.getWritableDatabase(); db.delete(EntryType.DATA.getName(), DataTable.KEY_ID + " = ?", new String[]{entry.getID() + ""}); db.close(); } @Override public int update(Object obj) { ListEntry entry = (ListEntry) obj; SQLiteDatabase db = this.dbContext.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(DataTable.KEY_ENTRY_NAME, entry.getName()); values.put(DataTable.KEY_ENTRY_GROUP_ID, entry.getGroupID()); values.put(DataTable.KEY_ENTRY_PASSWORD, entry.getPassword()); values.put(DataTable.KEY_ENTRY_DESCRIBE, entry.getDescribe()); return db.update(EntryType.DATA.getName(), values, DataTable.KEY_ID + " = ?", new String[]{String.valueOf(entry.getID())}); } @Override public Object read(Object obj) { SQLiteDatabase db = this.dbContext.getReadableDatabase(); ListEntry entry = (ListEntry) obj; if (Tools.isStringEmpty(entry.getName())) return null; Cursor cursor = db.query(EntryType.DATA.getName(), new String[]{DataTable.KEY_ID, DataTable.KEY_ENTRY_NAME, DataTable.KEY_ENTRY_DESCRIBE, DataTable.KEY_ENTRY_PASSWORD, DataTable.KEY_ENTRY_GROUP_ID}, DataTable.KEY_ENTRY_NAME + "=?", new String[]{entry.getName()}, null, null, null, null); entry = null; if (cursor != null) { if (cursor.moveToFirst()) { entry = new ListEntry(); entry.setName(cursor.getString(1)); entry.setDescribe(cursor.getString(2)); entry.setPassword(cursor.getString(3)); entry.setGroupID(Integer.parseInt(cursor.getString(4))); } } return entry; } @Override public ArrayList<Object> getAllEntries() { ArrayList<Object> entries = new ArrayList<>(); SQLiteDatabase db = this.dbContext.getReadableDatabase(); Cursor cursor = db.query(EntryType.DATA.getName(), new String[]{DataTable.KEY_ID, DataTable.KEY_ENTRY_NAME, DataTable.KEY_ENTRY_PASSWORD, DataTable.KEY_ENTRY_DESCRIBE, DataTable.KEY_ENTRY_GROUP_ID}, DataTable.KEY_ENTRY_GROUP_ID + "=?", new String[]{this.groupID + ""}, null, null, null, null); if (cursor.moveToFirst()) { do { ListEntry entry = new ListEntry(); entry.setID(Integer.parseInt(cursor.getString(0))); entry.setName(cursor.getString(1)); entry.setPassword(cursor.getString(2)); entry.setDescribe(cursor.getString(3)); entry.setGroupID(Integer.parseInt(cursor.getString(4))); entries.add(entry); } while (cursor.moveToNext()); } return entries; } }