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.sapienter.jbilling.server.util.db.AbstractDAS.java

License:Open Source License

@SuppressWarnings("unchecked")
protected T findByCriteriaSingle(Criterion... criterion) {
    Criteria crit = getSession().createCriteria(getPersistentClass());
    for (Criterion c : criterion) {
        crit.add(c);/*from  w w  w .  j a  v a 2  s  .  c o  m*/
    }
    crit.setCacheable(queriesCached);
    return (T) crit.uniqueResult();
}

From source file:com.thoughtworks.go.server.dao.AccessTokenSqlMapDao.java

License:Apache License

@Override
public List<AccessToken> findAllTokensForUser(String username, AccessTokenFilter filter) {
    return (List<AccessToken>) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
        Criteria criteria = sessionFactory.getCurrentSession().createCriteria(AccessToken.class)
                .add(Restrictions.eq("username", username))
                .add(Restrictions.eq("deletedBecauseUserDeleted", false));

        filter.applyTo(criteria);/*from  ww  w  . j a va 2s .c  om*/

        return criteria.setCacheable(true).list();
    });
}

From source file:com.thoughtworks.go.server.dao.AccessTokenSqlMapDao.java

License:Apache License

@Override
public List<AccessToken> findAllTokens(AccessTokenFilter filter) {
    return transactionTemplate.execute(status -> {
        Criteria criteria = sessionFactory.getCurrentSession().createCriteria(AccessToken.class);

        filter.applyTo(criteria);//from w  ww  . j  a v  a2  s . c  om

        return criteria.setCacheable(true).list();
    });
}

From source file:com.thoughtworks.go.server.dao.EnvironmentVariableSqlMapDao.java

License:Apache License

public EnvironmentVariables load(final Long entityId, final EnvironmentVariableType type) {
    List<EnvironmentVariable> result = (List<EnvironmentVariable>) transactionTemplate
            .execute((TransactionCallback) transactionStatus -> {
                Criteria criteria = sessionFactory.getCurrentSession().createCriteria(EnvironmentVariable.class)
                        .add(Restrictions.eq("entityId", entityId))
                        .add(Restrictions.eq("entityType", type.toString())).addOrder(Order.asc("id"));
                criteria.setCacheable(true);
                return criteria.list();
            });/* w w w .  j  av a  2s .c  o  m*/
    return new EnvironmentVariables(result);
}

From source file:com.thoughtworks.go.server.dao.PipelineStateDao.java

License:Apache License

public List<String> lockedPipelines() {
    return (List<String>) transactionTemplate.execute(new TransactionCallback() {
        @Override//from   w  ww  .j  a  va  2 s.  c o  m
        public Object doInTransaction(TransactionStatus status) {
            PropertyProjection pipelineName = Projections.property("pipelineName");
            Criteria criteria = sessionFactory.getCurrentSession().createCriteria(PipelineState.class)
                    .setProjection(pipelineName).add(Restrictions.eq("locked", true));
            criteria.setCacheable(false);
            List<String> list = criteria.list();
            return list;
        }
    });
}

From source file:com.thoughtworks.go.server.dao.UserSqlMapDao.java

License:Apache License

public Users findNotificationSubscribingUsers() {
    return (Users) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
        Criteria criteria = sessionFactory.getCurrentSession().createCriteria(User.class);
        criteria.setCacheable(true);
        criteria.add(Restrictions.isNotEmpty("notificationFilters"));
        criteria.add(Restrictions.eq("enabled", true));
        return new Users(criteria.list());
    });//from   w w  w . ja v  a2s.  com
}

From source file:com.ut.tekir.contact.ContactSuggestionBean.java

License:LGPL

public void selectCustomerList() {

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

    Criteria crit = session.createCriteria(Contact.class);

    if (getCode() != null && getCode().length() > 0) {
        crit.add(Restrictions.ilike("this.code", getCode(), MatchMode.START));
    }/*w  w  w  .java 2s .co m*/

    if (getCompany() != null && !getCompany().isEmpty()) {
        crit.add(Restrictions.ilike("this.company", getCompany(), MatchMode.START));
    }

    if (getSsn() != null && !getSsn().isEmpty()) {
        crit.add(Restrictions.ilike("this.ssn", getSsn(), MatchMode.START));
    }

    if (getTaxNumber() != null & !getTaxNumber().isEmpty()) {
        crit.add(Restrictions.ilike("this.taxNumber", getTaxNumber(), MatchMode.START));
    }

    if (getFullname() != null && getFullname().length() > 0) {
        crit.add(Restrictions.ilike("this.fullname", getFullname(), MatchMode.ANYWHERE));
    }
    if (getType() != null && getType() != ContactType.All) {
        crit.add(Restrictions.eq("this." + getType().toString().toLowerCase() + "Type", Boolean.TRUE));
    }
    if (getCategory() != null) {
        crit.add(Restrictions.eq("this.category", getCategory()));
    }
    if (getExCode1() != null & !getExCode1().isEmpty()) {
        crit.add(Restrictions.ilike("this.exCode1", getExCode1(), MatchMode.START));
    }
    if (getExCode2() != null & !getExCode2().isEmpty()) {
        crit.add(Restrictions.ilike("this.exCode2", getExCode2(), MatchMode.START));
    }

    crit.setProjection(Projections.projectionList().add(Projections.property("code"), "code")
            .add(Projections.property("fullname"), "fullname")
            .add(Projections.property("customerType"), "customerType")
            .add(Projections.property("personnelType"), "personnelType")
            .add(Projections.property("agentType"), "agentType")
            .add(Projections.property("branchType"), "branchType")
            .add(Projections.property("providerType"), "providerType")
            .add(Projections.property("contactType"), "contactType")
            .add(Projections.property("allType"), "allType").add(Projections.property("id"), "id")
            .add(Projections.property("category"), "category")
            .add(Projections.property("taxNumber"), "taxNumber").add(Projections.property("ssn"), "ssn")
            .add(Projections.property("company"), "company").add(Projections.property("exCode2"), "exCode2")
            .add(Projections.property("exCode1"), "exCode1"));

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

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

}

From source file:com.ut.tekir.finance.BankCardSuggestionBean.java

License:LGPL

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

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

    crit.createAlias("this.country", "country", Criteria.LEFT_JOIN);
    crit.createAlias("this.bank", "bank", Criteria.LEFT_JOIN);

    if (getCode() != null && getCode().length() > 0) {
        crit.add(Restrictions.like("code", getCode() + "%"));
    }//from w w  w  .j  a  v  a2s  .  co m

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

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

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

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

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

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

From source file:com.ut.tekir.finance.FinanceTxnReportBean.java

License:LGPL

@SuppressWarnings("unchecked")
@Override//  w w  w.ja va 2 s. c  o  m
public void search() {
    //super.search();
    log.debug("Rapora Balyoruz");

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

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

    log.debug("Kriterler build edildi");

    List ls = ecrit.list();

    log.debug("Sorgu ekildi");

    if (filterModel.getLocalCurrencyOnly()) {

        log.debug("Gruplama yapcaz...");

        List<FinanceTxn> res = new ArrayList<FinanceTxn>();
        FinanceTxn row;

        for (Iterator it = ls.iterator(); it.hasNext();) {
            Object obj[] = (Object[]) it.next();

            row = new FinanceTxn();
            row.setContact(new Contact());

            row.setDocumentType((DocumentType) obj[0]);
            row.setDocumentId((Long) obj[1]);
            row.setSerial((String) obj[2]);
            row.setReference((String) obj[3]);
            row.setDate((Date) obj[4]);
            row.getContact().setName((String) obj[5]);
            row.getContact().setCode((String) obj[6]);
            row.setCode((String) obj[7]);
            row.setInfo((String) obj[8]);
            row.setAction((FinanceAction) obj[9]);
            row.getAmount().setLocalAmount((BigDecimal) obj[10]);
            row.setProcessType((AdvanceProcessType) obj[11]);
            row.getAmount().setCurrency((String) obj[12]);
            //log.info("istakip icin arraydegeri : #0", obj[13]);
            if (obj[13] != null) {
                row.setWorkBunch((WorkBunch) obj[13]);
                //log.info("istakip icin eklenen1 : #0", row.getWorkBunch().getCode());
            }

            res.add(row);

            log.debug("Row : #0", row);

        }

        setEntityList(res);

    } else {
        setEntityList(ls);
    }

}

From source file:com.ut.tekir.finance.SecuritySuggestionBean.java

License:LGPL

public void selectSecurityList() {

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

    if (getCode() != null && getCode().length() > 0) {
        crit.add(Restrictions.like("code", getCode() + "%"));
    }/*from  w w w. j  a  va 2  s  .  co  m*/

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

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

    crit.setMaxResults(30);
    crit.setCacheable(true);
    securityList = crit.list();

}