/* * (non-Javadoc) * @see * FormsOnlineDAO#createInstance(com.silverpeas.formsonline.model * .FormInstance) */ public FormInstance createInstance(FormInstance instance) throws FormsOnlineDatabaseException { Connection con = getConnection(); try (PreparedStatement stmt = con.prepareStatement(QUERY_INSERT_FORMINSTANCE)) { int id = DBUtil.getNextId(FORMS_INSTANCES_TABLENAME, "id"); stmt.setInt(1, id); stmt.setInt(2, instance.getFormId()); stmt.setInt(3, instance.getState()); stmt.setString(4, instance.getCreatorId()); prepareDateStatement(stmt, 5, instance.getCreationDate()); stmt.setString(6, instance.getValidatorId()); prepareDateStatement(stmt, 7, instance.getValidationDate()); stmt.setString(8, instance.getComments()); stmt.setString(9, instance.getComponentInstanceId()); stmt.executeUpdate(); instance.setId(id); return instance; } catch (SQLException se) { throw new FormsOnlineDatabaseException( "FormsOnlineDAOJdbc.createInstance()", SilverpeasException.ERROR, "formsOnline.INSERTING_FORMINSTANCE_FAILED", se); } finally { freeConnection(con); } }
public void updateRequest(FormInstance formInstance) throws FormsOnlineDatabaseException { Connection con = getConnection(); try (PreparedStatement stmt = con.prepareStatement(QUERY_UPDATE_FORM_INSTANCE)) { stmt.setInt(1, formInstance.getFormId()); stmt.setInt(2, formInstance.getState()); stmt.setString(3, formInstance.getCreatorId()); prepareDateStatement(stmt, 4, formInstance.getCreationDate()); stmt.setString(5, formInstance.getValidatorId()); prepareDateStatement(stmt, 6, formInstance.getValidationDate()); stmt.setString(7, formInstance.getComments()); stmt.setString(8, formInstance.getComponentInstanceId()); stmt.setInt(9, formInstance.getIdAsInt()); stmt.executeUpdate(); } catch (SQLException se) { throw new FormsOnlineDatabaseException( "FormsOnlineDAOJdbc.updateFormInstance()", SilverpeasException.ERROR, "formsOnline.UPDATE_FORM_INSTANCE_FAILED", se); } finally { freeConnection(con); } }