コード例 #1
0
  // getting all incidents under single incident type
  public List<Incident> getAllIncidentsByIncidentType(IncidentType incidentType) {
    List<Incident> incidents = new ArrayList<>();
    String selectQuery =
        "SELECT Id, IncidentTypeId, CreatedByContactId, IncidentDate, Description, InitialAction, Reportable FROM "
            + Constants.TABLE_INCIDENT;

    Log.e(LOG, selectQuery);

    db = dbHelper.getReadableDatabase();
    // Cursor c = db.rawQuery(selectQuery, null);

    Cursor c =
        db.query(
            Constants.TABLE_INCIDENT, // a. table
            new String[] {
              "Id",
              "IncidentTypeId",
              "CreatedByContactId",
              "IncidentDate",
              "Description",
              "InitialAction",
              "Reportable"
            }, // b. column names
            " IncidentTypeId = ?", // c. selections
            new String[] {String.valueOf(incidentType.getId())}, // d. selections args
            null, // e. group by
            null, // f. having
            null, // g. order by
            null);

    // looping through all rows and adding to list
    if (c.moveToFirst()) {
      do {
        Incident anIncident = new Incident();
        anIncident.setId(c.getInt((c.getColumnIndex("Id"))));
        anIncident.setIncidentType(
            incidentType_dao.getIncidentType(c.getInt(c.getColumnIndex("IncidentTypeId"))));
        anIncident.setCreatedBy(
            contact_dao.getContact(c.getInt(c.getColumnIndex("CreatedByContactId"))));
        anIncident.setIncidentDate(
            DateTimeHelper.parseFromISO8601(c.getString(c.getColumnIndex("IncidentDate"))));
        anIncident.setDescription((c.getString(c.getColumnIndex("Description"))));
        anIncident.setInitialAction((c.getString(c.getColumnIndex("InitialAction"))));
        anIncident.setReportable(c.getInt(c.getColumnIndex("Reportable")) > 0);
        // anIncident.setNotifyContacts();

        // adding to incident list
        incidents.add(anIncident);
      } while (c.moveToNext());
    }
    c.close();

    return incidents;
  }
コード例 #2
0
  // get single Incident
  public Incident getIncident(long incident_id) {
    Incident anIncident = new Incident();
    db = dbHelper.getReadableDatabase();
    String selectQuery = "SELECT * FROM " + Constants.TABLE_INCIDENT + " WHERE Id = " + incident_id;

    Log.e(LOG, selectQuery);

    // Cursor c = db.rawQuery(selectQuery, null);
    Cursor c =
        db.query(
            Constants.TABLE_INCIDENT, // a. table
            new String[] {
              "Id",
              "IncidentTypeId",
              "CreatedByContactId",
              "IncidentDate",
              "Description",
              "InitialAction",
              "Reportable"
            }, // b. column names
            " Id = ?", // c. selections
            new String[] {String.valueOf(incident_id)}, // d. selections args
            null, // e. group by
            null, // f. having
            null, // g. order by
            null);

    // if (c != null)
    //    c.moveToFirst();
    if (c.moveToFirst()) {
      anIncident.setId(c.getInt(c.getColumnIndex("Id")));
      anIncident.setIncidentType(
          incidentType_dao.getIncidentType(c.getInt(c.getColumnIndex("IncidentTypeId"))));
      anIncident.setCreatedBy(contact_dao.getContact(c.getColumnIndex("CreatedByContactId")));
      anIncident.setIncidentDate(
          DateTimeHelper.parseFromISO8601(c.getString(c.getColumnIndex("IncidentDate"))));
      anIncident.setDescription((c.getString(c.getColumnIndex("Description"))));
      anIncident.setInitialAction((c.getString(c.getColumnIndex("InitialAction"))));
      anIncident.setReportable(c.getInt(c.getColumnIndex("Reportable")) > 0);
      anIncident.setNotifyContacts(getAllNotifyContactsForIncident(incident_id));
      anIncident.setAttachments(getAllAttachmentsForIncident(incident_id));
    }
    c.close();

    return anIncident;
  }