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

com.quamto.jira.data.design.dao.ElementIssuesRelationsDAO Maven / Gradle / Ivy

The newest version!
package com.quamto.jira.data.design.dao;

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

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.design.entity.ElementBaseEntity.DesignElementTypes;
import com.quamto.jira.data.design.entity.ElementIssuesRelationsEntity;


  public class ElementIssuesRelationsDAO extends BaseEntityDAO{
    public ElementIssuesRelationsDAO(DbConnection conexionBD){
        super(conexionBD, "qji_design_issues_rel", "rid_id", ElementIssuesRelationsDAO.class);
    }

    /**
     * Get an instance of ElementIssuesRelations with data loaded according to id provided
     */
    @Override
    public ElementIssuesRelationsEntity get(Long id) throws QException {
        ElementIssuesRelationsEntity ent = null;
        try {
            ent = (ElementIssuesRelationsEntity)getEntityLoaded(id);
        } catch (Exception e) {
            throw new QException(e, ExceptionType.LoadData_err, subClassName + "-get");
        }
        return ent;
    }
    
    /**
     * Return a list of ElementIssuesRelations elements stored in the database
     */
    @Override
    public List getAll() throws QException {
        ArrayList listElementIssuesRelations = new ArrayList();
        try {
            ResultSet rs = getResultSet();
            while(rs.next()){
                listElementIssuesRelations.add(loadEntityAttributesFromRs(rs));
            }
        } catch (Exception e) {
            throw new QException(e, ExceptionType.LoadData_err, subClassName + "-getAll");
        }
        return listElementIssuesRelations;
    }

    /**
     * Make assignments of fields and values of entity to be used in 
     * insertion and update database operations
     */
    @Override
    protected void loadQueryParameters(BaseEntity entity)
            throws QException {
        try {
            ElementIssuesRelationsEntity ent = (ElementIssuesRelationsEntity)entity;
            addQueryParameter("rid_id", ent.getID(), SQLDataType.Long_sdt);
            addQueryParameter("rid_id_design_element", ent.getIdDesignElement(), SQLDataType.Long_sdt);
            addQueryParameter("rid_id_issue", ent.getIdIssue(), 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
    protected ElementIssuesRelationsEntity loadEntityAttributesFromRs(ResultSet rs) throws QException {
        ElementIssuesRelationsEntity ent = new ElementIssuesRelationsEntity();
        try { 
        	ent.setID(rs.getLong("rid_id"));
            ent.setIdDesignElement(rs.getLong("rid_id_design_element"));
            ent.setIdIssue(rs.getLong("rid_id_issue"));
            
        } catch (Exception e) {
            throw new QException(e, ExceptionType.LoadData_err, subClassName + "-loadEntityAttributesFromRs");
        }
        return ent;
    }

    /**
     * Return a list of Relations elements stored in the database issue
     * @param issueId Issue identifier
     * @return All element relation by issue
     */
    public List> getAllByIssue(Long issueId) throws QException {
        try {
        	String query = "SELECT"
        			+ " rid_id as id,"
        			+ " rid_id_issue,"
        			+ " rid_id_design_element,"
        			+ " elm_name,"
        			+ " elm_description,"
        			+ " pak_name as packageName,"
        			+   dbOperator.buildSelectCase("elm_element_type", DesignElementTypes.Actor.getMapIntValuesNames(), "elementTypeName") 
        			+ " FROM " + entityTableName
        			+ " INNER JOIN qji_design_elements ON  rid_id_design_element = elm_id"
        			+ " INNER JOIN qji_design_packages ON pak_id = elm_id_package_owner"
        			+ " WHERE rid_id_issue = '" + issueId +"'";
        	
        	List> r = mapArrayFromQuery(query);
        	return r;
        } catch (Exception e) {
            throw new QException(e, ExceptionType.LoadData_err, subClassName + "-getAllByIssue");
        }
    }
    
    @Override
	public void close() throws Exception {
		try {
			
		} catch (Exception e) {
			throw e;
		}
	}

}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy