com.quamto.jira.data.time.dao.UserConfigurationDAO Maven / Gradle / Ivy
The newest version!
package com.quamto.jira.data.time.dao;
import com.quamto.core.QException;
import com.quamto.db.DbConnection;
import com.quamto.db.SQLParameter;
import com.quamto.entity.BaseEntity;
import com.quamto.entity.BaseEntityDAO;
import com.quamto.jira.data.time.entity.UserConfigurationEntity;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by QUAMTO-DEV3 on 28/07/2017.
* [email protected]
*/
public class UserConfigurationDAO extends BaseEntityDAO{
public UserConfigurationDAO(DbConnection dbConnection){
super( dbConnection, "qji_user_configuration", "ucf_id", UserConfigurationDAO.class );
}
/**
* Get an instance of the entity with data loaded according to Id provided
*/
@Override
public UserConfigurationEntity get(Long id) throws QException {
UserConfigurationEntity entity = null;
try {
entity = (UserConfigurationEntity)getEntityLoaded(id);
} catch (Exception e) {
throw new QException(e, QException.ExceptionType.LoadData_err, subClassName + "-get");
}
return entity;
}
/**
* 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 {
UserConfigurationEntity ent = (UserConfigurationEntity) entity;
addQueryParameter(entityIdFieldName, ent.getID(), SQLParameter.SQLDataType.Long_sdt);
addQueryParameter("ucf_id_user", ent.getIdUser(), SQLParameter.SQLDataType.String_sdt);
addQueryParameter("ucf_id_owner", ent.getIdOwner(), SQLParameter.SQLDataType.Long_sdt);
addQueryParameter("ucf_hour_cost", ent.getHourCost(), SQLParameter.SQLDataType.Decimal_sdt);
addQueryParameter("ucf_created_from", ent.getCreatedFrom(), SQLParameter.SQLDataType.DateTime_sdt);
} catch (Exception e) {
throw new QException(e, QException.ExceptionType.LoadData_err, subClassName + "-loadQueryParameters");
}
}
/**
* Load the values of ResultSet of table from entity in to returned object.
*/
@Override
public UserConfigurationEntity loadEntityAttributesFromRs(ResultSet rs) throws QException {
UserConfigurationEntity entity = new UserConfigurationEntity();
try {
entity.setID(rs.getLong(entityIdFieldName));
entity.setIdUser(rs.getString("ucf_id_user"));
entity.setIdOwner(rs.getLong("ucf_id_owner"));
entity.setHourCost(rs.getDouble("ucf_hour_cost"));
entity.setCreatedFrom(rs.getTimestamp("ucf_created_from"));
} catch (Exception e) {
throw new QException(e, QException.ExceptionType.LoadData_err, subClassName + "-loadEntityAttributesFromRs");
}
return entity;
}
/**
* Gets list of users with costs
* @return Return a list of the costs
*/
public List getAllUsersCosts(Long idOwner) throws QException {
ArrayList listUsersWithCosts = new ArrayList();
try {
ResultSet rs = getResultSet();
String query = "SELECT * "
+ " FROM " + entityTableName
+ " WHERE ucf_id_owner = " + idOwner;
rs = dbOperator.getResultSet(query);
while(rs.next()){
listUsersWithCosts.add(loadEntityAttributesFromRs(rs));
}
} catch (Exception e) {
throw new QException(e, QException.ExceptionType.LoadData_err, subClassName + "-getAllUsersCosts");
}
return listUsersWithCosts;
}
/**
* Gets configuration cost the user
* @return Return configuration cost the user to the owner in the database
*/
public UserConfigurationEntity getCostByOwnerUser(String idUser, Long idOwner) throws QException {
UserConfigurationEntity entity = null;
try {
ResultSet rs = getResultSet();
String query = "SELECT * "
+ " FROM " + entityTableName
+ " WHERE ucf_id_user = '" +idUser +"'"
+ " AND ucf_id_owner = " +idOwner;
rs = dbOperator.getResultSet(query);
while(rs.next()){
entity = loadEntityAttributesFromRs(rs);
}
} catch (Exception e) {
throw new QException(e, QException.ExceptionType.LoadData_err, subClassName + "-getCostByOwnerUser");
}
return entity;
}
/**
* Gets list of costs of the issue
* @return Return a list cost of the issue
*/
public List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy