com.quamto.jira.data.design.dao.StepsScenarioDAO Maven / Gradle / Ivy
The newest version!
package com.quamto.jira.data.design.dao;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import com.quamto.core.QException;
import com.quamto.core.QException.ExceptionType;
import com.quamto.core.Result;
import com.quamto.db.DbConnection;
import com.quamto.db.SQLParameter.SQLDataType;
import com.quamto.entity.BaseEntity;
import com.quamto.entity.BaseEntityDAO;
import com.quamto.jira.data.design.entity.StepsScenarioEntity;
import com.quamto.jira.data.design.entity.StepsScenarioEntity.StepsOwners;
public class StepsScenarioDAO extends BaseEntityDAO{
public StepsScenarioDAO(DbConnection conexionBD){
super(conexionBD, "qji_scenarios_steps", "pas_id", StepsScenarioDAO.class);
}
/**
* Gets an object loaded of type StageSteps according to the record identifier
*/
@Override
public StepsScenarioEntity get(Long id) throws QException {
StepsScenarioEntity ent = null;
try {
ent = (StepsScenarioEntity)getEntityLoaded(id);
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-get");
}
return ent;
}
/**
* Returns a list of StageSteps stored in the database
*/
@Override
public List getAll() throws QException {
ArrayList stepsScenarioList = new ArrayList();
try {
ResultSet rs = getResultSet();
while(rs.next()){
stepsScenarioList.add(loadEntityAttributesFromRs(rs));
}
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-getAll");
}
return stepsScenarioList;
}
/**
* Make the assignment of the fields and values of the entity to be used in
* operations insert and update data
*/
@Override
protected void loadQueryParameters(BaseEntity entity)
throws QException {
try {
StepsScenarioEntity ent = (StepsScenarioEntity)entity;
addQueryParameter("pas_id", ent.getID(), SQLDataType.Long_sdt);
addQueryParameter("pas_id_scenario", ent.getIdScenario(), SQLDataType.Long_sdt);
addQueryParameter("pas_description", ent.getDescription(), SQLDataType.String_sdt);
addQueryParameter("pas_input_data", ent.getData(), SQLDataType.String_sdt);
addQueryParameter("pas_order", ent.getOrder(), SQLDataType.AutoIncrement_sdt, false, "pas_id_scenario=" + ent.getIdScenario());
addQueryParameter("pas_owner", ent.getOwner().getInt(), SQLDataType.Integer_sdt);
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-loadQueryParameters");
}
}
/**
* result set load values corresponding to the table of the entity in the object returned
*/
@Override
protected StepsScenarioEntity loadEntityAttributesFromRs(ResultSet rs) throws QException {
StepsScenarioEntity ent = new StepsScenarioEntity();
try {
ent.setID(rs.getLong("pas_id"));
ent.setIdScenario(rs.getLong("pas_id_scenario"));
ent.setDescription(rs.getString("pas_description"));
ent.setData(rs.getString("pas_input_data"));
ent.setOrder(rs.getInt("pas_order"));
ent.setType(StepsOwners.System.getEnumValue(rs.getInt("pas_owner")));
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-loadEntityAttributesFromRs");
}
return ent;
}
/**
* Returns a list of StageSteps stored in the database by idScenario
*
* @param idScenario Scenario identifier
*
* @return A list of StageSteps stored in the database
*/
public List getAllByScenario(long idScenario) throws QException{
ArrayList StepsScenarioList = new ArrayList();
try {
String sql = "SELECT *" +
" FROM " + entityTableName +
" WHERE pas_id_scenario = " + idScenario +
" ORDER BY pas_order ASC";
ResultSet rs = getResultSet(sql);
while(rs.next()){
StepsScenarioList.add(loadEntityAttributesFromRs(rs));
}
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-getAllByScenario");
}
return StepsScenarioList;
}
/**
*
* @param id Deletes the Package with param identifier
*/
public Result deleteStep(Long id){
Result result = new Result();
StepsScenarioEntity stepsScenario = new StepsScenarioEntity();
try {
stepsScenario = get(id);
result = dbOperator.executeQuery("UPDATE qji_scenarios_steps "
+ " SET pas_order = pas_order -1 "
+ " WHERE pas_order > " + stepsScenario.getOrder()
+ " AND pas_id_scenario = " + stepsScenario.getIdScenario());
if(result.isSuccessful()){
result = delete(id);
}
} catch (Exception e) {
result.setException(new QException(e, ExceptionType.OperationFailed_err, subClassName + "-deletePackage"));
}
return result;
};
@Override
public void close() throws Exception {
try {
} catch (Exception e) {
throw e;
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy