Hibernate SVN: r17254 - in core/trunk/entitymanager/src/main/java/org/hibernate/ejb: metamodel and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-08-09 14:04:35 -0400 (Sun, 09 Aug 2009)
New Revision: 17254
Added:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/BasicTypeImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EmbeddableTypeImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeDelegator.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/ManagedTypeImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelFactory.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
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java
Log:
EJB-456 have the implementation of Metamodel ready minus some concepts left behind. This has NOT been tested to don't be too excited ladies
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java 2009-08-09 12:54:15 UTC (rev 17253)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java 2009-08-09 18:04:35 UTC (rev 17254)
@@ -712,7 +712,8 @@
cfg.buildSessionFactory(),
transactionType,
discardOnClose,
- getSessionInterceptorClass( cfg.getProperties() )
+ getSessionInterceptorClass( cfg.getProperties() ),
+ cfg
);
}
catch (HibernateException e) {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java 2009-08-09 12:54:15 UTC (rev 17253)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java 2009-08-09 18:04:35 UTC (rev 17254)
@@ -3,6 +3,7 @@
import java.util.Map;
import java.util.Set;
+import java.util.Iterator;
import java.io.Serializable;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContextType;
@@ -12,28 +13,36 @@
import javax.persistence.spi.PersistenceUnitTransactionType;
import org.hibernate.SessionFactory;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.cfg.Configuration;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.metamodel.MetamodelImpl;
/**
* @author Gavin King
* @author Emmanuel Bernard
*/
public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
- private SessionFactory sessionFactory;
- private PersistenceUnitTransactionType transactionType;
- private boolean discardOnClose;
- private Class sessionInterceptorClass;
- private QueryBuilderImpl criteriaQueryBuilder;
+ private final SessionFactory sessionFactory;
+ private final PersistenceUnitTransactionType transactionType;
+ private final boolean discardOnClose;
+ private final Class sessionInterceptorClass;
+ private final QueryBuilderImpl criteriaQueryBuilder;
+ private final Metamodel metamodel;
public EntityManagerFactoryImpl(
SessionFactory sessionFactory,
PersistenceUnitTransactionType transactionType,
boolean discardOnClose,
- Class sessionInterceptorClass) {
+ Class<?> sessionInterceptorClass,
+ Configuration cfg) {
this.sessionFactory = sessionFactory;
this.transactionType = transactionType;
this.discardOnClose = discardOnClose;
this.sessionInterceptorClass = sessionInterceptorClass;
+ @SuppressWarnings( "unchecked" )
+ final Iterator<PersistentClass> classes = cfg.getClassMappings();
+ this.metamodel = new MetamodelImpl( classes );
this.criteriaQueryBuilder = new QueryBuilderImpl( this );
}
@@ -54,8 +63,7 @@
}
public Metamodel getMetamodel() {
- //FIXME
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return metamodel; //To change body of implemented methods use File | Settings | File Templates.
}
public void close() {
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/BasicTypeImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/BasicTypeImpl.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/BasicTypeImpl.java 2009-08-09 18:04:35 UTC (rev 17254)
@@ -0,0 +1,26 @@
+package org.hibernate.ejb.metamodel;
+
+import java.io.Serializable;
+import javax.persistence.metamodel.BasicType;
+import javax.persistence.metamodel.Type;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class BasicTypeImpl<X> implements BasicType<X>, Serializable {
+ private final Class<X> clazz;
+ private PersistenceType persistenceType;
+
+ public PersistenceType getPersistenceType() {
+ return persistenceType;
+ }
+
+ public Class<X> getJavaType() {
+ return clazz;
+ }
+
+ public BasicTypeImpl(Class<X> clazz, PersistenceType persistenceType) {
+ this.clazz = clazz;
+ this.persistenceType = persistenceType;
+ }
+}
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EmbeddableTypeImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EmbeddableTypeImpl.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EmbeddableTypeImpl.java 2009-08-09 18:04:35 UTC (rev 17254)
@@ -0,0 +1,21 @@
+package org.hibernate.ejb.metamodel;
+
+import java.util.Iterator;
+import java.io.Serializable;
+import javax.persistence.metamodel.EmbeddableType;
+import javax.persistence.metamodel.Type;
+
+import org.hibernate.mapping.Property;
+
+/**
+ * @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 PersistenceType getPersistenceType() {
+ return PersistenceType.EMBEDDABLE;
+ }
+}
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeDelegator.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeDelegator.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeDelegator.java 2009-08-09 18:04:35 UTC (rev 17254)
@@ -0,0 +1,196 @@
+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, ?, ?>> getCollections() {
+ return delegate.getCollections();
+ }
+
+ public Set<PluralAttribute<X, ?, ?>> getDeclaredCollections() {
+ return delegate.getDeclaredCollections();
+ }
+
+ 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();
+ }
+}
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java 2009-08-09 18:04:35 UTC (rev 17254)
@@ -0,0 +1,164 @@
+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;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class EntityTypeImpl<X> extends ManagedTypeImpl<X> implements EntityType<X>, Serializable {
+
+ private final SingularAttribute<X, ?> id;
+ private final SingularAttribute<X, ?> version;
+ 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;
+ }
+ }
+
+ private <A> SingularAttribute<X, A> buildIdAttribute(PersistentClass persistentClass) {
+ 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();
+ }
+
+ 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 )
+ );
+ }
+ 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
+ @SuppressWarnings( "unchecked")
+ final SingularAttribute<? super X, Y> result = ( SingularAttribute<? super X, Y> ) id;
+ return result;
+ }
+
+ 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) {
+ //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() {
+ return id.getType();
+ }
+
+ public BindableType getBindableType() {
+ return BindableType.ENTITY_TYPE;
+ }
+
+ public Class<X> getBindableJavaType() {
+ return getJavaType();
+ }
+
+ public PersistenceType getPersistenceType() {
+ return PersistenceType.ENTITY;
+ }
+}
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/ManagedTypeImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/ManagedTypeImpl.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/ManagedTypeImpl.java 2009-08-09 18:04:35 UTC (rev 17254)
@@ -0,0 +1,284 @@
+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 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> {
+ 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.LIST );
+ @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, ?, ?>> getCollections() {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Set<PluralAttribute<X, ?, ?>> getDeclaredCollections() {
+ 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;
+ }
+}
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java 2009-08-09 18:04:35 UTC (rev 17254)
@@ -0,0 +1,42 @@
+package org.hibernate.ejb.metamodel;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.persistence.metamodel.Metamodel;
+import javax.persistence.metamodel.EmbeddableType;
+
+/**
+ * Keep contextual information related tot he metedata building process.
+ * In particular keeps data than theens to be processed in a second phase.
+ * @author Emmanuel Bernard
+ */
+class MetadataContext {
+ private Map<EntityTypeDelegator<?>, Class<?>> delegators = new HashMap<EntityTypeDelegator<?>, Class<?>>();
+ private Map<Class<?>, EmbeddableType<?>> embeddables = new HashMap<Class<?>, EmbeddableType<?>>();
+
+ void addDelegator(EntityTypeDelegator<?> type, Class<?> clazz) {
+ delegators.put(type, clazz);
+ }
+
+ void postProcess(Metamodel model) {
+ for ( Map.Entry<EntityTypeDelegator<?>, Class<?>> entry : delegators.entrySet() ) {
+ setDelegate( model, entry );
+ }
+ }
+
+ 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 ) );
+ }
+
+ <X> void addEmbeddableType(Class<X> clazz, EmbeddableType<X> embeddableType) {
+ embeddables.put( clazz, embeddableType );
+ }
+
+ Map<Class<?>, EmbeddableType<?>> getEmbeddableTypes() {
+ return embeddables;
+ }
+}
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelFactory.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelFactory.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelFactory.java 2009-08-09 18:04:35 UTC (rev 17254)
@@ -0,0 +1,323 @@
+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) {
+ 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 );
+ attribute = SingularAttributeImpl.create( ownerType, attrType )
+ // .member( ); //TODO member
+ .property( property )
+ .persistentAttributeType( attrContext.getElementAttributeType() )
+ .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;
+ }
+}
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelImpl.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelImpl.java 2009-08-09 18:04:35 UTC (rev 17254)
@@ -0,0 +1,81 @@
+package org.hibernate.ejb.metamodel;
+
+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;
+import javax.persistence.metamodel.EntityType;
+import javax.persistence.metamodel.ManagedType;
+import javax.persistence.metamodel.EmbeddableType;
+
+import org.hibernate.mapping.PersistentClass;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class MetamodelImpl implements Metamodel, Serializable {
+
+ private final Map<Class<?>,EntityType<?>> entities;
+ private Map<Class<?>, EmbeddableType<?>> embeddables;
+
+ public MetamodelImpl(Iterator<PersistentClass> classes) {
+ Map<Class<?>,EntityType<?>> localEntities = new HashMap<Class<?>,EntityType<?>>();
+ MetadataContext context = new MetadataContext();
+ while ( classes.hasNext() ) {
+ buildEntityType( classes, localEntities, context );
+ }
+ this.entities = Collections.unmodifiableMap( localEntities );
+ this.embeddables = Collections.unmodifiableMap( context.getEmbeddableTypes() );
+ context.postProcess( this );
+ }
+
+ 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) );
+ }
+ }
+
+ public <X> EntityType<X> entity(Class<X> cls) {
+ final EntityType<?> entityType = entities.get( cls );
+ if ( entityType == null ) throw new IllegalArgumentException( "Not an entity: " + cls );
+ //unsafe casting is our map inserts guarantee them
+ return (EntityType<X>) entityType;
+ }
+
+ public <X> ManagedType<X> type(Class<X> cls) {
+ ManagedType<?> type = null;
+ type = entities.get( cls );
+ if ( type == null ) throw new IllegalArgumentException( "Not an managed type: " + cls );
+ //unsafe casting is our map inserts guarantee them
+ return (ManagedType<X>) type;
+ }
+
+ public <X> EmbeddableType<X> embeddable(Class<X> cls) {
+ final EmbeddableType<?> embeddableType = embeddables.get( cls );
+ if ( embeddableType == null ) throw new IllegalArgumentException( "Not an entity: " + cls );
+ //unsafe casting is our map inserts guarantee them
+ return (EmbeddableType<X>) embeddableType;
+ }
+
+ public Set<ManagedType<?>> getManagedTypes() {
+ final Set<ManagedType<?>> managedTypes = new HashSet<ManagedType<?>>( entities.size() + embeddables.size() );
+ managedTypes.addAll( entities.values() );
+ managedTypes.addAll( embeddables.values() );
+ return managedTypes;
+ }
+
+ public Set<EntityType<?>> getEntities() {
+ return new HashSet<EntityType<?>>(entities.values());
+ }
+
+ public Set<EmbeddableType<?>> getEmbeddables() {
+ return new HashSet<EmbeddableType<?>>(embeddables.values());
+ }
+}
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/PluralAttributeImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/PluralAttributeImpl.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/PluralAttributeImpl.java 2009-08-09 18:04:35 UTC (rev 17254)
@@ -0,0 +1,214 @@
+package org.hibernate.ejb.metamodel;
+
+import java.lang.reflect.Member;
+import java.util.Map;
+import java.util.List;
+import java.util.Set;
+import java.util.Collection;
+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 org.hibernate.mapping.Property;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public abstract class PluralAttributeImpl<X, C, E> implements PluralAttribute<X, C, E> {
+
+ 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;
+ 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 Member member;
+ private PersistentAttributeType persistentAttributeType;
+ private Property property;
+ private Class<C> collectionClass;
+ private Type<K> keyType;
+
+
+ private Builder(ManagedType<X> ownerType, Type<E> attrType, Class<C> collectionClass, Type<K> keyType) {
+ this.type = ownerType;
+ this.attributeType = attrType;
+ this.collectionClass = collectionClass;
+ this.keyType = keyType;
+ }
+
+ public Builder<X,C,E,K> member(Member member) {
+ this.member = member;
+ return this;
+ }
+
+ public Builder<X,C,E,K> property(Property property) {
+ this.property = property;
+ return this;
+ }
+
+ public Builder<X,C,E,K> persistentAttributeType(PersistentAttributeType attrType) {
+ this.persistentAttributeType = attrType;
+ return this;
+ }
+
+ 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>(
+ 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>(
+ 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>(
+ 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>(
+ builder
+ );
+ return result;
+ }
+ throw new UnsupportedOperationException( "Unkown collection: " + collectionClass );
+ }
+ }
+
+ public static <X,C,E,K> Builder<X,C,E,K> create(
+ ManagedType<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();
+
+ public Type<E> getElementType() {
+ return elementType;
+ }
+
+
+ public Member getJavaMember() {
+ return member;
+ }
+
+ public boolean isAssociation() {
+ return true;
+ }
+
+ public boolean isCollection() {
+ return true;
+ }
+
+ public BindableType getBindableType() {
+ return BindableType.PLURAL_ATTRIBUTE;
+ }
+
+ public Class<E> getBindableJavaType() {
+ return elementType.getJavaType();
+ }
+
+ static class SetAttributeImpl<X,E> extends PluralAttributeImpl<X,Set<E>,E> implements SetAttribute<X,E> {
+ SetAttributeImpl(Builder<X,Set<E>,E,?> xceBuilder) {
+ super( xceBuilder );
+ }
+
+ public CollectionType getCollectionType() {
+ return CollectionType.SET;
+ }
+ }
+
+ static class CollectionAttributeImpl<X,E> extends PluralAttributeImpl<X,Collection<E>,E> implements CollectionAttribute<X,E> {
+ CollectionAttributeImpl(Builder<X, Collection<E>,E,?> xceBuilder) {
+ super( xceBuilder );
+ }
+
+ public CollectionType getCollectionType() {
+ return CollectionType.COLLECTION;
+ }
+ }
+
+ static class ListAttributeImpl<X,E> extends PluralAttributeImpl<X,List<E>,E> implements ListAttribute<X,E> {
+ ListAttributeImpl(Builder<X,List<E>,E,?> xceBuilder) {
+ super( xceBuilder );
+ }
+
+ public CollectionType getCollectionType() {
+ return CollectionType.LIST;
+ }
+ }
+
+ static class MapAttributeImpl<X,K,V> extends PluralAttributeImpl<X,Map<K,V>,V> implements MapAttribute<X,K,V> {
+ private final Type<K> keyType;
+
+ MapAttributeImpl(Builder<X,Map<K,V>,V,K> xceBuilder) {
+ super( xceBuilder );
+ this.keyType = xceBuilder.keyType;
+ }
+
+ public CollectionType getCollectionType() {
+ return CollectionType.MAP;
+ }
+
+ public Class<K> getKeyJavaType() {
+ return keyType.getJavaType();
+ }
+
+ public Type<K> getKeyType() {
+ return keyType;
+ }
+ }
+}
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/SingularAttributeImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/SingularAttributeImpl.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/SingularAttributeImpl.java 2009-08-09 18:04:35 UTC (rev 17254)
@@ -0,0 +1,146 @@
+package org.hibernate.ejb.metamodel;
+
+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
+ */
+public class SingularAttributeImpl<X, Y> implements SingularAttribute<X, Y>, Serializable {
+ private final boolean isId;
+ 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 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 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;
+ }
+
+ public Builder<X,Y> member(Member member) {
+ this.member = member;
+ return this;
+ }
+
+ 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);
+ }
+
+ public boolean isId() {
+ return isId;
+ }
+
+ public boolean isVersion() {
+ return isVersion;
+ }
+
+ public boolean isOptional() {
+ return isOptional;
+ }
+
+ public Type<Y> getType() {
+ return attrType;
+ }
+
+ 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;
+ }
+
+ public boolean isAssociation() {
+ return false;
+ }
+
+ public boolean isCollection() {
+ return false;
+ }
+
+ public BindableType getBindableType() {
+ return BindableType.SINGULAR_ATTRIBUTE;
+ }
+
+ public Class<Y> getBindableJavaType() {
+ return attrType.getJavaType();
+ }
+}
15 years, 4 months
Hibernate SVN: r17253 - core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2009-08-09 08:54:15 -0400 (Sun, 09 Aug 2009)
New Revision: 17253
Modified:
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/SybaseASE15Dialect.java
Log:
JBPAPP-1547 HHH-3686 : Sybase - QueryCacheTest.testQueryCacheInvalidation fails
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/SybaseASE15Dialect.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/SybaseASE15Dialect.java 2009-08-07 18:38:07 UTC (rev 17252)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/SybaseASE15Dialect.java 2009-08-09 12:54:15 UTC (rev 17253)
@@ -41,12 +41,12 @@
return false;
}
/**
- * By default, Sybase string comparisons are case-insensitive.
+ * By default, Sybase string comparisons are case-insensitive.<br>
+ * If the DB is configured to be case-sensitive, then the return value will be incorrect.
*/
public boolean areStringComparisonsCaseInsensitive() {
return true;
}
-
public boolean supportsExpectedLobUsagePattern() {
return false;
}
15 years, 4 months
Hibernate SVN: r17252 - in core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria: expression and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-08-07 14:38:07 -0400 (Fri, 07 Aug 2009)
New Revision: 17252
Added:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CoalesceExpression.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/NullifExpression.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/SimpleCaseExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExistsPredicate.java
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/LiteralExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/AbstractSimplePredicate.java
Log:
EJB-447 : Implement JPA 2.0 criteria apis (miscellaneous)
Modified: 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-08-07 12:12:20 UTC (rev 17251)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.java 2009-08-07 18:38:07 UTC (rev 17252)
@@ -42,9 +42,15 @@
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.CompoundSelectionImpl;
+import org.hibernate.ejb.criteria.expression.ConcatExpression;
+import org.hibernate.ejb.criteria.expression.ExpressionImpl;
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.SubqueryComparisonModifierExpression;
import org.hibernate.ejb.criteria.expression.UnaryArithmeticOperation;
import org.hibernate.ejb.criteria.expression.function.AbsFunction;
@@ -68,6 +74,7 @@
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.LikePredicate;
import static org.hibernate.ejb.criteria.predicate.ComparisonPredicate.ComparisonOperator;
@@ -1023,7 +1030,7 @@
* {@inheritDoc}
*/
public Predicate exists(Subquery<?> subquery) {
- return null;
+ return new ExistsPredicate( this, subquery );
}
/**
@@ -1063,88 +1070,140 @@
}
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // miscellaneous expressions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- public <C extends Collection<?>> Predicate isEmpty(Expression<C> cExpression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public <Y> Expression<Y> coalesce(Expression<? extends Y> exp1, Expression<? extends Y> exp2) {
+ return coalesce( (Class<Y>)null, exp1, exp2 );
}
- public <C extends Collection<?>> Predicate isNotEmpty(Expression<C> cExpression) {
- return null;
+ 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 );
}
- public <C extends Collection<?>> Expression<Integer> size(C c) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public <Y> Expression<Y> coalesce(Expression<? extends Y> exp1, Y exp2) {
+ return coalesce( (Class<Y>)null, exp1, exp2 );
}
- public <C extends Collection<?>> Expression<Integer> size(Expression<C> cExpression) {
- return null;
+ public <Y> Expression<Y> coalesce(Class<Y> type, Expression<? extends Y> exp1, Y exp2) {
+ return new CoalesceExpression<Y>( this, type ).value( exp1 ).value( exp2 );
}
- public <E, C extends Collection<E>> Predicate isMember(E e, Expression<C> cExpression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public <T> Coalesce<T> coalesce() {
+ return coalesce( (Class<T>)null );
}
- public <E, C extends Collection<E>> Predicate isNotMember(E e, Expression<C> cExpression) {
- return null;
+ public <T> Coalesce<T> coalesce(Class<T> type) {
+ return new CoalesceExpression<T>( this, type );
}
- public <E, C extends Collection<E>> Predicate isMember(Expression<E> eExpression, Expression<C> cExpression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<String> concat(Expression<String> string1, Expression<String> string2) {
+ return new ConcatExpression( this, string1, string2 );
}
- public <E, C extends Collection<E>> Predicate isNotMember(Expression<E> eExpression, Expression<C> cExpression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<String> concat(Expression<String> string1, String string2) {
+ return new ConcatExpression( this, string1, string2 );
}
- public <V, M extends Map<?, V>> Expression<Collection<V>> values(M map) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<String> concat(String string1, Expression<String> string2) {
+ return new ConcatExpression( this, string1, string2 );
}
- public <K, M extends Map<K, ?>> Expression<Set<K>> keys(M m) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public <Y> Expression<Y> nullif(Expression<Y> exp1, Expression<?> exp2) {
+ return nullif( (Class<Y>)null, exp1, exp2 );
}
- public Expression<String> concat(Expression<String> stringExpression, Expression<String> stringExpression1) {
- return null;
+ public <Y> Expression<Y> nullif(Class<Y> type, Expression<Y> exp1, Expression<?> exp2) {
+ return new NullifExpression<Y>( this, type, exp1, exp2 );
}
- public Expression<String> concat(Expression<String> stringExpression, String s) {
- return null;
+ public <Y> Expression<Y> nullif(Expression<Y> exp1, Y exp2) {
+ return nullif( (Class<Y>)null, exp1, exp2 );
}
- public Expression<String> concat(String s, Expression<String> stringExpression) {
- return null;
+ public <Y> Expression<Y> nullif(Class<Y> type, Expression<Y> exp1, Y exp2) {
+ return new NullifExpression<Y>( this, type, exp1, exp2 );
}
- public <Y> Expression<Y> coalesce(Expression<? extends Y> expression, Expression<? extends Y> expression1) {
- return null;
+ public <C, R> SimpleCase<C, R> selectCase(Expression<? extends C> expression) {
+ return selectCase( (Class<R>)null, expression );
}
- public <Y> Expression<Y> coalesce(Expression<? extends Y> expression, Y y) {
- return null;
+ public <C, R> SimpleCase<C, R> selectCase(Class<R> type, Expression<? extends C> expression) {
+ return new SimpleCaseExpression<C, R>( this, type, expression );
}
- public <Y> Expression<Y> nullif(Expression<Y> yExpression, Expression<?> expression) {
- return null;
+ public <R> Case<R> selectCase() {
+ return selectCase( (Class<R>)null );
}
- public <Y> Expression<Y> nullif(Expression<Y> yExpression, Y y) {
- return null;
+ public <R> Case<R> selectCase(Class<R> type) {
+ return new SearchedCaseExpression<R>( this, type );
}
- public <T> Coalesce<T> coalesce() {
- return null;
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public <C extends Collection<?>> Predicate isEmpty(Expression<C> cExpression) {
+ throw new UnsupportedOperationException( "Not yet implemented!" );
}
- public <C, R> SimpleCase<C, R> selectCase(Expression<? extends C> expression) {
- return null;
+ public <C extends Collection<?>> Predicate isNotEmpty(Expression<C> colelctionExpression) {
+ return isEmpty( colelctionExpression ).negate();
}
- public <R> Case<R> selectCase() {
- return null;
+ public <C extends Collection<?>> Expression<Integer> size(C c) {
+ throw new UnsupportedOperationException( "Not yet implemented!" );
}
+
+ public <C extends Collection<?>> Expression<Integer> size(Expression<C> cExpression) {
+ throw new UnsupportedOperationException( "Not yet implemented!" );
+ }
+
+ public <E, C extends Collection<E>> Predicate isMember(E e, Expression<C> cExpression) {
+ throw new UnsupportedOperationException( "Not yet implemented!" );
+ }
+
+ public <E, C extends Collection<E>> Predicate isNotMember(E e, Expression<C> cExpression) {
+ throw new UnsupportedOperationException( "Not yet implemented!" );
+ }
+
+ public <E, C extends Collection<E>> Predicate isMember(Expression<E> eExpression, Expression<C> cExpression) {
+ throw new UnsupportedOperationException( "Not yet implemented!" );
+ }
+
+ public <E, C extends Collection<E>> Predicate isNotMember(Expression<E> eExpression, Expression<C> cExpression) {
+ throw new UnsupportedOperationException( "Not yet implemented!" );
+ }
+
+ public <V, M extends Map<?, V>> Expression<Collection<V>> values(M map) {
+ throw new UnsupportedOperationException( "Not yet implemented!" );
+ }
+
+ public <K, M extends Map<K, ?>> Expression<Set<K>> keys(M m) {
+ throw new UnsupportedOperationException( "Not yet implemented!" );
+ }
}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CoalesceExpression.java 2009-08-07 18:38:07 UTC (rev 17252)
@@ -0,0 +1,68 @@
+/*
+ * 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.criteria.expression;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.persistence.criteria.Expression;
+import javax.persistence.criteria.QueryBuilder.Coalesce;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+
+/**
+ * Models an ANSI SQL <tt>COALESCE</tt> expression. <tt>COALESCE</tt> is a specialized <tt>CASE</tt> statement.
+ *
+ * @author Steve Ebersole
+ */
+public class CoalesceExpression<T> extends ExpressionImpl<T> implements Coalesce<T> {
+ private final List<Expression<? extends T>> expressions;
+ private Class<T> javaType;
+
+ public CoalesceExpression(QueryBuilderImpl queryBuilder) {
+ this( queryBuilder, null );
+ }
+
+ public CoalesceExpression(
+ QueryBuilderImpl queryBuilder,
+ Class<T> javaType) {
+ super( queryBuilder, javaType );
+ this.javaType = javaType;
+ this.expressions = new ArrayList<Expression<? extends T>>();
+ }
+
+ @Override
+ public Class<T> getJavaType() {
+ return javaType;
+ }
+
+ public Coalesce<T> value(T value) {
+ return value( new LiteralExpression<T>( queryBuilder(), value ) );
+ }
+
+ public Coalesce<T> value(Expression<? extends T> value) {
+ expressions.add( value );
+ if ( javaType == null ) {
+ javaType = (Class<T>) value.getJavaType();
+ }
+ return this;
+ }
+
+}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ConcatExpression.java 2009-08-07 18:38:07 UTC (rev 17252)
@@ -0,0 +1,71 @@
+/*
+ * 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.criteria.expression;
+
+import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class ConcatExpression extends ExpressionImpl<String> {
+ private Expression<String> string1;
+ private Expression<String> string2;
+
+ public ConcatExpression(
+ QueryBuilderImpl queryBuilder,
+ Expression<String> expression1,
+ Expression<String> expression2) {
+ super( queryBuilder, String.class );
+ this.string1 = expression1;
+ this.string2 = expression2;
+ }
+
+ public ConcatExpression(
+ QueryBuilderImpl queryBuilder,
+ Expression<String> string1,
+ String string2) {
+ this( queryBuilder, string1, wrap(queryBuilder, string2) );
+ }
+
+ private static Expression<String> wrap(QueryBuilderImpl queryBuilder, String string) {
+ return new LiteralExpression<String>( queryBuilder, string );
+ }
+
+ public ConcatExpression(
+ QueryBuilderImpl queryBuilder,
+ String string1,
+ Expression<String> string2) {
+ this( queryBuilder, wrap(queryBuilder, string1), string2 );
+ }
+
+ public Expression<String> getString1() {
+ return string1;
+ }
+
+ public Expression<String> getString2() {
+ return string2;
+ }
+
+}
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-08-07 12:12:20 UTC (rev 17251)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/LiteralExpression.java 2009-08-07 18:38:07 UTC (rev 17252)
@@ -31,11 +31,16 @@
public class LiteralExpression<T> extends ExpressionImpl<T> {
private final T literal;
- public LiteralExpression(
- QueryBuilderImpl queryBuilder,
- T literal) {
- //noinspection unchecked
- super( queryBuilder, ( Class<T> ) literal.getClass() );
+ public LiteralExpression(QueryBuilderImpl queryBuilder, T literal) {
+ this( queryBuilder, (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 );
this.literal = literal;
}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/NullifExpression.java 2009-08-07 18:38:07 UTC (rev 17252)
@@ -0,0 +1,68 @@
+/*
+ * 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.criteria.expression;
+
+import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+
+/**
+ * Models an ANSI SQL <tt>NULLIF</tt> expression. <tt>NULLIF</tt> is a specialized <tt>CASE</tt> statement.
+ *
+ * @author Steve Ebersole
+ */
+public class NullifExpression<T> extends ExpressionImpl<T> {
+ private final Expression<? extends T> primaryExpression;
+ private final Expression<?> secondaryExpression;
+
+ public NullifExpression(
+ QueryBuilderImpl queryBuilder,
+ Class<T> javaType,
+ Expression<? extends T> primaryExpression,
+ Expression<?> secondaryExpression) {
+ super( queryBuilder, (Class<T>)determineType(javaType, primaryExpression) );
+ this.primaryExpression = primaryExpression;
+ this.secondaryExpression = secondaryExpression;
+ }
+
+ public NullifExpression(
+ QueryBuilderImpl queryBuilder,
+ Class<T> javaType,
+ Expression<? extends T> primaryExpression,
+ Object secondaryExpression) {
+ super( queryBuilder, (Class<T>)determineType(javaType, primaryExpression) );
+ this.primaryExpression = primaryExpression;
+ this.secondaryExpression = new LiteralExpression( queryBuilder, secondaryExpression );
+ }
+
+ private static Class determineType(Class javaType, Expression primaryExpression) {
+ return javaType != null ? javaType : primaryExpression.getJavaType();
+ }
+
+ public Expression<? extends T> getPrimaryExpression() {
+ return primaryExpression;
+ }
+
+ public Expression<?> getSecondaryExpression() {
+ return secondaryExpression;
+ }
+
+}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SearchedCaseExpression.java 2009-08-07 18:38:07 UTC (rev 17252)
@@ -0,0 +1,108 @@
+/*
+ * 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.criteria.expression;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.persistence.criteria.Expression;
+import javax.persistence.criteria.QueryBuilder.Case;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class SearchedCaseExpression<R> extends ExpressionImpl<R> implements Case<R> {
+ private Class<R> javaType; // overrides the javaType kept on tuple-impl so that we can adjust it
+ private List<WhenClause> whenClauses = new ArrayList<WhenClause>();
+ private Expression<? extends R> otherwiseResult;
+
+ public class WhenClause {
+ private final Expression<Boolean> condition;
+ private final Expression<? extends R> result;
+
+ public WhenClause(Expression<Boolean> condition, Expression<? extends R> result) {
+ this.condition = condition;
+ this.result = result;
+ }
+
+ public Expression<Boolean> getCondition() {
+ return condition;
+ }
+
+ public Expression<? extends R> getResult() {
+ return result;
+ }
+ }
+
+ public SearchedCaseExpression(
+ QueryBuilderImpl queryBuilder,
+ Class<R> javaType) {
+ super(queryBuilder, javaType);
+ this.javaType = javaType;
+ }
+
+ public Case<R> when(Expression<Boolean> condition, R result) {
+ return when( condition, buildLiteral(result) );
+ }
+
+ private LiteralExpression<R> buildLiteral(R result) {
+ final Class<R> type = result != null
+ ? (Class<R>) result.getClass()
+ : (Class<R>) getJavaType();
+ return new LiteralExpression<R>( queryBuilder(), type, result );
+ }
+
+ public Case<R> when(Expression<Boolean> condition, Expression<? extends R> result) {
+ WhenClause whenClause = new WhenClause( condition, result );
+ whenClauses.add( whenClause );
+ adjustJavaType( result );
+ return this;
+ }
+
+ private void adjustJavaType(Expression<? extends R> exp) {
+ if ( javaType == null ) {
+ javaType = (Class<R>) exp.getJavaType();
+ }
+ }
+
+ public Expression<R> otherwise(R result) {
+ return otherwise( buildLiteral(result) );
+ }
+
+ public Expression<R> otherwise(Expression<? extends R> result) {
+ this.otherwiseResult = result;
+ adjustJavaType( result );
+ return this;
+ }
+
+ public Expression<? extends R> getOtherwiseResult() {
+ return otherwiseResult;
+ }
+
+ public List<WhenClause> getWhenClauses() {
+ return whenClauses;
+ }
+
+
+}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SimpleCaseExpression.java 2009-08-07 18:38:07 UTC (rev 17252)
@@ -0,0 +1,114 @@
+/*
+ * 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.criteria.expression;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.persistence.criteria.Expression;
+import javax.persistence.criteria.QueryBuilder.SimpleCase;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class SimpleCaseExpression<C,R> extends ExpressionImpl<R> implements SimpleCase<C,R> {
+ private Class<R> javaType;
+ private final Expression<? extends C> expression;
+ private List<WhenClause> whenClauses = new ArrayList<WhenClause>();
+ private Expression<? extends R> otherwiseResult;
+
+ public class WhenClause {
+ private final C condition;
+ private final Expression<? extends R> result;
+
+ public WhenClause(C condition, Expression<? extends R> result) {
+ this.condition = condition;
+ this.result = result;
+ }
+
+ public C getCondition() {
+ return condition;
+ }
+
+ public Expression<? extends R> getResult() {
+ return result;
+ }
+
+ }
+
+ public SimpleCaseExpression(
+ QueryBuilderImpl queryBuilder,
+ Class<R> javaType,
+ Expression<? extends C> expression) {
+ super(queryBuilder, javaType);
+ this.javaType = javaType;
+ this.expression = expression;
+ }
+
+ public Expression<C> getExpression() {
+ return (Expression<C>) expression;
+ }
+
+ public SimpleCase<C, R> when(C condition, R result) {
+ return when( condition, buildLiteral(result) );
+ }
+
+ private LiteralExpression<R> buildLiteral(R result) {
+ final Class<R> type = result != null
+ ? (Class<R>) result.getClass()
+ : (Class<R>) getJavaType();
+ return new LiteralExpression<R>( queryBuilder(), type, result );
+ }
+
+ public SimpleCase<C, R> when(C condition, Expression<? extends R> result) {
+ WhenClause whenClause = new WhenClause( condition, result );
+ whenClauses.add( whenClause );
+ adjustJavaType( result );
+ return this;
+ }
+
+ private void adjustJavaType(Expression<? extends R> exp) {
+ if ( javaType == null ) {
+ javaType = (Class<R>) exp.getJavaType();
+ }
+ }
+
+ public Expression<R> otherwise(R result) {
+ return otherwise( buildLiteral(result) );
+ }
+
+ public Expression<R> otherwise(Expression<? extends R> result) {
+ this.otherwiseResult = result;
+ adjustJavaType( result );
+ return this;
+ }
+
+ public Expression<? extends R> getOtherwiseResult() {
+ return otherwiseResult;
+ }
+
+ public List<WhenClause> getWhenClauses() {
+ return whenClauses;
+ }
+}
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-08-07 12:12:20 UTC (rev 17251)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/AbstractSimplePredicate.java 2009-08-07 18:38:07 UTC (rev 17252)
@@ -43,7 +43,7 @@
return BooleanOperator.AND;
}
- public List<Expression<Boolean>> getExpressions() {
+ public final List<Expression<Boolean>> getExpressions() {
return NO_EXPRESSIONS;
}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExistsPredicate.java 2009-08-07 18:38:07 UTC (rev 17252)
@@ -0,0 +1,44 @@
+/*
+ * 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.criteria.predicate;
+
+import javax.persistence.criteria.Subquery;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+
+/**
+ * Models an <tt>EXISTS(<subquery>)</tt> predicate
+ *
+ * @author Steve Ebersole
+ */
+public class ExistsPredicate extends AbstractSimplePredicate {
+ private final Subquery<?> subquery;
+
+ public ExistsPredicate(QueryBuilderImpl queryBuilder, Subquery<?> subquery) {
+ super(queryBuilder);
+ this.subquery = subquery;
+ }
+
+ public Subquery<?> getSubquery() {
+ return subquery;
+ }
+
+}
15 years, 4 months
Hibernate SVN: r17251 - in core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria: expression and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-08-07 08:12:20 -0400 (Fri, 07 Aug 2009)
New Revision: 17251
Added:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryOperatorExpression.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/UnaryOperatorExpression.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/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/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/LikePredicate.java
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.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/FunctionExpression.java
Log:
EJB-447 : Implement JPA 2.0 criteria apis (completed function support)
Modified: 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-08-06 18:39:33 UTC (rev 17250)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -41,10 +41,25 @@
import javax.persistence.Tuple;
import org.hibernate.ejb.EntityManagerFactoryImpl;
+import org.hibernate.ejb.criteria.expression.BinaryArithmeticOperation;
import org.hibernate.ejb.criteria.expression.CompoundSelectionImpl;
import org.hibernate.ejb.criteria.expression.ParameterExpressionImpl;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
+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.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.ExplicitTruthValueCheck;
import org.hibernate.ejb.criteria.predicate.TruthValue;
@@ -53,6 +68,7 @@
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.LikePredicate;
import static org.hibernate.ejb.criteria.predicate.ComparisonPredicate.ComparisonOperator;
/**
@@ -519,7 +535,55 @@
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 ).negate();
+ }
+
+ public Predicate notLike(Expression<String> matchExpression, Expression<String> pattern, Expression<Character> escapeCharacter) {
+ return like( matchExpression, pattern, escapeCharacter ).negate();
+ }
+
+ public Predicate notLike(Expression<String> matchExpression, Expression<String> pattern, char escapeCharacter) {
+ return like( matchExpression, pattern, escapeCharacter ).negate();
+ }
+
+ public Predicate notLike(Expression<String> matchExpression, String pattern) {
+ return like( matchExpression, pattern ).negate();
+ }
+
+ public Predicate notLike(Expression<String> matchExpression, String pattern, Expression<Character> escapeCharacter) {
+ return like( matchExpression, pattern, escapeCharacter ).negate();
+ }
+
+ public Predicate notLike(Expression<String> matchExpression, String pattern, char escapeCharacter) {
+ return like( matchExpression, pattern, escapeCharacter ).negate();
+ }
+
+
// parameters ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
@@ -603,307 +667,459 @@
}
+ // other functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- public Predicate exists(Subquery<?> subquery) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public <T> Expression<T> function(String name, Class<T> returnType, Expression<?>... arguments) {
+ return new BasicFunctionExpression<T>( this, returnType, name, arguments );
}
- public <Y> Expression<Y> all(Subquery<Y> ySubquery) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public <N extends Number> Expression<N> abs(Expression<N> expression) {
+ return new AbsFunction<N>( this, expression );
}
- public <Y> Expression<Y> some(Subquery<Y> ySubquery) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Double> sqrt(Expression<? extends Number> expression) {
+ return new SqrtFunction( this, expression );
}
- public <Y> Expression<Y> any(Subquery<Y> ySubquery) {
- return null;
+ public Expression<java.sql.Date> currentDate() {
+ return new CurrentDateFunction( this );
}
- public <N extends Number> Expression<N> neg(Expression<N> nExpression) {
- return null;
+ public Expression<java.sql.Timestamp> currentTimestamp() {
+ return new CurrentTimestampFunction( this );
}
- public <N extends Number> Expression<N> abs(Expression<N> nExpression) {
- return null;
+ public Expression<java.sql.Time> currentTime() {
+ return new CurrentTimeFunction( this );
}
- public <N extends Number> Expression<N> sum(Expression<? extends N> expression, Expression<? extends N> expression1) {
- return null;
+ public Expression<String> substring(Expression<String> value, Expression<Integer> start) {
+ return new SubstringFunction( this, value, start );
}
- public <N extends Number> Expression<N> prod(Expression<? extends N> expression, Expression<? extends N> expression1) {
- return null;
+ public Expression<String> substring(Expression<String> value, int start) {
+ return new SubstringFunction( this, value, start );
}
- public <N extends Number> Expression<N> diff(Expression<? extends N> expression, Expression<? extends N> expression1) {
- return null;
+ public Expression<String> substring(Expression<String> value, Expression<Integer> start, Expression<Integer> length) {
+ return new SubstringFunction( this, value, start, length );
}
- public <N extends Number> Expression<N> sum(Expression<? extends N> expression, N n) {
- return null;
+ public Expression<String> substring(Expression<String> value, int start, int length) {
+ return new SubstringFunction( this, value, start, length );
}
- public <N extends Number> Expression<N> prod(Expression<? extends N> expression, N n) {
- return null;
+ public Expression<String> trim(Expression<String> trimSource ) {
+ return new TrimFunction( this, trimSource );
}
- public <N extends Number> Expression<N> diff(Expression<? extends N> expression, N n) {
- return null;
+ public Expression<String> trim(Trimspec trimspec, Expression<String> trimSource) {
+ return new TrimFunction( this, trimspec, trimSource );
}
- public <N extends Number> Expression<N> sum(N n, Expression<? extends N> expression) {
- return null;
+ public Expression<String> trim(Expression<Character> trimCharacter, Expression<String> trimSource) {
+ return new TrimFunction( this, trimCharacter, trimSource );
}
- public <N extends Number> Expression<N> prod(N n, Expression<? extends N> expression) {
- return null;
+ public Expression<String> trim(Trimspec trimspec, Expression<Character> trimCharacter, Expression<String> trimSource) {
+ return new TrimFunction( this, trimspec, trimCharacter, trimSource );
}
- public <N extends Number> Expression<N> diff(N n, Expression<? extends N> expression) {
- return null;
+ public Expression<String> trim(char trimCharacter, Expression<String> trimSource) {
+ return new TrimFunction( this, trimCharacter, trimSource );
}
- public Expression<Number> quot(Expression<? extends Number> expression, Expression<? extends Number> expression1) {
- return null;
+ public Expression<String> trim(Trimspec trimspec, char trimCharacter, Expression<String> trimSource) {
+ return new TrimFunction( this, trimspec, trimCharacter, trimSource );
}
- public Expression<Number> quot(Expression<? extends Number> expression, Number number) {
- return null;
+ public Expression<String> lower(Expression<String> value) {
+ return new LowerFunction( this, value );
}
- public Expression<Number> quot(Number number, Expression<? extends Number> expression) {
- return null;
+ public Expression<String> upper(Expression<String> value) {
+ return new UpperFunction( this, value );
}
- public Expression<Integer> mod(Expression<Integer> integerExpression, Expression<Integer> integerExpression1) {
- return null;
+ public Expression<Integer> length(Expression<String> value) {
+ return new LengthFunction( this, value );
}
- public Expression<Integer> mod(Expression<Integer> integerExpression, Integer integer) {
- return null;
+ public Expression<Integer> locate(Expression<String> string, Expression<String> pattern) {
+ return new LocateFunction( this, pattern, string );
}
- public Expression<Integer> mod(Integer integer, Expression<Integer> integerExpression) {
- return null;
+ public Expression<Integer> locate(Expression<String> string, Expression<String> pattern, Expression<Integer> start) {
+ return new LocateFunction( this, pattern, string, start );
}
- public Expression<Double> sqrt(Expression<? extends Number> expression) {
- return null;
+ public Expression<Integer> locate(Expression<String> string, String pattern) {
+ return new LocateFunction( this, pattern, string );
}
- public Expression<Long> toLong(Expression<? extends Number> expression) {
- return null;
+ public Expression<Integer> locate(Expression<String> string, String pattern, int start) {
+ return new LocateFunction( this, pattern, string, start );
}
- public Expression<Integer> toInteger(Expression<? extends Number> expression) {
- return null;
- }
- public Expression<Float> toFloat(Expression<? extends Number> expression) {
- return null;
- }
+ // arithmetic operations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- public Expression<Double> toDouble(Expression<? extends Number> expression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public <N extends Number> Expression<N> neg(Expression<N> expression) {
+ return new UnaryArithmeticOperation<N>(
+ this,
+ UnaryArithmeticOperation.Operation.UNARY_MINUS,
+ expression
+ );
}
- public Expression<BigDecimal> toBigDecimal(Expression<? extends Number> expression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public <N extends Number> Expression<N> sum(Expression<? extends N> expression1, Expression<? extends N> expression2) {
+ return new BinaryArithmeticOperation<N>(
+ this,
+ (Class<N>) expression1.getJavaType(),
+ BinaryArithmeticOperation.Operation.ADD,
+ expression1,
+ expression2
+ );
}
- public Expression<BigInteger> toBigInteger(Expression<? extends Number> expression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public <N extends Number> Expression<N> prod(Expression<? extends N> expression1, Expression<? extends N> expression2) {
+ return new BinaryArithmeticOperation<N>(
+ this,
+ (Class<N>) expression1.getJavaType(),
+ BinaryArithmeticOperation.Operation.MULTIPLY,
+ expression1,
+ expression2
+ );
}
- public Expression<String> toString(Expression<Character> characterExpression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public <N extends Number> Expression<N> diff(Expression<? extends N> expression1, Expression<? extends N> expression2) {
+ return new BinaryArithmeticOperation<N>(
+ this,
+ (Class<N>) expression1.getJavaType(),
+ BinaryArithmeticOperation.Operation.SUBTRACT,
+ expression1,
+ expression2
+ );
}
- public <C extends Collection<?>> Predicate isEmpty(Expression<C> cExpression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public <N extends Number> Expression<N> sum(Expression<? extends N> expression, N n) {
+ return new BinaryArithmeticOperation<N>(
+ this,
+ (Class<N>) expression.getJavaType(),
+ BinaryArithmeticOperation.Operation.ADD,
+ expression,
+ n
+ );
}
- public <C extends Collection<?>> Predicate isNotEmpty(Expression<C> cExpression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public <N extends Number> Expression<N> prod(Expression<? extends N> expression, N n) {
+ return new BinaryArithmeticOperation<N>(
+ this,
+ (Class<N>) expression.getJavaType(),
+ BinaryArithmeticOperation.Operation.MULTIPLY,
+ expression,
+ n
+ );
}
- public <C extends Collection<?>> Expression<Integer> size(C c) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public <N extends Number> Expression<N> diff(Expression<? extends N> expression, N n) {
+ return new BinaryArithmeticOperation<N>(
+ this,
+ (Class<N>) expression.getJavaType(),
+ BinaryArithmeticOperation.Operation.SUBTRACT,
+ expression,
+ n
+ );
}
- public <C extends Collection<?>> Expression<Integer> size(Expression<C> cExpression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public <N extends Number> Expression<N> sum(N n, Expression<? extends N> expression) {
+ return new BinaryArithmeticOperation<N>(
+ this,
+ (Class<N>) expression.getJavaType(),
+ BinaryArithmeticOperation.Operation.ADD,
+ n,
+ expression
+ );
}
- public <E, C extends Collection<E>> Predicate isMember(E e, Expression<C> cExpression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public <N extends Number> Expression<N> prod(N n, Expression<? extends N> expression) {
+ return new BinaryArithmeticOperation<N>(
+ this,
+ (Class<N>) expression.getJavaType(),
+ BinaryArithmeticOperation.Operation.MULTIPLY,
+ n,
+ expression
+ );
}
- public <E, C extends Collection<E>> Predicate isNotMember(E e, Expression<C> cExpression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public <N extends Number> Expression<N> diff(N n, Expression<? extends N> expression) {
+ return new BinaryArithmeticOperation<N>(
+ this,
+ (Class<N>) expression.getJavaType(),
+ BinaryArithmeticOperation.Operation.SUBTRACT,
+ n,
+ expression
+ );
}
- public <E, C extends Collection<E>> Predicate isMember(Expression<E> eExpression, Expression<C> cExpression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Number> quot(Expression<? extends Number> expression1, Expression<? extends Number> expression2) {
+ // TODO : still open question whether this should be a quotient (integer division) or division
+ throw new UnsupportedOperationException( "Not yet implemented!" );
}
- public <E, C extends Collection<E>> Predicate isNotMember(Expression<E> eExpression, Expression<C> cExpression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Number> quot(Expression<? extends Number> expression, Number number) {
+ // TODO : still open question whether this should be a quotient (integer division) or division
+ throw new UnsupportedOperationException( "Not yet implemented!" );
}
- public <V, M extends Map<?, V>> Expression<Collection<V>> values(M map) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Number> quot(Number number, Expression<? extends Number> expression) {
+ // TODO : still open question whether this should be a quotient (integer division) or division
+ throw new UnsupportedOperationException( "Not yet implemented!" );
}
- public <K, M extends Map<K, ?>> Expression<Set<K>> keys(M m) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Integer> mod(Expression<Integer> expression1, Expression<Integer> expression2) {
+ return new BinaryArithmeticOperation<Integer>(
+ this,
+ Integer.class,
+ BinaryArithmeticOperation.Operation.MOD,
+ expression1,
+ expression2
+ );
}
- public Predicate like(Expression<String> stringExpression, Expression<String> stringExpression1) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Integer> mod(Expression<Integer> expression, Integer integer) {
+ return new BinaryArithmeticOperation<Integer>(
+ this,
+ Integer.class,
+ BinaryArithmeticOperation.Operation.MOD,
+ expression,
+ integer
+ );
}
- public Predicate like(Expression<String> stringExpression, Expression<String> stringExpression1, Expression<Character> characterExpression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Integer> mod(Integer integer, Expression<Integer> expression) {
+ return new BinaryArithmeticOperation<Integer>(
+ this,
+ Integer.class,
+ BinaryArithmeticOperation.Operation.MOD,
+ integer,
+ expression
+ );
}
- public Predicate like(Expression<String> stringExpression, Expression<String> stringExpression1, char c) {
- return null;
- }
- public Predicate like(Expression<String> stringExpression, String s) {
- return null;
- }
+ // casting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- public Predicate like(Expression<String> stringExpression, String s, Expression<Character> characterExpression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Long> toLong(Expression<? extends Number> expression) {
+ return expression.as( Long.class );
}
- public Predicate like(Expression<String> stringExpression, String s, char c) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Integer> toInteger(Expression<? extends Number> expression) {
+ return expression.as( Integer.class );
}
- public Predicate notLike(Expression<String> stringExpression, Expression<String> stringExpression1) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Float> toFloat(Expression<? extends Number> expression) {
+ return expression.as( Float.class );
}
- public Predicate notLike(Expression<String> stringExpression, Expression<String> stringExpression1, Expression<Character> characterExpression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<Double> toDouble(Expression<? extends Number> expression) {
+ return expression.as( Double.class );
}
- public Predicate notLike(Expression<String> stringExpression, Expression<String> stringExpression1, char c) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<BigDecimal> toBigDecimal(Expression<? extends Number> expression) {
+ return expression.as( BigDecimal.class );
}
- public Predicate notLike(Expression<String> stringExpression, String s) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<BigInteger> toBigInteger(Expression<? extends Number> expression) {
+ return expression.as( BigInteger.class );
}
- public Predicate notLike(Expression<String> stringExpression, String s, Expression<Character> characterExpression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public Expression<String> toString(Expression<Character> characterExpression) {
+ return characterExpression.as( String.class );
}
- public Predicate notLike(Expression<String> stringExpression, String s, char c) {
- return null;
- }
- public Expression<String> concat(Expression<String> stringExpression, Expression<String> stringExpression1) {
- return null;
- }
+ // subqueries ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- public Expression<String> concat(Expression<String> stringExpression, String s) {
+ /**
+ * {@inheritDoc}
+ */
+ public Predicate exists(Subquery<?> subquery) {
return null;
}
- public Expression<String> concat(String s, Expression<String> stringExpression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public <Y> Expression<Y> all(Subquery<Y> subquery) {
+ return new SubqueryComparisonModifierExpression<Y>(
+ this,
+ subquery.getJavaType(),
+ subquery,
+ SubqueryComparisonModifierExpression.Modifier.ALL
+ );
}
- public Expression<String> substring(Expression<String> stringExpression, Expression<Integer> integerExpression) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public <Y> Expression<Y> some(Subquery<Y> subquery) {
+ return new SubqueryComparisonModifierExpression<Y>(
+ this,
+ subquery.getJavaType(),
+ subquery,
+ SubqueryComparisonModifierExpression.Modifier.SOME
+ );
}
- public Expression<String> substring(Expression<String> stringExpression, int i) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public <Y> Expression<Y> any(Subquery<Y> subquery) {
+ return new SubqueryComparisonModifierExpression<Y>(
+ this,
+ subquery.getJavaType(),
+ subquery,
+ SubqueryComparisonModifierExpression.Modifier.ANY
+ );
}
- public Expression<String> substring(Expression<String> stringExpression, Expression<Integer> integerExpression, Expression<Integer> integerExpression1) {
- return null;
- }
- public Expression<String> substring(Expression<String> stringExpression, int i, int i1) {
- return null;
- }
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- public Expression<String> trim(Expression<String> stringExpression) {
+ public <C extends Collection<?>> Predicate isEmpty(Expression<C> cExpression) {
return null;
}
- public Expression<String> trim(Trimspec trimspec, Expression<String> stringExpression) {
+ public <C extends Collection<?>> Predicate isNotEmpty(Expression<C> cExpression) {
return null;
}
- public Expression<String> trim(Expression<Character> characterExpression, Expression<String> stringExpression) {
+ public <C extends Collection<?>> Expression<Integer> size(C c) {
return null;
}
- public Expression<String> trim(Trimspec trimspec, Expression<Character> characterExpression, Expression<String> stringExpression) {
+ public <C extends Collection<?>> Expression<Integer> size(Expression<C> cExpression) {
return null;
}
- public Expression<String> trim(char c, Expression<String> stringExpression) {
+ public <E, C extends Collection<E>> Predicate isMember(E e, Expression<C> cExpression) {
return null;
}
- public Expression<String> trim(Trimspec trimspec, char c, Expression<String> stringExpression) {
+ public <E, C extends Collection<E>> Predicate isNotMember(E e, Expression<C> cExpression) {
return null;
}
- public Expression<String> lower(Expression<String> stringExpression) {
+ public <E, C extends Collection<E>> Predicate isMember(Expression<E> eExpression, Expression<C> cExpression) {
return null;
}
- public Expression<String> upper(Expression<String> stringExpression) {
+ public <E, C extends Collection<E>> Predicate isNotMember(Expression<E> eExpression, Expression<C> cExpression) {
return null;
}
- public Expression<Integer> length(Expression<String> stringExpression) {
+ public <V, M extends Map<?, V>> Expression<Collection<V>> values(M map) {
return null;
}
- public Expression<Integer> locate(Expression<String> stringExpression, Expression<String> stringExpression1) {
+ public <K, M extends Map<K, ?>> Expression<Set<K>> keys(M m) {
return null;
}
- public Expression<Integer> locate(Expression<String> stringExpression, Expression<String> stringExpression1, Expression<Integer> integerExpression) {
+ public Expression<String> concat(Expression<String> stringExpression, Expression<String> stringExpression1) {
return null;
}
- public Expression<Integer> locate(Expression<String> stringExpression, String s) {
+ public Expression<String> concat(Expression<String> stringExpression, String s) {
return null;
}
- public Expression<Integer> locate(Expression<String> stringExpression, String s, int i) {
+ public Expression<String> concat(String s, Expression<String> stringExpression) {
return null;
}
- public Expression<java.sql.Date> currentDate() {
- return null;
- }
-
- public Expression<java.sql.Timestamp> currentTimestamp() {
- return null;
- }
-
- public Expression<java.sql.Time> currentTime() {
- return null;
- }
-
public <Y> Expression<Y> coalesce(Expression<? extends Y> expression, Expression<? extends Y> expression1) {
return null;
}
@@ -931,8 +1147,4 @@
public <R> Case<R> selectCase() {
return null;
}
-
- public <T> Expression<T> function(String s, Class<T> tClass, Expression<?>... expressions) {
- return null;
- }
}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -0,0 +1,92 @@
+/*
+ * 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.criteria.expression;
+
+import javax.persistence.criteria.Expression;
+
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+
+/**
+ * Models standard arithmetc operations with two operands.
+ *
+ * @author Steve Ebersole
+ */
+public class BinaryArithmeticOperation<N extends Number>
+ extends ExpressionImpl<N>
+ implements BinaryOperatorExpression<N> {
+
+ public static enum Operation {
+ ADD, SUBTRACT, MULTIPLY, DIVIDE, QUOT, MOD
+ }
+
+ private final Operation operator;
+ private final Expression<? extends N> rhs;
+ private final Expression<? extends N> lhs;
+
+ public BinaryArithmeticOperation(
+ QueryBuilderImpl queryBuilder,
+ Class<N> javaType,
+ Operation operator,
+ Expression<? extends N> rhs,
+ Expression<? extends N> lhs) {
+ super( queryBuilder, javaType );
+ this.operator = operator;
+ this.rhs = rhs;
+ this.lhs = lhs;
+ }
+
+ public BinaryArithmeticOperation(
+ QueryBuilderImpl queryBuilder,
+ Class<N> javaType,
+ Operation operator,
+ Expression<? extends N> rhs,
+ N lhs) {
+ super( queryBuilder, javaType );
+ this.operator = operator;
+ this.rhs = rhs;
+ this.lhs = new LiteralExpression<N>( queryBuilder, lhs );
+ }
+
+ public BinaryArithmeticOperation(
+ QueryBuilderImpl queryBuilder,
+ Class<N> javaType,
+ Operation operator,
+ N rhs,
+ Expression<? extends N> lhs) {
+ super( queryBuilder, javaType );
+ this.operator = operator;
+ this.rhs = new LiteralExpression<N>( queryBuilder, rhs );
+ this.lhs = lhs;
+ }
+
+ public Operation getOperator() {
+ return operator;
+ }
+
+ public Expression<? extends N> getRightHandOperand() {
+ return rhs;
+ }
+
+ public Expression<? extends N> getLeftHandOperand() {
+ return lhs;
+ }
+}
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryOperatorExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryOperatorExpression.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryOperatorExpression.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -0,0 +1,45 @@
+/*
+ * 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.criteria.expression;
+
+import javax.persistence.criteria.Expression;
+
+/**
+ * Contract for operators with two operands.
+ *
+ * @author Steve Ebersole
+ */
+public interface BinaryOperatorExpression<T> extends Expression<T> {
+ /**
+ * Get the right-hand operand.
+ *
+ * @return The right-hand operand.
+ */
+ public Expression<?> getRightHandOperand();
+
+ /**
+ * Get the left-hand operand.
+ *
+ * @return The left-hand operand.
+ */
+ public Expression<?> getLeftHandOperand();
+}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SubqueryComparisonModifierExpression.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -0,0 +1,36 @@
+package org.hibernate.ejb.criteria.expression;
+
+import javax.persistence.criteria.Subquery;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+
+/**
+ * Represents a {@link Modifier#ALL}, {@link Modifier#ANY}, {@link Modifier#SOME} modifier appplied to a subquery as
+ * part of a comparison.
+ *
+ * @author Steve Ebersole
+ */
+public class SubqueryComparisonModifierExpression<Y> extends ExpressionImpl<Y> {
+ public static enum Modifier { ALL, SOME, ANY };
+
+ private final Subquery<Y> subquery;
+ private final Modifier modifier;
+
+ public SubqueryComparisonModifierExpression(
+ QueryBuilderImpl queryBuilder,
+ Class<Y> javaType,
+ Subquery<Y> subquery,
+ Modifier modifier) {
+ super(queryBuilder, javaType);
+ this.subquery = subquery;
+ this.modifier = modifier;
+ }
+
+ public Modifier getModifier() {
+ return modifier;
+ }
+
+ public Subquery<Y> getSubquery() {
+ return subquery;
+ }
+
+}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryArithmeticOperation.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -0,0 +1,39 @@
+package org.hibernate.ejb.criteria.expression;
+
+import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+
+/**
+ * Models arithmetc operations with two operands.
+ *
+ * @author Steve Ebersole
+ */
+public class UnaryArithmeticOperation<T>
+ extends ExpressionImpl<T>
+ implements UnaryOperatorExpression<T> {
+
+ public static enum Operation {
+ UNARY_PLUS, UNARY_MINUS
+ }
+
+ private final Operation operation;
+ private final Expression<T> operand;
+
+ public UnaryArithmeticOperation(
+ QueryBuilderImpl queryBuilder,
+ Operation operation,
+ Expression<T> operand) {
+ super( queryBuilder, operand.getJavaType() );
+ this.operation = operation;
+ this.operand = operand;
+ }
+
+ public Expression<T> getOperand() {
+ return operand;
+ }
+
+ public Operation getOperation() {
+ return operation;
+ }
+
+}
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryOperatorExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryOperatorExpression.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryOperatorExpression.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -0,0 +1,38 @@
+/*
+ * 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.criteria.expression;
+
+import javax.persistence.criteria.Expression;
+
+/**
+ * Contract for operators with a single operand.
+ *
+ * @author Steve Ebersole
+ */
+public interface UnaryOperatorExpression<T> extends Expression<T> {
+ /**
+ * Get the operand.
+ *
+ * @return The operand.
+ */
+ public Expression<?> getOperand();
+}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AbsFunction.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -0,0 +1,40 @@
+/*
+ * 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.criteria.expression.function;
+
+import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+
+/**
+ * Models the ANSI SQL <tt>ABS</tt> function.
+ *
+ * @author Steve Ebersole
+ */
+public class AbsFunction<N extends Number>
+ extends BasicFunctionExpression<N> {
+
+ public static final String NAME = "abs";
+
+ public AbsFunction(QueryBuilderImpl queryBuilder, Expression<N> expression) {
+ super( queryBuilder, 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-08-06 18:39:33 UTC (rev 17250)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AggregationFunction.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -1,7 +1,26 @@
+/*
+ * 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.criteria.expression.function;
-import java.util.Collections;
-import java.util.List;
import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
@@ -12,8 +31,6 @@
* @author Steve Ebersole
*/
public class AggregationFunction<T> extends BasicFunctionExpression<T> {
- private static final List<Expression<?>> NO_ARGS = Collections.emptyList();
-
/**
* Constructs an aggregation function with no arguments (<tt>COUNT(*)</tt> e.g.).
*
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-08-06 18:39:33 UTC (rev 17250)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/BasicFunctionExpression.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -25,22 +25,35 @@
import org.hibernate.ejb.criteria.expression.*;
import java.util.List;
import java.util.Arrays;
+import java.util.Collections;
import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
- * TODO : javadoc
+ * Models the basic conept of a SQL function.
*
* @author Steve Ebersole
*/
-public class BasicFunctionExpression<X> extends ExpressionImpl<X> implements FunctionExpression<X> {
+public class BasicFunctionExpression<X>
+ extends ExpressionImpl<X>
+ implements FunctionExpression<X> {
+
+ public static final List<Expression<?>> NO_ARGS = Collections.emptyList();
+
private final String functionName;
private final List<Expression<?>> argumentExpressions;
public BasicFunctionExpression(
QueryBuilderImpl queryBuilder,
Class<X> javaType,
+ String functionName) {
+ this( queryBuilder, javaType, functionName, NO_ARGS );
+ }
+
+ public BasicFunctionExpression(
+ QueryBuilderImpl queryBuilder,
+ Class<X> javaType,
String functionName,
List<Expression<?>> argumentExpressions) {
super( queryBuilder, javaType );
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CurrentDateFunction.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -0,0 +1,37 @@
+/*
+ * 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.criteria.expression.function;
+
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+
+/**
+ * Models the ANSI SQL <tt>CURRENT_DATE</tt> function.
+ *
+ * @author Steve Ebersole
+ */
+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 );
+ }
+}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CurrentTimeFunction.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -0,0 +1,37 @@
+/*
+ * 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.criteria.expression.function;
+
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+
+/**
+ * Models the ANSI SQL <tt>CURRENT_TIME</tt> function.
+ *
+ * @author Steve Ebersole
+ */
+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 );
+ }
+}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CurrentTimestampFunction.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -0,0 +1,38 @@
+/*
+ * 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.criteria.expression.function;
+
+import java.sql.Timestamp;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+
+/**
+ * Models the ANSI SQL <tt>CURRENT_TIMESTAMP</tt> function.
+ *
+ * @author Steve Ebersole
+ */
+public class CurrentTimestampFunction extends BasicFunctionExpression<Timestamp> {
+ public static final String NAME = "current_timestamp";
+
+ public CurrentTimestampFunction(QueryBuilderImpl queryBuilder) {
+ super( queryBuilder, Timestamp.class, NAME );
+ }
+}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/FunctionExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/FunctionExpression.java 2009-08-06 18:39:33 UTC (rev 17250)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/FunctionExpression.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -24,7 +24,7 @@
import javax.persistence.criteria.Expression;
/**
- * Models an expression resolved as a SQL function call.
+ * Contract for expressions which model a SQL function call.
*
* @param <T> The type of the function result.
*
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LengthFunction.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -0,0 +1,38 @@
+/*
+ * 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.criteria.expression.function;
+
+import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+
+/**
+ * Models the ANSI SQL <tt>LENGTH</tt> function.
+ *
+ * @author Steve Ebersole
+ */
+public class LengthFunction extends BasicFunctionExpression<Integer> {
+ public static final String NAME = "length";
+
+ public LengthFunction(QueryBuilderImpl queryBuilder, Expression<String> value) {
+ super( queryBuilder, Integer.class, NAME, value );
+ }
+}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LocateFunction.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -0,0 +1,88 @@
+/*
+ * 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.criteria.expression.function;
+
+import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.expression.LiteralExpression;
+
+/**
+ * Models the ANSI SQL <tt>LOCATE</tt> function.
+ *
+ * @author Steve Ebersole
+ */
+public class LocateFunction extends BasicFunctionExpression<Integer> {
+ public static final String NAME = "locate";
+
+ private final Expression<String> pattern;
+ private final Expression<String> string;
+ private final Expression<Integer> start;
+
+ public LocateFunction(
+ QueryBuilderImpl queryBuilder,
+ Expression<String> pattern,
+ Expression<String> string,
+ Expression<Integer> start) {
+ super( queryBuilder, Integer.class, NAME );
+ this.pattern = pattern;
+ this.string = string;
+ this.start = start;
+ }
+
+ public LocateFunction(
+ QueryBuilderImpl queryBuilder,
+ Expression<String> pattern,
+ Expression<String> string) {
+ this( queryBuilder, pattern, string, null );
+ }
+
+ public LocateFunction(QueryBuilderImpl queryBuilder, String pattern, Expression<String> string) {
+ this(
+ queryBuilder,
+ new LiteralExpression<String>( queryBuilder, pattern ),
+ string,
+ null
+ );
+ }
+
+ public LocateFunction(QueryBuilderImpl queryBuilder, String pattern, Expression<String> string, int start) {
+ this(
+ queryBuilder,
+ new LiteralExpression<String>( queryBuilder, pattern ),
+ string,
+ new LiteralExpression<Integer>( queryBuilder, start )
+ );
+ }
+
+ public Expression<String> getPattern() {
+ return pattern;
+ }
+
+ public Expression<Integer> getStart() {
+ return start;
+ }
+
+ public Expression<String> getString() {
+ return string;
+ }
+
+}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LowerFunction.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -0,0 +1,38 @@
+/*
+ * 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.criteria.expression.function;
+
+import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+
+/**
+ * Models the ANSI SQL <tt>LOWER</tt> function.
+ *
+ * @author Steve Ebersole
+ */
+public class LowerFunction extends BasicFunctionExpression<String> {
+ public static final String NAME = "lower";
+
+ public LowerFunction(QueryBuilderImpl queryBuilder, Expression<String> string) {
+ super( queryBuilder, String.class, NAME, string );
+ }
+}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SqrtFunction.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -0,0 +1,38 @@
+/*
+ * 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.criteria.expression.function;
+
+import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+
+/**
+ * Models the ANSI SQL <tt>SQRT</tt> function.
+ *
+ * @author Steve Ebersole
+ */
+public class SqrtFunction extends BasicFunctionExpression<Double> {
+ public static final String NAME = "sqrt";
+
+ public SqrtFunction(QueryBuilderImpl queryBuilder, Expression<? extends Number> expression) {
+ super( queryBuilder, Double.class, NAME, expression );
+ }
+}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SubstringFunction.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -0,0 +1,74 @@
+package org.hibernate.ejb.criteria.expression.function;
+
+import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.expression.LiteralExpression;
+
+/**
+ * Models the ANSI SQL <tt>SUBSTRING</tt> function.
+ *
+ * @author Steve Ebersole
+ */
+public class SubstringFunction extends BasicFunctionExpression<String> {
+ public static final String NAME = "substring";
+
+ private final Expression<String> value;
+ private final Expression<Integer> start;
+ private final Expression<Integer> length;
+
+ public SubstringFunction(
+ QueryBuilderImpl queryBuilder,
+ Expression<String> value,
+ Expression<Integer> start,
+ Expression<Integer> length) {
+ super( queryBuilder, String.class, NAME );
+ this.value = value;
+ this.start = start;
+ this.length = length;
+ }
+
+ public SubstringFunction(
+ QueryBuilderImpl queryBuilder,
+ Expression<String> value,
+ Expression<Integer> start) {
+ this( queryBuilder, value, start, (Expression<Integer>)null );
+ }
+
+ public SubstringFunction(
+ QueryBuilderImpl queryBuilder,
+ Expression<String> value,
+ int start) {
+ this(
+ queryBuilder,
+ value,
+ new LiteralExpression<Integer>( queryBuilder, start )
+ );
+ }
+
+ public SubstringFunction(
+ QueryBuilderImpl queryBuilder,
+ Expression<String> value,
+ int start,
+ int length) {
+ this(
+ queryBuilder,
+ value,
+ new LiteralExpression<Integer>( queryBuilder, start ),
+ new LiteralExpression<Integer>( queryBuilder, length )
+ );
+ }
+
+ public Expression<Integer> getLength() {
+ return length;
+ }
+
+ public Expression<Integer> getStart() {
+ return start;
+ }
+
+ public Expression<String> getValue() {
+ return value;
+ }
+
+
+}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/TrimFunction.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -0,0 +1,83 @@
+package org.hibernate.ejb.criteria.expression.function;
+
+import javax.persistence.criteria.Expression;
+import javax.persistence.criteria.QueryBuilder.Trimspec;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.expression.LiteralExpression;
+
+/**
+ * Models the ANSI SQL <tt>TRIM</tt> function.
+ *
+ * @author Steve Ebersole
+ */
+public class TrimFunction extends BasicFunctionExpression<String> {
+ public static final String NAME = "trim";
+ public static final Trimspec DEFAULT_TRIMSPEC = Trimspec.BOTH;
+ public static final char DEFAULT_TRIM_CHAR = ' ';
+
+ private final Trimspec trimspec;
+ private final Expression<Character> trimCharacter;
+ private final Expression<String> trimSource;
+
+ public TrimFunction(
+ QueryBuilderImpl queryBuilder,
+ Trimspec trimspec,
+ Expression<Character> trimCharacter,
+ Expression<String> trimSource) {
+ super( queryBuilder, String.class, NAME );
+ this.trimspec = trimspec;
+ this.trimCharacter = trimCharacter;
+ this.trimSource = trimSource;
+ }
+
+ public TrimFunction(
+ QueryBuilderImpl queryBuilder,
+ Trimspec trimspec,
+ char trimCharacter,
+ Expression<String> trimSource) {
+ super( queryBuilder, String.class, NAME );
+ this.trimspec = trimspec;
+ this.trimCharacter = new LiteralExpression<Character>( queryBuilder, trimCharacter );
+ this.trimSource = trimSource;
+ }
+
+ public TrimFunction(
+ QueryBuilderImpl queryBuilder,
+ Expression<String> trimSource) {
+ this( queryBuilder, DEFAULT_TRIMSPEC, DEFAULT_TRIM_CHAR, trimSource );
+ }
+
+ public TrimFunction(
+ QueryBuilderImpl queryBuilder,
+ Expression<Character> trimCharacter,
+ Expression<String> trimSource) {
+ this( queryBuilder, DEFAULT_TRIMSPEC, trimCharacter, trimSource );
+ }
+
+ public TrimFunction(
+ QueryBuilderImpl queryBuilder,
+ char trimCharacter,
+ Expression<String> trimSource) {
+ this( queryBuilder, DEFAULT_TRIMSPEC, trimCharacter, trimSource );
+ }
+
+ public TrimFunction(
+ QueryBuilderImpl queryBuilder,
+ Trimspec trimspec,
+ Expression<String> trimSource) {
+ this( queryBuilder, trimspec, DEFAULT_TRIM_CHAR, trimSource );
+ }
+
+ public Expression<Character> getTrimCharacter() {
+ return trimCharacter;
+ }
+
+ public Expression<String> getTrimSource() {
+ return trimSource;
+ }
+
+ public Trimspec getTrimspec() {
+ return trimspec;
+ }
+
+}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/UpperFunction.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -0,0 +1,38 @@
+/*
+ * 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.criteria.expression.function;
+
+import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+
+/**
+ * Models the ANSI SQL <tt>UPPER</tt> function.
+ *
+ * @author Steve Ebersole
+ */
+public class UpperFunction extends BasicFunctionExpression<String> {
+ public static final String NAME = "upper";
+
+ public UpperFunction(QueryBuilderImpl queryBuilder, Expression<String> string) {
+ super( queryBuilder, String.class, NAME, string );
+ }
+}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/LikePredicate.java 2009-08-07 12:12:20 UTC (rev 17251)
@@ -0,0 +1,115 @@
+/*
+ * 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.criteria.predicate;
+
+import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.expression.LiteralExpression;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class LikePredicate extends AbstractSimplePredicate {
+ private final Expression<String> matchExpression;
+ private final Expression<String> pattern;
+ private final Expression<Character> escapeCharacter;
+
+ public LikePredicate(
+ QueryBuilderImpl queryBuilder,
+ Expression<String> matchExpression,
+ Expression<String> pattern) {
+ this( queryBuilder, matchExpression, pattern, null );
+ }
+
+ public LikePredicate(
+ QueryBuilderImpl queryBuilder,
+ Expression<String> matchExpression,
+ String pattern) {
+ this( queryBuilder, matchExpression, new LiteralExpression<String>( queryBuilder, pattern) );
+ }
+
+ public LikePredicate(
+ QueryBuilderImpl queryBuilder,
+ Expression<String> matchExpression,
+ Expression<String> pattern,
+ Expression<Character> escapeCharacter) {
+ super( queryBuilder );
+ this.matchExpression = matchExpression;
+ this.pattern = pattern;
+ this.escapeCharacter = escapeCharacter;
+ }
+
+ public LikePredicate(
+ QueryBuilderImpl queryBuilder,
+ Expression<String> matchExpression,
+ Expression<String> pattern,
+ char escapeCharacter) {
+ this(
+ queryBuilder,
+ matchExpression,
+ pattern,
+ new LiteralExpression<Character>( queryBuilder, escapeCharacter )
+ );
+ }
+
+ public LikePredicate(
+ QueryBuilderImpl queryBuilder,
+ Expression<String> matchExpression,
+ String pattern,
+ char escapeCharacter) {
+ this(
+ queryBuilder,
+ matchExpression,
+ new LiteralExpression<String>( queryBuilder, pattern ),
+ new LiteralExpression<Character>( queryBuilder, escapeCharacter )
+ );
+ }
+
+ public LikePredicate(
+ QueryBuilderImpl queryBuilder,
+ Expression<String> matchExpression,
+ String pattern,
+ Expression<Character> escapeCharacter) {
+ this(
+ queryBuilder,
+ matchExpression,
+ new LiteralExpression<String>( queryBuilder, pattern ),
+ escapeCharacter
+ );
+ }
+
+ public Expression<Character> getEscapeCharacter() {
+ return escapeCharacter;
+ }
+
+ public Expression<String> getMatchExpression() {
+ return matchExpression;
+ }
+
+ public Expression<String> getPattern() {
+ return pattern;
+ }
+
+
+}
15 years, 4 months
Hibernate SVN: r17250 - core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-08-06 14:39:33 -0400 (Thu, 06 Aug 2009)
New Revision: 17250
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.java
Log:
EJB-447 : Implement JPA 2.0 criteria apis (revert to strict method sigs)
Modified: 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-08-06 18:30:13 UTC (rev 17249)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.java 2009-08-06 18:39:33 UTC (rev 17250)
@@ -549,28 +549,28 @@
/**
* {@inheritDoc}
*/
- public <N extends Number> AggregationFunction.AVG avg(Expression<N> x) {
+ public <N extends Number> Expression<Double> avg(Expression<N> x) {
return new AggregationFunction.AVG( this, x );
}
/**
* {@inheritDoc}
*/
- public <N extends Number> AggregationFunction.SUM<N> sum(Expression<N> x) {
+ public <N extends Number> Expression<N> sum(Expression<N> x) {
return new AggregationFunction.SUM<N>( this, x );
}
/**
* {@inheritDoc}
*/
- public <N extends Number> AggregationFunction.MAX<N> max(Expression<N> x) {
+ public <N extends Number> Expression<N> max(Expression<N> x) {
return new AggregationFunction.MAX<N>( this, x );
}
/**
* {@inheritDoc}
*/
- public <N extends Number> AggregationFunction.MIN<N> min(Expression<N> x) {
+ public <N extends Number> Expression<N> min(Expression<N> x) {
return new AggregationFunction.MIN<N>( this, x );
}
15 years, 4 months
Hibernate SVN: r17249 - in core/branches/envers-hibernate-3.3/src: main/java/org/hibernate/envers/configuration and 11 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-08-06 14:30:13 -0400 (Thu, 06 Aug 2009)
New Revision: 17249
Added:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/RelationTargetAuditMode.java
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/manytoone/
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/TargetNotAuditedEntity.java
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/manytoone/
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/RelationNotAuditedTarget.java
Removed:
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/TargetNotAuditedEntity.java
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/RelationNotAuditedTarget.java
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/Audited.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/EntitiesConfigurator.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/PropertyAuditingData.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/EntitiesConfigurations.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java
Log:
svn merge -r 16710:17248 https://svn.jboss.org/repos/hibernate/core/trunk/envers .
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/Audited.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/Audited.java 2009-08-06 18:21:38 UTC (rev 17248)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/Audited.java 2009-08-06 18:30:13 UTC (rev 17249)
@@ -32,9 +32,17 @@
* When applied to a class, indicates that all of its properties should be audited.
* When applied to a field, indicates that this field should be audited.
* @author Adam Warski (adam at warski dot org)
+ * @author Tomasz Bech
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
public @interface Audited {
ModificationStore modStore() default ModificationStore.FULL;
+
+ /**
+ * @return Specifies if the entity that is the target of the relation should be audited or not. If not, then when
+ * reading a historic version an audited entity, the realtion will always point to the "current" entity.
+ * This is useful for dictionary-like entities, which don't change and don't need to be audited.
+ */
+ RelationTargetAuditMode targetAuditMode() default RelationTargetAuditMode.AUDITED;
}
Copied: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/RelationTargetAuditMode.java (from rev 17248, core/trunk/envers/src/main/java/org/hibernate/envers/RelationTargetAuditMode.java)
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/RelationTargetAuditMode.java (rev 0)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/RelationTargetAuditMode.java 2009-08-06 18:30:13 UTC (rev 17249)
@@ -0,0 +1,32 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, 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.envers;
+
+/**
+ * @author Tomasz Bech
+ */
+public enum RelationTargetAuditMode {
+ AUDITED,
+ NOT_AUDITED
+}
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/EntitiesConfigurator.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/EntitiesConfigurator.java 2009-08-06 18:21:38 UTC (rev 17248)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/EntitiesConfigurator.java 2009-08-06 18:30:13 UTC (rev 17249)
@@ -84,9 +84,13 @@
}
EntityXmlMappingData xmlMappingData = new EntityXmlMappingData();
- auditMetaGen.generateFirstPass(pc, auditData, xmlMappingData);
+ auditMetaGen.generateFirstPass(pc, auditData, xmlMappingData, true);
xmlMappings.put(pc, xmlMappingData);
- }
+ } else {
+ EntityXmlMappingData xmlMappingData = new EntityXmlMappingData();
+ auditMetaGen.generateFirstPass(pc, auditData, xmlMappingData, false);
+ xmlMappings.put(pc, xmlMappingData);
+ }
}
// Second pass
@@ -123,7 +127,8 @@
}
}
- return new EntitiesConfigurations(auditMetaGen.getEntitiesConfigurations());
+ return new EntitiesConfigurations(auditMetaGen.getEntitiesConfigurations(),
+ auditMetaGen.getNotAuditedEntitiesConfigurations());
}
// todo
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-08-06 18:21:38 UTC (rev 17248)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-08-06 18:30:13 UTC (rev 17249)
@@ -53,6 +53,7 @@
/**
* @author Adam Warski (adam at warski dot org)
* @author Sebastian Komander
+ * @author Tomasz Bech
*/
public final class AuditMetadataGenerator {
private final Configuration cfg;
@@ -66,6 +67,7 @@
private final ToOneRelationMetadataGenerator toOneRelationMetadataGenerator;
private final Map<String, EntityConfiguration> entitiesConfigurations;
+ private final Map<String, EntityConfiguration> notAuditedEntitiesConfigurations;
// Map entity name -> (join descriptor -> element describing the "versioned" join)
private final Map<String, Map<Join, Element>> entitiesJoins;
@@ -84,6 +86,7 @@
this.toOneRelationMetadataGenerator = new ToOneRelationMetadataGenerator(this);
entitiesConfigurations = new HashMap<String, EntityConfiguration>();
+ notAuditedEntitiesConfigurations = new HashMap<String, EntityConfiguration>();
entitiesJoins = new HashMap<String, Map<Join, Element>>();
}
@@ -310,7 +313,7 @@
@SuppressWarnings({"unchecked"})
public void generateFirstPass(PersistentClass pc, ClassAuditingData auditingData,
- EntityXmlMappingData xmlMappingData) {
+ EntityXmlMappingData xmlMappingData, boolean isAudited) {
String schema = auditingData.getAuditTable().schema();
if (StringTools.isEmpty(schema)) {
schema = pc.getTable().getSchema();
@@ -321,6 +324,17 @@
catalog = pc.getTable().getCatalog();
}
+ if (!isAudited) {
+ String entityName = pc.getEntityName();
+ IdMappingData idMapper = idMetadataGenerator.addId(pc);
+ ExtendedPropertyMapper propertyMapper = null;
+ String parentEntityName = null;
+ EntityConfiguration entityCfg = new EntityConfiguration(entityName, idMapper, propertyMapper,
+ parentEntityName);
+ notAuditedEntitiesConfigurations.put(pc.getEntityName(), entityCfg);
+ return;
+ }
+
String entityName = pc.getEntityName();
String auditEntityName = verEntCfg.getAuditEntityName(entityName);
String auditTableName = verEntCfg.getAuditTableName(entityName, pc.getTable().getName());
@@ -437,4 +451,13 @@
throw new MappingException(message);
}
+
+ /**
+ * Get the notAuditedEntitiesConfigurations property.
+ *
+ * @return the notAuditedEntitiesConfigurations property value
+ */
+ public Map<String, EntityConfiguration> getNotAuditedEntitiesConfigurations() {
+ return notAuditedEntitiesConfigurations;
+ }
}
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2009-08-06 18:21:38 UTC (rev 17248)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2009-08-06 18:30:13 UTC (rev 17249)
@@ -36,6 +36,7 @@
import org.dom4j.Element;
import org.hibernate.envers.ModificationStore;
+import org.hibernate.envers.RelationTargetAuditMode;
import org.hibernate.envers.configuration.metadata.reader.PropertyAuditingData;
import org.hibernate.envers.entities.EntityConfiguration;
import org.hibernate.envers.entities.IdMappingData;
@@ -231,7 +232,7 @@
// middle table for mapping this relation.
return StringTools.getLastComponent(entityName) + "_" + StringTools.getLastComponent(getReferencedEntityName(value.getElement()));
} else {
- // Hibernate uses a middle table for mapping this relation, so we get it's name directly.
+ // Hibernate uses a middle table for mapping this relation, so we get it's name directly.
return value.getCollectionTable().getName();
}
}
@@ -413,7 +414,7 @@
} else {
// Last but one parameter: collection components are always insertable
boolean mapped = mainGenerator.getBasicMetadataGenerator().addBasic(xmlMapping,
- new PropertyAuditingData(prefix, "field", ModificationStore.FULL), value, null,
+ new PropertyAuditingData(prefix, "field", ModificationStore.FULL, RelationTargetAuditMode.AUDITED), value, null,
true, true);
if (mapped) {
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java 2009-08-06 18:21:38 UTC (rev 17248)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java 2009-08-06 18:30:13 UTC (rev 17249)
@@ -28,6 +28,7 @@
import org.dom4j.Element;
import org.dom4j.tree.DefaultElement;
import org.hibernate.envers.ModificationStore;
+import org.hibernate.envers.RelationTargetAuditMode;
import org.hibernate.envers.configuration.metadata.reader.PropertyAuditingData;
import org.hibernate.envers.entities.IdMappingData;
import org.hibernate.envers.entities.PropertyData;
@@ -133,6 +134,6 @@
private PropertyAuditingData getIdPersistentPropertyAuditingData(Property property) {
return new PropertyAuditingData(property.getName(), property.getPropertyAccessorName(),
- ModificationStore.FULL);
+ ModificationStore.FULL, RelationTargetAuditMode.AUDITED);
}
}
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java 2009-08-06 18:21:38 UTC (rev 17248)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java 2009-08-06 18:30:13 UTC (rev 17249)
@@ -24,6 +24,7 @@
package org.hibernate.envers.configuration.metadata;
import org.dom4j.Element;
+import org.hibernate.envers.RelationTargetAuditMode;
import org.hibernate.envers.entities.EntityConfiguration;
import org.hibernate.envers.entities.IdMappingData;
import org.hibernate.envers.entities.PropertyData;
@@ -54,10 +55,22 @@
CompositeMapperBuilder mapper, String entityName, boolean insertable) {
String referencedEntityName = ((ToOne) value).getReferencedEntityName();
- EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().get(referencedEntityName);
- if (configuration == null) {
- throw new MappingException("An audited relation to a non-audited entity " + referencedEntityName + "!");
- }
+ EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().get(referencedEntityName);
+ if (configuration == null) {
+ configuration = mainGenerator.getNotAuditedEntitiesConfigurations().get(referencedEntityName);
+ if (configuration != null) {
+ RelationTargetAuditMode relationTargetAuditMode = propertyAuditingData.getRelationTargetAuditMode();
+ if (!RelationTargetAuditMode.NOT_AUDITED.equals(relationTargetAuditMode)) {
+ throw new MappingException("An audited relation from " + entityName + "."
+ + propertyAuditingData.getName() + " to a not audited entity " + referencedEntityName + "!"
+ + ". Such mapping is possible, but has to be strictly defined using RelationTargetAuditMode.NOT_AUDITED in @Audited.");
+ }
+ }
+ }
+ if (configuration == null) {
+ throw new MappingException("An audited relation from " + entityName + "."
+ + propertyAuditingData.getName() + " to a not audited entity " + referencedEntityName + "!");
+ }
IdMappingData idMapping = configuration.getIdMappingData();
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java 2009-08-06 18:21:38 UTC (rev 17248)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java 2009-08-06 18:30:13 UTC (rev 17249)
@@ -160,6 +160,7 @@
Versioned ver = property.getAnnotation(Versioned.class);
if (aud != null) {
propertyData.setStore(aud.modStore());
+ propertyData.setRelationTargetAuditMode(aud.targetAuditMode());
} else if (ver != null) {
propertyData.setStore(ModificationStore.FULL);
} else {
@@ -203,7 +204,7 @@
/***
* Add the {@link org.hibernate.envers.AuditOverride} annotations.
- *
+ *
* @param property the property being processed
* @param propertyData the Envers auditing data for this property
*/
@@ -220,13 +221,13 @@
/**
* Process the {@link org.hibernate.envers.AuditOverride} annotations for this property.
- *
+ *
* @param property
* the property for which the {@link org.hibernate.envers.AuditOverride}
* annotations are being processed
* @param propertyData
* the Envers auditing data for this property
- * @return {@code false} if isAudited() of the override annotation was set to
+ * @return {@code false} if isAudited() of the override annotation was set to
*/
private boolean processPropertyAuditingOverrides(XProperty property, PropertyAuditingData propertyData) {
// if this property is part of a component, process all override annotations
@@ -236,7 +237,7 @@
if (property.getName().equals(override.name())) {
// the override applies to this property
if (!override.isAudited()) {
- return false;
+ return false;
} else {
if (override.auditJoinTable() != null) {
propertyData.setJoinTable(override.auditJoinTable());
@@ -267,7 +268,7 @@
} catch (ClassNotFoundException e) {
throw new MappingException(e);
}
-
+
this.component = component;
}
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/PropertyAuditingData.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/PropertyAuditingData.java 2009-08-06 18:21:38 UTC (rev 17248)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/PropertyAuditingData.java 2009-08-06 18:30:13 UTC (rev 17249)
@@ -31,6 +31,7 @@
import org.hibernate.envers.AuditOverrides;
import org.hibernate.envers.ModificationStore;
import org.hibernate.envers.AuditJoinTable;
+import org.hibernate.envers.RelationTargetAuditMode;
import org.hibernate.envers.entities.PropertyData;
/**
@@ -44,15 +45,18 @@
private AuditJoinTable joinTable;
private String accessType;
private final List<AuditOverride> auditJoinTableOverrides = new ArrayList<AuditOverride>(0);
+ private RelationTargetAuditMode relationTargetAuditMode;
- public PropertyAuditingData() {
+ public PropertyAuditingData() {
}
- public PropertyAuditingData(String name, String accessType, ModificationStore store) {
+ public PropertyAuditingData(String name, String accessType, ModificationStore store,
+ RelationTargetAuditMode relationTargetAuditMode) {
this.name = name;
this.beanName = name;
this.accessType = accessType;
this.store = store;
+ this.relationTargetAuditMode = relationTargetAuditMode;
}
public String getName() {
@@ -108,7 +112,7 @@
}
public List<AuditOverride> getAuditingOverrides() {
- return auditJoinTableOverrides;
+ return auditJoinTableOverrides;
}
public void addAuditingOverride(AuditOverride annotation) {
@@ -135,4 +139,22 @@
}
}
+ /**
+ * Get the relationTargetAuditMode property.
+ *
+ * @return the relationTargetAuditMode property value
+ */
+ public RelationTargetAuditMode getRelationTargetAuditMode() {
+ return relationTargetAuditMode;
+ }
+
+ /**
+ * Set the relationTargetAuditMode property value.
+ *
+ * @param relationTargetAuditMode the relationTargetAuditMode to set
+ */
+ public void setRelationTargetAuditMode(RelationTargetAuditMode relationTargetAuditMode) {
+ this.relationTargetAuditMode = relationTargetAuditMode;
+ }
+
}
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/EntitiesConfigurations.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/EntitiesConfigurations.java 2009-08-06 18:21:38 UTC (rev 17248)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/EntitiesConfigurations.java 2009-08-06 18:30:13 UTC (rev 17249)
@@ -32,12 +32,15 @@
*/
public class EntitiesConfigurations {
private Map<String, EntityConfiguration> entitiesConfigurations;
+ private Map<String, EntityConfiguration> notAuditedEntitiesConfigurations;
// Map versions entity name -> entity name
private Map<String, String> entityNamesForVersionsEntityNames = new HashMap<String, String>();
- public EntitiesConfigurations(Map<String, EntityConfiguration> entitiesConfigurations) {
+ public EntitiesConfigurations(Map<String, EntityConfiguration> entitiesConfigurations,
+ Map<String, EntityConfiguration> notAuditedEntitiesConfigurations) {
this.entitiesConfigurations = entitiesConfigurations;
+ this.notAuditedEntitiesConfigurations = notAuditedEntitiesConfigurations;
generateBidirectionRelationInfo();
generateVersionsEntityToEntityNames();
@@ -61,14 +64,17 @@
// If this is an "owned" relation, checking the related entity, if it has a relation that has
// a mapped-by attribute to the currently checked. If so, this is a bidirectional relation.
if (relDesc.getRelationType() == RelationType.TO_ONE ||
- relDesc.getRelationType() == RelationType.TO_MANY_MIDDLE) {
- for (RelationDescription other : entitiesConfigurations.get(relDesc.getToEntityName()).getRelationsIterator()) {
- if (relDesc.getFromPropertyName().equals(other.getMappedByPropertyName()) &&
- (entityName.equals(other.getToEntityName()))) {
- relDesc.setBidirectional(true);
- other.setBidirectional(true);
- }
- }
+ relDesc.getRelationType() == RelationType.TO_MANY_MIDDLE) {
+ EntityConfiguration entityConfiguration = entitiesConfigurations.get(relDesc.getToEntityName());
+ if (entityConfiguration != null) {
+ for (RelationDescription other : entityConfiguration.getRelationsIterator()) {
+ if (relDesc.getFromPropertyName().equals(other.getMappedByPropertyName()) &&
+ (entityName.equals(other.getToEntityName()))) {
+ relDesc.setBidirectional(true);
+ other.setBidirectional(true);
+ }
+ }
+ }
}
}
}
@@ -78,6 +84,10 @@
return entitiesConfigurations.get(entityName);
}
+ public EntityConfiguration getNotVersionEntityConfiguration(String entityName) {
+ return notAuditedEntitiesConfigurations.get(entityName);
+ }
+
public String getEntityNameForVersionsEntityName(String versionsEntityName) {
return entityNamesForVersionsEntityNames.get(versionsEntityName);
}
@@ -98,4 +108,5 @@
return null;
}
}
+
}
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java 2009-08-06 18:21:38 UTC (rev 17248)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java 2009-08-06 18:30:13 UTC (rev 17249)
@@ -82,7 +82,7 @@
Class<?> entityClass = ReflectionTools.loadClass(referencedEntityName);
value = versionsReader.getSessionImplementor().getFactory().getEntityPersister(referencedEntityName).
- createProxy(null, new ToOneDelegateSessionImplementor(versionsReader, entityClass, entityId, revision));
+ createProxy(null, new ToOneDelegateSessionImplementor(versionsReader, entityClass, entityId, revision, verCfg));
}
}
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java 2009-08-06 18:21:38 UTC (rev 17248)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java 2009-08-06 18:30:13 UTC (rev 17249)
@@ -23,29 +23,47 @@
*/
package org.hibernate.envers.entities.mapper.relation.lazy;
+import java.io.Serializable;
+
+import org.hibernate.envers.configuration.AuditConfiguration;
+import org.hibernate.envers.entities.EntitiesConfigurations;
+import org.hibernate.envers.entities.EntityConfiguration;
import org.hibernate.envers.reader.AuditReaderImplementor;
import org.hibernate.HibernateException;
+import org.hibernate.Session;
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Tomasz Bech
*/
public class ToOneDelegateSessionImplementor extends AbstractDelegateSessionImplementor {
+ private static final long serialVersionUID = 4770438372940785488L;
+
private final AuditReaderImplementor versionsReader;
private final Class<?> entityClass;
private final Object entityId;
private final Number revision;
+ private EntityConfiguration notVersionedEntityConfiguration;
- public ToOneDelegateSessionImplementor(AuditReaderImplementor versionsReader,
- Class<?> entityClass, Object entityId, Number revision) {
+ public ToOneDelegateSessionImplementor(AuditReaderImplementor versionsReader,
+ Class<?> entityClass, Object entityId, Number revision,
+ AuditConfiguration verCfg) {
super(versionsReader.getSessionImplementor());
this.versionsReader = versionsReader;
this.entityClass = entityClass;
this.entityId = entityId;
this.revision = revision;
+ EntitiesConfigurations entCfg = verCfg.getEntCfg();
+ notVersionedEntityConfiguration = entCfg.getNotVersionEntityConfiguration(entityClass.getName());
}
public Object doImmediateLoad(String entityName) throws HibernateException {
- return versionsReader.find(entityClass, entityId, revision);
+ if (notVersionedEntityConfiguration == null) {
+ return versionsReader.find(entityClass, entityId, revision);
+ } else {
+ Session session = versionsReader.getSession();
+ return session.get(entityClass, (Serializable) entityId);
+ }
}
}
Copied: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/manytoone (from rev 17248, core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytoone)
Copied: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional (from rev 17248, core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional)
Deleted: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/TargetNotAuditedEntity.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/TargetNotAuditedEntity.java 2009-08-06 18:21:38 UTC (rev 17248)
+++ core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/TargetNotAuditedEntity.java 2009-08-06 18:30:13 UTC (rev 17249)
@@ -1,115 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, 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.envers.test.entities.manytoone.unidirectional;
-
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.Id;
-import javax.persistence.ManyToOne;
-
-import org.hibernate.envers.Audited;
-import org.hibernate.envers.RelationTargetAuditMode;
-import org.hibernate.envers.test.entities.UnversionedStrTestEntity;
-
-/**
- * Audited entity with a reference to not audited entity.
- * @author Toamsz Bech
- */
-@Entity
-public class TargetNotAuditedEntity {
- @Id
- private Integer id;
-
- @Audited
- private String data;
-
- @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
- @ManyToOne(fetch = FetchType.EAGER)
- private UnversionedStrTestEntity reference;
-
- public TargetNotAuditedEntity() { }
-
- public TargetNotAuditedEntity(Integer id, String data, UnversionedStrTestEntity reference) {
- this.id = id;
- this.data = data;
- this.reference = reference;
- }
-
- public TargetNotAuditedEntity(String data, UnversionedStrTestEntity reference) {
- this.data = data;
- this.reference = reference;
- }
-
- public TargetNotAuditedEntity(Integer id, String data) {
- this.id = id;
- this.data = data;
- }
-
- public Integer getId() {
- return id;
- }
-
- public void setId(Integer id) {
- this.id = id;
- }
-
- public String getData() {
- return data;
- }
-
- public void setData(String data) {
- this.data = data;
- }
-
- public UnversionedStrTestEntity getReference() {
- return reference;
- }
-
- public void setReference(UnversionedStrTestEntity reference) {
- this.reference = reference;
- }
-
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof TargetNotAuditedEntity)) return false;
-
- TargetNotAuditedEntity that = (TargetNotAuditedEntity) o;
-
- if (data != null ? !data.equals(that.data) : that.data != null) return false;
- if (id != null ? !id.equals(that.id) : that.id != null) return false;
-
- return true;
- }
-
- public int hashCode() {
- int result;
- result = (id != null ? id.hashCode() : 0);
- result = 31 * result + (data != null ? data.hashCode() : 0);
- return result;
- }
-
- public String toString() {
- return "TargetNotAuditedEntity(id = " + id + ", data = " + data + ")";
- }
-}
Copied: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/TargetNotAuditedEntity.java (from rev 17248, core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/TargetNotAuditedEntity.java)
===================================================================
--- core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/TargetNotAuditedEntity.java (rev 0)
+++ core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/TargetNotAuditedEntity.java 2009-08-06 18:30:13 UTC (rev 17249)
@@ -0,0 +1,115 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, 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.envers.test.entities.manytoone.unidirectional;
+
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+import org.hibernate.envers.Audited;
+import org.hibernate.envers.RelationTargetAuditMode;
+import org.hibernate.envers.test.entities.UnversionedStrTestEntity;
+
+/**
+ * Audited entity with a reference to not audited entity.
+ * @author Toamsz Bech
+ */
+@Entity
+public class TargetNotAuditedEntity {
+ @Id
+ private Integer id;
+
+ @Audited
+ private String data;
+
+ @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
+ @ManyToOne(fetch = FetchType.EAGER)
+ private UnversionedStrTestEntity reference;
+
+ public TargetNotAuditedEntity() { }
+
+ public TargetNotAuditedEntity(Integer id, String data, UnversionedStrTestEntity reference) {
+ this.id = id;
+ this.data = data;
+ this.reference = reference;
+ }
+
+ public TargetNotAuditedEntity(String data, UnversionedStrTestEntity reference) {
+ this.data = data;
+ this.reference = reference;
+ }
+
+ public TargetNotAuditedEntity(Integer id, String data) {
+ this.id = id;
+ this.data = data;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public UnversionedStrTestEntity getReference() {
+ return reference;
+ }
+
+ public void setReference(UnversionedStrTestEntity reference) {
+ this.reference = reference;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof TargetNotAuditedEntity)) return false;
+
+ TargetNotAuditedEntity that = (TargetNotAuditedEntity) o;
+
+ if (data != null ? !data.equals(that.data) : that.data != null) return false;
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (data != null ? data.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "TargetNotAuditedEntity(id = " + id + ", data = " + data + ")";
+ }
+}
Copied: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/manytoone (from rev 17248, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytoone)
Copied: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional (from rev 17248, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional)
Deleted: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/RelationNotAuditedTarget.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/RelationNotAuditedTarget.java 2009-08-06 18:21:38 UTC (rev 17248)
+++ core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/RelationNotAuditedTarget.java 2009-08-06 18:30:13 UTC (rev 17249)
@@ -1,161 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, 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.envers.test.integration.manytoone.unidirectional;
-
-import java.util.Arrays;
-import java.util.List;
-
-import javax.persistence.EntityManager;
-
-import org.hibernate.ejb.Ejb3Configuration;
-import org.hibernate.envers.test.AbstractEntityTest;
-import org.hibernate.envers.test.entities.UnversionedStrTestEntity;
-import org.hibernate.envers.test.entities.manytoone.unidirectional.TargetNotAuditedEntity;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-/**
- * @author Tomasz Bech
- */
-public class RelationNotAuditedTarget extends AbstractEntityTest {
- private Integer tnae1_id;
- private Integer tnae2_id;
-
- private Integer uste1_id;
- private Integer uste2_id;
-
- public void configure(Ejb3Configuration cfg) {
- cfg.addAnnotatedClass(TargetNotAuditedEntity.class);
- cfg.addAnnotatedClass(UnversionedStrTestEntity.class);
- }
-
- @BeforeClass(dependsOnMethods = "init")
- public void initData() {
- EntityManager em = getEntityManager();
-
- UnversionedStrTestEntity uste1 = new UnversionedStrTestEntity("str1");
- UnversionedStrTestEntity uste2 = new UnversionedStrTestEntity("str2");
-
- // No revision
- em.getTransaction().begin();
-
- em.persist(uste1);
- em.persist(uste2);
-
- em.getTransaction().commit();
-
- // Revision 1
- em.getTransaction().begin();
-
- uste1 = em.find(UnversionedStrTestEntity.class, uste1.getId());
- uste2 = em.find(UnversionedStrTestEntity.class, uste2.getId());
-
- TargetNotAuditedEntity tnae1 = new TargetNotAuditedEntity(1, "tnae1", uste1);
- TargetNotAuditedEntity tnae2 = new TargetNotAuditedEntity(2, "tnae2", uste2);
- em.persist(tnae1);
- em.persist(tnae2);
-
- em.getTransaction().commit();
-
- // Revision 2
- em.getTransaction().begin();
-
- tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId());
- tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId());
-
- tnae1.setReference(uste2);
- tnae2.setReference(uste1);
-
- em.getTransaction().commit();
-
- // Revision 3
- em.getTransaction().begin();
-
- tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId());
- tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId());
-
- //field not changed!!!
- tnae1.setReference(uste2);
- tnae2.setReference(uste2);
-
- em.getTransaction().commit();
-
- // Revision 4
- em.getTransaction().begin();
-
- tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId());
- tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId());
-
- tnae1.setReference(uste1);
- tnae2.setReference(uste1);
-
- em.getTransaction().commit();
-
- //
- tnae1_id = tnae1.getId();
- tnae2_id = tnae2.getId();
- uste1_id = uste1.getId();
- uste2_id = uste2.getId();
- }
-
- @Test
- public void testRevisionsCounts() {
- List<Number> revisions = getAuditReader().getRevisions(TargetNotAuditedEntity.class, tnae1_id);
- assert Arrays.asList(1, 2, 4).equals(revisions);
- revisions = getAuditReader().getRevisions(TargetNotAuditedEntity.class, tnae2_id);
- assert Arrays.asList(1, 2, 3, 4).equals(revisions);
- }
-
- @Test
- public void testHistoryOfTnae1_id() {
- UnversionedStrTestEntity uste1 = getEntityManager().find(UnversionedStrTestEntity.class, uste1_id);
- UnversionedStrTestEntity uste2 = getEntityManager().find(UnversionedStrTestEntity.class, uste2_id);
-
- TargetNotAuditedEntity rev1 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 1);
- TargetNotAuditedEntity rev2 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 2);
- TargetNotAuditedEntity rev3 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 3);
- TargetNotAuditedEntity rev4 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 4);
-
- assert rev1.getReference().equals(uste1);
- assert rev2.getReference().equals(uste2);
- assert rev3.getReference().equals(uste2);
- assert rev4.getReference().equals(uste1);
- }
-
- @Test
- public void testHistoryOfTnae2_id() {
- UnversionedStrTestEntity uste1 = getEntityManager().find(UnversionedStrTestEntity.class, uste1_id);
- UnversionedStrTestEntity uste2 = getEntityManager().find(UnversionedStrTestEntity.class, uste2_id);
-
- TargetNotAuditedEntity rev1 = getAuditReader().find(TargetNotAuditedEntity.class, tnae2_id, 1);
- TargetNotAuditedEntity rev2 = getAuditReader().find(TargetNotAuditedEntity.class, tnae2_id, 2);
- TargetNotAuditedEntity rev3 = getAuditReader().find(TargetNotAuditedEntity.class, tnae2_id, 3);
- TargetNotAuditedEntity rev4 = getAuditReader().find(TargetNotAuditedEntity.class, tnae2_id, 4);
-
- assert rev1.getReference().equals(uste2);
- assert rev2.getReference().equals(uste1);
- assert rev3.getReference().equals(uste2);
- assert rev4.getReference().equals(uste1);
- }
-}
Copied: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/RelationNotAuditedTarget.java (from rev 17248, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/RelationNotAuditedTarget.java)
===================================================================
--- core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/RelationNotAuditedTarget.java (rev 0)
+++ core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/RelationNotAuditedTarget.java 2009-08-06 18:30:13 UTC (rev 17249)
@@ -0,0 +1,161 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, 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.envers.test.integration.manytoone.unidirectional;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.entities.UnversionedStrTestEntity;
+import org.hibernate.envers.test.entities.manytoone.unidirectional.TargetNotAuditedEntity;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * @author Tomasz Bech
+ */
+public class RelationNotAuditedTarget extends AbstractEntityTest {
+ private Integer tnae1_id;
+ private Integer tnae2_id;
+
+ private Integer uste1_id;
+ private Integer uste2_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(TargetNotAuditedEntity.class);
+ cfg.addAnnotatedClass(UnversionedStrTestEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ UnversionedStrTestEntity uste1 = new UnversionedStrTestEntity("str1");
+ UnversionedStrTestEntity uste2 = new UnversionedStrTestEntity("str2");
+
+ // No revision
+ em.getTransaction().begin();
+
+ em.persist(uste1);
+ em.persist(uste2);
+
+ em.getTransaction().commit();
+
+ // Revision 1
+ em.getTransaction().begin();
+
+ uste1 = em.find(UnversionedStrTestEntity.class, uste1.getId());
+ uste2 = em.find(UnversionedStrTestEntity.class, uste2.getId());
+
+ TargetNotAuditedEntity tnae1 = new TargetNotAuditedEntity(1, "tnae1", uste1);
+ TargetNotAuditedEntity tnae2 = new TargetNotAuditedEntity(2, "tnae2", uste2);
+ em.persist(tnae1);
+ em.persist(tnae2);
+
+ em.getTransaction().commit();
+
+ // Revision 2
+ em.getTransaction().begin();
+
+ tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId());
+ tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId());
+
+ tnae1.setReference(uste2);
+ tnae2.setReference(uste1);
+
+ em.getTransaction().commit();
+
+ // Revision 3
+ em.getTransaction().begin();
+
+ tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId());
+ tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId());
+
+ //field not changed!!!
+ tnae1.setReference(uste2);
+ tnae2.setReference(uste2);
+
+ em.getTransaction().commit();
+
+ // Revision 4
+ em.getTransaction().begin();
+
+ tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId());
+ tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId());
+
+ tnae1.setReference(uste1);
+ tnae2.setReference(uste1);
+
+ em.getTransaction().commit();
+
+ //
+ tnae1_id = tnae1.getId();
+ tnae2_id = tnae2.getId();
+ uste1_id = uste1.getId();
+ uste2_id = uste2.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ List<Number> revisions = getAuditReader().getRevisions(TargetNotAuditedEntity.class, tnae1_id);
+ assert Arrays.asList(1, 2, 4).equals(revisions);
+ revisions = getAuditReader().getRevisions(TargetNotAuditedEntity.class, tnae2_id);
+ assert Arrays.asList(1, 2, 3, 4).equals(revisions);
+ }
+
+ @Test
+ public void testHistoryOfTnae1_id() {
+ UnversionedStrTestEntity uste1 = getEntityManager().find(UnversionedStrTestEntity.class, uste1_id);
+ UnversionedStrTestEntity uste2 = getEntityManager().find(UnversionedStrTestEntity.class, uste2_id);
+
+ TargetNotAuditedEntity rev1 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 1);
+ TargetNotAuditedEntity rev2 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 2);
+ TargetNotAuditedEntity rev3 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 3);
+ TargetNotAuditedEntity rev4 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 4);
+
+ assert rev1.getReference().equals(uste1);
+ assert rev2.getReference().equals(uste2);
+ assert rev3.getReference().equals(uste2);
+ assert rev4.getReference().equals(uste1);
+ }
+
+ @Test
+ public void testHistoryOfTnae2_id() {
+ UnversionedStrTestEntity uste1 = getEntityManager().find(UnversionedStrTestEntity.class, uste1_id);
+ UnversionedStrTestEntity uste2 = getEntityManager().find(UnversionedStrTestEntity.class, uste2_id);
+
+ TargetNotAuditedEntity rev1 = getAuditReader().find(TargetNotAuditedEntity.class, tnae2_id, 1);
+ TargetNotAuditedEntity rev2 = getAuditReader().find(TargetNotAuditedEntity.class, tnae2_id, 2);
+ TargetNotAuditedEntity rev3 = getAuditReader().find(TargetNotAuditedEntity.class, tnae2_id, 3);
+ TargetNotAuditedEntity rev4 = getAuditReader().find(TargetNotAuditedEntity.class, tnae2_id, 4);
+
+ assert rev1.getReference().equals(uste2);
+ assert rev2.getReference().equals(uste1);
+ assert rev3.getReference().equals(uste2);
+ assert rev4.getReference().equals(uste1);
+ }
+}
15 years, 4 months
Hibernate SVN: r17248 - in core/trunk: envers/src/main/java/org/hibernate/envers and 12 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-08-06 14:21:38 -0400 (Thu, 06 Aug 2009)
New Revision: 17248
Added:
core/trunk/envers/src/main/java/org/hibernate/envers/RelationTargetAuditMode.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytoone/
core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/
core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/TargetNotAuditedEntity.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytoone/
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/RelationNotAuditedTarget.java
Modified:
core/trunk/documentation/envers/src/main/docbook/en-US/content/configuration.xml
core/trunk/envers/src/main/java/org/hibernate/envers/Audited.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/EntitiesConfigurator.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/PropertyAuditingData.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/EntitiesConfigurations.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java
Log:
HHH-4010:
- applying patch: allow audited relations to non-audited entities
- doc update
Modified: core/trunk/documentation/envers/src/main/docbook/en-US/content/configuration.xml
===================================================================
--- core/trunk/documentation/envers/src/main/docbook/en-US/content/configuration.xml 2009-08-06 17:55:14 UTC (rev 17247)
+++ core/trunk/documentation/envers/src/main/docbook/en-US/content/configuration.xml 2009-08-06 18:21:38 UTC (rev 17248)
@@ -218,4 +218,11 @@
please see <xref linkend="exceptions"/> for a description of the additional
<literal>@AuditJoinTable</literal> annotation that you'll probably want to use.
</para>
+
+ <para>
+ If you want to audit a relation, where the target entity is not audited (that is the case for example with
+ dictionary-like entities, which don't change and don't have to be audited), just annotate it with
+ <literal>@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)</literal>. Then, when reading historic
+ versions of your entity, the relation will always point to the "current" related entity.
+ </para>
</chapter>
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/Audited.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/Audited.java 2009-08-06 17:55:14 UTC (rev 17247)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/Audited.java 2009-08-06 18:21:38 UTC (rev 17248)
@@ -32,9 +32,17 @@
* When applied to a class, indicates that all of its properties should be audited.
* When applied to a field, indicates that this field should be audited.
* @author Adam Warski (adam at warski dot org)
+ * @author Tomasz Bech
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
public @interface Audited {
ModificationStore modStore() default ModificationStore.FULL;
+
+ /**
+ * @return Specifies if the entity that is the target of the relation should be audited or not. If not, then when
+ * reading a historic version an audited entity, the realtion will always point to the "current" entity.
+ * This is useful for dictionary-like entities, which don't change and don't need to be audited.
+ */
+ RelationTargetAuditMode targetAuditMode() default RelationTargetAuditMode.AUDITED;
}
Added: core/trunk/envers/src/main/java/org/hibernate/envers/RelationTargetAuditMode.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/RelationTargetAuditMode.java (rev 0)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/RelationTargetAuditMode.java 2009-08-06 18:21:38 UTC (rev 17248)
@@ -0,0 +1,32 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, 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.envers;
+
+/**
+ * @author Tomasz Bech
+ */
+public enum RelationTargetAuditMode {
+ AUDITED,
+ NOT_AUDITED
+}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/EntitiesConfigurator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/EntitiesConfigurator.java 2009-08-06 17:55:14 UTC (rev 17247)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/EntitiesConfigurator.java 2009-08-06 18:21:38 UTC (rev 17248)
@@ -84,9 +84,13 @@
}
EntityXmlMappingData xmlMappingData = new EntityXmlMappingData();
- auditMetaGen.generateFirstPass(pc, auditData, xmlMappingData);
+ auditMetaGen.generateFirstPass(pc, auditData, xmlMappingData, true);
xmlMappings.put(pc, xmlMappingData);
- }
+ } else {
+ EntityXmlMappingData xmlMappingData = new EntityXmlMappingData();
+ auditMetaGen.generateFirstPass(pc, auditData, xmlMappingData, false);
+ xmlMappings.put(pc, xmlMappingData);
+ }
}
// Second pass
@@ -123,7 +127,8 @@
}
}
- return new EntitiesConfigurations(auditMetaGen.getEntitiesConfigurations());
+ return new EntitiesConfigurations(auditMetaGen.getEntitiesConfigurations(),
+ auditMetaGen.getNotAuditedEntitiesConfigurations());
}
// todo
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-08-06 17:55:14 UTC (rev 17247)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-08-06 18:21:38 UTC (rev 17248)
@@ -53,6 +53,7 @@
/**
* @author Adam Warski (adam at warski dot org)
* @author Sebastian Komander
+ * @author Tomasz Bech
*/
public final class AuditMetadataGenerator {
private final Configuration cfg;
@@ -66,6 +67,7 @@
private final ToOneRelationMetadataGenerator toOneRelationMetadataGenerator;
private final Map<String, EntityConfiguration> entitiesConfigurations;
+ private final Map<String, EntityConfiguration> notAuditedEntitiesConfigurations;
// Map entity name -> (join descriptor -> element describing the "versioned" join)
private final Map<String, Map<Join, Element>> entitiesJoins;
@@ -84,6 +86,7 @@
this.toOneRelationMetadataGenerator = new ToOneRelationMetadataGenerator(this);
entitiesConfigurations = new HashMap<String, EntityConfiguration>();
+ notAuditedEntitiesConfigurations = new HashMap<String, EntityConfiguration>();
entitiesJoins = new HashMap<String, Map<Join, Element>>();
}
@@ -278,7 +281,7 @@
@SuppressWarnings({"unchecked"})
public void generateFirstPass(PersistentClass pc, ClassAuditingData auditingData,
- EntityXmlMappingData xmlMappingData) {
+ EntityXmlMappingData xmlMappingData, boolean isAudited) {
String schema = auditingData.getAuditTable().schema();
if (StringTools.isEmpty(schema)) {
schema = pc.getTable().getSchema();
@@ -289,6 +292,17 @@
catalog = pc.getTable().getCatalog();
}
+ if (!isAudited) {
+ String entityName = pc.getEntityName();
+ IdMappingData idMapper = idMetadataGenerator.addId(pc);
+ ExtendedPropertyMapper propertyMapper = null;
+ String parentEntityName = null;
+ EntityConfiguration entityCfg = new EntityConfiguration(entityName, idMapper, propertyMapper,
+ parentEntityName);
+ notAuditedEntitiesConfigurations.put(pc.getEntityName(), entityCfg);
+ return;
+ }
+
String entityName = pc.getEntityName();
String auditEntityName = verEntCfg.getAuditEntityName(entityName);
String auditTableName = verEntCfg.getAuditTableName(entityName, pc.getTable().getName());
@@ -400,4 +414,13 @@
throw new MappingException(message);
}
+
+ /**
+ * Get the notAuditedEntitiesConfigurations property.
+ *
+ * @return the notAuditedEntitiesConfigurations property value
+ */
+ public Map<String, EntityConfiguration> getNotAuditedEntitiesConfigurations() {
+ return notAuditedEntitiesConfigurations;
+ }
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2009-08-06 17:55:14 UTC (rev 17247)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2009-08-06 18:21:38 UTC (rev 17248)
@@ -36,6 +36,7 @@
import org.dom4j.Element;
import org.hibernate.envers.ModificationStore;
+import org.hibernate.envers.RelationTargetAuditMode;
import org.hibernate.envers.configuration.metadata.reader.PropertyAuditingData;
import org.hibernate.envers.entities.EntityConfiguration;
import org.hibernate.envers.entities.IdMappingData;
@@ -231,7 +232,7 @@
// middle table for mapping this relation.
return StringTools.getLastComponent(entityName) + "_" + StringTools.getLastComponent(getReferencedEntityName(value.getElement()));
} else {
- // Hibernate uses a middle table for mapping this relation, so we get it's name directly.
+ // Hibernate uses a middle table for mapping this relation, so we get it's name directly.
return value.getCollectionTable().getName();
}
}
@@ -413,7 +414,7 @@
} else {
// Last but one parameter: collection components are always insertable
boolean mapped = mainGenerator.getBasicMetadataGenerator().addBasic(xmlMapping,
- new PropertyAuditingData(prefix, "field", ModificationStore.FULL), value, null,
+ new PropertyAuditingData(prefix, "field", ModificationStore.FULL, RelationTargetAuditMode.AUDITED), value, null,
true, true);
if (mapped) {
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java 2009-08-06 17:55:14 UTC (rev 17247)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java 2009-08-06 18:21:38 UTC (rev 17248)
@@ -28,6 +28,7 @@
import org.dom4j.Element;
import org.dom4j.tree.DefaultElement;
import org.hibernate.envers.ModificationStore;
+import org.hibernate.envers.RelationTargetAuditMode;
import org.hibernate.envers.configuration.metadata.reader.PropertyAuditingData;
import org.hibernate.envers.entities.IdMappingData;
import org.hibernate.envers.entities.PropertyData;
@@ -133,6 +134,6 @@
private PropertyAuditingData getIdPersistentPropertyAuditingData(Property property) {
return new PropertyAuditingData(property.getName(), property.getPropertyAccessorName(),
- ModificationStore.FULL);
+ ModificationStore.FULL, RelationTargetAuditMode.AUDITED);
}
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java 2009-08-06 17:55:14 UTC (rev 17247)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java 2009-08-06 18:21:38 UTC (rev 17248)
@@ -24,6 +24,7 @@
package org.hibernate.envers.configuration.metadata;
import org.dom4j.Element;
+import org.hibernate.envers.RelationTargetAuditMode;
import org.hibernate.envers.entities.EntityConfiguration;
import org.hibernate.envers.entities.IdMappingData;
import org.hibernate.envers.entities.PropertyData;
@@ -54,10 +55,22 @@
CompositeMapperBuilder mapper, String entityName, boolean insertable) {
String referencedEntityName = ((ToOne) value).getReferencedEntityName();
- EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().get(referencedEntityName);
- if (configuration == null) {
- throw new MappingException("An audited relation to a non-audited entity " + referencedEntityName + "!");
- }
+ EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().get(referencedEntityName);
+ if (configuration == null) {
+ configuration = mainGenerator.getNotAuditedEntitiesConfigurations().get(referencedEntityName);
+ if (configuration != null) {
+ RelationTargetAuditMode relationTargetAuditMode = propertyAuditingData.getRelationTargetAuditMode();
+ if (!RelationTargetAuditMode.NOT_AUDITED.equals(relationTargetAuditMode)) {
+ throw new MappingException("An audited relation from " + entityName + "."
+ + propertyAuditingData.getName() + " to a not audited entity " + referencedEntityName + "!"
+ + ". Such mapping is possible, but has to be strictly defined using RelationTargetAuditMode.NOT_AUDITED in @Audited.");
+ }
+ }
+ }
+ if (configuration == null) {
+ throw new MappingException("An audited relation from " + entityName + "."
+ + propertyAuditingData.getName() + " to a not audited entity " + referencedEntityName + "!");
+ }
IdMappingData idMapping = configuration.getIdMappingData();
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java 2009-08-06 17:55:14 UTC (rev 17247)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java 2009-08-06 18:21:38 UTC (rev 17248)
@@ -160,6 +160,7 @@
Versioned ver = property.getAnnotation(Versioned.class);
if (aud != null) {
propertyData.setStore(aud.modStore());
+ propertyData.setRelationTargetAuditMode(aud.targetAuditMode());
} else if (ver != null) {
propertyData.setStore(ModificationStore.FULL);
} else {
@@ -203,7 +204,7 @@
/***
* Add the {@link org.hibernate.envers.AuditOverride} annotations.
- *
+ *
* @param property the property being processed
* @param propertyData the Envers auditing data for this property
*/
@@ -220,13 +221,13 @@
/**
* Process the {@link org.hibernate.envers.AuditOverride} annotations for this property.
- *
+ *
* @param property
* the property for which the {@link org.hibernate.envers.AuditOverride}
* annotations are being processed
* @param propertyData
* the Envers auditing data for this property
- * @return {@code false} if isAudited() of the override annotation was set to
+ * @return {@code false} if isAudited() of the override annotation was set to
*/
private boolean processPropertyAuditingOverrides(XProperty property, PropertyAuditingData propertyData) {
// if this property is part of a component, process all override annotations
@@ -236,7 +237,7 @@
if (property.getName().equals(override.name())) {
// the override applies to this property
if (!override.isAudited()) {
- return false;
+ return false;
} else {
if (override.auditJoinTable() != null) {
propertyData.setJoinTable(override.auditJoinTable());
@@ -267,7 +268,7 @@
} catch (ClassNotFoundException e) {
throw new MappingException(e);
}
-
+
this.component = component;
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/PropertyAuditingData.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/PropertyAuditingData.java 2009-08-06 17:55:14 UTC (rev 17247)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/PropertyAuditingData.java 2009-08-06 18:21:38 UTC (rev 17248)
@@ -31,6 +31,7 @@
import org.hibernate.envers.AuditOverrides;
import org.hibernate.envers.ModificationStore;
import org.hibernate.envers.AuditJoinTable;
+import org.hibernate.envers.RelationTargetAuditMode;
import org.hibernate.envers.entities.PropertyData;
/**
@@ -44,15 +45,18 @@
private AuditJoinTable joinTable;
private String accessType;
private final List<AuditOverride> auditJoinTableOverrides = new ArrayList<AuditOverride>(0);
+ private RelationTargetAuditMode relationTargetAuditMode;
- public PropertyAuditingData() {
+ public PropertyAuditingData() {
}
- public PropertyAuditingData(String name, String accessType, ModificationStore store) {
+ public PropertyAuditingData(String name, String accessType, ModificationStore store,
+ RelationTargetAuditMode relationTargetAuditMode) {
this.name = name;
this.beanName = name;
this.accessType = accessType;
this.store = store;
+ this.relationTargetAuditMode = relationTargetAuditMode;
}
public String getName() {
@@ -108,7 +112,7 @@
}
public List<AuditOverride> getAuditingOverrides() {
- return auditJoinTableOverrides;
+ return auditJoinTableOverrides;
}
public void addAuditingOverride(AuditOverride annotation) {
@@ -135,4 +139,22 @@
}
}
+ /**
+ * Get the relationTargetAuditMode property.
+ *
+ * @return the relationTargetAuditMode property value
+ */
+ public RelationTargetAuditMode getRelationTargetAuditMode() {
+ return relationTargetAuditMode;
+ }
+
+ /**
+ * Set the relationTargetAuditMode property value.
+ *
+ * @param relationTargetAuditMode the relationTargetAuditMode to set
+ */
+ public void setRelationTargetAuditMode(RelationTargetAuditMode relationTargetAuditMode) {
+ this.relationTargetAuditMode = relationTargetAuditMode;
+ }
+
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/EntitiesConfigurations.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/EntitiesConfigurations.java 2009-08-06 17:55:14 UTC (rev 17247)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/EntitiesConfigurations.java 2009-08-06 18:21:38 UTC (rev 17248)
@@ -32,12 +32,15 @@
*/
public class EntitiesConfigurations {
private Map<String, EntityConfiguration> entitiesConfigurations;
+ private Map<String, EntityConfiguration> notAuditedEntitiesConfigurations;
// Map versions entity name -> entity name
private Map<String, String> entityNamesForVersionsEntityNames = new HashMap<String, String>();
- public EntitiesConfigurations(Map<String, EntityConfiguration> entitiesConfigurations) {
+ public EntitiesConfigurations(Map<String, EntityConfiguration> entitiesConfigurations,
+ Map<String, EntityConfiguration> notAuditedEntitiesConfigurations) {
this.entitiesConfigurations = entitiesConfigurations;
+ this.notAuditedEntitiesConfigurations = notAuditedEntitiesConfigurations;
generateBidirectionRelationInfo();
generateVersionsEntityToEntityNames();
@@ -61,14 +64,17 @@
// If this is an "owned" relation, checking the related entity, if it has a relation that has
// a mapped-by attribute to the currently checked. If so, this is a bidirectional relation.
if (relDesc.getRelationType() == RelationType.TO_ONE ||
- relDesc.getRelationType() == RelationType.TO_MANY_MIDDLE) {
- for (RelationDescription other : entitiesConfigurations.get(relDesc.getToEntityName()).getRelationsIterator()) {
- if (relDesc.getFromPropertyName().equals(other.getMappedByPropertyName()) &&
- (entityName.equals(other.getToEntityName()))) {
- relDesc.setBidirectional(true);
- other.setBidirectional(true);
- }
- }
+ relDesc.getRelationType() == RelationType.TO_MANY_MIDDLE) {
+ EntityConfiguration entityConfiguration = entitiesConfigurations.get(relDesc.getToEntityName());
+ if (entityConfiguration != null) {
+ for (RelationDescription other : entityConfiguration.getRelationsIterator()) {
+ if (relDesc.getFromPropertyName().equals(other.getMappedByPropertyName()) &&
+ (entityName.equals(other.getToEntityName()))) {
+ relDesc.setBidirectional(true);
+ other.setBidirectional(true);
+ }
+ }
+ }
}
}
}
@@ -78,6 +84,10 @@
return entitiesConfigurations.get(entityName);
}
+ public EntityConfiguration getNotVersionEntityConfiguration(String entityName) {
+ return notAuditedEntitiesConfigurations.get(entityName);
+ }
+
public String getEntityNameForVersionsEntityName(String versionsEntityName) {
return entityNamesForVersionsEntityNames.get(versionsEntityName);
}
@@ -98,4 +108,5 @@
return null;
}
}
+
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java 2009-08-06 17:55:14 UTC (rev 17247)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java 2009-08-06 18:21:38 UTC (rev 17248)
@@ -82,7 +82,7 @@
Class<?> entityClass = ReflectionTools.loadClass(referencedEntityName);
value = versionsReader.getSessionImplementor().getFactory().getEntityPersister(referencedEntityName).
- createProxy(null, new ToOneDelegateSessionImplementor(versionsReader, entityClass, entityId, revision));
+ createProxy(null, new ToOneDelegateSessionImplementor(versionsReader, entityClass, entityId, revision, verCfg));
}
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java 2009-08-06 17:55:14 UTC (rev 17247)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java 2009-08-06 18:21:38 UTC (rev 17248)
@@ -23,29 +23,47 @@
*/
package org.hibernate.envers.entities.mapper.relation.lazy;
+import java.io.Serializable;
+
+import org.hibernate.envers.configuration.AuditConfiguration;
+import org.hibernate.envers.entities.EntitiesConfigurations;
+import org.hibernate.envers.entities.EntityConfiguration;
import org.hibernate.envers.reader.AuditReaderImplementor;
import org.hibernate.HibernateException;
+import org.hibernate.Session;
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Tomasz Bech
*/
public class ToOneDelegateSessionImplementor extends AbstractDelegateSessionImplementor {
+ private static final long serialVersionUID = 4770438372940785488L;
+
private final AuditReaderImplementor versionsReader;
private final Class<?> entityClass;
private final Object entityId;
private final Number revision;
+ private EntityConfiguration notVersionedEntityConfiguration;
- public ToOneDelegateSessionImplementor(AuditReaderImplementor versionsReader,
- Class<?> entityClass, Object entityId, Number revision) {
+ public ToOneDelegateSessionImplementor(AuditReaderImplementor versionsReader,
+ Class<?> entityClass, Object entityId, Number revision,
+ AuditConfiguration verCfg) {
super(versionsReader.getSessionImplementor());
this.versionsReader = versionsReader;
this.entityClass = entityClass;
this.entityId = entityId;
this.revision = revision;
+ EntitiesConfigurations entCfg = verCfg.getEntCfg();
+ notVersionedEntityConfiguration = entCfg.getNotVersionEntityConfiguration(entityClass.getName());
}
public Object doImmediateLoad(String entityName) throws HibernateException {
- return versionsReader.find(entityClass, entityId, revision);
+ if (notVersionedEntityConfiguration == null) {
+ return versionsReader.find(entityClass, entityId, revision);
+ } else {
+ Session session = versionsReader.getSession();
+ return session.get(entityClass, (Serializable) entityId);
+ }
}
}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/TargetNotAuditedEntity.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/TargetNotAuditedEntity.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytoone/unidirectional/TargetNotAuditedEntity.java 2009-08-06 18:21:38 UTC (rev 17248)
@@ -0,0 +1,115 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, 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.envers.test.entities.manytoone.unidirectional;
+
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+import org.hibernate.envers.Audited;
+import org.hibernate.envers.RelationTargetAuditMode;
+import org.hibernate.envers.test.entities.UnversionedStrTestEntity;
+
+/**
+ * Audited entity with a reference to not audited entity.
+ * @author Toamsz Bech
+ */
+@Entity
+public class TargetNotAuditedEntity {
+ @Id
+ private Integer id;
+
+ @Audited
+ private String data;
+
+ @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
+ @ManyToOne(fetch = FetchType.EAGER)
+ private UnversionedStrTestEntity reference;
+
+ public TargetNotAuditedEntity() { }
+
+ public TargetNotAuditedEntity(Integer id, String data, UnversionedStrTestEntity reference) {
+ this.id = id;
+ this.data = data;
+ this.reference = reference;
+ }
+
+ public TargetNotAuditedEntity(String data, UnversionedStrTestEntity reference) {
+ this.data = data;
+ this.reference = reference;
+ }
+
+ public TargetNotAuditedEntity(Integer id, String data) {
+ this.id = id;
+ this.data = data;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public UnversionedStrTestEntity getReference() {
+ return reference;
+ }
+
+ public void setReference(UnversionedStrTestEntity reference) {
+ this.reference = reference;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof TargetNotAuditedEntity)) return false;
+
+ TargetNotAuditedEntity that = (TargetNotAuditedEntity) o;
+
+ if (data != null ? !data.equals(that.data) : that.data != null) return false;
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (data != null ? data.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "TargetNotAuditedEntity(id = " + id + ", data = " + data + ")";
+ }
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/RelationNotAuditedTarget.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/RelationNotAuditedTarget.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytoone/unidirectional/RelationNotAuditedTarget.java 2009-08-06 18:21:38 UTC (rev 17248)
@@ -0,0 +1,161 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, 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.envers.test.integration.manytoone.unidirectional;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.entities.UnversionedStrTestEntity;
+import org.hibernate.envers.test.entities.manytoone.unidirectional.TargetNotAuditedEntity;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * @author Tomasz Bech
+ */
+public class RelationNotAuditedTarget extends AbstractEntityTest {
+ private Integer tnae1_id;
+ private Integer tnae2_id;
+
+ private Integer uste1_id;
+ private Integer uste2_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(TargetNotAuditedEntity.class);
+ cfg.addAnnotatedClass(UnversionedStrTestEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ UnversionedStrTestEntity uste1 = new UnversionedStrTestEntity("str1");
+ UnversionedStrTestEntity uste2 = new UnversionedStrTestEntity("str2");
+
+ // No revision
+ em.getTransaction().begin();
+
+ em.persist(uste1);
+ em.persist(uste2);
+
+ em.getTransaction().commit();
+
+ // Revision 1
+ em.getTransaction().begin();
+
+ uste1 = em.find(UnversionedStrTestEntity.class, uste1.getId());
+ uste2 = em.find(UnversionedStrTestEntity.class, uste2.getId());
+
+ TargetNotAuditedEntity tnae1 = new TargetNotAuditedEntity(1, "tnae1", uste1);
+ TargetNotAuditedEntity tnae2 = new TargetNotAuditedEntity(2, "tnae2", uste2);
+ em.persist(tnae1);
+ em.persist(tnae2);
+
+ em.getTransaction().commit();
+
+ // Revision 2
+ em.getTransaction().begin();
+
+ tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId());
+ tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId());
+
+ tnae1.setReference(uste2);
+ tnae2.setReference(uste1);
+
+ em.getTransaction().commit();
+
+ // Revision 3
+ em.getTransaction().begin();
+
+ tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId());
+ tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId());
+
+ //field not changed!!!
+ tnae1.setReference(uste2);
+ tnae2.setReference(uste2);
+
+ em.getTransaction().commit();
+
+ // Revision 4
+ em.getTransaction().begin();
+
+ tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId());
+ tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId());
+
+ tnae1.setReference(uste1);
+ tnae2.setReference(uste1);
+
+ em.getTransaction().commit();
+
+ //
+ tnae1_id = tnae1.getId();
+ tnae2_id = tnae2.getId();
+ uste1_id = uste1.getId();
+ uste2_id = uste2.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ List<Number> revisions = getAuditReader().getRevisions(TargetNotAuditedEntity.class, tnae1_id);
+ assert Arrays.asList(1, 2, 4).equals(revisions);
+ revisions = getAuditReader().getRevisions(TargetNotAuditedEntity.class, tnae2_id);
+ assert Arrays.asList(1, 2, 3, 4).equals(revisions);
+ }
+
+ @Test
+ public void testHistoryOfTnae1_id() {
+ UnversionedStrTestEntity uste1 = getEntityManager().find(UnversionedStrTestEntity.class, uste1_id);
+ UnversionedStrTestEntity uste2 = getEntityManager().find(UnversionedStrTestEntity.class, uste2_id);
+
+ TargetNotAuditedEntity rev1 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 1);
+ TargetNotAuditedEntity rev2 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 2);
+ TargetNotAuditedEntity rev3 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 3);
+ TargetNotAuditedEntity rev4 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 4);
+
+ assert rev1.getReference().equals(uste1);
+ assert rev2.getReference().equals(uste2);
+ assert rev3.getReference().equals(uste2);
+ assert rev4.getReference().equals(uste1);
+ }
+
+ @Test
+ public void testHistoryOfTnae2_id() {
+ UnversionedStrTestEntity uste1 = getEntityManager().find(UnversionedStrTestEntity.class, uste1_id);
+ UnversionedStrTestEntity uste2 = getEntityManager().find(UnversionedStrTestEntity.class, uste2_id);
+
+ TargetNotAuditedEntity rev1 = getAuditReader().find(TargetNotAuditedEntity.class, tnae2_id, 1);
+ TargetNotAuditedEntity rev2 = getAuditReader().find(TargetNotAuditedEntity.class, tnae2_id, 2);
+ TargetNotAuditedEntity rev3 = getAuditReader().find(TargetNotAuditedEntity.class, tnae2_id, 3);
+ TargetNotAuditedEntity rev4 = getAuditReader().find(TargetNotAuditedEntity.class, tnae2_id, 4);
+
+ assert rev1.getReference().equals(uste2);
+ assert rev2.getReference().equals(uste1);
+ assert rev3.getReference().equals(uste2);
+ assert rev4.getReference().equals(uste1);
+ }
+}
15 years, 4 months
Hibernate SVN: r17247 - in core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria: expression/function and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-08-06 13:55:14 -0400 (Thu, 06 Aug 2009)
New Revision: 17247
Added:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AggregationFunction.java
Removed:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AverageAggregrateFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SumAggregateFunction.java
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.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/FunctionExpression.java
Log:
EJB-447 : Implement JPA 2.0 criteria apis (completed aggregation function support)
Modified: 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-08-06 15:33:38 UTC (rev 17246)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.java 2009-08-06 17:55:14 UTC (rev 17247)
@@ -44,8 +44,7 @@
import org.hibernate.ejb.criteria.expression.CompoundSelectionImpl;
import org.hibernate.ejb.criteria.expression.ParameterExpressionImpl;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
-import org.hibernate.ejb.criteria.expression.function.AverageAggregrateFunction;
-import org.hibernate.ejb.criteria.expression.function.SumAggregateFunction;
+import org.hibernate.ejb.criteria.expression.function.AggregationFunction;
import org.hibernate.ejb.criteria.predicate.BooleanExpressionPredicate;
import org.hibernate.ejb.criteria.predicate.ExplicitTruthValueCheck;
import org.hibernate.ejb.criteria.predicate.TruthValue;
@@ -550,63 +549,57 @@
/**
* {@inheritDoc}
*/
- public <N extends Number> Expression<Double> avg(Expression<N> x) {
- return new AverageAggregrateFunction( this, x );
+ public <N extends Number> AggregationFunction.AVG avg(Expression<N> x) {
+ return new AggregationFunction.AVG( this, x );
}
/**
* {@inheritDoc}
*/
- public <N extends Number> Expression<N> sum(Expression<N> x) {
- return new SumAggregateFunction<N>( this, x );
+ public <N extends Number> AggregationFunction.SUM<N> sum(Expression<N> x) {
+ return new AggregationFunction.SUM<N>( this, x );
}
/**
* {@inheritDoc}
*/
- public <N extends Number> Expression<N> max(Expression<N> x) {
- // TODO : requires a MaxAggregrateFunction
- throw new UnsupportedOperationException( "Note yet implemented!" );
+ public <N extends Number> AggregationFunction.MAX<N> max(Expression<N> x) {
+ return new AggregationFunction.MAX<N>( this, x );
}
/**
* {@inheritDoc}
*/
- public <N extends Number> Expression<N> min(Expression<N> x) {
- // TODO : requires a MaxAggregrateFunction
- throw new UnsupportedOperationException( "Note yet implemented!" );
+ public <N extends Number> AggregationFunction.MIN<N> min(Expression<N> x) {
+ return new AggregationFunction.MIN<N>( this, x );
}
/**
* {@inheritDoc}
*/
public <X extends Comparable<X>> Expression<X> greatest(Expression<X> x) {
- // TODO : not exactly sure what this should be returning, same as #max ?
- throw new UnsupportedOperationException( "Note yet implemented!" );
+ return new AggregationFunction.GREATEST<X>( this, x );
}
/**
* {@inheritDoc}
*/
public <X extends Comparable<X>> Expression<X> least(Expression<X> x) {
- // TODO : not exactly sure what this should be returning, same as #min ?
- throw new UnsupportedOperationException( "Note yet implemented!" );
+ return new AggregationFunction.LEAST<X>( this, x );
}
/**
* {@inheritDoc}
*/
public Expression<Long> count(Expression<?> x) {
- // TODO : CountAggregateFunction
- throw new UnsupportedOperationException( "Note yet implemented!" );
+ return new AggregationFunction.COUNT( this, x, false );
}
/**
* {@inheritDoc}
*/
public Expression<Long> countDistinct(Expression<?> x) {
- // TODO : CountDistinctAggregateFunction or CountAggregateFunction w/ distinct parameterization
- throw new UnsupportedOperationException( "Note yet implemented!" );
+ return new AggregationFunction.COUNT( this, x, true );
}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AggregationFunction.java 2009-08-06 17:55:14 UTC (rev 17247)
@@ -0,0 +1,170 @@
+package org.hibernate.ejb.criteria.expression.function;
+
+import java.util.Collections;
+import java.util.List;
+import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.expression.LiteralExpression;
+
+/**
+ * Models SQL aggregation functions (<tt>MIN</tt>, <tt>MAX</tt>, <tt>COUNT</tt>, etc).
+ *
+ * @author Steve Ebersole
+ */
+public class AggregationFunction<T> extends BasicFunctionExpression<T> {
+ private static final List<Expression<?>> NO_ARGS = Collections.emptyList();
+
+ /**
+ * Constructs an aggregation function with no arguments (<tt>COUNT(*)</tt> e.g.).
+ *
+ * @param queryBuilder The query builder instance.
+ * @param returnType The function return type.
+ * @param functionName The name of the function.
+ */
+ public AggregationFunction(
+ QueryBuilderImpl queryBuilder,
+ Class<T> returnType,
+ String functionName) {
+ super( queryBuilder, returnType, functionName, NO_ARGS );
+ }
+
+ /**
+ * Constructs an aggregation function with a single literal argument.
+ *
+ * @param queryBuilder The query builder instance.
+ * @param returnType The function return type.
+ * @param functionName The name of the function.
+ * @param argument The literal argument
+ */
+ public AggregationFunction(
+ QueryBuilderImpl queryBuilder,
+ Class<T> returnType,
+ String functionName,
+ Object argument) {
+ this( queryBuilder, returnType, functionName, new LiteralExpression( queryBuilder, argument ) );
+ }
+
+ /**
+ * Constructs an aggregation function with a single literal argument.
+ *
+ * @param queryBuilder 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,
+ Class<T> returnType,
+ String functionName,
+ Expression<?> argument) {
+ super( queryBuilder, returnType, functionName, argument );
+ }
+
+ @Override
+ public boolean isAggregation() {
+ return true;
+ }
+
+ /**
+ * Implementation of a <tt>COUNT</tt> function providing convenience in construction.
+ * <p/>
+ * Parameterized as {@link Long} because thats what JPA states
+ * that the return from <tt>COUNT</tt> should be.
+ */
+ public static class COUNT extends AggregationFunction<Long> {
+ public static final String NAME = "count";
+
+ private final boolean distinct;
+
+ public COUNT(QueryBuilderImpl queryBuilder, Expression<?> expression, boolean distinct) {
+ super( queryBuilder, Long.class, NAME , expression );
+ this.distinct = distinct;
+ }
+
+ public boolean isDistinct() {
+ return distinct;
+ }
+
+ }
+
+ /**
+ * Implementation of a <tt>AVG</tt> function providing convenience in construction.
+ * <p/>
+ * Parameterized as {@link Double} because thats what JPA states that the return from <tt>AVG</tt> should be.
+ */
+ 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 );
+ }
+ }
+
+ /**
+ * Implementation of a <tt>SUM</tt> function providing convenience in construction.
+ * <p/>
+ * Parameterized as {@link Number N extends Number} because thats what JPA states
+ * that the return from <tt>SUM</tt> should be.
+ */
+ public static class SUM<N extends Number> extends AggregationFunction<N> {
+ public static final String NAME = "sum";
+
+ public SUM(QueryBuilderImpl queryBuilder, Expression<N> expression) {
+ super( queryBuilder, expression.getJavaType(), NAME , expression);
+ }
+ }
+
+ /**
+ * Implementation of a <tt>MIN</tt> function providing convenience in construction.
+ * <p/>
+ * Parameterized as {@link Number N extends Number} because thats what JPA states
+ * that the return from <tt>MIN</tt> should be.
+ */
+ public static class MIN<N extends Number> extends AggregationFunction<N> {
+ public static final String NAME = "min";
+
+ public MIN(QueryBuilderImpl queryBuilder, Expression<N> expression) {
+ super( queryBuilder, expression.getJavaType(), NAME , expression);
+ }
+ }
+
+ /**
+ * Implementation of a <tt>MAX</tt> function providing convenience in construction.
+ * <p/>
+ * Parameterized as {@link Number N extends Number} because thats what JPA states
+ * that the return from <tt>MAX</tt> should be.
+ */
+ public static class MAX<N extends Number> extends AggregationFunction<N> {
+ public static final String NAME = "max";
+
+ public MAX(QueryBuilderImpl queryBuilder, Expression<N> expression) {
+ super( queryBuilder, expression.getJavaType(), NAME , expression);
+ }
+ }
+
+ /**
+ * Models the <tt>MIN</tt> function in terms of non-numeric expressions.
+ *
+ * @see MIN
+ */
+ public static class LEAST<X extends Comparable<X>> extends AggregationFunction<X> {
+ public static final String NAME = "min";
+
+ public LEAST(QueryBuilderImpl queryBuilder, Expression<X> expression) {
+ super( queryBuilder, expression.getJavaType(), NAME , expression);
+ }
+ }
+
+ /**
+ * Models the <tt>MAX</tt> function in terms of non-numeric expressions.
+ *
+ * @see MAX
+ */
+ public static class GREATEST<X extends Comparable<X>> extends AggregationFunction<X> {
+ public static final String NAME = "max";
+
+ public GREATEST(QueryBuilderImpl queryBuilder, Expression<X> expression) {
+ super( queryBuilder, expression.getJavaType(), NAME , expression);
+ }
+ }
+}
Deleted: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AverageAggregrateFunction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AverageAggregrateFunction.java 2009-08-06 15:33:38 UTC (rev 17246)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AverageAggregrateFunction.java 2009-08-06 17:55:14 UTC (rev 17247)
@@ -1,42 +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.criteria.expression.function;
-
-import javax.persistence.criteria.Expression;
-
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
-
-/**
- * Implementation of a <tt>AVG</tt> function providing convenience in construction.
- * <p/>
- * Parameterized as {@link Double} because thats what JPA states that the return
- * from <tt>AVG</tt> should be.
- *
- * @author Steve Ebersole
- */
-public class AverageAggregrateFunction extends BasicFunctionExpression<Double> {
- public AverageAggregrateFunction(
- QueryBuilderImpl queryBuilder,
- Expression<? extends Number> expression) {
- super( queryBuilder, Double.class, "avg", 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-08-06 15:33:38 UTC (rev 17246)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/BasicFunctionExpression.java 2009-08-06 17:55:14 UTC (rev 17247)
@@ -21,6 +21,7 @@
*/
package org.hibernate.ejb.criteria.expression.function;
+import java.util.ArrayList;
import org.hibernate.ejb.criteria.expression.*;
import java.util.List;
import java.util.Arrays;
@@ -33,7 +34,7 @@
*
* @author Steve Ebersole
*/
-public class BasicFunctionExpression<X> extends ExpressionImpl<X> implements Expression<X> {
+public class BasicFunctionExpression<X> extends ExpressionImpl<X> implements FunctionExpression<X> {
private final String functionName;
private final List<Expression<?>> argumentExpressions;
@@ -57,10 +58,27 @@
this.argumentExpressions = Arrays.asList( argumentExpressions );
}
+ protected static List<Expression<?>> wrapAsLiterals(QueryBuilderImpl queryBuilder, Object... literalArguments) {
+ List<Expression<?>> arguments = new ArrayList<Expression<?>>( properSize( literalArguments.length) );
+ for ( Object o : literalArguments ) {
+ arguments.add( new LiteralExpression( queryBuilder, o ) );
+ }
+ return arguments;
+ }
+
+ protected static int properSize(int number) {
+ return number + (int)( number*.75 ) + 1;
+ }
+
public String getFunctionName() {
return functionName;
}
+ public boolean isAggregation() {
+ return false;
+ }
+
+
public List<Expression<?>> getArgumentExpressions() {
return argumentExpressions;
}
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-08-06 15:33:38 UTC (rev 17246)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CastFunction.java 2009-08-06 17:55:14 UTC (rev 17247)
@@ -49,6 +49,10 @@
return CAST_NAME;
}
+ public boolean isAggregation() {
+ return false;
+ }
+
public ExpressionImpl<Y> getCastSource() {
return castSource;
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/FunctionExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/FunctionExpression.java 2009-08-06 15:33:38 UTC (rev 17246)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/FunctionExpression.java 2009-08-06 17:55:14 UTC (rev 17247)
@@ -31,5 +31,17 @@
* @author Steve Ebersole
*/
public interface FunctionExpression<T> extends Expression<T> {
+ /**
+ * Retrieve the name of the function.
+ *
+ * @return The function name.
+ */
public String getFunctionName();
+
+ /**
+ * Is this function a value aggregator (like a <tt>COUNT</tt> or <tt>MAX</tt> function e.g.)?
+ *
+ * @return True if this functions does aggregation.
+ */
+ public boolean isAggregation();
}
Deleted: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SumAggregateFunction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SumAggregateFunction.java 2009-08-06 15:33:38 UTC (rev 17246)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SumAggregateFunction.java 2009-08-06 17:55:14 UTC (rev 17247)
@@ -1,42 +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.criteria.expression.function;
-
-import javax.persistence.criteria.Expression;
-
-import org.hibernate.ejb.criteria.QueryBuilderImpl;
-
-/**
- * Implementation of a <tt>SUM</tt> function providing convenience in construction.
- * <p/>
- * Parameterized as {@link Number N extends Number} because thats what JPA states
- * that the return from <tt>SUM</tt> should be.
- *
- * @author Steve Ebersole
- */
-public class SumAggregateFunction<N extends Number> extends BasicFunctionExpression<N> {
- public SumAggregateFunction(
- QueryBuilderImpl queryBuilder,
- Expression<N> expression) {
- super( queryBuilder, expression.getJavaType(), "sum", expression );
- }
-}
15 years, 4 months