@Override public boolean updateData(Object data) { boolean ret = false; SQLiteDatabase db = null; try { db = DB.getInstance(mContext).getDB(true); if (!isTableExists()) { db.execSQL(CREATE_TABLE); } TBIRIGATANGGULN tbirigatangguln = (TBIRIGATANGGULN) data; ContentValues val = new ContentValues(); val.put(Nama_Jaringan_Irigasi, tbirigatangguln.getNama_Jaringan_Irigasi()); val.put(Kondisi, tbirigatangguln.getKondisi()); val.put(Informasi_Tambahan, tbirigatangguln.getInformasi_Tambahan()); String whereClause = TABLE_ID + "=?"; String whereArgs[] = new String[] {String.valueOf(tbirigatangguln.getId())}; db.update(TABLE_NAME, val, whereClause, whereArgs); ret = true; } catch (Exception e) { Log.e(TAG, e.getMessage()); } finally { if (db != null) { db.close(); } } return ret; }
@Override public boolean insertData(Object data) { boolean ret = false; SQLiteDatabase db = null; try { db = DB.getInstance(mContext).getDB(true); if (!isTableExists()) { db.execSQL(CREATE_TABLE); } TBIRIGATANGGULN tbirigatangguln = (TBIRIGATANGGULN) data; ContentValues val = new ContentValues(); val.put(OBJECTID, tbirigatangguln.getOBJECTID()); val.put(kodeaset, tbirigatangguln.getKodeaset()); val.put(Nama_Jaringan_Irigasi, tbirigatangguln.getNama_Jaringan_Irigasi()); val.put(Kondisi, tbirigatangguln.getKondisi()); val.put(Informasi_Tambahan, tbirigatangguln.getInformasi_Tambahan()); db.insert(TABLE_NAME, null, val); ret = true; } catch (Exception e) { Log.e(TAG, e.getMessage()); } finally { if (db != null) { db.close(); } } return ret; }
@Override public boolean deleteData(Object data) { boolean ret = false; SQLiteDatabase db = null; try { db = DB.getInstance(mContext).getDB(true); if (!isTableExists()) { db.execSQL(CREATE_TABLE); } TBIRIGATANGGULN tbirigatangguln = (TBIRIGATANGGULN) data; String whereClause = TABLE_ID + "=?"; String whereArgs[] = new String[] {String.valueOf(tbirigatangguln.getId())}; db.delete(TABLE_NAME, whereClause, whereArgs); ret = true; } catch (Exception e) { Log.e(TAG, e.getMessage()); } finally { if (db != null) { db.close(); } } return ret; }
@Override public <T> List<T> getData(Class<T> returnTypeClass, String whereClause, String[] whereArgs) { List<T> data = new LinkedList<>(); SQLiteDatabase db = null; Cursor cur = null; try { db = DB.getInstance(mContext).getDB(false); if (!isTableExists()) { db.execSQL(CREATE_TABLE); } String sql = "SELECT * FROM " + TABLE_NAME + " WHERE " + whereClause; cur = db.rawQuery(sql, whereArgs); if (cur != null) { TBIRIGATANGGULN tbirigatangguln = null; if (cur.moveToFirst()) { do { tbirigatangguln = new TBIRIGATANGGULN(); // FCIRIGAPBWPRILN = new fcirigapbwpriln(); // myLayer = new MyLayer(); tbirigatangguln.setId(cur.getInt(0)); tbirigatangguln.setKodeaset(cur.getInt(1)); tbirigatangguln.setNama_Jaringan_Irigasi(cur.getInt(2)); tbirigatangguln.setKondisi(cur.getString(3)); tbirigatangguln.setInformasi_Tambahan(cur.getString(4)); data.add(returnTypeClass.cast(tbirigatangguln)); } while (cur.moveToNext()); } cur.close(); } } catch (Exception e) { Log.e(TAG, e.getMessage()); } finally { if (db != null) { db.close(); } } return data; }