HHH-7957 - Integrate Latest draft(s) of the JPA 2.1 spec

This commit is contained in:
Steve Ebersole 2013-04-02 20:10:44 -05:00
parent 8316367683
commit 076e17e5b1
3 changed files with 18 additions and 1 deletions

View File

@ -427,6 +427,7 @@ public class CriteriaQueryImpl<T> extends AbstractNode implements CriteriaQuery<
} }
return new CriteriaQueryTypeQueryAdapter( return new CriteriaQueryTypeQueryAdapter(
entityManager,
jpaqlQuery, jpaqlQuery,
parameterMetadata.explicitParameterMapping(), parameterMetadata.explicitParameterMapping(),
parameterMetadata.explicitParameterNameMapping() parameterMetadata.explicitParameterNameMapping()

View File

@ -38,19 +38,23 @@ import java.util.Set;
import org.hibernate.Query; import org.hibernate.Query;
import org.hibernate.ejb.HibernateQuery; import org.hibernate.ejb.HibernateQuery;
import org.hibernate.jpa.internal.QueryImpl; import org.hibernate.jpa.internal.QueryImpl;
import org.hibernate.jpa.spi.HibernateEntityManagerImplementor;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, HibernateQuery { public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, HibernateQuery {
private final HibernateEntityManagerImplementor entityManager;
private final QueryImpl<X> jpaqlQuery; private final QueryImpl<X> jpaqlQuery;
private final Map<ParameterExpression<?>, String> explicitParameterMapping; private final Map<ParameterExpression<?>, String> explicitParameterMapping;
private final Map<String, ParameterExpression<?>> explicitParameterNameMapping; private final Map<String, ParameterExpression<?>> explicitParameterNameMapping;
public CriteriaQueryTypeQueryAdapter( public CriteriaQueryTypeQueryAdapter(
HibernateEntityManagerImplementor entityManager,
QueryImpl<X> jpaqlQuery, QueryImpl<X> jpaqlQuery,
Map<ParameterExpression<?>, String> explicitParameterMapping, Map<ParameterExpression<?>, String> explicitParameterMapping,
Map<String, ParameterExpression<?>> explicitParameterNameMapping) { Map<String, ParameterExpression<?>> explicitParameterNameMapping) {
this.entityManager = entityManager;
this.jpaqlQuery = jpaqlQuery; this.jpaqlQuery = jpaqlQuery;
this.explicitParameterMapping = explicitParameterMapping; this.explicitParameterMapping = explicitParameterMapping;
this.explicitParameterNameMapping = explicitParameterNameMapping; this.explicitParameterNameMapping = explicitParameterNameMapping;
@ -116,20 +120,24 @@ public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, Hibernat
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public Set getParameters() { public Set getParameters() {
entityManager.checkOpen( false );
return explicitParameterMapping.keySet(); return explicitParameterMapping.keySet();
} }
public boolean isBound(Parameter<?> param) { public boolean isBound(Parameter<?> param) {
entityManager.checkOpen( false );
return jpaqlQuery.isBound( param ); return jpaqlQuery.isBound( param );
} }
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public <T> T getParameterValue(Parameter<T> param) { public <T> T getParameterValue(Parameter<T> param) {
entityManager.checkOpen( false );
return ( T ) jpaqlQuery.getParameterValue( mapToNamedParameter( param ) ); return ( T ) jpaqlQuery.getParameterValue( mapToNamedParameter( param ) );
} }
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public <T> TypedQuery<X> setParameter(Parameter<T> param, T t) { public <T> TypedQuery<X> setParameter(Parameter<T> param, T t) {
entityManager.checkOpen( false );
jpaqlQuery.setParameter( mapToNamedParameter( param ), t ); jpaqlQuery.setParameter( mapToNamedParameter( param ), t );
return this; return this;
} }
@ -143,12 +151,14 @@ public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, Hibernat
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public TypedQuery<X> setParameter(Parameter<Calendar> param, Calendar calendar, TemporalType temporalType) { public TypedQuery<X> setParameter(Parameter<Calendar> param, Calendar calendar, TemporalType temporalType) {
entityManager.checkOpen( false );
jpaqlQuery.setParameter( mapToNamedParameter( param ), calendar, temporalType ); jpaqlQuery.setParameter( mapToNamedParameter( param ), calendar, temporalType );
return this; return this;
} }
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public TypedQuery<X> setParameter(Parameter<Date> param, Date date, TemporalType temporalType) { public TypedQuery<X> setParameter(Parameter<Date> param, Date date, TemporalType temporalType) {
entityManager.checkOpen( false );
jpaqlQuery.setParameter( mapToNamedParameter( param ), date, temporalType ); jpaqlQuery.setParameter( mapToNamedParameter( param ), date, temporalType );
return this; return this;
} }
@ -159,6 +169,7 @@ public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, Hibernat
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public Object getParameterValue(String name) { public Object getParameterValue(String name) {
entityManager.checkOpen( false );
return getParameterValue( resolveExplicitCriteriaParameterName( name ) ); return getParameterValue( resolveExplicitCriteriaParameterName( name ) );
} }
@ -171,11 +182,13 @@ public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, Hibernat
} }
public Parameter<?> getParameter(String name) { public Parameter<?> getParameter(String name) {
entityManager.checkOpen( false );
return mapToNamedParameter( resolveExplicitCriteriaParameterName( name ) ); return mapToNamedParameter( resolveExplicitCriteriaParameterName( name ) );
} }
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public <T> Parameter<T> getParameter(String name, Class<T> type) { public <T> Parameter<T> getParameter(String name, Class<T> type) {
entityManager.checkOpen( false );
Parameter parameter = resolveExplicitCriteriaParameterName( name ); Parameter parameter = resolveExplicitCriteriaParameterName( name );
if ( type.isAssignableFrom( parameter.getParameterType() ) ) { if ( type.isAssignableFrom( parameter.getParameterType() ) ) {
return parameter; return parameter;
@ -188,6 +201,7 @@ public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, Hibernat
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public TypedQuery<X> setParameter(String name, Object value) { public TypedQuery<X> setParameter(String name, Object value) {
entityManager.checkOpen( true );
setParameter( setParameter(
resolveExplicitCriteriaParameterName( name, value ), resolveExplicitCriteriaParameterName( name, value ),
value value
@ -212,6 +226,7 @@ public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, Hibernat
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public TypedQuery<X> setParameter(String name, Calendar calendar, TemporalType temporalType) { public TypedQuery<X> setParameter(String name, Calendar calendar, TemporalType temporalType) {
entityManager.checkOpen( true );
Parameter parameter = resolveExplicitCriteriaParameterName( name ); Parameter parameter = resolveExplicitCriteriaParameterName( name );
if ( ! Calendar.class.isAssignableFrom( parameter.getParameterType() ) ) { if ( ! Calendar.class.isAssignableFrom( parameter.getParameterType() ) ) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
@ -226,6 +241,7 @@ public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, Hibernat
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public TypedQuery<X> setParameter(String name, Date date, TemporalType temporalType) { public TypedQuery<X> setParameter(String name, Date date, TemporalType temporalType) {
entityManager.checkOpen( true );
Parameter parameter = resolveExplicitCriteriaParameterName( name ); Parameter parameter = resolveExplicitCriteriaParameterName( name );
if ( ! Date.class.isAssignableFrom( parameter.getParameterType() ) ) { if ( ! Date.class.isAssignableFrom( parameter.getParameterType() ) ) {
throw new IllegalArgumentException( throw new IllegalArgumentException(

View File

@ -54,7 +54,7 @@ ext {
javassist: 'org.javassist:javassist:3.15.0-GA', javassist: 'org.javassist:javassist:3.15.0-GA',
// javax // javax
jpa: 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Draft-14', jpa: 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Draft-16',
jta: 'org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.0.Alpha1', jta: 'org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.0.Alpha1',
validation: 'javax.validation:validation-api:1.1.0.CR3', validation: 'javax.validation:validation-api:1.1.0.CR3',
jacc: 'org.jboss.spec.javax.security.jacc:jboss-jacc-api_1.4_spec:1.0.2.Final', jacc: 'org.jboss.spec.javax.security.jacc:jboss-jacc-api_1.4_spec:1.0.2.Final',