Tabnine Logo
Criteria.setCacheable
Code IndexAdd Tabnine 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)

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

  • Reading from database using SQL prepared statement
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • getExternalFilesDir (Context)
  • getContentResolver (Context)
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • Table (org.hibernate.mapping)
    A relational table
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now