com.quamto.jira.data.common.dao.CommentDAO Maven / Gradle / Ivy
The newest version!
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.entity.CommentEntity;
public class CommentDAO extends BaseEntityDAO{
/**
* Initializes the class
* @param connectionDB ConexionBD object type used for interaction with the BD
*/
public CommentDAO(DbConnection connectionDB){
super(connectionDB, "qji_comments", "com_id", CommentDAO.class);
}
/**
* Gets an object of type CommentEntity charged according to the record identifier
*
* @param id CommentEntity identifier requested to be loaded
* @return Object loaded with the information related to the CommentEntity requested
*/
@Override
public CommentEntity get(Long id) throws QException {
CommentEntity ent = null;
try {
ent = (CommentEntity)getEntityLoaded(id);
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-get");
}
return ent;
}
/**
* Gets all the comments that were recorded
* @return Object List with all records of the table bd
* @throws QException Throws an exception in case of failing to load data
*/
@Override
public List getAll() throws QException {
ArrayList commentsList = new ArrayList();
try {
ResultSet rs = getResultSet();
while(rs.next()){
commentsList.add(loadEntityAttributesFromRs(rs));
}
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-getAll");
}
return commentsList;
}
/**
* Gets a list of comments related to the given entity
* @return CommentEntity List of the defined entity
* @throws QException Throws an exception in case of failing to load data
*/
public List getAll(Long idEntity, PluginEntities entityType) throws QException{
List commentsEntity = new ArrayList();
try {
ResultSet rs = getResultSet("SELECT *" +
" FROM " + entityTableName +
" WHERE com_id_entity = " + idEntity +
" AND com_entity_type = " + entityType.getInt().toString());
while(rs.next()){
commentsEntity.add(loadEntityAttributesFromRs(rs));
}
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-getAll");
}
return commentsEntity;
}
/**
* 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 {
CommentEntity ent = (CommentEntity)entity;
addQueryParameter(entityIdFieldName, ent.getID(), SQLDataType.Long_sdt);
addQueryParameter("com_id_user", ent.getIdUser(), SQLDataType.String_sdt);
addQueryParameter("com_id_entity", ent.getIdEntity(), SQLDataType.Long_sdt);
addQueryParameter("com_entity_type", ent.getEntityType().getInt(), SQLDataType.Integer_sdt);
addQueryParameter("com_comment_date", ent.getCommentDate(), SQLDataType.DateTime_sdt);
addQueryParameter("com_comment", ent.getComment(), SQLDataType.String_sdt);
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-loadQueryParameters");
}
}
/**
* 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 CommentEntity
* @return CommentEntity Object with data loaded
* @throws QException Throws an exception in case of failing to load the parameters
*/
@Override
protected CommentEntity loadEntityAttributesFromRs(ResultSet rs) throws QException {
CommentEntity ent = new CommentEntity();
try {
ent.setID(rs.getLong(entityIdFieldName));
ent.setIdUser(rs.getString("com_id_user"));
ent.setIdEntity(rs.getLong("com_id_entity"));
ent.setEntityType(PluginEntities.Projects.getEnumValue(rs.getInt("com_entity_type")));
ent.setCommentDate(rs.getTimestamp("com_comment_date"));
ent.setComment(rs.getString("com_comment"));
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-loadEntityAttributesFromRs");
}
return ent;
}
@Override
public void close() throws Exception {
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy