Hibernate SVN: r17836 - core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-10-26 01:23:40 -0400 (Mon, 26 Oct 2009)
New Revision: 17836
Added:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractAttribute.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractIdentifiableType.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractManagedType.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractType.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeImplementor.java
Removed:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeDelegator.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/ManagedTypeImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelFactory.java
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EmbeddableTypeImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/PluralAttributeImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/SingularAttributeImpl.java
Log:
HHH-4202 - Implement JPA 2.0 metamodel APIs
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractAttribute.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractAttribute.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractAttribute.java 2009-10-26 05:23:40 UTC (rev 17836)
@@ -0,0 +1,142 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @author tags or express
+ * copyright attribution statements applied by the authors. All
+ * third-party contributions are distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.ejb.metamodel;
+
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.io.ObjectInputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.ManagedType;
+
+import org.hibernate.util.ReflectHelper;
+
+/**
+ * Models the commonality of the JPA {@link Attribute} hierarchy.
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractAttribute<X, Y>
+ implements Attribute<X, Y>, AttributeImplementor<X,Y>, Serializable {
+ private final String name;
+ private final Class<Y> javaType;
+ private final AbstractManagedType<X> declaringType;
+ private transient Member member;
+ private final PersistentAttributeType persistentAttributeType;
+
+ public AbstractAttribute(
+ String name,
+ Class<Y> javaType,
+ AbstractManagedType<X> declaringType,
+ Member member,
+ PersistentAttributeType persistentAttributeType) {
+ this.name = name;
+ this.javaType = javaType;
+ this.declaringType = declaringType;
+ this.member = member;
+ this.persistentAttributeType = persistentAttributeType;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ManagedType<X> getDeclaringType() {
+ return declaringType;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Class<Y> getJavaType() {
+ return javaType;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Member getJavaMember() {
+ return member;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PersistentAttributeType getPersistentAttributeType() {
+ return persistentAttributeType;
+ }
+
+ /**
+ * Used by JDK serialization...
+ *
+ * @param ois The input stream from which we are being read...
+ * @throws java.io.IOException Indicates a general IO stream exception
+ * @throws ClassNotFoundException Indicates a class resolution issue
+ */
+ protected void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
+ ois.defaultReadObject();
+ final String memberDeclaringClassName = ( String ) ois.readObject();
+ final String memberName = ( String ) ois.readObject();
+ final String memberType = ( String ) ois.readObject();
+
+ final Class memberDeclaringClass = Class.forName(
+ memberDeclaringClassName,
+ false,
+ declaringType.getJavaType().getClassLoader()
+ );
+ try {
+ this.member = "method".equals( memberType )
+ ? memberDeclaringClass.getMethod( memberName, ReflectHelper.NO_PARAM_SIGNATURE )
+ : memberDeclaringClass.getField( memberName );
+ }
+ catch ( Exception e ) {
+ throw new IllegalStateException(
+ "Unable to locate member [" + memberDeclaringClassName + "#"
+ + memberName + "]"
+ );
+ }
+ }
+
+ /**
+ * Used by JDK serialization...
+ *
+ * @param oos The output stream to which we are being written...
+ * @throws IOException Indicates a general IO stream exception
+ */
+ protected void writeObject(ObjectOutputStream oos) throws IOException {
+ oos.defaultWriteObject();
+ oos.writeObject( getJavaMember().getDeclaringClass().getName() );
+ oos.writeObject( getJavaMember().getName() );
+ // should only ever be a field or the getter-method...
+ oos.writeObject( Method.class.isInstance( getJavaMember() ) ? "method" : "field" );
+ }
+}
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractIdentifiableType.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractIdentifiableType.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractIdentifiableType.java 2009-10-26 05:23:40 UTC (rev 17836)
@@ -0,0 +1,243 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @author tags or express
+ * copyright attribution statements applied by the authors. All
+ * third-party contributions are distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.ejb.metamodel;
+
+import java.io.Serializable;
+import java.util.Set;
+import javax.persistence.metamodel.IdentifiableType;
+import javax.persistence.metamodel.SingularAttribute;
+import javax.persistence.metamodel.Type;
+import javax.persistence.metamodel.Attribute;
+
+/**
+ * Defines commonality for the JPA {@link IdentifiableType} types. JPA defines
+ * identifiable types as entities or mapped-superclasses. Basically things to which an
+ * identifier can be attached.
+ * <p/>
+ * NOTE : Currently we only really have support for direct entities in the Hibernate metamodel
+ * as the information for them is consumed into the closest actual entity subclass(es) in the
+ * internal Hibernate mapping-metamodel.
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractIdentifiableType<X>
+ extends AbstractManagedType<X>
+ implements IdentifiableType<X>, Serializable {
+
+ private final boolean hasIdentifierProperty;
+ private final boolean isVersioned;
+
+ private SingularAttributeImpl<X, ?> id;
+ private SingularAttributeImpl<X, ?> version;
+ private Set<SingularAttribute<? super X,?>> idClassAttributes;
+
+ public AbstractIdentifiableType(
+ Class<X> javaType,
+ AbstractIdentifiableType<? super X> superType,
+ boolean hasIdentifierProperty,
+ boolean versioned) {
+ super( javaType, superType );
+ this.hasIdentifierProperty = hasIdentifierProperty;
+ isVersioned = versioned;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public AbstractIdentifiableType<? super X> getSupertype() {
+ return ( AbstractIdentifiableType<? super X> ) super.getSupertype();
+ }
+
+ protected AbstractIdentifiableType<? super X> requireSupertype() {
+ if ( getSupertype() == null ) {
+ throw new IllegalStateException( "No supertype found" );
+ }
+ return getSupertype();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasSingleIdAttribute() {
+ return hasIdentifierProperty;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <Y> SingularAttribute<? super X, Y> getId(Class<Y> type) {
+ final SingularAttribute<? super X, Y> id_;
+ if ( id != null ) {
+ checkSimpleId();
+ id_ = ( SingularAttribute<? super X, Y> ) id;
+ }
+ else {
+ id_ = requireSupertype().getId( type );
+ }
+ // TODO : check that type and id_.getJavaType() are related
+ return id_;
+ }
+
+ /**
+ * Centralized check to ensure the id for this hierarchy is a simple one (i.e., does not use
+ * an id-class).
+ *
+ * @see #checkIdClass()
+ */
+ protected void checkSimpleId() {
+ if ( ! hasIdentifierProperty ) {
+ throw new IllegalStateException( "This class uses an @IdClass" );
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <Y> SingularAttribute<X, Y> getDeclaredId(Class<Y> yClass) {
+ checkDeclaredId();
+ checkSimpleId();
+ // TODO : check that type and id.getJavaType() are related
+ return (SingularAttribute<X, Y>) id;
+ }
+
+ /**
+ * Centralized check to ensure the id is actually declared on the class mapped here, as opposed to a
+ * super class.
+ */
+ protected void checkDeclaredId() {
+ if ( id == null ) {
+ throw new IllegalArgumentException( "The id attribute is not declared on this type" );
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Type<?> getIdType() {
+ if ( id != null ) {
+ checkSimpleId();
+ return id.getType();
+ }
+ else {
+ return requireSupertype().getIdType();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<SingularAttribute<? super X, ?>> getIdClassAttributes() {
+ checkIdClass();
+ return idClassAttributes;
+ }
+
+ /**
+ * Centralized check to ensure the id for this hierarchy uses an id-class.
+ *
+ * @see #checkSimpleId()
+ */
+ private void checkIdClass() {
+ if ( hasIdentifierProperty ) {
+ throw new IllegalArgumentException( "This class does not use @IdClass" );
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasVersionAttribute() {
+ return isVersioned;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <Y> SingularAttribute<? super X, Y> getVersion(Class<Y> type) {
+ if ( ! hasVersionAttribute() ) {
+ return null;
+ }
+ final SingularAttribute<? super X, Y> version_;
+ if ( version != null ) {
+ version_ = ( SingularAttribute<? super X, Y> ) version;
+ }
+ else {
+ version_ = requireSupertype().getVersion( type );
+ }
+ // TODO : check that type and version_.getJavaType() are related
+ return version_;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <Y> SingularAttribute<X, Y> getDeclaredVersion(Class<Y> yClass) {
+ checkDeclaredVersion();
+ // TODO : check that type and version_.getJavaType() are related
+ return ( SingularAttribute<X, Y> ) version;
+ }
+
+ /**
+ * Centralized check to ensure the version (if one) is actually declared on the class mapped here, as opposed to a
+ * super class.
+ */
+ protected void checkDeclaredVersion() {
+ if ( version == null ) {
+ if ( getSupertype() != null && getSupertype().hasVersionAttribute() ) {
+ throw new IllegalArgumentException( "The version attribute is not declared on this type" );
+ }
+ }
+ }
+
+ public Builder<X> getBuilder() {
+ final AbstractManagedType.Builder<X> managedBuilder = super.getBuilder();
+ return new Builder<X>() {
+ public void applyIdAttribute(SingularAttributeImpl<X, ?> idAttribute) {
+ AbstractIdentifiableType.this.id = idAttribute;
+ }
+
+ public void applyIdClassAttributes(Set<SingularAttribute<? super X,?>> idClassAttributes) {
+ AbstractIdentifiableType.this.idClassAttributes = idClassAttributes;
+ }
+
+ public void applyVersionAttribute(SingularAttributeImpl<X, ?> versionAttribute) {
+ AbstractIdentifiableType.this.version = versionAttribute;
+ }
+
+ public void addAttribute(Attribute<X, ?> attribute) {
+ managedBuilder.addAttribute( attribute );
+ }
+ };
+ }
+
+ public static interface Builder<X> extends AbstractManagedType.Builder<X> {
+ public void applyIdAttribute(SingularAttributeImpl<X,?> idAttribute);
+ public void applyIdClassAttributes(Set<SingularAttribute<? super X,?>> idClassAttributes);
+ public void applyVersionAttribute(SingularAttributeImpl<X,?> versionAttribute);
+ }
+}
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractManagedType.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractManagedType.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractManagedType.java 2009-10-26 05:23:40 UTC (rev 17836)
@@ -0,0 +1,494 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @author tags or express
+ * copyright attribution statements applied by the authors. All
+ * third-party contributions are distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.ejb.metamodel;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.HashSet;
+import javax.persistence.metamodel.ManagedType;
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.SingularAttribute;
+import javax.persistence.metamodel.PluralAttribute;
+import javax.persistence.metamodel.Bindable;
+import javax.persistence.metamodel.CollectionAttribute;
+import javax.persistence.metamodel.SetAttribute;
+import javax.persistence.metamodel.ListAttribute;
+import javax.persistence.metamodel.MapAttribute;
+
+import org.hibernate.annotations.common.AssertionFailure;
+
+/**
+ * Defines commonality for the JPA {@link ManagedType} hierarchy of interfaces.
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractManagedType<X>
+ extends AbstractType<X>
+ implements ManagedType<X>, Serializable {
+
+ private final AbstractManagedType<? super X> superType;
+
+ private final Map<String,Attribute<X, ?>> declaredAttributes
+ = new HashMap<String, Attribute<X,?>>();
+ private final Map<String, SingularAttribute<X, ?>> declaredSingularAttributes
+ = new HashMap<String, SingularAttribute<X,?>>();
+ private final Map<String, PluralAttribute<X, ?, ?>> declaredPluralAttributes
+ = new HashMap<String, PluralAttribute<X,?,?>>();
+
+ protected AbstractManagedType(Class<X> javaType, AbstractManagedType<? super X> superType) {
+ super( javaType );
+ this.superType = superType;
+ }
+
+ protected AbstractManagedType<? super X> getSupertype() {
+ return superType;
+ }
+
+ private boolean locked = false;
+
+ public Builder<X> getBuilder() {
+ if ( locked ) {
+ throw new IllegalStateException( "Type has been locked" );
+ }
+ return new Builder<X>() {
+ public void addAttribute(Attribute<X,?> attribute) {
+ declaredAttributes.put( attribute.getName(), attribute );
+ final Bindable.BindableType bindableType = ( ( Bindable ) attribute ).getBindableType();
+ switch ( bindableType ) {
+ case SINGULAR_ATTRIBUTE : {
+ declaredSingularAttributes.put( attribute.getName(), (SingularAttribute<X,?>) attribute );
+ break;
+ }
+ case PLURAL_ATTRIBUTE : {
+ declaredPluralAttributes.put(attribute.getName(), (PluralAttribute<X,?,?>) attribute );
+ break;
+ }
+ default : {
+ throw new AssertionFailure( "unknown bindable type: " + bindableType );
+ }
+ }
+ }
+ };
+ }
+
+ public void lock() {
+ locked = true;
+ }
+
+ public static interface Builder<X> {
+ public void addAttribute(Attribute<X,?> attribute);
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public Set<Attribute<? super X, ?>> getAttributes() {
+ HashSet attributes = new HashSet<Attribute<X, ?>>( declaredAttributes.values() );
+ if ( getSupertype() != null ) {
+ attributes.addAll( getSupertype().getAttributes() );
+ }
+ return attributes;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<Attribute<X, ?>> getDeclaredAttributes() {
+ return new HashSet<Attribute<X, ?>>( declaredAttributes.values() );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public Attribute<? super X, ?> getAttribute(String name) {
+ Attribute<? super X, ?> attribute = declaredAttributes.get( name );
+ if ( attribute == null && getSupertype() != null ) {
+ attribute = getSupertype().getAttribute( name );
+ }
+ return attribute;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Attribute<X, ?> getDeclaredAttribute(String name) {
+ final Attribute<X, ?> attr = declaredSingularAttributes.get( name );
+ checkNotNull( "Attribute ", attr, name );
+ return attr;
+ }
+
+ private void checkNotNull(String attributeType, Attribute<?,?> attribute, String name) {
+ if ( attribute == null ) {
+ throw new IllegalArgumentException( attributeType + " named " + name + " is not present" );
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public Set<SingularAttribute<? super X, ?>> getSingularAttributes() {
+ HashSet attributes = new HashSet<SingularAttribute<X, ?>>( declaredSingularAttributes.values() );
+ if ( getSupertype() != null ) {
+ attributes.addAll( getSupertype().getSingularAttributes() );
+ }
+ return attributes;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<SingularAttribute<X, ?>> getDeclaredSingularAttributes() {
+ return new HashSet<SingularAttribute<X, ?>>( declaredSingularAttributes.values() );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public SingularAttribute<? super X, ?> getSingularAttribute(String name) {
+ SingularAttribute<? super X, ?> attribute = declaredSingularAttributes.get( name );
+ if ( attribute == null && getSupertype() != null ) {
+ attribute = getSupertype().getSingularAttribute( name );
+ }
+ return attribute;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public SingularAttribute<X, ?> getDeclaredSingularAttribute(String name) {
+ final SingularAttribute<X, ?> attr = declaredSingularAttributes.get( name );
+ checkNotNull( "SingularAttribute ", attr, name );
+ return attr;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <Y> SingularAttribute<? super X, Y> getSingularAttribute(String name, Class<Y> type) {
+ SingularAttribute<? super X, ?> attribute = declaredSingularAttributes.get( name );
+ if ( attribute == null && getSupertype() != null ) {
+ attribute = getSupertype().getSingularAttribute( name );
+ }
+ checkTypeForSingleAttribute( "SingularAttribute ", attribute, name, type );
+ return ( SingularAttribute<? super X, Y> ) attribute;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings( "unchecked")
+ public <Y> SingularAttribute<X, Y> getDeclaredSingularAttribute(String name, Class<Y> javaType) {
+ final SingularAttribute<X, ?> attr = declaredSingularAttributes.get( name );
+ checkTypeForSingleAttribute( "SingularAttribute ", attr, name, javaType );
+ return ( SingularAttribute<X, Y> ) attr;
+ }
+
+ private <Y> void checkTypeForSingleAttribute(
+ String attributeType,
+ SingularAttribute<?,?> attribute,
+ String name,
+ Class<Y> javaType) {
+ if ( attribute == null || ( javaType != null && !attribute.getBindableJavaType().equals( javaType ) ) ) {
+ throw new IllegalArgumentException(
+ attributeType + " named " + name
+ + ( javaType != null ? " and of type " + javaType.getName() : "" )
+ + " is not present"
+ );
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public Set<PluralAttribute<? super X, ?, ?>> getPluralAttributes() {
+ HashSet attributes = new HashSet<PluralAttribute<? super X, ?, ?>>( declaredPluralAttributes.values() );
+ if ( getSupertype() != null ) {
+ attributes.addAll( getSupertype().getPluralAttributes() );
+ }
+ return attributes;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<PluralAttribute<X, ?, ?>> getDeclaredPluralAttributes() {
+ return new HashSet<PluralAttribute<X,?,?>>( declaredPluralAttributes.values() );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public CollectionAttribute<? super X, ?> getCollection(String name) {
+ PluralAttribute<? super X, ?, ?> attribute = getPluralAttribute( name );
+ if ( attribute == null && getSupertype() != null ) {
+ attribute = getSupertype().getPluralAttribute( name );
+ }
+ basicCollectionCheck( attribute, name );
+ return ( CollectionAttribute<X, ?> ) attribute;
+ }
+
+ private PluralAttribute<? super X, ?, ?> getPluralAttribute(String name) {
+ return declaredPluralAttributes.get( name );
+ }
+
+ private void basicCollectionCheck(PluralAttribute<? super X, ?, ?> attribute, String name) {
+ checkNotNull( "CollectionAttribute", attribute, name );
+ if ( ! CollectionAttribute.class.isAssignableFrom( attribute.getClass() ) ) {
+ throw new IllegalArgumentException( name + " is not a CollectionAttribute: " + attribute.getClass() );
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings( "unchecked")
+ public CollectionAttribute<X, ?> getDeclaredCollection(String name) {
+ final PluralAttribute<X,?,?> attribute = declaredPluralAttributes.get( name );
+ basicCollectionCheck( attribute, name );
+ return ( CollectionAttribute<X, ?> ) attribute;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public SetAttribute<? super X, ?> getSet(String name) {
+ PluralAttribute<? super X, ?, ?> attribute = getPluralAttribute( name );
+ if ( attribute == null && getSupertype() != null ) {
+ attribute = getSupertype().getPluralAttribute( name );
+ }
+ basicSetCheck( attribute, name );
+ return (SetAttribute<? super X, ?>) attribute;
+ }
+
+ private void basicSetCheck(PluralAttribute<? super X, ?, ?> attribute, String name) {
+ checkNotNull( "SetAttribute", attribute, name );
+ if ( ! SetAttribute.class.isAssignableFrom( attribute.getClass() ) ) {
+ throw new IllegalArgumentException( name + " is not a SetAttribute: " + attribute.getClass() );
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings( "unchecked")
+ public SetAttribute<X, ?> getDeclaredSet(String name) {
+ final PluralAttribute<X,?,?> attribute = declaredPluralAttributes.get( name );
+ basicSetCheck( attribute, name );
+ return ( SetAttribute<X, ?> ) attribute;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public ListAttribute<? super X, ?> getList(String name) {
+ PluralAttribute<? super X, ?, ?> attribute = getPluralAttribute( name );
+ if ( attribute == null && getSupertype() != null ) {
+ attribute = getSupertype().getPluralAttribute( name );
+ }
+ basicListCheck( attribute, name );
+ return (ListAttribute<? super X, ?>) attribute;
+ }
+
+ private void basicListCheck(PluralAttribute<? super X, ?, ?> attribute, String name) {
+ checkNotNull( "ListAttribute", attribute, name );
+ if ( ! ListAttribute.class.isAssignableFrom( attribute.getClass() ) ) {
+ throw new IllegalArgumentException( name + " is not a ListAttribute: " + attribute.getClass() );
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ListAttribute<X, ?> getDeclaredList(String name) {
+ final PluralAttribute<X,?,?> attribute = declaredPluralAttributes.get( name );
+ basicListCheck( attribute, name );
+ return ( ListAttribute<X, ?> ) attribute;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public MapAttribute<? super X, ?, ?> getMap(String name) {
+ PluralAttribute<? super X, ?, ?> attribute = getPluralAttribute( name );
+ if ( attribute == null && getSupertype() != null ) {
+ attribute = getSupertype().getPluralAttribute( name );
+ }
+ basicMapCheck( attribute, name );
+ return (MapAttribute<? super X, ?, ?>) attribute;
+ }
+
+ private void basicMapCheck(PluralAttribute<? super X, ?, ?> attribute, String name) {
+ checkNotNull( "MapAttribute", attribute, name );
+ if ( ! MapAttribute.class.isAssignableFrom( attribute.getClass() ) ) {
+ throw new IllegalArgumentException( name + " is not a MapAttribute: " + attribute.getClass() );
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public MapAttribute<X, ?, ?> getDeclaredMap(String name) {
+ final PluralAttribute<X,?,?> attribute = declaredPluralAttributes.get( name );
+ basicMapCheck( attribute, name );
+ return ( MapAttribute<X,?,?> ) attribute;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <E> CollectionAttribute<? super X, E> getCollection(String name, Class<E> elementType) {
+ PluralAttribute<? super X, ?, ?> attribute = declaredPluralAttributes.get( name );
+ if ( attribute == null && getSupertype() != null ) {
+ attribute = getSupertype().getPluralAttribute( name );
+ }
+ checkCollectionElementType( attribute, name, elementType );
+ return ( CollectionAttribute<? super X, E> ) attribute;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <E> CollectionAttribute<X, E> getDeclaredCollection(String name, Class<E> elementType) {
+ final PluralAttribute<X,?,?> attribute = declaredPluralAttributes.get( name );
+ checkCollectionElementType( attribute, name, elementType );
+ return ( CollectionAttribute<X, E> ) attribute;
+ }
+
+ private <E> void checkCollectionElementType(PluralAttribute<?,?,?> attribute, String name, Class<E> elementType) {
+ checkTypeForPluralAttributes( "CollectionAttribute", attribute, name, elementType, PluralAttribute.CollectionType.COLLECTION );
+ }
+
+ private <E> void checkTypeForPluralAttributes(
+ String attributeType,
+ PluralAttribute<?,?,?> attribute,
+ String name,
+ Class<E> elementType,
+ PluralAttribute.CollectionType collectionType) {
+ if ( attribute == null
+ || ( elementType != null && !attribute.getBindableJavaType().equals( elementType ) )
+ || attribute.getCollectionType() != collectionType ) {
+ throw new IllegalArgumentException(
+ attributeType + " named " + name
+ + ( elementType != null ? " and of element type " + elementType : "" )
+ + " is not present"
+ );
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <E> SetAttribute<? super X, E> getSet(String name, Class<E> elementType) {
+ PluralAttribute<? super X, ?, ?> attribute = declaredPluralAttributes.get( name );
+ if ( attribute == null && getSupertype() != null ) {
+ attribute = getSupertype().getPluralAttribute( name );
+ }
+ checkSetElementType( attribute, name, elementType );
+ return ( SetAttribute<? super X, E> ) attribute;
+ }
+
+ private <E> void checkSetElementType(PluralAttribute<? super X, ?, ?> attribute, String name, Class<E> elementType) {
+ checkTypeForPluralAttributes( "SetAttribute", attribute, name, elementType, PluralAttribute.CollectionType.SET );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <E> SetAttribute<X, E> getDeclaredSet(String name, Class<E> elementType) {
+ final PluralAttribute<X,?,?> attribute = declaredPluralAttributes.get( name );
+ checkSetElementType( attribute, name, elementType );
+ return ( SetAttribute<X, E> ) attribute;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <E> ListAttribute<? super X, E> getList(String name, Class<E> elementType) {
+ PluralAttribute<? super X, ?, ?> attribute = declaredPluralAttributes.get( name );
+ if ( attribute == null && getSupertype() != null ) {
+ attribute = getSupertype().getPluralAttribute( name );
+ }
+ checkListElementType( attribute, name, elementType );
+ return ( ListAttribute<? super X, E> ) attribute;
+ }
+
+ private <E> void checkListElementType(PluralAttribute<? super X, ?, ?> attribute, String name, Class<E> elementType) {
+ checkTypeForPluralAttributes( "ListAttribute", attribute, name, elementType, PluralAttribute.CollectionType.LIST );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType) {
+ final PluralAttribute<X,?,?> attribute = declaredPluralAttributes.get( name );
+ checkListElementType( attribute, name, elementType );
+ return ( ListAttribute<X, E> ) attribute;
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <K, V> MapAttribute<? super X, K, V> getMap(String name, Class<K> keyType, Class<V> valueType) {
+ PluralAttribute<? super X, ?, ?> attribute = getPluralAttribute( name );
+ if ( attribute == null && getSupertype() != null ) {
+ attribute = getSupertype().getPluralAttribute( name );
+ }
+ checkMapValueType( attribute, name, valueType );
+ final MapAttribute<? super X, K, V> mapAttribute = ( MapAttribute<? super X, K, V> ) attribute;
+ checkMapKeyType( mapAttribute, name, keyType );
+ return mapAttribute;
+ }
+
+ private <V> void checkMapValueType(PluralAttribute<? super X, ?, ?> attribute, String name, Class<V> valueType) {
+ checkTypeForPluralAttributes( "MapAttribute", attribute, name, valueType, PluralAttribute.CollectionType.MAP);
+ }
+
+ private <K,V> void checkMapKeyType(MapAttribute<? super X, K, V> mapAttribute, String name, Class<K> keyType) {
+ if ( mapAttribute.getKeyJavaType() != keyType ) {
+ throw new IllegalArgumentException( "MapAttribute named " + name + " does not support a key of type " + keyType );
+ }
+ }
+
+ public <K, V> MapAttribute<X, K, V> getDeclaredMap(String name, Class<K> keyType, Class<V> valueType) {
+ final PluralAttribute<X,?,?> attribute = declaredPluralAttributes.get( name );
+ checkMapValueType( attribute, name, valueType );
+ final MapAttribute<X, K, V> mapAttribute = ( MapAttribute<X, K, V> ) attribute;
+ checkMapKeyType( mapAttribute, name, keyType );
+ return mapAttribute;
+ }
+}
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractType.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractType.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractType.java 2009-10-26 05:23:40 UTC (rev 17836)
@@ -0,0 +1,44 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @author tags or express
+ * copyright attribution statements applied by the authors. All
+ * third-party contributions are distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.ejb.metamodel;
+
+import java.io.Serializable;
+import javax.persistence.metamodel.Type;
+
+/**
+ * Defines commonality for the JPA {@link Type} hierarchy of interfaces.
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractType<X> implements Type<X>, Serializable {
+ private final Class<X> javaType;
+
+ public AbstractType(Class<X> javaType) {
+ this.javaType = javaType;
+ }
+
+ public Class<X> getJavaType() {
+ return javaType;
+ }
+}
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java 2009-10-26 05:23:40 UTC (rev 17836)
@@ -0,0 +1,356 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @author tags or express
+ * copyright attribution statements applied by the authors. All
+ * third-party contributions are distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.ejb.metamodel;
+
+import java.util.Iterator;
+import java.lang.reflect.Member;
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.Type;
+
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.Value;
+import org.hibernate.mapping.Collection;
+import org.hibernate.mapping.Map;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.OneToMany;
+import org.hibernate.annotations.common.AssertionFailure;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ * @author Emmanuel Bernard
+ */
+public class AttributeFactory {
+ private final MetadataContext context;
+
+ public AttributeFactory(MetadataContext context) {
+ this.context = context;
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X, Y> AttributeImplementor<X, Y> buildAttribute(AbstractManagedType<X> ownerType, Property property) {
+ AttributeContext attrContext = getAttributeContext( property );
+ final AttributeImplementor<X, Y> attribute;
+ if ( attrContext.isCollection() ) {
+ attribute = buildPluralAttribute( ownerType, property, attrContext );
+ }
+ else {
+ final Type<Y> attrType = getType( attrContext.getElementTypeStatus(), attrContext.getElementValue() );
+ attribute = new SingularAttributeImpl<X,Y>(
+ property.getName(),
+ property.getType().getReturnedClass(),
+ ownerType,
+ determineJavaMember( property ),
+ false,
+ false,
+ property.isOptional(),
+ attrType,
+ attrContext.getElementAttributeType()
+ );
+ }
+ return attribute;
+ }
+
+ @SuppressWarnings( "unchecked" )
+ private <X, Y, V, K> AttributeImplementor<X, Y> buildPluralAttribute(AbstractManagedType<X> ownerType, Property property, AttributeContext attrContext) {
+ AttributeImplementor<X, Y> attribute;
+ final Type<V> attrType = getType( attrContext.getElementTypeStatus(), attrContext.getElementValue() );
+ final Class<Y> collectionClass = (Class<Y>) attrContext.getCollectionClass();
+ if ( java.util.Map.class.isAssignableFrom( collectionClass ) ) {
+ final Type<K> keyType = getType( attrContext.getKeyTypeStatus(), attrContext.getKeyValue() );
+ attribute = PluralAttributeImpl.create( ownerType, attrType, collectionClass, keyType )
+ .member( determineJavaMember( property ) )
+ .property( property )
+ .persistentAttributeType( attrContext.getElementAttributeType() )
+ .build();
+ }
+ else {
+ attribute = PluralAttributeImpl.create( ownerType, attrType, collectionClass, null )
+ .member( determineJavaMember( property ) )
+ .property( property )
+ .persistentAttributeType( attrContext.getElementAttributeType() )
+ .build();
+ }
+ return attribute;
+ }
+
+ private <X> Type<X> getType(AttributeContext.TypeStatus elementTypeStatus, Value value) {
+ final org.hibernate.type.Type type = value.getType();
+ switch ( elementTypeStatus ) {
+ case BASIC:
+ return buildBasicType( type );
+ case EMBEDDABLE:
+ return buildEmbeddableType( value, type );
+ case ENTITY:
+ return buildEntityType( type );
+ default:
+ throw new AssertionFailure( "Unknown AttributeContext.TypeStatus: " + elementTypeStatus );
+
+ }
+ }
+
+ @SuppressWarnings( "unchecked" )
+ private <X> Type<X> buildBasicType(org.hibernate.type.Type type) {
+ final Class<X> clazz = type.getReturnedClass();
+ return new BasicTypeImpl<X>( clazz, Type.PersistenceType.BASIC );
+ }
+
+ @SuppressWarnings( "unchecked" )
+ private <X> Type<X> buildEntityType(org.hibernate.type.Type type) {
+ String entityName = ( (org.hibernate.type.EntityType) type ).getAssociatedEntityName();
+ return ( Type<X> ) context.locateEntityType( entityName );
+ }
+
+ @SuppressWarnings( "unchecked" )
+ private <X> Type<X> buildEmbeddableType(Value value, org.hibernate.type.Type type) {
+ //build embedable type
+ final Class<X> clazz = type.getReturnedClass();
+ final EmbeddableTypeImpl<X> embeddableType = new EmbeddableTypeImpl<X>( clazz );
+ context.registerEmbeddedableType( embeddableType );
+ final Component component = (Component) value;
+ final Iterator<Property> subProperties = component.getPropertyIterator();
+ while ( subProperties.hasNext() ) {
+ final Property property = subProperties.next();
+ embeddableType.getBuilder().addAttribute( buildAttribute( embeddableType, property ) );
+ }
+ embeddableType.lock();
+ return embeddableType;
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X, Y> SingularAttributeImpl<X, Y> buildIdAttribute(AbstractManagedType<X> ownerType, Property property) {
+ final AttributeContext attrContext = getAttributeContext( property );
+ final Type<Y> attrType = getType( attrContext.getElementTypeStatus(), attrContext.getElementValue() );
+ final Class<Y> idJavaType = property.getType().getReturnedClass();
+ return new SingularAttributeImpl.Identifier(
+ property.getName(),
+ idJavaType,
+ ownerType,
+ determineJavaMember( property ),
+ attrType,
+ attrContext.getElementAttributeType()
+ );
+ }
+
+ @SuppressWarnings({ "UnusedDeclaration" })
+ private Member determineJavaMember(Property property) {
+ return null;
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X, Y> SingularAttributeImpl<X, Y> buildVerisonAttribute(AbstractManagedType<X> ownerType, Property property) {
+ final AttributeContext attrContext = getAttributeContext( property );
+ final Class<Y> javaType = property.getType().getReturnedClass();
+ final Type<Y> attrType = getType( attrContext.getElementTypeStatus(), attrContext.getElementValue() );
+ return new SingularAttributeImpl.Version(
+ property.getName(),
+ javaType,
+ ownerType,
+ determineJavaMember( property ),
+ attrType,
+ attrContext.getElementAttributeType()
+ );
+ }
+
+ private static class AttributeContext {
+ private final Value elementValue;
+ private final TypeStatus typeStatus;
+ private final Class<?> collectionClass;
+ private final Attribute.PersistentAttributeType attrType;
+ private final Value keyValue;
+ private final TypeStatus keyTypeStatus;
+
+ enum TypeStatus {
+ EMBEDDABLE,
+ ENTITY,
+ BASIC
+ }
+
+ private AttributeContext(
+ Value elementValue,
+ TypeStatus elementTypeStatus,
+ Attribute.PersistentAttributeType elementPAT,
+ Class<?> collectionClass,
+ Value keyValue,
+ TypeStatus keyTypeStatus) {
+ this.elementValue = elementValue;
+ this.typeStatus = elementTypeStatus;
+ this.collectionClass = collectionClass;
+ this.attrType = elementPAT;
+ this.keyValue = keyValue;
+ this.keyTypeStatus = keyTypeStatus;
+ }
+
+ public Value getElementValue() {
+ return elementValue;
+ }
+
+ public TypeStatus getElementTypeStatus() {
+ return typeStatus;
+ }
+
+ public boolean isCollection() {
+ return collectionClass != null;
+ }
+
+ public Class<?> getCollectionClass() {
+ return collectionClass;
+ }
+
+ public Attribute.PersistentAttributeType getElementAttributeType() {
+ return attrType;
+ }
+
+ public Value getKeyValue() {
+ return keyValue;
+ }
+
+ public TypeStatus getKeyTypeStatus() {
+ return keyTypeStatus;
+ }
+ }
+
+ private static AttributeContext getAttributeContext(Property property) {
+ // FIXME the logical level for *To* is different from the Hibernate physical model.
+ // ie a @ManyToOne @AssocTable is a many-to-many for hibernate
+ // and a @OneToMany @AssocTable is a many-to-many for hibernate
+ // FIXME so basically Attribute.PersistentAttributeType is crap at the moment
+ final Value value = property.getValue();
+ final org.hibernate.type.Type type = value.getType();
+ if ( type.isAnyType() ) {
+ throw new UnsupportedOperationException( "any not supported yet" );
+ }
+ else if ( type.isAssociationType() ) {
+ //collection or entity
+ if ( type.isCollectionType() ) {
+ //do collection
+ if ( value instanceof Collection ) {
+ final Collection collValue = ( Collection ) value;
+ final Value elementValue = collValue.getElement();
+ final org.hibernate.type.Type elementType = elementValue.getType();
+ final AttributeContext.TypeStatus elementTypeStatus;
+ final Attribute.PersistentAttributeType elementPAT;
+ final Class<?> collectionClass = collValue.getCollectionType().getReturnedClass();
+
+
+ final Value keyValue;
+ final org.hibernate.type.Type keyType;
+ final AttributeContext.TypeStatus keyTypeStatus;
+ if ( value instanceof Map ) {
+ keyValue = ( ( Map ) value ).getIndex();
+ keyType = keyValue.getType();
+ if ( keyValue instanceof Component ) {
+ keyTypeStatus = AttributeContext.TypeStatus.EMBEDDABLE;
+ }
+ else if ( keyType.isAnyType() ) {
+ throw new UnsupportedOperationException( "collection of any not supported yet" );
+ }
+ else if ( keyType.isAssociationType() ) {
+ keyTypeStatus = AttributeContext.TypeStatus.ENTITY;
+ }
+ else {
+ keyTypeStatus = AttributeContext.TypeStatus.BASIC;
+ }
+ }
+ else {
+ keyValue = null;
+ keyTypeStatus = null;
+ }
+
+ if ( elementValue instanceof Component ) {
+ //collection of components
+ elementTypeStatus = AttributeContext.TypeStatus.EMBEDDABLE;
+ elementPAT = Attribute.PersistentAttributeType.ELEMENT_COLLECTION;
+ }
+ else if ( elementType.isAnyType() ) {
+ throw new UnsupportedOperationException( "collection of any not supported yet" );
+ }
+ else if ( elementType.isAssociationType() ) {
+ //collection of entity
+ elementTypeStatus = AttributeContext.TypeStatus.ENTITY;
+ elementPAT = Attribute.PersistentAttributeType.MANY_TO_MANY;
+ }
+ else {
+ //collection of basic type
+ elementTypeStatus = AttributeContext.TypeStatus.BASIC;
+ elementPAT = Attribute.PersistentAttributeType.ELEMENT_COLLECTION;
+ }
+ return new AttributeContext(
+ elementValue,
+ elementTypeStatus,
+ elementPAT,
+ collectionClass,
+ keyValue,
+ keyTypeStatus
+ );
+ }
+ else if ( value instanceof OneToMany ) {
+ //one to many with FK => entity
+ return new AttributeContext(
+ value,
+ AttributeContext.TypeStatus.ENTITY,
+ Attribute.PersistentAttributeType.ONE_TO_MANY,
+ null, null, null
+ );
+ }
+
+ }
+ else {
+ //ToOne association
+ return new AttributeContext(
+ value,
+ AttributeContext.TypeStatus.ENTITY,
+ Attribute.PersistentAttributeType.MANY_TO_MANY,
+ //FIXME how to differentiate the logical many to one from the one to one (not physical level)
+ null,
+ null,
+ null
+ );
+ }
+ }
+ else if ( property.isComposite() ) {
+ //embeddable
+ return new AttributeContext(
+ value,
+ AttributeContext.TypeStatus.EMBEDDABLE,
+ Attribute.PersistentAttributeType.EMBEDDED,
+ null, null, null
+ );
+
+ }
+ else {
+ //basic type
+ return new AttributeContext(
+ value,
+ AttributeContext.TypeStatus.BASIC,
+ Attribute.PersistentAttributeType.BASIC,
+ null, null, null
+ );
+ }
+ throw new UnsupportedOperationException( "oops, we are missing something: " + property.toString() );
+ }
+
+
+}
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeImplementor.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeImplementor.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeImplementor.java 2009-10-26 05:23:40 UTC (rev 17836)
@@ -0,0 +1,34 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @author tags or express
+ * copyright attribution statements applied by the authors. All
+ * third-party contributions are distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.ejb.metamodel;
+
+import javax.persistence.metamodel.Attribute;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public interface AttributeImplementor<X, Y> extends Attribute<X, Y> {
+}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EmbeddableTypeImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EmbeddableTypeImpl.java 2009-10-25 19:19:48 UTC (rev 17835)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EmbeddableTypeImpl.java 2009-10-26 05:23:40 UTC (rev 17836)
@@ -30,9 +30,12 @@
/**
* @author Emmanuel Bernard
*/
-public class EmbeddableTypeImpl<X> extends ManagedTypeImpl<X> implements EmbeddableType<X>, Serializable {
- EmbeddableTypeImpl(Class<X> clazz, Iterator<Property> properties, MetadataContext context) {
- super(clazz, properties, context);
+public class EmbeddableTypeImpl<X>
+ extends AbstractManagedType<X>
+ implements EmbeddableType<X>, Serializable {
+
+ public EmbeddableTypeImpl(Class<X> javaType) {
+ super( javaType, null );
}
public PersistenceType getPersistenceType() {
Deleted: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeDelegator.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeDelegator.java 2009-10-25 19:19:48 UTC (rev 17835)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeDelegator.java 2009-10-26 05:23:40 UTC (rev 17836)
@@ -1,217 +0,0 @@
-/*
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.ejb.metamodel;
-
-import java.util.Set;
-import java.io.Serializable;
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.CollectionAttribute;
-import javax.persistence.metamodel.EntityType;
-import javax.persistence.metamodel.IdentifiableType;
-import javax.persistence.metamodel.ListAttribute;
-import javax.persistence.metamodel.MapAttribute;
-import javax.persistence.metamodel.PluralAttribute;
-import javax.persistence.metamodel.SetAttribute;
-import javax.persistence.metamodel.SingularAttribute;
-import javax.persistence.metamodel.Type;
-
-/**
- * Delegate to an other EntityType<X>
- * Helps break infinite loops when creating entity metamodel related to each other
- *
- * @author Emmanuel Bernard
- */
-public class EntityTypeDelegator<X> implements EntityType<X>, Serializable {
- private volatile EntityType<X> delegate;
-
- void setDelegate(EntityType<X> delegate) {
- this.delegate = delegate;
- }
-
- public String getName() {
- return delegate.getName();
- }
-
- public <Y> SingularAttribute<? super X, Y> getId(Class<Y> type) {
- return delegate.getId( type );
- }
-
- public <Y> SingularAttribute<? super X, Y> getVersion(Class<Y> type) {
- return delegate.getVersion( type );
- }
-
- public <Y> SingularAttribute<X, Y> getDeclaredId(Class<Y> type) {
- return delegate.getDeclaredId( type );
- }
-
- public <Y> SingularAttribute<X, Y> getDeclaredVersion(Class<Y> type) {
- return delegate.getDeclaredVersion( type );
- }
-
- public IdentifiableType<? super X> getSupertype() {
- return delegate.getSupertype();
- }
-
- public boolean hasSingleIdAttribute() {
- return delegate.hasSingleIdAttribute();
- }
-
- public boolean hasVersionAttribute() {
- return delegate.hasVersionAttribute();
- }
-
- public Set<SingularAttribute<? super X, ?>> getIdClassAttributes() {
- return delegate.getIdClassAttributes();
- }
-
- public Type<?> getIdType() {
- return delegate.getIdType();
- }
-
- public Set<Attribute<? super X, ?>> getAttributes() {
- return delegate.getAttributes();
- }
-
- public Set<Attribute<X, ?>> getDeclaredAttributes() {
- return delegate.getDeclaredAttributes();
- }
-
- public <Y> SingularAttribute<? super X, Y> getSingularAttribute(String name, Class<Y> type) {
- return delegate.getSingularAttribute( name, type );
- }
-
- public <Y> SingularAttribute<X, Y> getDeclaredSingularAttribute(String name, Class<Y> type) {
- return delegate.getDeclaredSingularAttribute( name, type );
- }
-
- public Set<SingularAttribute<? super X, ?>> getSingularAttributes() {
- return delegate.getSingularAttributes();
- }
-
- public Set<SingularAttribute<X, ?>> getDeclaredSingularAttributes() {
- return delegate.getDeclaredSingularAttributes();
- }
-
- public <E> CollectionAttribute<? super X, E> getCollection(String name, Class<E> elementType) {
- return delegate.getCollection( name, elementType );
- }
-
- public <E> SetAttribute<? super X, E> getSet(String name, Class<E> elementType) {
- return delegate.getSet( name, elementType );
- }
-
- public <E> ListAttribute<? super X, E> getList(String name, Class<E> elementType) {
- return delegate.getList( name, elementType );
- }
-
- public <K, V> MapAttribute<? super X, K, V> getMap(String name, Class<K> keyType, Class<V> valueType) {
- return delegate.getMap( name, keyType, valueType );
- }
-
- public <E> CollectionAttribute<X, E> getDeclaredCollection(String name, Class<E> elementType) {
- return delegate.getDeclaredCollection( name, elementType );
- }
-
- public <E> SetAttribute<X, E> getDeclaredSet(String name, Class<E> elementType) {
- return delegate.getDeclaredSet( name, elementType );
- }
-
- public <E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType) {
- return delegate.getDeclaredList( name, elementType );
- }
-
- public <K, V> MapAttribute<X, K, V> getDeclaredMap(String name, Class<K> keyType, Class<V> valueType) {
- return delegate.getDeclaredMap( name, keyType, valueType );
- }
-
- public Set<PluralAttribute<? super X, ?, ?>> getPluralAttributes() {
- return delegate.getPluralAttributes();
- }
-
- public Set<PluralAttribute<X, ?, ?>> getDeclaredPluralAttributes() {
- return delegate.getDeclaredPluralAttributes();
- }
-
- public Attribute<? super X, ?> getAttribute(String name) {
- return delegate.getAttribute( name );
- }
-
- public Attribute<X, ?> getDeclaredAttribute(String name) {
- return delegate.getDeclaredAttribute( name );
- }
-
- public SingularAttribute<? super X, ?> getSingularAttribute(String name) {
- return delegate.getSingularAttribute( name );
- }
-
- public SingularAttribute<X, ?> getDeclaredSingularAttribute(String name) {
- return delegate.getDeclaredSingularAttribute( name );
- }
-
- public CollectionAttribute<? super X, ?> getCollection(String name) {
- return delegate.getCollection( name );
- }
-
- public SetAttribute<? super X, ?> getSet(String name) {
- return delegate.getSet( name );
- }
-
- public ListAttribute<? super X, ?> getList(String name) {
- return delegate.getList( name );
- }
-
- public MapAttribute<? super X, ?, ?> getMap(String name) {
- return delegate.getMap( name );
- }
-
- public CollectionAttribute<X, ?> getDeclaredCollection(String name) {
- return delegate.getDeclaredCollection( name );
- }
-
- public SetAttribute<X, ?> getDeclaredSet(String name) {
- return delegate.getDeclaredSet( name );
- }
-
- public ListAttribute<X, ?> getDeclaredList(String name) {
- return delegate.getDeclaredList( name );
- }
-
- public MapAttribute<X, ?, ?> getDeclaredMap(String name) {
- return delegate.getDeclaredMap( name );
- }
-
- public PersistenceType getPersistenceType() {
- return delegate.getPersistenceType();
- }
-
- public Class<X> getJavaType() {
- return delegate.getJavaType();
- }
-
- public BindableType getBindableType() {
- return delegate.getBindableType();
- }
-
- public Class<X> getBindableJavaType() {
- return delegate.getBindableJavaType();
- }
-}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java 2009-10-25 19:19:48 UTC (rev 17835)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java 2009-10-26 05:23:40 UTC (rev 17836)
@@ -21,168 +21,34 @@
*/
package org.hibernate.ejb.metamodel;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
import java.io.Serializable;
import javax.persistence.metamodel.EntityType;
-import javax.persistence.metamodel.IdentifiableType;
-import javax.persistence.metamodel.SingularAttribute;
-import javax.persistence.metamodel.Type;
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.mapping.Property;
-
/**
+ * Defines the Hibernate implementation of the JPA {@link EntityType} contract.
+ *
+ * @author Steve Ebersole
* @author Emmanuel Bernard
*/
-public class EntityTypeImpl<X> extends ManagedTypeImpl<X> implements EntityType<X>, Serializable {
-
- private final SingularAttribute<X, ?> id;
- private final SingularAttribute<X, ?> version;
+public class EntityTypeImpl<X>
+ extends AbstractIdentifiableType<X>
+ implements EntityType<X>, Serializable {
private final String className;
- private final boolean hasIdentifierProperty;
- private final boolean isVersioned;
- private final Set<SingularAttribute<? super X,?>> idClassAttributes;
- private final IdentifiableType<? super X> supertype;
- public EntityTypeImpl(Class<X> clazz, PersistentClass persistentClass, MetadataContext context) {
- super(clazz, (Iterator<Property>) persistentClass.getPropertyIterator(), context );
- this.className = persistentClass.getClassName();
- this.hasIdentifierProperty = persistentClass.hasIdentifierProperty();
- this.isVersioned = persistentClass.isVersioned();
- id = buildIdAttribute( persistentClass );
- version = buildVersionAttribute( persistentClass );
- final Set<SingularAttribute<? super X, ?>> attributes = buildIdClassAttributes( persistentClass, context );
- this.idClassAttributes = attributes != null ? Collections.unmodifiableSet( attributes ) : null;
-
- PersistentClass superPersistentClass = persistentClass.getSuperclass();
- if ( superPersistentClass == null ) {
- supertype = null;
- }
- else {
- final Class<?> superclass = superPersistentClass.getMappedClass();
- final EntityTypeDelegator<X> entityTypeDelegator = new EntityTypeDelegator<X>();
- context.addDelegator( entityTypeDelegator, superclass );
- supertype = entityTypeDelegator;
- }
+ public EntityTypeImpl(
+ Class<X> javaType,
+ AbstractIdentifiableType<? super X> superType,
+ String className,
+ boolean hasIdentifierProperty,
+ boolean isVersioned) {
+ super( javaType, superType, hasIdentifierProperty, isVersioned );
+ this.className = className;
}
- private <A> SingularAttribute<X, A> buildIdAttribute(PersistentClass persistentClass) {
- if ( hasIdentifierProperty ) {
- final Property identifierProperty = persistentClass.getIdentifierProperty();
- @SuppressWarnings( "unchecked" )
- Class<A> idClass = identifierProperty.getType().getReturnedClass();
- final Type<A> attrType = new BasicTypeImpl<A>( idClass,
- identifierProperty.isComposite() ?
- PersistenceType.EMBEDDABLE :
- PersistenceType.BASIC);
- return SingularAttributeImpl.create(this, attrType )
- .property(identifierProperty)
- //.member( null ) //TODO member
- .id()
- .build();
- }
- else {
- return null;
- }
- }
-
- private <A> SingularAttribute<X, A> buildVersionAttribute(PersistentClass persistentClass) {
- if ( persistentClass.isVersioned() ) {
- @SuppressWarnings( "unchecked" )
- Class<A> versionClass = persistentClass.getVersion().getType().getReturnedClass();
- Property property = persistentClass.getVersion();
- final Type<A> attrType = new BasicTypeImpl<A>( versionClass, PersistenceType.BASIC);
- return SingularAttributeImpl.create(this, attrType )
- .property(property)
- //.member( null ) //TODO member
- .version()
- .build();
- }
- else {
- return null;
- }
- }
-
- private Set<SingularAttribute<? super X, ?>> buildIdClassAttributes(PersistentClass persistentClass, MetadataContext context) {
- if ( hasSingleIdAttribute() ) {
- return null;
- }
- @SuppressWarnings( "unchecked")
- Iterator<Property> properties = persistentClass.getIdentifierMapper().getPropertyIterator();
- Set<SingularAttribute<? super X, ?>> attributes = new HashSet<SingularAttribute<? super X, ?>>();
- while ( properties.hasNext() ) {
- attributes.add(
- (SingularAttribute<? super X, ?>) MetamodelFactory.getAttribute( this, properties.next(), context, true )
- );
- }
- return attributes;
- }
-
public String getName() {
return className;
}
- public <Y> SingularAttribute<? super X, Y> getId(Class<Y> type) {
- //TODO check that type and id.getJavaType() are related
- checkId();
- @SuppressWarnings( "unchecked")
- final SingularAttribute<? super X, Y> result = ( SingularAttribute<? super X, Y> ) id;
- return result;
- }
-
- private void checkId() {
- if ( ! hasSingleIdAttribute() ) throw new IllegalArgumentException("This is an @IdClass");
- }
-
- public <Y> SingularAttribute<? super X, Y> getVersion(Class<Y> type) {
- //TODO check that type and version.getJavaType() are related
- @SuppressWarnings( "unchecked")
- final SingularAttribute<? super X, Y> result = ( SingularAttribute<? super X, Y> ) version;
- return result;
- }
-
- public <Y> SingularAttribute<X, Y> getDeclaredId(Class<Y> type) {
- checkId();
- //TODO check that type and id.getJavaType() are related
- @SuppressWarnings("unchecked")
- final SingularAttribute<X, Y> result = ( SingularAttribute<X, Y> ) id;
- return result;
- }
-
- public <Y> SingularAttribute<X, Y> getDeclaredVersion(Class<Y> type) {
- //TODO check that type and version.getJavaType() are related
- @SuppressWarnings("unchecked")
- final SingularAttribute<X, Y> result = ( SingularAttribute<X, Y> ) version;
- return result;
- }
-
- public IdentifiableType<? super X> getSupertype() {
- return supertype;
- }
-
- public boolean hasSingleIdAttribute() {
- return hasIdentifierProperty;
- }
-
- public boolean hasVersionAttribute() {
- return isVersioned;
- }
-
- public Set<SingularAttribute<? super X, ?>> getIdClassAttributes() {
- if ( hasSingleIdAttribute() ) {
- throw new IllegalArgumentException( "This class does not use @IdClass: " + getName() );
- }
- return idClassAttributes;
- }
-
- public Type<?> getIdType() {
- checkId();
- return id.getType();
- }
-
public BindableType getBindableType() {
return BindableType.ENTITY_TYPE;
}
Deleted: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/ManagedTypeImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/ManagedTypeImpl.java 2009-10-25 19:19:48 UTC (rev 17835)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/ManagedTypeImpl.java 2009-10-26 05:23:40 UTC (rev 17836)
@@ -1,309 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
- * third-party contributors as indicated by either @author tags or express
- * copyright attribution statements applied by the authors. All
- * third-party contributions are distributed under license by Red Hat Inc.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.ejb.metamodel;
-
-import java.util.Iterator;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Collections;
-import java.util.Map;
-import java.util.HashMap;
-import java.io.Serializable;
-
-import javax.persistence.metamodel.ManagedType;
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.SingularAttribute;
-import javax.persistence.metamodel.CollectionAttribute;
-import javax.persistence.metamodel.SetAttribute;
-import javax.persistence.metamodel.ListAttribute;
-import javax.persistence.metamodel.MapAttribute;
-import javax.persistence.metamodel.PluralAttribute;
-import javax.persistence.metamodel.Bindable;
-
-import org.hibernate.mapping.Property;
-import org.hibernate.annotations.common.AssertionFailure;
-
-/**
- * @author Emmanuel Bernard
- */
-public abstract class ManagedTypeImpl<X> implements ManagedType<X>, Serializable {
- private final Class<X> javaClass;
- private final Map<String,Attribute<X, ?>> declaredAttributes;
- private final Map<String,SingularAttribute<X, ?>> declaredSingularAttributes;
- private final Map<String,PluralAttribute<X, ?, ?>> declaredCollections;
-
-
-
- ManagedTypeImpl(Class<X> clazz, Iterator<Property> properties, MetadataContext context) {
- this.javaClass = clazz;
- Map<String,Attribute<X, ?>> localDeclAttr = new HashMap<String,Attribute<X, ?>>();
- Map<String,SingularAttribute<X, ?>> localDeclSingAttr = new HashMap<String,SingularAttribute<X, ?>>();
- Map<String,PluralAttribute<X,?,?>> localDeclPlurAttr = new HashMap<String,PluralAttribute<X,?,?>>();
-
- while ( properties.hasNext() ) {
- Property property = properties.next();
- addProperty( property, context, localDeclAttr, localDeclSingAttr, localDeclPlurAttr );
- }
- declaredAttributes = Collections.unmodifiableMap( localDeclAttr );
- declaredSingularAttributes = Collections.unmodifiableMap( localDeclSingAttr );
- declaredCollections = Collections.unmodifiableMap( localDeclPlurAttr );
- }
-
- private <T> void addProperty(Property property,
- MetadataContext context,
- Map<String,Attribute<X, ?>> localDeclAttr,
- Map<String,SingularAttribute<X, ?>> localDeclSingAttr,
- Map<String,PluralAttribute<X,?,?>> localDeclPlurAttr) {
- final Attribute<X, ?> attribute = MetamodelFactory.getAttribute( this, property, context );
- localDeclAttr.put(attribute.getName(), attribute );
- final Bindable.BindableType bindableType = ( ( Bindable<T> ) attribute ).getBindableType();
- switch ( bindableType ) {
- case SINGULAR_ATTRIBUTE:
- localDeclSingAttr.put(attribute.getName(), (SingularAttribute<X, ?>) attribute );
- break;
- case PLURAL_ATTRIBUTE:
- localDeclPlurAttr.put(attribute.getName(), (PluralAttribute<X,?,?>) attribute );
- break;
- default:
- throw new AssertionFailure( "unknown bindable type: " + bindableType );
- }
-
- }
-
- public Set<Attribute<? super X, ?>> getAttributes() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Set<Attribute<X, ?>> getDeclaredAttributes() {
- return new HashSet<Attribute<X, ?>>(declaredAttributes.values());
- }
-
- public <Y> SingularAttribute<? super X, Y> getSingularAttribute(String name, Class<Y> type) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public <Y> SingularAttribute<X, Y> getDeclaredSingularAttribute(String name, Class<Y> type) {
- final SingularAttribute<X, ?> attr = declaredSingularAttributes.get( name );
- checkTypeForSingleAttribute( "SingularAttribute ", attr, name, type );
- @SuppressWarnings( "unchecked")
- final SingularAttribute<X, Y> result = ( SingularAttribute<X, Y> ) attr;
- return result;
- }
-
- private <Y> void checkTypeForSingleAttribute(String error, SingularAttribute<?,?> attr, String name, Class<Y> type) {
- if (attr == null || ( type != null && !attr.getBindableJavaType().equals( type ) ) ) {
- throw new IllegalArgumentException(
- error + " named " + name
- + (type != null ? " and of type " + type : "")
- + " is not present");
- }
- }
-
- private <Y> void checkTypeForPluralAttributes(String error,
- PluralAttribute<?,?,?> attr,
- String name,
- Class<Y> type,
- PluralAttribute.CollectionType collectionType) {
- if (attr == null
- || ( type != null && !attr.getBindableJavaType().equals( type ) )
- || attr.getCollectionType() != collectionType ) {
- throw new IllegalArgumentException(
- error + " named " + name
- + (type != null ? " and of element type " + type : "")
- + " is not present");
- }
- }
-
- private <Y> void checkNotNull(String error, Attribute<?,?> attr, String name) {
- if (attr == null) {
- throw new IllegalArgumentException(
- error + " named " + name
- + " is not present");
- }
- }
-
- public Set<SingularAttribute<? super X, ?>> getSingularAttributes() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Set<SingularAttribute<X, ?>> getDeclaredSingularAttributes() {
- return new HashSet<SingularAttribute<X, ?>>(declaredSingularAttributes.values());
- }
-
- public <E> CollectionAttribute<? super X, E> getCollection(String name, Class<E> elementType) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public <E> SetAttribute<? super X, E> getSet(String name, Class<E> elementType) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public <E> ListAttribute<? super X, E> getList(String name, Class<E> elementType) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public <K, V> MapAttribute<? super X, K, V> getMap(String name, Class<K> keyType, Class<V> valueType) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public <E> CollectionAttribute<X, E> getDeclaredCollection(String name, Class<E> elementType) {
- final PluralAttribute<X,?,?> attr = declaredCollections.get( name );
- checkTypeForPluralAttributes( "CollectionAttribute ", attr, name, elementType, PluralAttribute.CollectionType.COLLECTION );
- @SuppressWarnings( "unchecked")
- final CollectionAttribute<X, E> result = ( CollectionAttribute<X, E> ) attr;
- return result;
- }
-
- public <E> SetAttribute<X, E> getDeclaredSet(String name, Class<E> elementType) {
- final PluralAttribute<X,?,?> attr = declaredCollections.get( name );
- checkTypeForPluralAttributes( "SetAttribute ", attr, name, elementType, PluralAttribute.CollectionType.SET );
- @SuppressWarnings( "unchecked")
- final SetAttribute<X, E> result = ( SetAttribute<X, E> ) attr;
- return result;
- }
-
- public <E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType) {
- final PluralAttribute<X,?,?> attr = declaredCollections.get( name );
- checkTypeForPluralAttributes( "ListAttribute ", attr, name, elementType, PluralAttribute.CollectionType.LIST );
- @SuppressWarnings( "unchecked")
- final ListAttribute<X, E> result = ( ListAttribute<X, E> ) attr;
- return result;
- }
-
- public <K, V> MapAttribute<X, K, V> getDeclaredMap(String name, Class<K> keyType, Class<V> valueType) {
- final PluralAttribute<X,?,?> attr = declaredCollections.get( name );
- final String error = "MapAttribute ";
- checkTypeForPluralAttributes( error, attr, name, valueType, PluralAttribute.CollectionType.MAP );
- @SuppressWarnings( "unchecked")
- final MapAttribute<X, K, V> result = ( MapAttribute<X, K, V> ) attr;
- if ( result.getKeyJavaType() != keyType ) {
- throw new IllegalArgumentException(
- error + " named " + name + " does not support a key of type " + keyType
- );
- }
- return result;
- }
-
- public Set<PluralAttribute<? super X, ?, ?>> getPluralAttributes() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Set<PluralAttribute<X, ?, ?>> getDeclaredPluralAttributes() {
- return new HashSet<PluralAttribute<X,?,?>>(declaredCollections.values());
- }
-
- public Attribute<? super X, ?> getAttribute(String name) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Attribute<X, ?> getDeclaredAttribute(String name) {
- final Attribute<X, ?> attr = declaredSingularAttributes.get( name );
- checkNotNull( "Attribute ", attr, name );
- return attr;
- }
-
- public SingularAttribute<? super X, ?> getSingularAttribute(String name) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public SingularAttribute<X, ?> getDeclaredSingularAttribute(String name) {
- final SingularAttribute<X, ?> attr = declaredSingularAttributes.get( name );
- checkNotNull( "SingularAttribute ", attr, name );
- return attr;
- }
-
- public CollectionAttribute<? super X, ?> getCollection(String name) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public SetAttribute<? super X, ?> getSet(String name) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public ListAttribute<? super X, ?> getList(String name) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public MapAttribute<? super X, ?, ?> getMap(String name) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public CollectionAttribute<X, ?> getDeclaredCollection(String name) {
- final PluralAttribute<X,?,?> attr = declaredCollections.get( name );
- final String error = "CollectionAttribute ";
- checkNotNull( error, attr, name );
- if ( ! CollectionAttribute.class.isAssignableFrom( attr.getClass() ) ) {
- throw new IllegalArgumentException( name
- + " is not a " + error + ": " + attr.getClass() );
- }
- @SuppressWarnings( "unchecked")
- final CollectionAttribute<X, ?> result = ( CollectionAttribute<X, ?> ) attr;
- return result;
- }
-
- public SetAttribute<X, ?> getDeclaredSet(String name) {
- final PluralAttribute<X,?,?> attr = declaredCollections.get( name );
- final String error = "SetAttribute ";
- checkNotNull( error, attr, name );
- if ( ! CollectionAttribute.class.isAssignableFrom( attr.getClass() ) ) {
- throw new IllegalArgumentException( name
- + " is not a " + error + ": " + attr.getClass() );
- }
- @SuppressWarnings( "unchecked")
- final SetAttribute<X, ?> result = ( SetAttribute<X, ?> ) attr;
- return result;
- }
-
- public ListAttribute<X, ?> getDeclaredList(String name) {
- final PluralAttribute<X,?,?> attr = declaredCollections.get( name );
- final String error = "ListAttribute ";
- checkNotNull( error, attr, name );
- if ( ! CollectionAttribute.class.isAssignableFrom( attr.getClass() ) ) {
- throw new IllegalArgumentException( name
- + " is not a " + error + ": " + attr.getClass() );
- }
- @SuppressWarnings( "unchecked")
- final ListAttribute<X, ?> result = ( ListAttribute<X, ?> ) attr;
- return result;
- }
-
- public MapAttribute<X, ?, ?> getDeclaredMap(String name) {
- final PluralAttribute<X,?,?> attr = declaredCollections.get( name );
- final String error = "MapAttribute ";
- checkNotNull( error, attr, name );
- if ( ! MapAttribute.class.isAssignableFrom( attr.getClass() ) ) {
- throw new IllegalArgumentException( name
- + " is not a " + error + ": " + attr.getClass() );
- }
- @SuppressWarnings( "unchecked")
- final MapAttribute<X,?,?> result = ( MapAttribute<X,?,?> ) attr;
- return result;
- }
-
- public abstract PersistenceType getPersistenceType();
-
- public Class<X> getJavaType() {
- return javaClass;
- }
-}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java 2009-10-25 19:19:48 UTC (rev 17835)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java 2009-10-26 05:23:40 UTC (rev 17836)
@@ -21,43 +21,146 @@
*/
package org.hibernate.ejb.metamodel;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.Map;
-import javax.persistence.metamodel.Metamodel;
-import javax.persistence.metamodel.EmbeddableType;
+import java.util.Set;
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.SingularAttribute;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.Property;
+
/**
- * Keep contextual information related tot he metedata building process.
- * In particular keeps data than theens to be processed in a second phase.
+ * Defines a context for storing information during the building of the {@link MetamodelImpl}.
+ * <p/>
+ * This contextual information includes data needing to be processed in a second pass as well as
+ * cross-references into the built metamodel classes.
+ *
+ * @author Steve Ebersole
* @author Emmanuel Bernard
*/
class MetadataContext {
- private Map<EntityTypeDelegator<?>, Class<?>> delegators = new HashMap<EntityTypeDelegator<?>, Class<?>>();
- private Map<Class<?>, EmbeddableType<?>> embeddables = new HashMap<Class<?>, EmbeddableType<?>>();
+ private final AttributeFactory attributeFactory = new AttributeFactory( this );
- void addDelegator(EntityTypeDelegator<?> type, Class<?> clazz) {
- delegators.put(type, clazz);
+ private HashMap<Class<?>,EntityTypeImpl<?>> entityTypes
+ = new HashMap<Class<?>, EntityTypeImpl<?>>();
+ private HashMap<String,EntityTypeImpl<?>> entityTypesByEntityName
+ = new HashMap<String, EntityTypeImpl<?>>();
+ private LinkedHashMap<PersistentClass,EntityTypeImpl<?>> entityTypesByPersistentClass
+ = new LinkedHashMap<PersistentClass,EntityTypeImpl<?>>();
+ private HashMap<Class<?>, EmbeddableTypeImpl<?>> embeddables
+ = new HashMap<Class<?>, EmbeddableTypeImpl<?>>();
+
+ /**
+ * Given a Hibernate {@link PersistentClass}, locate the corresponding JPA {@link org.hibernate.type.EntityType}
+ * implementation. May retur null if the given {@link PersistentClass} has not yet been processed.
+ *
+ * @param persistentClass The Hibernate (config time) metamodel instance representing an entity.
+ * @return Tne corresponding JPA {@link org.hibernate.type.EntityType}, or null if not yet processed.
+ */
+ public EntityTypeImpl<?> locateEntityType(PersistentClass persistentClass) {
+ return entityTypesByPersistentClass.get( persistentClass );
}
- void postProcess(Metamodel model) {
- for ( Map.Entry<EntityTypeDelegator<?>, Class<?>> entry : delegators.entrySet() ) {
- setDelegate( model, entry );
+ /**
+ * Given a Java {@link Class}, locate the corresponding JPA {@link org.hibernate.type.EntityType}. May
+ * return null which could means that no such mapping exists at least at this time.
+ *
+ * @param javaType The java class.
+ * @return The corresponding JPA {@link org.hibernate.type.EntityType}, or null.
+ */
+ public EntityTypeImpl<?> locateEntityType(Class<?> javaType) {
+ return entityTypes.get( javaType );
+ }
+
+ /**
+ * Given an entity-name, locate the corresponding JPA {@link org.hibernate.type.EntityType}. May
+ * return null which could means that no such mapping exists at least at this time.
+ *
+ * @param entityName The entity-name.
+ * @return The corresponding JPA {@link org.hibernate.type.EntityType}, or null.
+ */
+ public EntityTypeImpl<?> locateEntityType(String entityName) {
+ return entityTypesByEntityName.get( entityName );
+ }
+
+ /**
+ * Retrieves the {@link Class java type} to {@link EntityType} map.
+ *
+ * @return The {@link Class java type} to {@link EntityType} map.
+ */
+ public Map<Class<?>, EntityTypeImpl<?>> getEntityTypeMap() {
+ return Collections.unmodifiableMap( entityTypes );
+ }
+
+ /*package*/ void registerEntityType(PersistentClass persistentClass, EntityTypeImpl<?> entityType) {
+ entityTypes.put( entityType.getBindableJavaType(), entityType );
+ entityTypesByEntityName.put( persistentClass.getEntityName(), entityType );
+ entityTypesByPersistentClass.put( persistentClass, entityType );
+ }
+
+ /*package*/ void registerEmbeddedableType(EmbeddableTypeImpl<?> embeddableType) {
+ embeddables.put( embeddableType.getJavaType(), embeddableType );
+ }
+
+ public Map<Class<?>, EmbeddableTypeImpl<?>> getEmbeddableTypeMap() {
+ return Collections.unmodifiableMap( embeddables );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public void wrapUp() {
+ // IMPL NOTE : entityTypesByPersistentClass is a insertion-ordered map, where the insertion order
+ // ensures that a type's super type is already processed...
+ for ( Map.Entry<PersistentClass,EntityTypeImpl<?>> entry : entityTypesByPersistentClass.entrySet() ) {
+ applyIdMetadata( entry.getKey(), entry.getValue() );
+ applyVersionAttribute( entry.getKey(), entry.getValue() );
+ Iterator<Property> properties = ( Iterator<Property> ) entry.getKey().getPropertyIterator();
+ while ( properties.hasNext() ) {
+ final Property property = properties.next();
+ final Attribute attribute = attributeFactory.buildAttribute( entry.getValue(), property );
+ entry.getValue().getBuilder().addAttribute( attribute );
+ }
+ entry.getValue().lock();
+ // todo : find the X_ style metamodel classes, if present, and inject
}
}
- private <X> void setDelegate(Metamodel model, Map.Entry<EntityTypeDelegator<?>, Class<?>> entry) {
- @SuppressWarnings( "unchecked" )
- final Class<X> entityClass = (Class<X>) entry.getValue();
- @SuppressWarnings( "unchecked" )
- final EntityTypeDelegator<X> delegator = (EntityTypeDelegator<X>) entry.getKey();
- delegator.setDelegate( model.entity( entityClass ) );
+ private <X> void applyIdMetadata(PersistentClass persistentClass, EntityTypeImpl<X> jpaEntityType) {
+ if ( persistentClass.hasIdentifierProperty() ) {
+ jpaEntityType.getBuilder().applyIdAttribute(
+ attributeFactory.buildIdAttribute( jpaEntityType, persistentClass.getIdentifierProperty() )
+ );
+ }
+ else {
+ jpaEntityType.getBuilder().applyIdClassAttributes( buildIdClassAttributes( jpaEntityType, persistentClass ) );
+ }
}
- <X> void addEmbeddableType(Class<X> clazz, EmbeddableType<X> embeddableType) {
- embeddables.put( clazz, embeddableType );
+ private <X> void applyVersionAttribute(PersistentClass persistentClass, EntityTypeImpl<X> jpaEntityType) {
+ if ( ! persistentClass.isVersioned() ) {
+ return;
+ }
+ jpaEntityType.getBuilder().applyVersionAttribute(
+ attributeFactory.buildVerisonAttribute( jpaEntityType, persistentClass.getVersion() )
+ );
}
- Map<Class<?>, EmbeddableType<?>> getEmbeddableTypes() {
- return embeddables;
+ @SuppressWarnings( "unchecked")
+ private <X> Set<SingularAttribute<? super X, ?>> buildIdClassAttributes(
+ EntityTypeImpl<X> jpaEntityType,
+ PersistentClass persistentClass) {
+ Set<SingularAttribute<? super X, ?>> attributes = new HashSet<SingularAttribute<? super X, ?>>();
+ Iterator<Property> properties = persistentClass.getIdentifierMapper().getPropertyIterator();
+ while ( properties.hasNext() ) {
+ attributes.add(
+ (SingularAttribute<? super X, ?>) attributeFactory.buildAttribute( jpaEntityType, properties.next() )
+ );
+ }
+ return attributes;
}
+
}
Deleted: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelFactory.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelFactory.java 2009-10-25 19:19:48 UTC (rev 17835)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelFactory.java 2009-10-26 05:23:40 UTC (rev 17836)
@@ -1,349 +0,0 @@
-/*
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.ejb.metamodel;
-
-import java.util.Iterator;
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.ManagedType;
-import javax.persistence.metamodel.Type;
-import javax.persistence.metamodel.EmbeddableType;
-
-import org.hibernate.annotations.common.AssertionFailure;
-import org.hibernate.mapping.Collection;
-import org.hibernate.mapping.Component;
-import org.hibernate.mapping.Map;
-import org.hibernate.mapping.OneToMany;
-import org.hibernate.mapping.Property;
-import org.hibernate.mapping.Value;
-
-/**
- * @author Emmanuel Bernard
- */
-class MetamodelFactory {
-
- static<X, Y, V, K> Attribute<X, Y> getAttribute(ManagedType<X> ownerType, Property property, MetadataContext metadataContext) {
- return getAttribute( ownerType, property, metadataContext, false );
- }
-
- static<X, Y, V, K> Attribute<X, Y> getAttribute(ManagedType<X> ownerType, Property property, MetadataContext metadataContext, boolean isId) {
- AttributeContext attrContext = getAttributeContext( property );
- final Attribute<X, Y> attribute;
- if ( attrContext.isCollection() ) {
- final Type<V> attrType = getType( attrContext.getElementTypeStatus(), attrContext.getElementValue(), metadataContext );
- @SuppressWarnings( "unchecked" )
- final Class<Y> collectionClass = (Class<Y>) attrContext.getCollectionClass();
- if ( java.util.Map.class.isAssignableFrom( collectionClass ) ) {
- final Type<K> keyType = getType( attrContext.getKeyTypeStatus(), attrContext.getKeyValue(), metadataContext );
- attribute = PluralAttributeImpl.create( ownerType, attrType, collectionClass, keyType )
- // .member( ); //TODO member
- .property( property )
- .persistentAttributeType( attrContext.getElementAttributeType() )
- .build();
- }
- else {
- attribute = PluralAttributeImpl.create( ownerType, attrType, collectionClass, null )
- // .member( ); //TODO member
- .property( property )
- .persistentAttributeType( attrContext.getElementAttributeType() )
- .build();
- }
- }
- else {
- final Type<Y> attrType = getType( attrContext.getElementTypeStatus(), attrContext.getElementValue(), metadataContext );
- final SingularAttributeImpl.Builder<X, Y> xyBuilder = SingularAttributeImpl.create( ownerType, attrType )
- // .member( ); //TODO member
- .property( property )
- .persistentAttributeType( attrContext.getElementAttributeType() );
- if (isId) xyBuilder.id();
- attribute = xyBuilder.build();
- }
- return attribute;
- }
-
- private static <X> Type<X> getType(AttributeContext.TypeStatus elementTypeStatus, Value value, MetadataContext metadataContext) {
- final org.hibernate.type.Type type = value.getType();
- switch ( elementTypeStatus ) {
- case BASIC:
- return buildBasicType( type );
- case EMBEDDABLE:
- return buildEmbeddableType( value, type, metadataContext );
- case ENTITY:
- return buildEntityType( type, metadataContext );
- default:
- throw new AssertionFailure( "Unknown AttributeContext.TypeStatus: " + elementTypeStatus );
-
- }
- }
-
- private static class AttributeContext {
- private final Value elementValue;
- private final TypeStatus typeStatus;
- private final Class<?> collectionClass;
- private final Attribute.PersistentAttributeType attrType;
- private final Value keyValue;
- private final TypeStatus keyTypeStatus;
-
- enum TypeStatus {
- EMBEDDABLE,
- ENTITY,
- BASIC
- }
-
- AttributeContext(Value elementValue,
- TypeStatus elementTypeStatus,
- Attribute.PersistentAttributeType elementPAT,
- Class<?> collectionClass,
- Value keyValue,
- TypeStatus keyTypeStatus) {
- this.elementValue = elementValue;
- this.typeStatus = elementTypeStatus;
- this.collectionClass = collectionClass;
- this.attrType = elementPAT;
- this.keyValue = keyValue;
- this.keyTypeStatus = keyTypeStatus;
- }
-
- public Value getElementValue() {
- return elementValue;
- }
-
- public TypeStatus getElementTypeStatus() {
- return typeStatus;
- }
-
- public boolean isCollection() {
- return collectionClass != null;
- }
-
- public Class<?> getCollectionClass() {
- return collectionClass;
- }
-
- public Attribute.PersistentAttributeType getElementAttributeType() {
- return attrType;
- }
-
- public Value getKeyValue() {
- return keyValue;
- }
-
- public TypeStatus getKeyTypeStatus() {
- return keyTypeStatus;
- }
- }
-
-
- //FIXME the logical level for *To* is different from the Hibernate physical model.
- //ie a @ManyToOne @AssocTable is a many-to-many for hibernate
- //and a @OneToMany @AssocTable is a many-to-many for hibernate
- //FIXME so basically Attribute.PersistentAttributeType is crap at the moment
- private static AttributeContext getAttributeContext(Property property) {
- final Value value = property.getValue();
- org.hibernate.type.Type type = value.getType();
- if ( type.isAnyType() ) {
- throw new UnsupportedOperationException( "any not supported yet" );
- }
- else if ( type.isAssociationType() ) {
- //collection or entity
- if ( type.isCollectionType() ) {
- //do collection
- if ( value instanceof Collection ) {
- final Collection collValue = (Collection) value;
- final Value elementValue = collValue.getElement();
- final org.hibernate.type.Type elementType = elementValue.getType();
- final AttributeContext.TypeStatus elementTypeStatus;
- final Attribute.PersistentAttributeType elementPAT;
- final Class<?> collectionClass = collValue.getCollectionType().getReturnedClass();
-
-
- final Value keyValue;
- final org.hibernate.type.Type keyType;
- final AttributeContext.TypeStatus keyTypeStatus;
- if ( value instanceof Map ) {
- keyValue = ( (Map) value).getIndex();
- keyType = keyValue.getType();
- if ( keyValue instanceof Component ) {
- keyTypeStatus = AttributeContext.TypeStatus.EMBEDDABLE;
- }
- else if ( keyType.isAnyType() ) {
- throw new UnsupportedOperationException( "collection of any not supported yet" );
- }
- else if ( keyType.isAssociationType() ) {
- keyTypeStatus = AttributeContext.TypeStatus.ENTITY;
- }
- else {
- keyTypeStatus = AttributeContext.TypeStatus.BASIC;
- }
- }
- else {
- keyValue = null;
- keyTypeStatus = null;
- }
-
- if ( elementValue instanceof Component ) {
- //collection of components
- elementTypeStatus = AttributeContext.TypeStatus.EMBEDDABLE;
- elementPAT = Attribute.PersistentAttributeType.ELEMENT_COLLECTION;
- }
- else if ( elementType.isAnyType() ) {
- throw new UnsupportedOperationException( "collection of any not supported yet" );
- }
- else if ( elementType.isAssociationType() ) {
- //collection of entity
- elementTypeStatus = AttributeContext.TypeStatus.ENTITY;
- elementPAT = Attribute.PersistentAttributeType.MANY_TO_MANY;
- }
- else {
- //collection of basic type
- elementTypeStatus = AttributeContext.TypeStatus.BASIC;
- elementPAT = Attribute.PersistentAttributeType.ELEMENT_COLLECTION;
- }
- return new AttributeContext(
- elementValue,
- elementTypeStatus,
- elementPAT,
- collectionClass,
- keyValue,
- keyTypeStatus
- );
- }
- else if ( value instanceof OneToMany ) {
- //one to many with FK => entity
- return new AttributeContext(
- value,
- AttributeContext.TypeStatus.ENTITY,
- Attribute.PersistentAttributeType.ONE_TO_MANY,
- null, null, null );
- }
-
- }
- else {
- //ToOne association
- return new AttributeContext(
- value,
- AttributeContext.TypeStatus.ENTITY,
- Attribute.PersistentAttributeType.MANY_TO_MANY, //FIXME how to differentiate the logical many to one from the one to one (not physical level)
- null, null, null);
- }
- }
- else if ( property.isComposite() ) {
- //embeddable
- return new AttributeContext(
- value,
- AttributeContext.TypeStatus.EMBEDDABLE,
- Attribute.PersistentAttributeType.EMBEDDED,
- null, null, null);
-
- }
- else {
- //basic type
- return new AttributeContext(
- value,
- AttributeContext.TypeStatus.BASIC,
- Attribute.PersistentAttributeType.BASIC,
- null, null, null);
- }
- throw new UnsupportedOperationException("oops, we are missing something: " + property.toString() );
- }
-
-
-
- static <X> Type<X> getType(Property property, MetadataContext context) {
- final Value value = property.getValue();
- org.hibernate.type.Type type = value.getType();
- if ( type.isAnyType() ) {
- throw new UnsupportedOperationException( "any not supported yet" );
- }
- else if ( type.isAssociationType() ) {
- //collection or entity
- if ( type.isCollectionType() ) {
- //do collection
- if ( value instanceof Collection ) {
- Collection collValue = (Collection) value;
- collValue.getCollectionType();
- Value elementValue = collValue.getElement();
- final org.hibernate.type.Type elementType = elementValue.getType();
- if ( elementValue instanceof Component ) {
- //colelction of components
- return buildEmbeddableType( elementValue, elementType, context );
- }
- else if ( elementType.isAnyType() ) {
- throw new UnsupportedOperationException( "collection of any not supported yet" );
- }
- else if ( elementType.isAssociationType() ) {
- //collection of entity
- return buildEntityType( elementType, context);
- }
- else {
- //collection of basic type
- buildBasicType( elementType );
- }
- }
- else if ( value instanceof OneToMany ) {
- //one to many with FK => entity
- return buildEntityType( value.getType(), context );
- }
-
- }
- else {
- //ToOne association
- return buildEntityType( type, context );
- }
- }
- else if ( property.isComposite() ) {
- //embeddable
- return buildEmbeddableType( value, type, context );
-
- }
- else {
- //basic type
- return buildBasicType( type );
- }
- throw new UnsupportedOperationException("oops, we are missing something: " + property.toString() );
- }
-
- private static <X> Type<X> buildBasicType(org.hibernate.type.Type type) {
- @SuppressWarnings( "unchecked" )
- final Class<X> clazz = type.getReturnedClass();
- return new BasicTypeImpl<X>( clazz, Type.PersistenceType.BASIC );
- }
-
- private static <X> Type<X> buildEntityType(org.hibernate.type.Type type, MetadataContext context) {
- @SuppressWarnings( "unchecked" )
- final Class<X> clazz = type.getReturnedClass();
- final EntityTypeDelegator<X> entityTypeDelegator = new EntityTypeDelegator<X>();
- context.addDelegator( entityTypeDelegator, clazz );
- return entityTypeDelegator;
- }
-
- private static <X> Type<X> buildEmbeddableType(Value value, org.hibernate.type.Type type, MetadataContext context) {
- //build embedable type
- @SuppressWarnings( "unchecked" )
- final Class<X> clazz = type.getReturnedClass();
- Component component = (Component) value;
- @SuppressWarnings( "unchecked")
- final Iterator<Property> subProperties = component.getPropertyIterator();
- final EmbeddableType<X> embeddableType = new EmbeddableTypeImpl<X>( clazz, subProperties, context );
- context.addEmbeddableType( clazz, embeddableType );
- return embeddableType;
- }
-}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelImpl.java 2009-10-25 19:19:48 UTC (rev 17835)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelImpl.java 2009-10-26 05:23:40 UTC (rev 17836)
@@ -24,8 +24,6 @@
import java.util.Set;
import java.util.Iterator;
import java.util.Map;
-import java.util.HashMap;
-import java.util.Collections;
import java.util.HashSet;
import java.io.Serializable;
import javax.persistence.metamodel.Metamodel;
@@ -36,33 +34,56 @@
import org.hibernate.mapping.PersistentClass;
/**
+ * Hibernate implementation of the JPA {@link Metamodel} contract.
+ *
+ * @author Steve Ebersole
* @author Emmanuel Bernard
*/
public class MetamodelImpl implements Metamodel, Serializable {
+ private final Map<Class<?>,EntityTypeImpl<?>> entities;
+ private final Map<Class<?>, EmbeddableTypeImpl<?>> embeddables;
- private final Map<Class<?>,EntityType<?>> entities;
- private Map<Class<?>, EmbeddableType<?>> embeddables;
-
- public MetamodelImpl(Iterator<PersistentClass> classes) {
- Map<Class<?>,EntityType<?>> localEntities = new HashMap<Class<?>,EntityType<?>>();
+ /**
+ * Instantiate the metamodel from the collection of Hibernate {@link PersistentClass} models.
+ *
+ * @param persistentClasses An iterator over the Hibernate {@link PersistentClass} models.
+ */
+ public MetamodelImpl(Iterator<PersistentClass> persistentClasses) {
MetadataContext context = new MetadataContext();
- while ( classes.hasNext() ) {
- buildEntityType( classes, localEntities, context );
+ while ( persistentClasses.hasNext() ) {
+ locateOrBuildEntityType( persistentClasses.next(), context );
}
- this.entities = Collections.unmodifiableMap( localEntities );
- this.embeddables = Collections.unmodifiableMap( context.getEmbeddableTypes() );
- context.postProcess( this );
+ this.entities = context.getEntityTypeMap();
+ context.wrapUp();
+ this.embeddables = context.getEmbeddableTypeMap();
}
- private <X> void buildEntityType(Iterator<PersistentClass> classes, Map<Class<?>, EntityType<?>> localEntities, MetadataContext context) {
- PersistentClass persistentClass = classes.next();
- @SuppressWarnings( "unchecked" )
- final Class<X> clazz = persistentClass.getMappedClass();
- if ( clazz != null ) {
- localEntities.put( clazz, new EntityTypeImpl<X>(clazz, persistentClass, context) );
+ private EntityTypeImpl<?> locateOrBuildEntityType(PersistentClass persistentClass, MetadataContext context) {
+ EntityTypeImpl<?> entityType = context.locateEntityType( persistentClass );
+ if ( entityType == null ) {
+ entityType = buildEntityType( persistentClass, context );
}
+ return entityType;
}
+ @SuppressWarnings({ "unchecked" })
+ private EntityTypeImpl<?> buildEntityType(PersistentClass persistentClass, MetadataContext context) {
+ final PersistentClass superPersistentClass = persistentClass.getSuperclass();
+ final EntityTypeImpl superEntityType = superPersistentClass == null
+ ? null
+ : locateOrBuildEntityType( superPersistentClass, context );
+ final Class javaType = persistentClass.getMappedClass();
+ EntityTypeImpl entityType = new EntityTypeImpl(
+ javaType,
+ superEntityType,
+ persistentClass.getClassName(),
+ persistentClass.hasIdentifierProperty(),
+ persistentClass.isVersioned()
+ );
+ context.registerEntityType( persistentClass, entityType );
+ return entityType;
+ }
+
/**
* {@inheritDoc}
*/
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/PluralAttributeImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/PluralAttributeImpl.java 2009-10-25 19:19:48 UTC (rev 17835)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/PluralAttributeImpl.java 2009-10-26 05:23:40 UTC (rev 17836)
@@ -21,47 +21,45 @@
*/
package org.hibernate.ejb.metamodel;
+import java.io.Serializable;
import java.lang.reflect.Member;
-import java.util.Map;
+import java.util.Collection;
import java.util.List;
+import java.util.Map;
import java.util.Set;
-import java.util.Collection;
-import java.io.Serializable;
-import javax.persistence.metamodel.PluralAttribute;
-import javax.persistence.metamodel.ManagedType;
-import javax.persistence.metamodel.Type;
-import javax.persistence.metamodel.SetAttribute;
import javax.persistence.metamodel.CollectionAttribute;
import javax.persistence.metamodel.ListAttribute;
import javax.persistence.metamodel.MapAttribute;
+import javax.persistence.metamodel.PluralAttribute;
+import javax.persistence.metamodel.SetAttribute;
+import javax.persistence.metamodel.Type;
import org.hibernate.mapping.Property;
/**
* @author Emmanuel Bernard
+ * @author Steve Ebersole
*/
-public abstract class PluralAttributeImpl<X, C, E> implements PluralAttribute<X, C, E>, Serializable {
+public abstract class PluralAttributeImpl<X, C, E>
+ extends AbstractAttribute<X,C>
+ implements PluralAttribute<X, C, E>, Serializable {
- private final ManagedType<X> ownerType;
private final Type<E> elementType;
- //FIXME member is not serializable
- private final Member member;
- private final String name;
- private final PersistentAttributeType persistentAttributeType;
- private final Class<C> collectionClass;
private PluralAttributeImpl(Builder<X,C,E,?> builder) {
- this.ownerType = builder.type;
+ super(
+ builder.property.getName(),
+ builder.collectionClass,
+ builder.type,
+ builder.member,
+ builder.persistentAttributeType
+ );
this.elementType = builder.attributeType;
- this.collectionClass = builder.collectionClass;
- this.member = builder.member;
- this.name = builder.property.getName();
- this.persistentAttributeType = builder.persistentAttributeType;
}
public static class Builder<X, C, E, K> {
private final Type<E> attributeType;
- private final ManagedType<X> type;
+ private final AbstractManagedType<X> type;
private Member member;
private PersistentAttributeType persistentAttributeType;
private Property property;
@@ -69,7 +67,7 @@
private Type<K> keyType;
- private Builder(ManagedType<X> ownerType, Type<E> attrType, Class<C> collectionClass, Type<K> keyType) {
+ private Builder(AbstractManagedType<X> ownerType, Type<E> attrType, Class<C> collectionClass, Type<K> keyType) {
this.type = ownerType;
this.attributeType = attrType;
this.collectionClass = collectionClass;
@@ -91,94 +89,75 @@
return this;
}
+ @SuppressWarnings( "unchecked" )
public <K> PluralAttributeImpl<X,C,E> build() {
if ( Map.class.isAssignableFrom( collectionClass ) ) {
- @SuppressWarnings( "unchecked" )
final Builder<X,Map<K,E>,E,K> builder = (Builder<X,Map<K,E>,E,K>) this;
- @SuppressWarnings( "unchecked" )
- final PluralAttributeImpl<X, C, E> result = ( PluralAttributeImpl<X, C, E> ) new MapAttributeImpl<X,K,E>(
+ return ( PluralAttributeImpl<X, C, E> ) new MapAttributeImpl<X,K,E>(
builder
);
- return result;
}
else if ( Set.class.isAssignableFrom( collectionClass ) ) {
- @SuppressWarnings( "unchecked" )
final Builder<X,Set<E>, E,?> builder = (Builder<X, Set<E>, E,?>) this;
- @SuppressWarnings( "unchecked" )
- final PluralAttributeImpl<X, C, E> result = ( PluralAttributeImpl<X, C, E> ) new SetAttributeImpl<X,E>(
+ return ( PluralAttributeImpl<X, C, E> ) new SetAttributeImpl<X,E>(
builder
);
- return result;
}
else if ( List.class.isAssignableFrom( collectionClass ) ) {
- @SuppressWarnings( "unchecked" )
final Builder<X, List<E>, E,?> builder = (Builder<X, List<E>, E,?>) this;
- @SuppressWarnings( "unchecked" )
- final PluralAttributeImpl<X, C, E> result = ( PluralAttributeImpl<X, C, E> ) new ListAttributeImpl<X,E>(
+ return ( PluralAttributeImpl<X, C, E> ) new ListAttributeImpl<X,E>(
builder
);
- return result;
}
else if ( Collection.class.isAssignableFrom( collectionClass ) ) {
- @SuppressWarnings( "unchecked" )
final Builder<X, Collection<E>,E,?> builder = (Builder<X, Collection<E>, E,?>) this;
- @SuppressWarnings( "unchecked" )
- final PluralAttributeImpl<X, C, E> result = ( PluralAttributeImpl<X, C, E> ) new CollectionAttributeImpl<X, E>(
+ return ( PluralAttributeImpl<X, C, E> ) new CollectionAttributeImpl<X, E>(
builder
);
- return result;
}
throw new UnsupportedOperationException( "Unkown collection: " + collectionClass );
}
}
public static <X,C,E,K> Builder<X,C,E,K> create(
- ManagedType<X> ownerType,
+ AbstractManagedType<X> ownerType,
Type<E> attrType,
Class<C> collectionClass,
Type<K> keyType) {
return new Builder<X,C,E,K>(ownerType, attrType, collectionClass, keyType);
}
- public String getName() {
- return name;
- }
-
- public PersistentAttributeType getPersistentAttributeType() {
- return persistentAttributeType;
- }
-
- public ManagedType<X> getDeclaringType() {
- return ownerType;
- }
-
- public Class<C> getJavaType() {
- return collectionClass;
- }
-
- public abstract CollectionType getCollectionType();
-
+ /**
+ * {@inheritDoc}
+ */
public Type<E> getElementType() {
return elementType;
}
-
- public Member getJavaMember() {
- return member;
- }
-
+ /**
+ * {@inheritDoc}
+ */
public boolean isAssociation() {
return true;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isCollection() {
return true;
}
+ /**
+ * {@inheritDoc}
+ */
public BindableType getBindableType() {
return BindableType.PLURAL_ATTRIBUTE;
}
+ /**
+ * {@inheritDoc}
+ */
public Class<E> getBindableJavaType() {
return elementType.getJavaType();
}
@@ -188,6 +167,9 @@
super( xceBuilder );
}
+ /**
+ * {@inheritDoc}
+ */
public CollectionType getCollectionType() {
return CollectionType.SET;
}
@@ -198,6 +180,9 @@
super( xceBuilder );
}
+ /**
+ * {@inheritDoc}
+ */
public CollectionType getCollectionType() {
return CollectionType.COLLECTION;
}
@@ -208,6 +193,9 @@
super( xceBuilder );
}
+ /**
+ * {@inheritDoc}
+ */
public CollectionType getCollectionType() {
return CollectionType.LIST;
}
@@ -221,14 +209,23 @@
this.keyType = xceBuilder.keyType;
}
+ /**
+ * {@inheritDoc}
+ */
public CollectionType getCollectionType() {
return CollectionType.MAP;
}
+ /**
+ * {@inheritDoc}
+ */
public Class<K> getKeyJavaType() {
return keyType.getJavaType();
}
+ /**
+ * {@inheritDoc}
+ */
public Type<K> getKeyType() {
return keyType;
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/SingularAttributeImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/SingularAttributeImpl.java 2009-10-25 19:19:48 UTC (rev 17835)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/SingularAttributeImpl.java 2009-10-26 05:23:40 UTC (rev 17836)
@@ -23,145 +23,123 @@
import java.lang.reflect.Member;
import java.io.Serializable;
-import javax.persistence.metamodel.ManagedType;
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.Type;
-import org.hibernate.mapping.Property;
-
/**
* @author Emmanuel Bernard
+ * @author Steve Ebersole
*/
-public class SingularAttributeImpl<X, Y> implements SingularAttribute<X, Y>, Serializable {
- private final boolean isId;
+public class SingularAttributeImpl<X, Y>
+ extends AbstractAttribute<X,Y>
+ implements SingularAttribute<X, Y>, Serializable {
+ private final boolean isIdentifier;
private final boolean isVersion;
private final boolean isOptional;
- private final ManagedType<X> ownerType;
- private final Type<Y> attrType;
- //FIXME member is not serializable
- private final Member member;
- private final String name;
- private final PersistentAttributeType persistentAttributeType;
+ private final Type<Y> attributeType;
- private SingularAttributeImpl(Builder<X,Y> builder) {
- this.ownerType = builder.type;
- this.attrType = builder.attributeType;
- this.isId = builder.isId;
- this.isVersion = builder.isVersion;
- final Property property = builder.property;
- this.isOptional = property.isOptional();
- this.member = builder.member;
- this.name = property.getName();
- if ( builder.persistentAttributeType != null) {
- this.persistentAttributeType = builder.persistentAttributeType;
- }
- else {
- this.persistentAttributeType = property.isComposite() ?
- PersistentAttributeType.EMBEDDED :
- PersistentAttributeType.BASIC;
- }
+ public SingularAttributeImpl(
+ String name,
+ Class<Y> javaType,
+ AbstractManagedType<X> declaringType,
+ Member member,
+ boolean isIdentifier,
+ boolean isVersion,
+ boolean isOptional,
+ Type<Y> attributeType,
+ PersistentAttributeType persistentAttributeType) {
+ super( name, javaType, declaringType, member, persistentAttributeType );
+ this.isIdentifier = isIdentifier;
+ this.isVersion = isVersion;
+ this.isOptional = isOptional;
+ this.attributeType = attributeType;
}
- public static class Builder<X,Y> {
- private boolean isId;
- private boolean isVersion;
- //private boolean isOptional = true;
- private final Type<Y> attributeType;
- private final ManagedType<X> type;
- private Member member;
- //private String name;
- private PersistentAttributeType persistentAttributeType;
- private Property property;
-
-
- private Builder(ManagedType<X> ownerType, Type<Y> attrType) {
- this.type = ownerType;
- this.attributeType = attrType;
+ /**
+ * Subclass used to simply instantiation of singular attributes representing an entity's
+ * identifier.
+ */
+ public static class Identifier<X,Y> extends SingularAttributeImpl<X,Y> {
+ public Identifier(
+ String name,
+ Class<Y> javaType,
+ AbstractManagedType<X> declaringType,
+ Member member,
+ Type<Y> attributeType,
+ PersistentAttributeType persistentAttributeType) {
+ super( name, javaType, declaringType, member, true, false, false, attributeType, persistentAttributeType );
}
+ }
- public Builder<X,Y> member(Member member) {
- this.member = member;
- return this;
+ /**
+ * Subclass used to simply instantiation of singular attributes representing an entity's
+ * version.
+ */
+ public static class Version<X,Y> extends SingularAttributeImpl<X,Y> {
+ public Version(
+ String name,
+ Class<Y> javaType,
+ AbstractManagedType<X> declaringType,
+ Member member,
+ Type<Y> attributeType,
+ PersistentAttributeType persistentAttributeType) {
+ super( name, javaType, declaringType, member, false, true, false, attributeType, persistentAttributeType );
}
-
- public Builder<X, Y> property(Property property) {
- this.property = property;
- return this;
- }
-
- public Builder<X,Y> id() {
- isId = true;
- return this;
- }
-
- public Builder<X,Y> version() {
- isVersion = true;
- return this;
- }
-
- public SingularAttribute<X, Y> build() {
- return new SingularAttributeImpl<X,Y>(this);
- }
-
- public Builder<X, Y> persistentAttributeType(PersistentAttributeType attrType) {
- this.persistentAttributeType = attrType;
- return this;
- }
}
- public static <X,Y> Builder<X,Y> create(ManagedType<X> ownerType, Type<Y> attrType) {
- return new Builder<X,Y>(ownerType, attrType);
- }
-
+ /**
+ * {@inheritDoc}
+ */
public boolean isId() {
- return isId;
+ return isIdentifier;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isVersion() {
return isVersion;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isOptional() {
return isOptional;
}
+ /**
+ * {@inheritDoc}
+ */
public Type<Y> getType() {
- return attrType;
+ return attributeType;
}
- public String getName() {
- return name;
- }
-
- public PersistentAttributeType getPersistentAttributeType() {
- return persistentAttributeType;
- }
-
- public ManagedType<X> getDeclaringType() {
- return ownerType;
- }
-
- public Class<Y> getJavaType() {
- return attrType.getJavaType();
- }
-
- public Member getJavaMember() {
- return member;
- }
-
+ /**
+ * {@inheritDoc}
+ */
public boolean isAssociation() {
return false;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isCollection() {
return false;
}
+ /**
+ * {@inheritDoc}
+ */
public BindableType getBindableType() {
return BindableType.SINGULAR_ATTRIBUTE;
}
+ /**
+ * {@inheritDoc}
+ */
public Class<Y> getBindableJavaType() {
- return attrType.getJavaType();
+ return attributeType.getJavaType();
}
}
14 years, 6 months
Hibernate SVN: r17835 - core/trunk/distribution.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-10-25 15:19:48 -0400 (Sun, 25 Oct 2009)
New Revision: 17835
Modified:
core/trunk/distribution/pom.xml
Log:
HHH-4526 - Add better metainf information to the hibernate all jar gennerated for dist
Modified: core/trunk/distribution/pom.xml
===================================================================
--- core/trunk/distribution/pom.xml 2009-10-25 19:11:38 UTC (rev 17834)
+++ core/trunk/distribution/pom.xml 2009-10-25 19:19:48 UTC (rev 17835)
@@ -55,6 +55,15 @@
<descriptor>src/assembly/hibernate-all.xml</descriptor>
<descriptor>src/assembly/dist.xml</descriptor>
</descriptors>
+ <archive>
+ <manifest>
+ <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
+ <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+ </manifest>
+ <manifestEntries>
+ <Implementation-URL>http://hibernate.org</Implementation-URL>
+ </manifestEntries>
+ </archive>
</configuration>
</plugin>
</plugins>
14 years, 6 months
Hibernate SVN: r17834 - in core/trunk/distribution: src/assembly and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-10-25 15:11:38 -0400 (Sun, 25 Oct 2009)
New Revision: 17834
Modified:
core/trunk/distribution/pom.xml
core/trunk/distribution/src/assembly/dist.xml
core/trunk/distribution/src/assembly/hibernate-all.xml
Log:
HHH-4525 - Trunk is not including the newly added modules to the distribution bundle
Modified: core/trunk/distribution/pom.xml
===================================================================
--- core/trunk/distribution/pom.xml 2009-10-25 18:30:03 UTC (rev 17833)
+++ core/trunk/distribution/pom.xml 2009-10-25 19:11:38 UTC (rev 17834)
@@ -107,6 +107,21 @@
<artifactId>hibernate-proxool</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>hibernate-annotations</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>hibernate-envers</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<!-- optional deps for bytecode providers since they are optional on core -->
<dependency>
Modified: core/trunk/distribution/src/assembly/dist.xml
===================================================================
--- core/trunk/distribution/src/assembly/dist.xml 2009-10-25 18:30:03 UTC (rev 17833)
+++ core/trunk/distribution/src/assembly/dist.xml 2009-10-25 19:11:38 UTC (rev 17834)
@@ -24,9 +24,9 @@
~ Boston, MA 02110-1301 USA
-->
-<assembly xmlns="http://maven.apache.org/POM/4.0.0"
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.1.0-SNAPSHOT.xsd">
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<!--
Produces a dist-style bundle similar to what previous (non-mavenized) versions of
@@ -106,18 +106,6 @@
<dependencySet>
<outputDirectory>lib/optional/jbosscache</outputDirectory>
<includes>
- <include>jboss:jboss-cache</include>
- <include>concurrent:concurrent:1.3.4</include>
- <include>jboss:jboss-common:4.0.2</include>
- <include>jboss:jboss-jmx:4.0.2</include>
- <include>jboss:jboss-system:4.0.2</include>
- <include>jgroups:jgroups-all:2.2.7</include>
- </includes>
- </dependencySet>
-
- <dependencySet>
- <outputDirectory>lib/optional/jbosscache2</outputDirectory>
- <includes>
<include>org.jboss.cache:jbosscache-core</include>
</includes>
</dependencySet>
Modified: core/trunk/distribution/src/assembly/hibernate-all.xml
===================================================================
--- core/trunk/distribution/src/assembly/hibernate-all.xml 2009-10-25 18:30:03 UTC (rev 17833)
+++ core/trunk/distribution/src/assembly/hibernate-all.xml 2009-10-25 19:11:38 UTC (rev 17834)
@@ -25,9 +25,9 @@
~
-->
-<assembly xmlns="http://maven.apache.org/POM/4.0.0"
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.1.0-SNAPSHOT.xsd">
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<!--
Take the 'core' resoures and build a jar, ala the legacy hibernate3.jar
@@ -46,6 +46,10 @@
<includes>
<include>org.hibernate:*</include>
</includes>
+ <excludes>
+ <exclude>org.hibernate:hibernate-tools:*</exclude>
+ <exclude>org.hibernate:jtidy:*</exclude>
+ </excludes>
</dependencySet>
</dependencySets>
14 years, 6 months
Hibernate SVN: r17833 - in search/trunk/src/main/java/org/hibernate/search: sandbox and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-10-25 14:30:03 -0400 (Sun, 25 Oct 2009)
New Revision: 17833
Added:
search/trunk/src/main/java/org/hibernate/search/sandbox/
search/trunk/src/main/java/org/hibernate/search/sandbox/standalone/
search/trunk/src/main/java/org/hibernate/search/sandbox/standalone/FullTextManager.java
search/trunk/src/main/java/org/hibernate/search/sandbox/standalone/FullTextQuery.java
search/trunk/src/main/java/org/hibernate/search/sandbox/standalone/InstanceTransactionContext.java
search/trunk/src/main/java/org/hibernate/search/sandbox/standalone/LuceneFullTextManager.java
Log:
HSEARCH-407 Initial PoC start on a pure Lucene storage (ie not relying on Hibernate Core
Added: search/trunk/src/main/java/org/hibernate/search/sandbox/standalone/FullTextManager.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/sandbox/standalone/FullTextManager.java (rev 0)
+++ search/trunk/src/main/java/org/hibernate/search/sandbox/standalone/FullTextManager.java 2009-10-25 18:30:03 UTC (rev 17833)
@@ -0,0 +1,82 @@
+package org.hibernate.search.sandbox.standalone;
+
+import org.hibernate.search.*;
+
+import java.io.Serializable;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public interface FullTextManager {
+
+ /**
+ * Returns the entity instance of a given type and id value
+ */
+ public <T> T get(Class<T> entityType, Serializable id);
+
+ /**
+ * Create a fulltext query on top of a native Lucene query returning the matching objects
+ * of type <code>entities</code> and their respective subclasses.
+ *
+ * @param luceneQuery The native Lucene query to be rn against the Lucene index.
+ * @param entities List of classes for type filtering. The query result will only return entities of
+ * the specified types and their respective subtype. If no class is specified no type filtering will take place.
+ *
+ * @return A <code>FullTextQuery</code> wrapping around the native Lucene wuery.
+ *
+ * @throws IllegalArgumentException if entityType is <code>null</code> or not a class or superclass annotated with <code>@Indexed</code>.
+ */
+ FullTextQuery createFullTextQuery(org.apache.lucene.search.Query luceneQuery, Class<?>... entities);
+
+ /**
+ * Force the (re)indexing of a given <b>managed</b> object.
+ * Indexation is batched per transaction: if a transaction is active, the operation
+ * will not affect the index at least until commit.
+ *
+ * @param entity The entity to index - must not be <code>null</code>.
+ *
+ * @throws IllegalArgumentException if entity is null or not an @Indexed entity
+ */
+ <T> void index(T entity);
+
+ /**
+ * @return the <code>SearchFactory</code> instance.
+ */
+ SearchFactory getSearchFactory();
+
+ /**
+ * Remove the entity with the type <code>entityType</code> and the identifier <code>id</code> from the index.
+ * If <code>id == null</code> all indexed entities of this type and its indexed subclasses are deleted. In this
+ * case this method behaves like {@link #purgeAll(Class)}.
+ *
+ * @param entityType The type of the entity to delete.
+ * @param id The id of the entity to delete.
+ *
+ * @throws IllegalArgumentException if entityType is <code>null</code> or not a class or superclass annotated with <code>@Indexed</code>.
+ */
+ public <T> void purge(Class<T> entityType, Serializable id);
+
+ /**
+ * Remove all entities from of particular class and all its subclasses from the index.
+ *
+ * @param entityType The class of the entities to remove.
+ *
+ * @throws IllegalArgumentException if entityType is <code>null</code> or not a class or superclass annotated with <code>@Indexed</code>.
+ */
+ public <T> void purgeAll(Class<T> entityType);
+
+ /**
+ * Flush all index changes forcing Hibernate Search to apply all changes to the index not waiting for the batch limit.
+ */
+ public void flushToIndexes();
+
+ //FIXME add support for mass indexer: does it even makes sense?
+ /**
+ * Creates a MassIndexer to rebuild the indexes of some
+ * or all indexed entity types.
+ * Instances cannot be reused.
+ * @param types optionally restrict the operation to selected types
+ * @return
+ */
+ //public MassIndexer createIndexer(Class<?>... types);
+}
Added: search/trunk/src/main/java/org/hibernate/search/sandbox/standalone/FullTextQuery.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/sandbox/standalone/FullTextQuery.java (rev 0)
+++ search/trunk/src/main/java/org/hibernate/search/sandbox/standalone/FullTextQuery.java 2009-10-25 18:30:03 UTC (rev 17833)
@@ -0,0 +1,10 @@
+package org.hibernate.search.sandbox.standalone;
+
+import java.util.List;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public interface FullTextQuery {
+ List<?> list();
+}
Added: search/trunk/src/main/java/org/hibernate/search/sandbox/standalone/InstanceTransactionContext.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/sandbox/standalone/InstanceTransactionContext.java (rev 0)
+++ search/trunk/src/main/java/org/hibernate/search/sandbox/standalone/InstanceTransactionContext.java 2009-10-25 18:30:03 UTC (rev 17833)
@@ -0,0 +1,80 @@
+package org.hibernate.search.sandbox.standalone;
+
+import org.hibernate.search.backend.TransactionContext;
+
+import javax.transaction.Synchronization;
+import javax.transaction.Status;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * Transaction context that contains transaction boundaries methods.
+ * While not "transactional" it allows to call Synchronization elements
+ *
+ * @author Emmanuel Bernard
+ */
+public class InstanceTransactionContext implements TransactionContext {
+ private State transactionState = State.NO_TRANSACTION;
+ private final List<Synchronization> synchronizations = new ArrayList<Synchronization>(5);
+
+ public void beginTransaction() {
+ if (transactionState != State.NO_TRANSACTION) {
+ throw new IllegalStateException( "Transaction context already started: " + transactionState);
+ }
+ transactionState = State.IN_TRANSACTION;
+ }
+
+ public void commit() {
+ if ( transactionState != State.IN_TRANSACTION ) {
+ throw new IllegalStateException( "Transaction context not in active state: " + transactionState);
+ }
+ try {
+ for (Synchronization sync : synchronizations) {
+ sync.beforeCompletion();
+ }
+ for (Synchronization sync : synchronizations) {
+ sync.afterCompletion( Status.STATUS_COMMITTED );
+ }
+ }
+ finally {
+ synchronizations.clear();
+ transactionState = State.TRANSACTION_CLOSED;
+ }
+ }
+
+ public void rollback() {
+ if ( transactionState != State.IN_TRANSACTION ) {
+ throw new IllegalStateException( "Transaction context not in active state: " + transactionState);
+ }
+ try {
+ for (Synchronization sync : synchronizations) {
+ sync.beforeCompletion();
+ }
+ for (Synchronization sync : synchronizations) {
+ sync.afterCompletion( Status.STATUS_ROLLEDBACK );
+ }
+ }
+ finally {
+ synchronizations.clear();
+ transactionState = State.TRANSACTION_CLOSED;
+ }
+ }
+
+ public boolean isTransactionInProgress() {
+ return transactionState == State.IN_TRANSACTION;
+ }
+
+ public Object getTransactionIdentifier() {
+ return this;
+ }
+
+ public void registerSynchronization(Synchronization synchronization) {
+ synchronizations.add( synchronization );
+ }
+
+ private static enum State {
+ NO_TRANSACTION,
+ IN_TRANSACTION,
+ TRANSACTION_CLOSED
+ }
+}
Added: search/trunk/src/main/java/org/hibernate/search/sandbox/standalone/LuceneFullTextManager.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/sandbox/standalone/LuceneFullTextManager.java (rev 0)
+++ search/trunk/src/main/java/org/hibernate/search/sandbox/standalone/LuceneFullTextManager.java 2009-10-25 18:30:03 UTC (rev 17833)
@@ -0,0 +1,140 @@
+package org.hibernate.search.sandbox.standalone;
+
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.index.Term;
+import org.hibernate.search.MassIndexer;
+import org.hibernate.search.SearchFactory;
+import org.hibernate.search.ProjectionConstants;
+import org.hibernate.search.SearchException;
+import org.hibernate.search.backend.Work;
+import org.hibernate.search.backend.WorkType;
+import org.hibernate.search.engine.DocumentBuilderIndexedEntity;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+
+import java.io.Serializable;
+import java.util.Set;
+import java.util.List;
+
+/**
+ * Implements a standalone full text service.
+ * Data is stored in Lucene
+ *
+ * @author Emmanuel Bernard
+ */
+public class LuceneFullTextManager implements FullTextManager {
+ private final SearchFactoryImplementor searchFactory;
+ private final InstanceTransactionContext transactionContext;
+
+ LuceneFullTextManager(SearchFactoryImplementor sfi) {
+ this.searchFactory = sfi;
+ this.transactionContext = new InstanceTransactionContext();
+ transactionContext.beginTransaction();
+ }
+
+ public <T> T get(Class<T> entityType, Serializable id) {
+ final DocumentBuilderIndexedEntity<?> docBuilder = searchFactory.getDocumentBuilderIndexedEntity( entityType );
+ if ( docBuilder == null ) {
+ String msg = "Entity to retrueve is not an @Indexed entity: " + entityType.getClass().getName();
+ throw new IllegalArgumentException( msg );
+ }
+ if (id == null) {
+ throw new IllegalArgumentException( "Identifier cannot be null" );
+ }
+ Query luceneQuery = new TermQuery( docBuilder.getTerm( id ) );
+ FullTextQuery searchQuery = createFullTextQuery( luceneQuery, entityType );
+ List<?> results = searchQuery.list();
+ if (results.size() > 1) {
+ //TODO find correct exception
+ throw new SearchException("Several entities with he same id found: " + entityType + "#" + id);
+ }
+ @SuppressWarnings( "unchecked" )
+ final T result = (T) ( results.size() == 0 ? null : results.get( 0 ) );
+ return result;
+ }
+
+ public FullTextQuery createFullTextQuery(Query luceneQuery, Class<?>... entities) {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+
+
+ /**
+ * (Re-)index an entity.
+ * The entity must be associated with the session and non indexable entities are ignored.
+ *
+ * @param entity The entity to index - must not be <code>null</code>.
+ *
+ * @throws IllegalArgumentException if entity is null or not an @Indexed entity
+ */
+ public <T> void index(T entity) {
+ if ( entity == null ) {
+ throw new IllegalArgumentException( "Entity to index should not be null" );
+ }
+
+ Class<?> clazz = getClass( entity );
+ //TODO cache that at the FTSession level
+ //not strictly necessary but a small optimization
+ final DocumentBuilderIndexedEntity<?> docBuilder = searchFactory.getDocumentBuilderIndexedEntity( clazz );
+ if ( docBuilder == null ) {
+ String msg = "Entity to index is not an @Indexed entity: " + entity.getClass().getName();
+ throw new IllegalArgumentException( msg );
+ }
+ Serializable id = docBuilder.getId( entity );
+ Work<T> work = new Work<T>( entity, id, WorkType.INDEX );
+ searchFactory.getWorker().performWork( work, transactionContext );
+
+ //TODO
+ //need to add elements in a queue kept at the Session level
+ //the queue will be processed by a Lucene(Auto)FlushEventListener
+ //note that we could keep this queue somewhere in the event listener in the mean time but that requires
+ //a synchronized hashmap holding this queue on a per session basis plus some session house keeping (yuk)
+ //another solution would be to subclass SessionImpl instead of having this LuceneSession delegation model
+ //this is an open discussion
+ }
+
+ private Class<?> getClass(Object entity) {
+ return entity.getClass();
+ }
+
+ public SearchFactory getSearchFactory() {
+ return searchFactory;
+ }
+
+ public <T> void purge(Class<T> entityType, Serializable id) {
+ if ( entityType == null ) {
+ return;
+ }
+
+ Set<Class<?>> targetedClasses = searchFactory.getIndexedTypesPolymorphic( new Class[] {entityType} );
+ if ( targetedClasses.isEmpty() ) {
+ String msg = entityType.getName() + " is not an indexed entity or a subclass of an indexed entity";
+ throw new IllegalArgumentException( msg );
+ }
+
+ for ( Class<?> clazz : targetedClasses ) {
+ if ( id == null ) {
+ createAndPerformWork( clazz, null, WorkType.PURGE_ALL );
+ }
+ else {
+ createAndPerformWork( clazz, id, WorkType.PURGE );
+ }
+ }
+ }
+
+ private <T> void createAndPerformWork(Class<T> clazz, Serializable id, WorkType workType) {
+ Work<T> work;
+ work = new Work<T>( clazz, id, workType );
+ searchFactory.getWorker().performWork( work, transactionContext );
+ }
+
+ public <T> void purgeAll(Class<T> entityType) {
+ purge( entityType, null );
+ }
+
+ public void flushToIndexes() {
+ searchFactory.getWorker().flushWorks( transactionContext );
+ }
+}
14 years, 6 months
Hibernate SVN: r17832 - core/trunk/core/src/test/java/org/hibernate/dialect/resolver.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-10-25 14:23:36 -0400 (Sun, 25 Oct 2009)
New Revision: 17832
Modified:
core/trunk/core/src/test/java/org/hibernate/dialect/resolver/DialectFactoryTest.java
Log:
HHH-4442 : sybase dialects and dialect factory
Modified: core/trunk/core/src/test/java/org/hibernate/dialect/resolver/DialectFactoryTest.java
===================================================================
--- core/trunk/core/src/test/java/org/hibernate/dialect/resolver/DialectFactoryTest.java 2009-10-25 17:53:52 UTC (rev 17831)
+++ core/trunk/core/src/test/java/org/hibernate/dialect/resolver/DialectFactoryTest.java 2009-10-25 18:23:36 UTC (rev 17832)
@@ -32,7 +32,6 @@
import junit.framework.Test;
import org.hibernate.HibernateException;
-import org.hibernate.dialect.resolver.DialectFactory;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.MySQLDialect;
@@ -40,7 +39,6 @@
import org.hibernate.dialect.DerbyDialect;
import org.hibernate.dialect.IngresDialect;
import org.hibernate.dialect.SQLServerDialect;
-import org.hibernate.dialect.SybaseDialect;
import org.hibernate.dialect.InformixDialect;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.Oracle8iDialect;
@@ -48,6 +46,8 @@
import org.hibernate.dialect.Oracle10gDialect;
import org.hibernate.dialect.TestingDialects;
import org.hibernate.dialect.Mocks;
+import org.hibernate.dialect.SybaseASE15Dialect;
+import org.hibernate.dialect.SybaseAnywhereDialect;
import org.hibernate.cfg.Environment;
/**
@@ -113,8 +113,9 @@
testDetermination( "INGRES", IngresDialect.class );
testDetermination( "Microsoft SQL Server Database", SQLServerDialect.class );
testDetermination( "Microsoft SQL Server", SQLServerDialect.class );
- testDetermination( "Sybase SQL Server", SybaseDialect.class );
- testDetermination( "Adaptive Server Enterprise", SybaseDialect.class );
+ testDetermination( "Sybase SQL Server", SybaseASE15Dialect.class );
+ testDetermination( "Adaptive Server Enterprise", SybaseASE15Dialect.class );
+ testDetermination( "Adaptive Server Anywhere", SybaseAnywhereDialect.class );
testDetermination( "Informix Dynamic Server", InformixDialect.class );
testDetermination( "DB2/NT", DB2Dialect.class );
testDetermination( "DB2/LINUX", DB2Dialect.class );
14 years, 6 months
Hibernate SVN: r17831 - in search/trunk/src/main/java/org/hibernate/search: engine and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-10-25 13:53:52 -0400 (Sun, 25 Oct 2009)
New Revision: 17831
Modified:
search/trunk/src/main/java/org/hibernate/search/cfg/SearchConfiguration.java
search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java
search/trunk/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java
Log:
Various cleanup and enhancements on core Hibernate Search
Modified: search/trunk/src/main/java/org/hibernate/search/cfg/SearchConfiguration.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/SearchConfiguration.java 2009-10-24 21:37:27 UTC (rev 17830)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/SearchConfiguration.java 2009-10-25 17:53:52 UTC (rev 17831)
@@ -45,7 +45,7 @@
/**
* Returns a {@link java.lang.Class} from a String parameter.
* @param name
- * @return An iterator of Classes.
+ * @return corresponding class instance.
*/
Class<?> getClassMapping(String name);
Modified: search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java 2009-10-24 21:37:27 UTC (rev 17830)
+++ search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java 2009-10-25 17:53:52 UTC (rev 17831)
@@ -600,6 +600,19 @@
return idKeywordName;
}
+ /**
+ * Return the entity id if possible
+ * An IllegalStateException otherwise
+ *
+ * If the id is provided, we can't extract it from the entity
+ *
+ * @return entity id
+ */
+ public Serializable getId(Object entity) {
+ if( entity == null || idGetter == null) throw new IllegalStateException( "Cannot guess id form entity");
+ return ( Serializable ) ReflectionHelper.getMemberValue( entity, idGetter );
+ }
+
public static Serializable getDocumentId(SearchFactoryImplementor searchFactoryImplementor, Class<?> clazz, Document document) {
DocumentBuilderIndexedEntity<?> builderIndexedEntity = searchFactoryImplementor.getDocumentBuilderIndexedEntity(
clazz
Modified: search/trunk/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
+++ search/trunk/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java 2009-10-25 17:53:52 UTC (rev 17831)
@@ -127,32 +127,33 @@
/**
* {@inheritDoc}
*/
- @SuppressWarnings( "unchecked" )
public <T> void purge(Class<T> entityType, Serializable id) {
if ( entityType == null ) {
return;
}
- SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
- Set<Class<?>> targetedClasses = searchFactoryImplementor.getIndexedTypesPolymorphic( new Class[] {entityType} );
+ Set<Class<?>> targetedClasses = getSearchFactoryImplementor().getIndexedTypesPolymorphic( new Class[] {entityType} );
if ( targetedClasses.isEmpty() ) {
String msg = entityType.getName() + " is not an indexed entity or a subclass of an indexed entity";
throw new IllegalArgumentException( msg );
}
- Work<T> work;
- for ( Class clazz : targetedClasses ) {
+ for ( Class<?> clazz : targetedClasses ) {
if ( id == null ) {
- work = new Work<T>( clazz, null, WorkType.PURGE_ALL );
- searchFactoryImplementor.getWorker().performWork( work, transactionContext );
+ createAndPerformWork( clazz, null, WorkType.PURGE_ALL );
}
else {
- work = new Work<T>( clazz, id, WorkType.PURGE );
- searchFactoryImplementor.getWorker().performWork( work, transactionContext );
+ createAndPerformWork( clazz, id, WorkType.PURGE );
}
}
}
+ private <T> void createAndPerformWork(Class<T> clazz, Serializable id, WorkType workType) {
+ Work<T> work;
+ work = new Work<T>( clazz, id, workType );
+ getSearchFactoryImplementor().getWorker().performWork( work, transactionContext );
+ }
+
/**
* (Re-)index an entity.
* The entity must be associated with the session and non indexable entities are ignored.
@@ -197,10 +198,7 @@
}
public SearchFactory getSearchFactory() {
- if ( searchFactory == null ) {
- searchFactory = ContextHelper.getSearchFactory( session );
- }
- return searchFactory;
+ return getSearchFactoryImplementor();
}
private SearchFactoryImplementor getSearchFactoryImplementor() {
14 years, 6 months
Hibernate SVN: r17830 - in core/trunk/entitymanager/src: main/java/org/hibernate/ejb/criteria and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-10-24 17:37:27 -0400 (Sat, 24 Oct 2009)
New Revision: 17830
Added:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaBuilderImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/TableExpressionMapper.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImplementor.java
Removed:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.java
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/AbstractBasicPluralJoin.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/AbstractNode.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicCollectionJoinImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicListJoinImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicMapJoinImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicSetJoinImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CollectionJoinImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryCompiler.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/FromImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/JoinImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ListJoinImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapJoinImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapKeyHelpers.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/PathImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/RootImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/SetJoinImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/AbstractTupleElement.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CoalesceExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CollectionExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CompoundSelectionImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ConcatExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/EntityTypeExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ListIndexExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/LiteralExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/NullifExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ParameterExpressionImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SearchedCaseExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SelectionImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SimpleCaseExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SizeOfCollectionExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SubqueryComparisonModifierExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryArithmeticOperation.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AbsFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AggregationFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/BasicFunctionExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CastFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CurrentDateFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CurrentTimeFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CurrentTimestampFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LengthFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LocateFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LowerFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/ParameterizedFunctionExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SqrtFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SubstringFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/TrimFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/UpperFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/AbstractPredicateImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/AbstractSimplePredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BetweenPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BooleanExpressionPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ComparisonPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExistsPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExplicitTruthValueCheck.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/InPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/IsEmptyPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/LikePredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/MemberOfPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/NullnessPredicate.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/BasicCriteriaUsageTest.java
Log:
HHH-4203 - Implement JPA 2.0 criteria apis (compiling)
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -35,10 +35,9 @@
import javax.persistence.spi.LoadState;
import org.hibernate.SessionFactory;
-import org.hibernate.Hibernate;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.cfg.Configuration;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.metamodel.MetamodelImpl;
import org.hibernate.ejb.util.PersistenceUtilHelper;
@@ -54,7 +53,7 @@
private final PersistenceUnitTransactionType transactionType;
private final boolean discardOnClose;
private final Class sessionInterceptorClass;
- private final QueryBuilderImpl criteriaQueryBuilder;
+ private final CriteriaBuilderImpl criteriaBuilder;
private final Metamodel metamodel;
private final HibernatePersistenceUnitUtil util;
@@ -77,7 +76,7 @@
else {
this.metamodel = null;
}
- this.criteriaQueryBuilder = new QueryBuilderImpl( this );
+ this.criteriaBuilder = new CriteriaBuilderImpl( this );
this.util = new HibernatePersistenceUnitUtil( this );
}
@@ -94,7 +93,7 @@
}
public CriteriaBuilder getCriteriaBuilder() {
- return criteriaQueryBuilder;
+ return criteriaBuilder;
}
public Metamodel getMetamodel() {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/AbstractBasicPluralJoin.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/AbstractBasicPluralJoin.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/AbstractBasicPluralJoin.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -50,12 +50,12 @@
implements PluralJoin<O,C,E>, Fetch<O,E> {
public AbstractBasicPluralJoin(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<E> javaType,
PathImpl<O> lhs,
PluralAttribute<? super O, ?, ?> joinProperty,
JoinType joinType) {
- super(queryBuilder, javaType, lhs, joinProperty, joinType);
+ super( criteriaBuilder, javaType, lhs, joinProperty, joinType);
}
@Override
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/AbstractNode.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/AbstractNode.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/AbstractNode.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -24,24 +24,24 @@
package org.hibernate.ejb.criteria;
/**
- * All nodes in a criteria query tree will generally need access to the {@link QueryBuilderImpl} from which they
+ * All nodes in a criteria query tree will generally need access to the {@link CriteriaBuilderImpl} from which they
* come. This base class provides convenient, consistent support for that.
*
* @author Steve Ebersole
*/
public class AbstractNode {
- private final QueryBuilderImpl queryBuilder;
+ private final CriteriaBuilderImpl criteriaBuilder;
- public AbstractNode(QueryBuilderImpl queryBuilder) {
- this.queryBuilder = queryBuilder;
+ public AbstractNode(CriteriaBuilderImpl criteriaBuilder) {
+ this.criteriaBuilder = criteriaBuilder;
}
/**
- * Provides protected access to the underlying {@link QueryBuilderImpl}.
+ * Provides protected access to the underlying {@link CriteriaBuilderImpl}.
*
- * @return The underlying {@link QueryBuilderImpl} instance.
+ * @return The underlying {@link CriteriaBuilderImpl} instance.
*/
- protected QueryBuilderImpl queryBuilder() {
- return queryBuilder;
+ protected CriteriaBuilderImpl queryBuilder() {
+ return criteriaBuilder;
}
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicCollectionJoinImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicCollectionJoinImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicCollectionJoinImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -39,12 +39,12 @@
implements JoinImplementors.CollectionJoinImplementor<O,E> {
public BasicCollectionJoinImpl(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<E> javaType,
PathImpl<O> lhs,
CollectionAttribute<? super O, E> joinProperty,
JoinType joinType) {
- super(queryBuilder, javaType, lhs, joinProperty, joinType);
+ super( criteriaBuilder, javaType, lhs, joinProperty, joinType);
}
@Override
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicListJoinImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicListJoinImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicListJoinImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -41,12 +41,12 @@
implements JoinImplementors.ListJoinImplementor<O,E> {
public BasicListJoinImpl(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<E> javaType,
PathImpl<O> lhs,
ListAttribute<? super O, ?> joinProperty,
JoinType joinType) {
- super(queryBuilder, javaType, lhs, joinProperty, joinType);
+ super( criteriaBuilder, javaType, lhs, joinProperty, joinType);
}
@Override
@@ -60,7 +60,7 @@
}
public Expression<Integer> index() {
- return new ListIndexExpression( queryBuilder(), getAttribute() );
+ return new ListIndexExpression( queryBuilder(), this, getAttribute() );
}
@Override
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicMapJoinImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicMapJoinImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicMapJoinImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -50,12 +50,12 @@
public BasicMapJoinImpl(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<V> javaType,
PathImpl<O> lhs,
MapAttribute<? super O, K, V> joinProperty,
JoinType joinType) {
- super( queryBuilder, javaType, lhs, joinProperty, joinType );
+ super( criteriaBuilder, javaType, lhs, joinProperty, joinType );
}
@Override
@@ -78,6 +78,7 @@
/**
* {@inheritDoc}
*/
+ @SuppressWarnings({ "unchecked" })
public Join<Map<K, V>, K> joinKey(JoinType jt) {
if ( PersistenceType.BASIC.equals( getAttribute().getKeyType().getPersistenceType() ) ) {
throw new BasicPathUsageException( "Cannot join to map key of basic type", getAttribute() );
@@ -95,14 +96,12 @@
getParentPath().getModel()
);
final MapKeyHelpers.MapKeyAttribute attribute = new MapKeyHelpers.MapKeyAttribute( queryBuilder(), getAttribute() );
- final Join<Map<K, V>, K> join = new MapKeyHelpers.MapKeyJoin<K,V>(
+ return new MapKeyHelpers.MapKeyJoin<K,V>(
queryBuilder(),
source,
attribute,
jt
);
-
- return join;
}
@@ -133,13 +132,15 @@
/**
* {@inheritDoc}
*/
+ @SuppressWarnings({ "unchecked" })
public Expression<Entry<K, V>> entry() {
- return new MapKeyHelpers.MapEntryExpression( queryBuilder(), Map.Entry.class, getAttribute() );
+ return new MapKeyHelpers.MapEntryExpression( queryBuilder(), Map.Entry.class, this, getAttribute() );
}
private From<O, V> correlationParent;
@Override
+ @SuppressWarnings({ "unchecked" })
public MapJoinImplementor<O, K, V> correlateTo(CriteriaSubqueryImpl subquery) {
BasicMapJoinImpl<O,K,V> correlation = new BasicMapJoinImpl<O,K,V>(
queryBuilder(),
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicSetJoinImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicSetJoinImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicSetJoinImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -39,12 +39,12 @@
implements JoinImplementors.SetJoinImplementor<O,E> {
public BasicSetJoinImpl(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<E> javaType,
PathImpl<O> lhs,
SetAttribute<? super O, ?> joinProperty,
JoinType joinType) {
- super( queryBuilder, javaType, lhs, joinProperty, joinType );
+ super( criteriaBuilder, javaType, lhs, joinProperty, joinType );
}
@Override
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CollectionJoinImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CollectionJoinImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CollectionJoinImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -39,12 +39,12 @@
implements JoinImplementors.CollectionJoinImplementor<O,E> {
public CollectionJoinImpl(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<E> javaType,
PathImpl<O> lhs,
CollectionAttribute<? super O, ?> joinProperty,
JoinType joinType) {
- super(queryBuilder, javaType, lhs, joinProperty, joinType);
+ super( criteriaBuilder, javaType, lhs, joinProperty, joinType);
}
@Override
Copied: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaBuilderImpl.java (from rev 17768, core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.java)
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaBuilderImpl.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaBuilderImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -0,0 +1,1364 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @author tags or express
+ * copyright attribution statements applied by the authors. All
+ * third-party contributions are distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.ejb.criteria;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Selection;
+import javax.persistence.criteria.CompoundSelection;
+import javax.persistence.criteria.Order;
+import javax.persistence.criteria.Expression;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.ParameterExpression;
+import javax.persistence.criteria.Subquery;
+import javax.persistence.Tuple;
+
+import org.hibernate.ejb.EntityManagerFactoryImpl;
+import org.hibernate.ejb.criteria.expression.BinaryArithmeticOperation;
+import org.hibernate.ejb.criteria.expression.CoalesceExpression;
+import org.hibernate.ejb.criteria.expression.CollectionExpression;
+import org.hibernate.ejb.criteria.expression.CompoundSelectionImpl;
+import org.hibernate.ejb.criteria.expression.ConcatExpression;
+import org.hibernate.ejb.criteria.expression.ParameterExpressionImpl;
+import org.hibernate.ejb.criteria.expression.LiteralExpression;
+import org.hibernate.ejb.criteria.expression.NullifExpression;
+import org.hibernate.ejb.criteria.expression.SearchedCaseExpression;
+import org.hibernate.ejb.criteria.expression.SimpleCaseExpression;
+import org.hibernate.ejb.criteria.expression.SizeOfCollectionExpression;
+import org.hibernate.ejb.criteria.expression.SubqueryComparisonModifierExpression;
+import org.hibernate.ejb.criteria.expression.UnaryArithmeticOperation;
+import org.hibernate.ejb.criteria.expression.function.AbsFunction;
+import org.hibernate.ejb.criteria.expression.function.AggregationFunction;
+import org.hibernate.ejb.criteria.expression.function.BasicFunctionExpression;
+import org.hibernate.ejb.criteria.expression.function.CurrentDateFunction;
+import org.hibernate.ejb.criteria.expression.function.CurrentTimeFunction;
+import org.hibernate.ejb.criteria.expression.function.CurrentTimestampFunction;
+import org.hibernate.ejb.criteria.expression.function.LengthFunction;
+import org.hibernate.ejb.criteria.expression.function.LocateFunction;
+import org.hibernate.ejb.criteria.expression.function.LowerFunction;
+import org.hibernate.ejb.criteria.expression.function.ParameterizedFunctionExpression;
+import org.hibernate.ejb.criteria.expression.function.SqrtFunction;
+import org.hibernate.ejb.criteria.expression.function.SubstringFunction;
+import org.hibernate.ejb.criteria.expression.function.TrimFunction;
+import org.hibernate.ejb.criteria.expression.function.UpperFunction;
+import org.hibernate.ejb.criteria.predicate.BooleanExpressionPredicate;
+import org.hibernate.ejb.criteria.predicate.NullnessPredicate;
+import org.hibernate.ejb.criteria.predicate.CompoundPredicate;
+import org.hibernate.ejb.criteria.predicate.ComparisonPredicate;
+import org.hibernate.ejb.criteria.predicate.InPredicate;
+import org.hibernate.ejb.criteria.predicate.BetweenPredicate;
+import org.hibernate.ejb.criteria.predicate.ExistsPredicate;
+import org.hibernate.ejb.criteria.predicate.IsEmptyPredicate;
+import org.hibernate.ejb.criteria.predicate.LikePredicate;
+import org.hibernate.ejb.criteria.predicate.MemberOfPredicate;
+import static org.hibernate.ejb.criteria.predicate.ComparisonPredicate.ComparisonOperator;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class CriteriaBuilderImpl implements CriteriaBuilder, Serializable {
+ private final EntityManagerFactoryImpl entityManagerFactory;
+
+ public CriteriaBuilderImpl(EntityManagerFactoryImpl entityManagerFactory) {
+ this.entityManagerFactory = entityManagerFactory;
+ }
+
+ /**
+ * Provides protected access to the underlying {@link EntityManagerFactoryImpl}.
+ *
+ * @return The underlying {@link EntityManagerFactoryImpl}
+ */
+ public EntityManagerFactoryImpl getEntityManagerFactory() {
+ return entityManagerFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public CriteriaQuery<Object> createQuery() {
+ return new CriteriaQueryImpl<Object>( this, Object.class );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <T> CriteriaQuery<T> createQuery(Class<T> resultClass) {
+ return new CriteriaQueryImpl<T>( this, resultClass );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public CriteriaQuery<Tuple> createTupleQuery() {
+ return new CriteriaQueryImpl<Tuple>( this, Tuple.class );
+ }
+
+ /**
+ * Package-protected method to centralize checking of criteria query
+ * multiselects as defined by the
+ * {@link CriteriaQuery#multiselect(List)} method.
+ *
+ * @param selections The selection varargs to check
+ *
+ * @throws IllegalArgumentException If, as per
+ * {@link CriteriaQuery#multiselect(List)} documentation,
+ * <i>"An argument to the multiselect method must not be a tuple-
+ * or array-valued compound selection item."</i>
+ */
+ void checkMultiselect(List<Selection<?>> selections) {
+ for ( Selection<?> selection : selections ) {
+ if ( selection.isCompoundSelection() ) {
+ if ( selection.getJavaType().isArray() ) {
+ throw new IllegalArgumentException(
+ "multiselect selections cannot contain " +
+ "compound array-valued elements"
+ );
+ }
+ if ( Tuple.class.isAssignableFrom( selection.getJavaType() ) ) {
+ throw new IllegalArgumentException(
+ "multiselect selections cannot contain " +
+ "compound tuple-valued elements"
+ );
+ }
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public CompoundSelection<Tuple> tuple(Selection<?>... selections) {
+ return tuple( Arrays.asList( selections ) );
+ }
+
+ /**
+ * Version of {@link #tuple(Selection[])} taking a list.
+ *
+ * @param selections List of selections.
+ *
+ * @return The tuple compound selection
+ */
+ public CompoundSelection<Tuple> tuple(List<Selection<?>> selections) {
+ checkMultiselect( selections );
+ return new CompoundSelectionImpl<Tuple>( this, Tuple.class, selections );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public CompoundSelection<Object[]> array(Selection<?>... selections) {
+ return array( Arrays.asList( selections ) );
+ }
+
+ /**
+ * Version of {@link #array(Selection[])} taking a list of selections.
+ *
+ * @param selections List of selections.
+ *
+ * @return The array compound selection
+ */
+ public CompoundSelection<Object[]> array(List<Selection<?>> selections) {
+ return array( Object[].class, selections );
+ }
+
+ /**
+ * Version of {@link #array(Selection[])} taking a list of selections,
+ * as well as the type of array.
+ *
+ * @param type The type of array
+ * @param selections List of selections.
+ *
+ * @return The array compound selection
+ */
+ public <Y> CompoundSelection<Y> array(Class<Y> type, List<Selection<?>> selections) {
+ checkMultiselect( selections );
+ return new CompoundSelectionImpl<Y>( this, type, selections );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <Y> CompoundSelection<Y> construct(Class<Y> result, Selection<?>... selections) {
+ return construct( result, Arrays.asList( selections ) );
+ }
+
+ /**
+ * Version of {@link #construct(Class,Selection[])} taking the
+ * to-be-constructed type as well as a list of selections.
+ *
+ * @param result The result class to be constructed.
+ * @param selections The selections to use in the constructor call.
+ *
+ * @return The <b>view</b> compound selection.
+ */
+ public <Y> CompoundSelection<Y> construct(Class<Y> result, List<Selection<?>> selections) {
+ checkMultiselect( selections );
+ return new CompoundSelectionImpl<Y>( this, result, selections );
+ }
+
+
+ // ordering ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ /**
+ * {@inheritDoc}
+ */
+ public Order asc(Expression<?> x) {
+ return new OrderImpl( x, true );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Order desc(Expression<?> x) {
+ return new OrderImpl( x, false );
+ }
+
+
+ // predicates ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public Predicate wrap(Expression<Boolean> expression) {
+ if ( Predicate.class.isInstance( expression ) ) {
+ return ( ( Predicate ) expression );
+ }
+ else {
+ return new BooleanExpressionPredicate( this, expression );
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate not(Expression<Boolean> expression) {
+ return wrap( expression ).not();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate and(Expression<Boolean> x, Expression<Boolean> y) {
+ return new CompoundPredicate( this, Predicate.BooleanOperator.AND, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate or(Expression<Boolean> x, Expression<Boolean> y) {
+ return new CompoundPredicate( this, Predicate.BooleanOperator.OR, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate and(Predicate... restrictions) {
+ return new CompoundPredicate( this, Predicate.BooleanOperator.AND, restrictions );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate or(Predicate... restrictions) {
+ return new CompoundPredicate( this, Predicate.BooleanOperator.OR, restrictions );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate conjunction() {
+ return new CompoundPredicate( this, Predicate.BooleanOperator.AND );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate disjunction() {
+ return new CompoundPredicate( this, Predicate.BooleanOperator.OR );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate isTrue(Expression<Boolean> x) {
+ return wrap( x );
+// TODO : the correct thing here depends on response to #5 on my wiki page
+// return new ExplicitTruthValueCheck( this, x, TruthValue.TRUE );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate isFalse(Expression<Boolean> x) {
+ return wrap( x ).not();
+// TODO : the correct thing here depends on response to #5 on my wiki page
+// return new ExplicitTruthValueCheck( this, x, TruthValue.FALSE );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate isNull(Expression<?> x) {
+ return new NullnessPredicate( this, x );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate isNotNull(Expression<?> x) {
+ return isNull( x ).not();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate equal(Expression<?> x, Expression<?> y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.EQUAL, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate notEqual(Expression<?> x, Expression<?> y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.NOT_EQUAL, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate equal(Expression<?> x, Object y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.EQUAL, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate notEqual(Expression<?> x, Object y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.NOT_EQUAL, x, y ).not();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <Y extends Comparable<? super Y>> Predicate greaterThan(Expression<? extends Y> x, Expression<? extends Y> y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.GREATER_THAN, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <Y extends Comparable<? super Y>> Predicate lessThan(
+ Expression<? extends Y> x,
+ Expression<? extends Y> y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.LESS_THAN, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <Y extends Comparable<? super Y>> Predicate greaterThanOrEqualTo(
+ Expression<? extends Y> x,
+ Expression<? extends Y> y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.GREATER_THAN_OR_EQUAL, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <Y extends Comparable<? super Y>> Predicate lessThanOrEqualTo(
+ Expression<? extends Y> x,
+ Expression<? extends Y> y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.LESS_THAN_OR_EQUAL, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <Y extends Comparable<? super Y>> Predicate greaterThan(
+ Expression<? extends Y> x,
+ Y y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.GREATER_THAN, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <Y extends Comparable<? super Y>> Predicate lessThan(
+ Expression<? extends Y> x,
+ Y y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.LESS_THAN, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <Y extends Comparable<? super Y>> Predicate greaterThanOrEqualTo(
+ Expression<? extends Y> x,
+ Y y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.GREATER_THAN_OR_EQUAL, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public<Y extends Comparable<? super Y>> Predicate lessThanOrEqualTo(
+ Expression<? extends Y> x,
+ Y y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.LESS_THAN_OR_EQUAL, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate gt(Expression<? extends Number> x, Expression<? extends Number> y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.GREATER_THAN, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate lt(Expression<? extends Number> x, Expression<? extends Number> y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.LESS_THAN, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate ge(Expression<? extends Number> x, Expression<? extends Number> y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.GREATER_THAN_OR_EQUAL, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate le(Expression<? extends Number> x, Expression<? extends Number> y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.LESS_THAN_OR_EQUAL, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate gt(Expression<? extends Number> x, Number y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.GREATER_THAN, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate lt(Expression<? extends Number> x, Number y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.LESS_THAN, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate ge(Expression<? extends Number> x, Number y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.GREATER_THAN_OR_EQUAL, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate le(Expression<? extends Number> x, Number y) {
+ //noinspection SuspiciousNameCombination
+ return new ComparisonPredicate( this, ComparisonOperator.LESS_THAN_OR_EQUAL, x, y );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <Y extends Comparable<? super Y>> Predicate between(
+ Expression<? extends Y> expression,
+ Y lowerBound,
+ Y upperBound) {
+ return new BetweenPredicate<Y>( this, expression, lowerBound, upperBound );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <Y extends Comparable<? super Y>> Predicate between(
+ Expression<? extends Y> expression,
+ Expression<? extends Y> lowerBound,
+ Expression<? extends Y> upperBound) {
+ return new BetweenPredicate<Y>( this, expression, lowerBound, upperBound );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <T> In<T> in(Expression<? extends T> expression) {
+ return new InPredicate<T>( this, expression );
+ }
+
+ public <T> In<T> in(Expression<? extends T> expression, Expression<? extends T>... values) {
+ return new InPredicate<T>( this, expression, values );
+ }
+
+ public <T> In<T> in(Expression<? extends T> expression, T... values) {
+ return new InPredicate<T>( this, expression, values );
+ }
+
+ public <T> In<T> in(Expression<? extends T> expression, Collection<T> values) {
+ return new InPredicate<T>( this, expression, values );
+ }
+
+ public Predicate like(Expression<String> matchExpression, Expression<String> pattern) {
+ return new LikePredicate( this, matchExpression, pattern );
+ }
+
+ public Predicate like(Expression<String> matchExpression, Expression<String> pattern, Expression<Character> escapeCharacter) {
+ return new LikePredicate( this, matchExpression, pattern, escapeCharacter );
+ }
+
+ public Predicate like(Expression<String> matchExpression, Expression<String> pattern, char escapeCharacter) {
+ return new LikePredicate( this, matchExpression, pattern, escapeCharacter );
+ }
+
+ public Predicate like(Expression<String> matchExpression, String pattern) {
+ return new LikePredicate( this, matchExpression, pattern );
+ }
+
+ public Predicate like(Expression<String> matchExpression, String pattern, Expression<Character> escapeCharacter) {
+ return new LikePredicate( this, matchExpression, pattern, escapeCharacter );
+ }
+
+ public Predicate like(Expression<String> matchExpression, String pattern, char escapeCharacter) {
+ return new LikePredicate( this, matchExpression, pattern, escapeCharacter );
+ }
+
+ public Predicate notLike(Expression<String> matchExpression, Expression<String> pattern) {
+ return like( matchExpression, pattern ).not();
+ }
+
+ public Predicate notLike(Expression<String> matchExpression, Expression<String> pattern, Expression<Character> escapeCharacter) {
+ return like( matchExpression, pattern, escapeCharacter ).not();
+ }
+
+ public Predicate notLike(Expression<String> matchExpression, Expression<String> pattern, char escapeCharacter) {
+ return like( matchExpression, pattern, escapeCharacter ).not();
+ }
+
+ public Predicate notLike(Expression<String> matchExpression, String pattern) {
+ return like( matchExpression, pattern ).not();
+ }
+
+ public Predicate notLike(Expression<String> matchExpression, String pattern, Expression<Character> escapeCharacter) {
+ return like( matchExpression, pattern, escapeCharacter ).not();
+ }
+
+ public Predicate notLike(Expression<String> matchExpression, String pattern, char escapeCharacter) {
+ return like( matchExpression, pattern, escapeCharacter ).not();
+ }
+
+
+ // parameters ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ /**
+ * {@inheritDoc}
+ */
+ public <T> ParameterExpression<T> parameter(Class<T> paramClass) {
+ return new ParameterExpressionImpl<T>( this, paramClass );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <T> ParameterExpression<T> parameter(Class<T> paramClass, String name) {
+ return new ParameterExpressionImpl<T>( this, paramClass, name );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <T> Expression<T> literal(T value) {
+ return new LiteralExpression<T>( this, value );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <T> Expression<T> nullLiteral(Class<T> resultClass) {
+ return new LiteralExpression<T>( this, resultClass, null );
+ }
+
+
+ // aggregate functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ /**
+ * {@inheritDoc}
+ */
+ public <N extends Number> Expression<Double> avg(Expression<N> x) {
+ return new AggregationFunction.AVG( this, x );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <N extends Number> Expression<N> sum(Expression<N> x) {
+ return new AggregationFunction.SUM<N>( this, x );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Long> sumAsLong(Expression<Integer> x) {
+ return new AggregationFunction.SUM<Long>( this, x, Long.class );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Double> sumAsDouble(Expression<Float> x) {
+ return new AggregationFunction.SUM<Double>( this, x, Double.class );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <N extends Number> Expression<N> max(Expression<N> x) {
+ return new AggregationFunction.MAX<N>( this, x );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <N extends Number> Expression<N> min(Expression<N> x) {
+ return new AggregationFunction.MIN<N>( this, x );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <X extends Comparable<? super X>> Expression<X> greatest(Expression<X> x) {
+ return new AggregationFunction.GREATEST( this, x );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <X extends Comparable<? super X>> Expression<X> least(Expression<X> x) {
+ return new AggregationFunction.LEAST( this, x );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Long> count(Expression<?> x) {
+ return new AggregationFunction.COUNT( this, x, false );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Long> countDistinct(Expression<?> x) {
+ return new AggregationFunction.COUNT( this, x, true );
+ }
+
+
+ // other functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ /**
+ * {@inheritDoc}
+ */
+ public <T> Expression<T> function(String name, Class<T> returnType, Expression<?>... arguments) {
+ return new ParameterizedFunctionExpression<T>( this, returnType, name, arguments );
+ }
+
+ /**
+ * Create a reference to a function taking no params.
+ *
+ * @param name The function name.
+ * @param returnType The return type.
+ *
+ * @return The function expression
+ */
+ public <T> Expression<T> function(String name, Class<T> returnType) {
+ return new BasicFunctionExpression<T>( this, returnType, name );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <N extends Number> Expression<N> abs(Expression<N> expression) {
+ return new AbsFunction<N>( this, expression );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Double> sqrt(Expression<? extends Number> expression) {
+ return new SqrtFunction( this, expression );
+ }
+
+ public Expression<java.sql.Date> currentDate() {
+ return new CurrentDateFunction( this );
+ }
+
+ public Expression<java.sql.Timestamp> currentTimestamp() {
+ return new CurrentTimestampFunction( this );
+ }
+
+ public Expression<java.sql.Time> currentTime() {
+ return new CurrentTimeFunction( this );
+ }
+
+ public Expression<String> substring(Expression<String> value, Expression<Integer> start) {
+ return new SubstringFunction( this, value, start );
+ }
+
+ public Expression<String> substring(Expression<String> value, int start) {
+ return new SubstringFunction( this, value, start );
+ }
+
+ public Expression<String> substring(Expression<String> value, Expression<Integer> start, Expression<Integer> length) {
+ return new SubstringFunction( this, value, start, length );
+ }
+
+ public Expression<String> substring(Expression<String> value, int start, int length) {
+ return new SubstringFunction( this, value, start, length );
+ }
+
+ public Expression<String> trim(Expression<String> trimSource ) {
+ return new TrimFunction( this, trimSource );
+ }
+
+ public Expression<String> trim(Trimspec trimspec, Expression<String> trimSource) {
+ return new TrimFunction( this, trimspec, trimSource );
+ }
+
+ public Expression<String> trim(Expression<Character> trimCharacter, Expression<String> trimSource) {
+ return new TrimFunction( this, trimCharacter, trimSource );
+ }
+
+ public Expression<String> trim(Trimspec trimspec, Expression<Character> trimCharacter, Expression<String> trimSource) {
+ return new TrimFunction( this, trimspec, trimCharacter, trimSource );
+ }
+
+ public Expression<String> trim(char trimCharacter, Expression<String> trimSource) {
+ return new TrimFunction( this, trimCharacter, trimSource );
+ }
+
+ public Expression<String> trim(Trimspec trimspec, char trimCharacter, Expression<String> trimSource) {
+ return new TrimFunction( this, trimspec, trimCharacter, trimSource );
+ }
+
+ public Expression<String> lower(Expression<String> value) {
+ return new LowerFunction( this, value );
+ }
+
+ public Expression<String> upper(Expression<String> value) {
+ return new UpperFunction( this, value );
+ }
+
+ public Expression<Integer> length(Expression<String> value) {
+ return new LengthFunction( this, value );
+ }
+
+ public Expression<Integer> locate(Expression<String> string, Expression<String> pattern) {
+ return new LocateFunction( this, pattern, string );
+ }
+
+ public Expression<Integer> locate(Expression<String> string, Expression<String> pattern, Expression<Integer> start) {
+ return new LocateFunction( this, pattern, string, start );
+ }
+
+ public Expression<Integer> locate(Expression<String> string, String pattern) {
+ return new LocateFunction( this, pattern, string );
+ }
+
+ public Expression<Integer> locate(Expression<String> string, String pattern, int start) {
+ return new LocateFunction( this, pattern, string, start );
+ }
+
+
+ // arithmetic operations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ /**
+ * {@inheritDoc}
+ */
+ public <N extends Number> Expression<N> neg(Expression<N> expression) {
+ return new UnaryArithmeticOperation<N>(
+ this,
+ UnaryArithmeticOperation.Operation.UNARY_MINUS,
+ expression
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <N extends Number> Expression<N> sum(Expression<? extends N> expression1, Expression<? extends N> expression2) {
+ Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression1 );
+ type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, (Expression)expression2 );
+ return new BinaryArithmeticOperation<N>(
+ this,
+ type,
+ BinaryArithmeticOperation.Operation.ADD,
+ expression1,
+ expression2
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <N extends Number> Expression<N> prod(Expression<? extends N> expression1, Expression<? extends N> expression2) {
+ Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression1 );
+ type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, (Expression)expression2 );
+ return new BinaryArithmeticOperation<N>(
+ this,
+ type,
+ BinaryArithmeticOperation.Operation.MULTIPLY,
+ expression1,
+ expression2
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <N extends Number> Expression<N> diff(Expression<? extends N> expression1, Expression<? extends N> expression2) {
+ Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression1 );
+ type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, (Expression)expression2 );
+ return new BinaryArithmeticOperation<N>(
+ this,
+ type,
+ BinaryArithmeticOperation.Operation.SUBTRACT,
+ expression1,
+ expression2
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <N extends Number> Expression<N> sum(Expression<? extends N> expression, N n) {
+ Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression );
+ type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, n );
+ return new BinaryArithmeticOperation<N>(
+ this,
+ type,
+ BinaryArithmeticOperation.Operation.ADD,
+ expression,
+ n
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <N extends Number> Expression<N> prod(Expression<? extends N> expression, N n) {
+ Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression );
+ type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, n );
+ return new BinaryArithmeticOperation<N>(
+ this,
+ type,
+ BinaryArithmeticOperation.Operation.MULTIPLY,
+ expression,
+ n
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <N extends Number> Expression<N> diff(Expression<? extends N> expression, N n) {
+ Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression );
+ type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, n );
+ return new BinaryArithmeticOperation<N>(
+ this,
+ type,
+ BinaryArithmeticOperation.Operation.SUBTRACT,
+ expression,
+ n
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <N extends Number> Expression<N> sum(N n, Expression<? extends N> expression) {
+ Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression );
+ type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, n );
+ return new BinaryArithmeticOperation<N>(
+ this,
+ type,
+ BinaryArithmeticOperation.Operation.ADD,
+ n,
+ expression
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <N extends Number> Expression<N> prod(N n, Expression<? extends N> expression) {
+ Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression );
+ type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, n );
+ return new BinaryArithmeticOperation<N>(
+ this,
+ type,
+ BinaryArithmeticOperation.Operation.MULTIPLY,
+ n,
+ expression
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <N extends Number> Expression<N> diff(N n, Expression<? extends N> expression) {
+ Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression );
+ type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, n );
+ return new BinaryArithmeticOperation<N>(
+ this,
+ type,
+ BinaryArithmeticOperation.Operation.SUBTRACT,
+ n,
+ expression
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Number> quot(Expression<? extends Number> expression1, Expression<? extends Number> expression2) {
+ return new BinaryArithmeticOperation<Number>(
+ this,
+ Number.class,
+ BinaryArithmeticOperation.Operation.DIVIDE,
+ expression1,
+ expression2
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Number> quot(Expression<? extends Number> expression, Number number) {
+ return new BinaryArithmeticOperation<Number>(
+ this,
+ Number.class,
+ BinaryArithmeticOperation.Operation.DIVIDE,
+ expression,
+ number
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Number> quot(Number number, Expression<? extends Number> expression) {
+ return new BinaryArithmeticOperation<Number>(
+ this,
+ Number.class,
+ BinaryArithmeticOperation.Operation.DIVIDE,
+ number,
+ expression
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Integer> mod(Expression<Integer> expression1, Expression<Integer> expression2) {
+ return new BinaryArithmeticOperation<Integer>(
+ this,
+ Integer.class,
+ BinaryArithmeticOperation.Operation.MOD,
+ expression1,
+ expression2
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Integer> mod(Expression<Integer> expression, Integer integer) {
+ return new BinaryArithmeticOperation<Integer>(
+ this,
+ Integer.class,
+ BinaryArithmeticOperation.Operation.MOD,
+ expression,
+ integer
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Integer> mod(Integer integer, Expression<Integer> expression) {
+ return new BinaryArithmeticOperation<Integer>(
+ this,
+ Integer.class,
+ BinaryArithmeticOperation.Operation.MOD,
+ integer,
+ expression
+ );
+ }
+
+
+ // casting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Long> toLong(Expression<? extends Number> expression) {
+ return expression.as( Long.class );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Integer> toInteger(Expression<? extends Number> expression) {
+ return expression.as( Integer.class );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Float> toFloat(Expression<? extends Number> expression) {
+ return expression.as( Float.class );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Double> toDouble(Expression<? extends Number> expression) {
+ return expression.as( Double.class );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<BigDecimal> toBigDecimal(Expression<? extends Number> expression) {
+ return expression.as( BigDecimal.class );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<BigInteger> toBigInteger(Expression<? extends Number> expression) {
+ return expression.as( BigInteger.class );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<String> toString(Expression<Character> characterExpression) {
+ return characterExpression.as( String.class );
+ }
+
+
+ // subqueries ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate exists(Subquery<?> subquery) {
+ return new ExistsPredicate( this, subquery );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <Y> Expression<Y> all(Subquery<Y> subquery) {
+ return new SubqueryComparisonModifierExpression<Y>(
+ this,
+ (Class)subquery.getJavaType(),
+ subquery,
+ SubqueryComparisonModifierExpression.Modifier.ALL
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <Y> Expression<Y> some(Subquery<Y> subquery) {
+ return new SubqueryComparisonModifierExpression<Y>(
+ this,
+ (Class)subquery.getJavaType(),
+ subquery,
+ SubqueryComparisonModifierExpression.Modifier.SOME
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <Y> Expression<Y> any(Subquery<Y> subquery) {
+ return new SubqueryComparisonModifierExpression<Y>(
+ this,
+ (Class)subquery.getJavaType(),
+ subquery,
+ SubqueryComparisonModifierExpression.Modifier.ANY
+ );
+ }
+
+
+ // miscellaneous expressions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ /**
+ * {@inheritDoc}
+ */
+ public <Y> Expression<Y> coalesce(Expression<? extends Y> exp1, Expression<? extends Y> exp2) {
+ return coalesce( (Class<Y>)null, exp1, exp2 );
+ }
+
+ public <Y> Expression<Y> coalesce(Class<Y> type, Expression<? extends Y> exp1, Expression<? extends Y> exp2) {
+ return new CoalesceExpression<Y>( this, type ).value( exp1 ).value( exp2 );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <Y> Expression<Y> coalesce(Expression<? extends Y> exp1, Y exp2) {
+ return coalesce( (Class<Y>)null, exp1, exp2 );
+ }
+
+ public <Y> Expression<Y> coalesce(Class<Y> type, Expression<? extends Y> exp1, Y exp2) {
+ return new CoalesceExpression<Y>( this, type ).value( exp1 ).value( exp2 );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <T> Coalesce<T> coalesce() {
+ return coalesce( (Class<T>)null );
+ }
+
+ public <T> Coalesce<T> coalesce(Class<T> type) {
+ return new CoalesceExpression<T>( this, type );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<String> concat(Expression<String> string1, Expression<String> string2) {
+ return new ConcatExpression( this, string1, string2 );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<String> concat(Expression<String> string1, String string2) {
+ return new ConcatExpression( this, string1, string2 );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<String> concat(String string1, Expression<String> string2) {
+ return new ConcatExpression( this, string1, string2 );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <Y> Expression<Y> nullif(Expression<Y> exp1, Expression<?> exp2) {
+ return nullif( null, exp1, exp2 );
+ }
+
+ public <Y> Expression<Y> nullif(Class<Y> type, Expression<Y> exp1, Expression<?> exp2) {
+ return new NullifExpression<Y>( this, type, exp1, exp2 );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <Y> Expression<Y> nullif(Expression<Y> exp1, Y exp2) {
+ return nullif( null, exp1, exp2 );
+ }
+
+ public <Y> Expression<Y> nullif(Class<Y> type, Expression<Y> exp1, Y exp2) {
+ return new NullifExpression<Y>( this, type, exp1, exp2 );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <C, R> SimpleCase<C, R> selectCase(Expression<? extends C> expression) {
+ return selectCase( (Class<R>)null, expression );
+ }
+
+ public <C, R> SimpleCase<C, R> selectCase(Class<R> type, Expression<? extends C> expression) {
+ return new SimpleCaseExpression<C, R>( this, type, expression );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <R> Case<R> selectCase() {
+ return selectCase( (Class<R>)null );
+ }
+
+ public <R> Case<R> selectCase(Class<R> type) {
+ return new SearchedCaseExpression<R>( this, type );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <C extends Collection<?>> Expression<Integer> size(C c) {
+ int size = c == null ? 0 : c.size();
+ return new LiteralExpression<Integer>(this, Integer.class, size);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <C extends Collection<?>> Expression<Integer> size(Expression<C> exp) {
+ if ( LiteralExpression.class.isInstance(exp) ) {
+ return size( ( (LiteralExpression<C>) exp ).getLiteral() );
+ }
+ else if ( CollectionExpression.class.isInstance(exp) ) {
+ return new SizeOfCollectionExpression<C>(this, null);
+ }
+ // TODO : what other specific types? any?
+ throw new IllegalArgumentException("unknown collection expression type [" + exp.getClass().getName() + "]" );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <V, M extends Map<?, V>> Expression<Collection<V>> values(M map) {
+ return new LiteralExpression<Collection<V>>( this, map.values() );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <K, M extends Map<K, ?>> Expression<Set<K>> keys(M map) {
+ return new LiteralExpression<Set<K>>( this, map.keySet() );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <C extends Collection<?>> Predicate isEmpty(Expression<C> collectionExpression) {
+ if ( CollectionExpression.class.isInstance(collectionExpression) ) {
+ return new IsEmptyPredicate(
+ this,
+ (CollectionExpression<C>) collectionExpression
+ );
+ }
+ // TODO : what other specific types? any?
+ throw new IllegalArgumentException(
+ "unknown collection expression type [" + collectionExpression.getClass().getName() + "]"
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <C extends Collection<?>> Predicate isNotEmpty(Expression<C> collectionExpression) {
+ return isEmpty( collectionExpression ).not();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <E, C extends Collection<E>> Predicate isMember(E e, Expression<C> collectionExpression) {
+ if ( ! CollectionExpression.class.isInstance(collectionExpression) ) {
+ throw new IllegalArgumentException(
+ "unknown collection expression type [" + collectionExpression.getClass().getName() + "]"
+ );
+ }
+ return new MemberOfPredicate<E, C>(
+ this,
+ e,
+ (CollectionExpression<C>)collectionExpression
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <E, C extends Collection<E>> Predicate isNotMember(E e, Expression<C> cExpression) {
+ return isMember(e, cExpression).not();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <E, C extends Collection<E>> Predicate isMember(Expression<E> elementExpression, Expression<C> collectionExpression) {
+ if ( ! CollectionExpression.class.isInstance(collectionExpression) ) {
+ throw new IllegalArgumentException(
+ "unknown collection expression type [" + collectionExpression.getClass().getName() + "]"
+ );
+ }
+ return new MemberOfPredicate<E, C>(
+ this,
+ elementExpression,
+ (CollectionExpression<C>)collectionExpression
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <E, C extends Collection<E>> Predicate isNotMember(Expression<E> eExpression, Expression<C> cExpression) {
+ return isMember(eExpression, cExpression).not();
+ }
+}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryCompiler.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryCompiler.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryCompiler.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -24,7 +24,17 @@
package org.hibernate.ejb.criteria;
import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
import javax.persistence.TypedQuery;
+import javax.persistence.Parameter;
+import javax.persistence.TemporalType;
+import javax.persistence.FlushModeType;
+import javax.persistence.LockModeType;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.ParameterExpression;
@@ -40,6 +50,22 @@
* @author Steve Ebersole
*/
public class CriteriaQueryCompiler {
+ public static interface ImplicitParameterBinding {
+ public void bind(TypedQuery typedQuery);
+ }
+
+ public static interface RenderingContext {
+ public String generateAlias();
+ public String generateParameterName();
+
+ public void registerExplicitParameter(ParameterExpression<?> criteriaQueryParameter, String jpaqlParameterName);
+ public void registerImplicitParameterBinding(ImplicitParameterBinding binding);
+ }
+
+ public static interface RenderedCriteriaQuery {
+ public String getQueryString();
+ }
+
private final HibernateEntityManagerImplementor entityManager;
public CriteriaQueryCompiler(HibernateEntityManagerImplementor entityManager) {
@@ -48,14 +74,191 @@
public <T> TypedQuery<T> compile(CriteriaQuery<T> criteriaQuery) {
CriteriaQueryImpl<T> criteriaQueryImpl = ( CriteriaQueryImpl<T> ) criteriaQuery;
-
criteriaQueryImpl.validate();
- Set<ParameterExpression<?>> explicitParameters = criteriaQueryImpl.getParameters();
- // todo : implicit parameter handling (handling literal as param, etc).
- String jpaqlEquivalent = criteriaQueryImpl.render();
+ final Map<ParameterExpression<?>,String> explicitParameterMapping = new HashMap<ParameterExpression<?>,String>();
+ final List<ImplicitParameterBinding> implicitParameterBindings = new ArrayList<ImplicitParameterBinding>();
+ RenderingContext renderingContext = new RenderingContext() {
+ private int aliasCount = 0;
+ private int explicitParameterCount = 0;
+ public String generateAlias() {
+ return "generatedAlias" + aliasCount++;
+ }
- return null;
+ public String generateParameterName() {
+ return "param" + explicitParameterCount++;
+ }
+
+ public void registerExplicitParameter(ParameterExpression<?> criteriaQueryParameter, String jpaqlParameterName) {
+ explicitParameterMapping.put( criteriaQueryParameter, jpaqlParameterName );
+ }
+
+ public void registerImplicitParameterBinding(ImplicitParameterBinding binding) {
+ implicitParameterBindings.add( binding );
+ }
+ };
+
+ RenderedCriteriaQuery renderedCriteriaQuery = criteriaQueryImpl.render( renderingContext );
+
+ TypedQuery<T> jpaqlQuery = entityManager.createQuery(
+ renderedCriteriaQuery.getQueryString(),
+ criteriaQuery.getResultType()
+ );
+ for ( ImplicitParameterBinding implicitParameterBinding : implicitParameterBindings ) {
+ implicitParameterBinding.bind( jpaqlQuery );
+ }
+
+ return wrap( jpaqlQuery, explicitParameterMapping );
}
+
+ private <X> TypedQuery<X> wrap(
+ final TypedQuery<X> jpaqlQuery,
+ final Map<ParameterExpression<?>, String> explicitParameterMapping) {
+ return new TypedQuery<X>() {
+
+ public List<X> getResultList() {
+ return jpaqlQuery.getResultList();
+ }
+
+ public X getSingleResult() {
+ return jpaqlQuery.getSingleResult();
+ }
+
+ public int getMaxResults() {
+ return jpaqlQuery.getMaxResults();
+ }
+
+ public TypedQuery<X> setMaxResults(int i) {
+ return jpaqlQuery.setMaxResults( i );
+ }
+
+ public int getFirstResult() {
+ return jpaqlQuery.getFirstResult();
+ }
+
+ public TypedQuery<X> setFirstResult(int i) {
+ return jpaqlQuery.setFirstResult( i );
+ }
+
+ public Map<String, Object> getHints() {
+ return jpaqlQuery.getHints();
+ }
+
+ public TypedQuery<X> setHint(String name, Object value) {
+ return jpaqlQuery.setHint( name, value);
+ }
+
+ public FlushModeType getFlushMode() {
+ return jpaqlQuery.getFlushMode();
+ }
+
+ public TypedQuery<X> setFlushMode(FlushModeType flushModeType) {
+ return jpaqlQuery.setFlushMode( flushModeType );
+ }
+
+ public LockModeType getLockMode() {
+ return jpaqlQuery.getLockMode();
+ }
+
+ public TypedQuery<X> setLockMode(LockModeType lockModeType) {
+ return jpaqlQuery.setLockMode( lockModeType );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public Set getParameters() {
+ return explicitParameterMapping.keySet();
+ }
+
+ public boolean isBound(Parameter<?> param) {
+ return jpaqlQuery.isBound( param );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <T> T getParameterValue(Parameter<T> param) {
+ return ( T ) jpaqlQuery.getParameterValue( mapToNamedParameter( param ) );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <T> TypedQuery<X> setParameter(Parameter<T> param, T t) {
+ return jpaqlQuery.setParameter( mapToNamedParameter( param ), t );
+ }
+
+ @SuppressWarnings({ "RedundantCast" })
+ private Parameter mapToNamedParameter(Parameter criteriaParameter) {
+ return jpaqlQuery.getParameter(
+ explicitParameterMapping.get( (ParameterExpression) criteriaParameter )
+ );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public TypedQuery<X> setParameter(Parameter<Calendar> param, Calendar calendar, TemporalType temporalType) {
+ return jpaqlQuery.setParameter( mapToNamedParameter( param ), calendar, temporalType );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public TypedQuery<X> setParameter(Parameter<Date> param, Date date, TemporalType temporalType) {
+ return jpaqlQuery.setParameter( mapToNamedParameter( param ), date, temporalType );
+ }
+
+ public <T> T unwrap(Class<T> cls) {
+ return jpaqlQuery.unwrap( cls );
+ }
+
+
+ // unsupported stuff ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public int executeUpdate() {
+ throw new IllegalArgumentException( "Criteria queries do not support update queries" );
+ }
+
+ public TypedQuery<X> setParameter(String s, Object o) {
+ throw new IllegalArgumentException( "Criteria queries do not support named parameters" );
+ }
+
+ public TypedQuery<X> setParameter(String s, Calendar calendar, TemporalType temporalType) {
+ throw new IllegalArgumentException( "Criteria queries do not support named parameters" );
+ }
+
+ public TypedQuery<X> setParameter(String s, Date date, TemporalType temporalType) {
+ throw new IllegalArgumentException( "Criteria queries do not support named parameters" );
+ }
+
+ public Object getParameterValue(String name) {
+ throw new IllegalArgumentException( "Criteria queries do not support named parameters" );
+ }
+
+ public Parameter<?> getParameter(String name) {
+ throw new IllegalArgumentException( "Criteria queries do not support named parameters" );
+ }
+
+ public <T> Parameter<T> getParameter(String name, Class<T> type) {
+ throw new IllegalArgumentException( "Criteria queries do not support named parameters" );
+ }
+
+ public TypedQuery<X> setParameter(int i, Object o) {
+ throw new IllegalArgumentException( "Criteria queries do not support positioned parameters" );
+ }
+
+ public TypedQuery<X> setParameter(int i, Calendar calendar, TemporalType temporalType) {
+ throw new IllegalArgumentException( "Criteria queries do not support positioned parameters" );
+ }
+
+ public TypedQuery<X> setParameter(int i, Date date, TemporalType temporalType) {
+ throw new IllegalArgumentException( "Criteria queries do not support positioned parameters" );
+ }
+
+ public Object getParameterValue(int position) {
+ throw new IllegalArgumentException( "Criteria queries do not support positioned parameters" );
+ }
+
+ public Parameter<?> getParameter(int position) {
+ throw new IllegalArgumentException( "Criteria queries do not support positioned parameters" );
+ }
+
+ public <T> Parameter<T> getParameter(int position, Class<T> type) {
+ throw new IllegalArgumentException( "Criteria queries do not support positioned parameters" );
+ }
+ };
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -38,6 +38,8 @@
import javax.persistence.criteria.Subquery;
import javax.persistence.metamodel.EntityType;
+import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
+
/**
* The Hibernate implementation of the JPA {@link CriteriaQuery} contract. Mostly a set of delegation to its
* internal {@link QueryStructure}.
@@ -52,11 +54,11 @@
public CriteriaQueryImpl(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<T> returnType) {
- super( queryBuilder );
+ super( criteriaBuilder );
this.returnType = returnType;
- this.queryStructure = new QueryStructure<T>( this, queryBuilder );
+ this.queryStructure = new QueryStructure<T>( this, criteriaBuilder );
}
/**
@@ -73,7 +75,7 @@
* {@inheritDoc}
*/
public CriteriaQuery<T> distinct(boolean applyDistinction) {
- queryStructure.setDistinction( applyDistinction );
+ queryStructure.setDistinct( applyDistinction );
return this;
}
@@ -81,7 +83,7 @@
* {@inheritDoc}
*/
public boolean isDistinct() {
- return queryStructure.isDistinction();
+ return queryStructure.isDistinct();
}
/**
@@ -330,7 +332,26 @@
return true;
}
- public String render() {
- return null;
+ public CriteriaQueryCompiler.RenderedCriteriaQuery render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ final StringBuilder jpaqlQuery = new StringBuilder();
+
+ queryStructure.render( jpaqlQuery, renderingContext );
+
+ if ( ! getOrderList().isEmpty() ) {
+ jpaqlQuery.append( " order by " );
+ String sep = "";
+ for ( Order orderSpec : getOrderList() ) {
+ jpaqlQuery.append( sep )
+ .append( ( ( ExpressionImplementor ) orderSpec.getExpression() ).render( renderingContext ) )
+ .append( orderSpec.isAscending() ? " asc" : " desc" );
+ sep = ", ";
+ }
+ }
+
+ return new CriteriaQueryCompiler.RenderedCriteriaQuery() {
+ public String getQueryString() {
+ return jpaqlQuery.toString();
+ }
+ };
}
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -26,7 +26,6 @@
import java.util.List;
import java.util.Set;
import java.util.HashSet;
-import java.util.Collections;
import javax.persistence.criteria.AbstractQuery;
import javax.persistence.criteria.CollectionJoin;
import javax.persistence.criteria.Expression;
@@ -76,12 +75,12 @@
};
public CriteriaSubqueryImpl(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<T> javaType,
AbstractQuery<?> parent) {
- super(queryBuilder, javaType);
+ super( criteriaBuilder, javaType);
this.parent = parent;
- this.queryStructure = new QueryStructure<T>( this, queryBuilder );
+ this.queryStructure = new QueryStructure<T>( this, criteriaBuilder );
}
/**
@@ -144,12 +143,12 @@
// SELECTION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public Subquery<T> distinct(boolean applyDistinction) {
- queryStructure.setDistinction( applyDistinction );
+ queryStructure.setDistinct( applyDistinction );
return this;
}
public boolean isDistinct() {
- return queryStructure.isDistinction();
+ return queryStructure.isDistinct();
}
public Expression<T> getSelection() {
@@ -298,4 +297,14 @@
return queryStructure.subquery( subqueryType );
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ StringBuilder subqueryBuffer = new StringBuilder( "(" );
+ queryStructure.render( subqueryBuffer, renderingContext );
+ subqueryBuffer.append( ')' );
+ return subqueryBuffer.toString();
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ throw new IllegalStateException( "Subquery cannot occur in select clause" );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/FromImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/FromImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/FromImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -58,7 +58,7 @@
*
* @author Steve Ebersole
*/
-public abstract class FromImpl<Z,X> extends PathImpl<X> implements From<Z,X> {
+public abstract class FromImpl<Z,X> extends PathImpl<X> implements From<Z,X>, TableExpressionMapper {
public static final JoinType DEFAULT_JOIN_TYPE = JoinType.INNER;
/**
@@ -102,22 +102,33 @@
/**
* Special constructor for {@link RootImpl}.
*
- * @param queryBuilder The query build
+ * @param criteriaBuilder The query build
* @param entityType The entity defining this root
*/
- protected FromImpl(QueryBuilderImpl queryBuilder, EntityType<X> entityType) {
- super( queryBuilder, entityType.getBindableJavaType(), null, null, entityType );
- this.type = new EntityTypeExpression( queryBuilder, entityType.getBindableJavaType() );
+ @SuppressWarnings({ "unchecked" })
+ protected FromImpl(CriteriaBuilderImpl criteriaBuilder, EntityType<X> entityType) {
+ super( criteriaBuilder, entityType.getBindableJavaType(), null, null, entityType );
+ this.type = new EntityTypeExpression( criteriaBuilder, entityType.getBindableJavaType() );
}
+ /**
+ * The general constructor for a {@link From} implementor.
+ *
+ * @param criteriaBuilder
+ * @param javaType
+ * @param origin
+ * @param attribute
+ * @param model
+ */
+ @SuppressWarnings({ "unchecked" })
public FromImpl(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<X> javaType,
PathImpl<Z> origin,
Attribute<? super Z, ?> attribute,
ManagedType<X> model) {
- super( queryBuilder, javaType, origin, attribute, model );
- this.type = new EntityTypeExpression( queryBuilder, model.getJavaType() );
+ super( criteriaBuilder, javaType, origin, attribute, model );
+ this.type = new EntityTypeExpression( criteriaBuilder, model.getJavaType() );
}
protected void defineJoinScope(JoinScope<X> joinScope) {
@@ -341,6 +352,7 @@
/**
* {@inheritDoc}
*/
+ @SuppressWarnings({ "unchecked" })
public <X,Y> Join<X, Y> join(String attributeName, JoinType jt) {
if ( jt.equals( JoinType.RIGHT ) ) {
throw new UnsupportedOperationException( "RIGHT JOIN not supported" );
@@ -377,6 +389,7 @@
/**
* {@inheritDoc}
*/
+ @SuppressWarnings({ "unchecked" })
public <X,Y> CollectionJoin<X, Y> joinCollection(String attributeName, JoinType jt) {
final Attribute<X,?> attribute = (Attribute<X, ?>) getAttribute( attributeName );
if ( ! attribute.isCollection() ) {
@@ -401,6 +414,7 @@
/**
* {@inheritDoc}
*/
+ @SuppressWarnings({ "unchecked" })
public <X,Y> SetJoin<X, Y> joinSet(String attributeName, JoinType jt) {
final Attribute<X,?> attribute = (Attribute<X, ?>) getAttribute( attributeName );
if ( ! attribute.isCollection() ) {
@@ -425,6 +439,7 @@
/**
* {@inheritDoc}
*/
+ @SuppressWarnings({ "unchecked" })
public <X,Y> ListJoin<X, Y> joinList(String attributeName, JoinType jt) {
final Attribute<X,?> attribute = (Attribute<X, ?>) getAttribute( attributeName );
if ( ! attribute.isCollection() ) {
@@ -449,6 +464,7 @@
/**
* {@inheritDoc}
*/
+ @SuppressWarnings({ "unchecked" })
public <X, K, V> MapJoin<X, K, V> joinMap(String attributeName, JoinType jt) {
final Attribute<X,?> attribute = (Attribute<X, ?>) getAttribute( attributeName );
if ( ! attribute.isCollection() ) {
@@ -520,6 +536,7 @@
return fetch( attributeName, DEFAULT_JOIN_TYPE );
}
+ @SuppressWarnings({ "unchecked" })
public <X,Y> Fetch<X, Y> fetch(String attributeName, JoinType jt) {
Attribute<X,?> attribute = (Attribute<X, ?>) getAttribute( attributeName );
if ( attribute.isCollection() ) {
@@ -545,15 +562,17 @@
@Override
public <E, C extends Collection<E>> Expression<C> get(PluralAttribute<X, C, E> collection) {
- return new CollectionExpression<C>( queryBuilder(), collection.getJavaType(), collection );
+ return new CollectionExpression<C>( queryBuilder(), collection.getJavaType(), this, collection );
}
@Override
+ @SuppressWarnings({ "unchecked" })
public <K, V, M extends Map<K, V>> Expression<M> get(MapAttribute<X, K, V> map) {
- return ( Expression<M> ) new CollectionExpression<Map<K, V>>( queryBuilder(), map.getJavaType(), map );
+ return ( Expression<M> ) new CollectionExpression<Map<K, V>>( queryBuilder(), map.getJavaType(), this, map );
}
@Override
+ @SuppressWarnings({ "unchecked" })
public <Y> Path<Y> get(String attributeName) {
Attribute attribute = getAttribute( attributeName );
if ( attribute.isCollection() ) {
@@ -575,4 +594,32 @@
return get( (SingularAttribute<X,Y>) attribute );
}
}
+
+ @Override
+ public String getPathIdentifier() {
+ return getAlias();
+ }
+
+ @Override
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ prepareAlias( renderingContext );
+ return getAlias();
+ }
+
+ @Override
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ prepareAlias( renderingContext );
+ return getAlias();
+ }
+
+ public String renderTableExpression(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ prepareAlias( renderingContext );
+ return ( (EntityType) getModel() ).getName() + " as " + getAlias();
+ }
+
+ public void prepareAlias(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ if ( getAlias() == null ) {
+ setAlias( renderingContext.generateAlias() );
+ }
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/JoinImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/JoinImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/JoinImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -44,18 +44,19 @@
private final ManagedType<X> managedType;
private final JoinType joinType;
+ @SuppressWarnings({ "unchecked" })
public JoinImpl(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<X> javaType,
PathImpl<Z> lhs,
Attribute<? super Z, ?> joinProperty,
JoinType joinType) {
super(
- queryBuilder,
+ criteriaBuilder,
javaType,
lhs,
joinProperty,
- (ManagedType<X>)queryBuilder.getEntityManagerFactory().getMetamodel().managedType( javaType )
+ (ManagedType<X>) criteriaBuilder.getEntityManagerFactory().getMetamodel().managedType( javaType )
);
this.managedType = (ManagedType<X>) getModel();
this.joinType = joinType;
@@ -64,12 +65,14 @@
/**
* {@inheritDoc}
*/
+ @SuppressWarnings({ "unchecked" })
public From<?, Z> getParent() {
// AFAICT, only "froms" (specifically roots and joins) can be the parent of a join.
return ( From<?, Z> ) getParentPath();
}
@Override
+ @SuppressWarnings({ "unchecked" })
public Attribute<? super Z, ?> getAttribute() {
return (Attribute<? super Z, ?>) super.getAttribute();
}
@@ -82,10 +85,12 @@
}
@Override
+ @SuppressWarnings({ "unchecked" })
protected Attribute<X, ?> getAttribute(String name) {
return (Attribute<X, ?>) managedType.getAttribute( name );
}
+ @SuppressWarnings({ "unchecked" })
public JoinImplementors.JoinImplementor<Z,X> correlateTo(CriteriaSubqueryImpl subquery) {
JoinImpl<Z,X> correlation = new JoinImpl<Z,X>(
queryBuilder(),
@@ -112,7 +117,12 @@
* {@inheritDoc}
*/
public From<Z,X> getCorrelationParent() {
- return null;
+ return correlationParent;
}
+ public String renderTableExpression(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ prepareAlias( renderingContext );
+ ( (FromImpl) getParent() ).prepareAlias( renderingContext );
+ return getParent().getAlias() + '.' + getAttribute().getName() + " as " + getAlias();
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ListJoinImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ListJoinImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ListJoinImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -38,12 +38,12 @@
*/
public class ListJoinImpl<O,E> extends JoinImpl<O,E> implements JoinImplementors.ListJoinImplementor<O,E> {
public ListJoinImpl(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<E> javaType,
PathImpl<O> lhs,
ListAttribute<? super O, ?> joinProperty,
JoinType joinType) {
- super( queryBuilder, javaType, lhs, joinProperty, joinType );
+ super( criteriaBuilder, javaType, lhs, joinProperty, joinType );
}
@Override
@@ -60,7 +60,7 @@
* {@inheritDoc}
*/
public Expression<Integer> index() {
- return new ListIndexExpression( queryBuilder(), getAttribute() );
+ return new ListIndexExpression( queryBuilder(), this, getAttribute() );
}
@Override
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapJoinImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapJoinImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapJoinImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -45,12 +45,12 @@
implements JoinImplementors.MapJoinImplementor<O,K,V> {
public MapJoinImpl(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<V> javaType,
PathImpl<O> lhs,
MapAttribute<? super O, K, V> joinProperty,
JoinType joinType) {
- super(queryBuilder, javaType, lhs, joinProperty, joinType);
+ super( criteriaBuilder, javaType, lhs, joinProperty, joinType);
}
@Override
@@ -73,6 +73,7 @@
/**
* {@inheritDoc}
*/
+ @SuppressWarnings({ "unchecked" })
public Join<Map<K, V>, K> joinKey(JoinType jt) {
if ( PersistenceType.BASIC.equals( getAttribute().getKeyType().getPersistenceType() ) ) {
throw new BasicPathUsageException( "Cannot join to map key of basic type", getAttribute() );
@@ -90,19 +91,18 @@
getParentPath().getModel()
);
final MapKeyHelpers.MapKeyAttribute mapKeyAttribute = new MapKeyHelpers.MapKeyAttribute( queryBuilder(), getAttribute() );
- final Join<Map<K, V>, K> join = new MapKeyHelpers.MapKeyJoin<K,V>(
+ return new MapKeyHelpers.MapKeyJoin<K,V>(
queryBuilder(),
mapKeySource,
mapKeyAttribute,
jt
);
-
- return join;
}
/**
* {@inheritDoc}
*/
+ @SuppressWarnings({ "unchecked" })
public Path<K> key() {
final MapKeyHelpers.MapPath<K,V> mapKeySource = new MapKeyHelpers.MapPath<K,V>(
queryBuilder(),
@@ -125,14 +125,16 @@
/**
* {@inheritDoc}
*/
+ @SuppressWarnings({ "unchecked" })
public Expression<Entry<K, V>> entry() {
- return new MapKeyHelpers.MapEntryExpression( queryBuilder(), Map.Entry.class, getAttribute() );
+ return new MapKeyHelpers.MapEntryExpression( queryBuilder(), Map.Entry.class, this, getAttribute() );
}
private From<O, V> correlationParent;
@Override
+ @SuppressWarnings({ "unchecked" })
public MapJoinImplementor<O, K, V> correlateTo(CriteriaSubqueryImpl subquery) {
MapJoinImpl<O, K, V> correlation = new MapJoinImpl<O, K, V>(
queryBuilder(),
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapKeyHelpers.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapKeyHelpers.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapKeyHelpers.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -33,13 +33,13 @@
import javax.persistence.criteria.Path;
import javax.persistence.criteria.From;
import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.Bindable.BindableType;
import javax.persistence.metamodel.ManagedType;
import javax.persistence.metamodel.MapAttribute;
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.Type.PersistenceType;
import org.hibernate.ejb.criteria.JoinImplementors.JoinImplementor;
import org.hibernate.ejb.criteria.expression.ExpressionImpl;
+import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.type.Type;
@@ -61,9 +61,9 @@
* @param <V> The type of the map value
*/
public static class MapKeyJoin<K,V> extends JoinImpl<Map<K, V>, K> implements Join<Map<K, V>, K> {
- public MapKeyJoin(QueryBuilderImpl queryBuilder, MapPath<K,V> source, MapKeyAttribute<K> attribute, JoinType jt) {
+ public MapKeyJoin(CriteriaBuilderImpl criteriaBuilder, MapPath<K,V> source, MapKeyAttribute<K> attribute, JoinType jt) {
super(
- queryBuilder,
+ criteriaBuilder,
attribute.getJavaType(),
source,
attribute,
@@ -92,10 +92,10 @@
*/
public static class MapKeyPath<K> extends PathImpl<K> implements Path<K> {
public MapKeyPath(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
MapPath<K,?> source,
MapKeyAttribute<K> attribute) {
- super( queryBuilder, attribute.getJavaType(), source, attribute, attribute.getType() );
+ super( criteriaBuilder, attribute.getJavaType(), source, attribute, attribute.getType() );
}
}
@@ -110,12 +110,12 @@
private final MapJoin<?,K,V> mapJoin;
public MapPath(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<Map<K, V>> javaType,
MapJoin<?,K,V> mapJoin,
MapAttribute<?,K,V> attribute,
Object model) {
- super(queryBuilder, javaType, null, attribute, model);
+ super( criteriaBuilder, javaType, null, attribute, model);
this.mapJoin = mapJoin;
}
@@ -146,7 +146,7 @@
private final BindableType jpaBindableType;
private final Class<K> jpaBinableJavaType;
- public MapKeyAttribute(QueryBuilderImpl queryBuilder, MapAttribute<?, K, ?> attribute) {
+ public MapKeyAttribute(CriteriaBuilderImpl criteriaBuilder, MapAttribute<?, K, ?> attribute) {
this.attribute = attribute;
this.jpaType = attribute.getKeyType();
this.jpaBinableJavaType = attribute.getKeyJavaType();
@@ -156,7 +156,7 @@
String guessedRoleName = determineRole( attribute );
SessionFactoryImplementor sfi = (SessionFactoryImplementor)
- queryBuilder.getEntityManagerFactory().getSessionFactory();
+ criteriaBuilder.getEntityManagerFactory().getSessionFactory();
mapPersister = sfi.getCollectionPersister( guessedRoleName );
if ( mapPersister == null ) {
throw new IllegalStateException( "Could not locate collection persister [" + guessedRoleName + "]" );
@@ -260,13 +260,16 @@
public static class MapEntryExpression<K,V>
extends ExpressionImpl<Map.Entry<K,V>>
implements Expression<Map.Entry<K,V>> {
+ private final PathImpl origin;
private final MapAttribute<?, K, V> attribute;
public MapEntryExpression(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<Entry<K, V>> javaType,
+ PathImpl origin,
MapAttribute<?, K, V> attribute) {
- super(queryBuilder, javaType);
+ super( criteriaBuilder, javaType);
+ this.origin = origin;
this.attribute = attribute;
}
@@ -278,6 +281,20 @@
// none to register
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ // i dont think this is vqalid outside of select clause...
+ throw new IllegalStateException( "illegal reference to map entry outside of select clause." );
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return "entry(" + path( renderingContext ) + ")";
+ }
+
+ private String path(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return origin.getPathIdentifier()
+ + '.'
+ + ( (ExpressionImplementor) getAttribute() ).renderProjection( renderingContext );
+ }
}
/**
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/PathImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/PathImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/PathImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -48,19 +48,19 @@
/**
* Constructs a path.
*
- * @param queryBuilder The delegate for building query components.
+ * @param criteriaBuilder The delegate for building query components.
* @param javaType The java type of this path,
* @param origin The source ("lhs") of this path.
* @param attribute The attribute defining this path element.
* @param model The corresponding model of this path.
*/
protected PathImpl(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<X> javaType,
PathImpl<?> origin,
Attribute<?,?> attribute,
Object model) {
- super( queryBuilder, javaType );
+ super( criteriaBuilder, javaType );
this.origin = origin;
this.attribute = attribute;
this.model = model;
@@ -80,7 +80,8 @@
/**
* {@inheritDoc}
*/
- public Bindable<X> getModel() {
+ @SuppressWarnings({ "unchecked" })
+ public Bindable<X> getModel() {
if ( model == null ) {
throw new IllegalStateException( this + " represents a basic path and not a bindable" );
}
@@ -145,4 +146,24 @@
// none to register
}
+ /**
+ * Get the string representation of this path as a navigation from one of the
+ * queries <tt>identification variables</tt>
+ *
+ * @return The path's identifier.
+ */
+ public String getPathIdentifier() {
+ return getParentPath().getPathIdentifier() + "." + getAttribute().getName();
+ }
+
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ ( (TableExpressionMapper) getParentPath() ).prepareAlias( renderingContext );
+ return getParentPath().getAlias()
+ + '.'
+ + getAttribute().getName();
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Deleted: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -1,1364 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
- * third-party contributors as indicated by either @author tags or express
- * copyright attribution statements applied by the authors. All
- * third-party contributions are distributed under license by Red Hat Inc.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.ejb.criteria;
-
-import java.io.Serializable;
-import java.util.List;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Selection;
-import javax.persistence.criteria.CompoundSelection;
-import javax.persistence.criteria.Order;
-import javax.persistence.criteria.Expression;
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.ParameterExpression;
-import javax.persistence.criteria.Subquery;
-import javax.persistence.Tuple;
-
-import org.hibernate.ejb.EntityManagerFactoryImpl;
-import org.hibernate.ejb.criteria.expression.BinaryArithmeticOperation;
-import org.hibernate.ejb.criteria.expression.CoalesceExpression;
-import org.hibernate.ejb.criteria.expression.CollectionExpression;
-import org.hibernate.ejb.criteria.expression.CompoundSelectionImpl;
-import org.hibernate.ejb.criteria.expression.ConcatExpression;
-import org.hibernate.ejb.criteria.expression.ParameterExpressionImpl;
-import org.hibernate.ejb.criteria.expression.LiteralExpression;
-import org.hibernate.ejb.criteria.expression.NullifExpression;
-import org.hibernate.ejb.criteria.expression.SearchedCaseExpression;
-import org.hibernate.ejb.criteria.expression.SimpleCaseExpression;
-import org.hibernate.ejb.criteria.expression.SizeOfCollectionExpression;
-import org.hibernate.ejb.criteria.expression.SubqueryComparisonModifierExpression;
-import org.hibernate.ejb.criteria.expression.UnaryArithmeticOperation;
-import org.hibernate.ejb.criteria.expression.function.AbsFunction;
-import org.hibernate.ejb.criteria.expression.function.AggregationFunction;
-import org.hibernate.ejb.criteria.expression.function.BasicFunctionExpression;
-import org.hibernate.ejb.criteria.expression.function.CurrentDateFunction;
-import org.hibernate.ejb.criteria.expression.function.CurrentTimeFunction;
-import org.hibernate.ejb.criteria.expression.function.CurrentTimestampFunction;
-import org.hibernate.ejb.criteria.expression.function.LengthFunction;
-import org.hibernate.ejb.criteria.expression.function.LocateFunction;
-import org.hibernate.ejb.criteria.expression.function.LowerFunction;
-import org.hibernate.ejb.criteria.expression.function.ParameterizedFunctionExpression;
-import org.hibernate.ejb.criteria.expression.function.SqrtFunction;
-import org.hibernate.ejb.criteria.expression.function.SubstringFunction;
-import org.hibernate.ejb.criteria.expression.function.TrimFunction;
-import org.hibernate.ejb.criteria.expression.function.UpperFunction;
-import org.hibernate.ejb.criteria.predicate.BooleanExpressionPredicate;
-import org.hibernate.ejb.criteria.predicate.NullnessPredicate;
-import org.hibernate.ejb.criteria.predicate.CompoundPredicate;
-import org.hibernate.ejb.criteria.predicate.ComparisonPredicate;
-import org.hibernate.ejb.criteria.predicate.InPredicate;
-import org.hibernate.ejb.criteria.predicate.BetweenPredicate;
-import org.hibernate.ejb.criteria.predicate.ExistsPredicate;
-import org.hibernate.ejb.criteria.predicate.IsEmptyPredicate;
-import org.hibernate.ejb.criteria.predicate.LikePredicate;
-import org.hibernate.ejb.criteria.predicate.MemberOfPredicate;
-import static org.hibernate.ejb.criteria.predicate.ComparisonPredicate.ComparisonOperator;
-
-/**
- * TODO : javadoc
- *
- * @author Steve Ebersole
- */
-public class QueryBuilderImpl implements CriteriaBuilder, Serializable {
- private final EntityManagerFactoryImpl entityManagerFactory;
-
- public QueryBuilderImpl(EntityManagerFactoryImpl entityManagerFactory) {
- this.entityManagerFactory = entityManagerFactory;
- }
-
- /**
- * Provides protected access to the underlying {@link EntityManagerFactoryImpl}.
- *
- * @return The underlying {@link EntityManagerFactoryImpl}
- */
- public EntityManagerFactoryImpl getEntityManagerFactory() {
- return entityManagerFactory;
- }
-
- /**
- * {@inheritDoc}
- */
- public CriteriaQuery<Object> createQuery() {
- return new CriteriaQueryImpl<Object>( this, Object.class );
- }
-
- /**
- * {@inheritDoc}
- */
- public <T> CriteriaQuery<T> createQuery(Class<T> resultClass) {
- return new CriteriaQueryImpl<T>( this, resultClass );
- }
-
- /**
- * {@inheritDoc}
- */
- public CriteriaQuery<Tuple> createTupleQuery() {
- return new CriteriaQueryImpl<Tuple>( this, Tuple.class );
- }
-
- /**
- * Package-protected method to centralize checking of criteria query
- * multiselects as defined by the
- * {@link CriteriaQuery#multiselect(List)} method.
- *
- * @param selections The selection varargs to check
- *
- * @throws IllegalArgumentException If, as per
- * {@link CriteriaQuery#multiselect(List)} documentation,
- * <i>"An argument to the multiselect method must not be a tuple-
- * or array-valued compound selection item."</i>
- */
- void checkMultiselect(List<Selection<?>> selections) {
- for ( Selection<?> selection : selections ) {
- if ( selection.isCompoundSelection() ) {
- if ( selection.getJavaType().isArray() ) {
- throw new IllegalArgumentException(
- "multiselect selections cannot contain " +
- "compound array-valued elements"
- );
- }
- if ( Tuple.class.isAssignableFrom( selection.getJavaType() ) ) {
- throw new IllegalArgumentException(
- "multiselect selections cannot contain " +
- "compound tuple-valued elements"
- );
- }
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public CompoundSelection<Tuple> tuple(Selection<?>... selections) {
- return tuple( Arrays.asList( selections ) );
- }
-
- /**
- * Version of {@link #tuple(Selection[])} taking a list.
- *
- * @param selections List of selections.
- *
- * @return The tuple compound selection
- */
- public CompoundSelection<Tuple> tuple(List<Selection<?>> selections) {
- checkMultiselect( selections );
- return new CompoundSelectionImpl<Tuple>( this, Tuple.class, selections );
- }
-
- /**
- * {@inheritDoc}
- */
- public CompoundSelection<Object[]> array(Selection<?>... selections) {
- return array( Arrays.asList( selections ) );
- }
-
- /**
- * Version of {@link #array(Selection[])} taking a list of selections.
- *
- * @param selections List of selections.
- *
- * @return The array compound selection
- */
- public CompoundSelection<Object[]> array(List<Selection<?>> selections) {
- return array( Object[].class, selections );
- }
-
- /**
- * Version of {@link #array(Selection[])} taking a list of selections,
- * as well as the type of array.
- *
- * @param type The type of array
- * @param selections List of selections.
- *
- * @return The array compound selection
- */
- public <Y> CompoundSelection<Y> array(Class<Y> type, List<Selection<?>> selections) {
- checkMultiselect( selections );
- return new CompoundSelectionImpl<Y>( this, type, selections );
- }
-
- /**
- * {@inheritDoc}
- */
- public <Y> CompoundSelection<Y> construct(Class<Y> result, Selection<?>... selections) {
- return construct( result, Arrays.asList( selections ) );
- }
-
- /**
- * Version of {@link #construct(Class,Selection[])} taking the
- * to-be-constructed type as well as a list of selections.
- *
- * @param result The result class to be constructed.
- * @param selections The selections to use in the constructor call.
- *
- * @return The <b>view</b> compound selection.
- */
- public <Y> CompoundSelection<Y> construct(Class<Y> result, List<Selection<?>> selections) {
- checkMultiselect( selections );
- return new CompoundSelectionImpl<Y>( this, result, selections );
- }
-
-
- // ordering ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- /**
- * {@inheritDoc}
- */
- public Order asc(Expression<?> x) {
- return new OrderImpl( x, true );
- }
-
- /**
- * {@inheritDoc}
- */
- public Order desc(Expression<?> x) {
- return new OrderImpl( x, false );
- }
-
-
- // predicates ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- public Predicate wrap(Expression<Boolean> expression) {
- if ( Predicate.class.isInstance( expression ) ) {
- return ( ( Predicate ) expression );
- }
- else {
- return new BooleanExpressionPredicate( this, expression );
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate not(Expression<Boolean> expression) {
- return wrap( expression ).not();
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate and(Expression<Boolean> x, Expression<Boolean> y) {
- return new CompoundPredicate( this, Predicate.BooleanOperator.AND, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate or(Expression<Boolean> x, Expression<Boolean> y) {
- return new CompoundPredicate( this, Predicate.BooleanOperator.OR, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate and(Predicate... restrictions) {
- return new CompoundPredicate( this, Predicate.BooleanOperator.AND, restrictions );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate or(Predicate... restrictions) {
- return new CompoundPredicate( this, Predicate.BooleanOperator.OR, restrictions );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate conjunction() {
- return new CompoundPredicate( this, Predicate.BooleanOperator.AND );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate disjunction() {
- return new CompoundPredicate( this, Predicate.BooleanOperator.OR );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate isTrue(Expression<Boolean> x) {
- return wrap( x );
-// TODO : the correct thing here depends on response to #5 on my wiki page
-// return new ExplicitTruthValueCheck( this, x, TruthValue.TRUE );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate isFalse(Expression<Boolean> x) {
- return wrap( x ).not();
-// TODO : the correct thing here depends on response to #5 on my wiki page
-// return new ExplicitTruthValueCheck( this, x, TruthValue.FALSE );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate isNull(Expression<?> x) {
- return new NullnessPredicate( this, x );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate isNotNull(Expression<?> x) {
- return isNull( x ).not();
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate equal(Expression<?> x, Expression<?> y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.EQUAL, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate notEqual(Expression<?> x, Expression<?> y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.NOT_EQUAL, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate equal(Expression<?> x, Object y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.EQUAL, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate notEqual(Expression<?> x, Object y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.NOT_EQUAL, x, y ).not();
- }
-
- /**
- * {@inheritDoc}
- */
- public <Y extends Comparable<? super Y>> Predicate greaterThan(Expression<? extends Y> x, Expression<? extends Y> y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.GREATER_THAN, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public <Y extends Comparable<? super Y>> Predicate lessThan(
- Expression<? extends Y> x,
- Expression<? extends Y> y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.LESS_THAN, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public <Y extends Comparable<? super Y>> Predicate greaterThanOrEqualTo(
- Expression<? extends Y> x,
- Expression<? extends Y> y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.GREATER_THAN_OR_EQUAL, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public <Y extends Comparable<? super Y>> Predicate lessThanOrEqualTo(
- Expression<? extends Y> x,
- Expression<? extends Y> y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.LESS_THAN_OR_EQUAL, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public <Y extends Comparable<? super Y>> Predicate greaterThan(
- Expression<? extends Y> x,
- Y y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.GREATER_THAN, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public <Y extends Comparable<? super Y>> Predicate lessThan(
- Expression<? extends Y> x,
- Y y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.LESS_THAN, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public <Y extends Comparable<? super Y>> Predicate greaterThanOrEqualTo(
- Expression<? extends Y> x,
- Y y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.GREATER_THAN_OR_EQUAL, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public<Y extends Comparable<? super Y>> Predicate lessThanOrEqualTo(
- Expression<? extends Y> x,
- Y y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.LESS_THAN_OR_EQUAL, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate gt(Expression<? extends Number> x, Expression<? extends Number> y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.GREATER_THAN, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate lt(Expression<? extends Number> x, Expression<? extends Number> y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.LESS_THAN, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate ge(Expression<? extends Number> x, Expression<? extends Number> y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.GREATER_THAN_OR_EQUAL, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate le(Expression<? extends Number> x, Expression<? extends Number> y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.LESS_THAN_OR_EQUAL, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate gt(Expression<? extends Number> x, Number y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.GREATER_THAN, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate lt(Expression<? extends Number> x, Number y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.LESS_THAN, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate ge(Expression<? extends Number> x, Number y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.GREATER_THAN_OR_EQUAL, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public Predicate le(Expression<? extends Number> x, Number y) {
- //noinspection SuspiciousNameCombination
- return new ComparisonPredicate( this, ComparisonOperator.LESS_THAN_OR_EQUAL, x, y );
- }
-
- /**
- * {@inheritDoc}
- */
- public <Y extends Comparable<? super Y>> Predicate between(
- Expression<? extends Y> expression,
- Y lowerBound,
- Y upperBound) {
- return new BetweenPredicate<Y>( this, expression, lowerBound, upperBound );
- }
-
- /**
- * {@inheritDoc}
- */
- public <Y extends Comparable<? super Y>> Predicate between(
- Expression<? extends Y> expression,
- Expression<? extends Y> lowerBound,
- Expression<? extends Y> upperBound) {
- return new BetweenPredicate<Y>( this, expression, lowerBound, upperBound );
- }
-
- /**
- * {@inheritDoc}
- */
- public <T> In<T> in(Expression<? extends T> expression) {
- return new InPredicate<T>( this, expression );
- }
-
- public <T> In<T> in(Expression<? extends T> expression, Expression<? extends T>... values) {
- return new InPredicate<T>( this, expression, values );
- }
-
- public <T> In<T> in(Expression<? extends T> expression, T... values) {
- return new InPredicate<T>( this, expression, values );
- }
-
- public <T> In<T> in(Expression<? extends T> expression, Collection<T> values) {
- return new InPredicate<T>( this, expression, values );
- }
-
- public Predicate like(Expression<String> matchExpression, Expression<String> pattern) {
- return new LikePredicate( this, matchExpression, pattern );
- }
-
- public Predicate like(Expression<String> matchExpression, Expression<String> pattern, Expression<Character> escapeCharacter) {
- return new LikePredicate( this, matchExpression, pattern, escapeCharacter );
- }
-
- public Predicate like(Expression<String> matchExpression, Expression<String> pattern, char escapeCharacter) {
- return new LikePredicate( this, matchExpression, pattern, escapeCharacter );
- }
-
- public Predicate like(Expression<String> matchExpression, String pattern) {
- return new LikePredicate( this, matchExpression, pattern );
- }
-
- public Predicate like(Expression<String> matchExpression, String pattern, Expression<Character> escapeCharacter) {
- return new LikePredicate( this, matchExpression, pattern, escapeCharacter );
- }
-
- public Predicate like(Expression<String> matchExpression, String pattern, char escapeCharacter) {
- return new LikePredicate( this, matchExpression, pattern, escapeCharacter );
- }
-
- public Predicate notLike(Expression<String> matchExpression, Expression<String> pattern) {
- return like( matchExpression, pattern ).not();
- }
-
- public Predicate notLike(Expression<String> matchExpression, Expression<String> pattern, Expression<Character> escapeCharacter) {
- return like( matchExpression, pattern, escapeCharacter ).not();
- }
-
- public Predicate notLike(Expression<String> matchExpression, Expression<String> pattern, char escapeCharacter) {
- return like( matchExpression, pattern, escapeCharacter ).not();
- }
-
- public Predicate notLike(Expression<String> matchExpression, String pattern) {
- return like( matchExpression, pattern ).not();
- }
-
- public Predicate notLike(Expression<String> matchExpression, String pattern, Expression<Character> escapeCharacter) {
- return like( matchExpression, pattern, escapeCharacter ).not();
- }
-
- public Predicate notLike(Expression<String> matchExpression, String pattern, char escapeCharacter) {
- return like( matchExpression, pattern, escapeCharacter ).not();
- }
-
-
- // parameters ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- /**
- * {@inheritDoc}
- */
- public <T> ParameterExpression<T> parameter(Class<T> paramClass) {
- return new ParameterExpressionImpl<T>( this, paramClass );
- }
-
- /**
- * {@inheritDoc}
- */
- public <T> ParameterExpression<T> parameter(Class<T> paramClass, String name) {
- return new ParameterExpressionImpl<T>( this, paramClass, name );
- }
-
- /**
- * {@inheritDoc}
- */
- public <T> Expression<T> literal(T value) {
- return new LiteralExpression<T>( this, value );
- }
-
- /**
- * {@inheritDoc}
- */
- public <T> Expression<T> nullLiteral(Class<T> resultClass) {
- return new LiteralExpression<T>( this, resultClass, null );
- }
-
-
- // aggregate functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- /**
- * {@inheritDoc}
- */
- public <N extends Number> Expression<Double> avg(Expression<N> x) {
- return new AggregationFunction.AVG( this, x );
- }
-
- /**
- * {@inheritDoc}
- */
- public <N extends Number> Expression<N> sum(Expression<N> x) {
- return new AggregationFunction.SUM<N>( this, x );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<Long> sumAsLong(Expression<Integer> x) {
- return new AggregationFunction.SUM<Long>( this, x, Long.class );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<Double> sumAsDouble(Expression<Float> x) {
- return new AggregationFunction.SUM<Double>( this, x, Double.class );
- }
-
- /**
- * {@inheritDoc}
- */
- public <N extends Number> Expression<N> max(Expression<N> x) {
- return new AggregationFunction.MAX<N>( this, x );
- }
-
- /**
- * {@inheritDoc}
- */
- public <N extends Number> Expression<N> min(Expression<N> x) {
- return new AggregationFunction.MIN<N>( this, x );
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings({ "unchecked" })
- public <X extends Comparable<? super X>> Expression<X> greatest(Expression<X> x) {
- return new AggregationFunction.GREATEST( this, x );
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings({ "unchecked" })
- public <X extends Comparable<? super X>> Expression<X> least(Expression<X> x) {
- return new AggregationFunction.LEAST( this, x );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<Long> count(Expression<?> x) {
- return new AggregationFunction.COUNT( this, x, false );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<Long> countDistinct(Expression<?> x) {
- return new AggregationFunction.COUNT( this, x, true );
- }
-
-
- // other functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- /**
- * {@inheritDoc}
- */
- public <T> Expression<T> function(String name, Class<T> returnType, Expression<?>... arguments) {
- return new ParameterizedFunctionExpression<T>( this, returnType, name, arguments );
- }
-
- /**
- * Create a reference to a function taking no params.
- *
- * @param name The function name.
- * @param returnType The return type.
- *
- * @return The function expression
- */
- public <T> Expression<T> function(String name, Class<T> returnType) {
- return new BasicFunctionExpression<T>( this, returnType, name );
- }
-
- /**
- * {@inheritDoc}
- */
- public <N extends Number> Expression<N> abs(Expression<N> expression) {
- return new AbsFunction<N>( this, expression );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<Double> sqrt(Expression<? extends Number> expression) {
- return new SqrtFunction( this, expression );
- }
-
- public Expression<java.sql.Date> currentDate() {
- return new CurrentDateFunction( this );
- }
-
- public Expression<java.sql.Timestamp> currentTimestamp() {
- return new CurrentTimestampFunction( this );
- }
-
- public Expression<java.sql.Time> currentTime() {
- return new CurrentTimeFunction( this );
- }
-
- public Expression<String> substring(Expression<String> value, Expression<Integer> start) {
- return new SubstringFunction( this, value, start );
- }
-
- public Expression<String> substring(Expression<String> value, int start) {
- return new SubstringFunction( this, value, start );
- }
-
- public Expression<String> substring(Expression<String> value, Expression<Integer> start, Expression<Integer> length) {
- return new SubstringFunction( this, value, start, length );
- }
-
- public Expression<String> substring(Expression<String> value, int start, int length) {
- return new SubstringFunction( this, value, start, length );
- }
-
- public Expression<String> trim(Expression<String> trimSource ) {
- return new TrimFunction( this, trimSource );
- }
-
- public Expression<String> trim(Trimspec trimspec, Expression<String> trimSource) {
- return new TrimFunction( this, trimspec, trimSource );
- }
-
- public Expression<String> trim(Expression<Character> trimCharacter, Expression<String> trimSource) {
- return new TrimFunction( this, trimCharacter, trimSource );
- }
-
- public Expression<String> trim(Trimspec trimspec, Expression<Character> trimCharacter, Expression<String> trimSource) {
- return new TrimFunction( this, trimspec, trimCharacter, trimSource );
- }
-
- public Expression<String> trim(char trimCharacter, Expression<String> trimSource) {
- return new TrimFunction( this, trimCharacter, trimSource );
- }
-
- public Expression<String> trim(Trimspec trimspec, char trimCharacter, Expression<String> trimSource) {
- return new TrimFunction( this, trimspec, trimCharacter, trimSource );
- }
-
- public Expression<String> lower(Expression<String> value) {
- return new LowerFunction( this, value );
- }
-
- public Expression<String> upper(Expression<String> value) {
- return new UpperFunction( this, value );
- }
-
- public Expression<Integer> length(Expression<String> value) {
- return new LengthFunction( this, value );
- }
-
- public Expression<Integer> locate(Expression<String> string, Expression<String> pattern) {
- return new LocateFunction( this, pattern, string );
- }
-
- public Expression<Integer> locate(Expression<String> string, Expression<String> pattern, Expression<Integer> start) {
- return new LocateFunction( this, pattern, string, start );
- }
-
- public Expression<Integer> locate(Expression<String> string, String pattern) {
- return new LocateFunction( this, pattern, string );
- }
-
- public Expression<Integer> locate(Expression<String> string, String pattern, int start) {
- return new LocateFunction( this, pattern, string, start );
- }
-
-
- // arithmetic operations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- /**
- * {@inheritDoc}
- */
- public <N extends Number> Expression<N> neg(Expression<N> expression) {
- return new UnaryArithmeticOperation<N>(
- this,
- UnaryArithmeticOperation.Operation.UNARY_MINUS,
- expression
- );
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings({ "unchecked" })
- public <N extends Number> Expression<N> sum(Expression<? extends N> expression1, Expression<? extends N> expression2) {
- Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression1 );
- type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, (Expression)expression2 );
- return new BinaryArithmeticOperation<N>(
- this,
- type,
- BinaryArithmeticOperation.Operation.ADD,
- expression1,
- expression2
- );
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings({ "unchecked" })
- public <N extends Number> Expression<N> prod(Expression<? extends N> expression1, Expression<? extends N> expression2) {
- Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression1 );
- type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, (Expression)expression2 );
- return new BinaryArithmeticOperation<N>(
- this,
- type,
- BinaryArithmeticOperation.Operation.MULTIPLY,
- expression1,
- expression2
- );
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings({ "unchecked" })
- public <N extends Number> Expression<N> diff(Expression<? extends N> expression1, Expression<? extends N> expression2) {
- Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression1 );
- type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, (Expression)expression2 );
- return new BinaryArithmeticOperation<N>(
- this,
- type,
- BinaryArithmeticOperation.Operation.SUBTRACT,
- expression1,
- expression2
- );
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings({ "unchecked" })
- public <N extends Number> Expression<N> sum(Expression<? extends N> expression, N n) {
- Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression );
- type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, n );
- return new BinaryArithmeticOperation<N>(
- this,
- type,
- BinaryArithmeticOperation.Operation.ADD,
- expression,
- n
- );
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings({ "unchecked" })
- public <N extends Number> Expression<N> prod(Expression<? extends N> expression, N n) {
- Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression );
- type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, n );
- return new BinaryArithmeticOperation<N>(
- this,
- type,
- BinaryArithmeticOperation.Operation.MULTIPLY,
- expression,
- n
- );
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings({ "unchecked" })
- public <N extends Number> Expression<N> diff(Expression<? extends N> expression, N n) {
- Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression );
- type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, n );
- return new BinaryArithmeticOperation<N>(
- this,
- type,
- BinaryArithmeticOperation.Operation.SUBTRACT,
- expression,
- n
- );
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings({ "unchecked" })
- public <N extends Number> Expression<N> sum(N n, Expression<? extends N> expression) {
- Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression );
- type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, n );
- return new BinaryArithmeticOperation<N>(
- this,
- type,
- BinaryArithmeticOperation.Operation.ADD,
- n,
- expression
- );
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings({ "unchecked" })
- public <N extends Number> Expression<N> prod(N n, Expression<? extends N> expression) {
- Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression );
- type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, n );
- return new BinaryArithmeticOperation<N>(
- this,
- type,
- BinaryArithmeticOperation.Operation.MULTIPLY,
- n,
- expression
- );
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings({ "unchecked" })
- public <N extends Number> Expression<N> diff(N n, Expression<? extends N> expression) {
- Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression );
- type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, n );
- return new BinaryArithmeticOperation<N>(
- this,
- type,
- BinaryArithmeticOperation.Operation.SUBTRACT,
- n,
- expression
- );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<Number> quot(Expression<? extends Number> expression1, Expression<? extends Number> expression2) {
- return new BinaryArithmeticOperation<Number>(
- this,
- Number.class,
- BinaryArithmeticOperation.Operation.DIVIDE,
- expression1,
- expression2
- );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<Number> quot(Expression<? extends Number> expression, Number number) {
- return new BinaryArithmeticOperation<Number>(
- this,
- Number.class,
- BinaryArithmeticOperation.Operation.DIVIDE,
- expression,
- number
- );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<Number> quot(Number number, Expression<? extends Number> expression) {
- return new BinaryArithmeticOperation<Number>(
- this,
- Number.class,
- BinaryArithmeticOperation.Operation.DIVIDE,
- number,
- expression
- );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<Integer> mod(Expression<Integer> expression1, Expression<Integer> expression2) {
- return new BinaryArithmeticOperation<Integer>(
- this,
- Integer.class,
- BinaryArithmeticOperation.Operation.MOD,
- expression1,
- expression2
- );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<Integer> mod(Expression<Integer> expression, Integer integer) {
- return new BinaryArithmeticOperation<Integer>(
- this,
- Integer.class,
- BinaryArithmeticOperation.Operation.MOD,
- expression,
- integer
- );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<Integer> mod(Integer integer, Expression<Integer> expression) {
- return new BinaryArithmeticOperation<Integer>(
- this,
- Integer.class,
- BinaryArithmeticOperation.Operation.MOD,
- integer,
- expression
- );
- }
-
-
- // casting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- /**
- * {@inheritDoc}
- */
- public Expression<Long> toLong(Expression<? extends Number> expression) {
- return expression.as( Long.class );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<Integer> toInteger(Expression<? extends Number> expression) {
- return expression.as( Integer.class );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<Float> toFloat(Expression<? extends Number> expression) {
- return expression.as( Float.class );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<Double> toDouble(Expression<? extends Number> expression) {
- return expression.as( Double.class );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<BigDecimal> toBigDecimal(Expression<? extends Number> expression) {
- return expression.as( BigDecimal.class );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<BigInteger> toBigInteger(Expression<? extends Number> expression) {
- return expression.as( BigInteger.class );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<String> toString(Expression<Character> characterExpression) {
- return characterExpression.as( String.class );
- }
-
-
- // subqueries ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- /**
- * {@inheritDoc}
- */
- public Predicate exists(Subquery<?> subquery) {
- return new ExistsPredicate( this, subquery );
- }
-
- /**
- * {@inheritDoc}
- */
- public <Y> Expression<Y> all(Subquery<Y> subquery) {
- return new SubqueryComparisonModifierExpression<Y>(
- this,
- (Class)subquery.getJavaType(),
- subquery,
- SubqueryComparisonModifierExpression.Modifier.ALL
- );
- }
-
- /**
- * {@inheritDoc}
- */
- public <Y> Expression<Y> some(Subquery<Y> subquery) {
- return new SubqueryComparisonModifierExpression<Y>(
- this,
- (Class)subquery.getJavaType(),
- subquery,
- SubqueryComparisonModifierExpression.Modifier.SOME
- );
- }
-
- /**
- * {@inheritDoc}
- */
- public <Y> Expression<Y> any(Subquery<Y> subquery) {
- return new SubqueryComparisonModifierExpression<Y>(
- this,
- (Class)subquery.getJavaType(),
- subquery,
- SubqueryComparisonModifierExpression.Modifier.ANY
- );
- }
-
-
- // miscellaneous expressions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- /**
- * {@inheritDoc}
- */
- public <Y> Expression<Y> coalesce(Expression<? extends Y> exp1, Expression<? extends Y> exp2) {
- return coalesce( (Class<Y>)null, exp1, exp2 );
- }
-
- public <Y> Expression<Y> coalesce(Class<Y> type, Expression<? extends Y> exp1, Expression<? extends Y> exp2) {
- return new CoalesceExpression<Y>( this, type ).value( exp1 ).value( exp2 );
- }
-
- /**
- * {@inheritDoc}
- */
- public <Y> Expression<Y> coalesce(Expression<? extends Y> exp1, Y exp2) {
- return coalesce( (Class<Y>)null, exp1, exp2 );
- }
-
- public <Y> Expression<Y> coalesce(Class<Y> type, Expression<? extends Y> exp1, Y exp2) {
- return new CoalesceExpression<Y>( this, type ).value( exp1 ).value( exp2 );
- }
-
- /**
- * {@inheritDoc}
- */
- public <T> Coalesce<T> coalesce() {
- return coalesce( (Class<T>)null );
- }
-
- public <T> Coalesce<T> coalesce(Class<T> type) {
- return new CoalesceExpression<T>( this, type );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<String> concat(Expression<String> string1, Expression<String> string2) {
- return new ConcatExpression( this, string1, string2 );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<String> concat(Expression<String> string1, String string2) {
- return new ConcatExpression( this, string1, string2 );
- }
-
- /**
- * {@inheritDoc}
- */
- public Expression<String> concat(String string1, Expression<String> string2) {
- return new ConcatExpression( this, string1, string2 );
- }
-
- /**
- * {@inheritDoc}
- */
- public <Y> Expression<Y> nullif(Expression<Y> exp1, Expression<?> exp2) {
- return nullif( null, exp1, exp2 );
- }
-
- public <Y> Expression<Y> nullif(Class<Y> type, Expression<Y> exp1, Expression<?> exp2) {
- return new NullifExpression<Y>( this, type, exp1, exp2 );
- }
-
- /**
- * {@inheritDoc}
- */
- public <Y> Expression<Y> nullif(Expression<Y> exp1, Y exp2) {
- return nullif( null, exp1, exp2 );
- }
-
- public <Y> Expression<Y> nullif(Class<Y> type, Expression<Y> exp1, Y exp2) {
- return new NullifExpression<Y>( this, type, exp1, exp2 );
- }
-
- /**
- * {@inheritDoc}
- */
- public <C, R> SimpleCase<C, R> selectCase(Expression<? extends C> expression) {
- return selectCase( (Class<R>)null, expression );
- }
-
- public <C, R> SimpleCase<C, R> selectCase(Class<R> type, Expression<? extends C> expression) {
- return new SimpleCaseExpression<C, R>( this, type, expression );
- }
-
- /**
- * {@inheritDoc}
- */
- public <R> Case<R> selectCase() {
- return selectCase( (Class<R>)null );
- }
-
- public <R> Case<R> selectCase(Class<R> type) {
- return new SearchedCaseExpression<R>( this, type );
- }
-
- /**
- * {@inheritDoc}
- */
- public <C extends Collection<?>> Expression<Integer> size(C c) {
- int size = c == null ? 0 : c.size();
- return new LiteralExpression<Integer>(this, Integer.class, size);
- }
-
- /**
- * {@inheritDoc}
- */
- public <C extends Collection<?>> Expression<Integer> size(Expression<C> exp) {
- if ( LiteralExpression.class.isInstance(exp) ) {
- return size( ( (LiteralExpression<C>) exp ).getLiteral() );
- }
- else if ( CollectionExpression.class.isInstance(exp) ) {
- return new SizeOfCollectionExpression<C>(this, null);
- }
- // TODO : what other specific types? any?
- throw new IllegalArgumentException("unknown collection expression type [" + exp.getClass().getName() + "]" );
- }
-
- /**
- * {@inheritDoc}
- */
- public <V, M extends Map<?, V>> Expression<Collection<V>> values(M map) {
- return new LiteralExpression<Collection<V>>( this, map.values() );
- }
-
- /**
- * {@inheritDoc}
- */
- public <K, M extends Map<K, ?>> Expression<Set<K>> keys(M map) {
- return new LiteralExpression<Set<K>>( this, map.keySet() );
- }
-
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings({ "unchecked" })
- public <C extends Collection<?>> Predicate isEmpty(Expression<C> collectionExpression) {
- if ( CollectionExpression.class.isInstance(collectionExpression) ) {
- return new IsEmptyPredicate(
- this,
- (CollectionExpression<C>) collectionExpression
- );
- }
- // TODO : what other specific types? any?
- throw new IllegalArgumentException(
- "unknown collection expression type [" + collectionExpression.getClass().getName() + "]"
- );
- }
-
- /**
- * {@inheritDoc}
- */
- public <C extends Collection<?>> Predicate isNotEmpty(Expression<C> collectionExpression) {
- return isEmpty( collectionExpression ).not();
- }
-
- /**
- * {@inheritDoc}
- */
- public <E, C extends Collection<E>> Predicate isMember(E e, Expression<C> collectionExpression) {
- if ( ! CollectionExpression.class.isInstance(collectionExpression) ) {
- throw new IllegalArgumentException(
- "unknown collection expression type [" + collectionExpression.getClass().getName() + "]"
- );
- }
- return new MemberOfPredicate<E, C>(
- this,
- e,
- (CollectionExpression<C>)collectionExpression
- );
- }
-
- /**
- * {@inheritDoc}
- */
- public <E, C extends Collection<E>> Predicate isNotMember(E e, Expression<C> cExpression) {
- return isMember(e, cExpression).not();
- }
-
- /**
- * {@inheritDoc}
- */
- public <E, C extends Collection<E>> Predicate isMember(Expression<E> elementExpression, Expression<C> collectionExpression) {
- if ( ! CollectionExpression.class.isInstance(collectionExpression) ) {
- throw new IllegalArgumentException(
- "unknown collection expression type [" + collectionExpression.getClass().getName() + "]"
- );
- }
- return new MemberOfPredicate<E, C>(
- this,
- elementExpression,
- (CollectionExpression<C>)collectionExpression
- );
- }
-
- /**
- * {@inheritDoc}
- */
- public <E, C extends Collection<E>> Predicate isNotMember(Expression<E> eExpression, Expression<C> cExpression) {
- return isMember(eExpression, cExpression).not();
- }
-}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -30,6 +30,7 @@
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.ArrayList;
+import java.util.Collection;
import javax.persistence.criteria.AbstractQuery;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Predicate;
@@ -37,8 +38,13 @@
import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.Selection;
import javax.persistence.criteria.Subquery;
+import javax.persistence.criteria.Join;
+import javax.persistence.criteria.Fetch;
+import javax.persistence.criteria.JoinType;
import javax.persistence.metamodel.EntityType;
+import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
+
/**
* Models basic query structure. Used as a delegate in implementing both
* {@link org.hibernate.criterion.CriteriaQuery} and
@@ -52,14 +58,14 @@
*/
public class QueryStructure<T> {
private final AbstractQuery<T> owner;
- private final QueryBuilderImpl queryBuilder;
+ private final CriteriaBuilderImpl criteriaBuilder;
- public QueryStructure(AbstractQuery<T> owner, QueryBuilderImpl queryBuilder) {
+ public QueryStructure(AbstractQuery<T> owner, CriteriaBuilderImpl criteriaBuilder) {
this.owner = owner;
- this.queryBuilder = queryBuilder;
+ this.criteriaBuilder = criteriaBuilder;
}
- private boolean distinction;
+ private boolean distinct;
private Selection<? extends T> selection;
private Set<Root<?>> roots = new HashSet<Root<?>>();
private Predicate restriction;
@@ -101,12 +107,12 @@
// SELECTION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- public boolean isDistinction() {
- return distinction;
+ public boolean isDistinct() {
+ return distinct;
}
- public void setDistinction(boolean distinction) {
- this.distinction = distinction;
+ public void setDistinct(boolean distinct) {
+ this.distinct = distinct;
}
public Selection<? extends T> getSelection() {
@@ -125,7 +131,7 @@
}
public <X> Root<X> from(Class<X> entityClass) {
- EntityType<X> entityType = queryBuilder.getEntityManagerFactory()
+ EntityType<X> entityType = criteriaBuilder.getEntityManagerFactory()
.getMetamodel()
.entity( entityClass );
if ( entityType == null ) {
@@ -135,7 +141,7 @@
}
public <X> Root<X> from(EntityType<X> entityType) {
- RootImpl<X> root = new RootImpl<X>( queryBuilder, entityType );
+ RootImpl<X> root = new RootImpl<X>( criteriaBuilder, entityType );
roots.add( root );
return root;
}
@@ -194,8 +200,111 @@
}
public <U> Subquery<U> subquery(Class<U> subqueryType) {
- CriteriaSubqueryImpl<U> subquery = new CriteriaSubqueryImpl<U>( queryBuilder, subqueryType, owner );
+ CriteriaSubqueryImpl<U> subquery = new CriteriaSubqueryImpl<U>( criteriaBuilder, subqueryType, owner );
internalGetSubqueries().add( subquery );
return subquery;
}
+
+ @SuppressWarnings({ "unchecked" })
+ public void render(StringBuilder jpaqlQuery, CriteriaQueryCompiler.RenderingContext renderingContext) {
+ jpaqlQuery.append( "select " );
+ if ( isDistinct() ) {
+ jpaqlQuery.append( " distinct " );
+ }
+ if ( getSelection() == null ) {
+ // we should have only a single root (query validation should have checked this...)
+ final Root root = getRoots().iterator().next();
+ ( (TableExpressionMapper) root ).prepareAlias( renderingContext );
+ jpaqlQuery.append( root.getAlias() );
+ }
+ else {
+ ( ( ExpressionImplementor ) getSelection() ).renderProjection( renderingContext );
+ }
+
+ jpaqlQuery.append( " from " );
+ String sep = "";
+ for ( Root root : getRoots() ) {
+ ( (TableExpressionMapper) root ).prepareAlias( renderingContext );
+ jpaqlQuery.append( sep );
+ jpaqlQuery.append( ( ( TableExpressionMapper ) root ).renderTableExpression( renderingContext ) );
+ sep = ", ";
+ }
+
+ for ( Root root : getRoots() ) {
+ renderJoins( jpaqlQuery, renderingContext, root.getJoins() );
+ renderFetches( jpaqlQuery, renderingContext, root.getFetches() );
+ }
+
+ if ( getRestriction() != null) {
+ jpaqlQuery.append( " where " )
+ .append( ( (ExpressionImplementor) getRestriction() ).render( renderingContext ) );
+ }
+
+ if ( ! getGroupings().isEmpty() ) {
+ jpaqlQuery.append( " group by " );
+ sep = "";
+ for ( Expression grouping : getGroupings() ) {
+ jpaqlQuery.append( sep )
+ .append( ( (ExpressionImplementor) grouping ).render( renderingContext ) );
+ sep = ", ";
+ }
+
+ if ( getHaving() != null ) {
+ jpaqlQuery.append( " having " )
+ .append( ( (ExpressionImplementor) getHaving() ).render( renderingContext ) );
+ }
+ }
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ private void renderJoins(
+ StringBuilder jpaqlQuery,
+ CriteriaQueryCompiler.RenderingContext renderingContext,
+ Collection<Join<?,?>> joins) {
+ if ( joins == null ) {
+ return;
+ }
+
+ for ( Join join : joins ) {
+ ( (TableExpressionMapper) join ).prepareAlias( renderingContext );
+ jpaqlQuery.append( renderJoinType( join.getJoinType() ) )
+ .append( ( ( TableExpressionMapper ) join ).renderTableExpression( renderingContext ) );
+ renderJoins( jpaqlQuery, renderingContext, join.getJoins() );
+ renderFetches( jpaqlQuery, renderingContext, join.getFetches() );
+ }
+ }
+
+ private String renderJoinType(JoinType joinType) {
+ switch ( joinType ) {
+ case INNER: {
+ return " inner join ";
+ }
+ case LEFT: {
+ return " left join ";
+ }
+ case RIGHT: {
+ return " right join ";
+ }
+ }
+ throw new IllegalStateException( "Unknown join type " + joinType );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ private void renderFetches(
+ StringBuilder jpaqlQuery,
+ CriteriaQueryCompiler.RenderingContext renderingContext,
+ Collection<Fetch> fetches) {
+ if ( fetches == null ) {
+ return;
+ }
+
+ for ( Fetch fetch : fetches ) {
+ ( (TableExpressionMapper) fetch ).prepareAlias( renderingContext );
+ jpaqlQuery.append( renderJoinType( fetch.getJoinType() ) )
+ .append( "fetch " )
+ .append( ( ( TableExpressionMapper ) fetch ).renderTableExpression( renderingContext ) );
+
+ renderFetches( jpaqlQuery, renderingContext, fetch.getFetches() );
+ }
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/RootImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/RootImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/RootImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -37,9 +37,9 @@
private RootImpl<X> correlationParent;
public RootImpl(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
EntityType<X> model) {
- super( queryBuilder, model );
+ super( criteriaBuilder, model );
}
@Override
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/SetJoinImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/SetJoinImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/SetJoinImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -39,12 +39,12 @@
implements JoinImplementors.SetJoinImplementor<O,E> {
public SetJoinImpl(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<E> javaType,
PathImpl<O> lhs,
SetAttribute<? super O, ?> joinProperty,
JoinType joinType) {
- super(queryBuilder, javaType, lhs, joinProperty, joinType);
+ super( criteriaBuilder, javaType, lhs, joinProperty, joinType);
}
@Override
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/TableExpressionMapper.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/TableExpressionMapper.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/TableExpressionMapper.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -0,0 +1,34 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @author tags or express
+ * copyright attribution statements applied by the authors. All
+ * third-party contributions are distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.ejb.criteria;
+
+/**
+ * Common contract for things which map to a table expression in a <tt>SQL FROM clause</tt>.
+ *
+ * @author Steve Ebersole
+ */
+public interface TableExpressionMapper {
+ public void prepareAlias(CriteriaQueryCompiler.RenderingContext renderingContext);
+ public String renderTableExpression(CriteriaQueryCompiler.RenderingContext renderingContext);
+}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/AbstractTupleElement.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/AbstractTupleElement.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/AbstractTupleElement.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -26,7 +26,7 @@
import javax.persistence.TupleElement;
import org.hibernate.ejb.criteria.AbstractNode;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
/**
* TODO : javadoc
@@ -37,8 +37,8 @@
private final Class<X> javaType;
private String alias;
- protected AbstractTupleElement(QueryBuilderImpl queryBuilder, Class<X> javaType) {
- super( queryBuilder );
+ protected AbstractTupleElement(CriteriaBuilderImpl criteriaBuilder, Class<X> javaType) {
+ super( criteriaBuilder );
this.javaType = javaType;
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -26,7 +26,8 @@
import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
/**
* Models standard arithmetc operations with two operands.
@@ -38,7 +39,37 @@
implements BinaryOperatorExpression<N> {
public static enum Operation {
- ADD, SUBTRACT, MULTIPLY, DIVIDE, QUOT, MOD
+ ADD {
+ String apply(String lhs, String rhs) {
+ return lhs + " + " + rhs;
+ }
+ },
+ SUBTRACT {
+ String apply(String lhs, String rhs) {
+ return lhs + " - " + rhs;
+ }
+ },
+ MULTIPLY {
+ String apply(String lhs, String rhs) {
+ return lhs + " * " + rhs;
+ }
+ },
+ DIVIDE {
+ String apply(String lhs, String rhs) {
+ return lhs + " / " + rhs;
+ }
+ },
+ QUOT {
+ String apply(String lhs, String rhs) {
+ return lhs + " / " + rhs;
+ }
+ },
+ MOD {
+ String apply(String lhs, String rhs) {
+ return lhs + " % " + rhs;
+ }
+ };
+ abstract String apply(String lhs, String rhs);
}
private final Operation operator;
@@ -78,19 +109,19 @@
/**
* Creates an arithmethic operation based on 2 expressions.
*
- * @param queryBuilder The builder for query components.
+ * @param criteriaBuilder The builder for query components.
* @param resultType The operation result type
* @param operator The operator (type of operation).
* @param rhs The right-hand operand
* @param lhs The left-hand operand.
*/
public BinaryArithmeticOperation(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<N> resultType,
Operation operator,
Expression<? extends N> rhs,
Expression<? extends N> lhs) {
- super( queryBuilder, resultType );
+ super( criteriaBuilder, resultType );
this.operator = operator;
this.rhs = rhs;
this.lhs = lhs;
@@ -99,42 +130,42 @@
/**
* Creates an arithmethic operation based on an expression and a literal.
*
- * @param queryBuilder The builder for query components.
- * @param resultType The operation result type
+ * @param criteriaBuilder The builder for query components.
+ * @param javaType The operation result type
* @param operator The operator (type of operation).
* @param rhs The right-hand operand
* @param lhs The left-hand operand (the literal).
*/
public BinaryArithmeticOperation(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<N> javaType,
Operation operator,
Expression<? extends N> rhs,
N lhs) {
- super( queryBuilder, javaType );
+ super( criteriaBuilder, javaType );
this.operator = operator;
this.rhs = rhs;
- this.lhs = new LiteralExpression<N>( queryBuilder, lhs );
+ this.lhs = new LiteralExpression<N>( criteriaBuilder, lhs );
}
/**
* Creates an arithmethic operation based on an expression and a literal.
*
- * @param queryBuilder The builder for query components.
- * @param resultType The operation result type
+ * @param criteriaBuilder The builder for query components.
+ * @param javaType The operation result type
* @param operator The operator (type of operation).
* @param rhs The right-hand operand (the literal).
* @param lhs The left-hand operand
*/
public BinaryArithmeticOperation(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<N> javaType,
Operation operator,
N rhs,
Expression<? extends N> lhs) {
- super( queryBuilder, javaType );
+ super( criteriaBuilder, javaType );
this.operator = operator;
- this.rhs = new LiteralExpression<N>( queryBuilder, rhs );
+ this.rhs = new LiteralExpression<N>( criteriaBuilder, rhs );
this.lhs = lhs;
}
public Operation getOperator() {
@@ -163,4 +194,14 @@
Helper.possibleParameter( getLeftHandOperand(), registry );
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return getOperator().apply(
+ ( (ExpressionImplementor) getLeftHandOperand() ).render( renderingContext ),
+ ( (ExpressionImplementor) getRightHandOperand() ).render( renderingContext )
+ );
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CoalesceExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CoalesceExpression.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CoalesceExpression.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -28,7 +28,8 @@
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.CriteriaBuilder.Coalesce;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
/**
* Models an ANSI SQL <tt>COALESCE</tt> expression. <tt>COALESCE</tt> is a specialized <tt>CASE</tt> statement.
@@ -39,14 +40,14 @@
private final List<Expression<? extends T>> expressions;
private Class<T> javaType;
- public CoalesceExpression(QueryBuilderImpl queryBuilder) {
- this( queryBuilder, null );
+ public CoalesceExpression(CriteriaBuilderImpl criteriaBuilder) {
+ this( criteriaBuilder, null );
}
public CoalesceExpression(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<T> javaType) {
- super( queryBuilder, javaType );
+ super( criteriaBuilder, javaType );
this.javaType = javaType;
this.expressions = new ArrayList<Expression<? extends T>>();
}
@@ -79,5 +80,18 @@
}
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ StringBuilder buffer = new StringBuilder( "coalesce(" );
+ String sep = "";
+ for ( Expression expression : getExpressions() ) {
+ buffer.append( sep )
+ .append( ( (ExpressionImplementor) expression ).render( renderingContext ) );
+ sep = ", ";
+ }
+ return buffer.append( ")" ).toString();
+ }
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CollectionExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CollectionExpression.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CollectionExpression.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -25,7 +25,9 @@
import javax.persistence.metamodel.PluralAttribute;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.PathImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.persister.collection.CollectionPersister;
@@ -35,19 +37,21 @@
* @author Steve Ebersole
*/
public class CollectionExpression<C> extends ExpressionImpl<C> {
+ private final PathImpl origin;
private final CollectionPersister persister;
private final PluralAttribute<?, C, ?> attribute;
public CollectionExpression(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<C> javaType,
+ PathImpl origin,
PluralAttribute<?, C, ?> attribute) {
- this( queryBuilder, javaType, resolvePersister( queryBuilder, attribute ), attribute );
+ this( criteriaBuilder, javaType, resolvePersister( criteriaBuilder, attribute ), origin, attribute );
}
- private static CollectionPersister resolvePersister(QueryBuilderImpl queryBuilder, PluralAttribute attribute) {
+ private static CollectionPersister resolvePersister(CriteriaBuilderImpl criteriaBuilder, PluralAttribute attribute) {
SessionFactoryImplementor sfi = (SessionFactoryImplementor)
- queryBuilder.getEntityManagerFactory().getSessionFactory();
+ criteriaBuilder.getEntityManagerFactory().getSessionFactory();
return sfi.getCollectionPersister( resolveRole( attribute ) );
}
@@ -57,11 +61,13 @@
}
public CollectionExpression(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<C> javaType,
CollectionPersister persister,
+ PathImpl origin,
PluralAttribute<?, C, ?> attribute) {
- super(queryBuilder, javaType);
+ super( criteriaBuilder, javaType );
+ this.origin = origin;
this.persister = persister;
this.attribute = attribute;
}
@@ -77,4 +83,12 @@
public void registerParameters(ParameterRegistry registry) {
// none to register
}
+
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return origin.getPathIdentifier() + '.' + getAttribute().getName();
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CompoundSelectionImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CompoundSelectionImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CompoundSelectionImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -27,9 +27,8 @@
import javax.persistence.criteria.CompoundSelection;
import javax.persistence.criteria.Selection;
-import org.hibernate.ejb.criteria.ParameterContainer;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
/**
* The Hibernate implementation of the JPA {@link CompoundSelection}
@@ -41,10 +40,10 @@
private List<Selection<?>> selectionItems;
public CompoundSelectionImpl(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<X> javaType,
List<Selection<?>> selectionItems) {
- super( queryBuilder, javaType );
+ super( criteriaBuilder, javaType );
this.selectionItems = selectionItems;
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ConcatExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ConcatExpression.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ConcatExpression.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -24,12 +24,12 @@
package org.hibernate.ejb.criteria.expression;
import javax.persistence.criteria.Expression;
-import org.hibernate.ejb.criteria.ParameterContainer;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
/**
- * TODO : javadoc
+ * A string concatenation.
*
* @author Steve Ebersole
*/
@@ -38,30 +38,30 @@
private Expression<String> string2;
public ConcatExpression(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<String> expression1,
Expression<String> expression2) {
- super( queryBuilder, String.class );
+ super( criteriaBuilder, String.class );
this.string1 = expression1;
this.string2 = expression2;
}
public ConcatExpression(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<String> string1,
String string2) {
- this( queryBuilder, string1, wrap(queryBuilder, string2) );
+ this( criteriaBuilder, string1, wrap( criteriaBuilder, string2) );
}
- private static Expression<String> wrap(QueryBuilderImpl queryBuilder, String string) {
- return new LiteralExpression<String>( queryBuilder, string );
+ private static Expression<String> wrap(CriteriaBuilderImpl criteriaBuilder, String string) {
+ return new LiteralExpression<String>( criteriaBuilder, string );
}
public ConcatExpression(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
String string1,
Expression<String> string2) {
- this( queryBuilder, wrap(queryBuilder, string1), string2 );
+ this( criteriaBuilder, wrap( criteriaBuilder, string1), string2 );
}
public Expression<String> getString1() {
@@ -77,4 +77,13 @@
Helper.possibleParameter( getString2(), registry );
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return ( (ExpressionImplementor) getString1() ).render( renderingContext )
+ + " || "
+ + ( (ExpressionImplementor) getString2() ).render( renderingContext );
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/EntityTypeExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/EntityTypeExpression.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/EntityTypeExpression.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -24,7 +24,8 @@
package org.hibernate.ejb.criteria.expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
/**
* TODO : javadoc
@@ -32,12 +33,20 @@
* @author Steve Ebersole
*/
public class EntityTypeExpression<T> extends ExpressionImpl<T> {
- public EntityTypeExpression(QueryBuilderImpl queryBuilder, Class<T> javaType) {
- super( queryBuilder, javaType );
+ public EntityTypeExpression(CriteriaBuilderImpl criteriaBuilder, Class<T> javaType) {
+ super( criteriaBuilder, javaType );
}
public void registerParameters(ParameterRegistry registry) {
// nothign to do
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ // todo : is it valid for this to get rendered into the query itself?
+ throw new IllegalArgumentException( "Unexpected call on EntityTypeExpression#render" );
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -27,7 +27,7 @@
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.expression.function.CastFunction;
/**
@@ -35,9 +35,9 @@
*
* @author Steve Ebersole
*/
-public abstract class ExpressionImpl<T> extends SelectionImpl<T> implements Expression<T> {
- public ExpressionImpl(QueryBuilderImpl queryBuilder, Class<T> javaType) {
- super( queryBuilder, javaType );
+public abstract class ExpressionImpl<T> extends SelectionImpl<T> implements ExpressionImplementor<T> {
+ public ExpressionImpl(CriteriaBuilderImpl criteriaBuilder, Class<T> javaType) {
+ super( criteriaBuilder, javaType );
}
/**
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImplementor.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImplementor.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImplementor.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -0,0 +1,38 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @author tags or express
+ * copyright attribution statements applied by the authors. All
+ * third-party contributions are distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.ejb.criteria.expression;
+
+import javax.persistence.criteria.Expression;
+
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public interface ExpressionImplementor<T> extends Expression<T> {
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext);
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext);
+}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ListIndexExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ListIndexExpression.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ListIndexExpression.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -25,7 +25,9 @@
import javax.persistence.metamodel.ListAttribute;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.PathImpl;
/**
* An expression for referring to the index of a list.
@@ -33,10 +35,12 @@
* @author Steve Ebersole
*/
public class ListIndexExpression extends ExpressionImpl<Integer> {
+ private final PathImpl origin;
private final ListAttribute<?,?> listAttribute;
- public ListIndexExpression(QueryBuilderImpl queryBuilder, ListAttribute<?,?> listAttribute) {
- super( queryBuilder, Integer.class );
+ public ListIndexExpression(CriteriaBuilderImpl criteriaBuilder, PathImpl origin, ListAttribute<?,?> listAttribute) {
+ super( criteriaBuilder, Integer.class );
+ this.origin = origin;
this.listAttribute = listAttribute;
}
@@ -47,4 +51,14 @@
public void registerParameters(ParameterRegistry registry) {
// nothign to do
}
+
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return "index("
+ + origin.getPathIdentifier() + '.' + getListAttribute().getName()
+ + ")";
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/LiteralExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/LiteralExpression.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/LiteralExpression.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -23,8 +23,11 @@
*/
package org.hibernate.ejb.criteria.expression;
+import javax.persistence.TypedQuery;
+
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
/**
* Represents a literal expression.
@@ -34,16 +37,17 @@
public class LiteralExpression<T> extends ExpressionImpl<T> {
private final T literal;
- public LiteralExpression(QueryBuilderImpl queryBuilder, T literal) {
- this( queryBuilder, (Class<T>) determineClass( literal ), literal );
+ @SuppressWarnings({ "unchecked" })
+ public LiteralExpression(CriteriaBuilderImpl criteriaBuilder, T literal) {
+ this( criteriaBuilder, (Class<T>) determineClass( literal ), literal );
}
private static Class determineClass(Object literal) {
return literal == null ? null : literal.getClass();
}
- public LiteralExpression(QueryBuilderImpl queryBuilder, Class<T> type, T literal) {
- super( queryBuilder, type );
+ public LiteralExpression(CriteriaBuilderImpl criteriaBuilder, Class<T> type, T literal) {
+ super( criteriaBuilder, type );
this.literal = literal;
}
@@ -54,4 +58,20 @@
public void registerParameters(ParameterRegistry registry) {
// nothign to do
}
+
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ final String parameterName = renderingContext.generateParameterName();
+ renderingContext.registerImplicitParameterBinding(
+ new CriteriaQueryCompiler.ImplicitParameterBinding() {
+ public void bind(TypedQuery typedQuery) {
+ typedQuery.setParameter( parameterName, getLiteral() );
+ }
+ }
+ );
+ return ':' + parameterName;
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/NullifExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/NullifExpression.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/NullifExpression.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -24,9 +24,9 @@
package org.hibernate.ejb.criteria.expression;
import javax.persistence.criteria.Expression;
-import org.hibernate.ejb.criteria.ParameterContainer;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
/**
* Models an ANSI SQL <tt>NULLIF</tt> expression. <tt>NULLIF</tt> is a specialized <tt>CASE</tt> statement.
@@ -38,23 +38,23 @@
private final Expression<?> secondaryExpression;
public NullifExpression(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<T> javaType,
Expression<? extends T> primaryExpression,
Expression<?> secondaryExpression) {
- super( queryBuilder, (Class<T>)determineType(javaType, primaryExpression) );
+ super( criteriaBuilder, (Class<T>)determineType(javaType, primaryExpression) );
this.primaryExpression = primaryExpression;
this.secondaryExpression = secondaryExpression;
}
public NullifExpression(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<T> javaType,
Expression<? extends T> primaryExpression,
Object secondaryExpression) {
- super( queryBuilder, (Class<T>)determineType(javaType, primaryExpression) );
+ super( criteriaBuilder, (Class<T>)determineType(javaType, primaryExpression) );
this.primaryExpression = primaryExpression;
- this.secondaryExpression = new LiteralExpression( queryBuilder, secondaryExpression );
+ this.secondaryExpression = new LiteralExpression( criteriaBuilder, secondaryExpression );
}
private static Class determineType(Class javaType, Expression primaryExpression) {
@@ -74,4 +74,15 @@
Helper.possibleParameter( getSecondaryExpression(), registry );
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return "nullif("
+ + ( (ExpressionImplementor) getPrimaryExpression() ).render( renderingContext )
+ + ','
+ + ( (ExpressionImplementor) getSecondaryExpression() ).render( renderingContext )
+ + ")";
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ParameterExpressionImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ParameterExpressionImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ParameterExpressionImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -26,7 +26,8 @@
import javax.persistence.criteria.ParameterExpression;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
/**
* Defines a parameter specification, or the information about a parameter (where it occurs, what is
@@ -39,27 +40,27 @@
private final Integer position;
public ParameterExpressionImpl(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<T> javaType,
String name) {
- super( queryBuilder, javaType );
+ super( criteriaBuilder, javaType );
this.name = name;
this.position = null;
}
public ParameterExpressionImpl(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<T> javaType,
Integer position) {
- super( queryBuilder, javaType );
+ super( criteriaBuilder, javaType );
this.name = null;
this.position = position;
}
public ParameterExpressionImpl(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<T> javaType) {
- super( queryBuilder, javaType );
+ super( criteriaBuilder, javaType );
this.name = null;
this.position = null;
}
@@ -80,4 +81,13 @@
registry.registerParameter( this );
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ final String jpaqlParamName = renderingContext.generateParameterName();
+ renderingContext.registerExplicitParameter( this, jpaqlParamName );
+ return ':' + jpaqlParamName;
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SearchedCaseExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SearchedCaseExpression.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SearchedCaseExpression.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -28,10 +28,18 @@
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.CriteriaBuilder.Case;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
/**
- * Models what ANSI SQL terms a <tt>searched case expression</tt
+ * Models what ANSI SQL terms a <tt>searched case expression</tt>. This is a <tt>CASE</tt> expression
+ * in the form<pre>
+ * CASE
+ * WHEN [firstCondition] THEN [firstResult]
+ * WHEN [secondCondition] THEN [secondResult]
+ * ELSE [defaultResult]
+ * END
+ * </pre>
*
* @author Steve Ebersole
*/
@@ -59,9 +67,9 @@
}
public SearchedCaseExpression(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<R> javaType) {
- super(queryBuilder, javaType);
+ super( criteriaBuilder, javaType);
this.javaType = javaType;
}
@@ -117,4 +125,21 @@
}
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ StringBuilder caseStatement = new StringBuilder( "case" );
+ for ( WhenClause whenClause : getWhenClauses() ) {
+ caseStatement.append( " when " )
+ .append( ( (ExpressionImplementor) whenClause.getCondition() ).render( renderingContext ) )
+ .append( " then " )
+ .append( ( (ExpressionImplementor) whenClause.getResult() ).render( renderingContext ) );
+ }
+ caseStatement.append( " else " )
+ .append( ( (ExpressionImplementor) getOtherwiseResult() ).render( renderingContext ) )
+ .append( " end" );
+ return caseStatement.toString();
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SelectionImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SelectionImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SelectionImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -27,7 +27,7 @@
import javax.persistence.criteria.Selection;
import org.hibernate.ejb.criteria.ParameterContainer;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
/**
* The Hibernate implementation of the JPA {@link Selection}
@@ -38,8 +38,8 @@
public abstract class SelectionImpl<X>
extends AbstractTupleElement<X>
implements Selection<X>, ParameterContainer {
- public SelectionImpl(QueryBuilderImpl queryBuilder, Class<X> javaType) {
- super( queryBuilder, javaType );
+ public SelectionImpl(CriteriaBuilderImpl criteriaBuilder, Class<X> javaType) {
+ super( criteriaBuilder, javaType );
}
public Selection<X> alias(String alias) {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SimpleCaseExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SimpleCaseExpression.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SimpleCaseExpression.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -28,10 +28,17 @@
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.CriteriaBuilder.SimpleCase;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
/**
- * Models what ANSI SQL terms a simple case statement.
+ * Models what ANSI SQL terms a simple case statement. This is a <tt>CASE</tt> expression in the form<pre>
+ * CASE [expression]
+ * WHEN [firstCondition] THEN [firstResult]
+ * WHEN [secondCondition] THEN [secondResult]
+ * ELSE [defaultResult]
+ * END
+ * </pre>
*
* @author Steve Ebersole
*/
@@ -61,10 +68,10 @@
}
public SimpleCaseExpression(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<R> javaType,
Expression<? extends C> expression) {
- super(queryBuilder, javaType);
+ super( criteriaBuilder, javaType);
this.javaType = javaType;
this.expression = expression;
}
@@ -126,4 +133,23 @@
Helper.possibleParameter( getOtherwiseResult(), registry );
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ StringBuilder caseExpr = new StringBuilder();
+ caseExpr.append( "case " )
+ .append( ( (ExpressionImplementor) getExpression() ).render( renderingContext ) )
+ .append( ' ' );
+ for ( WhenClause whenClause : getWhenClauses() ) {
+ caseExpr.append( ( (ExpressionImplementor) whenClause.getCondition() ).render( renderingContext ) )
+ .append( " then " )
+ .append( ( (ExpressionImplementor) whenClause.getResult() ).render( renderingContext ) );
+ }
+ caseExpr.append( " else " )
+ .append( ( (ExpressionImplementor) getOtherwiseResult() ).render( renderingContext ) )
+ .append( " end" );
+ return caseExpr.toString();
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SizeOfCollectionExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SizeOfCollectionExpression.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SizeOfCollectionExpression.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -25,7 +25,8 @@
import java.util.Collection;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
/**
* Represents a "size of" expression in regards to a persistent collection; the implication is
@@ -38,9 +39,9 @@
private final CollectionExpression<C> collectionExpression;
public SizeOfCollectionExpression(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
CollectionExpression<C> collectionExpression) {
- super(queryBuilder, Integer.class);
+ super( criteriaBuilder, Integer.class);
this.collectionExpression = collectionExpression;
}
@@ -52,4 +53,11 @@
// nothign to do
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return "size of " + getCollectionExpression().render( renderingContext );
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SubqueryComparisonModifierExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SubqueryComparisonModifierExpression.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SubqueryComparisonModifierExpression.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -25,7 +25,8 @@
import javax.persistence.criteria.Subquery;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
/**
* Represents a {@link Modifier#ALL}, {@link Modifier#ANY}, {@link Modifier#SOME} modifier appplied to a subquery as
@@ -34,17 +35,34 @@
* @author Steve Ebersole
*/
public class SubqueryComparisonModifierExpression<Y> extends ExpressionImpl<Y> {
- public static enum Modifier { ALL, SOME, ANY }
+ public static enum Modifier {
+ ALL {
+ String rendered() {
+ return "all ";
+ }
+ },
+ SOME {
+ String rendered() {
+ return "some ";
+ }
+ },
+ ANY {
+ String rendered() {
+ return "any ";
+ }
+ };
+ abstract String rendered();
+ }
private final Subquery<Y> subquery;
private final Modifier modifier;
public SubqueryComparisonModifierExpression(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<Y> javaType,
Subquery<Y> subquery,
Modifier modifier) {
- super(queryBuilder, javaType);
+ super( criteriaBuilder, javaType);
this.subquery = subquery;
this.modifier = modifier;
}
@@ -61,4 +79,11 @@
// nothign to do (the subquery should be handled directly, and the modified itself is not parameterized)
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return getModifier().rendered() + ( ( ExpressionImplementor ) getSubquery() ).render( renderingContext );
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryArithmeticOperation.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryArithmeticOperation.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryArithmeticOperation.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -25,7 +25,8 @@
import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
/**
* Models unary arithmetic operation (unary plus and unary minus).
@@ -43,11 +44,12 @@
private final Operation operation;
private final Expression<T> operand;
+ @SuppressWarnings({ "unchecked" })
public UnaryArithmeticOperation(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Operation operation,
Expression<T> operand) {
- super( queryBuilder, (Class)operand.getJavaType() );
+ super( criteriaBuilder, (Class)operand.getJavaType() );
this.operation = operation;
this.operand = operand;
}
@@ -70,4 +72,12 @@
Helper.possibleParameter( getOperand(), registry );
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return ( getOperation() == Operation.UNARY_MINUS ? '-' : '+' )
+ + ( (ExpressionImplementor) getOperand() ).render( renderingContext );
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AbsFunction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AbsFunction.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AbsFunction.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -24,7 +24,7 @@
package org.hibernate.ejb.criteria.expression.function;
import javax.persistence.criteria.Expression;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
/**
* Models the ANSI SQL <tt>ABS</tt> function.
@@ -36,7 +36,7 @@
public static final String NAME = "abs";
- public AbsFunction(QueryBuilderImpl queryBuilder, Expression expression) {
- super( queryBuilder, expression.getJavaType(), NAME, expression );
+ public AbsFunction(CriteriaBuilderImpl criteriaBuilder, Expression expression) {
+ super( criteriaBuilder, expression.getJavaType(), NAME, expression );
}
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AggregationFunction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AggregationFunction.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AggregationFunction.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -24,7 +24,7 @@
package org.hibernate.ejb.criteria.expression.function;
import javax.persistence.criteria.Expression;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
/**
@@ -36,34 +36,34 @@
/**
* Constructs an aggregation function with a single literal argument.
*
- * @param queryBuilder The query builder instance.
+ * @param criteriaBuilder The query builder instance.
* @param returnType The function return type.
* @param functionName The name of the function.
* @param argument The literal argument
*/
@SuppressWarnings({ "unchecked" })
public AggregationFunction(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<T> returnType,
String functionName,
Object argument) {
- this( queryBuilder, returnType, functionName, new LiteralExpression( queryBuilder, argument ) );
+ this( criteriaBuilder, returnType, functionName, new LiteralExpression( criteriaBuilder, argument ) );
}
/**
* Constructs an aggregation function with a single literal argument.
*
- * @param queryBuilder The query builder instance.
+ * @param criteriaBuilder The query builder instance.
* @param returnType The function return type.
* @param functionName The name of the function.
* @param argument The argument
*/
public AggregationFunction(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<T> returnType,
String functionName,
Expression<?> argument) {
- super( queryBuilder, returnType, functionName, argument );
+ super( criteriaBuilder, returnType, functionName, argument );
}
@Override
@@ -82,8 +82,8 @@
private final boolean distinct;
- public COUNT(QueryBuilderImpl queryBuilder, Expression<?> expression, boolean distinct) {
- super( queryBuilder, Long.class, NAME , expression );
+ public COUNT(CriteriaBuilderImpl criteriaBuilder, Expression<?> expression, boolean distinct) {
+ super( criteriaBuilder, Long.class, NAME , expression );
this.distinct = distinct;
}
@@ -101,8 +101,8 @@
public static class AVG extends AggregationFunction<Double> {
public static final String NAME = "avg";
- public AVG(QueryBuilderImpl queryBuilder, Expression<? extends Number> expression) {
- super( queryBuilder, Double.class, NAME, expression );
+ public AVG(CriteriaBuilderImpl criteriaBuilder, Expression<? extends Number> expression) {
+ super( criteriaBuilder, Double.class, NAME, expression );
}
}
@@ -116,12 +116,12 @@
public static final String NAME = "sum";
@SuppressWarnings({ "unchecked" })
- public SUM(QueryBuilderImpl queryBuilder, Expression<N> expression) {
- super( queryBuilder, (Class<N>)expression.getJavaType(), NAME , expression);
+ public SUM(CriteriaBuilderImpl criteriaBuilder, Expression<N> expression) {
+ super( criteriaBuilder, (Class<N>)expression.getJavaType(), NAME , expression);
}
- public SUM(QueryBuilderImpl queryBuilder, Expression<? extends Number> expression, Class<N> returnType) {
- super( queryBuilder, returnType, NAME , expression);
+ public SUM(CriteriaBuilderImpl criteriaBuilder, Expression<? extends Number> expression, Class<N> returnType) {
+ super( criteriaBuilder, returnType, NAME , expression);
}
}
@@ -135,8 +135,8 @@
public static final String NAME = "min";
@SuppressWarnings({ "unchecked" })
- public MIN(QueryBuilderImpl queryBuilder, Expression<N> expression) {
- super( queryBuilder, ( Class<N> ) expression.getJavaType(), NAME , expression);
+ public MIN(CriteriaBuilderImpl criteriaBuilder, Expression<N> expression) {
+ super( criteriaBuilder, ( Class<N> ) expression.getJavaType(), NAME , expression);
}
}
@@ -150,8 +150,8 @@
public static final String NAME = "max";
@SuppressWarnings({ "unchecked" })
- public MAX(QueryBuilderImpl queryBuilder, Expression<N> expression) {
- super( queryBuilder, ( Class<N> ) expression.getJavaType(), NAME , expression);
+ public MAX(CriteriaBuilderImpl criteriaBuilder, Expression<N> expression) {
+ super( criteriaBuilder, ( Class<N> ) expression.getJavaType(), NAME , expression);
}
}
@@ -164,8 +164,8 @@
public static final String NAME = "min";
@SuppressWarnings({ "unchecked" })
- public LEAST(QueryBuilderImpl queryBuilder, Expression<X> expression) {
- super( queryBuilder, ( Class<X> ) expression.getJavaType(), NAME , expression);
+ public LEAST(CriteriaBuilderImpl criteriaBuilder, Expression<X> expression) {
+ super( criteriaBuilder, ( Class<X> ) expression.getJavaType(), NAME , expression);
}
}
@@ -178,8 +178,8 @@
public static final String NAME = "max";
@SuppressWarnings({ "unchecked" })
- public GREATEST(QueryBuilderImpl queryBuilder, Expression<X> expression) {
- super( queryBuilder, ( Class<X> ) expression.getJavaType(), NAME , expression);
+ public GREATEST(CriteriaBuilderImpl criteriaBuilder, Expression<X> expression) {
+ super( criteriaBuilder, ( Class<X> ) expression.getJavaType(), NAME , expression);
}
}
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/BasicFunctionExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/BasicFunctionExpression.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/BasicFunctionExpression.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -25,7 +25,8 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.expression.ExpressionImpl;
/**
@@ -40,10 +41,10 @@
private final String functionName;
public BasicFunctionExpression(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<X> javaType,
String functionName) {
- super( queryBuilder, javaType );
+ super( criteriaBuilder, javaType );
this.functionName = functionName;
}
@@ -62,4 +63,12 @@
public void registerParameters(ParameterRegistry registry) {
// nothing to do here...
}
+
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return getFunctionName() + "()";
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CastFunction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CastFunction.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CastFunction.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -24,7 +24,7 @@
package org.hibernate.ejb.criteria.expression.function;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.expression.ExpressionImpl;
/**
@@ -41,10 +41,10 @@
private final ExpressionImpl<Y> castSource;
public CastFunction(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<T> javaType,
ExpressionImpl<Y> castSource) {
- super( queryBuilder, javaType, CAST_NAME );
+ super( criteriaBuilder, javaType, CAST_NAME );
this.castSource = castSource;
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CurrentDateFunction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CurrentDateFunction.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CurrentDateFunction.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -23,7 +23,7 @@
*/
package org.hibernate.ejb.criteria.expression.function;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
/**
* Models the ANSI SQL <tt>CURRENT_DATE</tt> function.
@@ -33,7 +33,7 @@
public class CurrentDateFunction extends BasicFunctionExpression<java.sql.Date> {
public static final String NAME = "current_date";
- public CurrentDateFunction(QueryBuilderImpl queryBuilder) {
- super( queryBuilder, java.sql.Date.class, NAME );
+ public CurrentDateFunction(CriteriaBuilderImpl criteriaBuilder) {
+ super( criteriaBuilder, java.sql.Date.class, NAME );
}
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CurrentTimeFunction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CurrentTimeFunction.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CurrentTimeFunction.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -23,7 +23,7 @@
*/
package org.hibernate.ejb.criteria.expression.function;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
/**
* Models the ANSI SQL <tt>CURRENT_TIME</tt> function.
@@ -33,7 +33,7 @@
public class CurrentTimeFunction extends BasicFunctionExpression<java.sql.Time> {
public static final String NAME = "current_time";
- public CurrentTimeFunction(QueryBuilderImpl queryBuilder) {
- super( queryBuilder, java.sql.Time.class, NAME );
+ public CurrentTimeFunction(CriteriaBuilderImpl criteriaBuilder) {
+ super( criteriaBuilder, java.sql.Time.class, NAME );
}
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CurrentTimestampFunction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CurrentTimestampFunction.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CurrentTimestampFunction.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -24,7 +24,7 @@
package org.hibernate.ejb.criteria.expression.function;
import java.sql.Timestamp;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
/**
* Models the ANSI SQL <tt>CURRENT_TIMESTAMP</tt> function.
@@ -34,7 +34,7 @@
public class CurrentTimestampFunction extends BasicFunctionExpression<Timestamp> {
public static final String NAME = "current_timestamp";
- public CurrentTimestampFunction(QueryBuilderImpl queryBuilder) {
- super( queryBuilder, Timestamp.class, NAME );
+ public CurrentTimestampFunction(CriteriaBuilderImpl criteriaBuilder) {
+ super( criteriaBuilder, Timestamp.class, NAME );
}
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LengthFunction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LengthFunction.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LengthFunction.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -24,7 +24,7 @@
package org.hibernate.ejb.criteria.expression.function;
import javax.persistence.criteria.Expression;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
/**
* Models the ANSI SQL <tt>LENGTH</tt> function.
@@ -34,7 +34,7 @@
public class LengthFunction extends ParameterizedFunctionExpression<Integer> {
public static final String NAME = "length";
- public LengthFunction(QueryBuilderImpl queryBuilder, Expression<String> value) {
- super( queryBuilder, Integer.class, NAME, value );
+ public LengthFunction(CriteriaBuilderImpl criteriaBuilder, Expression<String> value) {
+ super( criteriaBuilder, Integer.class, NAME, value );
}
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LocateFunction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LocateFunction.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LocateFunction.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -24,9 +24,9 @@
package org.hibernate.ejb.criteria.expression.function;
import javax.persistence.criteria.Expression;
-import org.hibernate.ejb.criteria.ParameterContainer;
+
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
/**
@@ -42,38 +42,38 @@
private final Expression<Integer> start;
public LocateFunction(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<String> pattern,
Expression<String> string,
Expression<Integer> start) {
- super( queryBuilder, Integer.class, NAME );
+ super( criteriaBuilder, Integer.class, NAME );
this.pattern = pattern;
this.string = string;
this.start = start;
}
public LocateFunction(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<String> pattern,
Expression<String> string) {
- this( queryBuilder, pattern, string, null );
+ this( criteriaBuilder, pattern, string, null );
}
- public LocateFunction(QueryBuilderImpl queryBuilder, String pattern, Expression<String> string) {
+ public LocateFunction(CriteriaBuilderImpl criteriaBuilder, String pattern, Expression<String> string) {
this(
- queryBuilder,
- new LiteralExpression<String>( queryBuilder, pattern ),
+ criteriaBuilder,
+ new LiteralExpression<String>( criteriaBuilder, pattern ),
string,
null
);
}
- public LocateFunction(QueryBuilderImpl queryBuilder, String pattern, Expression<String> string, int start) {
+ public LocateFunction(CriteriaBuilderImpl criteriaBuilder, String pattern, Expression<String> string, int start) {
this(
- queryBuilder,
- new LiteralExpression<String>( queryBuilder, pattern ),
+ criteriaBuilder,
+ new LiteralExpression<String>( criteriaBuilder, pattern ),
string,
- new LiteralExpression<Integer>( queryBuilder, start )
+ new LiteralExpression<Integer>( criteriaBuilder, start )
);
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LowerFunction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LowerFunction.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LowerFunction.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -24,7 +24,7 @@
package org.hibernate.ejb.criteria.expression.function;
import javax.persistence.criteria.Expression;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
/**
* Models the ANSI SQL <tt>LOWER</tt> function.
@@ -34,7 +34,7 @@
public class LowerFunction extends ParameterizedFunctionExpression<String> {
public static final String NAME = "lower";
- public LowerFunction(QueryBuilderImpl queryBuilder, Expression<String> string) {
- super( queryBuilder, String.class, NAME, string );
+ public LowerFunction(CriteriaBuilderImpl criteriaBuilder, Expression<String> string) {
+ super( criteriaBuilder, String.class, NAME, string );
}
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/ParameterizedFunctionExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/ParameterizedFunctionExpression.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/ParameterizedFunctionExpression.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -29,7 +29,7 @@
import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterContainer;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
/**
@@ -44,27 +44,27 @@
private final List<Expression<?>> argumentExpressions;
public ParameterizedFunctionExpression(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<X> javaType,
String functionName,
List<Expression<?>> argumentExpressions) {
- super( queryBuilder, javaType, functionName );
+ super( criteriaBuilder, javaType, functionName );
this.argumentExpressions = argumentExpressions;
}
public ParameterizedFunctionExpression(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Class<X> javaType,
String functionName,
Expression<?>... argumentExpressions) {
- super( queryBuilder, javaType, functionName );
+ super( criteriaBuilder, javaType, functionName );
this.argumentExpressions = Arrays.asList( argumentExpressions );
}
- protected static List<Expression<?>> wrapAsLiterals(QueryBuilderImpl queryBuilder, Object... literalArguments) {
+ protected static List<Expression<?>> wrapAsLiterals(CriteriaBuilderImpl criteriaBuilder, Object... literalArguments) {
List<Expression<?>> arguments = new ArrayList<Expression<?>>( properSize( literalArguments.length) );
for ( Object o : literalArguments ) {
- arguments.add( new LiteralExpression( queryBuilder, o ) );
+ arguments.add( new LiteralExpression( criteriaBuilder, o ) );
}
return arguments;
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SqrtFunction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SqrtFunction.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SqrtFunction.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -24,7 +24,7 @@
package org.hibernate.ejb.criteria.expression.function;
import javax.persistence.criteria.Expression;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
/**
* Models the ANSI SQL <tt>SQRT</tt> function.
@@ -34,7 +34,7 @@
public class SqrtFunction extends ParameterizedFunctionExpression<Double> {
public static final String NAME = "sqrt";
- public SqrtFunction(QueryBuilderImpl queryBuilder, Expression<? extends Number> expression) {
- super( queryBuilder, Double.class, NAME, expression );
+ public SqrtFunction(CriteriaBuilderImpl criteriaBuilder, Expression<? extends Number> expression) {
+ super( criteriaBuilder, Double.class, NAME, expression );
}
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SubstringFunction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SubstringFunction.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SubstringFunction.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -24,9 +24,9 @@
package org.hibernate.ejb.criteria.expression.function;
import javax.persistence.criteria.Expression;
-import org.hibernate.ejb.criteria.ParameterContainer;
+
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
/**
@@ -42,44 +42,44 @@
private final Expression<Integer> length;
public SubstringFunction(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<String> value,
Expression<Integer> start,
Expression<Integer> length) {
- super( queryBuilder, String.class, NAME );
+ super( criteriaBuilder, String.class, NAME );
this.value = value;
this.start = start;
this.length = length;
}
public SubstringFunction(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<String> value,
Expression<Integer> start) {
- this( queryBuilder, value, start, (Expression<Integer>)null );
+ this( criteriaBuilder, value, start, (Expression<Integer>)null );
}
public SubstringFunction(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<String> value,
int start) {
- this(
- queryBuilder,
+ this(
+ criteriaBuilder,
value,
- new LiteralExpression<Integer>( queryBuilder, start )
+ new LiteralExpression<Integer>( criteriaBuilder, start )
);
}
public SubstringFunction(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<String> value,
int start,
int length) {
this(
- queryBuilder,
+ criteriaBuilder,
value,
- new LiteralExpression<Integer>( queryBuilder, start ),
- new LiteralExpression<Integer>( queryBuilder, length )
+ new LiteralExpression<Integer>( criteriaBuilder, start ),
+ new LiteralExpression<Integer>( criteriaBuilder, length )
);
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/TrimFunction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/TrimFunction.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/TrimFunction.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -26,7 +26,7 @@
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.CriteriaBuilder.Trimspec;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
/**
@@ -44,52 +44,52 @@
private final Expression<String> trimSource;
public TrimFunction(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Trimspec trimspec,
Expression<Character> trimCharacter,
Expression<String> trimSource) {
- super( queryBuilder, String.class, NAME );
+ super( criteriaBuilder, String.class, NAME );
this.trimspec = trimspec;
this.trimCharacter = trimCharacter;
this.trimSource = trimSource;
}
public TrimFunction(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Trimspec trimspec,
char trimCharacter,
Expression<String> trimSource) {
- super( queryBuilder, String.class, NAME );
+ super( criteriaBuilder, String.class, NAME );
this.trimspec = trimspec;
- this.trimCharacter = new LiteralExpression<Character>( queryBuilder, trimCharacter );
+ this.trimCharacter = new LiteralExpression<Character>( criteriaBuilder, trimCharacter );
this.trimSource = trimSource;
}
public TrimFunction(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<String> trimSource) {
- this( queryBuilder, DEFAULT_TRIMSPEC, DEFAULT_TRIM_CHAR, trimSource );
+ this( criteriaBuilder, DEFAULT_TRIMSPEC, DEFAULT_TRIM_CHAR, trimSource );
}
public TrimFunction(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<Character> trimCharacter,
Expression<String> trimSource) {
- this( queryBuilder, DEFAULT_TRIMSPEC, trimCharacter, trimSource );
+ this( criteriaBuilder, DEFAULT_TRIMSPEC, trimCharacter, trimSource );
}
public TrimFunction(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
char trimCharacter,
Expression<String> trimSource) {
- this( queryBuilder, DEFAULT_TRIMSPEC, trimCharacter, trimSource );
+ this( criteriaBuilder, DEFAULT_TRIMSPEC, trimCharacter, trimSource );
}
public TrimFunction(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Trimspec trimspec,
Expression<String> trimSource) {
- this( queryBuilder, trimspec, DEFAULT_TRIM_CHAR, trimSource );
+ this( criteriaBuilder, trimspec, DEFAULT_TRIM_CHAR, trimSource );
}
public Expression<Character> getTrimCharacter() {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/UpperFunction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/UpperFunction.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/UpperFunction.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -24,7 +24,7 @@
package org.hibernate.ejb.criteria.expression.function;
import javax.persistence.criteria.Expression;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
/**
* Models the ANSI SQL <tt>UPPER</tt> function.
@@ -34,7 +34,7 @@
public class UpperFunction extends ParameterizedFunctionExpression<String> {
public static final String NAME = "upper";
- public UpperFunction(QueryBuilderImpl queryBuilder, Expression<String> string) {
- super( queryBuilder, String.class, NAME, string );
+ public UpperFunction(CriteriaBuilderImpl criteriaBuilder, Expression<String> string) {
+ super( criteriaBuilder, String.class, NAME, string );
}
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/AbstractPredicateImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/AbstractPredicateImpl.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/AbstractPredicateImpl.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -28,7 +28,7 @@
import javax.persistence.criteria.Selection;
import org.hibernate.ejb.criteria.expression.ExpressionImpl;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
/**
* Basic template support for {@link Predicate} implementors providing
@@ -39,8 +39,8 @@
public abstract class AbstractPredicateImpl extends ExpressionImpl<Boolean> implements Predicate {
private boolean negated;
- protected AbstractPredicateImpl(QueryBuilderImpl queryBuilder) {
- super( queryBuilder, Boolean.class );
+ protected AbstractPredicateImpl(CriteriaBuilderImpl criteriaBuilder) {
+ super( criteriaBuilder, Boolean.class );
}
public boolean isNegated() {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/AbstractSimplePredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/AbstractSimplePredicate.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/AbstractSimplePredicate.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -27,7 +27,7 @@
import java.util.Collections;
import javax.persistence.criteria.Expression;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
/**
* TODO : javadoc
@@ -37,8 +37,8 @@
public abstract class AbstractSimplePredicate extends AbstractPredicateImpl {
private static final List<Expression<Boolean>> NO_EXPRESSIONS = Collections.emptyList();
- public AbstractSimplePredicate(QueryBuilderImpl queryBuilder) {
- super( queryBuilder );
+ public AbstractSimplePredicate(CriteriaBuilderImpl criteriaBuilder) {
+ super( criteriaBuilder );
}
public BooleanOperator getOperator() {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BetweenPredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BetweenPredicate.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BetweenPredicate.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -25,9 +25,10 @@
import javax.persistence.criteria.Expression;
-import org.hibernate.ejb.criteria.ParameterContainer;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Models a <tt>BETWEEN</tt> {@link javax.persistence.criteria.Predicate}.
@@ -40,24 +41,24 @@
private final Expression<? extends Y> upperBound;
public BetweenPredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<? extends Y> expression,
Y lowerBound,
Y upperBound) {
this(
- queryBuilder,
+ criteriaBuilder,
expression,
- queryBuilder.literal( lowerBound ),
- queryBuilder.literal( upperBound )
+ criteriaBuilder.literal( lowerBound ),
+ criteriaBuilder.literal( upperBound )
);
}
public BetweenPredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<? extends Y> expression,
Expression<? extends Y> lowerBound,
Expression<? extends Y> upperBound) {
- super( queryBuilder );
+ super( criteriaBuilder );
this.expression = expression;
this.lowerBound = lowerBound;
this.upperBound = upperBound;
@@ -81,4 +82,15 @@
Helper.possibleParameter( getUpperBound(), registry );
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return ( (ExpressionImplementor) getExpression() ).render( renderingContext )
+ + " between "
+ + ( (ExpressionImplementor) getLowerBound() ).render( renderingContext )
+ + " and "
+ + ( (ExpressionImplementor) getUpperBound() ).render( renderingContext );
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BooleanExpressionPredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BooleanExpressionPredicate.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BooleanExpressionPredicate.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -27,7 +27,9 @@
import javax.persistence.criteria.Predicate;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Defines a {@link Predicate} used to wrap an {@link Expression Expression<Boolean>}.
@@ -37,8 +39,8 @@
public class BooleanExpressionPredicate extends AbstractSimplePredicate {
private final Expression<Boolean> expression;
- public BooleanExpressionPredicate(QueryBuilderImpl queryBuilder, Expression<Boolean> expression) {
- super( queryBuilder );
+ public BooleanExpressionPredicate(CriteriaBuilderImpl criteriaBuilder, Expression<Boolean> expression) {
+ super( criteriaBuilder );
this.expression = expression;
}
@@ -54,4 +56,12 @@
public void registerParameters(ParameterRegistry registry) {
Helper.possibleParameter(expression, registry);
}
+
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return ( ( ExpressionImplementor) getExpression() ).render( renderingContext );
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ComparisonPredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ComparisonPredicate.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ComparisonPredicate.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -26,9 +26,11 @@
import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.expression.BinaryOperatorExpression;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
+import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Models a basic relational comparison predicate.
@@ -41,25 +43,26 @@
private final Expression<?> rightHandSide;
public ComparisonPredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
ComparisonOperator comparisonOperator,
Expression<?> leftHandSide,
Expression<?> rightHandSide) {
- super( queryBuilder );
+ super( criteriaBuilder );
this.comparisonOperator = comparisonOperator;
this.leftHandSide = leftHandSide;
this.rightHandSide = rightHandSide;
}
+ @SuppressWarnings({ "unchecked" })
public ComparisonPredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
ComparisonOperator comparisonOperator,
Expression<?> leftHandSide,
Object rightHandSide) {
- super( queryBuilder );
+ super( criteriaBuilder );
this.comparisonOperator = comparisonOperator;
this.leftHandSide = leftHandSide;
- this.rightHandSide = new LiteralExpression( queryBuilder, rightHandSide );
+ this.rightHandSide = new LiteralExpression( criteriaBuilder, rightHandSide );
}
public ComparisonOperator getComparisonOperator() {
@@ -88,33 +91,63 @@
public ComparisonOperator negated() {
return NOT_EQUAL;
}
+ public String rendered() {
+ return "=";
+ }
},
NOT_EQUAL {
public ComparisonOperator negated() {
return EQUAL;
}
+ public String rendered() {
+ return "<>";
+ }
},
LESS_THAN {
public ComparisonOperator negated() {
return GREATER_THAN_OR_EQUAL;
}
+ public String rendered() {
+ return "<";
+ }
},
LESS_THAN_OR_EQUAL {
public ComparisonOperator negated() {
return GREATER_THAN;
}
+ public String rendered() {
+ return "<=";
+ }
},
GREATER_THAN {
public ComparisonOperator negated() {
return LESS_THAN_OR_EQUAL;
}
+ public String rendered() {
+ return ">";
+ }
},
GREATER_THAN_OR_EQUAL {
public ComparisonOperator negated() {
return LESS_THAN;
}
+ public String rendered() {
+ return ">=";
+ }
};
public abstract ComparisonOperator negated();
+
+ public abstract String rendered();
}
+
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return ( ( ExpressionImplementor) getLeftHandOperand() ).render( renderingContext )
+ + getComparisonOperator().rendered()
+ + ( ( ExpressionImplementor) getRightHandOperand() ).render( renderingContext );
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -29,9 +29,10 @@
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Expression;
-import org.hibernate.ejb.criteria.ParameterContainer;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* A compound {@link Predicate predicate} is a grouping of other {@link Predicate predicates} in order to apply
@@ -46,44 +47,44 @@
/**
* Constructs an empty conjunction or disjunction.
*
- * @param queryBuilder The query builder from whcih this originates.
+ * @param criteriaBuilder The query builder from whcih this originates.
* @param operator Indicates whether this predicate will funtion
* as a conjunction or disjuntion.
*/
- public CompoundPredicate(QueryBuilderImpl queryBuilder, BooleanOperator operator) {
- super( queryBuilder );
+ public CompoundPredicate(CriteriaBuilderImpl criteriaBuilder, BooleanOperator operator) {
+ super( criteriaBuilder );
this.operator = operator;
}
/**
* Constructs a conjunction or disjunction over the given expressions.
*
- * @param queryBuilder The query builder from which this originates.
+ * @param criteriaBuilder The query builder from which this originates.
* @param operator Indicates whether this predicate will funtion
* as a conjunction or disjuntion.
* @param expressions The expressions to be grouped.
*/
public CompoundPredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
BooleanOperator operator,
Expression<Boolean>... expressions) {
- this( queryBuilder, operator );
+ this( criteriaBuilder, operator );
applyExpressions( expressions );
}
/**
* Constructs a conjunction or disjunction over the given expressions.
*
- * @param queryBuilder The query builder from whcih this originates.
+ * @param criteriaBuilder The query builder from whcih this originates.
* @param operator Indicates whether this predicate will funtion
* as a conjunction or disjuntion.
* @param expressions The expressions to be grouped.
*/
public CompoundPredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
BooleanOperator operator,
List<Expression<Boolean>> expressions) {
- this( queryBuilder, operator );
+ this( criteriaBuilder, operator );
applyExpressions( expressions );
}
@@ -110,4 +111,29 @@
}
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ if ( getExpressions().size() == 1 ) {
+ return ( (ExpressionImplementor) getExpressions().get(0) ).render( renderingContext );
+ }
+ final StringBuilder buffer = new StringBuilder();
+ String sep = "";
+ for ( Expression expression : getExpressions() ) {
+ buffer.append( sep )
+ .append( "( " )
+ .append( ( (ExpressionImplementor) expression ).render( renderingContext ) )
+ .append( " )" );
+ sep = operatorTextWithSeparator();
+ }
+ return buffer.toString();
+ }
+
+ private String operatorTextWithSeparator() {
+ return getOperator() == BooleanOperator.AND
+ ? " and "
+ : " or ";
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExistsPredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExistsPredicate.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExistsPredicate.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -25,7 +25,9 @@
import javax.persistence.criteria.Subquery;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Models an <tt>EXISTS(<subquery>)</tt> predicate
@@ -35,8 +37,8 @@
public class ExistsPredicate extends AbstractSimplePredicate {
private final Subquery<?> subquery;
- public ExistsPredicate(QueryBuilderImpl queryBuilder, Subquery<?> subquery) {
- super(queryBuilder);
+ public ExistsPredicate(CriteriaBuilderImpl criteriaBuilder, Subquery<?> subquery) {
+ super( criteriaBuilder );
this.subquery = subquery;
}
@@ -48,4 +50,12 @@
// nothing to do here
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return ( isNegated() ? "not " : "" ) + "exists "
+ + ( ( ExpressionImplementor ) getSubquery() ).render( renderingContext );
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExplicitTruthValueCheck.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExplicitTruthValueCheck.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExplicitTruthValueCheck.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -26,7 +26,9 @@
import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* ANSI-SQL defines <tt>TRUE</tt>, <tt>FALSE</tt> and <tt>UNKNOWN</tt> as <i>truth values</i>. These
@@ -43,8 +45,8 @@
private final Expression<Boolean> booleanExpression;
private final TruthValue truthValue;
- public ExplicitTruthValueCheck(QueryBuilderImpl queryBuilder, Expression<Boolean> booleanExpression, TruthValue truthValue) {
- super( queryBuilder );
+ public ExplicitTruthValueCheck(CriteriaBuilderImpl criteriaBuilder, Expression<Boolean> booleanExpression, TruthValue truthValue) {
+ super( criteriaBuilder );
this.booleanExpression = booleanExpression;
this.truthValue = truthValue;
}
@@ -60,5 +62,15 @@
public void registerParameters(ParameterRegistry registry) {
Helper.possibleParameter( getBooleanExpression(), registry );
}
+
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return ( (ExpressionImplementor) getBooleanExpression() ).render( renderingContext )
+ + " = "
+ + ( getTruthValue() == TruthValue.TRUE ? "true" : "false" );
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/InPredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/InPredicate.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/InPredicate.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -28,58 +28,61 @@
import java.util.Arrays;
import java.util.Collection;
import javax.persistence.criteria.Expression;
+import javax.persistence.criteria.Subquery;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
+import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* TODO : javadoc
*
* @author Steve Ebersole
*/
-public class InPredicate<T> extends AbstractSimplePredicate implements QueryBuilderImpl.In<T> {
+public class InPredicate<T> extends AbstractSimplePredicate implements CriteriaBuilderImpl.In<T> {
private final Expression<? extends T> expression;
private final List<Expression<? extends T>> values;
/**
* Constructs an <tt>IN</tt> predicate against a given expression with an empty list of values.
*
- * @param queryBuilder The query builder from which this originates.
+ * @param criteriaBuilder The query builder from which this originates.
* @param expression The expression.
*/
public InPredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<? extends T> expression) {
- this( queryBuilder, expression, new ArrayList<Expression<? extends T>>() );
+ this( criteriaBuilder, expression, new ArrayList<Expression<? extends T>>() );
}
/**
* Constructs an <tt>IN</tt> predicate against a given expression with the given list of expression values.
*
- * @param queryBuilder The query builder from which this originates.
+ * @param criteriaBuilder The query builder from which this originates.
* @param expression The expression.
* @param values The value list.
*/
public InPredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<? extends T> expression,
Expression<? extends T>... values) {
- this( queryBuilder, expression, Arrays.asList( values ) );
+ this( criteriaBuilder, expression, Arrays.asList( values ) );
}
/**
* Constructs an <tt>IN</tt> predicate against a given expression with the given list of expression values.
*
- * @param queryBuilder The query builder from which this originates.
+ * @param criteriaBuilder The query builder from which this originates.
* @param expression The expression.
* @param values The value list.
*/
public InPredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<? extends T> expression,
List<Expression<? extends T>> values) {
- super( queryBuilder );
+ super( criteriaBuilder );
this.expression = expression;
this.values = values;
}
@@ -87,34 +90,34 @@
/**
* Constructs an <tt>IN</tt> predicate against a given expression with the given given literal value list.
*
- * @param queryBuilder The query builder from which this originates.
+ * @param criteriaBuilder The query builder from which this originates.
* @param expression The expression.
* @param values The value list.
*/
public InPredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<? extends T> expression,
T... values) {
- this( queryBuilder, expression, Arrays.asList( values ) );
+ this( criteriaBuilder, expression, Arrays.asList( values ) );
}
/**
* Constructs an <tt>IN</tt> predicate against a given expression with the given literal value list.
*
- * @param queryBuilder The query builder from which this originates.
+ * @param criteriaBuilder The query builder from which this originates.
* @param expression The expression.
* @param values The value list.
*/
public InPredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<? extends T> expression,
Collection<T> values) {
- super( queryBuilder );
+ super( criteriaBuilder );
this.expression = expression;
// TODO : size this?
this.values = new ArrayList<Expression<? extends T>>();
for ( T value : values ) {
- this.values.add( new LiteralExpression<T>( queryBuilder, value ) );
+ this.values.add( new LiteralExpression<T>( criteriaBuilder, value ) );
}
}
@@ -146,4 +149,31 @@
Helper.possibleParameter(value, registry);
}
}
+
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ StringBuilder buffer = new StringBuilder( "in" );
+
+ // subquery expressions are already wrapped in parenthesis, so we only
+ // need to render the parens here if the values represent an explicit value list
+ boolean isInSubqueryPredicate = getValues().size() == 1
+ && Subquery.class.isInstance( getValues().get( 0 ) );
+ if ( isInSubqueryPredicate ) {
+ buffer.append( ( (ExpressionImplementor) getValues().get(0) ).render( renderingContext ) );
+ }
+ else {
+ buffer.append( '(' );
+ String sep = "";
+ for ( Expression value : getValues() ) {
+ buffer.append( sep )
+ .append( ( (ExpressionImplementor) value ).render( renderingContext ) );
+ sep = ", ";
+ }
+ buffer.append( ')' );
+ }
+ return buffer.toString();
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/IsEmptyPredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/IsEmptyPredicate.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/IsEmptyPredicate.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -25,7 +25,8 @@
import java.util.Collection;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.expression.CollectionExpression;
import org.hibernate.ejb.criteria.expression.UnaryOperatorExpression;
@@ -41,9 +42,9 @@
private final CollectionExpression<C> collectionExpression;
public IsEmptyPredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
CollectionExpression<C> collectionExpression) {
- super(queryBuilder);
+ super( criteriaBuilder );
this.collectionExpression = collectionExpression;
}
@@ -55,4 +56,11 @@
// nothing to do
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return getOperand().render( renderingContext ) + " is empty";
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/LikePredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/LikePredicate.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/LikePredicate.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -25,11 +25,13 @@
import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
+import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
- * TODO : javadoc
+ * Models a SQL <tt>LIKE</tt> expression.
*
* @author Steve Ebersole
*/
@@ -39,65 +41,65 @@
private final Expression<Character> escapeCharacter;
public LikePredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<String> matchExpression,
Expression<String> pattern) {
- this( queryBuilder, matchExpression, pattern, null );
+ this( criteriaBuilder, matchExpression, pattern, null );
}
public LikePredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<String> matchExpression,
String pattern) {
- this( queryBuilder, matchExpression, new LiteralExpression<String>( queryBuilder, pattern) );
+ this( criteriaBuilder, matchExpression, new LiteralExpression<String>( criteriaBuilder, pattern) );
}
public LikePredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<String> matchExpression,
Expression<String> pattern,
Expression<Character> escapeCharacter) {
- super( queryBuilder );
+ super( criteriaBuilder );
this.matchExpression = matchExpression;
this.pattern = pattern;
this.escapeCharacter = escapeCharacter;
}
public LikePredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<String> matchExpression,
Expression<String> pattern,
char escapeCharacter) {
this(
- queryBuilder,
+ criteriaBuilder,
matchExpression,
pattern,
- new LiteralExpression<Character>( queryBuilder, escapeCharacter )
+ new LiteralExpression<Character>( criteriaBuilder, escapeCharacter )
);
}
public LikePredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<String> matchExpression,
String pattern,
char escapeCharacter) {
this(
- queryBuilder,
+ criteriaBuilder,
matchExpression,
- new LiteralExpression<String>( queryBuilder, pattern ),
- new LiteralExpression<Character>( queryBuilder, escapeCharacter )
+ new LiteralExpression<String>( criteriaBuilder, pattern ),
+ new LiteralExpression<Character>( criteriaBuilder, escapeCharacter )
);
}
public LikePredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<String> matchExpression,
String pattern,
Expression<Character> escapeCharacter) {
this(
- queryBuilder,
+ criteriaBuilder,
matchExpression,
- new LiteralExpression<String>( queryBuilder, pattern ),
+ new LiteralExpression<String>( criteriaBuilder, pattern ),
escapeCharacter
);
}
@@ -120,5 +122,19 @@
Helper.possibleParameter( getPattern(), registry );
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ StringBuilder likeExpr = new StringBuilder();
+ likeExpr.append( ( (ExpressionImplementor) getMatchExpression() ).render( renderingContext ) )
+ .append( " like " )
+ .append( ( (ExpressionImplementor) getPattern() ).render( renderingContext ) );
+ if ( escapeCharacter != null ) {
+ likeExpr.append( " escape " )
+ .append( ( (ExpressionImplementor) getEscapeCharacter() ).render( renderingContext ) );
+ }
+ return likeExpr.toString();
+ }
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/MemberOfPredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/MemberOfPredicate.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/MemberOfPredicate.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -26,7 +26,8 @@
import java.util.Collection;
import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.expression.CollectionExpression;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
@@ -42,21 +43,21 @@
private final CollectionExpression<C> collectionExpression;
public MemberOfPredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
Expression<E> elementExpression,
CollectionExpression<C> collectionExpression) {
- super(queryBuilder);
+ super( criteriaBuilder );
this.elementExpression = elementExpression;
this.collectionExpression = collectionExpression;
}
public MemberOfPredicate(
- QueryBuilderImpl queryBuilder,
+ CriteriaBuilderImpl criteriaBuilder,
E element,
CollectionExpression<C> collectionExpression) {
this(
- queryBuilder,
- new LiteralExpression<E>( queryBuilder, element ),
+ criteriaBuilder,
+ new LiteralExpression<E>( criteriaBuilder, element ),
collectionExpression
);
}
@@ -74,4 +75,12 @@
Helper.possibleParameter( getElementExpression(), registry );
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return ( isNegated() ? "not " : "" ) + "member of "
+ + collectionExpression.render( renderingContext );
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/NullnessPredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/NullnessPredicate.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/NullnessPredicate.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -26,15 +26,17 @@
import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.expression.UnaryOperatorExpression;
+import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Defines a {@link javax.persistence.criteria.Predicate} for checking the
* nullness state of an expression, aka an <tt>IS (NOT?) NULL</tt> predicate.
* <p/>
* The <tt>NOT NULL</tt> form can be built by calling the constructor and then
- * calling {@link #negate}.
+ * calling {@link #not}.
*
* @author Steve Ebersole
*/
@@ -43,14 +45,14 @@
/**
* Constructs the affirmitive form of nullness checking (<i>IS NULL</i>). To
- * construct the negative form (<i>IS NOT NULL</i>) call {@link #negate} on the
+ * construct the negative form (<i>IS NOT NULL</i>) call {@link #not} on the
* constructed instance.
*
- * @param queryBuilder The query builder from whcih this originates.
- * @param expression The expression to check.
+ * @param criteriaBuilder The query builder from whcih this originates.
+ * @param operand The expression to check.
*/
- public NullnessPredicate(QueryBuilderImpl queryBuilder, Expression<?> operand) {
- super( queryBuilder );
+ public NullnessPredicate(CriteriaBuilderImpl criteriaBuilder, Expression<?> operand) {
+ super( criteriaBuilder );
this.operand = operand;
}
@@ -61,4 +63,18 @@
public void registerParameters(ParameterRegistry registry) {
Helper.possibleParameter( getOperand(), registry );
}
+
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return ( (ExpressionImplementor) operand ).render( renderingContext ) + check();
+ }
+
+ private String check() {
+ return isNegated()
+ ? " is not null"
+ : " is null";
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/BasicCriteriaUsageTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/BasicCriteriaUsageTest.java 2009-10-23 17:07:50 UTC (rev 17829)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/BasicCriteriaUsageTest.java 2009-10-24 21:37:27 UTC (rev 17830)
@@ -41,19 +41,10 @@
return new Class[] { Wall.class };
}
- public void testSimplestCriterias() {
- EntityManager em = getOrCreateEntityManager();
- em.getTransaction().begin();
- CriteriaQuery criteria = em.getCriteriaBuilder().createQuery();
- criteria.from( Wall.class );
- em.getTransaction().commit();
- em.close();
- }
-
public void testParameterCollection() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
- CriteriaQuery criteria = em.getCriteriaBuilder().createQuery();
+ CriteriaQuery<Wall> criteria = em.getCriteriaBuilder().createQuery( Wall.class );
Root<Wall> from = criteria.from( Wall.class );
ParameterExpression param = em.getCriteriaBuilder().parameter( String.class );
SingularAttribute<? super Wall,?> colorAttribute = em.getMetamodel()
@@ -66,4 +57,14 @@
em.getTransaction().commit();
em.close();
}
+
+ public void testTrivialCompilation() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Wall> criteria = em.getCriteriaBuilder().createQuery( Wall.class );
+ criteria.from( Wall.class );
+ em.createQuery( criteria ).getResultList();
+ em.getTransaction().commit();
+ em.close();
+ }
}
14 years, 6 months
Contract of Settlements
by LSM Company
Greetings,
We have prepared a contract and added the paragraphs that you wanted to see in it.
Our lawyers made alterations on the last page. If you agree all the provisions we are ready to make the payment on Friday for the first consignment,
We are enclosing the file with prepared contract. Password: 345543
If necessary, we can send it by fax.
Looking forward to your dicision.
14 years, 6 months
Contract of Settlements
by LSM Company
Greetings,
We have prepared a contract and added the paragraphs that you wanted to see in it.
Our lawyers made alterations on the last page. If you agree all the provisions we are ready to make the payment on Friday for the first consignment,
We are enclosing the file with prepared contract. Password: 345543
If necessary, we can send it by fax.
Looking forward to your dicision.
14 years, 6 months
Hibernate SVN: r17829 - core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity.
by hibernate-commits@lists.jboss.org
Author: sharathjreddy
Date: 2009-10-23 13:07:50 -0400 (Fri, 23 Oct 2009)
New Revision: 17829
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Narrative.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Topic.java
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java
Log:
HHH-4288 Filters on collections are ignored
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java 2009-10-23 16:51:24 UTC (rev 17828)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java 2009-10-23 17:07:50 UTC (rev 17829)
@@ -276,7 +276,41 @@
tx.commit();
s.close();
}
+
+
+ public void testFilterOnCollection() {
+
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+
+ Topic topic = new Topic();
+ Narrative n1 = new Narrative();
+ n1.setState("published");
+ topic.addNarrative(n1);
+
+ Narrative n2 = new Narrative();
+ n2.setState("draft");
+ topic.addNarrative(n2);
+
+ s.persist(topic);
+ tx.commit();
+ s.close();
+ s = openSession();
+ tx = s.beginTransaction();
+ topic = (Topic) s.load( Topic.class, topic.getId() );
+
+ s.enableFilter("byState").setParameter("state", "published");
+ topic = (Topic) s.load( Topic.class, topic.getId() );
+ assertNotNull(topic);
+ assertTrue(topic.getNarratives().size() == 1);
+ assertEquals("published", topic.getNarratives().iterator().next().getState());
+ tx.commit();
+ s.close();
+
+ }
+
+
public void testFilter() throws Exception {
Session s;
Transaction tx;
@@ -496,7 +530,9 @@
FormalLastName.class,
Car.class,
Peugot.class,
- ContactDetails.class
+ ContactDetails.class,
+ Topic.class,
+ Narrative.class
};
}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Narrative.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Narrative.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Narrative.java 2009-10-23 17:07:50 UTC (rev 17829)
@@ -0,0 +1,66 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat, Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.test.annotations.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+/**
+ * @author Sharath Reddy
+ */
+@Entity
+public class Narrative {
+
+ private int id;
+ private String state;
+ private Topic topic;
+
+ @Id @GeneratedValue
+ public int getId() {
+ return id;
+ }
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ @Column(name="state")
+ public String getState() {
+ return state;
+ }
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ @ManyToOne
+ public Topic getTopic() {
+ return topic;
+ }
+ public void setTopic(Topic topic) {
+ this.topic = topic;
+ }
+}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Topic.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Topic.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Topic.java 2009-10-23 17:07:50 UTC (rev 17829)
@@ -0,0 +1,72 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat, Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.test.annotations.entity;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+import org.hibernate.annotations.Filter;
+import org.hibernate.annotations.FilterDef;
+import org.hibernate.annotations.ParamDef;
+
+/**
+ * @author Sharath Reddy
+ */
+@FilterDef(name="byState", defaultCondition=":state = state",
+ parameters=@ParamDef(name="state",type="string"))
+@Entity
+public class Topic {
+
+ @Id @GeneratedValue
+ private int id;
+ @OneToMany(mappedBy="topic", cascade=CascadeType.ALL)
+ @Filter(name="byState", condition=":state = state")
+ private Set<Narrative> narratives = new HashSet<Narrative>();
+
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public Set<Narrative> getNarratives() {
+ return narratives;
+ }
+
+ public void addNarrative(Narrative val) {
+ narratives.add(val);
+ val.setTopic(this);
+ }
+
+}
14 years, 6 months