本文整理汇总了Java中org.hibernate.annotations.QueryHints类的典型用法代码示例。如果您正苦于以下问题:Java QueryHints类的具体用法?Java QueryHints怎么用?Java QueryHints使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QueryHints类属于org.hibernate.annotations包,在下文中一共展示了QueryHints类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: queryLatestGreetings
import org.hibernate.annotations.QueryHints; //导入依赖的package包/类
@GET
@Path("greetings/latest")
@Produces(MediaType.TEXT_PLAIN)
public Response queryLatestGreetings(@QueryParam("maxResults") int maxResults) {
EntityManager em = Hibernate.createEntityManager();
try {
final List<Tuple> greetings = em
.createQuery("SELECT g.id, g.date, g.author.name, g.content FROM Greeting g ORDER by g.date DESC", Tuple.class)
.setHint(QueryHints.READ_ONLY, "true")
.setMaxResults(maxResults == 0 ? 500 : maxResults)
.getResultList();
em.close();
return RequestStats.wrap(Response.ok(toString(greetings)));
} catch (QueryTimeoutException e) {
LOGGER.severe("Caught QueryTimeoutException");
return Response.status(Response.Status.SERVICE_UNAVAILABLE).build();
}
}
开发者ID:bedatadriven,项目名称:appengine-hibernate,代码行数:24,代码来源:TestResources.java
示例2: getCacheMode
import org.hibernate.annotations.QueryHints; //导入依赖的package包/类
public CacheMode getCacheMode(String query) {
String hitName = QueryHints.CACHE_MODE;
String value =(String) hintsMap.get( hitName );
if ( value == null ) {
return null;
}
try {
return CacheMode.interpretExternalSetting( value );
}
catch ( MappingException e ) {
throw new AnnotationException( "Unknown CacheMode in hint: " + query + ":" + hitName, e );
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:QueryHintDefinition.java
示例3: getFlushMode
import org.hibernate.annotations.QueryHints; //导入依赖的package包/类
public FlushMode getFlushMode(String query) {
String hitName = QueryHints.FLUSH_MODE;
String value =(String) hintsMap.get( hitName );
if ( value == null ) {
return null;
}
try {
return FlushMode.interpretExternalSetting( value );
}
catch ( MappingException e ) {
throw new AnnotationException( "Unknown FlushMode in hint: " + query + ":" + hitName, e );
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:QueryHintDefinition.java
示例4: getTimeout
import org.hibernate.annotations.QueryHints; //导入依赖的package包/类
public Integer getTimeout(String queryName) {
Integer timeout = getInteger( queryName, QueryHints.TIMEOUT_JPA );
if ( timeout != null ) {
// convert milliseconds to seconds
timeout = (int) Math.round( timeout.doubleValue() / 1000.0 );
}
else {
// timeout is already in seconds
timeout = getInteger( queryName, QueryHints.TIMEOUT_HIBERNATE );
}
return timeout;
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:QueryHintDefinition.java
示例5: bindQuery
import org.hibernate.annotations.QueryHints; //导入依赖的package包/类
public static void bindQuery(NamedQuery queryAnn, Mappings mappings, boolean isDefault) {
if ( queryAnn == null ) return;
if ( BinderHelper.isEmptyAnnotationValue( queryAnn.name() ) ) {
throw new AnnotationException( "A named query must have a name when used in class or package level" );
}
//EJBQL Query
QueryHintDefinition hints = new QueryHintDefinition( queryAnn.hints() );
String queryName = queryAnn.query();
NamedQueryDefinition queryDefinition = new NamedQueryDefinitionBuilder( queryAnn.name() )
.setLockOptions( hints.determineLockOptions( queryAnn ) )
.setQuery( queryName )
.setCacheable( hints.getBoolean( queryName, QueryHints.CACHEABLE ) )
.setCacheRegion( hints.getString( queryName, QueryHints.CACHE_REGION ) )
.setTimeout( hints.getTimeout( queryName ) )
.setFetchSize( hints.getInteger( queryName, QueryHints.FETCH_SIZE ) )
.setFlushMode( hints.getFlushMode( queryName ) )
.setCacheMode( hints.getCacheMode( queryName ) )
.setReadOnly( hints.getBoolean( queryName, QueryHints.READ_ONLY ) )
.setComment( hints.getString( queryName, QueryHints.COMMENT ) )
.setParameterTypes( null )
.createNamedQueryDefinition();
if ( isDefault ) {
mappings.addDefaultQuery( queryDefinition.getName(), queryDefinition );
}
else {
mappings.addQuery( queryDefinition.getName(), queryDefinition );
}
if ( LOG.isDebugEnabled() ) {
LOG.debugf( "Binding named query: %s => %s", queryDefinition.getName(), queryDefinition.getQueryString() );
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:QueryBinder.java
示例6: getTimeout
import org.hibernate.annotations.QueryHints; //导入依赖的package包/类
private static Integer getTimeout(AnnotationInstance[] hints, String query) {
Integer timeout = getInteger( hints, QueryHints.TIMEOUT_JPA, query );
if ( timeout == null ) {
return getInteger( hints, QueryHints.TIMEOUT_HIBERNATE, query ); // timeout is already in seconds
}
return ( ( timeout + 500 ) / 1000 ); // convert milliseconds to seconds (rounded)
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:QueryBinder.java
示例7: getReferences
import org.hibernate.annotations.QueryHints; //导入依赖的package包/类
@Override
public Collection<MCRCategLinkReference> getReferences(String type) {
EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<MCRCategLinkReference> query = cb.createQuery(MCRCategLinkReference.class);
Root<MCRCategoryLinkImpl> li = query.from(LINK_CLASS);
Path<MCRCategLinkReference> objectReferencePath = li.get(MCRCategoryLinkImpl_.objectReference);
return em
.createQuery(
query.select(objectReferencePath)
.where(cb.equal(objectReferencePath.get(MCRCategLinkReference_.type), type)))
.setHint(QueryHints.READ_ONLY, "true")
.getResultList();
}
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:15,代码来源:MCRCategLinkServiceImpl.java
示例8: getTypes
import org.hibernate.annotations.QueryHints; //导入依赖的package包/类
@Override
public Collection<String> getTypes() {
EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> query = cb.createQuery(String.class);
Root<MCRCategoryLinkImpl> li = query.from(LINK_CLASS);
return em
.createQuery(
query
.distinct(true)
.select(li.get(MCRCategoryLinkImpl_.objectReference).get(MCRCategLinkReference_.type)))
.setHint(QueryHints.READ_ONLY, "true")
.getResultList();
}
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:15,代码来源:MCRCategLinkServiceImpl.java
示例9: getLinks
import org.hibernate.annotations.QueryHints; //导入依赖的package包/类
@Override
public Collection<MCRCategoryLink> getLinks(String type) {
EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<MCRCategoryLink> query = cb.createQuery(MCRCategoryLink.class);
Root<MCRCategoryLinkImpl> li = query.from(LINK_CLASS);
return em
.createQuery(
query
.where(
cb.equal(li.get(MCRCategoryLinkImpl_.objectReference).get(MCRCategLinkReference_.type), type)))
.setHint(QueryHints.READ_ONLY, "true")
.getResultList();
}
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:15,代码来源:MCRCategLinkServiceImpl.java
示例10: queryGreetings
import org.hibernate.annotations.QueryHints; //导入依赖的package包/类
@GET
@Path("greetings")
@Produces(MediaType.TEXT_PLAIN)
public Response queryGreetings(@QueryParam("maxResults") int maxResults) {
EntityManager em = Hibernate.createEntityManager();
final List<Tuple> greetings = em
.createQuery("SELECT g.id, g.date, g.author.name, g.content FROM Greeting g ", Tuple.class)
.setHint(QueryHints.READ_ONLY, "true")
.setMaxResults(maxResults == 0 ? 500 : maxResults)
.getResultList();
em.close();
return RequestStats.wrap(Response.ok(toString(greetings)));
}
开发者ID:bedatadriven,项目名称:appengine-hibernate,代码行数:15,代码来源:TestResources.java
示例11: getById
import org.hibernate.annotations.QueryHints; //导入依赖的package包/类
@Override
@Transactional(readOnly = true)
public T getById(ID id)
{
if (id == null)
throw new IllegalArgumentException("Must supply an id to retrieve!");
Map<String, Object> hints = Collections.singletonMap(QueryHints.FETCHGRAPH, getQEntity().getDefaultGraph(getSession()));
return getSession().find(clazz, id, hints);
}
开发者ID:petergeneric,项目名称:stdlib,代码行数:12,代码来源:HibernateDao.java
示例12: bindNamedQuery
import org.hibernate.annotations.QueryHints; //导入依赖的package包/类
/**
* Binds {@link javax.persistence.NamedQuery} as well as {@link org.hibernate.annotations.NamedQuery}.
*
* @param metadata the current metadata
* @param annotation the named query annotation
*/
private static void bindNamedQuery(MetadataImplementor metadata, AnnotationInstance annotation) {
String name = JandexHelper.getValue( annotation, "name", String.class );
if ( StringHelper.isEmpty( name ) ) {
throw new AnnotationException( "A named query must have a name when used in class or package level" );
}
String query = JandexHelper.getValue( annotation, "query", String.class );
AnnotationInstance[] hints = JandexHelper.getValue( annotation, "hints", AnnotationInstance[].class );
String cacheRegion = getString( hints, QueryHints.CACHE_REGION );
if ( StringHelper.isEmpty( cacheRegion ) ) {
cacheRegion = null;
}
Integer timeout = getTimeout( hints, query );
if ( timeout != null && timeout < 0 ) {
timeout = null;
}
Integer fetchSize = getInteger( hints, QueryHints.FETCH_SIZE, name );
if ( fetchSize != null && fetchSize < 0 ) {
fetchSize = null;
}
String comment = getString( hints, QueryHints.COMMENT );
if ( StringHelper.isEmpty( comment ) ) {
comment = null;
}
metadata.addNamedQuery(
new NamedQueryDefinitionBuilder().setName( name ).setQuery( query ).setCacheable(
getBoolean(
hints,
QueryHints.CACHEABLE,
name
)
).setCacheRegion( cacheRegion ).setTimeout( timeout ).setFetchSize( fetchSize ).setFlushMode(
getFlushMode( hints, QueryHints.FLUSH_MODE, name )
).setCacheMode( getCacheMode( hints, QueryHints.CACHE_MODE, name ) ).setReadOnly(
getBoolean(
hints,
QueryHints.READ_ONLY,
name
)
).setComment( comment ).setParameterTypes( null ).createNamedQueryDefinition()
);
LOG.debugf( "Binding named query: %s => %s", name, query );
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:56,代码来源:QueryBinder.java
注:本文中的org.hibernate.annotations.QueryHints类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论