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() + ");"); } }
/** * Gera o evento e salva o valor do parâmetros. Se algum parâmetro obrigatório estiver com valor * nulo é gerada uma exceção. * * @param event * @param eventModel * @throws SQLException * @throws Exception */ public void insert(Event event, EventModel eventModel) throws SQLException, Exception { if (this.database == null || !this.database.isOpen()) { try { this.database = (SQLiteDatabase) dataManager.getDatabaseHelper().openDatabaseConnection(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // Criar evento // String sql = "INSERT INTO generated_events // (event_id,entity_id,component_id,time,timeout,event_type) " // + " VALUES (?,?,?,?,?,?);"; ContentValues values = new ContentValues(); values.put("event_id", eventModel.getId()); values.put("entity_id", event.getEntityId()); values.put("component_id", event.getComponentManager().getComponentId()); values.put("time", event.getTime().getTime()); values.put("timeout", event.getTimeout()); values.put("event_type", event.getEventType()); event.setDatabaseId((int) (long) this.database.insertOrThrow("generated_events", null, values)); // adicionar conteúdos dos parâmetros for (Parameter p : eventModel.getParameters()) { if (event.getParameters().get(p.getLabel()) == null && !p.isOptional()) { throw new Exception( "Parameter " + p.getLabel() + " from the event " + eventModel.getDescription() + " id " + eventModel.getId() + " was not found. Such parameter is not optional!"); } else { if (event.getParameters().get(p.getLabel()) != null) { p.setContent( new Content( Content.parseContent(p.getDataType(), event.getParameters().get(p.getLabel())), event.getTime())); this.insertContent(p, event); } } } }