All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.quamto.jira.data.time.dao.UserCostsHistoryDAO 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 com.quamto.jira.data.time.entity.UserCostsHistoryEntity;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by QUAMTO-DEV3 on 28/07/2017.
 * [email protected]
 */
public class UserCostsHistoryDAO extends BaseEntityDAO {

    public UserCostsHistoryDAO(DbConnection dbConnection){
        super(dbConnection, "qji_user_costs_history", "uch_id", UserCostsHistoryDAO.class);
    }

    /**
     * Get an instance of the entity with data loaded according to Id provided
     */
    @Override
    public UserCostsHistoryEntity get(Long id) throws QException {
        UserCostsHistoryEntity entity = null;
        try {
            entity = (UserCostsHistoryEntity)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 {
            UserCostsHistoryEntity ent = (UserCostsHistoryEntity) entity;
            addQueryParameter(entityIdFieldName, ent.getID(), SQLParameter.SQLDataType.Long_sdt);
            addQueryParameter("uch_id_user", ent.getIdUser(), SQLParameter.SQLDataType.String_sdt);
            addQueryParameter("uch_id_owner", ent.getIdOwner(), SQLParameter.SQLDataType.Long_sdt);
            addQueryParameter("uch_hour_cost", ent.getHourCost(), SQLParameter.SQLDataType.Decimal_sdt);
            addQueryParameter("uch_from_date", ent.getFromDate(), SQLParameter.SQLDataType.DateTime_sdt);
            addQueryParameter("uch_until_date", ent.getUntilDate(), 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 UserCostsHistoryEntity loadEntityAttributesFromRs(ResultSet rs) throws QException {
        UserCostsHistoryEntity entity = new UserCostsHistoryEntity();
        try {
            entity.setID(rs.getLong(entityIdFieldName));
            entity.setIdUser(rs.getString("uch_id_user"));
            entity.setIdOwner(rs.getLong("uch_id_owner"));
            entity.setHourCost(rs.getDouble("uch_hour_cost"));
            entity.setFromDate(rs.getTimestamp("uch_from_date"));
            entity.setUntilDate(rs.getTimestamp("uch_until_date"));

        } 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  users with costs to the owner in the database
     */
    public List getAllUsersCostsHistory(Long idOwner) throws QException {
        ArrayList listUsersWithCostsHistory = new ArrayList();
        try {
            ResultSet rs = getResultSet();

            String query = "SELECT * "
                    + " FROM " + entityTableName
                    + " WHERE uch_id_owner = " + idOwner
                    + " ORDER BY uch_from_date";

            rs = dbOperator.getResultSet(query);

            while(rs.next()){
                listUsersWithCostsHistory.add(loadEntityAttributesFromRs(rs));
            }
        } catch (Exception e) {
            throw new QException(e, QException.ExceptionType.LoadData_err, subClassName + "-getAllUsersCostsHistory");
        }
        return listUsersWithCostsHistory;
    }

    @Override
    public void close() throws Exception {

    }

    @Override
    public List getAll() throws QException {
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy