/* * (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 FormDetail createForm(FormDetail formDetail) throws FormsOnlineDatabaseException { Connection con = getConnection(); try (PreparedStatement stmt = con.prepareStatement(QUERY_INSERT_FORM)) { int id = DBUtil.getNextId(FORMS_TABLENAME, "id"); stmt.setInt(1, id); stmt.setString(2, formDetail.getXmlFormName()); stmt.setString(3, formDetail.getName()); stmt.setString(4, formDetail.getDescription()); stmt.setString(5, formDetail.getTitle()); stmt.setString(6, formDetail.getCreatorId()); prepareDateStatement(stmt, 7, formDetail.getCreationDate()); stmt.setInt(8, formDetail.getState()); stmt.setInt(9, (formDetail.isAlreadyUsed()) ? 1 : 0); stmt.setString(10, formDetail.getInstanceId()); stmt.executeUpdate(); formDetail.setId(id); return formDetail; } catch (SQLException se) { throw new FormsOnlineDatabaseException( "FormsOnlineDAOJdbc.createForm()", SilverpeasException.ERROR, "formsOnline.INSERTING_FORM_FAILED", se); } finally { freeConnection(con); } }