com.quamto.jira.data.time.dao.RolesDAO Maven / Gradle / Ivy
The newest version!
package com.quamto.jira.data.time.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.time.entity.RolesEntity;
public class RolesDAO extends BaseEntityDAO {
public RolesDAO(DbConnection dbConnection){
super(dbConnection, "qji_roles", "tro_id", RolesDAO.class);
}
/**
* Get an instance of the entity with data loaded according to Id provided
*/
@Override
public RolesEntity get(Long id) throws QException {
RolesEntity entity = null;
try {
entity = (RolesEntity)getEntityLoaded(id);
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-get");
}
return entity;
}
/**
* Gets list of roles related to the owner in the database
* @param idOwner Owner identifier to be consulted
* @return Return a list of roles related to the owner in the database
*/
public List getAll(Long idOwner) throws QException {
ArrayList listTimeRegistrationTypes = new ArrayList();
try {
ResultSet rs = getResultSet();
String query = "SELECT * "
+ " FROM " + entityTableName
+ " WHERE tro_id_owner = " + idOwner;
rs = dbOperator.getResultSet(query);
while(rs.next()){
listTimeRegistrationTypes.add(loadEntityAttributesFromRs(rs));
}
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-getAll");
}
return listTimeRegistrationTypes;
}
/**
* Make assignments of fields and values of entity to be used in
* insertion and update database operations
*/
@Override
public void loadQueryParameters(BaseEntity entity)
throws QException {
try {
RolesEntity ent = (RolesEntity) entity;
addQueryParameter(entityIdFieldName, ent.getID(), SQLDataType.Long_sdt);
addQueryParameter("tro_name", ent.getName(), SQLDataType.String_sdt);
addQueryParameter("tro_id_owner", ent.getIdOwner(), SQLDataType.Long_sdt);
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-loadQueryParameters");
}
}
/**
* Load the values of ResultSet of table from entity in to returned object.
*/
@Override
public RolesEntity loadEntityAttributesFromRs(ResultSet rs) throws QException {
RolesEntity entity = new RolesEntity();
try {
entity.setID(rs.getLong(entityIdFieldName));
entity.setName(rs.getString("tro_name"));
entity.setIdOwner(rs.getLong("tro_id_owner"));
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-loadEntityAttributesFromRs");
}
return entity;
}
@Override
public void close() throws Exception {
}
@Override
public List> getAll() throws QException {
return null;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy