Example usage for org.hibernate Criteria setCacheable

List of usage examples for org.hibernate Criteria setCacheable

Introduction

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

Prototype

public Criteria setCacheable(boolean cacheable);

Source Link

Document

Enable caching of this query result, provided query caching is enabled for the underlying session factory.

Usage

From source file:com.ut.tekir.general.PaymentCommisionSuggestionBean.java

License:LGPL

@SuppressWarnings("unchecked")
public void selectPaymentCommissionList() {

    HibernateSessionProxy session = (HibernateSessionProxy) entityManager.getDelegate();
    Criteria crit = session.createCriteria(PaymentCommission.class);

    if (getCode() != null && getCode().length() > 0) {
        crit.add(Restrictions.like("code", getCode() + "%"));
    }/* w w  w.ja  v a2  s  . c  om*/

    if (getName() != null && getName().length() > 0) {
        crit.add(Restrictions.like("name", getName() + "%"));
    }

    if (getPaymentActionType() != null) {
        crit.add(Restrictions.eq("paymentActionType", getPaymentActionType()));
    }

    //FIXME: projection eklemeli.
    crit.setMaxResults(30);
    crit.setCacheable(true);
    paymentCommissionList = crit.list();
}

From source file:com.ut.tekir.invoice.yeni.LimitationChecker.java

License:LGPL

@SuppressWarnings("unchecked")
public void getPrices() {

    HibernateSessionProxy session = (HibernateSessionProxy) getEntityManager().getDelegate();

    Criteria ecrit = buildCriteriaForWarehouse().getExecutableCriteria(session);
    ecrit.setCacheable(true);
    ecrit.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    warehouseResult = ecrit.list();/*w  w w  .  j  a va  2 s. c  om*/
    calculateSummary();

}

From source file:com.ut.tekir.report.AccountTxnReportBean.java

License:LGPL

@SuppressWarnings("unchecked")
public void executeReport() {

    HibernateSessionProxy session = (HibernateSessionProxy) entityManager.getDelegate();

    Criteria ecrit = buildCriteria().getExecutableCriteria(session);
    ecrit.setCacheable(true);
    setResultList(ecrit.list());/*from w w w  .  jav a2 s  .  c o  m*/

    // log.debug("Result : #0", getResultList());

    //calculateSummary();
}

From source file:com.ut.tekir.report.TaxTxnReportBean.java

License:LGPL

@SuppressWarnings("unchecked")
public void search() {

    HibernateSessionProxy session = (HibernateSessionProxy) entityManager.getDelegate();

    Criteria ecrit = buildCriteria().getExecutableCriteria(session);
    ecrit.setCacheable(false);
    setResultList(ecrit.list());//from w  w  w.j a  v a2 s .  c  o  m

}

From source file:com.ut.tekir.stock.BarcodePrintBrowseBean.java

License:LGPL

@Override
public void search() {
    manualFlush();/*from w  w  w . j a v a 2  s  .  c  o m*/

    log.debug("Search Execute");

    HibernateSessionProxy session = (HibernateSessionProxy) getEntityManager().getDelegate();

    Criteria ecrit = buildCriteria().getExecutableCriteria(session);
    ecrit.setCacheable(false);
    ecrit.setMaxResults(100);

    entityList = new ArrayList<BarcodeTxnFilterModel>();

    BarcodeTxnFilterModel fm = null;
    for (BarcodeTxn txn : (List<BarcodeTxn>) ecrit.list()) {
        PriceItemDetail item = null;
        fm = new BarcodeTxnFilterModel();
        fm.setItem(txn);
        try {
            item = priceProvider.findSalePriceItemDetailForProduct(txn.getProduct());
        } catch (Exception e) {
            log.info("Fiyat bulunamad! Sebebi ", e);
        }

        if (item == null) {
            fm.setHasPrice(false);
        } else {
            MoneySet grossPrice = new MoneySet();
            grossPrice.moveFieldsOf(item.getGrossPrice());
            fm.setGrossPrice(grossPrice);
            //            fm.setGrossPrice(item.getGrossPrice());
        }
        entityList.add(fm);
    }

}

From source file:com.ut.tekir.stock.ProductTxnReportBean.java

License:LGPL

@SuppressWarnings("unchecked")
@Override/*from  www .j a v  a2 s  .c  om*/
public void search() {
    //super.search();

    HibernateSessionProxy session = (HibernateSessionProxy) getEntityManager().getDelegate();

    Criteria ecrit = buildCriteria().getExecutableCriteria(session);
    ecrit.setCacheable(true);

    List ls = ecrit.list();

    setEntityList(ls);

}

From source file:com.ut.tekir.stock.ProductTxnReportBean.java

License:LGPL

@SuppressWarnings("unchecked")
public void getPrices() {

    if (this.filterModel.isEmpty()) {
        facesMessages.add("Ltfen en az bir alan doldurunuz.");
        return;/*w  ww  .  ja va2 s  . c  om*/
    }

    HibernateSessionProxy session = (HibernateSessionProxy) getEntityManager().getDelegate();

    Criteria ecrit = buildCriteriaForPrice(TradeAction.Purchase).getExecutableCriteria(session);
    //ecrit.setCacheable(true);

    List ls = ecrit.list();
    setPurchaseEntityList(ls);

    setProductList(null);
    ecrit = buildCriteriaForProduct().getExecutableCriteria(session);
    ls = ecrit.list();
    setProductList(ls);

    //        
    //        setEntityList(null);
    //        if (ls.size()>0){
    //           setEntityList(ls);
    //        }
    //      

    ecrit = buildCriteriaForPrice(TradeAction.Sale).getExecutableCriteria(session);
    ecrit.setCacheable(true);

    ls = ecrit.list();

    //        if (ls.size()>0){
    //           setEntityList(ls);
    //        }
    //        
    setSaleEntityList(ls);

    ecrit = buildCriteriaForWarehouse().getExecutableCriteria(session);
    ecrit.setCacheable(true);
    ecrit.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    warehouseResult = ecrit.list();
    calculateSummary();

    ecrit = buildCriteriaForPriceList(TradeAction.Sale).getExecutableCriteria(session);
    ls = ecrit.list();
    setSalePriceListResult(ls);

    ecrit = buildCriteriaForPriceList(TradeAction.Purchase).getExecutableCriteria(session);
    ls = ecrit.list();
    setPurchasePriceListResult(ls);

}

From source file:com.ut.tekir.stock.StockSuggestionBean.java

License:LGPL

public void selectExpenseAndDiscountList() {

    HibernateSessionProxy session = (HibernateSessionProxy) entityManager.getDelegate();
    Criteria crit = session.createCriteria(Product.class);

    if (getCode() != null && getCode().length() > 0) {
        crit.add(Restrictions.like("this.code", getCode() + "%"));
    }/*ww w .  ja va 2s . c  o m*/

    if (getName() != null && getName().length() > 0) {
        crit.add(Restrictions.like("this.name", getName() + "%"));
    }

    if (getProductType() != null && getProductType() == ProductType.Unknown) {
        crit.add(Restrictions.or(Restrictions.eq("this.productType", ProductType.Expense),
                Restrictions.eq("this.productType", ProductType.Discount)));
    } else {
        crit.add(Restrictions.eq("this.productType", getProductType()));
    }

    crit.setProjection(Projections.projectionList().add(Projections.property("code"), "code")
            .add(Projections.property("name"), "name").add(Projections.property("productType"), "productType"));

    crit.add(Restrictions.eq("active", true));

    crit.setMaxResults(30);
    crit.setCacheable(true);
    //TODO: Map niye almyor kine?
    //crit.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    expenseAndDiscountList = crit.list();

}

From source file:cz.muni.fi.spc.SchedVis.model.BaseEntity.java

License:Open Source License

/**
 * Get a fresh criteria query. Using this method violates JPA as it does not
 * support criteria queries (JPA 1, that is) and thus locks the application
 * to Hibernate.//from w w w  .  j  a  v  a  2 s.co m
 * 
 * @param clazz
 *          The class on which the Criteria query will operate.
 * @return New criteria query.
 */
protected static Criteria getCriteria(final Class<?> clazz) {
    final Criteria crit = BaseEntity.getSession(Database.getEntityManager()).createCriteria(clazz);
    crit.setCacheable(true);
    return crit;
}

From source file:de.iew.framework.persistence.hibernate.HbmMessageBundleDaoImpl.java

License:Apache License

public List<Locale> getSupportedLocales() {
    Criteria crit = getCurrentSession().createCriteria(TextItem.class).setCacheable(true)
            .setProjection(Projections.distinct(Projections.projectionList()
                    .add(Projections.property("languageCode")).add(Projections.property("countryCode"))));
    crit.setCacheable(true);
    crit.setResultTransformer(LocaleTupleResultTransformer.DEFAULT);
    return crit.list();
}