public void deletePursuit(Pursuit pursuit) { long pursuitId = pursuit.getId(); scoreDAO.deleteScore(pursuit.getIdealScore()); /*long idealScoreId = pursuit.getIdealScore().getId();*/ Log.d(this.getClass().getSimpleName(), "Deleting task Id: " + pursuitId); database.delete( DatabaseHelper.PURSUIT_TABLE, DatabaseHelper.COLUMN_PURSUIT_ID_PK + " = " + pursuitId, null); }
private Pursuit cursorToPursuit(Cursor cursor) { Pursuit pursuit = new Pursuit(); pursuit.setId(cursor.getLong(DatabaseHelper.INDEX_COLUMN_PURSUIT_ID_PK)); pursuit.setName(cursor.getString(DatabaseHelper.INDEX_COLUMN_PURSUIT_NAME)); // TODO - pursuit.setIdealScore(); int type = (cursor.getInt(DatabaseHelper.INDEX_COLUMN_PURSUIT_TYPE)); // TODO - feels hacky to use -1 ... change? pursuit.setStatedType(Pursuit.PursuitType.values()[type - 1]); return pursuit; }
public void insertPursuit(Pursuit pursuit) { // TODO // Score idealScore = pursuit.getIdealScore(); // scoreDAO.insertScore(idealScore); ContentValues pursuitValues = getContentValues(pursuit); long insertId = database.insert(DatabaseHelper.PURSUIT_TABLE, null, pursuitValues); if (insertId == -1) { Log.e( this.getClass().getSimpleName(), "There was an error inserting " + pursuit.getName() + " into the database"); } else { pursuit.setId(insertId); Log.d(this.getClass().getSimpleName(), "Pursuit with id " + insertId + " added to database"); } }
public void update(Pursuit pursuit) { ContentValues values = getContentValues(pursuit); /* new ContentValues(); values.put(DatabaseHelper.COLUMN_PURSUIT_NAME, pursuit.getName()); values.put(DatabaseHelper.COLUMN_PURSUIT_TYPE, pursuit.getStatedType().getIntCode()); */ // TODO - values.put(DatabaseHelper.COLUMN_IDEAL_SCORE); // values.put(DatabaseHelper.COLUMN_COMPLETE, pursuit.getCompleteAsInteger()); database.update( DatabaseHelper.PURSUIT_TABLE, values, DatabaseHelper.COLUMN_PURSUIT_ID_PK + "=" + pursuit.getId(), null); }
private ContentValues getContentValues(Pursuit pursuit) { ContentValues pursuitValues = new ContentValues(); if (pursuit.getName() != null) pursuitValues.put(DatabaseHelper.COLUMN_PURSUIT_NAME, pursuit.getName()); if (pursuit.getStatedType() != null) pursuitValues.put(DatabaseHelper.COLUMN_PURSUIT_TYPE, pursuit.getStatedType().getIntCode()); if (pursuit.getIdealScore() != null) pursuitValues.put(DatabaseHelper.COLUMN_IDEAL_SCORE, pursuit.getIdealScore().getId()); return pursuitValues; }