Codota Logo
Criteria.setCacheable
Code IndexAdd Codota to your IDE (free)

How to use
setCacheable
method
in
org.hibernate.Criteria

Best Java code snippets using org.hibernate.Criteria.setCacheable (Showing top 20 results out of 342)

  • Common ways to obtain Criteria
private void myMethod () {
Criteria c =
  • Codota IconSession session;Class persistentClass;session.createCriteria(persistentClass)
  • Smart code suggestions by Codota
}
origin: gocd/gocd

  @Override
  public Object doInTransaction(TransactionStatus transactionStatus) {
    return sessionFactory.getCurrentSession()
        .createCriteria(PipelineState.class)
        .add(Restrictions.eq("pipelineName", pipelineName))
        .setCacheable(false).uniqueResult();
  }
});
origin: gocd/gocd

  @Override
  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;
  }
});
origin: gocd/gocd

@Override
public VersionInfo findByComponentName(final String name) {
  return (VersionInfo) transactionTemplate.execute((TransactionCallback) transactionStatus -> sessionFactory.getCurrentSession()
      .createCriteria(VersionInfo.class)
      .add(Restrictions.eq("componentName", name))
      .setCacheable(true).uniqueResult());
}
origin: gocd/gocd

@Override
public JobAgentMetadata load(final Long jobId) {
  return (JobAgentMetadata) transactionTemplate.execute((TransactionCallback) transactionStatus -> sessionFactory.getCurrentSession()
      .createCriteria(JobAgentMetadata.class)
      .add(Restrictions.eq("jobId", jobId))
      .setCacheable(true).uniqueResult());
}
origin: gocd/gocd

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());
  });
}
origin: gocd/gocd

public User findUser(final String userName) {
  return (User) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
    User user = (User) sessionFactory.getCurrentSession()
        .createCriteria(User.class)
        .add(Restrictions.eq("name", userName))
        .setCacheable(true).uniqueResult();
    return user == null ? new NullUser() : user;
  });
}
origin: gocd/gocd

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();
  });
  return new EnvironmentVariables(result);
}
origin: hibernate/hibernate-orm

private State getState(Session s, String name) {
  Criteria criteria = s.createCriteria( State.class );
  criteria.add( Restrictions.eq( "name", name ) );
  criteria.setCacheable( true );
  return (State) criteria.list().get( 0 );
}
origin: hibernate/hibernate-orm

/**
 * Use a Criteria query - see FORGE-247
 */
public List listEventsWithCriteria() {
  Session session = sessionFactory.getCurrentSession();
  session.beginTransaction();
  List result = session.createCriteria(Event.class)
    .setCacheable(true)
    .list();
  session.getTransaction().commit();
  return result;
}
origin: hibernate/hibernate-orm

/**
 * Use a Criteria query - see FORGE-247
 */
public List listEventsWithCriteria() {
  Session session = sessionFactory.getCurrentSession();
  session.beginTransaction();
  List result = session.createCriteria(Event.class)
    .setCacheable(true)
    .list();
  session.getTransaction().commit();
  return result;
}
origin: BroadleafCommerce/BroadleafCommerce

@Override
public List<Offer> readOffersByAutomaticDeliveryType() {
  //TODO change this to a JPA criteria
  Criteria criteria = ((HibernateEntityManager) em).getSession().createCriteria(OfferImpl.class);
  Date myDate = getCurrentDateAfterFactoringInDateResolution();
  Calendar c = Calendar.getInstance();
  c.setTime(myDate);
  c.add(Calendar.DATE, +1);
  criteria.add(Restrictions.lt("startDate", c.getTime()));
  c = Calendar.getInstance();
  c.setTime(myDate);
  c.add(Calendar.DATE, -1);
  criteria.add(Restrictions.or(Restrictions.isNull("endDate"), Restrictions.gt("endDate", c.getTime())));
  criteria.add(Restrictions.or(Restrictions.eq("archiveStatus.archived", 'N'),
      Restrictions.isNull("archiveStatus.archived")));
  
  criteria.add(Restrictions.eq("automaticallyAdded", true));
  criteria.setCacheable(true);
  criteria.setCacheRegion("query.Offer");
  return criteria.list();
}
origin: gocd/gocd

public long enabledUserCount() {
  Long value = (Long) goCache.get(ENABLED_USER_COUNT_CACHE_KEY);
  if (value != null) {
    return value;
  }
  synchronized (ENABLED_USER_COUNT_CACHE_KEY) {
    value = (Long) goCache.get(ENABLED_USER_COUNT_CACHE_KEY);
    if (value == null) {
      value = hibernateTemplate().execute(session -> (Long) session.createCriteria(User.class).add(Restrictions.eq("enabled", true)).setProjection(Projections.rowCount()).setCacheable(true).uniqueResult());
      goCache.put(ENABLED_USER_COUNT_CACHE_KEY, value);
    }
    return value;
  }
}
origin: hibernate/hibernate-orm

private Criteria getCriteria(Session s) {
  Criteria crit = s.createCriteria( A.class, "anAlias" );
  crit.add( Restrictions.naturalId().set( "name", "name1" ) );
  crit.setFlushMode( FlushMode.COMMIT );
  crit.setCacheable( true );
  return crit;
}
origin: gocd/gocd

@Override
public Plugin findPlugin(final String pluginId) {
  String cacheKey = cacheKeyForPluginSettings(pluginId);
  Plugin plugin = (Plugin) goCache.get(cacheKey);
  if (plugin != null) {
    return plugin;
  }
  synchronized (cacheKey) {
    plugin = (Plugin) goCache.get(cacheKey);
    if (plugin != null) {
      return plugin;
    }
    plugin = (Plugin) transactionTemplate.execute((TransactionCallback) transactionStatus -> sessionFactory.getCurrentSession()
        .createCriteria(Plugin.class)
        .add(Restrictions.eq("pluginId", pluginId))
        .setCacheable(true).uniqueResult());
    if (plugin != null) {
      goCache.put(cacheKey, plugin);
      return plugin;
    }
    goCache.remove(cacheKey);
    return new NullPlugin();
  }
}
origin: hibernate/hibernate-orm

  @Override
  protected Object getResults(Session s, boolean isSingleResult) throws Exception {
    Criteria criteria = getCriteria( s ).setCacheable( getQueryCacheMode() != CacheMode.IGNORE ).setCacheMode( getQueryCacheMode() );
    return ( isSingleResult ? criteria.uniqueResult() : criteria.list() );
  }
}
origin: hibernate/hibernate-orm

@Test
public void testNaturalIdCriteria() {
  Session s = openSession();
  s.beginTransaction();
  Account u = new Account(new AccountId(1), "testAcct" );
  s.persist( u );
  s.getTransaction().commit();
  s.close();
  s = openSession();
  s.beginTransaction();
  u = ( Account ) s.createCriteria( Account.class )
      .add( Restrictions.naturalId().set( "shortCode", "testAcct" ) )
      .setCacheable( true )
      .uniqueResult();
  assertNotNull( u );
  s.getTransaction().commit();
  s.close();
  s = openSession();
  s.beginTransaction();
  s.createQuery( "delete Account" ).executeUpdate();
  s.getTransaction().commit();
  s.close();
}
origin: spring-projects/spring-framework

/**
 * Prepare the given Criteria object, applying cache settings and/or
 * a transaction timeout.
 * @param criteria the Criteria object to prepare
 * @see #setCacheQueries
 * @see #setQueryCacheRegion
 */
protected void prepareCriteria(Criteria criteria) {
  if (isCacheQueries()) {
    criteria.setCacheable(true);
    if (getQueryCacheRegion() != null) {
      criteria.setCacheRegion(getQueryCacheRegion());
    }
  }
  if (getFetchSize() > 0) {
    criteria.setFetchSize(getFetchSize());
  }
  if (getMaxResults() > 0) {
    criteria.setMaxResults(getMaxResults());
  }
  ResourceHolderSupport sessionHolder =
      (ResourceHolderSupport) TransactionSynchronizationManager.getResource(obtainSessionFactory());
  if (sessionHolder != null && sessionHolder.hasTimeout()) {
    criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
  }
}
origin: hibernate/hibernate-orm

u = ( User ) s.createCriteria( User.class )
    .add( Restrictions.naturalId().set( "userName", "steve" ) )
    .setCacheable( true )
    .uniqueResult();
assertNotNull( u );
u = ( User ) s.createCriteria( User.class )
    .add( Restrictions.naturalId().set( "userName", "steve" ) )
    .setCacheable( true )
    .uniqueResult();
assertNotNull( u );
origin: org.springframework/spring-orm

/**
 * Prepare the given Criteria object, applying cache settings and/or
 * a transaction timeout.
 * @param criteria the Criteria object to prepare
 * @see #setCacheQueries
 * @see #setQueryCacheRegion
 */
protected void prepareCriteria(Criteria criteria) {
  if (isCacheQueries()) {
    criteria.setCacheable(true);
    if (getQueryCacheRegion() != null) {
      criteria.setCacheRegion(getQueryCacheRegion());
    }
  }
  if (getFetchSize() > 0) {
    criteria.setFetchSize(getFetchSize());
  }
  if (getMaxResults() > 0) {
    criteria.setMaxResults(getMaxResults());
  }
  ResourceHolderSupport sessionHolder =
      (ResourceHolderSupport) TransactionSynchronizationManager.getResource(obtainSessionFactory());
  if (sessionHolder != null && sessionHolder.hasTimeout()) {
    criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
  }
}
origin: hibernate/hibernate-orm

Criteria criteria = s.createCriteria( Citizen.class );
criteria.add( Restrictions.naturalId().set( "ssn", "1234" ).set( "state", france ) );
criteria.setCacheable( true );
org.hibernateCriteriasetCacheable

Javadoc

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

Popular methods of Criteria

  • list
    Get the results.
  • add
    Add a Criterion to constrain the results to be retrieved.
  • uniqueResult
    Convenience method to return a single instance that matches the query, or null if the query returns
  • addOrder
    Add an Order to the result set.
  • setProjection
    Used to specify that the query results will be a projection (scalar in nature). Implicitly specifies
  • setMaxResults
    Set a limit upon the number of objects to be retrieved.
  • setFirstResult
    Set the first result to be retrieved.
  • setResultTransformer
    Set a strategy for handling the query results. This determines the "shape" of the query result.
  • createAlias
    Join an association using the specified join-type, assigning an alias to the joined association. The
  • createCriteria
    Create a new Criteria, "rooted" at the associated entity, using the specified join type.
  • setFetchMode
    Specify an association fetching strategy for an association or a collection of values.
  • setFetchSize
    Set a fetch size for the underlying JDBC query.
  • setFetchMode,
  • setFetchSize,
  • scroll,
  • setLockMode,
  • setReadOnly,
  • setCacheRegion,
  • setTimeout,
  • setCacheMode,
  • setFlushMode

Popular in Java

  • Finding current android device location
  • runOnUiThread (Activity)
  • onCreateOptionsMenu (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • Dictionary (java.util)
    The Dictionary class is the abstract parent of any class, such as Hashtable, which maps keys to valu
  • LinkedHashMap (java.util)
    Hash table and linked list implementation of the Map interface, with predictable iteration order. Th
  • Reference (javax.naming)
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.This exception may include information for locating the er
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now