javax.persistence.NamedQuery Java Examples

The following examples show how to use javax.persistence.NamedQuery. 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: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private NamedQueries getNamedQueries(Element tree, XMLContext.Default defaults) {
	//TODO avoid the Proxy Creation (@NamedQueries) when possible
	List<NamedQuery> queries = (List<NamedQuery>) buildNamedQueries( tree, false, defaults, classLoaderAccess );
	if ( defaults.canUseJavaAnnotations() ) {
		NamedQuery annotation = getPhysicalAnnotation( NamedQuery.class );
		addNamedQueryIfNeeded( annotation, queries );
		NamedQueries annotations = getPhysicalAnnotation( NamedQueries.class );
		if ( annotations != null ) {
			for ( NamedQuery current : annotations.value() ) {
				addNamedQueryIfNeeded( current, queries );
			}
		}
	}
	if ( queries.size() > 0 ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( NamedQueries.class );
		ad.setValue( "value", queries.toArray( new NamedQuery[queries.size()] ) );
		return AnnotationFactory.create( ad );
	}
	else {
		return null;
	}
}
 
Example #2
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void addNamedQueryIfNeeded(NamedQuery annotation, List<NamedQuery> queries) {
	if ( annotation != null ) {
		String queryName = annotation.name();
		boolean present = false;
		for ( NamedQuery current : queries ) {
			if ( current.name().equals( queryName ) ) {
				present = true;
				break;
			}
		}
		if ( !present ) {
			queries.add( annotation );
		}
	}
}
 
Example #3
Source File: QueryHintDefinition.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public LockOptions determineLockOptions(NamedQuery namedQueryAnnotation) {
	LockModeType lockModeType = namedQueryAnnotation.lockMode();
	Integer lockTimeoutHint = getInteger( namedQueryAnnotation.name(), "javax.persistence.lock.timeout" );
	Boolean followOnLocking = getBoolean( namedQueryAnnotation.name(), QueryHints.FOLLOW_ON_LOCKING );

	return determineLockOptions(lockModeType, lockTimeoutHint, followOnLocking);
}
 
Example #4
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 #5
Source File: QueryBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static void bindQueries(NamedQueries queriesAnn, MetadataBuildingContext context, boolean isDefault) {
	if ( queriesAnn == null ) {
		return;
	}

	for (NamedQuery q : queriesAnn.value()) {
		bindQuery( q, context, isDefault );
	}
}
 
Example #6
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 #7
Source File: QueryBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static void bindQueries(
		org.hibernate.annotations.NamedQueries queriesAnn,
		MetadataBuildingContext context) {
	if ( queriesAnn == null ) {
		return;
	}

	for (org.hibernate.annotations.NamedQuery q : queriesAnn.value()) {
		bindQuery( q, context );
	}
}
 
Example #8
Source File: IssueHJIII100Test.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void testEntityAnnotation() throws Exception {

		Assert.assertNotNull(IssueHJIII100Type.class
				.getAnnotation(NamedQuery.class));

		Assert.assertEquals(
				1,
				IssueHJIII100Type.class.getAnnotation(NamedQuery.class).hints().length);
	}