Hibernate SVN: r11501 - branches/Branch_3_2/Hibernate3.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-05-09 13:45:59 -0400 (Wed, 09 May 2007)
New Revision: 11501
Modified:
branches/Branch_3_2/Hibernate3/changelog.txt
Log:
prep 3.2.4
Modified: branches/Branch_3_2/Hibernate3/changelog.txt
===================================================================
--- branches/Branch_3_2/Hibernate3/changelog.txt 2007-05-09 17:36:08 UTC (rev 11500)
+++ branches/Branch_3_2/Hibernate3/changelog.txt 2007-05-09 17:45:59 UTC (rev 11501)
@@ -6,6 +6,30 @@
more about each case.
+Changes in version 3.2.4 (2007.05.09)
+-------------------------------------------
+
+** Bug
+ * [HHH-511] - reattach object from same session
+ * [HHH-2316] - org.hibernate.cache.CacheKey.equals() can cause PropertyAccessException to be thrown
+ * [HHH-2553] - New LoadContexts Implementation causing possible performance degradation
+ * [HHH-2602] - instrumented many-to-one problem with aggressive release
+
+** Deprecation
+ * [HHH-2603] - Deprecate the Session.connection() method
+
+** Improvement
+ * [HHH-2549] - Warn users explicitly about schemaexport and schemaupdate does not support annotations
+
+** New Feature
+ * [HHH-1] - Optimize Hibernate for the bulk insertion of related entities
+
+** Patch
+ * [HHH-2301] - Identity generator with custom insert SQL broken in 3.2 (Scott Rankin and Gail Badner)
+ * [HHH-2336] - paremeterizable and typedef-able UserCollectionType (Holger Brands)
+ * [HHH-2580] - Performace: Too many lookups of WAS extended transaction support (Jesper Udby)
+
+
Changes in version 3.2.3 (2007.04.02)
-------------------------------------------
17 years
Hibernate SVN: r11500 - branches/Branch_3_2/Hibernate3/src/org/hibernate/cache.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-05-09 13:36:08 -0400 (Wed, 09 May 2007)
New Revision: 11500
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/cache/CacheKey.java
Log:
HHH-2316 : CacheKey.equals()
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/cache/CacheKey.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/cache/CacheKey.java 2007-05-09 17:35:55 UTC (rev 11499)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/cache/CacheKey.java 2007-05-09 17:36:08 UTC (rev 11500)
@@ -25,19 +25,24 @@
* Construct a new key for a collection or entity instance.
* Note that an entity name should always be the root entity
* name, not a subclass entity name.
+ *
+ * @param id The identifier associated with the cached data
+ * @param type The Hibernate type mapping
+ * @param entityOrRoleName The entity or collection-role name.
+ * @param entityMode The entiyt mode of the originating session
+ * @param factory The session factory for which we are caching
*/
public CacheKey(
final Serializable id,
final Type type,
final String entityOrRoleName,
final EntityMode entityMode,
- final SessionFactoryImplementor factory
- ) {
+ final SessionFactoryImplementor factory) {
this.key = id;
this.type = type;
this.entityOrRoleName = entityOrRoleName;
this.entityMode = entityMode;
- hashCode = type.getHashCode(key, entityMode, factory);
+ hashCode = type.getHashCode( key, entityMode, factory );
}
//Mainly for OSCache
@@ -48,8 +53,8 @@
public boolean equals(Object other) {
if ( !(other instanceof CacheKey) ) return false;
CacheKey that = (CacheKey) other;
- return type.isEqual(key, that.key, entityMode) &&
- entityOrRoleName.equals(that.entityOrRoleName);
+ return entityOrRoleName.equals( that.entityOrRoleName )
+ && type.isEqual( key, that.key, entityMode );
}
public int hashCode() {
17 years
Hibernate SVN: r11499 - trunk/Hibernate3/src/org/hibernate/cache.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-05-09 13:35:55 -0400 (Wed, 09 May 2007)
New Revision: 11499
Modified:
trunk/Hibernate3/src/org/hibernate/cache/CacheKey.java
Log:
HHH-2316 : CacheKey.equals()
Modified: trunk/Hibernate3/src/org/hibernate/cache/CacheKey.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/cache/CacheKey.java 2007-05-09 14:55:16 UTC (rev 11498)
+++ trunk/Hibernate3/src/org/hibernate/cache/CacheKey.java 2007-05-09 17:35:55 UTC (rev 11499)
@@ -8,10 +8,10 @@
import org.hibernate.type.Type;
/**
- * Allows multiple entity classes / collection roles to be
- * stored in the same cache region. Also allows for composite
+ * Allows multiple entity classes / collection roles to be
+ * stored in the same cache region. Also allows for composite
* keys which do not properly implement equals()/hashCode().
- *
+ *
* @author Gavin King
*/
public class CacheKey implements Serializable {
@@ -20,24 +20,29 @@
private final String entityOrRoleName;
private final EntityMode entityMode;
private final int hashCode;
-
+
/**
* Construct a new key for a collection or entity instance.
- * Note that an entity name should always be the root entity
+ * Note that an entity name should always be the root entity
* name, not a subclass entity name.
+ *
+ * @param id The identifier associated with the cached data
+ * @param type The Hibernate type mapping
+ * @param entityOrRoleName The entity or collection-role name.
+ * @param entityMode The entiyt mode of the originating session
+ * @param factory The session factory for which we are caching
*/
public CacheKey(
- final Serializable id,
- final Type type,
- final String entityOrRoleName,
- final EntityMode entityMode,
- final SessionFactoryImplementor factory
- ) {
+ final Serializable id,
+ final Type type,
+ final String entityOrRoleName,
+ final EntityMode entityMode,
+ final SessionFactoryImplementor factory) {
this.key = id;
this.type = type;
this.entityOrRoleName = entityOrRoleName;
this.entityMode = entityMode;
- hashCode = type.getHashCode(key, entityMode, factory);
+ hashCode = type.getHashCode( key, entityMode, factory );
}
//Mainly for OSCache
@@ -48,18 +53,18 @@
public boolean equals(Object other) {
if ( !(other instanceof CacheKey) ) return false;
CacheKey that = (CacheKey) other;
- return type.isEqual(key, that.key, entityMode) &&
- entityOrRoleName.equals(that.entityOrRoleName);
+ return entityOrRoleName.equals( that.entityOrRoleName )
+ && type.isEqual( key, that.key, entityMode );
}
public int hashCode() {
return hashCode;
}
-
+
public Serializable getKey() {
return key;
}
-
+
public String getEntityOrRoleName() {
return entityOrRoleName;
}
17 years
Hibernate SVN: r11498 - trunk/Hibernate3/src/org/hibernate/transaction.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-05-09 10:55:16 -0400 (Wed, 09 May 2007)
New Revision: 11498
Modified:
trunk/Hibernate3/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java
Log:
HHH-2580 : WAS ExtendedJTATransaction garbage
Modified: trunk/Hibernate3/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java 2007-05-09 14:55:01 UTC (rev 11497)
+++ trunk/Hibernate3/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java 2007-05-09 14:55:16 UTC (rev 11498)
@@ -7,9 +7,6 @@
import java.util.Properties;
import javax.naming.NamingException;
-import javax.transaction.HeuristicMixedException;
-import javax.transaction.HeuristicRollbackException;
-import javax.transaction.InvalidTransactionException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.Status;
@@ -23,16 +20,28 @@
import org.hibernate.util.NamingHelper;
/**
- * Support for proprietary interfaces for registering synchronizations in WebSphere 6.
- *
+ * TransactionManagerLookup implementation intended for use with WebSphere
+ * Application Server (WAS).
+ * <p/>
+ * WAS, unlike every other app server on the planet, does not allow direct
+ * access to the JTS TransactionManager. Instead, for common transaction-
+ * related tasks users must utilize a proprietary API known as
+ * ExtendedJTATransaction.
+ * <p/>
+ * Even more unfortunate, the exact TransactionManagerLookup to use inside of
+ * WAS is highly dependent upon (1) WAS version as well as (2) the WAS
+ * container in which Hibernate will be utilized.
+ * <p/>
+ * WebSphereExtendedJTATransactionLookup is reported to work on WAS version 6
+ * in any of the standard J2EE/JEE component containers.
+ *
* @author Gavin King
+ * @author <a href="mailto:jesper@udby.com>Jesper Udby</a>
*/
public class WebSphereExtendedJTATransactionLookup implements TransactionManagerLookup {
- public static final String E_TRN_JNDI_NAME = "java:comp/websphere/ExtendedJTATransaction";
- public TransactionManager getTransactionManager(Properties props)
- throws HibernateException {
- return new TransactionManagerAdapter(props);
+ public TransactionManager getTransactionManager(Properties props) {
+ return new TransactionManagerAdapter( props );
}
public String getUserTransactionName() {
@@ -40,29 +49,29 @@
}
public static class TransactionManagerAdapter implements TransactionManager {
-
private final Properties properties;
private final Class synchronizationCallbackClass;
private final Method registerSynchronizationMethod;
private final Method getLocalIdMethod;
+ private Object extendedJTATransaction;
- private TransactionManagerAdapter(Properties props) {
+ private TransactionManagerAdapter(Properties props) throws HibernateException {
this.properties = props;
try {
- synchronizationCallbackClass = Class.forName("com.ibm.websphere.jtaextensions.SynchronizationCallback");
- Class extendedJTATransactionClass = Class.forName("com.ibm.websphere.jtaextensions.ExtendedJTATransaction");
+ synchronizationCallbackClass = Class.forName( "com.ibm.websphere.jtaextensions.SynchronizationCallback" );
+ Class extendedJTATransactionClass = Class.forName( "com.ibm.websphere.jtaextensions.ExtendedJTATransaction" );
registerSynchronizationMethod = extendedJTATransactionClass.getMethod(
"registerSynchronizationCallbackForCurrentTran",
new Class[] { synchronizationCallbackClass }
- );
+ );
getLocalIdMethod = extendedJTATransactionClass.getMethod( "getLocalId", null );
}
- catch (ClassNotFoundException cnfe) {
- throw new HibernateException(cnfe);
+ catch ( ClassNotFoundException cnfe ) {
+ throw new HibernateException( cnfe );
}
- catch (NoSuchMethodException nsme) {
- throw new HibernateException(nsme);
+ catch ( NoSuchMethodException nsme ) {
+ throw new HibernateException( nsme );
}
}
@@ -70,13 +79,11 @@
throw new UnsupportedOperationException();
}
- public void commit() throws RollbackException, HeuristicMixedException,
- HeuristicRollbackException, SecurityException,
- IllegalStateException, SystemException {
+ public void commit() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
- public int getStatus() throws SystemException {
+ public int getStatus() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
@@ -84,36 +91,33 @@
return new TransactionAdapter( properties );
}
- public void resume(Transaction txn) throws InvalidTransactionException,
- IllegalStateException, SystemException {
+ public void resume(Transaction txn) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
- public void rollback() throws IllegalStateException, SecurityException,
- SystemException {
+ public void rollback() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
- public void setRollbackOnly() throws IllegalStateException,
- SystemException {
+ public void setRollbackOnly() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
- public void setTransactionTimeout(int i) throws SystemException {
+ public void setTransactionTimeout(int i) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
- public Transaction suspend() throws SystemException {
+ public Transaction suspend() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
public class TransactionAdapter implements Transaction {
- private Object extendedJTATransaction;
private TransactionAdapter(Properties props) {
try {
- if (extendedJTATransaction == null) {
- extendedJTATransaction = NamingHelper.getInitialContext( props ).lookup( E_TRN_JNDI_NAME );
+ if ( extendedJTATransaction == null ) {
+ extendedJTATransaction = NamingHelper.getInitialContext( props )
+ .lookup( "java:comp/websphere/ExtendedJTATransaction" );
}
}
catch (NamingException ne) {
@@ -173,43 +177,37 @@
return getLocalId().equals( that.getLocalId() );
}
- private Object getLocalId() {
+ private Object getLocalId() throws HibernateException {
try {
- return getLocalIdMethod.invoke(extendedJTATransaction, null);
+ return getLocalIdMethod.invoke( extendedJTATransaction, null );
}
- catch (Exception e) {
- throw new HibernateException(e);
+ catch ( Exception e ) {
+ throw new HibernateException( e );
}
}
- public void commit() throws RollbackException, HeuristicMixedException,
- HeuristicRollbackException, SecurityException,
- IllegalStateException, SystemException {
+ public void commit() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
- public boolean delistResource(XAResource resource, int i)
- throws IllegalStateException, SystemException {
+ public boolean delistResource(XAResource resource, int i) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
- public boolean enlistResource(XAResource resource)
- throws RollbackException, IllegalStateException,
- SystemException {
+ public boolean enlistResource(XAResource resource) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
- public int getStatus() throws SystemException {
+ public int getStatus() {
return new Integer(0).equals( getLocalId() ) ?
Status.STATUS_NO_TRANSACTION : Status.STATUS_ACTIVE;
}
- public void rollback() throws IllegalStateException, SystemException {
+ public void rollback() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
- public void setRollbackOnly() throws IllegalStateException,
- SystemException {
+ public void setRollbackOnly() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
}
17 years
Hibernate SVN: r11497 - branches/Branch_3_2/Hibernate3/src/org/hibernate/transaction.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-05-09 10:55:01 -0400 (Wed, 09 May 2007)
New Revision: 11497
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java
Log:
HHH-2580 : WAS ExtendedJTATransaction garbage
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java 2007-05-09 03:54:06 UTC (rev 11496)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java 2007-05-09 14:55:01 UTC (rev 11497)
@@ -7,9 +7,6 @@
import java.util.Properties;
import javax.naming.NamingException;
-import javax.transaction.HeuristicMixedException;
-import javax.transaction.HeuristicRollbackException;
-import javax.transaction.InvalidTransactionException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.Status;
@@ -23,16 +20,28 @@
import org.hibernate.util.NamingHelper;
/**
- * Support for proprietary interfaces for registering synchronizations in WebSphere 6.
+ * TransactionManagerLookup implementation intended for use with WebSphere
+ * Application Server (WAS).
+ * <p/>
+ * WAS, unlike every other app server on the planet, does not allow direct
+ * access to the JTS TransactionManager. Instead, for common transaction-
+ * related tasks users must utilize a proprietary API known as
+ * ExtendedJTATransaction.
+ * <p/>
+ * Even more unfortunate, the exact TransactionManagerLookup to use inside of
+ * WAS is highly dependent upon (1) WAS version as well as (2) the WAS
+ * container in which Hibernate will be utilized.
+ * <p/>
+ * WebSphereExtendedJTATransactionLookup is reported to work on WAS version 6
+ * in any of the standard J2EE/JEE component containers.
*
* @author Gavin King
+ * @author <a href="mailto:jesper@udby.com>Jesper Udby</a>
*/
public class WebSphereExtendedJTATransactionLookup implements TransactionManagerLookup {
- public static final String E_TRN_JNDI_NAME = "java:comp/websphere/ExtendedJTATransaction";
- public TransactionManager getTransactionManager(Properties props)
- throws HibernateException {
- return new TransactionManagerAdapter(props);
+ public TransactionManager getTransactionManager(Properties props) {
+ return new TransactionManagerAdapter( props );
}
public String getUserTransactionName() {
@@ -40,29 +49,29 @@
}
public static class TransactionManagerAdapter implements TransactionManager {
-
private final Properties properties;
private final Class synchronizationCallbackClass;
private final Method registerSynchronizationMethod;
private final Method getLocalIdMethod;
+ private Object extendedJTATransaction;
- private TransactionManagerAdapter(Properties props) {
+ private TransactionManagerAdapter(Properties props) throws HibernateException {
this.properties = props;
try {
- synchronizationCallbackClass = Class.forName("com.ibm.websphere.jtaextensions.SynchronizationCallback");
- Class extendedJTATransactionClass = Class.forName("com.ibm.websphere.jtaextensions.ExtendedJTATransaction");
+ synchronizationCallbackClass = Class.forName( "com.ibm.websphere.jtaextensions.SynchronizationCallback" );
+ Class extendedJTATransactionClass = Class.forName( "com.ibm.websphere.jtaextensions.ExtendedJTATransaction" );
registerSynchronizationMethod = extendedJTATransactionClass.getMethod(
"registerSynchronizationCallbackForCurrentTran",
new Class[] { synchronizationCallbackClass }
- );
+ );
getLocalIdMethod = extendedJTATransactionClass.getMethod( "getLocalId", null );
}
- catch (ClassNotFoundException cnfe) {
- throw new HibernateException(cnfe);
+ catch ( ClassNotFoundException cnfe ) {
+ throw new HibernateException( cnfe );
}
- catch (NoSuchMethodException nsme) {
- throw new HibernateException(nsme);
+ catch ( NoSuchMethodException nsme ) {
+ throw new HibernateException( nsme );
}
}
@@ -70,13 +79,11 @@
throw new UnsupportedOperationException();
}
- public void commit() throws RollbackException, HeuristicMixedException,
- HeuristicRollbackException, SecurityException,
- IllegalStateException, SystemException {
+ public void commit() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
- public int getStatus() throws SystemException {
+ public int getStatus() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
@@ -84,36 +91,33 @@
return new TransactionAdapter( properties );
}
- public void resume(Transaction txn) throws InvalidTransactionException,
- IllegalStateException, SystemException {
+ public void resume(Transaction txn) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
- public void rollback() throws IllegalStateException, SecurityException,
- SystemException {
+ public void rollback() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
- public void setRollbackOnly() throws IllegalStateException,
- SystemException {
+ public void setRollbackOnly() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
- public void setTransactionTimeout(int i) throws SystemException {
+ public void setTransactionTimeout(int i) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
- public Transaction suspend() throws SystemException {
+ public Transaction suspend() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
public class TransactionAdapter implements Transaction {
- private Object extendedJTATransaction;
private TransactionAdapter(Properties props) {
try {
- if (extendedJTATransaction == null) {
- extendedJTATransaction = NamingHelper.getInitialContext( props ).lookup( E_TRN_JNDI_NAME );
+ if ( extendedJTATransaction == null ) {
+ extendedJTATransaction = NamingHelper.getInitialContext( props )
+ .lookup( "java:comp/websphere/ExtendedJTATransaction" );
}
}
catch (NamingException ne) {
@@ -149,13 +153,13 @@
getClass().getClassLoader(),
new Class[] { synchronizationCallbackClass },
ih
- );
+ );
try {
registerSynchronizationMethod.invoke(
extendedJTATransaction,
new Object[] { synchronizationCallback }
- );
+ );
}
catch (Exception e) {
throw new HibernateException(e);
@@ -173,43 +177,37 @@
return getLocalId().equals( that.getLocalId() );
}
- private Object getLocalId() {
+ private Object getLocalId() throws HibernateException {
try {
- return getLocalIdMethod.invoke(extendedJTATransaction, null);
+ return getLocalIdMethod.invoke( extendedJTATransaction, null );
}
- catch (Exception e) {
- throw new HibernateException(e);
+ catch ( Exception e ) {
+ throw new HibernateException( e );
}
}
- public void commit() throws RollbackException, HeuristicMixedException,
- HeuristicRollbackException, SecurityException,
- IllegalStateException, SystemException {
+ public void commit() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
- public boolean delistResource(XAResource resource, int i)
- throws IllegalStateException, SystemException {
+ public boolean delistResource(XAResource resource, int i) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
- public boolean enlistResource(XAResource resource)
- throws RollbackException, IllegalStateException,
- SystemException {
+ public boolean enlistResource(XAResource resource) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
- public int getStatus() throws SystemException {
+ public int getStatus() {
return new Integer(0).equals( getLocalId() ) ?
Status.STATUS_NO_TRANSACTION : Status.STATUS_ACTIVE;
}
- public void rollback() throws IllegalStateException, SystemException {
+ public void rollback() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
- public void setRollbackOnly() throws IllegalStateException,
- SystemException {
+ public void setRollbackOnly() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
}
17 years
Hibernate SVN: r11496 - in trunk/Hibernate3: src/org/hibernate/mapping and 5 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-05-08 23:54:06 -0400 (Tue, 08 May 2007)
New Revision: 11496
Added:
trunk/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeSuite.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/
trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/Email.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/IMyList.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/MyList.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/MyListType.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/PersistentMyList.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/User.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/UserCollectionTypeTest.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/UserPermissions.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/
trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableList.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableListImpl.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableListType.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/Entity.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/Mapping.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/ParameterizedUserCollectionTypeTest.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/PersistentDefaultableList.java
Removed:
trunk/Hibernate3/test/org/hibernate/test/usercollection/Email.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/IMyList.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/MyList.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/MyListType.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/PersistentMyList.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/User.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeTest.java
trunk/Hibernate3/test/org/hibernate/test/usercollection/UserPermissions.hbm.xml
Modified:
trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java
trunk/Hibernate3/src/org/hibernate/mapping/Collection.java
trunk/Hibernate3/src/org/hibernate/type/CustomCollectionType.java
trunk/Hibernate3/src/org/hibernate/type/TypeFactory.java
trunk/Hibernate3/test/org/hibernate/test/AllTests.java
Log:
HHH-2336 : parameterized UserCollectionType
Modified: trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2007-05-09 03:52:56 UTC (rev 11495)
+++ trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -1345,7 +1345,17 @@
}
Attribute typeNode = node.attribute( "collection-type" );
- if ( typeNode != null ) collection.setTypeName( typeNode.getValue() );
+ if ( typeNode != null ) {
+ String typeName = typeNode.getValue();
+ TypeDef typeDef = mappings.getTypeDef( typeName );
+ if ( typeDef != null ) {
+ collection.setTypeName( typeDef.getTypeClass() );
+ collection.setTypeParameters( typeDef.getParameters() );
+ }
+ else {
+ collection.setTypeName( typeName );
+ }
+ }
// FETCH STRATEGY
Modified: trunk/Hibernate3/src/org/hibernate/mapping/Collection.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/mapping/Collection.java 2007-05-09 03:52:56 UTC (rev 11495)
+++ trunk/Hibernate3/src/org/hibernate/mapping/Collection.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -5,6 +5,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Properties;
import org.hibernate.FetchMode;
import org.hibernate.MappingException;
@@ -56,6 +57,7 @@
private boolean optimisticLocked = true;
private Class collectionPersisterClass;
private String typeName;
+ private Properties typeParameters;
private final java.util.Map filters = new HashMap();
private final java.util.Map manyToManyFilters = new HashMap();
private final java.util.Set synchronizedTables = new HashSet();
@@ -345,7 +347,7 @@
return getDefaultCollectionType();
}
else {
- return TypeFactory.customCollection( typeName, role, referencedPropertyName, isEmbedded() );
+ return TypeFactory.customCollection( typeName, typeParameters, role, referencedPropertyName, isEmbedded() );
}
}
@@ -541,6 +543,14 @@
this.typeName = typeName;
}
+ public Properties getTypeParameters() {
+ return typeParameters;
+ }
+
+ public void setTypeParameters(Properties parameterMap) {
+ this.typeParameters = parameterMap;
+ }
+
public boolean[] getColumnInsertability() {
return ArrayHelper.EMPTY_BOOLEAN_ARRAY;
}
Modified: trunk/Hibernate3/src/org/hibernate/type/CustomCollectionType.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/type/CustomCollectionType.java 2007-05-09 03:52:56 UTC (rev 11495)
+++ trunk/Hibernate3/src/org/hibernate/type/CustomCollectionType.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -87,4 +87,8 @@
return super.renderLoggableString( value, factory );
}
}
+
+ public UserCollectionType getUserType() {
+ return userType;
+ }
}
Modified: trunk/Hibernate3/src/org/hibernate/type/TypeFactory.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/type/TypeFactory.java 2007-05-09 03:52:56 UTC (rev 11495)
+++ trunk/Hibernate3/src/org/hibernate/type/TypeFactory.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -256,16 +256,37 @@
}
- public static CollectionType customCollection(String typeName, String role, String propertyRef,
+ /**
+ * The legacy contract.
+ *
+ * @deprecated Use {@link #customCollection(String, java.util.Properties, String, String, boolean)} instead
+ */
+ public static CollectionType customCollection(
+ String typeName,
+ String role,
+ String propertyRef,
boolean embedded) {
+ return customCollection( typeName, null, role, propertyRef, embedded );
+ }
+
+ public static CollectionType customCollection(
+ String typeName,
+ Properties typeParameters,
+ String role,
+ String propertyRef,
+ boolean embedded) {
Class typeClass;
try {
typeClass = ReflectHelper.classForName( typeName );
}
- catch (ClassNotFoundException cnfe) {
- throw new MappingException( "user colllection type class not found: " + typeName, cnfe );
+ catch ( ClassNotFoundException cnfe ) {
+ throw new MappingException( "user collection type class not found: " + typeName, cnfe );
}
- return new CustomCollectionType( typeClass, role, propertyRef, embedded );
+ CustomCollectionType result = new CustomCollectionType( typeClass, role, propertyRef, embedded );
+ if ( typeParameters != null ) {
+ TypeFactory.injectParameters( result.getUserType(), typeParameters );
+ }
+ return result;
}
// Collection Types:
Modified: trunk/Hibernate3/test/org/hibernate/test/AllTests.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/AllTests.java 2007-05-09 03:52:56 UTC (rev 11495)
+++ trunk/Hibernate3/test/org/hibernate/test/AllTests.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -123,7 +123,7 @@
import org.hibernate.test.unconstrained.UnconstrainedTest;
import org.hibernate.test.unidir.BackrefTest;
import org.hibernate.test.unionsubclass.UnionSubclassTest;
-import org.hibernate.test.usercollection.UserCollectionTypeTest;
+import org.hibernate.test.usercollection.UserCollectionTypeSuite;
import org.hibernate.test.util.UtilSuite;
import org.hibernate.test.version.VersionTest;
import org.hibernate.test.version.db.DbVersionTest;
@@ -298,7 +298,7 @@
suite.addTest( LobSuite.suite() );
suite.addTest( IdentifierPropertyReferencesTest.suite() );
suite.addTest( DeleteTransientEntityTest.suite() );
- suite.addTest( UserCollectionTypeTest.suite() );
+ suite.addTest( UserCollectionTypeSuite.suite() );
suite.addTest( KeyManyToOneSuite.suite() );
suite.addTest( DialectFunctionalTestsSuite.suite() );
suite.addTest( DialectUnitTestsSuite.suite() );
Deleted: trunk/Hibernate3/test/org/hibernate/test/usercollection/Email.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/Email.java 2007-05-09 03:52:56 UTC (rev 11495)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/Email.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -1,39 +0,0 @@
-//$Id$
-package org.hibernate.test.usercollection;
-
-/**
- * @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;
- }
-}
Deleted: trunk/Hibernate3/test/org/hibernate/test/usercollection/IMyList.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/IMyList.java 2007-05-09 03:52:56 UTC (rev 11495)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/IMyList.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -1,7 +0,0 @@
-package org.hibernate.test.usercollection;
-
-import java.util.List;
-
-public interface IMyList extends List {
-
-}
Deleted: trunk/Hibernate3/test/org/hibernate/test/usercollection/MyList.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/MyList.java 2007-05-09 03:52:56 UTC (rev 11495)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/MyList.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -1,14 +0,0 @@
-package org.hibernate.test.usercollection;
-
-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 {
-
-}
Deleted: trunk/Hibernate3/test/org/hibernate/test/usercollection/MyListType.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/MyListType.java 2007-05-09 03:52:56 UTC (rev 11495)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/MyListType.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -1,60 +0,0 @@
-package org.hibernate.test.usercollection;
-
-import java.util.Iterator;
-import java.util.Map;
-
-import org.hibernate.EntityMode;
-import org.hibernate.HibernateException;
-import org.hibernate.collection.PersistentCollection;
-import org.hibernate.engine.SessionImplementor;
-import org.hibernate.persister.collection.CollectionPersister;
-import org.hibernate.usertype.UserCollectionType;
-
-public class MyListType implements UserCollectionType {
-
- static int lastInstantiationRequest = -2;
-
- public PersistentCollection instantiate(SessionImplementor session, CollectionPersister persister) throws HibernateException {
- return new PersistentMyList(session);
- }
-
- public PersistentCollection wrap(SessionImplementor session, Object collection) {
- if ( session.getEntityMode()==EntityMode.DOM4J ) {
- throw new IllegalStateException("dom4j not supported");
- }
- else {
- return new PersistentMyList( session, (IMyList) collection );
- }
- }
-
- public Iterator getElementsIterator(Object collection) {
- return ( (IMyList) collection ).iterator();
- }
-
- public boolean contains(Object collection, Object entity) {
- return ( (IMyList) collection ).contains(entity);
- }
-
- public Object indexOf(Object collection, Object entity) {
- int l = ( (IMyList) collection ).indexOf(entity);
- if(l<0) {
- return null;
- } else {
- return new Integer(l);
- }
- }
-
- public Object replaceElements(Object original, Object target, CollectionPersister persister, Object owner, Map copyCache, SessionImplementor session) throws HibernateException {
- IMyList result = (IMyList) target;
- result.clear();
- result.addAll((MyList)original);
- return result;
- }
-
- public Object instantiate(int anticipatedSize) {
- lastInstantiationRequest = anticipatedSize;
- return new MyList();
- }
-
-
-}
Deleted: trunk/Hibernate3/test/org/hibernate/test/usercollection/PersistentMyList.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/PersistentMyList.java 2007-05-09 03:52:56 UTC (rev 11495)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/PersistentMyList.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -1,18 +0,0 @@
-package org.hibernate.test.usercollection;
-
-import org.hibernate.collection.PersistentList;
-import org.hibernate.engine.SessionImplementor;
-
-public class PersistentMyList extends PersistentList implements IMyList {
-
- public PersistentMyList(SessionImplementor session) {
- super(session);
- }
-
- public PersistentMyList(SessionImplementor session, IMyList list) {
- super(session, list);
- }
-
-
-
-}
Deleted: trunk/Hibernate3/test/org/hibernate/test/usercollection/User.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/User.java 2007-05-09 03:52:56 UTC (rev 11495)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/User.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -1,39 +0,0 @@
-//$Id$
-package org.hibernate.test.usercollection;
-
-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;
- }
-}
Added: trunk/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeSuite.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeSuite.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeSuite.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -0,0 +1,21 @@
+package org.hibernate.test.usercollection;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.usercollection.basic.UserCollectionTypeTest;
+import org.hibernate.test.usercollection.parameterized.ParameterizedUserCollectionTypeTest;
+
+/**
+ * Suite for testing various aspects of user collection types.
+ *
+ * @author Steve Ebersole
+ */
+public class UserCollectionTypeSuite {
+ public static Test suite() {
+ TestSuite suite = new TestSuite( "user collection type tests" );
+ suite.addTest( UserCollectionTypeTest.suite() );
+ suite.addTest( ParameterizedUserCollectionTypeTest.suite() );
+ return suite;
+ }
+}
Deleted: trunk/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeTest.java 2007-05-09 03:52:56 UTC (rev 11495)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeTest.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -1,63 +0,0 @@
-//$Id$
-package org.hibernate.test.usercollection;
-
-import junit.framework.Test;
-
-import org.hibernate.Hibernate;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.junit.functional.FunctionalTestCase;
-import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
-
-/**
- * @author Max Rydahl Andersen
- */
-public class UserCollectionTypeTest extends FunctionalTestCase {
-
- public UserCollectionTypeTest(String str) {
- super(str);
- }
-
- public String[] getMappings() {
- return new String[] { "usercollection/UserPermissions.hbm.xml" };
- }
-
- public static Test suite() {
- return new FunctionalTestClassTestSuite( UserCollectionTypeTest.class );
- }
-
- public void testBasicOperation() {
- Session s = openSession();
- Transaction t = s.beginTransaction();
- User u = new User("max");
- u.getEmailAddresses().add( new Email("max(a)hibernate.org") );
- u.getEmailAddresses().add( new Email("max.andersen(a)jboss.com") );
- s.persist(u);
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- User u2 = (User) s.createCriteria(User.class).uniqueResult();
- assertTrue( Hibernate.isInitialized( u2.getEmailAddresses() ) );
- assertEquals( u2.getEmailAddresses().size(), 2 );
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- u2 = ( User ) s.get( User.class, u.getUserName() );
- u2.getEmailAddresses().size();
- assertEquals( 2, MyListType.lastInstantiationRequest );
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- s.delete( u );
- t.commit();
- s.close();
- }
-
-}
-
Deleted: trunk/Hibernate3/test/org/hibernate/test/usercollection/UserPermissions.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/UserPermissions.hbm.xml 2007-05-09 03:52:56 UTC (rev 11495)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/UserPermissions.hbm.xml 2007-05-09 03:54:06 UTC (rev 11496)
@@ -1,33 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<!--
-
- This mapping is a basic example of how to write a UserCollectionType.
-
--->
-
-<hibernate-mapping
- package="org.hibernate.test.usercollection">
-
- <import class="Permission"/>
-
- <class name="User" table="`Users`">
- <id name="userName"/>
- <list name="emailAddresses" fetch="join" cascade="all, delete-orphan" collection-type="org.hibernate.test.usercollection.MyListType">
- <key column="userName"/>
- <list-index column="displayOrder" base="1"/>
- <one-to-many class="Email"/>
- </list>
- </class>
-
- <class name="Email">
- <id name="id">
- <generator class="native"/>
- </id>
- <property name="address"/>
- </class>
-
-</hibernate-mapping>
Copied: trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/Email.java (from rev 11075, trunk/Hibernate3/test/org/hibernate/test/usercollection/Email.java)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/Email.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/Email.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -0,0 +1,39 @@
+//$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;
+ }
+}
Property changes on: trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/Email.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/IMyList.java (from rev 11075, trunk/Hibernate3/test/org/hibernate/test/usercollection/IMyList.java)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/IMyList.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/IMyList.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -0,0 +1,7 @@
+package org.hibernate.test.usercollection.basic;
+
+import java.util.List;
+
+public interface IMyList extends List {
+
+}
Property changes on: trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/IMyList.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/MyList.java (from rev 11075, trunk/Hibernate3/test/org/hibernate/test/usercollection/MyList.java)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/MyList.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/MyList.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -0,0 +1,14 @@
+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 {
+
+}
Property changes on: trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/MyList.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/MyListType.java (from rev 11075, trunk/Hibernate3/test/org/hibernate/test/usercollection/MyListType.java)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/MyListType.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/MyListType.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -0,0 +1,60 @@
+package org.hibernate.test.usercollection.basic;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.hibernate.EntityMode;
+import org.hibernate.HibernateException;
+import org.hibernate.collection.PersistentCollection;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.persister.collection.CollectionPersister;
+import org.hibernate.usertype.UserCollectionType;
+
+public class MyListType implements UserCollectionType {
+
+ static int lastInstantiationRequest = -2;
+
+ public PersistentCollection instantiate(SessionImplementor session, CollectionPersister persister) throws HibernateException {
+ return new PersistentMyList(session);
+ }
+
+ public PersistentCollection wrap(SessionImplementor session, Object collection) {
+ if ( session.getEntityMode()==EntityMode.DOM4J ) {
+ throw new IllegalStateException("dom4j not supported");
+ }
+ else {
+ return new PersistentMyList( session, (IMyList) collection );
+ }
+ }
+
+ public Iterator getElementsIterator(Object collection) {
+ return ( (IMyList) collection ).iterator();
+ }
+
+ public boolean contains(Object collection, Object entity) {
+ return ( (IMyList) collection ).contains(entity);
+ }
+
+ public Object indexOf(Object collection, Object entity) {
+ int l = ( (IMyList) collection ).indexOf(entity);
+ if(l<0) {
+ return null;
+ } else {
+ return new Integer(l);
+ }
+ }
+
+ public Object replaceElements(Object original, Object target, CollectionPersister persister, Object owner, Map copyCache, SessionImplementor session) throws HibernateException {
+ IMyList result = (IMyList) target;
+ result.clear();
+ result.addAll((MyList)original);
+ return result;
+ }
+
+ public Object instantiate(int anticipatedSize) {
+ lastInstantiationRequest = anticipatedSize;
+ return new MyList();
+ }
+
+
+}
Property changes on: trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/MyListType.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/PersistentMyList.java (from rev 11075, trunk/Hibernate3/test/org/hibernate/test/usercollection/PersistentMyList.java)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/PersistentMyList.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/PersistentMyList.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -0,0 +1,18 @@
+package org.hibernate.test.usercollection.basic;
+
+import org.hibernate.collection.PersistentList;
+import org.hibernate.engine.SessionImplementor;
+
+public class PersistentMyList extends PersistentList implements IMyList {
+
+ public PersistentMyList(SessionImplementor session) {
+ super(session);
+ }
+
+ public PersistentMyList(SessionImplementor session, IMyList list) {
+ super(session, list);
+ }
+
+
+
+}
Property changes on: trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/PersistentMyList.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/User.java (from rev 11075, trunk/Hibernate3/test/org/hibernate/test/usercollection/User.java)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/User.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/User.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -0,0 +1,39 @@
+//$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;
+ }
+}
Property changes on: trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/User.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/UserCollectionTypeTest.java (from rev 11075, trunk/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeTest.java)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/UserCollectionTypeTest.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/UserCollectionTypeTest.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -0,0 +1,63 @@
+//$Id $
+package org.hibernate.test.usercollection.basic;
+
+import junit.framework.Test;
+
+import org.hibernate.Hibernate;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+
+/**
+ * @author Max Rydahl Andersen
+ */
+public class UserCollectionTypeTest extends FunctionalTestCase {
+
+ public UserCollectionTypeTest(String str) {
+ super(str);
+ }
+
+ public String[] getMappings() {
+ return new String[] { "usercollection/basic/UserPermissions.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( UserCollectionTypeTest.class );
+ }
+
+ public void testBasicOperation() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ User u = new User("max");
+ u.getEmailAddresses().add( new Email("max(a)hibernate.org") );
+ u.getEmailAddresses().add( new Email("max.andersen(a)jboss.com") );
+ s.persist(u);
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ User u2 = (User) s.createCriteria(User.class).uniqueResult();
+ assertTrue( Hibernate.isInitialized( u2.getEmailAddresses() ) );
+ assertEquals( u2.getEmailAddresses().size(), 2 );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ u2 = ( User ) s.get( User.class, u.getUserName() );
+ u2.getEmailAddresses().size();
+ assertEquals( 2, MyListType.lastInstantiationRequest );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ s.delete( u );
+ t.commit();
+ s.close();
+ }
+
+}
+
Property changes on: trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/UserCollectionTypeTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/UserPermissions.hbm.xml (from rev 11075, trunk/Hibernate3/test/org/hibernate/test/usercollection/UserPermissions.hbm.xml)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/UserPermissions.hbm.xml (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/UserPermissions.hbm.xml 2007-05-09 03:54:06 UTC (rev 11496)
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+ This mapping is a basic example of how to write a UserCollectionType.
+-->
+
+<hibernate-mapping package="org.hibernate.test.usercollection.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">
+ <key column="userName"/>
+ <list-index column="displayOrder" base="1"/>
+ <one-to-many class="Email"/>
+ </list>
+ </class>
+
+ <class name="Email">
+ <id name="id">
+ <generator class="native"/>
+ </id>
+ <property name="address"/>
+ </class>
+
+</hibernate-mapping>
Property changes on: trunk/Hibernate3/test/org/hibernate/test/usercollection/basic/UserPermissions.hbm.xml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableList.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableList.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableList.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -0,0 +1,13 @@
+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();
+}
Added: trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableListImpl.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableListImpl.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableListImpl.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -0,0 +1,28 @@
+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;
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableListType.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableListType.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableListType.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -0,0 +1,75 @@
+package org.hibernate.test.usercollection.parameterized;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.List;
+
+import org.hibernate.usertype.UserCollectionType;
+import org.hibernate.usertype.ParameterizedType;
+import org.hibernate.collection.PersistentCollection;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.persister.collection.CollectionPersister;
+import org.hibernate.EntityMode;
+
+/**
+ * Our Hibernate type-system extension for defining our specialized collection
+ * contract.
+ *
+ * @author Holger Brands
+ * @author Steve Ebersole
+ */
+public class DefaultableListType implements UserCollectionType, ParameterizedType {
+ private String defaultValue;
+
+ public Object instantiate(int anticipatedSize) {
+ DefaultableListImpl list = anticipatedSize < 0 ? new DefaultableListImpl() : new DefaultableListImpl( anticipatedSize );
+ list.setDefaultValue( defaultValue );
+ return list;
+ }
+
+ public PersistentCollection instantiate(
+ SessionImplementor session,
+ CollectionPersister persister) {
+ return new PersistentDefaultableList( session );
+ }
+
+ public PersistentCollection wrap(SessionImplementor session, Object collection) {
+ if ( session.getEntityMode() == EntityMode.DOM4J ) {
+ throw new IllegalStateException( "dom4j not supported" );
+ }
+ else {
+ return new PersistentDefaultableList( session, ( List ) collection );
+ }
+ }
+
+ public Iterator getElementsIterator(Object collection) {
+ return ( ( DefaultableList ) collection ).iterator();
+ }
+
+ public boolean contains(Object collection, Object entity) {
+ return ( ( DefaultableList ) collection ).contains( entity );
+ }
+
+ public Object indexOf(Object collection, Object entity) {
+ int index = ( ( DefaultableList ) collection ).indexOf( entity );
+ return index >= 0 ? new Integer( index ) : null;
+ }
+
+ public Object replaceElements(
+ Object original,
+ Object target,
+ CollectionPersister persister,
+ Object owner,
+ Map copyCache,
+ SessionImplementor session) {
+ DefaultableList result = ( DefaultableList ) target;
+ result.clear();
+ result.addAll( ( DefaultableList ) original );
+ return result;
+ }
+
+ public void setParameterValues(Properties parameters) {
+ defaultValue = parameters.getProperty( "default" );
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/Entity.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/Entity.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/Entity.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -0,0 +1,33 @@
+package org.hibernate.test.usercollection.parameterized;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * 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;
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/Mapping.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/Mapping.hbm.xml (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/Mapping.hbm.xml 2007-05-09 03:54:06 UTC (rev 11496)
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.usercollection.parameterized" default-access="field">
+
+ <typedef name="DefaultableList" class="org.hibernate.test.usercollection.parameterized.DefaultableListType">
+ <param name="default">Hello</param>
+ </typedef>
+
+ <class name="Entity">
+ <id name="name" type="string"/>
+ <list name="values" fetch="join" table="ENT_VAL" collection-type="DefaultableList">
+ <key column="ENT_ID"/>
+ <list-index column="POSITION"/>
+ <element type="string" column="VAL"/>
+ </list>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/ParameterizedUserCollectionTypeTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/ParameterizedUserCollectionTypeTest.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/ParameterizedUserCollectionTypeTest.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -0,0 +1,49 @@
+package org.hibernate.test.usercollection.parameterized;
+
+import junit.framework.Test;
+
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.Hibernate;
+
+/**
+ * Tes for parameterized user collection types.
+ *
+ * @author Holger Brands
+ * @author Steve Ebersole
+ */
+public class ParameterizedUserCollectionTypeTest extends FunctionalTestCase {
+ public ParameterizedUserCollectionTypeTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( ParameterizedUserCollectionTypeTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "usercollection/parameterized/Mapping.hbm.xml" };
+ }
+
+ public void testBasicOperation() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Entity entity = new Entity( "tester" );
+ entity.getValues().add( "value-1" );
+ s.persist( entity );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ entity = ( Entity ) s.get( Entity.class, "tester" );
+ assertTrue( Hibernate.isInitialized( entity.getValues() ) );
+ assertEquals( 1, entity.getValues().size() );
+ assertEquals( "Hello", ( ( DefaultableList ) entity.getValues() ).getDefaultValue() );
+ s.delete( entity );
+ t.commit();
+ s.close();
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/PersistentDefaultableList.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/PersistentDefaultableList.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/usercollection/parameterized/PersistentDefaultableList.java 2007-05-09 03:54:06 UTC (rev 11496)
@@ -0,0 +1,29 @@
+package org.hibernate.test.usercollection.parameterized;
+
+import java.util.List;
+
+import org.hibernate.collection.PersistentList;
+import org.hibernate.engine.SessionImplementor;
+
+/**
+ * The "persistent wrapper" around our specialized collection contract
+ *
+ * @author Holger Brands
+ * @author Steve Ebersole
+ */
+public class PersistentDefaultableList extends PersistentList implements DefaultableList {
+ public PersistentDefaultableList(SessionImplementor session) {
+ super( session );
+ }
+
+ public PersistentDefaultableList(SessionImplementor session, List list) {
+ super( session, list );
+ }
+
+ public PersistentDefaultableList() {
+ }
+
+ public String getDefaultValue() {
+ return ( ( DefaultableList ) this.list ).getDefaultValue();
+ }
+}
17 years
Hibernate SVN: r11495 - in branches/Branch_3_2/Hibernate3: src/org/hibernate/mapping and 5 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-05-08 23:52:56 -0400 (Tue, 08 May 2007)
New Revision: 11495
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeSuite.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/Email.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/IMyList.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/MyList.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/MyListType.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/PersistentMyList.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/User.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/UserCollectionTypeTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/UserPermissions.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableList.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableListImpl.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableListType.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/Entity.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/Mapping.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/ParameterizedUserCollectionTypeTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/PersistentDefaultableList.java
Removed:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/Email.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/IMyList.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/MyList.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/MyListType.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/PersistentMyList.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/User.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/UserPermissions.hbm.xml
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/HbmBinder.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/Collection.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/type/CustomCollectionType.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/type/TypeFactory.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java
Log:
HHH-2336 : parameterized UserCollectionType
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/HbmBinder.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2007-05-09 02:00:16 UTC (rev 11494)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -1345,7 +1345,17 @@
}
Attribute typeNode = node.attribute( "collection-type" );
- if ( typeNode != null ) collection.setTypeName( typeNode.getValue() );
+ if ( typeNode != null ) {
+ String typeName = typeNode.getValue();
+ TypeDef typeDef = mappings.getTypeDef( typeName );
+ if ( typeDef != null ) {
+ collection.setTypeName( typeDef.getTypeClass() );
+ collection.setTypeParameters( typeDef.getParameters() );
+ }
+ else {
+ collection.setTypeName( typeName );
+ }
+ }
// FETCH STRATEGY
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/Collection.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/Collection.java 2007-05-09 02:00:16 UTC (rev 11494)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/Collection.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -5,6 +5,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Properties;
import org.hibernate.FetchMode;
import org.hibernate.MappingException;
@@ -56,6 +57,7 @@
private boolean optimisticLocked = true;
private Class collectionPersisterClass;
private String typeName;
+ private Properties typeParameters;
private final java.util.Map filters = new HashMap();
private final java.util.Map manyToManyFilters = new HashMap();
private final java.util.Set synchronizedTables = new HashSet();
@@ -345,7 +347,7 @@
return getDefaultCollectionType();
}
else {
- return TypeFactory.customCollection( typeName, role, referencedPropertyName, isEmbedded() );
+ return TypeFactory.customCollection( typeName, typeParameters, role, referencedPropertyName, isEmbedded() );
}
}
@@ -541,6 +543,14 @@
this.typeName = typeName;
}
+ public Properties getTypeParameters() {
+ return typeParameters;
+ }
+
+ public void setTypeParameters(Properties parameterMap) {
+ this.typeParameters = parameterMap;
+ }
+
public boolean[] getColumnInsertability() {
return ArrayHelper.EMPTY_BOOLEAN_ARRAY;
}
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/type/CustomCollectionType.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/type/CustomCollectionType.java 2007-05-09 02:00:16 UTC (rev 11494)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/type/CustomCollectionType.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -87,4 +87,8 @@
return super.renderLoggableString( value, factory );
}
}
+
+ public UserCollectionType getUserType() {
+ return userType;
+ }
}
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/type/TypeFactory.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/type/TypeFactory.java 2007-05-09 02:00:16 UTC (rev 11494)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/type/TypeFactory.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -256,16 +256,37 @@
}
- public static CollectionType customCollection(String typeName, String role, String propertyRef,
+ /**
+ * The legacy contract.
+ *
+ * @deprecated Use {@link #customCollection(String, java.util.Properties, String, String, boolean)} instead
+ */
+ public static CollectionType customCollection(
+ String typeName,
+ String role,
+ String propertyRef,
boolean embedded) {
+ return customCollection( typeName, null, role, propertyRef, embedded );
+ }
+
+ public static CollectionType customCollection(
+ String typeName,
+ Properties typeParameters,
+ String role,
+ String propertyRef,
+ boolean embedded) {
Class typeClass;
try {
typeClass = ReflectHelper.classForName( typeName );
}
- catch (ClassNotFoundException cnfe) {
- throw new MappingException( "user colllection type class not found: " + typeName, cnfe );
+ catch ( ClassNotFoundException cnfe ) {
+ throw new MappingException( "user collection type class not found: " + typeName, cnfe );
}
- return new CustomCollectionType( typeClass, role, propertyRef, embedded );
+ CustomCollectionType result = new CustomCollectionType( typeClass, role, propertyRef, embedded );
+ if ( typeParameters != null ) {
+ TypeFactory.injectParameters( result.getUserType(), typeParameters );
+ }
+ return result;
}
// Collection Types:
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java 2007-05-09 02:00:16 UTC (rev 11494)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -123,7 +123,7 @@
import org.hibernate.test.unconstrained.UnconstrainedTest;
import org.hibernate.test.unidir.BackrefTest;
import org.hibernate.test.unionsubclass.UnionSubclassTest;
-import org.hibernate.test.usercollection.UserCollectionTypeTest;
+import org.hibernate.test.usercollection.UserCollectionTypeSuite;
import org.hibernate.test.util.UtilSuite;
import org.hibernate.test.version.VersionTest;
import org.hibernate.test.version.db.DbVersionTest;
@@ -299,7 +299,7 @@
suite.addTest( LobSuite.suite() );
suite.addTest( IdentifierPropertyReferencesTest.suite() );
suite.addTest( DeleteTransientEntityTest.suite() );
- suite.addTest( UserCollectionTypeTest.suite() );
+ suite.addTest( UserCollectionTypeSuite.suite() );
suite.addTest( KeyManyToOneSuite.suite() );
suite.addTest( DialectFunctionalTestsSuite.suite() );
suite.addTest( DialectUnitTestsSuite.suite() );
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/Email.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/Email.java 2007-05-09 02:00:16 UTC (rev 11494)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/Email.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -1,39 +0,0 @@
-//$Id$
-package org.hibernate.test.usercollection;
-
-/**
- * @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;
- }
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/IMyList.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/IMyList.java 2007-05-09 02:00:16 UTC (rev 11494)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/IMyList.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -1,7 +0,0 @@
-package org.hibernate.test.usercollection;
-
-import java.util.List;
-
-public interface IMyList extends List {
-
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/MyList.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/MyList.java 2007-05-09 02:00:16 UTC (rev 11494)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/MyList.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -1,14 +0,0 @@
-package org.hibernate.test.usercollection;
-
-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 {
-
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/MyListType.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/MyListType.java 2007-05-09 02:00:16 UTC (rev 11494)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/MyListType.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -1,60 +0,0 @@
-package org.hibernate.test.usercollection;
-
-import java.util.Iterator;
-import java.util.Map;
-
-import org.hibernate.EntityMode;
-import org.hibernate.HibernateException;
-import org.hibernate.collection.PersistentCollection;
-import org.hibernate.engine.SessionImplementor;
-import org.hibernate.persister.collection.CollectionPersister;
-import org.hibernate.usertype.UserCollectionType;
-
-public class MyListType implements UserCollectionType {
-
- static int lastInstantiationRequest = -2;
-
- public PersistentCollection instantiate(SessionImplementor session, CollectionPersister persister) throws HibernateException {
- return new PersistentMyList(session);
- }
-
- public PersistentCollection wrap(SessionImplementor session, Object collection) {
- if ( session.getEntityMode()==EntityMode.DOM4J ) {
- throw new IllegalStateException("dom4j not supported");
- }
- else {
- return new PersistentMyList( session, (IMyList) collection );
- }
- }
-
- public Iterator getElementsIterator(Object collection) {
- return ( (IMyList) collection ).iterator();
- }
-
- public boolean contains(Object collection, Object entity) {
- return ( (IMyList) collection ).contains(entity);
- }
-
- public Object indexOf(Object collection, Object entity) {
- int l = ( (IMyList) collection ).indexOf(entity);
- if(l<0) {
- return null;
- } else {
- return new Integer(l);
- }
- }
-
- public Object replaceElements(Object original, Object target, CollectionPersister persister, Object owner, Map copyCache, SessionImplementor session) throws HibernateException {
- IMyList result = (IMyList) target;
- result.clear();
- result.addAll((MyList)original);
- return result;
- }
-
- public Object instantiate(int anticipatedSize) {
- lastInstantiationRequest = anticipatedSize;
- return new MyList();
- }
-
-
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/PersistentMyList.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/PersistentMyList.java 2007-05-09 02:00:16 UTC (rev 11494)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/PersistentMyList.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -1,18 +0,0 @@
-package org.hibernate.test.usercollection;
-
-import org.hibernate.collection.PersistentList;
-import org.hibernate.engine.SessionImplementor;
-
-public class PersistentMyList extends PersistentList implements IMyList {
-
- public PersistentMyList(SessionImplementor session) {
- super(session);
- }
-
- public PersistentMyList(SessionImplementor session, IMyList list) {
- super(session, list);
- }
-
-
-
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/User.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/User.java 2007-05-09 02:00:16 UTC (rev 11494)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/User.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -1,39 +0,0 @@
-//$Id$
-package org.hibernate.test.usercollection;
-
-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;
- }
-}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeSuite.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeSuite.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeSuite.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -0,0 +1,21 @@
+package org.hibernate.test.usercollection;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.usercollection.basic.UserCollectionTypeTest;
+import org.hibernate.test.usercollection.parameterized.ParameterizedUserCollectionTypeTest;
+
+/**
+ * Suite for testing various aspects of user collection types.
+ *
+ * @author Steve Ebersole
+ */
+public class UserCollectionTypeSuite {
+ public static Test suite() {
+ TestSuite suite = new TestSuite( "user collection type tests" );
+ suite.addTest( UserCollectionTypeTest.suite() );
+ suite.addTest( ParameterizedUserCollectionTypeTest.suite() );
+ return suite;
+ }
+}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeTest.java 2007-05-09 02:00:16 UTC (rev 11494)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeTest.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -1,63 +0,0 @@
-//$Id$
-package org.hibernate.test.usercollection;
-
-import junit.framework.Test;
-
-import org.hibernate.Hibernate;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.junit.functional.FunctionalTestCase;
-import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
-
-/**
- * @author Max Rydahl Andersen
- */
-public class UserCollectionTypeTest extends FunctionalTestCase {
-
- public UserCollectionTypeTest(String str) {
- super(str);
- }
-
- public String[] getMappings() {
- return new String[] { "usercollection/UserPermissions.hbm.xml" };
- }
-
- public static Test suite() {
- return new FunctionalTestClassTestSuite( UserCollectionTypeTest.class );
- }
-
- public void testBasicOperation() {
- Session s = openSession();
- Transaction t = s.beginTransaction();
- User u = new User("max");
- u.getEmailAddresses().add( new Email("max(a)hibernate.org") );
- u.getEmailAddresses().add( new Email("max.andersen(a)jboss.com") );
- s.persist(u);
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- User u2 = (User) s.createCriteria(User.class).uniqueResult();
- assertTrue( Hibernate.isInitialized( u2.getEmailAddresses() ) );
- assertEquals( u2.getEmailAddresses().size(), 2 );
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- u2 = ( User ) s.get( User.class, u.getUserName() );
- u2.getEmailAddresses().size();
- assertEquals( 2, MyListType.lastInstantiationRequest );
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- s.delete( u );
- t.commit();
- s.close();
- }
-
-}
-
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/UserPermissions.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/UserPermissions.hbm.xml 2007-05-09 02:00:16 UTC (rev 11494)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/UserPermissions.hbm.xml 2007-05-09 03:52:56 UTC (rev 11495)
@@ -1,33 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<!--
-
- This mapping is a basic example of how to write a UserCollectionType.
-
--->
-
-<hibernate-mapping
- package="org.hibernate.test.usercollection">
-
- <import class="Permission"/>
-
- <class name="User" table="`Users`">
- <id name="userName"/>
- <list name="emailAddresses" fetch="join" cascade="all, delete-orphan" collection-type="org.hibernate.test.usercollection.MyListType">
- <key column="userName"/>
- <list-index column="displayOrder" base="1"/>
- <one-to-many class="Email"/>
- </list>
- </class>
-
- <class name="Email">
- <id name="id">
- <generator class="native"/>
- </id>
- <property name="address"/>
- </class>
-
-</hibernate-mapping>
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/Email.java (from rev 11089, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/Email.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/Email.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/Email.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -0,0 +1,39 @@
+//$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;
+ }
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/Email.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/IMyList.java (from rev 11089, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/IMyList.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/IMyList.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/IMyList.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -0,0 +1,7 @@
+package org.hibernate.test.usercollection.basic;
+
+import java.util.List;
+
+public interface IMyList extends List {
+
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/IMyList.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/MyList.java (from rev 11089, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/MyList.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/MyList.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/MyList.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -0,0 +1,14 @@
+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 {
+
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/MyList.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/MyListType.java (from rev 11089, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/MyListType.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/MyListType.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/MyListType.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -0,0 +1,60 @@
+package org.hibernate.test.usercollection.basic;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.hibernate.EntityMode;
+import org.hibernate.HibernateException;
+import org.hibernate.collection.PersistentCollection;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.persister.collection.CollectionPersister;
+import org.hibernate.usertype.UserCollectionType;
+
+public class MyListType implements UserCollectionType {
+
+ static int lastInstantiationRequest = -2;
+
+ public PersistentCollection instantiate(SessionImplementor session, CollectionPersister persister) throws HibernateException {
+ return new PersistentMyList(session);
+ }
+
+ public PersistentCollection wrap(SessionImplementor session, Object collection) {
+ if ( session.getEntityMode()==EntityMode.DOM4J ) {
+ throw new IllegalStateException("dom4j not supported");
+ }
+ else {
+ return new PersistentMyList( session, (IMyList) collection );
+ }
+ }
+
+ public Iterator getElementsIterator(Object collection) {
+ return ( (IMyList) collection ).iterator();
+ }
+
+ public boolean contains(Object collection, Object entity) {
+ return ( (IMyList) collection ).contains(entity);
+ }
+
+ public Object indexOf(Object collection, Object entity) {
+ int l = ( (IMyList) collection ).indexOf(entity);
+ if(l<0) {
+ return null;
+ } else {
+ return new Integer(l);
+ }
+ }
+
+ public Object replaceElements(Object original, Object target, CollectionPersister persister, Object owner, Map copyCache, SessionImplementor session) throws HibernateException {
+ IMyList result = (IMyList) target;
+ result.clear();
+ result.addAll((MyList)original);
+ return result;
+ }
+
+ public Object instantiate(int anticipatedSize) {
+ lastInstantiationRequest = anticipatedSize;
+ return new MyList();
+ }
+
+
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/MyListType.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/PersistentMyList.java (from rev 11089, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/PersistentMyList.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/PersistentMyList.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/PersistentMyList.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -0,0 +1,18 @@
+package org.hibernate.test.usercollection.basic;
+
+import org.hibernate.collection.PersistentList;
+import org.hibernate.engine.SessionImplementor;
+
+public class PersistentMyList extends PersistentList implements IMyList {
+
+ public PersistentMyList(SessionImplementor session) {
+ super(session);
+ }
+
+ public PersistentMyList(SessionImplementor session, IMyList list) {
+ super(session, list);
+ }
+
+
+
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/PersistentMyList.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/User.java (from rev 11089, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/User.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/User.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/User.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -0,0 +1,39 @@
+//$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;
+ }
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/User.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/UserCollectionTypeTest.java (from rev 11089, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeTest.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/UserCollectionTypeTest.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/UserCollectionTypeTest.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -0,0 +1,63 @@
+//$Id$
+package org.hibernate.test.usercollection.basic;
+
+import junit.framework.Test;
+
+import org.hibernate.Hibernate;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+
+/**
+ * @author Max Rydahl Andersen
+ */
+public class UserCollectionTypeTest extends FunctionalTestCase {
+
+ public UserCollectionTypeTest(String str) {
+ super(str);
+ }
+
+ public String[] getMappings() {
+ return new String[] { "usercollection/basic/UserPermissions.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( UserCollectionTypeTest.class );
+ }
+
+ public void testBasicOperation() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ User u = new User("max");
+ u.getEmailAddresses().add( new Email("max(a)hibernate.org") );
+ u.getEmailAddresses().add( new Email("max.andersen(a)jboss.com") );
+ s.persist(u);
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ User u2 = (User) s.createCriteria(User.class).uniqueResult();
+ assertTrue( Hibernate.isInitialized( u2.getEmailAddresses() ) );
+ assertEquals( u2.getEmailAddresses().size(), 2 );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ u2 = ( User ) s.get( User.class, u.getUserName() );
+ u2.getEmailAddresses().size();
+ assertEquals( 2, MyListType.lastInstantiationRequest );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ s.delete( u );
+ t.commit();
+ s.close();
+ }
+
+}
+
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/UserCollectionTypeTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/UserPermissions.hbm.xml (from rev 11089, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/UserPermissions.hbm.xml)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/UserPermissions.hbm.xml (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/UserPermissions.hbm.xml 2007-05-09 03:52:56 UTC (rev 11495)
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+ This mapping is a basic example of how to write a UserCollectionType.
+-->
+
+<hibernate-mapping package="org.hibernate.test.usercollection.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">
+ <key column="userName"/>
+ <list-index column="displayOrder" base="1"/>
+ <one-to-many class="Email"/>
+ </list>
+ </class>
+
+ <class name="Email">
+ <id name="id">
+ <generator class="native"/>
+ </id>
+ <property name="address"/>
+ </class>
+
+</hibernate-mapping>
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/basic/UserPermissions.hbm.xml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableList.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableList.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableList.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -0,0 +1,13 @@
+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();
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableListImpl.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableListImpl.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableListImpl.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -0,0 +1,28 @@
+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;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableListType.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableListType.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/DefaultableListType.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -0,0 +1,75 @@
+package org.hibernate.test.usercollection.parameterized;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.List;
+
+import org.hibernate.usertype.UserCollectionType;
+import org.hibernate.usertype.ParameterizedType;
+import org.hibernate.collection.PersistentCollection;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.persister.collection.CollectionPersister;
+import org.hibernate.EntityMode;
+
+/**
+ * Our Hibernate type-system extension for defining our specialized collection
+ * contract.
+ *
+ * @author Holger Brands
+ * @author Steve Ebersole
+ */
+public class DefaultableListType implements UserCollectionType, ParameterizedType {
+ private String defaultValue;
+
+ public Object instantiate(int anticipatedSize) {
+ DefaultableListImpl list = anticipatedSize < 0 ? new DefaultableListImpl() : new DefaultableListImpl( anticipatedSize );
+ list.setDefaultValue( defaultValue );
+ return list;
+ }
+
+ public PersistentCollection instantiate(
+ SessionImplementor session,
+ CollectionPersister persister) {
+ return new PersistentDefaultableList( session );
+ }
+
+ public PersistentCollection wrap(SessionImplementor session, Object collection) {
+ if ( session.getEntityMode() == EntityMode.DOM4J ) {
+ throw new IllegalStateException( "dom4j not supported" );
+ }
+ else {
+ return new PersistentDefaultableList( session, ( List ) collection );
+ }
+ }
+
+ public Iterator getElementsIterator(Object collection) {
+ return ( ( DefaultableList ) collection ).iterator();
+ }
+
+ public boolean contains(Object collection, Object entity) {
+ return ( ( DefaultableList ) collection ).contains( entity );
+ }
+
+ public Object indexOf(Object collection, Object entity) {
+ int index = ( ( DefaultableList ) collection ).indexOf( entity );
+ return index >= 0 ? new Integer( index ) : null;
+ }
+
+ public Object replaceElements(
+ Object original,
+ Object target,
+ CollectionPersister persister,
+ Object owner,
+ Map copyCache,
+ SessionImplementor session) {
+ DefaultableList result = ( DefaultableList ) target;
+ result.clear();
+ result.addAll( ( DefaultableList ) original );
+ return result;
+ }
+
+ public void setParameterValues(Properties parameters) {
+ defaultValue = parameters.getProperty( "default" );
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/Entity.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/Entity.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/Entity.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -0,0 +1,33 @@
+package org.hibernate.test.usercollection.parameterized;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * 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;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/Mapping.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/Mapping.hbm.xml (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/Mapping.hbm.xml 2007-05-09 03:52:56 UTC (rev 11495)
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.usercollection.parameterized" default-access="field">
+
+ <typedef name="DefaultableList" class="org.hibernate.test.usercollection.parameterized.DefaultableListType">
+ <param name="default">Hello</param>
+ </typedef>
+
+ <class name="Entity">
+ <id name="name" type="string"/>
+ <list name="values" fetch="join" table="ENT_VAL" collection-type="DefaultableList">
+ <key column="ENT_ID"/>
+ <list-index column="POSITION"/>
+ <element type="string" column="VAL"/>
+ </list>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/ParameterizedUserCollectionTypeTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/ParameterizedUserCollectionTypeTest.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/ParameterizedUserCollectionTypeTest.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -0,0 +1,49 @@
+package org.hibernate.test.usercollection.parameterized;
+
+import junit.framework.Test;
+
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.Hibernate;
+
+/**
+ * Tes for parameterized user collection types.
+ *
+ * @author Holger Brands
+ * @author Steve Ebersole
+ */
+public class ParameterizedUserCollectionTypeTest extends FunctionalTestCase {
+ public ParameterizedUserCollectionTypeTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( ParameterizedUserCollectionTypeTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "usercollection/parameterized/Mapping.hbm.xml" };
+ }
+
+ public void testBasicOperation() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Entity entity = new Entity( "tester" );
+ entity.getValues().add( "value-1" );
+ s.persist( entity );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ entity = ( Entity ) s.get( Entity.class, "tester" );
+ assertTrue( Hibernate.isInitialized( entity.getValues() ) );
+ assertEquals( 1, entity.getValues().size() );
+ assertEquals( "Hello", ( ( DefaultableList ) entity.getValues() ).getDefaultValue() );
+ s.delete( entity );
+ t.commit();
+ s.close();
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/PersistentDefaultableList.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/PersistentDefaultableList.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/usercollection/parameterized/PersistentDefaultableList.java 2007-05-09 03:52:56 UTC (rev 11495)
@@ -0,0 +1,29 @@
+package org.hibernate.test.usercollection.parameterized;
+
+import java.util.List;
+
+import org.hibernate.collection.PersistentList;
+import org.hibernate.engine.SessionImplementor;
+
+/**
+ * The "persistent wrapper" around our specialized collection contract
+ *
+ * @author Holger Brands
+ * @author Steve Ebersole
+ */
+public class PersistentDefaultableList extends PersistentList implements DefaultableList {
+ public PersistentDefaultableList(SessionImplementor session) {
+ super( session );
+ }
+
+ public PersistentDefaultableList(SessionImplementor session, List list) {
+ super( session, list );
+ }
+
+ public PersistentDefaultableList() {
+ }
+
+ public String getDefaultValue() {
+ return ( ( DefaultableList ) this.list ).getDefaultValue();
+ }
+}
17 years
Hibernate SVN: r11494 - trunk/Hibernate3/src/org/hibernate.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-05-08 22:00:16 -0400 (Tue, 08 May 2007)
New Revision: 11494
Modified:
trunk/Hibernate3/src/org/hibernate/Session.java
Log:
HHH-2603 : deprecate Session.connection()
Modified: trunk/Hibernate3/src/org/hibernate/Session.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/Session.java 2007-05-09 02:00:05 UTC (rev 11493)
+++ trunk/Hibernate3/src/org/hibernate/Session.java 2007-05-09 02:00:16 UTC (rev 11494)
@@ -158,6 +158,7 @@
*
* @return the JDBC connection in use by the <tt>Session</tt>
* @throws HibernateException if the <tt>Session</tt> is disconnected
+ * @deprecated To be replaced with a SPI for performing work against the connection; scheduled for removal in 4.x
*/
public Connection connection() throws HibernateException;
17 years
Hibernate SVN: r11493 - branches/Branch_3_2/Hibernate3/src/org/hibernate.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-05-08 22:00:05 -0400 (Tue, 08 May 2007)
New Revision: 11493
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/Session.java
Log:
HHH-2603 : deprecate Session.connection()
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/Session.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/Session.java 2007-05-09 01:57:11 UTC (rev 11492)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/Session.java 2007-05-09 02:00:05 UTC (rev 11493)
@@ -158,6 +158,7 @@
*
* @return the JDBC connection in use by the <tt>Session</tt>
* @throws HibernateException if the <tt>Session</tt> is disconnected
+ * @deprecated To be replaced with a SPI for performing work against the connection; scheduled for removal in 4.x
*/
public Connection connection() throws HibernateException;
17 years
Hibernate SVN: r11492 - trunk/Hibernate3/src/org/hibernate/cache.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-05-08 21:57:11 -0400 (Tue, 08 May 2007)
New Revision: 11492
Modified:
trunk/Hibernate3/src/org/hibernate/cache/CacheException.java
Log:
have ctor take Throwable, not Exception
Modified: trunk/Hibernate3/src/org/hibernate/cache/CacheException.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/cache/CacheException.java 2007-05-09 01:56:57 UTC (rev 11491)
+++ trunk/Hibernate3/src/org/hibernate/cache/CacheException.java 2007-05-09 01:57:11 UTC (rev 11492)
@@ -12,18 +12,12 @@
super(s);
}
- public CacheException(String s, Exception e) {
+ public CacheException(String s, Throwable e) {
super(s, e);
}
- public CacheException(Exception e) {
+ public CacheException(Throwable e) {
super(e);
}
}
-
-
-
-
-
-
17 years