public EventModel get(int modelId, int entityModelId, int componentId) throws SQLException {
    if (this.database == null || !this.database.isOpen()) {
      try {
        this.database = (SQLiteDatabase) dataManager.getDatabaseHelper().openDatabaseConnection();
      } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    EventModel event = null;
    String sql =
        "SELECT events.id as event_id, events.model_id, events.description as event_description, synchronous, \n"
            + "                implementation_type_id, implementation_types.description as implementation_description \n"
            + "                FROM events, implementation_types, entities, components \n"
            + "                WHERE events.model_id = ? AND entities.model_id = ? AND components.id = ? "
            + "                AND implementation_type_id = implementation_types.id AND entity_id = entities.id\n"
            + "                AND component_id = components.id;";

    Cursor cursor =
        this.database.rawQuery(
            sql,
            new String[] {
              String.valueOf(modelId), String.valueOf(entityModelId), String.valueOf(componentId)
            });

    if (cursor.moveToNext()) {
      event = new EventModel();
      event.setId(cursor.getInt(cursor.getColumnIndex("event_id")));
      event.setDescription(cursor.getString(cursor.getColumnIndex("event_description")));
      event.setSynchronous(cursor.getInt(cursor.getColumnIndex("synchronous")) > 0);
      event.setModelId(cursor.getInt(cursor.getColumnIndex("model_id")));
      event.setImplementation(
          new Implementation(
              cursor.getInt(cursor.getColumnIndex("implementation_type_id")),
              cursor.getString(cursor.getColumnIndex("implementation_description"))));
      event.setTargets(this.getEventTargets(event));
      event.setParameters(this.getEventParameters(event));
    }
    if (!cursor.isClosed()) {
      cursor.close();
    }
    return event;
  }
  public void insert(EventModel event) throws SQLException {
    if (this.database == null || !this.database.isOpen()) {
      try {
        this.database = (SQLiteDatabase) dataManager.getDatabaseHelper().openDatabaseConnection();
      } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    // String sql = "INSERT INTO events
    // (model_id,description,synchronous,implementation_type_id,entity_id) "
    //        + " VALUES (?,?,?,?,?);";
    event.setModelId(event.getId());
    ContentValues values = new ContentValues();
    values.put("model_id", event.getId());
    values.put("description", event.getDescription());
    values.put("synchronous", event.isSynchronous());
    values.put("implementation_type_id", event.getImplementation().getId());
    values.put("entity_id", event.getEntity().getId());

    event.setId((int) (long) this.database.insertOrThrow("events", null, values));

    if (DeveloperSettings.SHOW_DAO_SQL) {
      Log.d(
          "SQL_DEBUG",
          "INSERT INTO events (id,model_id,description,synchronous,implementation_type_id,entity_id) "
              + " VALUES ("
              + event.getId()
              + ","
              + event.getModelId()
              + ",'"
              + event.getDescription()
              + "',"
              + event.isSynchronous()
              + ","
              + event.getImplementation().getId()
              + ","
              + event.getEntity().getId()
              + ");");
    }
  }
  public List<EventModel> getEntityEventModels(Entity entity) throws SQLException {
    if (this.database == null || !this.database.isOpen()) {
      try {
        this.database = (SQLiteDatabase) dataManager.getDatabaseHelper().openDatabaseConnection();
      } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    List<EventModel> events = new ArrayList();
    EventModel event = null;
    String sql =
        "SELECT events.id as event_id, model_id, events.description as event_description, synchronous, "
            + " implementation_type_id, implementation_types.description as implementation_description "
            + " FROM events, implementation_types\n"
            + " WHERE entity_id = ? AND implementation_type_id = implementation_types.id;";

    Cursor cursor = this.database.rawQuery(sql, new String[] {String.valueOf(entity.getId())});

    while (cursor.moveToNext()) {
      event = new EventModel();
      event.setId(cursor.getInt(cursor.getColumnIndex("event_id")));
      event.setDescription(cursor.getString(cursor.getColumnIndex("event_description")));
      event.setSynchronous(cursor.getInt(cursor.getColumnIndex("synchronous")) > 0);
      event.setModelId(cursor.getInt(cursor.getColumnIndex("model_id")));
      event.setEntity(entity);
      event.setImplementation(
          new Implementation(
              cursor.getInt(cursor.getColumnIndex("implementation_type_id")),
              cursor.getString(cursor.getColumnIndex("implementation_description"))));
      event.setTargets(this.getEventTargets(event));
      event.setParameters(this.getEventParameters(event));
      events.add(event);
    }
    if (!cursor.isClosed()) {
      cursor.close();
    }
    return events;
  }