Example usage for org.hibernate SQLQuery list

List of usage examples for org.hibernate SQLQuery list

Introduction

In this page you can find the example usage for org.hibernate SQLQuery list.

Prototype

List<R> list();

Source Link

Document

Return the query results as a List.

Usage

From source file:com.sysware.customize.hd.investment.baseData.vendor.VendorDaoImpl.java

/**
 * ????//from   w w  w .  j a  va  2  s. c om
 * @param vendorName
 * @return
 */
@SuppressWarnings("unchecked")
public List<Vendor> GetAVendor(String vendorName) {
    String sql = "select t.vendorcode,t.vendorname from t_vendor t where t.vendorname=?";
    SQLQuery query = dao.getHibernateSession().createSQLQuery(sql);
    SetAVendor(query);
    query = (SQLQuery) query.setResultTransformer(Transformers.aliasToBean(Vendor.class));
    query.setParameter(0, vendorName);
    return query.list();
}

From source file:com.sysware.customize.hd.investment.baseData.vendor.VendorDaoImpl.java

/**
 * ? materialGrid.js ?(?)//  w w  w.  ja v a  2 s.co m
 * @param materialVo
 * return gridData
 */
public List<MaterialVo> getAll(MaterialVo materialVo, Pager pager) {
    List<MaterialVo> returnList = new ArrayList<MaterialVo>();
    String sql = "FROM t_material a ,( \n" + "SELECT materialid,COUNT(distinct vendorid) AS materialNums\n"
            + "FROM t_vendor_material\n" + "WHERE EXISTS (SELECT 1 FROM T_VENDOR d\n"
            + "WHERE d.vendorid = vendorid\n" + "AND d.type IN ('1','2')\n"
            + "AND d.evaluation_status = '2') \n" + "GROUP BY materialid) b\n"
            + "WHERE a.materialid = b.materialid(+) \n";

    BigDecimal count = (BigDecimal) materialDao.getHibernateSession().createSQLQuery("select count(1) " + sql)
            .uniqueResult();
    pager.setRecordCount(count.intValue());

    sql = "SELECT  a.materialid,\n" + "a.materialitemname,\n" + "a.desingnation,\n" + "a.materialstandard,\n"
            + "a.techniccondition,\n" + "a.demension,\n"
            + "to_char(nvl(a.warningvalue,0),'FM9999990.000099'),\n" + "a.preserveperiod,\n"
            + "to_char(nvl(a.referenceprice,0),'FM9999990.000099'),\n" + "a.remarks,\n" + "a.parentid,\n"
            + "a.materialitemcode, \n" + "nvl(b.materialNums,0), \n"
            + "(SELECT c.materialtypename FROM t_materialcatalog c WHERE c.materialcatalogid = a.parentid and rownum = 1) \n"
            + sql;

    SQLQuery query = materialDao.getHibernateSession().createSQLQuery(sql);
    if (pager != null) {
        query.setFirstResult(pager.getStart());
        query.setMaxResults(pager.getPageSize());
    }
    //      listSize = query.list().size();//???

    if (count.intValue() > 0) {
        List<Object[]> list = query.list();
        for (Object[] obj : list) {
            MaterialVo vo = new MaterialVo();

            vo.setMaterialid(String.valueOf(obj[0]));
            vo.setMaterialItemName(String.valueOf(obj[1]));
            vo.setDesingnation(String.valueOf(obj[2]));
            vo.setMaterialStandard(String.valueOf(obj[3]));
            vo.setTechnicCondition(String.valueOf(obj[4]));
            vo.setDemension(String.valueOf(obj[5]));
            vo.setWarningValue(Double.parseDouble(String.valueOf(obj[6])));
            vo.setPreservePeriod(String.valueOf(obj[7]));
            vo.setReferencePrice(Double.parseDouble(String.valueOf(obj[8])));
            vo.setRemarks(String.valueOf(obj[9]));
            vo.setParentId(String.valueOf(obj[10]));
            vo.setMaterialitemcode(String.valueOf(obj[11]));
            vo.setMaterialLinkVendorNum(Integer.parseInt(String.valueOf(obj[12])));
            vo.setParentidName(String.valueOf(obj[13]));//(?)

            returnList.add(vo);
        }
    }
    return returnList;
}

From source file:com.sysware.customize.hd.investment.baseData.vendor.VendorDaoImpl.java

/**
 * ? materialGrid.js ??(?)//w  w  w.  j av  a  2s . co m
 * @param materialVo
 * return gridData
 */
public List<MaterialVo> getSelect(MaterialVo materialVo, Pager pager) {
    List<MaterialVo> returnList = new ArrayList<MaterialVo>();

    String materialItemName = StringUtils.isBlank(materialVo.getMaterialItemName()) ? ""
            : materialVo.getMaterialItemName();
    String desingnation = StringUtils.isBlank(materialVo.getDesingnation()) ? "" : materialVo.getDesingnation();
    String materialStandard = StringUtils.isBlank(materialVo.getMaterialStandard()) ? ""
            : materialVo.getMaterialStandard();
    String demension = StringUtils.isBlank(materialVo.getDemension()) ? "" : materialVo.getDemension();
    String technicCondition = StringUtils.isBlank(materialVo.getTechnicCondition()) ? ""
            : materialVo.getTechnicCondition();
    String materialitemcode = StringUtils.isBlank(materialVo.getMaterialitemcode()) ? ""
            : materialVo.getMaterialitemcode();
    String parentidName = StringUtils.isBlank(materialVo.getParentidName()) ? "" : materialVo.getParentidName();
    String materialcatalogName = StringUtils.isBlank(materialVo.getMaterialcatalogName()) ? ""
            : materialVo.getMaterialcatalogName();

    String sql = "FROM t_material a ,( \n" + "SELECT materialid,COUNT(distinct vendorid) AS materialNums\n"
            + "FROM t_vendor_material\n" + "WHERE EXISTS (SELECT 1 FROM T_VENDOR d\n"
            + "WHERE d.vendorid = vendorid\n" + "AND d.type IN ('1','2')\n"
            + "AND d.evaluation_status = '2') \n" + "GROUP BY materialid) b\n"
            + "WHERE a.materialid = b.materialid(+) \n";
    if (!materialItemName.equals("")) {
        sql += " AND a.materialitemname like '%" + materialItemName + "%' \n";
    }
    if (!desingnation.equals("")) {
        sql += " AND a.desingnation LIKE '%" + desingnation + "%' \n";
    }
    if (!materialStandard.equals("")) {
        sql += " AND a.materialstandard LIKE '%" + materialStandard + "%' \n";
    }
    if (!demension.equals("")) {
        sql += " AND a.demension LIKE '%" + demension + "%' \n";
    }
    if (!technicCondition.equals("")) {
        sql += " AND a.techniccondition LIKE '%" + technicCondition + "%' \n";
    }
    if (!materialitemcode.equals("")) {
        sql += " AND a.materialitemcode LIKE '%" + materialitemcode + "%' \n";
    }
    //?
    if (!parentidName.equals("")) {
        //sql += " AND a.materialitemname = '"+materialItemName+"' \n";
        sql += " AND a.parentid IN (SELECT d.materialcatalogid  \n"
                + "                    FROM t_materialcatalog d  \n"
                + "                    WHERE d.materialtypename LIKE '%" + parentidName + "%' ) \n";
    }
    //
    if (!materialcatalogName.equals("")) {
        //sql += " AND a.materialitemname = '"+materialItemName+"' \n";
        sql += " AND a.parentid IN (SELECT d.materialcatalogid  \n"
                + "                    FROM t_materialcatalog d " + "    start with d.materialtypename LIKE '%"
                + materialcatalogName + "%' connect by prior d.materialcatalogid = d.parentid ) ";
    }
    BigDecimal count = (BigDecimal) materialDao.getHibernateSession().createSQLQuery("select count(1) " + sql)
            .uniqueResult();
    pager.setRecordCount(count.intValue());

    sql = "SELECT  a.materialid,\n" + "a.materialitemname,\n" + "a.desingnation,\n" + "a.materialstandard,\n"
            + "a.techniccondition,\n" + "a.demension,\n"
            + "to_char(nvl(a.warningvalue,0),'FM9999990.000099'),\n" + "a.preserveperiod,\n"
            + "to_char(nvl(a.referenceprice,0),'FM9999990.000099'),\n" + "a.remarks,\n" + "a.parentid,\n"
            + "a.materialitemcode, \n" + "nvl(b.materialNums,0), \n"
            + "(SELECT c.materialtypename FROM t_materialcatalog c WHERE c.materialcatalogid = a.parentid and rownum = 1) \n"
            + sql;

    SQLQuery query = materialDao.getHibernateSession().createSQLQuery(sql);
    if (pager != null) {
        query.setFirstResult(pager.getStart());
        query.setMaxResults(pager.getPageSize());
    }

    if (count.intValue() > 0) {
        List<Object[]> list = query.list();
        for (Object[] obj : list) {
            MaterialVo vo = new MaterialVo();

            vo.setMaterialid(String.valueOf(obj[0]));
            vo.setMaterialItemName(String.valueOf(obj[1]));
            vo.setDesingnation(String.valueOf(obj[2]));
            vo.setMaterialStandard(String.valueOf(obj[3]));
            vo.setTechnicCondition(String.valueOf(obj[4]));
            vo.setDemension(String.valueOf(obj[5]));
            vo.setWarningValue(Double.parseDouble(String.valueOf(obj[6])));
            vo.setPreservePeriod(String.valueOf(obj[7]));
            vo.setReferencePrice(Double.parseDouble(String.valueOf(obj[8])));
            vo.setRemarks(String.valueOf(obj[9]));
            vo.setParentId(String.valueOf(obj[10]));
            vo.setMaterialitemcode(String.valueOf(obj[11]));
            vo.setMaterialLinkVendorNum(Integer.parseInt(String.valueOf(obj[12])));
            vo.setParentidName(String.valueOf(obj[13]));//(?)

            returnList.add(vo);
        }
    }
    return returnList;
}

From source file:com.sysware.customize.hd.investment.engineeringProject.executiveManagement.EngineeringProjectExecutiveManagementDaoImp.java

public List<EngineeringProjectExecutiveManagementVo> getCivilManageById(String id) {
    List<EngineeringProjectExecutiveManagementVo> returnList = new ArrayList<EngineeringProjectExecutiveManagementVo>();
    //String fuzzyQueryString = StringUtils.isBlank(vo.getFuzzyQueryString()) ? "" : vo.getFuzzyQueryString();
    //??,/*from   www. ja  v  a 2 s.  c om*/
    String sql = "SELECT distinct\n" + "b.id,\n" + "a.id AS CIVILREGISTID,\n" + "a.projectnum,\n"
            + "a.projectname,\n" + "a.nums,\n" + "a.numsunit,\n" + "b.projectmanagername,\n" + "a.useunit,\n"
            + "b.planfilearrivaltime ,\n" + "b.planfilearrivaldutyperson ,\n" + "b.planlocationfinishtime,\n"
            + "b.planlocationfinishdutyperson,\n" + "b.buildingplanfinishtime ,\n"
            + "b.buildingplanfinishdutyperson ,\n" + "b.licensefinishtime,\n" + "b.licensefinishdutyperson,\n"
            + "b.constructiondesignfinishtime,\n" + "b.constructiondesigndutyperson,\n" + "b.approvaltime ,\n"
            + "b.approvaldutyperson ,\n" + "b.tendertime ,\n" + "b.tenderdutyperson ,\n"
            + "b.contractsignedtime ,\n" + "b.contractsigneddutyperson ,\n" + "b.startworktime ,\n"
            + "b.startworkperson ,\n" + "b.mainacceptancetime ,\n" + "b.mainacceptancedutyperson ,\n"
            + "b.delivertime ,\n" + "b.deliverdutyperson ,\n" + "b.lastupdatetime, \n" + "b.status, \n"
            + "b.usetype \n" + "FROM  TB_CIVILREGIST a , TB_ENGINEERINGEXEMANADETAILS b\n"
            + "WHERE a.id = b.civilregistid(+)\n" + "AND a.approvalstate = '7' \n"
            + "AND (b.usetype IS NULL  OR  b.usetype != '1') \n" +
            //   ???
            "AND EXISTS (SELECT 1 FROM  TB_ENGINEERINGPLANDETAILS c \n"
            + "WHERE c.civilregistid = b.civilregistid \n" + "AND c.status = '?') \n" + "And a.id = '"
            + id + "'";
    /*if(fuzzyQueryString != "" && fuzzyQueryString != "null" && fuzzyQueryString != null){
       sql += "AND a.projectnum LIKE '%"+fuzzyQueryString+"%' OR a.projectname LIKE '%"+fuzzyQueryString+"%' \n";
    }*/

    SQLQuery query = engineeringProjectExecutiveManagementDaoImp.getHibernateSession().createSQLQuery(sql);
    int listSize = query.list().size();//?,

    listSize = query.list().size();//???

    if (listSize > 0) {
        List<Object[]> list = query.list();
        for (Object[] obj : list) {
            EngineeringProjectExecutiveManagementVo thisVo = new EngineeringProjectExecutiveManagementVo();

            thisVo.setId(String.valueOf(obj[0]));
            thisVo.setCivilRegistId(String.valueOf(obj[1]));
            thisVo.setProjectCode(String.valueOf(obj[2]));
            thisVo.setProjectName(String.valueOf(obj[3]));
            thisVo.setNums(String.valueOf(obj[4]));
            thisVo.setNumsunit(String.valueOf(obj[5]));
            thisVo.setProjectManagerName(String.valueOf(obj[6]));
            thisVo.setUseunit(String.valueOf(obj[7]));
            thisVo.setPlanFileArrivalTime((String.valueOf(obj[8])));//2012-08-14
            thisVo.setPlanFileArrivalDutyPerson(String.valueOf(obj[9]));
            thisVo.setPlanLocationFinishTime(String.valueOf(obj[10]));
            thisVo.setPlanLocationFinishDutyPerson(String.valueOf(obj[11]));
            thisVo.setBuildingPlanFinishTime(String.valueOf(obj[12]));
            thisVo.setBuildingPlanFinishDutyPerson(String.valueOf(obj[13]));
            thisVo.setLicenseFinishTime(String.valueOf(obj[14]));
            thisVo.setLicenseFinishDutyPerson(String.valueOf(obj[15]));
            thisVo.setConstructionDesignFinishTime(String.valueOf(obj[16]));
            thisVo.setConstructionDesignDutyPerson(String.valueOf(obj[17]));
            thisVo.setApprovalTime(String.valueOf(obj[18]));
            thisVo.setApprovalDutyPerson(String.valueOf(obj[19]));
            thisVo.setTenderTime(String.valueOf(obj[20]));
            thisVo.setTenderDutyPerson(String.valueOf(obj[21]));
            thisVo.setContractSignedTime(String.valueOf(obj[22]));
            thisVo.setContractSignedDutyPerson(String.valueOf(obj[23]));
            thisVo.setStartWorkTime(String.valueOf(obj[24]));
            thisVo.setStartWorkPerson(String.valueOf(obj[25]));
            thisVo.setMainAcceptanceTime(String.valueOf(obj[26]));
            thisVo.setMainAcceptanceDutyPerson(String.valueOf(obj[27]));
            thisVo.setDeliverTime(String.valueOf(obj[28]));
            thisVo.setDeliverDutyPerson(String.valueOf(obj[29]));
            thisVo.setLastupdateTime(String.valueOf(obj[30]));
            thisVo.setStatus(String.valueOf(obj[31]));//?(1,2,3)
            thisVo.setUseType(String.valueOf(obj[32]));//(1,2?) 
            returnList.add(thisVo);
        }
    }
    return returnList;
}

From source file:com.sysware.customize.hd.investment.engineeringProject.executiveManagement.EngineeringProjectExecutiveManagementDaoImp.java

/**
 * ? ?/*from   ww  w .  ja v  a2s.c om*/
 * @param vo
 * @param pager
 * @return
 */
public List<FixedAssetAcceptanceApplyModelVo> getVendorByGroup(FixedAssetAcceptanceApplyModelVo vo,
        Pager pager) {
    List<FixedAssetAcceptanceApplyModelVo> returnList = new ArrayList<FixedAssetAcceptanceApplyModelVo>();
    //String time = StringUtils.isBlank(vo.getTime()) ? "" : vo.getTime() ;//?????
    String fuzzyQueryString = StringUtils.isBlank(vo.getFuzzyQueryString()) ? "" : vo.getFuzzyQueryString();

    String sql = "SELECT\n" + "a.vendorid,\n" + "a.vendorname,\n" + "a.egal,\n" + "a.phone,\n" + "a.email,\n"
            + "a.zipcode\n" + "FROM t_vendor a \n" + "WHERE 1=1 \n" + "AND EVALUATION_STATUS=2 \n";

    if (fuzzyQueryString != "" && fuzzyQueryString != "null" && fuzzyQueryString != null) {
        sql += "AND a.vendorname LIKE '%" + fuzzyQueryString + "%' or a.egal LIKE '%" + fuzzyQueryString
                + "%' or a.phone LIKE '%" + fuzzyQueryString + "%' \n";
    }

    SQLQuery query = this.getHibernateSession().createSQLQuery(sql);
    int listSize = query.list().size();//?,
    pager.setRecordCount(listSize);//?
    if (pager != null) {
        query.setFirstResult(pager.getStart());
        query.setMaxResults(pager.getPageSize());
    }
    listSize = query.list().size();//???

    if (listSize > 0) {
        List<Object[]> list = query.list();
        for (Object[] obj : list) {
            FixedAssetAcceptanceApplyModelVo thisVo = new FixedAssetAcceptanceApplyModelVo();

            /*thisVo.setEngineeringContractId(String.valueOf(obj[0]));//id
            thisVo.setProjectCode(String.valueOf(obj[1]));//?
            thisVo.setProjectName(String.valueOf(obj[2]));//??
             */
            thisVo.setVendorId(String.valueOf(obj[0]));//id
            thisVo.setContractmanuFacturers(String.valueOf(obj[1]));//??
            thisVo.setContactPerson(String.valueOf(obj[2]));//
            thisVo.setContractmanuFacturersTel(String.valueOf(obj[3]));//?
            returnList.add(thisVo);
        }
    }
    return returnList;

}

From source file:com.sysware.customize.hd.investment.engineeringProject.executiveManagement.EngineeringProjectExecutiveManagementDaoImp.java

/**
 * ajax,?,,?//from  w  ww. j  a v a 2  s .com
 * @param vo
 * @return
 */
public String selectModel(FixedAssetAcceptanceApplyModelVo vo) {
    String returnString = "";
    String civilregistId = StringUtils.isBlank(vo.getCivilregistId()) ? "" : vo.getCivilregistId();
    String sql = "SELECT * FROM TB_FIXEDASSETACCEPTANCEAPPLY  a \n" + "WHERE a.civilregistid = '"
            + civilregistId + "' \n";
    SQLQuery query = engineeringProjectExecutiveManagementDaoImp.getHibernateSession().createSQLQuery(sql);
    int nums = query.list().size();
    if (nums > 0) {//>=1?,
        returnString = "no";
    } else {
        returnString = "yes";
    }

    return returnString;
}

From source file:com.sysware.customize.hd.investment.engineeringProject.implementPlan.EngineeringProjectImplementplanDaoImp.java

/**
 * ?//from w w w .  j a  v a  2  s. c o  m
 * @param vo
 * @return
 */
@SuppressWarnings("unchecked")
public List<EngineeringProjectPlanVo> getImplementPlanById(String id) {
    List<EngineeringProjectPlanVo> returnList = new ArrayList<EngineeringProjectPlanVo>();
    String sql = "SELECT distinct\n" + "b.id,\n" + "a.id AS CIVILREGISTID,\n" + "a.projectnum,\n"
            + "a.projectname,\n" + "a.nums,\n" + "a.numsunit,\n" + "b.projectmanagername,\n" + "a.useunit,\n"
            + "b.planfilearrivaltime ,\n" + "b.planfilearrivaldutyperson ,\n" + "b.planlocationfinishtime,\n"
            + "b.planlocationfinishdutyperson,\n" + "b.buildingplanfinishtime ,\n"
            + "b.buildingplanfinishdutyperson ,\n" + "b.licensefinishtime,\n" + "b.licensefinishdutyperson,\n"
            + "b.constructiondesignfinishtime,\n" + "b.constructiondesigndutyperson,\n" + "b.approvaltime ,\n"
            + "b.approvaldutyperson ,\n" + "b.tendertime ,\n" + "b.tenderdutyperson ,\n"
            + "b.contractsignedtime ,\n" + "b.contractsigneddutyperson ,\n" + "b.startworktime ,\n"
            + "b.startworkperson ,\n" + "b.mainacceptancetime ,\n" + "b.mainacceptancedutyperson ,\n"
            + "b.delivertime ,\n" + "b.deliverdutyperson ,\n" + "b.lastupdatetime, \n" + "b.status, \n"
            + "b.usetype \n" + "FROM  TB_CIVILREGIST a , TB_ENGINEERINGPLANDETAILS b\n"
            + "WHERE a.id = b.civilregistid(+)\n" + "AND a.approvalstate = '7' \n"
            + "AND (b.usetype IS NULL  OR  b.usetype != '2') \n" + "AND a.id = '" + id + "'";

    SQLQuery query = engineeringProjectImplementplanDaoImp.getHibernateSession().createSQLQuery(sql);
    int listSize = query.list().size();//?,

    listSize = query.list().size();//???

    if (listSize > 0) {
        List<Object[]> list = query.list();
        for (Object[] obj : list) {
            EngineeringProjectPlanVo thisVo = new EngineeringProjectPlanVo();

            thisVo.setId(String.valueOf(obj[0]));
            thisVo.setCivilRegistId(String.valueOf(obj[1]));
            thisVo.setProjectCode(String.valueOf(obj[2]));
            thisVo.setProjectName(String.valueOf(obj[3]));
            thisVo.setNums(String.valueOf(obj[4]));
            thisVo.setNumsunit(String.valueOf(obj[5]));
            thisVo.setProjectManagerName(String.valueOf(obj[6]));
            thisVo.setUseunit(String.valueOf(obj[7]));
            thisVo.setPlanFileArrivalTime((String.valueOf(obj[8])));//2012-08-14
            thisVo.setPlanFileArrivalDutyPerson(String.valueOf(obj[9]));
            thisVo.setPlanLocationFinishTime(String.valueOf(obj[10]));
            thisVo.setPlanLocationFinishDutyPerson(String.valueOf(obj[11]));
            thisVo.setBuildingPlanFinishTime(String.valueOf(obj[12]));
            thisVo.setBuildingPlanFinishDutyPerson(String.valueOf(obj[13]));
            thisVo.setLicenseFinishTime(String.valueOf(obj[14]));
            thisVo.setLicenseFinishDutyPerson(String.valueOf(obj[15]));
            thisVo.setConstructionDesignFinishTime(String.valueOf(obj[16]));
            thisVo.setConstructionDesignDutyPerson(String.valueOf(obj[17]));
            thisVo.setApprovalTime(String.valueOf(obj[18]));
            thisVo.setApprovalDutyPerson(String.valueOf(obj[19]));
            thisVo.setTenderTime(String.valueOf(obj[20]));
            thisVo.setTenderDutyPerson(String.valueOf(obj[21]));
            thisVo.setContractSignedTime(String.valueOf(obj[22]));
            thisVo.setContractSignedDutyPerson(String.valueOf(obj[23]));
            thisVo.setStartWorkTime(String.valueOf(obj[24]));
            thisVo.setStartWorkPerson(String.valueOf(obj[25]));
            thisVo.setMainAcceptanceTime(String.valueOf(obj[26]));
            thisVo.setMainAcceptanceDutyPerson(String.valueOf(obj[27]));
            thisVo.setDeliverTime(String.valueOf(obj[28]));
            thisVo.setDeliverDutyPerson(String.valueOf(obj[29]));
            thisVo.setLastupdateTime(String.valueOf(obj[30]));
            thisVo.setStatus(String.valueOf(obj[31]));//?(1,2,3)
            thisVo.setUseType(String.valueOf(obj[32]));//(1,2?) 
            returnList.add(thisVo);
        }
    }
    return returnList;
}

From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java

License:Apache License

@SuppressWarnings({ "unchecked" })
public List<Modification> getModificationsForPipelineRange(final String pipelineName, final Integer fromCounter,
        final Integer toCounter) {
    return (List<Modification>) getHibernateTemplate().execute((HibernateCallback) session -> {
        final List<Long> fromInclusiveModificationList = fromInclusiveModificationsForPipelineRange(session,
                pipelineName, fromCounter, toCounter);

        final Set<Long> fromModifications = new TreeSet<>(
                fromInclusiveModificationsForPipelineRange(session, pipelineName, fromCounter, fromCounter));

        final Set<Long> fromExclusiveModificationList = new HashSet<>();

        for (Long modification : fromInclusiveModificationList) {
            if (fromModifications.contains(modification)) {
                fromModifications.remove(modification);
            } else {
                fromExclusiveModificationList.add(modification);
            }/*from   w  w  w.j a  v a2s .c o m*/
        }

        SQLQuery query = session.createSQLQuery(
                "SELECT * FROM modifications WHERE id IN (:ids) ORDER BY materialId ASC, id DESC");
        query.addEntity(Modification.class);
        query.setParameterList("ids", fromExclusiveModificationList.isEmpty() ? fromInclusiveModificationList
                : fromExclusiveModificationList);
        return query.list();
    });
}

From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java

License:Apache License

private List<Long> fromInclusiveModificationsForPipelineRange(Session session, String pipelineName,
        Integer fromCounter, Integer toCounter) {
    String pipelineIdsSql = queryExtensions.queryFromInclusiveModificationsForPipelineRange(pipelineName,
            fromCounter, toCounter);/*from  w w  w. j  a  v a  2  s.  co  m*/
    SQLQuery pipelineIdsQuery = session.createSQLQuery(pipelineIdsSql);
    final List ids = pipelineIdsQuery.list();
    if (ids.isEmpty()) {
        return new ArrayList<>();
    }

    String minMaxQuery = " SELECT mods1.materialId as materialId, min(mods1.id) as min, max(mods1.id) as max"
            + " FROM modifications mods1 "
            + "     INNER JOIN pipelineMaterialRevisions pmr ON (mods1.id >= pmr.actualFromRevisionId AND mods1.id <= pmr.toRevisionId) AND mods1.materialId = pmr.materialId "
            + " WHERE pmr.pipelineId IN (:ids) " + " GROUP BY mods1.materialId";

    SQLQuery query = session
            .createSQLQuery("SELECT mods.id " + " FROM modifications mods" + "     INNER JOIN (" + minMaxQuery
                    + ") as edges on edges.materialId = mods.materialId and mods.id >= min and mods.id <= max"
                    + " ORDER BY mods.materialId ASC, mods.id DESC");
    query.addScalar("id", new LongType());
    query.setParameterList("ids", ids);

    return query.list();
}

From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java

License:Apache License

private Map<PipelineId, Set<Long>> relevantToLookedUpDependencyMap(Session session, List<Long> pipelineIds) {
    final int LOOKED_UP_PIPELINE_ID = 2;
    final int RELEVANT_PIPELINE_ID = 0;
    final int RELEVANT_PIPELINE_NAME = 1;

    String pipelineIdsSql = queryExtensions.queryRelevantToLookedUpDependencyMap(pipelineIds);
    SQLQuery pipelineIdsQuery = session.createSQLQuery(pipelineIdsSql);
    pipelineIdsQuery.addScalar("id", new LongType());
    pipelineIdsQuery.addScalar("name", new StringType());
    pipelineIdsQuery.addScalar("lookedUpId", new LongType());
    final List<Object[]> ids = pipelineIdsQuery.list();

    Map<Long, List<PipelineId>> lookedUpToParentMap = new HashMap<>();
    CollectionUtil.CollectionValueMap<Long, PipelineId> lookedUpToRelevantMap = CollectionUtil
            .collectionValMap(lookedUpToParentMap, new CollectionUtil.ArrayList<>());
    for (Object[] relevantAndLookedUpId : ids) {
        lookedUpToRelevantMap.put((Long) relevantAndLookedUpId[LOOKED_UP_PIPELINE_ID],
                new PipelineId((String) relevantAndLookedUpId[RELEVANT_PIPELINE_NAME],
                        (Long) relevantAndLookedUpId[RELEVANT_PIPELINE_ID]));
    }//from  w w  w .  j av a2  s  . c  o m
    return CollectionUtil.reverse(lookedUpToParentMap);
}