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 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;
  }