Example usage for org.hibernate Criteria createCriteria

List of usage examples for org.hibernate Criteria createCriteria

Introduction

In this page you can find the example usage for org.hibernate Criteria createCriteria.

Prototype

public Criteria createCriteria(String associationPath) throws HibernateException;

Source Link

Document

Create a new Criteria, "rooted" at the associated entity.

Usage

From source file:com.npower.dm.hibernate.management.UpdateImageManagementBeanImpl.java

License:Open Source License

public List<Update> findReleasedUpdates(Model model, String versionId) throws DMException {
    Image image = this.getImageByVersionID(model, versionId);
    if (image == null) {
        return new ArrayList<Update>(0);
    }//from  w w w. j  a va  2 s  .  c  o  m
    Session session = this.getHibernateSession();
    long releaseStatus = Image.STATUS_RELEASED;
    try {
        ImageUpdateStatus status = getImageUpdateStatus(releaseStatus);
        Criteria criteria = session.createCriteria(UpdateEntity.class);
        criteria.add(Expression.eq("fromImage", image));
        criteria.add(Expression.eq("status", status));

        Criteria upgradeCriteria = criteria.createCriteria("toImage");
        upgradeCriteria.add(Expression.eq("model", model));
        upgradeCriteria.addOrder(Order.desc("versionId"));

        return criteria.list();
    } catch (HibernateException e) {
        throw new DMException(e);
    } finally {
    }
}

From source file:com.npower.dm.hibernate.management.UpdateImageManagementBeanImpl.java

License:Open Source License

public List<Update> findUpdates(Model model) throws DMException {
    Session session = this.getHibernateSession();
    try {//from  ww  w  .  ja  va  2  s .co m
        Criteria criteria = session.createCriteria(UpdateEntity.class);

        Criteria upgradeCriteria = criteria.createCriteria("toImage");
        upgradeCriteria.add(Expression.eq("model", model));
        upgradeCriteria.addOrder(Order.desc("versionId"));

        return criteria.list();
    } catch (HibernateException e) {
        throw new DMException(e);
    } finally {
    }
}

From source file:com.npower.dm.hibernate.management.UpdateImageManagementBeanImpl.java

License:Open Source License

public List<Update> findReleasedUpdates(Model model) throws DMException {
    Session session = this.getHibernateSession();
    long releaseStatus = Image.STATUS_RELEASED;
    try {/*w ww . j a  v a2 s.c o  m*/
        ImageUpdateStatus status = getImageUpdateStatus(releaseStatus);
        Criteria criteria = session.createCriteria(UpdateEntity.class);
        criteria.add(Expression.eq("status", status));

        Criteria upgradeCriteria = criteria.createCriteria("toImage");
        upgradeCriteria.add(Expression.eq("model", model));
        upgradeCriteria.addOrder(Order.desc("versionId"));

        return criteria.list();
    } catch (HibernateException e) {
        throw new DMException(e);
    } finally {
    }
}

From source file:com.npower.dm.hibernate.management.UpdateImageManagementBeanImpl.java

License:Open Source License

public List<Update> findReleasedUpdates() throws DMException {
    Session session = this.getHibernateSession();
    long releaseStatus = Image.STATUS_RELEASED;
    try {/*from  w  ww. j  a v a 2 s.  co m*/
        ImageUpdateStatus status = getImageUpdateStatus(releaseStatus);
        Criteria criteria = session.createCriteria(UpdateEntity.class);
        criteria.add(Expression.eq("status", status));

        Criteria upgradeCriteria = criteria.createCriteria("toImage");
        upgradeCriteria.addOrder(Order.asc("model"));
        upgradeCriteria.addOrder(Order.desc("versionId"));

        return criteria.list();
    } catch (HibernateException e) {
        throw new DMException(e);
    } finally {
    }
}

From source file:com.npower.dm.management.TestSearchBean.java

License:Open Source License

/**
 * @param bean//  w  w w  .j  a va  2s. c  o  m
 * @return
 * @throws DMException
 */
private Criteria getDeviceCriteria(ManagementBeanFactory factory, SearchBean bean, String searchManufacturerID,
        String searchMadelID) throws DMException {
    SearchBean searchBean = factory.createSearchBean();
    ModelBean modelBean = factory.createModelBean();
    Criteria criteria = searchBean.newCriteriaInstance(DeviceEntity.class);
    criteria.addOrder(Order.asc("externalId"));
    if (StringUtils.isNotEmpty(searchManufacturerID)) {
        Manufacturer manufactuer = modelBean.getManufacturerByID(searchManufacturerID);
        if (manufactuer != null) {
            Criteria subCriteria = criteria.createCriteria("model");
            subCriteria.add(Expression.eq("manufacturer", manufactuer));
        }
    }

    if (StringUtils.isNotEmpty(searchMadelID)) {
        Model model = modelBean.getModelByID(searchMadelID);
        if (model != null) {
            criteria.add(Expression.eq("model", model));
        }
    }
    return criteria;
}

From source file:com.opengamma.masterdb.batch.DbBatchWriter.java

License:Open Source License

protected RiskRun findRiskRunInDbInTransaction(final Instant valuationTime,
        final VersionCorrection versionCorrection, final UniqueId viewDefinitionUid,
        final UniqueId marketDataBaseUid) {
    return getHibernateTemplate().execute(new HibernateCallback<RiskRun>() {
        @Override/*w w w  .ja v  a 2s .  c  o m*/
        public RiskRun doInHibernate(Session session) throws HibernateException, SQLException {
            Criteria criteria = session.createCriteria(RiskRun.class);
            criteria.add(Restrictions.eq("valuationTime", valuationTime));
            criteria.add(Restrictions.eq("versionCorrection", versionCorrection));
            criteria.add(Restrictions.eq("viewDefinitionUidScheme", viewDefinitionUid.getScheme()));
            criteria.add(Restrictions.eq("viewDefinitionUidValue", viewDefinitionUid.getValue()));
            criteria.add(eqOrIsNull("viewDefinitionUidVersion", viewDefinitionUid.getVersion()));

            criteria.createCriteria("marketData")
                    .add(Restrictions.eq("baseUidScheme", marketDataBaseUid.getScheme()))
                    .add(Restrictions.eq("baseUidValue", marketDataBaseUid.getValue()))
                    .add(eqOrIsNull("baseUidVersion", marketDataBaseUid.getVersion()));

            return (RiskRun) criteria.uniqueResult();
        }
    });
}

From source file:com.salesmanager.core.service.catalog.impl.db.dao.CategoryDao.java

License:Open Source License

public List<Category> findByMerchantIdAndLanguage(int merchantId, int language) {
    try {/*  www. j  av  a2 s. c  o  m*/

        Collection ids = new ArrayList();
        ids.add(Constants.GLOBAL_MERCHANT_ID);
        ids.add(merchantId);

        Criteria query = super.getSession().createCriteria(com.salesmanager.core.entity.catalog.Product.class)
                .add(Expression.in("merchantId", ids)).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

        Criteria descCriteria = query.createCriteria("descriptions");
        descCriteria.add(Restrictions.eq("id.languageId", language));

        List list = query.list();

        return list;

    } catch (RuntimeException re) {
        log.error("get failed", re);
        throw re;
    }
}

From source file:com.salesmanager.core.service.catalog.impl.db.dao.CategoryDescriptionDao.java

License:Open Source License

public List<CategoryDescription> findByMerchantIdandLanguageId(int merchantId, int languageId) {

    try {//ww  w . j  a v a2s. c om

        Collection ids = new ArrayList();
        ids.add(Constants.GLOBAL_MERCHANT_ID);
        ids.add(merchantId);

        Criteria descriptions = super.getSession().createCriteria(CategoryDescription.class)
                .add(Restrictions.eq("id.languageId", languageId))
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

        Criteria category = descriptions.createCriteria("category").add(Expression.in("merchantId", ids))
                .addOrder(Order.asc("sortOrder"));

        List list = descriptions.list();

        return list;
    } catch (RuntimeException re) {
        log.error("get failed", re);
        throw re;
    }
}

From source file:com.salesmanager.core.service.catalog.impl.db.dao.CategoryDescriptionDao.java

License:Open Source License

public CategoryDescription findByMerchantIdAndCategoryIdAndLanguageId(int merchantId, long categoryId,
        int languageId) {

    try {//w  w w. j  a v  a2s . c om

        Collection ids = new ArrayList();
        ids.add(Constants.GLOBAL_MERCHANT_ID);
        ids.add(merchantId);

        Criteria descriptions = super.getSession().createCriteria(CategoryDescription.class)
                .add(Restrictions.eq("id.languageId", languageId))
                .add(Restrictions.eq("id.categoryId", categoryId))
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

        Criteria category = descriptions.createCriteria("category").add(Expression.in("merchantId", ids))
                .addOrder(Order.asc("sortOrder"));

        CategoryDescription description = (CategoryDescription) descriptions.uniqueResult();

        return description;

    } catch (RuntimeException re) {
        log.error("get failed", re);
        throw re;
    }
}

From source file:com.salesmanager.core.service.catalog.impl.db.dao.CategoryDescriptionDao.java

License:Open Source License

public List<CategoryDescription> findByParentCategoryIDMerchantIdandLanguageId(int merchantId,
        long parentCategoryId, int languageId) {

    try {/*from w  ww  .  j a  va 2  s  .  co  m*/

        Collection ids = new ArrayList();
        ids.add(Constants.GLOBAL_MERCHANT_ID);
        ids.add(merchantId);

        Criteria descriptions = super.getSession().createCriteria(CategoryDescription.class)
                .add(Restrictions.eq("id.languageId", languageId))
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

        Criteria category = descriptions.createCriteria("category").add(Expression.in("merchantId", ids))
                .add(Restrictions.eq("parentId", parentCategoryId)).addOrder(Order.asc("sortOrder"));

        List list = descriptions.list();

        return list;
    } catch (RuntimeException re) {
        log.error("get failed", re);
        throw re;
    }
}