org.hibernate.engine.spi.NamedQueryDefinition Java Examples

The following examples show how to use org.hibernate.engine.spi.NamedQueryDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractSharedSessionContract.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected  <T> QueryImplementor<T> buildQueryFromName(String name, Class<T> resultType) {
	checkOpen();
	try {
		checkTransactionSynchStatus();
		delayedAfterCompletion();

		// todo : apply stored setting at the JPA Query level too

		final NamedQueryDefinition namedQueryDefinition = getFactory().getNamedQueryRepository().getNamedQueryDefinition( name );
		if ( namedQueryDefinition != null ) {
			return createQuery( namedQueryDefinition, resultType );
		}

		final NamedSQLQueryDefinition nativeQueryDefinition = getFactory().getNamedQueryRepository().getNamedSQLQueryDefinition( name );
		if ( nativeQueryDefinition != null ) {
			return (QueryImplementor<T>) createNativeQuery( nativeQueryDefinition, resultType );
		}

		throw exceptionConverter.convert( new IllegalArgumentException( "No query defined for that name [" + name + "]" ) );
	}
	catch (RuntimeException e) {
		throw !( e instanceof IllegalArgumentException ) ? new IllegalArgumentException( e ) : e;
	}
}
 
Example #2
Source File: BasicHibernateDao.java    From base-framework with Apache License 2.0 6 votes vote down vote up
/**
 * 根据hql创建Hibernate Query对象
 * 
 * @param queryOrNamedQuery hql 或者Hibernate的NamedQuery
 * @param values
 *            数量可变的参数,按顺序绑定.
 *            
 * @return {@link Query}
 */
protected Query createQuery(String queryOrNamedQuery, Object... values) {
	Assert.hasText(queryOrNamedQuery, "queryOrNamedQuery不能为空");
	
	SessionFactoryImpl factory = (SessionFactoryImpl) sessionFactory;
	NamedQueryDefinition nqd = factory.getNamedQuery( queryOrNamedQuery );
	Query query = null;
	
	if (nqd != null) {
		query = getSession().getNamedQuery(queryOrNamedQuery);
	} else {
		query = getSession().createQuery(queryOrNamedQuery);
	}
	
	setQueryValues(query, values);
	return query;
}
 
Example #3
Source File: ReactiveSessionImpl.java    From hibernate-reactive with GNU Lesser General Public License v2.1 6 votes vote down vote up
private <T> ReactiveQuery<T> buildReactiveQueryFromName(String name, Class<T> resultType) {
	checkOpen();
	try {
		pulseTransactionCoordinator();
		delayedAfterCompletion();

		// todo : apply stored setting at the JPA Query level too

		final NamedQueryDefinition namedQueryDefinition = getFactory().getNamedQueryRepository().getNamedQueryDefinition( name );
		if ( namedQueryDefinition != null ) {
			return createReactiveQuery( namedQueryDefinition, resultType );
		}

		final NamedSQLQueryDefinition nativeQueryDefinition = getFactory().getNamedQueryRepository().getNamedSQLQueryDefinition( name );
		if ( nativeQueryDefinition != null ) {
			return createReactiveNativeQuery( nativeQueryDefinition, resultType );
		}

		throw getExceptionConverter().convert( new IllegalArgumentException( "No query defined for that name [" + name + "]" ) );
	}
	catch (RuntimeException e) {
		throw !( e instanceof IllegalArgumentException ) ? new IllegalArgumentException( e ) : e;
	}
}
 
Example #4
Source File: AbstractSharedSessionContract.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected QueryImplementor createQuery(NamedQueryDefinition queryDefinition) {
		String queryString = queryDefinition.getQueryString();
		final QueryImpl query = new QueryImpl(
				this,
				getQueryPlan( queryString, false ).getParameterMetadata(),
				queryString
		);
		query.setHibernateFlushMode( queryDefinition.getFlushMode() );
		query.setComment( queryDefinition.getComment() != null ? queryDefinition.getComment() : queryDefinition.getName() );
		if ( queryDefinition.getLockOptions() != null ) {
			query.setLockOptions( queryDefinition.getLockOptions() );
		}

		initQueryFromNamedDefinition( query, queryDefinition );
//		applyQuerySettingsAndHints( query );

		return query;
	}
 
Example #5
Source File: AbstractSharedSessionContract.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public QueryImplementor getNamedQuery(String name) {
	checkOpen();
	checkTransactionSynchStatus();
	delayedAfterCompletion();

	// look as HQL/JPQL first
	final NamedQueryDefinition queryDefinition = factory.getNamedQueryRepository().getNamedQueryDefinition( name );
	if ( queryDefinition != null ) {
		return createQuery( queryDefinition );
	}

	// then as a native query
	final NamedSQLQueryDefinition nativeQueryDefinition = factory.getNamedQueryRepository().getNamedSQLQueryDefinition( name );
	if ( nativeQueryDefinition != null ) {
		return createNativeQuery( nativeQueryDefinition, true );
	}

	throw exceptionConverter.convert( new IllegalArgumentException( "No query defined for that name [" + name + "]" ) );
}
 
Example #6
Source File: NamedQueryRepository.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public synchronized void registerNamedSQLQueryDefinition(String name, NamedSQLQueryDefinition definition) {
	if ( ! name.equals( definition.getName() ) ) {
		definition = definition.makeCopy( name );
	}

	final Map<String, NamedSQLQueryDefinition> copy = CollectionHelper.makeCopy( namedSqlQueryDefinitionMap );
	final NamedQueryDefinition previous = copy.put( name, definition );
	if ( previous != null ) {
		log.debugf(
				"registering named SQL query definition [%s] overriding previously registered definition [%s]",
				name,
				previous
		);
	}

	this.namedSqlQueryDefinitionMap = Collections.unmodifiableMap( copy );
}
 
Example #7
Source File: NamedQueryRepository.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public synchronized void registerNamedQueryDefinition(String name, NamedQueryDefinition definition) {
	if ( NamedSQLQueryDefinition.class.isInstance( definition ) ) {
		throw new IllegalArgumentException( "NamedSQLQueryDefinition instance incorrectly passed to registerNamedQueryDefinition" );
	}

	if ( ! name.equals( definition.getName() ) ) {
		definition = definition.makeCopy( name );
	}

	final Map<String, NamedQueryDefinition> copy = CollectionHelper.makeCopy( namedQueryDefinitionMap );
	final NamedQueryDefinition previous = copy.put( name, definition );
	if ( previous != null ) {
		log.debugf(
				"registering named query definition [%s] overriding previously registered definition [%s]",
				name,
				previous
		);
	}

	this.namedQueryDefinitionMap = Collections.unmodifiableMap( copy );
}
 
Example #8
Source File: NamedQueryRepository.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public NamedQueryRepository(
		Iterable<NamedQueryDefinition> namedQueryDefinitions,
		Iterable<NamedSQLQueryDefinition> namedSqlQueryDefinitions,
		Iterable<ResultSetMappingDefinition> namedSqlResultSetMappings,
		Map<String, ProcedureCallMemento> namedProcedureCalls) {
	final HashMap<String, NamedQueryDefinition> namedQueryDefinitionMap = new HashMap<String, NamedQueryDefinition>();
	for ( NamedQueryDefinition namedQueryDefinition : namedQueryDefinitions ) {
		namedQueryDefinitionMap.put( namedQueryDefinition.getName(), namedQueryDefinition );
	}
	this.namedQueryDefinitionMap = Collections.unmodifiableMap( namedQueryDefinitionMap );


	final HashMap<String, NamedSQLQueryDefinition> namedSqlQueryDefinitionMap = new HashMap<String, NamedSQLQueryDefinition>();
	for ( NamedSQLQueryDefinition namedSqlQueryDefinition : namedSqlQueryDefinitions ) {
		namedSqlQueryDefinitionMap.put( namedSqlQueryDefinition.getName(), namedSqlQueryDefinition );
	}
	this.namedSqlQueryDefinitionMap = Collections.unmodifiableMap( namedSqlQueryDefinitionMap );

	final HashMap<String, ResultSetMappingDefinition> namedSqlResultSetMappingMap = new HashMap<String, ResultSetMappingDefinition>();
	for ( ResultSetMappingDefinition resultSetMappingDefinition : namedSqlResultSetMappings ) {
		namedSqlResultSetMappingMap.put( resultSetMappingDefinition.getName(), resultSetMappingDefinition );
	}
	this.namedSqlResultSetMappingMap = Collections.unmodifiableMap( namedSqlResultSetMappingMap );
	this.procedureCallMementoMap = Collections.unmodifiableMap( namedProcedureCalls );
}
 
Example #9
Source File: QueryBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static void bindQuery(
		NamedQuery queryAnn,
		MetadataBuildingContext context,
		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 ) {
		context.getMetadataCollector().addDefaultQuery( queryDefinition );
	}
	else {
		context.getMetadataCollector().addNamedQuery( queryDefinition );
	}

	if ( LOG.isDebugEnabled() ) {
		LOG.debugf( "Binding named query: %s => %s", queryDefinition.getName(), queryDefinition.getQueryString() );
	}
}
 
Example #10
Source File: ReactiveSessionImpl.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
private <T> ReactiveQuery<T> createReactiveQuery(NamedQueryDefinition namedQueryDefinition, Class<T> resultType) {
	final ReactiveQuery<T> query = createReactiveQuery( namedQueryDefinition );
	if ( resultType != null ) {
		resultClassChecking( resultType, createQuery( namedQueryDefinition ) );
	}
	return query;
}
 
Example #11
Source File: InFlightMetadataCollectorImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addNamedQuery(NamedQueryDefinition def) {
	if ( def == null ) {
		throw new IllegalArgumentException( "Named query definition is null" );
	}
	else if ( def.getName() == null ) {
		throw new IllegalArgumentException( "Named query definition name is null: " + def.getQueryString() );
	}

	if ( defaultNamedQueryNames.contains( def.getName() ) ) {
		return;
	}

	applyNamedQuery( def.getName(), def );
}
 
Example #12
Source File: AbstractSharedSessionContract.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({"WeakerAccess", "unchecked"})
protected <T> QueryImplementor<T> createQuery(NamedQueryDefinition namedQueryDefinition, Class<T> resultType) {
	final QueryImplementor query = createQuery( namedQueryDefinition );
	if ( resultType != null ) {
		resultClassChecking( resultType, query );
	}
	return query;
}
 
Example #13
Source File: ReactiveSessionImpl.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
private <T> ReactiveQuery<T> createReactiveQuery(NamedQueryDefinition queryDefinition) {
	String queryString = queryDefinition.getQueryString();
	ParameterMetadataImpl paramMetadata = getQueryPlan( queryString, false ).getParameterMetadata();
	ReactiveQueryImpl<T> query = new ReactiveQueryImpl<>( this, paramMetadata, queryString, queryType( queryString ) );
	applyQuerySettingsAndHints( query );
	query.setHibernateFlushMode( queryDefinition.getFlushMode() );
	query.setComment( queryDefinition.getComment() != null ? queryDefinition.getComment() : queryDefinition.getName() );
	if ( queryDefinition.getLockOptions() != null ) {
		query.setLockOptions( queryDefinition.getLockOptions() );
	}

	initQueryFromNamedDefinition( query, queryDefinition );

	return query;
}
 
Example #14
Source File: AbstractSharedSessionContract.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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() );
	}
}
 
Example #15
Source File: SessionFactoryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private NamedQueryDefinition extractHqlQueryDefinition(org.hibernate.query.Query hqlQuery, String name) {
	final NamedQueryDefinitionBuilder builder = new NamedQueryDefinitionBuilder( name );
	fillInNamedQueryBuilder( builder, hqlQuery );
	// LockOptions only valid for HQL/JPQL queries...
	builder.setLockOptions( hqlQuery.getLockOptions().makeCopy() );
	return builder.createNamedQueryDefinition();
}
 
Example #16
Source File: QueryBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static void bindQuery(
		org.hibernate.annotations.NamedQuery queryAnn,
		MetadataBuildingContext context) {
	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" );
	}

	FlushMode flushMode;
	flushMode = getFlushMode( queryAnn.flushMode() );

	NamedQueryDefinition query = new NamedQueryDefinitionBuilder().setName( queryAnn.name() )
			.setQuery( queryAnn.query() )
			.setCacheable( queryAnn.cacheable() )
			.setCacheRegion(
					BinderHelper.isEmptyAnnotationValue( queryAnn.cacheRegion() ) ?
							null :
							queryAnn.cacheRegion()
			)
			.setTimeout( queryAnn.timeout() < 0 ? null : queryAnn.timeout() )
			.setFetchSize( queryAnn.fetchSize() < 0 ? null : queryAnn.fetchSize() )
			.setFlushMode( flushMode )
			.setCacheMode( getCacheMode( queryAnn.cacheMode() ) )
			.setReadOnly( queryAnn.readOnly() )
			.setComment( BinderHelper.isEmptyAnnotationValue( queryAnn.comment() ) ? null : queryAnn.comment() )
			.setParameterTypes( null )
			.createNamedQueryDefinition();

	context.getMetadataCollector().addNamedQuery( query );
	if ( LOG.isDebugEnabled() ) {
		LOG.debugf( "Binding named query: %s => %s", query.getName(), query.getQueryString() );
	}
}
 
Example #17
Source File: Configuration.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected void reset() {
	implicitNamingStrategy = ImplicitNamingStrategyJpaCompliantImpl.INSTANCE;
	physicalNamingStrategy = PhysicalNamingStrategyStandardImpl.INSTANCE;
	namedQueries = new HashMap<String,NamedQueryDefinition>();
	namedSqlQueries = new HashMap<String,NamedSQLQueryDefinition>();
	sqlResultSetMappings = new HashMap<String, ResultSetMappingDefinition>();
	namedEntityGraphMap = new HashMap<String, NamedEntityGraphDefinition>();
	namedProcedureCallMap = new HashMap<String, NamedProcedureCallDefinition>(  );

	standardServiceRegistryBuilder = new StandardServiceRegistryBuilder( bootstrapServiceRegistry );
	entityTuplizerFactory = new EntityTuplizerFactory();
	interceptor = EmptyInterceptor.INSTANCE;
	properties = new Properties(  );
	properties.putAll( standardServiceRegistryBuilder.getSettings());
}
 
Example #18
Source File: NamedQueryRepository.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public NamedQueryRepository(
		Map<String,NamedQueryDefinition> namedQueryDefinitionMap,
		Map<String,NamedSQLQueryDefinition> namedSqlQueryDefinitionMap,
		Map<String,ResultSetMappingDefinition> namedSqlResultSetMappingMap,
		Map<String, ProcedureCallMemento> namedProcedureCallMap) {
	this.namedQueryDefinitionMap = Collections.unmodifiableMap( namedQueryDefinitionMap );
	this.namedSqlQueryDefinitionMap = Collections.unmodifiableMap( namedSqlQueryDefinitionMap );
	this.namedSqlResultSetMappingMap = Collections.unmodifiableMap( namedSqlResultSetMappingMap );
	this.procedureCallMementoMap = Collections.unmodifiableMap( namedProcedureCallMap );
}
 
Example #19
Source File: AbstractDelegatingMetadata.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Collection<NamedQueryDefinition> getNamedQueryDefinitions() {
	return delegate.getNamedQueryDefinitions();
}
 
Example #20
Source File: SessionFactoryWrapper.java    From lemon with Apache License 2.0 4 votes vote down vote up
public void registerNamedQueryDefinition(String name,
        NamedQueryDefinition definition) {
    sessionFactoryImplementor
            .registerNamedQueryDefinition(name, definition);
}
 
Example #21
Source File: SessionFactoryWrapper.java    From lemon with Apache License 2.0 4 votes vote down vote up
public NamedQueryDefinition getNamedQuery(String queryName) {
    return sessionFactoryImplementor.getNamedQuery(queryName);
}
 
Example #22
Source File: MetadataImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public java.util.Collection<NamedQueryDefinition> getNamedQueryDefinitions() {
	return namedQueryMap.values();
}
 
Example #23
Source File: MetadataImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public NamedQueryDefinition getNamedQueryDefinition(String name) {
	return namedQueryMap.get( name );
}
 
Example #24
Source File: MetadataImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
MetadataImpl(
		UUID uuid,
		MetadataBuildingOptions metadataBuildingOptions,
		MutableIdentifierGeneratorFactory identifierGeneratorFactory,
		Map<String, PersistentClass> entityBindingMap,
		Map<Class, MappedSuperclass> mappedSuperclassMap,
		Map<String, Collection> collectionBindingMap,
		Map<String, TypeDefinition> typeDefinitionMap,
		Map<String, FilterDefinition> filterDefinitionMap,
		Map<String, FetchProfile> fetchProfileMap,
		Map<String, String> imports,
		Map<String, IdentifierGeneratorDefinition> idGeneratorDefinitionMap,
		Map<String, NamedQueryDefinition> namedQueryMap,
		Map<String, NamedSQLQueryDefinition> namedNativeQueryMap,
		Map<String, NamedProcedureCallDefinition> namedProcedureCallMap,
		Map<String, ResultSetMappingDefinition> sqlResultSetMappingMap,
		Map<String, NamedEntityGraphDefinition> namedEntityGraphMap,
		Map<String, SQLFunction> sqlFunctionMap,
		java.util.Collection<DomainDataRegionConfigImpl.Builder> cacheRegionConfigBuilders,
		Database database,
		BootstrapContext bootstrapContext) {
	this.uuid = uuid;
	this.metadataBuildingOptions = metadataBuildingOptions;
	this.identifierGeneratorFactory = identifierGeneratorFactory;
	this.entityBindingMap = entityBindingMap;
	this.mappedSuperclassMap = mappedSuperclassMap;
	this.collectionBindingMap = collectionBindingMap;
	this.typeDefinitionMap = typeDefinitionMap;
	this.filterDefinitionMap = filterDefinitionMap;
	this.fetchProfileMap = fetchProfileMap;
	this.imports = imports;
	this.idGeneratorDefinitionMap = idGeneratorDefinitionMap;
	this.namedQueryMap = namedQueryMap;
	this.namedNativeQueryMap = namedNativeQueryMap;
	this.namedProcedureCallMap = namedProcedureCallMap;
	this.sqlResultSetMappingMap = sqlResultSetMappingMap;
	this.namedEntityGraphMap = namedEntityGraphMap;
	this.sqlFunctionMap = sqlFunctionMap;
	this.cacheRegionConfigBuilders = cacheRegionConfigBuilders;
	this.database = database;
	this.bootstrapContext = bootstrapContext;
}
 
Example #25
Source File: InFlightMetadataCollectorImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void addDefaultQuery(NamedQueryDefinition queryDefinition) {
	applyNamedQuery( queryDefinition.getName(), queryDefinition );
	defaultNamedQueryNames.add( queryDefinition.getName() );
}
 
Example #26
Source File: InFlightMetadataCollectorImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void applyNamedQuery(String name, NamedQueryDefinition query) {
	checkQueryName( name );
	namedQueryMap.put( name.intern(), query );
}
 
Example #27
Source File: InFlightMetadataCollectorImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public java.util.Collection<NamedQueryDefinition> getNamedQueryDefinitions() {
	return namedQueryMap.values();
}
 
Example #28
Source File: InFlightMetadataCollectorImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public NamedQueryDefinition getNamedQueryDefinition(String name) {
	if ( name == null ) {
		throw new IllegalArgumentException( "null is not a valid query name" );
	}
	return namedQueryMap.get( name );
}
 
Example #29
Source File: SessionImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void initQueryFromNamedDefinition(Query query, NamedQueryDefinition namedQueryDefinition) {
	super.initQueryFromNamedDefinition( query, namedQueryDefinition );

	if ( namedQueryDefinition.isCacheable() ) {
		query.setHint( QueryHints.HINT_CACHEABLE, true );
		if ( namedQueryDefinition.getCacheRegion() != null ) {
			query.setHint( QueryHints.HINT_CACHE_REGION, namedQueryDefinition.getCacheRegion() );
		}
	}

	if ( namedQueryDefinition.getCacheMode() != null ) {
		query.setHint( QueryHints.HINT_CACHE_MODE, namedQueryDefinition.getCacheMode() );
	}

	if ( namedQueryDefinition.isReadOnly() ) {
		query.setHint( QueryHints.HINT_READONLY, true );
	}

	if ( namedQueryDefinition.getTimeout() != null ) {
		query.setHint( QueryHints.SPEC_HINT_TIMEOUT, namedQueryDefinition.getTimeout() * 1000 );
	}

	if ( namedQueryDefinition.getFetchSize() != null ) {
		query.setHint( QueryHints.HINT_FETCH_SIZE, namedQueryDefinition.getFetchSize() );
	}

	if ( namedQueryDefinition.getComment() != null ) {
		query.setHint( QueryHints.HINT_COMMENT, namedQueryDefinition.getComment() );
	}

	if ( namedQueryDefinition.getFirstResult() != null ) {
		query.setFirstResult( namedQueryDefinition.getFirstResult() );
	}

	if ( namedQueryDefinition.getMaxResults() != null ) {
		query.setMaxResults( namedQueryDefinition.getMaxResults() );
	}

	if ( namedQueryDefinition.getLockOptions() != null ) {
		if ( namedQueryDefinition.getLockOptions().getLockMode() != null ) {
			query.setLockMode(
					LockModeTypeHelper.getLockModeType( namedQueryDefinition.getLockOptions().getLockMode() )
			);
		}
	}

	if ( namedQueryDefinition.getFlushMode() != null ) {
		query.setHibernateFlushMode( namedQueryDefinition.getFlushMode() );
	}
}
 
Example #30
Source File: AbstractDelegatingMetadata.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public NamedQueryDefinition getNamedQueryDefinition(String name) {
	return delegate.getNamedQueryDefinition( name );
}