本文整理了Java中org.hibernate.query.Query.setCacheable
方法的一些代码示例,展示了Query.setCacheable
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setCacheable
方法的具体详情如下:
包路径:org.hibernate.query.Query
类名称:Query
方法名:setCacheable
暂无
代码示例来源:origin: hibernate/hibernate-orm
public HolidayCalendar getHolidayCalendar() {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
List calendars = session.createQuery("from HolidayCalendar").setCacheable(true).list();
session.getTransaction().commit();
return calendars.isEmpty() ? null : (HolidayCalendar)calendars.get(0);
}
}
代码示例来源:origin: hibernate/hibernate-orm
public HolidayCalendar getHolidayCalendar() {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
List calendars = session.createQuery("from HolidayCalendar").setCacheable(true).list();
session.getTransaction().commit();
return calendars.isEmpty() ? null : (HolidayCalendar)calendars.get(0);
}
}
代码示例来源:origin: hibernate/hibernate-orm
public List listEvents() {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
List result = session.createQuery("from Event").setCacheable(true).list();
session.getTransaction().commit();
return result;
}
代码示例来源:origin: hibernate/hibernate-orm
public List listEvents() {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
List result = session.createQuery("from Event").setCacheable(true).list();
session.getTransaction().commit();
return result;
}
代码示例来源:origin: hibernate/hibernate-orm
public Long createHolidayCalendar() {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
// delete all existing calendars
List calendars = session.createQuery("from HolidayCalendar").setCacheable(true).list();
for (ListIterator li = calendars.listIterator(); li.hasNext(); ) {
session.delete(li.next());
}
HolidayCalendar calendar = new HolidayCalendar();
calendar.init();
Long calendarId = (Long)session.save(calendar);
session.getTransaction().commit();
return calendarId;
}
代码示例来源:origin: hibernate/hibernate-orm
public Long createHolidayCalendar() {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
// delete all existing calendars
List calendars = session.createQuery("from HolidayCalendar").setCacheable(true).list();
for (ListIterator li = calendars.listIterator(); li.hasNext(); ) {
session.delete(li.next());
}
HolidayCalendar calendar = new HolidayCalendar();
calendar.init();
Long calendarId = (Long)session.save(calendar);
session.getTransaction().commit();
return calendarId;
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void test_hql_api_basic_usage_example() {
doInJPA( this::entityManagerFactory, entityManager -> {
Session session = entityManager.unwrap( Session.class );
//tag::hql-api-basic-usage-example[]
org.hibernate.query.Query query = session.createQuery(
"select p " +
"from Person p " +
"where p.name like :name" )
// timeout - in seconds
.setTimeout( 2 )
// write to L2 caches, but do not read from them
.setCacheMode( CacheMode.REFRESH )
// assuming query cache was enabled for the SessionFactory
.setCacheable( true )
// add a comment to the generated SQL if enabled via the hibernate.use_sql_comments configuration property
.setComment( "+ INDEX(p idx_person_name)" );
//end::hql-api-basic-usage-example[]
});
}
代码示例来源:origin: hibernate/hibernate-orm
MyReferenceData queried = (MyReferenceData) s.createQuery( "from MyReferenceData" ).setCacheable( true ).list().get( 0 );
s.getTransaction().commit();
s.close();
代码示例来源:origin: hibernate/hibernate-orm
MyEnhancedReferenceData queried = (MyEnhancedReferenceData) s.createQuery( "from MyEnhancedReferenceData" ).setCacheable( true ).list().get( 0 );
s.getTransaction().commit();
s.close();
代码示例来源:origin: hibernate/hibernate-orm
.setCacheable( true )
.list();
assertEquals( "incorrect result size", 2, results.size() );
long initCacheHits = stats.getCacheHitCount();
results = session.createQuery( "select new Animal(an.description, an.bodyWeight) from Animal an" )
.setCacheable( true )
.list();
assertEquals( "dynamic intantiation query not served from cache", initCacheHits + 1, stats.getCacheHitCount() );
代码示例来源:origin: hibernate/hibernate-orm
protected void setQueryProperties(Query query) {
if ( maxResults != null ) {
query.setMaxResults( maxResults );
}
if ( firstResult != null ) {
query.setFirstResult( firstResult );
}
if ( cacheable != null ) {
query.setCacheable( cacheable );
}
if ( cacheRegion != null ) {
query.setCacheRegion( cacheRegion );
}
if ( comment != null ) {
query.setComment( comment );
}
if ( flushMode != null ) {
query.setFlushMode( flushMode );
}
if ( cacheMode != null ) {
query.setCacheMode( cacheMode );
}
if ( timeout != null ) {
query.setTimeout( timeout );
}
if ( lockOptions != null && lockOptions.getLockMode() != LockMode.NONE ) {
query.setLockMode( REFERENCED_ENTITY_ALIAS, lockOptions.getLockMode() );
}
}
代码示例来源:origin: hibernate/hibernate-orm
.setCacheable( true )
.uniqueResult();
assertTrue( child.getParent().getChildren().contains( child ) );
.setCacheable( true )
.uniqueResult();
assertTrue( child.getParent().getChildren().contains( child ) );
代码示例来源:origin: hibernate/hibernate-orm
List list = s.createQuery( "from Animal a left join fetch a.offspring" ).setCacheable( true ).list();
assertEquals( 0, sessionFactory().getStatistics().getQueryCacheHitCount() );
assertEquals( 1, sessionFactory().getStatistics().getQueryCachePutCount() );
list = s.createQuery( "select a from Animal a left join fetch a.offspring" ).setCacheable( true ).list();
assertEquals( 1, sessionFactory().getStatistics().getQueryCacheHitCount() );
assertEquals( 1, sessionFactory().getStatistics().getQueryCachePutCount() );
list = s.createQuery( "select a, o from Animal a left join a.offspring o" ).setCacheable( true ).list();
assertEquals( 1, sessionFactory().getStatistics().getQueryCacheHitCount() );
assertEquals( 2, sessionFactory().getStatistics().getQueryCachePutCount() );
代码示例来源:origin: hibernate/hibernate-orm
List list = s.createQuery( "from Animal a left join fetch a.mother" ).setCacheable( true ).list();
assertEquals( 0, sessionFactory().getStatistics().getQueryCacheHitCount() );
assertEquals( 1, sessionFactory().getStatistics().getQueryCachePutCount() );
list = s.createQuery( "select a from Animal a left join fetch a.mother" ).setCacheable( true ).list();
assertEquals( 1, sessionFactory().getStatistics().getQueryCacheHitCount() );
assertEquals( 1, sessionFactory().getStatistics().getQueryCachePutCount() );
list = s.createQuery( "select a, m from Animal a left join a.mother m" ).setCacheable( true ).list();
assertEquals( 1, sessionFactory().getStatistics().getQueryCacheHitCount() );
assertEquals( 2, sessionFactory().getStatistics().getQueryCachePutCount() );
代码示例来源:origin: hibernate/hibernate-orm
"where p.name = :name")
.setParameter( "name", "John Doe")
.setCacheable(true)
.list();
"where p.id > :id")
.setParameter( "id", 0L)
.setCacheable(true)
.setCacheRegion( "query.cache.person" )
.list();
"where p.id > :id")
.setParameter( "id", 0L)
.setCacheable(true)
.setCacheRegion( "query.cache.person" )
.setCacheMode( CacheMode.REFRESH )
.setCacheable( true )
.setCacheMode( CacheMode.REFRESH )
.list();
代码示例来源:origin: hibernate/hibernate-orm
protected void initQueryFromNamedDefinition(Query query, NamedQueryDefinition nqd) {
// todo : cacheable and readonly should be Boolean rather than boolean...
query.setCacheable( nqd.isCacheable() );
query.setCacheRegion( nqd.getCacheRegion() );
query.setReadOnly( nqd.isReadOnly() );
if ( nqd.getTimeout() != null ) {
query.setTimeout( nqd.getTimeout() );
}
if ( nqd.getFetchSize() != null ) {
query.setFetchSize( nqd.getFetchSize() );
}
if ( nqd.getCacheMode() != null ) {
query.setCacheMode( nqd.getCacheMode() );
}
if ( nqd.getComment() != null ) {
query.setComment( nqd.getComment() );
}
if ( nqd.getFirstResult() != null ) {
query.setFirstResult( nqd.getFirstResult() );
}
if ( nqd.getMaxResults() != null ) {
query.setMaxResults( nqd.getMaxResults() );
}
if ( nqd.getFlushMode() != null ) {
query.setHibernateFlushMode( nqd.getFlushMode() );
}
}
代码示例来源:origin: hibernate/hibernate-orm
queryString,
Object[].class
).setCacheable( true ).uniqueResult();
assertEquals( 2, result.length );
assertTrue( AnEntity.class.isInstance( result[0] ) );
queryString,
Object[].class
).setCacheable( true ).uniqueResult();
assertEquals( 2, result.length );
assertTrue( AnEntity.class.isInstance( result[0] ) );
代码示例来源:origin: hibernate/hibernate-orm
queryString,
AnEntity.class
).setCacheable( true ).uniqueResult();
assertNull( anEntity );
queryString,
AnEntity.class
).setCacheable( true ).uniqueResult();
assertNull( anEntity );
代码示例来源:origin: hibernate/hibernate-orm
queryString,
AnEntity.class
).setCacheable( true ).uniqueResult();
assertNull( anEntity.otherEntity );
queryString,
AnEntity.class
).setCacheable( true ).uniqueResult();
assertNull( anEntity.otherEntity );
代码示例来源:origin: hibernate/hibernate-orm
queryString,
AnEntity.class
).setCacheable( true ).uniqueResult();
assertNull( anEntity.otherEntity );
queryString,
AnEntity.class
).setCacheable( true ).uniqueResult();
assertNull( anEntity.otherEntity );
内容来源于网络,如有侵权,请联系作者删除!