com.quamto.jira.data.common.dao.RestrictionDAO Maven / Gradle / Ivy
package com.quamto.jira.data.common.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.db.DbConnection;
import com.quamto.db.SQLParameter.SQLDataType;
import com.quamto.entity.BaseEntity;
import com.quamto.entity.BaseEntityDAO;
import com.quamto.jira.data.common.JEnumerators.PluginEntities;
import com.quamto.jira.data.common.JEnumerators.YesNo;
import com.quamto.jira.data.common.entity.RestrictionEntity;
public class RestrictionDAO extends BaseEntityDAO{
public RestrictionDAO(DbConnection conexionBD){
super(conexionBD, "qji_restrictions", "res_id", RestrictionDAO.class);
}
/**
* Gets an object of type Restrictions charged according to the record identifier
*
* @param id Restrictions identifier requested to be loaded
* @return Object loaded with the information related to the Restrictions requested
*/
@Override
public RestrictionEntity get(Long id) throws QException {
RestrictionEntity ent = null;
try {
ent = (RestrictionEntity)getEntityLoaded(id);
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-get");
}
return ent;
}
@Override
public List getAll() throws QException {
return getAll(null, null);
}
/**
* Gets all the Restrictions that were recorded in the table kong_restrictions
* @return Object List with all records of the table bd
* @throws QException Throws an exception in case of failing to load data
*/
public List getAll(PluginEntities entityType, Long entityId) throws QException {
List restrictionsList = new ArrayList();
try {
ResultSet rs = getResultSet();
while(rs.next()){
restrictionsList.add(loadEntityAttributesFromRs(rs));
}
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-getAll");
}
return restrictionsList;
}
/**
* Make the assignment of the fields and values of the entity
* to be used in operations insert and update data
* @param entity BaseEntidad Object containing the data to be loaded
* @throws QException Throws an exception in case of failing to load the parameters
*/
@Override
protected void loadQueryParameters(BaseEntity entity)
throws QException {
try {
RestrictionEntity ent = (RestrictionEntity)entity;
addQueryParameter("res_id", ent.getID(), SQLDataType.Long_sdt);
addQueryParameter("res_summary", ent.getSummary(), SQLDataType.String_sdt);
addQueryParameter("res_description", ent.getDescription(), SQLDataType.String_sdt);
addQueryParameter("res_mandatory", ent.getMandatory(), SQLDataType.Integer_sdt);
addQueryParameter("res_id_entity", ent.getIdEntity(), SQLDataType.Long_sdt);
addQueryParameter("res_entity_type", ent.getEntityType().getInt(), SQLDataType.Integer_sdt);
addQueryParameter("res_id_restriction_type", ent.getIdType(), SQLDataType.Long_sdt);
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-cargarParametrosSQLEntidad");
}
}
/**
* Load values corresponding to the resultset related to the table entity in the returned object
* @param rs ResultSet object containing the data to be loaded to an object of type Restrictions
* @return Restrictions Object with data loaded
* @throws QException Throws an exception in case of failing to load the parameters
*/
@Override
protected RestrictionEntity loadEntityAttributesFromRs(ResultSet rs) throws QException {
RestrictionEntity ent = new RestrictionEntity();
try {
ent.setID(rs.getLong("res_id"));
ent.setSummary(rs.getString("res_summary"));
ent.setDescription(rs.getString("res_description"));
ent.setMandatory(YesNo.Yes.getEnumValue(rs.getInt("res_mandatory")));
ent.setIdEntity(rs.getLong("res_id_entity"));
ent.setEntityType(PluginEntities.Projects.getEnumValue(rs.getInt("res_entity_type")));
ent.setIdType(rs.getLong("res_id_type"));
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-loadEntityAttributesFromRs");
}
return ent;
}
@Override
public void close() throws Exception {
try {
} catch (Exception e) {
throw e;
}
}
}