Java 类org.hibernate.criterion.ProjectionList 实例源码

项目:Equella    文件:BasicItemSerializerProvider.java   
@Override
public void prepareItemQuery(ItemSerializerState state)
{
    final DetachedCriteria criteria = state.getItemQuery();
    final ProjectionList projection = state.getItemProjection();

    if( state.hasCategory(ItemSerializerService.CATEGORY_BASIC) )
    {
        projection.add(Projections.property("name.id"), NAME_ALIAS);
        projection.add(Projections.property("description.id"), DESC_ALIAS);
    }

    if( state.hasCategory(ItemSerializerService.CATEGORY_METADATA) )
    {
        criteria.createAlias("itemXml", "itemXml");
        projection.add(Projections.property("itemXml.xml"), METADATA_ALIAS);
    }
}
项目:sjk    文件:AppDaoImpl.java   
@Override
public List<App> getAppsOfDropMarket(Session session, String marketName, Integer currentPage, Integer pageSize) {
    ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("pkname"));
    proList.add(Projections.property("signatureSha1"));
    Criteria cri = session.createCriteria(App.class);
    cri.setProjection(proList);
    cri.setMaxResults(pageSize);
    cri.setFirstResult(HibernateHelper.firstResult(currentPage, pageSize));
    List<Object[]> list = HibernateHelper.list(cri);
    List<App> apps = null;
    if (list != null) {
        apps = new ArrayList<App>(list.size());
        for (Object[] obj : list) {
            App e = new App();
            e.setPkname((String) obj[0]);
            e.setSignatureSha1((String) obj[1]);
            apps.add(e);
        }
        list.clear();
    }
    return apps;
}
项目:sjk    文件:AppDaoImpl.java   
@Override
public List<App> getAppsOfDropMarket(Session session, String marketName, Integer currentPage, Integer pageSize) {
    ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("pkname"));
    proList.add(Projections.property("signatureSha1"));
    Criteria cri = session.createCriteria(App.class);
    cri.setProjection(proList);
    cri.setMaxResults(pageSize);
    cri.setFirstResult(HibernateHelper.firstResult(currentPage, pageSize));
    List<Object[]> list = HibernateHelper.list(cri);
    List<App> apps = null;
    if (list != null) {
        apps = new ArrayList<App>(list.size());
        for (Object[] obj : list) {
            App e = new App();
            e.setPkname((String) obj[0]);
            e.setSignatureSha1((String) obj[1]);
            apps.add(e);
        }
        list.clear();
    }
    return apps;
}
项目:sjk    文件:MarketDaoImpl.java   
@Override
public List<Market> listMarketRank() {
    ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("marketName"));
    proList.add(Projections.property("rank"));
    Criteria cri = getSession().createCriteria(Market.class);
    cri.setProjection(proList);
    List<Object[]> list = HibernateHelper.list(cri);
    List<Market> markets = null;
    if (list != null && !list.isEmpty()) {
        markets = new ArrayList<Market>(list.size());
        for (Object[] obj : list) {
            Market m = new Market();
            m.setMarketName((String) obj[0]);
            m.setRank((Integer) obj[1]);
            markets.add(m);
        }
    }
    return markets;
}
项目:ctsms    文件:CriteriaUtil.java   
public static List listDistinctRoot(Criteria criteria,Object dao,String... fields) throws Exception {
    if (dao != null && criteria != null) {
        criteria.setProjection(null);
        criteria.setResultTransformer(Criteria.ROOT_ENTITY);
        Method loadMethod = CoreUtil.getDaoLoadMethod(dao);
        ProjectionList projectionList = Projections.projectionList().add(Projections.id());
        boolean cast = false;
        if (fields != null && fields.length > 0) {
            for (int i = 0; i< fields.length; i++) {
                projectionList.add(Projections.property(fields[i]));
            }
            cast = true;
        }
        List items = criteria.setProjection(Projections.distinct(projectionList)).list();
        Iterator it = items.iterator();
        ArrayList result = new ArrayList(items.size());
        while (it.hasNext()) {
            result.add(loadMethod.invoke(dao, cast ? ((Object[]) it.next())[0] : it.next()));
        }
        return result;
    }
    return null;
}
项目:ctsms    文件:ECRFFieldStatusEntryDaoImpl.java   
private static DetachedCriteria createEcrfFieldStatusEntryDetachedCriteriaMaxId(org.hibernate.Criteria ecrfFieldStatusEntryCriteria, org.hibernate.Criteria ecrfFieldCriteria,
        org.hibernate.Criteria probandListEntryCriteria,
        ECRFFieldStatusQueue queue, Long probandListEntryId, Long ecrfFieldId) {
    DetachedCriteria subQuery = createEcrfFieldStatusEntryDetachedCriteria(ecrfFieldStatusEntryCriteria, ecrfFieldCriteria, probandListEntryCriteria, probandListEntryId,
            ecrfFieldId);
    if (queue != null) {
        subQuery.add(Restrictions.eq("queue", queue));
        subQuery.setProjection(Projections.max("id"));
    } else {
        ProjectionList proj = Projections.projectionList();
        proj.add(Projections.sqlGroupProjection(
                "max({alias}.id) as maxId",
                "{alias}.queue",
                new String[] { "maxId" },
                new org.hibernate.type.Type[] { Hibernate.LONG }));
        subQuery.setProjection(proj);
    }

    return subQuery;
}
项目:coordinated-entry    文件:SectionScoreDaoImplV3.java   
public List<ClientSurveyScore> calculateClientSurveyScore(Integer startIndex,Integer maxItems,String projectGroupCode) {
    DetachedCriteria criteria = DetachedCriteria.forClass(SectionScoreEntity.class);
    criteria.createAlias("surveyEntity", "surveyEntity");

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.sum("sectionScore"),"surveyScore");
    projectionList.add(Projections.property("surveyEntity.id"),"surveyId");
    projectionList.add(Projections.property("clientId"),"clientId");
    projectionList.add(Projections.property("surveyEntity.projectGroupCode"),"projectGroupCode");
    projectionList.add(Projections.property("surveyEntity.createdAt"),"surveyDate");
    projectionList.add(Projections.groupProperty("surveyEntity.id"));
    projectionList.add(Projections.groupProperty("clientId"));
    projectionList.add(Projections.groupProperty("surveyEntity.tagValue"),"surveyTagValue");
    criteria.setProjection(projectionList);
    criteria.add(Restrictions.eq("surveyEntity.projectGroupCode",projectGroupCode));
    criteria.setResultTransformer(Transformers.aliasToBean(ClientSurveyScore.class));
    return (List<ClientSurveyScore>) findByCriteria(criteria,startIndex,maxItems);
}
项目:coordinated-entry    文件:SectionScoreDaoImpl.java   
public List<ClientSurveyScore> calculateClientSurveyScore(Integer startIndex,Integer maxItems,String projectGroupCode) {
    DetachedCriteria criteria = DetachedCriteria.forClass(SectionScoreEntity.class);
    criteria.createAlias("surveyEntity", "surveyEntity");

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.sum("sectionScore"),"surveyScore");
    projectionList.add(Projections.property("surveyEntity.id"),"surveyId");
    projectionList.add(Projections.property("clientId"),"clientId");
    projectionList.add(Projections.property("surveyEntity.projectGroupCode"),"projectGroupCode");
    projectionList.add(Projections.property("surveyEntity.createdAt"),"surveyDate");
    projectionList.add(Projections.groupProperty("surveyEntity.id"));
    projectionList.add(Projections.groupProperty("clientId"));
    projectionList.add(Projections.groupProperty("surveyEntity.tagValue"),"surveyTagValue");
    criteria.setProjection(projectionList);
    criteria.add(Restrictions.eq("surveyEntity.projectGroupCode",projectGroupCode));
    criteria.setResultTransformer(Transformers.aliasToBean(ClientSurveyScore.class));
    return (List<ClientSurveyScore>) findByCriteria(criteria,startIndex,maxItems);
}
项目:ehr    文件:PatientDAO.java   
public Encounter findCurrentEncounterByPatientId(int patientId) throws Exception {
  Patient patient = findPatientById(patientId);
  Session session = this.getSession();
  Criteria crit = session.createCriteria(Encounter.class);
  crit.add(Restrictions.eq("patient", patient));
  ProjectionList proj = Projections.projectionList();
  proj = proj.add(Projections.max("id"));
  crit = crit.setProjection(proj);
  Integer id = (Integer)crit.uniqueResult();
  crit = session.createCriteria(Encounter.class);
  crit.add(Restrictions.eq("id", id));
  Encounter encounter = (Encounter)crit.uniqueResult();
  if (encounter != null) {
    encounter.getSupp().setEncounterQuestionList(getEncounterQuestionsByEncounter(encounter.getId()));
    patient.getHist().setPatientMedicationList(getPatientMedicationsByPatient(patient.getId()));
    encounter.setDxCodes(getDxCodes(encounter.getId()));
    encounter.setTxCodes(getTxCodes(encounter.getId()));
  } 
  return encounter;
}
项目:shogun2    文件:GenericHibernateDao.java   
/**
 * Gets the results, that match a variable number of passed criterions, but return a
 * stripped version of the entities, where only the fieldNames in <code>restrictFieldNames</code>
 * have their actual values set.
 *
 * You can call this with <code>restrictFieldNames</code> = <code>null</code> to get the full
 * entities back.
 *
 * You can call this method without criterion arguments to find all entities (stripped down to
 * the <code>restrictFieldNames</code>).
 *
 * If this is called as <code>findByCriteriaRestricted(null)</code> the return value equals the
 * return value of <code>findByCriteria()</code>.
 *
 * @param restrictFieldNames
 * @param criterion
 * @return
 * @throws HibernateException
 */
@SuppressWarnings("unchecked")
public List<E> findByCriteriaRestricted(List<String> restrictFieldNames, Criterion... criterion) throws HibernateException {
    LOG.trace("Finding instances of " + entityClass.getSimpleName()
            + " based on " + criterion.length + " criteria");

    Criteria criteria = createDistinctRootEntityCriteria(criterion);

    if (restrictFieldNames != null){
        ProjectionList projectionList = Projections.projectionList();
        for (String restrictFieldName : restrictFieldNames) {
            PropertyProjection pp = Projections.property(restrictFieldName);
            projectionList.add(pp, restrictFieldName);
        }
        criteria.setProjection(projectionList);
        criteria.setResultTransformer(
            Transformers.aliasToBean(entityClass)
        );
    }

    return criteria.list();
}
项目:hypersocket-framework    文件:AbstractRepositoryImpl.java   
@Override
@Transactional(readOnly = true)
public List<?> sum(Class<?> clz, String groupBy, Sort order, CriteriaConfiguration... configs) {

    Criteria criteria = createCriteria(clz);

    for (CriteriaConfiguration c : configs) {
        c.configure(criteria);
    }

    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty(groupBy));
    projectionList.add(Projections.sum(groupBy), "sum");
    criteria.setProjection(projectionList);

    if(order.equals(Sort.DESC)) {
        criteria.addOrder(Order.desc("sum"));
    } else {
        criteria.addOrder(Order.asc("sum"));
    }

    return criteria.list();
}
项目:further-open-core    文件:HibernateUtil.java   
/**
 * @deprecated This method does not work well due to Hibernate bug HHH-817, nor does
 *             AliasToBeanResultTransformer handle multi-level property values.
 *             Therefore it should not be used.
 *
 * @param propertyNames
 * @param alias
 * @param aliasPath
 * @param domainClass
 * @return
 *
 * @see http://opensource.atlassian.com/projects/hibernate/browse/HHH-817
 */
@Deprecated
public static Projection createAliasedProjectionList(final String[] propertyNames,
        final String alias, final String aliasPath, final Class<?> domainClass)
{
    final ProjectionList projectionList = Projections.projectionList();
    for (final String propertyName : propertyNames)
    {
        final Field field = ReflectionUtils.findField(domainClass, propertyName);
        if (!hasAssociationAnnotation(field))
        {
            final String aliasedProperty = alias + "." + propertyName;
            projectionList
                    .add(Projections.property(aliasedProperty), aliasedProperty);
        }
    }
    return projectionList;
}
项目:chipster    文件:StatDataSource.java   
@SuppressWarnings("rawtypes")
private Map getJobDateRange(Session session, boolean ignoreTestAccounts) {
    //Get min and max values of dates
    Criteria rangeCriteria = session.createCriteria(JobLogEntry.class);
    testAccountFilter.addCriteriaForTestAccounts(session, ignoreTestAccounts, rangeCriteria);
    ProjectionList projections = Projections.projectionList();
    projections.add(Projections.min(JobLogContainer.START_TIME), "min");
    projections.add(Projections.max(JobLogContainer.START_TIME), "max");
    rangeCriteria.setProjection(projections);
    rangeCriteria.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);

    @SuppressWarnings("unchecked")
    List<Map> rangeList = rangeCriteria.list();

    return rangeList.get(0);
}
项目:national-biomedical-image-archive    文件:DicomSOPInstanceUIDQuery.java   
private UIDResult getIndividualUIDResult(String sopInstanceUID)
{
    UIDResult uidResult = null;
    DetachedCriteria criteria = DetachedCriteria.forClass(GeneralImage.class);
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("submissionDate"));
    projectionList.add(Projections.property("md5Digest"));
    criteria.setProjection(projectionList);
    criteria.add(Restrictions.eq("SOPInstanceUID",sopInstanceUID));
    List result = getHibernateTemplate().findByCriteria(criteria);
    //Since SOPInstanceUID is unique, the result either 0 or 1
    if (result != null && result.size() > 0)
    {
        Object[] o = (Object[])result.get(0);
        Date submissionDate = (Date)o[0];
        long datetime = submissionDate.getTime();
        String mdDigest = (String)o[1] == null ? "" : (String)o[1];
        uidResult = UIDResult.PRESENT(datetime, mdDigest);
    }
    if (result == null || result.size() == 0)
    {
        uidResult = UIDResult.MISSING();
    }

    return uidResult;
}
项目:national-biomedical-image-archive    文件:CustomSeriesListDAOImpl.java   
private List<Object[]> getSharedListResult (List<String> seriesUids)
{
    List<Object[]> results = new ArrayList<Object[]>();

    if (seriesUids != null && seriesUids.size() != 0){
        DetachedCriteria criteria = DetachedCriteria.forClass(CustomSeriesListAttribute.class);
        ProjectionList projectionList = Projections.projectionList();

        projectionList.add(Projections.property("csl.userName"));
        projectionList.add(Projections.property("csl.name"));
        projectionList.add(Projections.property("seriesInstanceUid"));

        criteria.setProjection(Projections.distinct(projectionList));

        criteria.createAlias("parent", "csl");

        criteria.add(Restrictions.in("seriesInstanceUid", seriesUids));

        results = getHibernateTemplate().findByCriteria(criteria);
    }

    return results;
}
项目:Equella    文件:AllVersionsWhereClause.java   
@Override
public void addWhere(ItemSerializerState state)
{
    ProjectionList projections = state.getItemProjection();
    DetachedCriteria criteria = state.getItemQuery();
    criteria.add(Restrictions.eq("uuid", uuid));
    criteria.addOrder(Order.asc(PROPERTY_VERSION));
    projections.add(Projections.property(PROPERTY_VERSION), ALIAS_VERSION);
}
项目:Equella    文件:LatestVersionWhereClause.java   
@Override
public void addWhere(ItemSerializerState state)
{
    DetachedCriteria criteria = state.getItemQuery();
    ProjectionList projections = state.getItemProjection();
    criteria.add(Restrictions.eq("uuid", uuid));
    if( live )
    {
        criteria.add(Restrictions.eq("status", ItemStatus.LIVE.name()));
    }
    criteria.addOrder(Order.desc(PROPERTY_VERSION));
    projections.add(Projections.property(PROPERTY_VERSION), ALIAS_VERSION);
    state.setMaxResults(1);
}
项目:Equella    文件:NavigationNodeSerializerProvider.java   
@Override
public void prepareItemQuery(ItemSerializerState state)
{
    if( state.hasCategory(CATEGORY_NAVIGATION) )
    {
        state.addPrivilege(ItemSecurityConstants.VIEW_ITEM);
        final ProjectionList projection = state.getItemProjection();
        projection.add(Projections.property("navigationSettings.manualNavigation"), ALIAS_MANUAL_NAVIGATION);
        projection.add(Projections.property("navigationSettings.showSplitOption"), ALIAS_SHOW_SPLIT);
    }
}
项目:Equella    文件:DetailsItemSerializerProvider.java   
@Override
public void prepareItemQuery(ItemSerializerState state)
{
    if( state.hasCategory(CATEGORY_DETAIL) )
    {
        final ProjectionList projection = state.getItemProjection();
        state.addOwnerQuery();
        state.addStatusQuery();
        state.addCollectionQuery();
        projection.add(Projections.property(CREATED_PROPERTY), CREATED_PROPERTY);
        projection.add(Projections.property(MODIFIED_PROPERTY), MODIFIED_PROPERTY);
        projection.add(Projections.property(RATING_PROPERTY), RATING_PROPERTY);
        projection.add(Projections.property(THUMBNAIL_PROPERTY), THUMBNAIL_PROPERTY);
    }
}
项目:sjk    文件:AppDaoImpl.java   
@Override
public List<App> listForBase(short catalog, Integer subCatalog, int currentPage, int pageSize) {
    ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("id"));
    proList.add(Projections.property("name"));
    proList.add(Projections.property("subCatalog"));
    proList.add(Projections.property("auditCatalog"));

    Criteria cri = getSession().createCriteria(App.class);
    cri.setProjection(proList);
    cri.addOrder(Order.asc("auditCatalog"));
    cri.addOrder(Order.asc("name"));
    cri.add(Restrictions.eq("catalog", catalog));
    if (subCatalog != null) {
        cri.add(Restrictions.eq("subCatalog", subCatalog));
    }
    cri.setMaxResults(pageSize);
    cri.setFirstResult(HibernateHelper.firstResult(currentPage, pageSize));
    List<Object[]> list = HibernateHelper.list(cri);
    List<App> apps = null;
    if (list != null) {
        apps = new ArrayList<App>(list.size());
        for (Object[] obj : list) {
            App e = new App((Integer) obj[0], (String) obj[1]);
            e.setSubCatalog((Integer) obj[2]);
            e.setAuditCatalog((Boolean) obj[3]);
            apps.add(e);
        }
        list.clear();
    }
    return apps;
}
项目:sjk    文件:AppDaoImpl.java   
@Override
public List<App> listForDownloads(Session session, int currentPage, int pageSize) {
    ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("id"));
    proList.add(Projections.property("pkname"));
    proList.add(Projections.property("marketName"));

    Criteria cri = session.createCriteria(App.class);
    cri.setProjection(proList);
    cri.setMaxResults(pageSize);
    cri.setFirstResult(HibernateHelper.firstResult(currentPage, pageSize));
    // 先全部更新.
    // cri.add(Restrictions.or(Restrictions.ltProperty("realDownload",
    // "lastDayDownload"),
    // Restrictions.ne("deltaDownload", 0)));
    List<Object[]> list = HibernateHelper.list(cri);
    List<App> apps = null;
    if (list != null) {
        apps = new ArrayList<App>(list.size());
        for (Object[] obj : list) {
            App e = new App();
            e.setId((Integer) obj[0]);
            e.setPkname((String) obj[1]);
            e.setMarketName((String) obj[2]);
            apps.add(e);
        }
        list.clear();
    }
    return apps;
}
项目:sjk    文件:AppDaoImpl.java   
@Override
public List<App> listForBase(short catalog, Integer subCatalog, int currentPage, int pageSize) {
    ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("id"));
    proList.add(Projections.property("name"));
    proList.add(Projections.property("subCatalog"));
    proList.add(Projections.property("auditCatalog"));

    Criteria cri = getSession().createCriteria(App.class);
    cri.setProjection(proList);
    cri.addOrder(Order.asc("auditCatalog"));
    cri.addOrder(Order.asc("name"));
    cri.add(Restrictions.eq("catalog", catalog));
    if (subCatalog != null) {
        cri.add(Restrictions.eq("subCatalog", subCatalog));
    }
    cri.setMaxResults(pageSize);
    cri.setFirstResult(HibernateHelper.firstResult(currentPage, pageSize));
    List<Object[]> list = HibernateHelper.list(cri);
    List<App> apps = null;
    if (list != null) {
        apps = new ArrayList<App>(list.size());
        for (Object[] obj : list) {
            App e = new App((Integer) obj[0], (String) obj[1]);
            e.setSubCatalog((Integer) obj[2]);
            e.setAuditCatalog((Boolean) obj[3]);
            apps.add(e);
        }
        list.clear();
    }
    return apps;
}
项目:sjk    文件:AppDaoImpl.java   
@Override
public List<App> listForDownloads(Session session, int currentPage, int pageSize) {
    ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("id"));
    proList.add(Projections.property("pkname"));
    proList.add(Projections.property("marketName"));

    Criteria cri = session.createCriteria(App.class);
    cri.setProjection(proList);
    cri.setMaxResults(pageSize);
    cri.setFirstResult(HibernateHelper.firstResult(currentPage, pageSize));
    // 先全部更新.
    // cri.add(Restrictions.or(Restrictions.ltProperty("realDownload",
    // "lastDayDownload"),
    // Restrictions.ne("deltaDownload", 0)));
    List<Object[]> list = HibernateHelper.list(cri);
    List<App> apps = null;
    if (list != null) {
        apps = new ArrayList<App>(list.size());
        for (Object[] obj : list) {
            App e = new App();
            e.setId((Integer) obj[0]);
            e.setPkname((String) obj[1]);
            e.setMarketName((String) obj[2]);
            apps.add(e);
        }
        list.clear();
    }
    return apps;
}
项目:sjk    文件:AppDaoImpl.java   
@Override
public List<App> getForQuickTipsIndex(Session session, Integer currentPage, Integer pageSize) {
    ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("name"));
    proList.add(Projections.property("downloadRank"));
    proList.add(Projections.property("catalog"));
    proList.add(Projections.property("id"));
    Criteria cri = session.createCriteria(App.class);
    cri.setProjection(proList);
    cri.add(Restrictions.eq("hidden", false));
    cri.addOrder(Order.asc("downloadRank"));
    if (currentPage != null && pageSize != null) {
        cri.setFirstResult(HibernateHelper.firstResult(currentPage, pageSize));
        cri.setMaxResults(pageSize);
    }
    List<Object[]> list = HibernateHelper.list(cri);
    List<App> apps = null;
    if (list != null) {
        apps = new ArrayList<App>(list.size());
        for (Object[] obj : list) {
            App e = new App();
            e.setName((String) obj[0]);
            e.setDownloadRank((Integer) obj[1]);
            e.setCatalog((Short) obj[2]);
            e.setId((Integer) obj[3]);
            apps.add(e);
        }
        list.clear();
    }
    return apps;
}
项目:openbravo-brazil    文件:MatchTransactionDao.java   
/**
 * Calculates the ending balance of automatic reconciliations. The sum of all the bank statement
 * lines of the reconciliation financial account that belong to the given reconciliation plus the
 * ones that does not have a transaction associated yet.
 * 
 * @param reconciliation
 *          Reconciliation.
 * @return Ending balance of an automatic reconciliation.
 */
@Deprecated
public static BigDecimal getReconciliationEndingBalance(FIN_Reconciliation reconciliation) {
  BigDecimal total = BigDecimal.ZERO;
  OBContext.setAdminMode(true);
  try {
    OBCriteria<FIN_BankStatementLine> obcBsl = OBDal.getInstance().createCriteria(
        FIN_BankStatementLine.class);
    obcBsl.createAlias(FIN_BankStatementLine.PROPERTY_BANKSTATEMENT, "bs");
    obcBsl.createAlias(FIN_BankStatementLine.PROPERTY_FINANCIALACCOUNTTRANSACTION, "tr",
        OBCriteria.LEFT_JOIN);
    obcBsl.add(Restrictions.or(
        Restrictions.isNull(FIN_BankStatementLine.PROPERTY_FINANCIALACCOUNTTRANSACTION),
        Restrictions.eq("tr." + FIN_FinaccTransaction.PROPERTY_RECONCILIATION, reconciliation)));

    obcBsl.add(Restrictions.eq("bs." + FIN_BankStatement.PROPERTY_ACCOUNT,
        reconciliation.getAccount()));
    obcBsl.add(Restrictions.eq("bs." + FIN_BankStatement.PROPERTY_PROCESSED, true));
    ProjectionList projections = Projections.projectionList();
    projections.add(Projections.sum(FIN_BankStatementLine.PROPERTY_CRAMOUNT));
    projections.add(Projections.sum(FIN_BankStatementLine.PROPERTY_DRAMOUNT));
    obcBsl.setProjection(projections);

    @SuppressWarnings("rawtypes")
    List o = obcBsl.list();
    if (o != null && o.size() > 0) {
      Object[] resultSet = (Object[]) o.get(0);
      BigDecimal credit = (resultSet[0] != null) ? (BigDecimal) resultSet[0] : BigDecimal.ZERO;
      BigDecimal debit = (resultSet[1] != null) ? (BigDecimal) resultSet[1] : BigDecimal.ZERO;
      total = credit.subtract(debit);
    }
    o.clear();

  } finally {
    OBContext.restorePreviousMode();
  }

  return total;
}
项目:openbravo-brazil    文件:MatchTransactionDao.java   
private static BigDecimal getBSLAmount(FIN_Reconciliation reconciliation) {
  BigDecimal total = BigDecimal.ZERO;
  OBContext.setAdminMode(false);
  try {
    OBCriteria<FIN_BankStatementLine> obcBsl = OBDal.getInstance().createCriteria(
        FIN_BankStatementLine.class);
    obcBsl.createAlias(FIN_BankStatementLine.PROPERTY_BANKSTATEMENT, "bs");
    obcBsl.createAlias(FIN_BankStatementLine.PROPERTY_FINANCIALACCOUNTTRANSACTION, "tr",
        OBCriteria.LEFT_JOIN);
    obcBsl.add(Restrictions.eq("bs." + FIN_BankStatement.PROPERTY_ACCOUNT,
        reconciliation.getAccount()));
    obcBsl.add(Restrictions.eq("bs." + FIN_BankStatement.PROPERTY_PROCESSED, true));
    obcBsl.add(Restrictions.le(FIN_BankStatementLine.PROPERTY_TRANSACTIONDATE,
        reconciliation.getEndingDate()));
    ProjectionList projections = Projections.projectionList();
    projections.add(Projections.sum(FIN_BankStatementLine.PROPERTY_CRAMOUNT));
    projections.add(Projections.sum(FIN_BankStatementLine.PROPERTY_DRAMOUNT));
    obcBsl.setProjection(projections);

    @SuppressWarnings("rawtypes")
    List o = obcBsl.list();
    if (o != null && o.size() > 0) {
      Object[] resultSet = (Object[]) o.get(0);
      BigDecimal credit = (resultSet[0] != null) ? (BigDecimal) resultSet[0] : BigDecimal.ZERO;
      BigDecimal debit = (resultSet[1] != null) ? (BigDecimal) resultSet[1] : BigDecimal.ZERO;
      total = credit.subtract(debit);
    }
    o.clear();

  } finally {
    OBContext.restorePreviousMode();
  }
  return total;
}
项目:openbravo-brazil    文件:ReportReconciliation.java   
/**
 * Calculates the sum of all the transactions in a higher date than the end date of the given
 * reconciliation.
 * 
 * @param recon
 *          Reconciliation.
 * @return Sum of all the transactions in a higher date than the end date of the given
 *         reconciliation.
 */
private BigDecimal getTransactionsTotalAfterReconciliationEndDate(FIN_Reconciliation recon) {
  BigDecimal balance = BigDecimal.ZERO;
  OBContext.setAdminMode(true);
  try {
    OBCriteria<FIN_FinaccTransaction> obcTrans = OBDal.getInstance().createCriteria(
        FIN_FinaccTransaction.class);
    obcTrans.add(Restrictions.eq(FIN_FinaccTransaction.PROPERTY_ACCOUNT, recon.getAccount()));
    obcTrans.add(Restrictions.eq(FIN_FinaccTransaction.PROPERTY_PROCESSED, true));
    obcTrans.add(Restrictions.gt(FIN_FinaccTransaction.PROPERTY_TRANSACTIONDATE,
        recon.getEndingDate()));
    ProjectionList projections = Projections.projectionList();
    projections.add(Projections.sum(FIN_FinaccTransaction.PROPERTY_PAYMENTAMOUNT));
    projections.add(Projections.sum(FIN_FinaccTransaction.PROPERTY_DEPOSITAMOUNT));
    obcTrans.setProjection(projections);

    if (obcTrans.list() != null && obcTrans.list().size() > 0) {
      @SuppressWarnings("rawtypes")
      List o = obcTrans.list();
      Object[] resultSet = (Object[]) o.get(0);
      BigDecimal paymentAmt = (resultSet[0] != null) ? (BigDecimal) resultSet[0]
          : BigDecimal.ZERO;
      BigDecimal depositAmt = (resultSet[1] != null) ? (BigDecimal) resultSet[1]
          : BigDecimal.ZERO;
      balance = depositAmt.subtract(paymentAmt);
    }

  } finally {
    OBContext.restorePreviousMode();
  }

  return balance;
}
项目:communote-server    文件:GlobalIdDaoImpl.java   
/**
 * {@inheritDoc}
 */
@Override
protected GlobalId handleFindLatestGlobalId() {
    Criteria criteria = getSession().createCriteria(GlobalId.class);
    ProjectionList projList = Projections.projectionList();
    projList.add(Projections.max(GlobalIdConstants.ID));
    criteria.setProjection(projList);
    List result = criteria.list();
    if (result != null && result.size() == 1 && result.get(0) != null) {
        Long id = (Long) result.get(0);
        return load(id);
    }
    return null;
}
项目:communote-server    文件:BlogDaoImpl.java   
/**
 * {@inheritDoc}
 */
@Override
protected Blog handleFindLatestBlog() {
    Criteria criteria = getSession().createCriteria(Blog.class);
    ProjectionList projList = Projections.projectionList();
    projList.add(Projections.max(BlogConstants.ID));
    criteria.setProjection(projList);
    List result = criteria.list();
    if (result != null && result.size() == 1 && result.get(0) != null) {
        Long id = (Long) result.get(0);
        return load(id);
    }
    return null;
}
项目:communote-server    文件:NoteDaoImpl.java   
/**
 * {@inheritDoc}
 */
@Override
protected Note handleFindLatestNote() {
    Criteria criteria = getSession().createCriteria(Note.class);
    ProjectionList projList = Projections.projectionList();
    projList.add(Projections.max(NoteConstants.ID));
    criteria.setProjection(projList);
    List<?> result = criteria.list();
    if (result != null && result.size() == 1 && result.get(0) != null) {
        Long id = (Long) result.get(0);
        return load(id);
    }
    return null;
}
项目:coordinated-entry    文件:SurveyMSServiceImpl.java   
public ClientsSurveyScores fetchSurveyResponses(String projectGroup){
    ClientsSurveyScores scores = new ClientsSurveyScores();
    org.hibernate.Session session =  entityManager.unwrap(org.hibernate.Session.class);

    DetachedCriteria criteria = DetachedCriteria.forClass(SectionScoreEntity.class);
    criteria.createAlias("surveyEntity", "surveyEntity");


    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.sum("sectionScore"),"surveyScore");
    projectionList.add(Projections.min("createdAt"),"surveyDate");
    projectionList.add(Projections.property("surveyEntity.id"),"surveyId");
    projectionList.add(Projections.property("clientId"),"clientId");
    projectionList.add(Projections.property("surveyEntity.projectGroupCode"),"projectGroupCode");
    projectionList.add(Projections.groupProperty("surveyEntity.id"));
    projectionList.add(Projections.groupProperty("clientId"));
    projectionList.add(Projections.groupProperty("surveyEntity.tagValue"),"surveyTagValue");
    criteria.setProjection(projectionList);
    criteria.add(Restrictions.eq("surveyEntity.projectGroupCode",projectGroup));
    criteria.add(Restrictions.eq("deleted", false));
    criteria.setResultTransformer(Transformers.aliasToBean(ClientSurveyScore.class));

    Criteria eCriteria = criteria.getExecutableCriteria(session);
    List<ClientSurveyScore> enities =  eCriteria.list();

    System.out.println("Suvey clients "+enities.size());
    scores.addAll(enities);     

    return scores;
}
项目:coordinated-entry    文件:SectionScoreDaoImplV3.java   
public Long countOfClientSurveyScore(String projectGroupCode) {
    DetachedCriteria criteria = DetachedCriteria.forClass(SectionScoreEntity.class);
    criteria.createAlias("surveyEntity", "surveyEntity");

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.sum("sectionScore"),"surveyScore");
    projectionList.add(Projections.property("surveyEntity.id"),"surveyId");
    projectionList.add(Projections.property("clientDedupId"),"clientDedupId");

    projectionList.add(Projections.groupProperty("surveyEntity.id"));
    projectionList.add(Projections.groupProperty("clientDedupId"));
    criteria.setProjection(projectionList);
    criteria.add(Restrictions.eq("surveyEntity.projectGroupCode",projectGroupCode));
    return countRows(criteria);
}
项目:coordinated-entry    文件:SectionScoreDaoImpl.java   
public Long countOfClientSurveyScore(String projectGroupCode) {
    DetachedCriteria criteria = DetachedCriteria.forClass(SectionScoreEntity.class);
    criteria.createAlias("surveyEntity", "surveyEntity");

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.sum("sectionScore"),"surveyScore");
    projectionList.add(Projections.property("surveyEntity.id"),"surveyId");
    projectionList.add(Projections.property("clientId"),"clientId");

    projectionList.add(Projections.groupProperty("surveyEntity.id"));
    projectionList.add(Projections.groupProperty("clientId"));
    criteria.setProjection(projectionList);
    criteria.add(Restrictions.eq("surveyEntity.projectGroupCode",projectGroupCode));
    return countRows(criteria);
}
项目:gisgraphy    文件:ProjectionBeanTest.java   
@SuppressWarnings("unchecked")
   @Test
   public void testPropertiesList() {

City p1 = GisgraphyTestHelper.createCity("paris", 48.86667F, 2.3333F, 1L);

this.cityDao.save(p1);
HibernateCallback hibernateCallback = new HibernateCallback() {

    public Object doInHibernate(Session session)
        throws PersistenceException {

    Criteria testCriteria = session.createCriteria(City.class);
    List<String> fieldList = new ArrayList<String>();
    fieldList.add("name");
    fieldList.add("featureId");
    ProjectionList projection = ProjectionBean.fieldList(fieldList,
        true);
    testCriteria.setProjection(projection);
    testCriteria.setResultTransformer(Transformers
        .aliasToBean(City.class));

    List<City> results = testCriteria.list();
    return results;
    }
};

List<City> cities = (List<City>) testDao
    .testCallback(hibernateCallback);
assertEquals(1, cities.size());
assertEquals("paris", cities.get(0).getName());
assertEquals("1", cities.get(0).getFeatureId() + "");
   }
项目:gisgraphy    文件:ProjectionBeanTest.java   
@SuppressWarnings("unchecked")
   @Test
   public void testBeanFieldList() {

City p1 = GisgraphyTestHelper.createCity("paris", 48.86667F, 2.3333F, 1L);

this.cityDao.save(p1);
HibernateCallback hibernateCallback = new HibernateCallback() {

    public Object doInHibernate(Session session)
        throws PersistenceException {

    try {
        Criteria testCriteria = session.createCriteria(City.class);
        String[] ignoreFields = { "distance" };
        ProjectionList projection = ProjectionBean.beanFieldList(
            _CityDTO.class, ignoreFields, true);
        testCriteria.setProjection(projection);
        testCriteria.setResultTransformer(Transformers
            .aliasToBean(_CityDTO.class));

        List<_CityDTO> results = testCriteria.list();
        return results;
    } catch (HibernateException e) {
        fail("An exception has occured : maybe ignoreFields are not taken into account if the error is 'could not resolve property: distance... :"
            + e);
        throw e;
    }
    }
};

List<_CityDTO> cities = (List<_CityDTO>) testDao
    .testCallback(hibernateCallback);
assertEquals(1, cities.size());
assertEquals("paris", cities.get(0).getName());
assertEquals("1", cities.get(0).getFeatureId() + "");
   }
项目:gisgraphy    文件:ProjectionBeanTest.java   
@SuppressWarnings("unchecked")
   public void testBeanFieldListWithOutAutoAliasing() {

City p1 = GisgraphyTestHelper.createCity("paris", 48.86667F, 2.3333F, 1L);

this.cityDao.save(p1);
HibernateCallback hibernateCallback = new HibernateCallback() {

    public Object doInHibernate(Session session)
        throws PersistenceException {

    try {
        Criteria testCriteria = session.createCriteria(City.class);
        String[] ignoreFields = { "distance" };
        ProjectionList projection = ProjectionBean.beanFieldList(
            _CityDTO.class, ignoreFields, false);
        testCriteria.setProjection(projection);
        testCriteria.add(Restrictions.eq("name", "paris"));

        List<Object[]> results = testCriteria.list();
        return results;
    } catch (HibernateException e) {
        fail("An exception has occured : there is maybe a bug with autoaliasing"
            + e);
        throw e;
    }
    }
};

List<Object[]> cities = (List<Object[]>) testDao
    .testCallback(hibernateCallback);
assertEquals(1, cities.size());
assertEquals(1L, cities.get(0)[0]);
   }
项目:vigor    文件:SqlClient.java   
/**
 * Queries the database for a result set which consists of parts of the result set for each of all rows that match the criteria within the table.
 *
 * @param model      the model class which represents the table
 * @param criteria   the criteria
 * @param properties the properties to return within each row of the result set
 * @param <T>        the type of the model which represents the table
 * @return a list of values for the specified properties
 */
public <T> List<Object[]> partialFind(Class<T> model, Criteria criteria, String... properties) {
    if (model == null || properties == null)
        throw new IllegalArgumentException();
    org.hibernate.Criteria c = session.createCriteria(model);
    if (criteria != null)
        criteria.accept(c);
    ProjectionList projection = Projections.projectionList();
    for (String property : properties)
        projection.add(Projections.property(property));
    c.setProjection(projection);
    return c.list();
}
项目:breeze.server.java    文件:CriteriaBuilder.java   
private void addSelect(Criteria crit, SelectClause selectClause) {
    if (selectClause == null) return;
    ProjectionList projList = Projections.projectionList();
    CriteriaWrapper critWrapper = new CriteriaWrapper(crit, _entityType);
    for (String propertyPath : selectClause.getPropertyPaths()) {
        String propertyName = _aliasBuilder.getPropertyName(critWrapper,
                propertyPath);
        projList.add(Projections.property(propertyName).as(propertyPath));
    }
    crit.setProjection(projList);
    crit.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);

}
项目:cananolab    文件:SampleServiceHelper.java   
public List<String> findSampleIdsByOwner(String currentOwner)
        throws Exception {
    List<String> sampleIds = new ArrayList<String>();

    // can't query for the entire Sample object due to
    // limitations in pagination in SDK
    // Sample sample = new Sample();
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("id"));
    DetachedCriteria crit = DetachedCriteria.forClass(Sample.class);
    crit.setProjection(Projections.distinct(projectionList));
    Criterion crit1 = Restrictions.eq("createdBy", currentOwner);
    // in case of copy createdBy is like lijowskim:COPY
    Criterion crit2 = Restrictions.like("createdBy", currentOwner + ":",
            MatchMode.START);
    crit.add(Expression.or(crit1, crit2));
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();

    List results = appService.query(crit);
    for(int i = 0; i < results.size(); i++){
        String id = results.get(i).toString();
        if (springSecurityAclService.currentUserHasReadPermission(Long.valueOf(id), SecureClassesEnum.SAMPLE.getClazz()) ||
            springSecurityAclService.currentUserHasWritePermission(Long.valueOf(id), SecureClassesEnum.SAMPLE.getClazz())) {
            sampleIds.add(id);
        } else {
            logger.debug("User doesn't have access to sample of ID: " + id);
        }
    }
    return sampleIds;
}
项目:further-open-core    文件:HibernateUtil.java   
/**
 * @deprecated This method does not work well due to Hibernate bug HHH-817, nor does
 *             AliasToBeanResultTransformer handle multi-level property values.
 *             Therefore it should not be used.
 * @see http://opensource.atlassian.com/projects/hibernate/browse/HHH-817
 */
@Deprecated
public static Projection createProjectionList(final String identifierProperty,
        final Type identifierType, final String[] propertyNames,
        final Class<?> domainClass)
{
    final ProjectionList projectionList = Projections.projectionList();
    if (identifierType.isComponentType())
    {
        final String[] idProperties = ((ComponentType) (identifierType))
                .getPropertyNames();
        for (final String idProperty : idProperties)
        {
            final String idPath = identifierProperty + "." + idProperty;
            projectionList.add(Projections.property(idPath));
        }
    }
    else
    {
        projectionList.add(Projections.id());
    }
    for (final String propertyName : propertyNames)
    {
        final Field field = ReflectionUtils.findField(domainClass, propertyName);
        if (!hasAssociationAnnotation(field))
        {
            projectionList.add(Projections.property(propertyName), propertyName);
        }

    }
    return projectionList;
}