HHH-4417 - Add annotation support for UserCollectionType
This commit is contained in:
parent
497f700c16
commit
36c135ab66
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) ${year}, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.annotations;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* Names a custom collection type for a persistent collection.
|
||||
*
|
||||
* @see org.hibernate.type.CollectionType
|
||||
* @see org.hibernate.usertype.UserCollectionType
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@java.lang.annotation.Target({FIELD, METHOD})
|
||||
@Retention(RUNTIME)
|
||||
public @interface CollectionType {
|
||||
/**
|
||||
* Names the type (either {@link org.hibernate.type.CollectionType} or
|
||||
* {@link org.hibernate.usertype.UserCollectionType} implementation class. Could also name a
|
||||
* custom type defined via a {@link TypeDef @TypeDef}
|
||||
*
|
||||
* @return The implementation class to use.
|
||||
*/
|
||||
String type();
|
||||
|
||||
/**
|
||||
* Specifies configuration information for the type. Note that if the named type is a
|
||||
* {@link org.hibernate.usertype.UserCollectionType}, it must also implement
|
||||
* {@link org.hibernate.usertype.ParameterizedType} in order to receive these values.
|
||||
*
|
||||
* @return The configuration parameters.
|
||||
*/
|
||||
Parameter[] parameters() default {};
|
||||
}
|
|
@ -1697,9 +1697,8 @@ public final class AnnotationBinder {
|
|||
propertyHolder.getEntityName(),
|
||||
property,
|
||||
!indexColumn.isImplicit(),
|
||||
property.isAnnotationPresent( MapKeyType.class )
|
||||
|
||||
// || property.isAnnotationPresent( ManyToAny.class )
|
||||
property.isAnnotationPresent( MapKeyType.class ),
|
||||
mappings
|
||||
);
|
||||
collectionBinder.setIndexColumn( indexColumn );
|
||||
collectionBinder.setMapKey( property.getAnnotation( MapKey.class ) );
|
||||
|
|
|
@ -23,14 +23,6 @@
|
|||
*/
|
||||
package org.hibernate.cfg.annotations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.AttributeOverrides;
|
||||
import javax.persistence.ElementCollection;
|
||||
|
@ -43,6 +35,14 @@ import javax.persistence.ManyToMany;
|
|||
import javax.persistence.MapKey;
|
||||
import javax.persistence.MapKeyColumn;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
|
@ -52,6 +52,7 @@ import org.hibernate.MappingException;
|
|||
import org.hibernate.annotations.BatchSize;
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CollectionId;
|
||||
import org.hibernate.annotations.CollectionType;
|
||||
import org.hibernate.annotations.Fetch;
|
||||
import org.hibernate.annotations.Filter;
|
||||
import org.hibernate.annotations.FilterJoinTable;
|
||||
|
@ -73,7 +74,6 @@ import org.hibernate.annotations.SQLInsert;
|
|||
import org.hibernate.annotations.SQLUpdate;
|
||||
import org.hibernate.annotations.Sort;
|
||||
import org.hibernate.annotations.SortType;
|
||||
import org.hibernate.annotations.Type;
|
||||
import org.hibernate.annotations.Where;
|
||||
import org.hibernate.annotations.WhereJoinTable;
|
||||
import org.hibernate.annotations.common.AssertionFailure;
|
||||
|
@ -252,7 +252,8 @@ public abstract class CollectionBinder {
|
|||
String entityName,
|
||||
XProperty property,
|
||||
boolean isIndexed,
|
||||
boolean isHibernateExtensionMapping) {
|
||||
boolean isHibernateExtensionMapping,
|
||||
Mappings mappings) {
|
||||
CollectionBinder result;
|
||||
if ( property.isArray() ) {
|
||||
if ( property.getElementClass().isPrimitive() ) {
|
||||
|
@ -332,11 +333,20 @@ public abstract class CollectionBinder {
|
|||
}
|
||||
result.setIsHibernateExtensionMapping( isHibernateExtensionMapping );
|
||||
|
||||
final Type typeAnnotation = property.getAnnotation( Type.class );
|
||||
final CollectionType typeAnnotation = property.getAnnotation( CollectionType.class );
|
||||
if ( typeAnnotation != null ) {
|
||||
result.explicitType = typeAnnotation.type();
|
||||
for ( Parameter param : typeAnnotation.parameters() ) {
|
||||
result.explicitTypeParameters.setProperty( param.name(), param.value() );
|
||||
final String typeName = typeAnnotation.type();
|
||||
// see if it names a type-def
|
||||
final TypeDef typeDef = mappings.getTypeDef( typeName );
|
||||
if ( typeDef != null ) {
|
||||
result.explicitType = typeDef.getTypeClass();
|
||||
result.explicitTypeParameters.putAll( typeDef.getParameters() );
|
||||
}
|
||||
else {
|
||||
result.explicitType = typeName;
|
||||
for ( Parameter param : typeAnnotation.parameters() ) {
|
||||
result.explicitTypeParameters.setProperty( param.name(), param.value() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,6 +369,7 @@ public abstract class CollectionBinder {
|
|||
}
|
||||
|
||||
public void setCollectionType(XClass collectionType) {
|
||||
// NOTE: really really badly named. This is actually NOT the collection-type, but rather the collection-element-type!
|
||||
this.collectionType = collectionType;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) ${year}, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.collection.custom.basic;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@Entity
|
||||
public class Email {
|
||||
private Long id;
|
||||
private String address;
|
||||
|
||||
Email() {
|
||||
}
|
||||
|
||||
public Email(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@Id
|
||||
@GeneratedValue( strategy = GenerationType.AUTO )
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
private void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String type) {
|
||||
this.address = type;
|
||||
}
|
||||
|
||||
public boolean equals(Object that) {
|
||||
if ( !(that instanceof Email) ) return false;
|
||||
Email p = (Email) that;
|
||||
return this.address.equals(p.address);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return address.hashCode();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) ${year}, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.collection.custom.basic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IMyList<X> extends List<X> {
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) ${year}, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.collection.custom.basic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* A custom collection class. We extend a java.util.Collection class, but that is not required.
|
||||
* It could be totally non-java-collection type, but then we would need to implement all the PersistentCollection methods.
|
||||
*
|
||||
* @author max
|
||||
*/
|
||||
public class MyList<X> extends ArrayList<X> implements IMyList<X> {
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package org.hibernate.test.usercollection.basic;
|
||||
package org.hibernate.test.collection.custom.basic;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import org.hibernate.EntityMode;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.test.usercollection.basic;
|
||||
package org.hibernate.test.collection.custom.basic;
|
||||
import org.hibernate.collection.internal.PersistentList;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) ${year}, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.collection.custom.basic;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OrderColumn;
|
||||
import javax.persistence.Transient;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.annotations.CollectionType;
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@Entity
|
||||
public class User {
|
||||
private String userName;
|
||||
private IMyList<Email> emailAddresses = new MyList<Email>();
|
||||
private Map sessionData = new HashMap();
|
||||
|
||||
User() {
|
||||
|
||||
}
|
||||
public User(String name) {
|
||||
userName = name;
|
||||
}
|
||||
|
||||
@Id
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
@OneToMany( fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true )
|
||||
@CollectionType( type = "org.hibernate.test.collection.custom.basic.MyListType" )
|
||||
@JoinColumn( name = "userName" )
|
||||
@OrderColumn( name = "displayOrder" )
|
||||
public List<Email> getEmailAddresses() {
|
||||
// does not work :(
|
||||
// public IMyList<Email> getEmailAddresses() {
|
||||
return emailAddresses;
|
||||
}
|
||||
public void setEmailAddresses(IMyList<Email> emailAddresses) {
|
||||
this.emailAddresses = emailAddresses;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public Map getSessionData() {
|
||||
return sessionData;
|
||||
}
|
||||
public void setSessionData(Map sessionData) {
|
||||
this.sessionData = sessionData;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) ${year}, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.collection.custom.basic;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class UserCollectionTypeAnnotationsVariantTest extends UserCollectionTypeTest {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { User.class, Email.class };
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) ${year}, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.collection.custom.basic;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class UserCollectionTypeHbmVariantTest extends UserCollectionTypeTest {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] { "collection/custom/basic/UserPermissions.hbm.xml" };
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.usercollection.basic;
|
||||
package org.hibernate.test.collection.custom.basic;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Session;
|
||||
|
@ -37,11 +37,7 @@ import static org.junit.Assert.assertTrue;
|
|||
/**
|
||||
* @author Max Rydahl Andersen
|
||||
*/
|
||||
public class UserCollectionTypeTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] { "usercollection/basic/UserPermissions.hbm.xml" };
|
||||
}
|
||||
public abstract class UserCollectionTypeTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected String getCacheConcurrencyStrategy() {
|
|
@ -7,13 +7,13 @@
|
|||
This mapping is a basic example of how to write a UserCollectionType.
|
||||
-->
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.usercollection.basic">
|
||||
<hibernate-mapping package="org.hibernate.test.collection.custom.basic">
|
||||
|
||||
<import class="Permission"/>
|
||||
|
||||
<class name="User" table="UC_BSC_USER">
|
||||
<id name="userName"/>
|
||||
<list name="emailAddresses" fetch="join" cascade="all, delete-orphan" collection-type="org.hibernate.test.usercollection.basic.MyListType">
|
||||
<list name="emailAddresses" fetch="join" cascade="all, delete-orphan" collection-type="org.hibernate.test.collection.custom.basic.MyListType">
|
||||
<key column="userName"/>
|
||||
<list-index column="displayOrder" base="1"/>
|
||||
<one-to-many class="Email"/>
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) ${year}, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.collection.custom.parameterized;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Our specialized collection contract
|
||||
*
|
||||
* @author Holger Brands
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface DefaultableList extends List {
|
||||
public String getDefaultValue();
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) ${year}, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.collection.custom.parameterized;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Implementation of our specialized collection contract
|
||||
*
|
||||
* @author Holger Brands
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class DefaultableListImpl extends ArrayList implements DefaultableList {
|
||||
private String defaultValue;
|
||||
|
||||
public DefaultableListImpl() {
|
||||
}
|
||||
|
||||
public DefaultableListImpl(int anticipatedSize) {
|
||||
super( anticipatedSize + ( int ) Math.ceil( anticipatedSize * .75f ) );
|
||||
}
|
||||
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setDefaultValue(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package org.hibernate.test.usercollection.parameterized;
|
||||
package org.hibernate.test.collection.custom.parameterized;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import org.hibernate.EntityMode;
|
||||
|
||||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
|
@ -0,0 +1,57 @@
|
|||
package org.hibernate.test.collection.custom.parameterized;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OrderColumn;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.annotations.CollectionType;
|
||||
import org.hibernate.annotations.Parameter;
|
||||
import org.hibernate.annotations.TypeDef;
|
||||
|
||||
|
||||
/**
|
||||
* Our test entity
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@TypeDef(
|
||||
name = "DefaultableList",
|
||||
typeClass = DefaultableListType.class,
|
||||
parameters = @Parameter(name = "default", value = "Hello" )
|
||||
)
|
||||
@javax.persistence.Entity
|
||||
public class Entity {
|
||||
private String name;
|
||||
private List values = new ArrayList();
|
||||
|
||||
public Entity() {
|
||||
}
|
||||
|
||||
public Entity(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Id
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@ElementCollection( targetClass = String.class, fetch = FetchType.EAGER )
|
||||
@CollectionType( type = "DefaultableList" )
|
||||
@JoinColumn( name = "ENT_ID" )
|
||||
@OrderColumn( name = "POS" )
|
||||
public List getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public void setValues(List values) {
|
||||
this.values = values;
|
||||
}
|
||||
}
|
|
@ -3,9 +3,9 @@
|
|||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.usercollection.parameterized" default-access="field">
|
||||
<hibernate-mapping package="org.hibernate.test.collection.custom.parameterized" default-access="field">
|
||||
|
||||
<typedef name="DefaultableList" class="org.hibernate.test.usercollection.parameterized.DefaultableListType">
|
||||
<typedef name="DefaultableList" class="org.hibernate.test.collection.custom.parameterized.DefaultableListType">
|
||||
<param name="default">Hello</param>
|
||||
</typedef>
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) ${year}, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.collection.custom.parameterized;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ParameterizedUserCollectionTypeAnnotationsVariantTest extends ParameterizedUserCollectionTypeTest {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { Entity.class };
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) ${year}, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.collection.custom.parameterized;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ParameterizedUserCollectionTypeHbmVariantTest extends ParameterizedUserCollectionTypeTest {
|
||||
public String[] getMappings() {
|
||||
return new String[] { "collection/custom/parameterized/Mapping.hbm.xml" };
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.usercollection.parameterized;
|
||||
package org.hibernate.test.collection.custom.parameterized;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Session;
|
||||
|
@ -40,11 +40,7 @@ import static org.junit.Assert.assertTrue;
|
|||
* @author Holger Brands
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ParameterizedUserCollectionTypeTest extends BaseCoreFunctionalTestCase {
|
||||
public String[] getMappings() {
|
||||
return new String[] { "usercollection/parameterized/Mapping.hbm.xml" };
|
||||
}
|
||||
|
||||
public abstract class ParameterizedUserCollectionTypeTest extends BaseCoreFunctionalTestCase {
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
@Test
|
||||
public void testBasicOperation() {
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.test.usercollection.parameterized;
|
||||
package org.hibernate.test.collection.custom.parameterized;
|
||||
import java.util.List;
|
||||
import org.hibernate.collection.internal.PersistentList;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
|
@ -1,40 +0,0 @@
|
|||
//$Id$
|
||||
package org.hibernate.test.usercollection.basic;
|
||||
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class Email {
|
||||
|
||||
private Long id;
|
||||
private String address;
|
||||
|
||||
Email() {}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
public void setAddress(String type) {
|
||||
this.address = type;
|
||||
}
|
||||
public Email(String type) {
|
||||
this.address = type;
|
||||
}
|
||||
public boolean equals(Object that) {
|
||||
if ( !(that instanceof Email) ) return false;
|
||||
Email p = (Email) that;
|
||||
return this.address.equals(p.address);
|
||||
}
|
||||
public int hashCode() {
|
||||
return address.hashCode();
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
private void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
package org.hibernate.test.usercollection.basic;
|
||||
import java.util.List;
|
||||
|
||||
public interface IMyList extends List {
|
||||
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package org.hibernate.test.usercollection.basic;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* A custom collection class. We extend a java.util.Collection class, but that is not required.
|
||||
* It could be totally non-java-collection type, but then we would need to implement all the PersistentCollection methods.
|
||||
*
|
||||
* @author max
|
||||
*
|
||||
*/
|
||||
public class MyList extends ArrayList implements IMyList {
|
||||
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
//$Id$
|
||||
package org.hibernate.test.usercollection.basic;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class User {
|
||||
private String userName;
|
||||
private IMyList emailAddresses = new MyList();
|
||||
private Map sessionData = new HashMap();
|
||||
|
||||
User() {}
|
||||
public User(String name) {
|
||||
userName = name;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
public List getEmailAddresses() {
|
||||
return emailAddresses;
|
||||
}
|
||||
public void setEmailAddresses(IMyList emailAddresses) {
|
||||
this.emailAddresses = emailAddresses;
|
||||
}
|
||||
public Map getSessionData() {
|
||||
return sessionData;
|
||||
}
|
||||
public void setSessionData(Map sessionData) {
|
||||
this.sessionData = sessionData;
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package org.hibernate.test.usercollection.parameterized;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Our specialized collection contract
|
||||
*
|
||||
* @author Holger Brands
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface DefaultableList extends List {
|
||||
public String getDefaultValue();
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package org.hibernate.test.usercollection.parameterized;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Implementation of our specialized collection contract
|
||||
*
|
||||
* @author Holger Brands
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class DefaultableListImpl extends ArrayList implements DefaultableList {
|
||||
private String defaultValue;
|
||||
|
||||
public DefaultableListImpl() {
|
||||
}
|
||||
|
||||
public DefaultableListImpl(int anticipatedSize) {
|
||||
super( anticipatedSize + ( int ) Math.ceil( anticipatedSize * .75f ) );
|
||||
}
|
||||
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setDefaultValue(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package org.hibernate.test.usercollection.parameterized;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Our test entity
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Entity {
|
||||
private String name;
|
||||
private List values = new ArrayList();
|
||||
|
||||
public Entity() {
|
||||
}
|
||||
|
||||
public Entity(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public void setValues(List values) {
|
||||
this.values = values;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue