Hibernate SVN: r10320 - trunk/Hibernate3/src/org/hibernate/mapping
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-08-23 17:57:26 -0400 (Wed, 23 Aug 2006)
New Revision: 10320
Modified:
trunk/Hibernate3/src/org/hibernate/mapping/PersistentClass.java
Log:
ANN-381 add identifierProperty to getProperty and getRecursiveProperty
Modified: trunk/Hibernate3/src/org/hibernate/mapping/PersistentClass.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/mapping/PersistentClass.java 2006-08-23 21:57:10 UTC (rev 10319)
+++ trunk/Hibernate3/src/org/hibernate/mapping/PersistentClass.java 2006-08-23 21:57:26 UTC (rev 10320)
@@ -349,7 +349,14 @@
while ( st.hasMoreElements() ) {
String element = (String) st.nextElement();
if (property == null) {
- property = getProperty( element, iter );
+ Property identifierProperty = getIdentifierProperty();
+ if ( identifierProperty != null
+ && identifierProperty.getName().equals( StringHelper.root(element) ) ) {
+ property = identifierProperty;
+ }
+ else {
+ property = getProperty( element, iter );
+ }
}
else {
//flat recursive algorithm
@@ -379,7 +386,15 @@
public Property getProperty(String propertyName) throws MappingException {
Iterator iter = getPropertyClosureIterator();
- return getProperty( propertyName, iter );
+ Property identifierProperty = getIdentifierProperty();
+ if ( identifierProperty != null
+ && identifierProperty.getName().equals( StringHelper.root(propertyName) )
+ ) {
+ return identifierProperty;
+ }
+ else {
+ return getProperty( propertyName, iter );
+ }
}
abstract public int getOptimisticLockMode();
17 years, 9 months
Hibernate SVN: r10319 - branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-08-23 17:57:10 -0400 (Wed, 23 Aug 2006)
New Revision: 10319
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/PersistentClass.java
Log:
ANN-381 add identifierProperty to getProperty and getRecursiveProperty
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/PersistentClass.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/PersistentClass.java 2006-08-23 13:36:35 UTC (rev 10318)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/PersistentClass.java 2006-08-23 21:57:10 UTC (rev 10319)
@@ -349,7 +349,14 @@
while ( st.hasMoreElements() ) {
String element = (String) st.nextElement();
if (property == null) {
- property = getProperty( element, iter );
+ Property identifierProperty = getIdentifierProperty();
+ if ( identifierProperty != null
+ && identifierProperty.getName().equals( StringHelper.root(element) ) ) {
+ property = identifierProperty;
+ }
+ else {
+ property = getProperty( element, iter );
+ }
}
else {
//flat recursive algorithm
@@ -379,7 +386,15 @@
public Property getProperty(String propertyName) throws MappingException {
Iterator iter = getPropertyClosureIterator();
- return getProperty( propertyName, iter );
+ Property identifierProperty = getIdentifierProperty();
+ if ( identifierProperty != null
+ && identifierProperty.getName().equals( StringHelper.root(propertyName) )
+ ) {
+ return identifierProperty;
+ }
+ else {
+ return getProperty( propertyName, iter );
+ }
}
abstract public int getOptimisticLockMode();
17 years, 9 months
Hibernate SVN: r10318 - branches/Branch_3_2/Hibernate3/src/org/hibernate/util
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-08-23 09:36:35 -0400 (Wed, 23 Aug 2006)
New Revision: 10318
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/util/StringHelper.java
Log:
HHH-2022 : property names with leading underscores
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/util/StringHelper.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/util/StringHelper.java 2006-08-23 13:35:51 UTC (rev 10317)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/util/StringHelper.java 2006-08-23 13:36:35 UTC (rev 10318)
@@ -305,6 +305,10 @@
}
}
+ public static String generateAlias(String description) {
+ return generateAliasRoot(description) + '_';
+ }
+
/**
* Generate a nice alias for the given class name or collection role
* name and unique integer. Subclasses of Loader do <em>not</em> have
@@ -317,11 +321,20 @@
'_';
}
+ /**
+ * Generates a root alias by truncating the "root name" defined by
+ * the incoming decription and removing/modifying any non-valid
+ * alias characters.
+ *
+ * @param description The root name from which to generate a root alias.
+ * @return The generated root alias.
+ */
private static String generateAliasRoot(String description) {
- final String result = truncate( unqualifyEntityName(description), ALIAS_TRUNCATE_LENGTH )
+ String result = truncate( unqualifyEntityName(description), ALIAS_TRUNCATE_LENGTH )
.toLowerCase()
.replace( '/', '_' ) // entityNames may now include slashes for the representations
.replace( '$', '_' ); //classname may be an inner class
+ result = cleanAlias( result );
if ( Character.isDigit( result.charAt(result.length()-1) ) ) {
return result + "x"; //ick!
}
@@ -330,6 +343,28 @@
}
}
+ /**
+ * Clean the generated alias by removing any non-alpha characters from the
+ * beginning.
+ *
+ * @param alias The generated alias to be cleaned.
+ * @return The cleaned alias, stripped of any leading non-alpha characters.
+ */
+ private static String cleanAlias(String alias) {
+ char[] chars = alias.toCharArray();
+ // short cut check...
+ if ( !Character.isLetter( chars[0] ) ) {
+ for ( int i = 1; i < chars.length; i++ ) {
+ // as soon as we encounter our first letter, return the substring
+ // from that position
+ if ( Character.isLetter( chars[i] ) ) {
+ return alias.substring( i );
+ }
+ }
+ }
+ return alias;
+ }
+
public static String unqualifyEntityName(String entityName) {
String result = unqualify(entityName);
int slashPos = result.indexOf( '/' );
@@ -339,10 +374,6 @@
return result;
}
- public static String generateAlias(String description) {
- return generateAliasRoot(description) + '_';
- }
-
public static String toUpperCase(String str) {
return str==null ? null : str.toUpperCase();
}
17 years, 9 months
Hibernate SVN: r10317 - branches/Branch_3_2/Hibernate3/test/org/hibernate/test
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-08-23 09:35:51 -0400 (Wed, 23 Aug 2006)
New Revision: 10317
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java
Log:
HHH-2022 : property names with leading underscores
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java 2006-08-23 13:35:06 UTC (rev 10316)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java 2006-08-23 13:35:51 UTC (rev 10317)
@@ -130,6 +130,7 @@
import org.hibernate.test.version.db.DbVersionTest;
import org.hibernate.test.version.sybase.SybaseTimestampVersioningTest;
import org.hibernate.test.where.WhereTest;
+import org.hibernate.test.util.UtilSuite;
/**
* @author Gavin King
@@ -290,6 +291,7 @@
suite.addTest( JPAComplianceSuite.suite() );
suite.addTest( AbstractComponentPropertyRefTest.suite() );
suite.addTest( AbstractCompositeIdTest.suite() );
+ suite.addTest( UtilSuite.suite() );
return filter( suite );
//return suite;
17 years, 9 months
Hibernate SVN: r10316 - in branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util: . dtd
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-08-23 09:35:06 -0400 (Wed, 23 Aug 2006)
New Revision: 10316
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/StringHelperTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/UtilSuite.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/Child.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/EntityResolverTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/Parent.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/Parent.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/child.xml
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/PropertiesHelperTest.java
Log:
HHH-2022 : property names with leading underscores
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/PropertiesHelperTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/PropertiesHelperTest.java 2006-08-23 13:22:54 UTC (rev 10315)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/PropertiesHelperTest.java 2006-08-23 13:35:06 UTC (rev 10316)
@@ -1,6 +1,8 @@
package org.hibernate.test.util;
import junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
import java.util.Properties;
import java.util.Iterator;
@@ -101,4 +103,8 @@
catch( NumberFormatException expected ) {
}
}
+
+ public static Test suite() {
+ return new TestSuite( PropertiesHelperTest.class );
+ }
}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/StringHelperTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/StringHelperTest.java 2006-08-23 13:22:54 UTC (rev 10315)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/StringHelperTest.java 2006-08-23 13:35:06 UTC (rev 10316)
@@ -0,0 +1,32 @@
+package org.hibernate.test.util;
+
+import junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.hibernate.util.StringHelper;
+
+/**
+ * todo: describe StringHelperTest
+ *
+ * @author Steve Ebersole
+ */
+public class StringHelperTest extends TestCase {
+ public StringHelperTest(String string) {
+ super( string );
+ }
+
+ public void testAliasGeneration() {
+ assertSimpleAlias( "xyz", "xyz_" );
+ assertSimpleAlias( "_xyz", "xyz_" );
+ assertSimpleAlias( "!xyz", "xyz_" );
+ assertSimpleAlias( "abcdefghijklmnopqrstuvwxyz", "abcdefghij_" );
+ }
+
+ private void assertSimpleAlias(String source, String expected) {
+ assertEquals( expected, StringHelper.generateAlias( source ) );
+ }
+
+ public static Test suite() {
+ return new TestSuite( StringHelperTest.class );
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/UtilSuite.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/UtilSuite.java 2006-08-23 13:22:54 UTC (rev 10315)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/UtilSuite.java 2006-08-23 13:35:06 UTC (rev 10316)
@@ -0,0 +1,20 @@
+package org.hibernate.test.util;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.hibernate.test.util.dtd.EntityResolverTest;
+
+/**
+ * todo: describe UtilSuite
+ *
+ * @author Steve Ebersole
+ */
+public class UtilSuite {
+ public static Test suite() {
+ TestSuite suite = new TestSuite( "Utility package tests" );
+ suite.addTest( PropertiesHelperTest.suite() );
+ suite.addTest( EntityResolverTest.suite() );
+ suite.addTest( StringHelperTest.suite() );
+ return suite;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/Child.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/Child.java 2006-08-23 13:22:54 UTC (rev 10315)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/Child.java 2006-08-23 13:35:06 UTC (rev 10316)
@@ -0,0 +1,36 @@
+package org.hibernate.test.util.dtd;
+
+/**
+ * The Child class.
+ *
+ * @author Steve Ebersole
+ */
+public class Child {
+ private Long id;
+ private int age;
+ private Parent parent;
+
+ public Child() {
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public Parent getParent() {
+ return parent;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+
+ /*package*/ void injectParent(Parent parent) {
+ this.parent = parent;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/EntityResolverTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/EntityResolverTest.java 2006-08-23 13:22:54 UTC (rev 10315)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/EntityResolverTest.java 2006-08-23 13:35:06 UTC (rev 10316)
@@ -0,0 +1,28 @@
+package org.hibernate.test.util.dtd;
+
+import junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.hibernate.cfg.Configuration;
+
+
+/**
+ * todo: describe EntityResolverTest
+ *
+ * @author Steve Ebersole
+ */
+public class EntityResolverTest extends TestCase {
+ public EntityResolverTest(String name) {
+ super( name );
+ }
+
+ public void testEntityIncludeResolution() {
+ Configuration cfg = new Configuration();
+ cfg.addResource( "org/hibernate/test/util/dtd/Parent.hbm.xml" );
+ cfg.buildMappings();
+ }
+
+ public static Test suite() {
+ return new TestSuite( EntityResolverTest.class );
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/Parent.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/Parent.hbm.xml 2006-08-23 13:22:54 UTC (rev 10315)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/Parent.hbm.xml 2006-08-23 13:35:06 UTC (rev 10316)
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" [
+ <!ENTITY child SYSTEM "classpath://org/hibernate/test/util/dtd/child.xml">
+]>
+
+
+<hibernate-mapping package="org.hibernate.test.util.dtd" default-access="field">
+
+ <class name="Parent">
+ <id name="id" column="ID">
+ <generator class="increment"/>
+ </id>
+ <list name="children" inverse="true" cascade="persist,merge">
+ <key column="PRNT_ID" not-null="true"/>
+ <list-index column="SIBLING_ORD"/>
+ <one-to-many class="Child"/>
+ </list>
+ </class>
+
+ &child;
+
+</hibernate-mapping>
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/Parent.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/Parent.java 2006-08-23 13:22:54 UTC (rev 10315)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/Parent.java 2006-08-23 13:35:06 UTC (rev 10316)
@@ -0,0 +1,33 @@
+package org.hibernate.test.util.dtd;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Iterator;
+
+/**
+ * The Parent class.
+ *
+ * @author Steve Ebersole
+ */
+public class Parent {
+ private Long id;
+ private Set children = new HashSet();
+
+ public Long getId() {
+ return id;
+ }
+
+ public Iterator getChildren() {
+ return children.iterator();
+ }
+
+ public Child newChild() {
+ Child child = new Child();
+ child.setAge( 0 );
+
+ child.injectParent( this );
+ this.children.add( child );
+
+ return child;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/child.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/child.xml 2006-08-23 13:22:54 UTC (rev 10315)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/util/dtd/child.xml 2006-08-23 13:35:06 UTC (rev 10316)
@@ -0,0 +1,9 @@
+
+
+ <class name="Child">
+ <id name="id" column="ID">
+ <generator class="increment"/>
+ </id>
+ <property name="age" column="AGE" not-null="true"/>
+ <many-to-one name="parent" class="Parent" column="PRNT_ID"/>
+ </class>
\ No newline at end of file
17 years, 9 months
Hibernate SVN: r10315 - trunk/Hibernate3/src/org/hibernate/util
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-08-23 09:22:54 -0400 (Wed, 23 Aug 2006)
New Revision: 10315
Modified:
trunk/Hibernate3/src/org/hibernate/util/StringHelper.java
Log:
HHH-2022 : property names with leading underscores
Modified: trunk/Hibernate3/src/org/hibernate/util/StringHelper.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/util/StringHelper.java 2006-08-23 13:21:47 UTC (rev 10314)
+++ trunk/Hibernate3/src/org/hibernate/util/StringHelper.java 2006-08-23 13:22:54 UTC (rev 10315)
@@ -305,6 +305,10 @@
}
}
+ public static String generateAlias(String description) {
+ return generateAliasRoot(description) + '_';
+ }
+
/**
* Generate a nice alias for the given class name or collection role
* name and unique integer. Subclasses of Loader do <em>not</em> have
@@ -317,11 +321,20 @@
'_';
}
+ /**
+ * Generates a root alias by truncating the "root name" defined by
+ * the incoming decription and removing/modifying any non-valid
+ * alias characters.
+ *
+ * @param description The root name from which to generate a root alias.
+ * @return The generated root alias.
+ */
private static String generateAliasRoot(String description) {
- final String result = truncate( unqualifyEntityName(description), ALIAS_TRUNCATE_LENGTH )
+ String result = truncate( unqualifyEntityName(description), ALIAS_TRUNCATE_LENGTH )
.toLowerCase()
.replace( '/', '_' ) // entityNames may now include slashes for the representations
.replace( '$', '_' ); //classname may be an inner class
+ result = cleanAlias( result );
if ( Character.isDigit( result.charAt(result.length()-1) ) ) {
return result + "x"; //ick!
}
@@ -330,6 +343,28 @@
}
}
+ /**
+ * Clean the generated alias by removing any non-alpha characters from the
+ * beginning.
+ *
+ * @param alias The generated alias to be cleaned.
+ * @return The cleaned alias, stripped of any leading non-alpha characters.
+ */
+ private static String cleanAlias(String alias) {
+ char[] chars = alias.toCharArray();
+ // short cut check...
+ if ( !Character.isLetter( chars[0] ) ) {
+ for ( int i = 1; i < chars.length; i++ ) {
+ // as soon as we encounter our first letter, return the substring
+ // from that position
+ if ( Character.isLetter( chars[i] ) ) {
+ return alias.substring( i );
+ }
+ }
+ }
+ return alias;
+ }
+
public static String unqualifyEntityName(String entityName) {
String result = unqualify(entityName);
int slashPos = result.indexOf( '/' );
@@ -338,10 +373,6 @@
}
return result;
}
-
- public static String generateAlias(String description) {
- return generateAliasRoot(description) + '_';
- }
public static String toUpperCase(String str) {
return str==null ? null : str.toUpperCase();
17 years, 9 months
Hibernate SVN: r10314 - trunk/Hibernate3/test/org/hibernate/test/util
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-08-23 09:21:47 -0400 (Wed, 23 Aug 2006)
New Revision: 10314
Modified:
trunk/Hibernate3/test/org/hibernate/test/util/StringHelperTest.java
trunk/Hibernate3/test/org/hibernate/test/util/UtilSuite.java
Log:
HHH-2022 : property names with leading underscores
Modified: trunk/Hibernate3/test/org/hibernate/test/util/StringHelperTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/util/StringHelperTest.java 2006-08-23 13:19:43 UTC (rev 10313)
+++ trunk/Hibernate3/test/org/hibernate/test/util/StringHelperTest.java 2006-08-23 13:21:47 UTC (rev 10314)
@@ -1,6 +1,8 @@
package org.hibernate.test.util;
import junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
import org.hibernate.util.StringHelper;
/**
@@ -23,4 +25,8 @@
private void assertSimpleAlias(String source, String expected) {
assertEquals( expected, StringHelper.generateAlias( source ) );
}
+
+ public static Test suite() {
+ return new TestSuite( StringHelperTest.class );
+ }
}
Modified: trunk/Hibernate3/test/org/hibernate/test/util/UtilSuite.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/util/UtilSuite.java 2006-08-23 13:19:43 UTC (rev 10313)
+++ trunk/Hibernate3/test/org/hibernate/test/util/UtilSuite.java 2006-08-23 13:21:47 UTC (rev 10314)
@@ -14,6 +14,7 @@
TestSuite suite = new TestSuite( "Utility package tests" );
suite.addTest( PropertiesHelperTest.suite() );
suite.addTest( EntityResolverTest.suite() );
+ suite.addTest( StringHelperTest.suite() );
return suite;
}
}
17 years, 9 months
Hibernate SVN: r10313 - trunk/Hibernate3/test/org/hibernate/test/util
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-08-23 09:19:43 -0400 (Wed, 23 Aug 2006)
New Revision: 10313
Added:
trunk/Hibernate3/test/org/hibernate/test/util/StringHelperTest.java
Log:
HHH-2022 : property names with leading underscores
Added: trunk/Hibernate3/test/org/hibernate/test/util/StringHelperTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/util/StringHelperTest.java 2006-08-23 12:43:54 UTC (rev 10312)
+++ trunk/Hibernate3/test/org/hibernate/test/util/StringHelperTest.java 2006-08-23 13:19:43 UTC (rev 10313)
@@ -0,0 +1,26 @@
+package org.hibernate.test.util;
+
+import junit.framework.TestCase;
+import org.hibernate.util.StringHelper;
+
+/**
+ * todo: describe StringHelperTest
+ *
+ * @author Steve Ebersole
+ */
+public class StringHelperTest extends TestCase {
+ public StringHelperTest(String string) {
+ super( string );
+ }
+
+ public void testAliasGeneration() {
+ assertSimpleAlias( "xyz", "xyz_" );
+ assertSimpleAlias( "_xyz", "xyz_" );
+ assertSimpleAlias( "!xyz", "xyz_" );
+ assertSimpleAlias( "abcdefghijklmnopqrstuvwxyz", "abcdefghij_" );
+ }
+
+ private void assertSimpleAlias(String source, String expected) {
+ assertEquals( expected, StringHelper.generateAlias( source ) );
+ }
+}
17 years, 9 months
Hibernate SVN: r10312 - trunk/Hibernate3/src/org/hibernate
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-08-23 08:43:54 -0400 (Wed, 23 Aug 2006)
New Revision: 10312
Modified:
trunk/Hibernate3/src/org/hibernate/TransactionException.java
Log:
allow nested exception
Modified: trunk/Hibernate3/src/org/hibernate/TransactionException.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/TransactionException.java 2006-08-22 21:29:27 UTC (rev 10311)
+++ trunk/Hibernate3/src/org/hibernate/TransactionException.java 2006-08-23 12:43:54 UTC (rev 10312)
@@ -11,7 +11,7 @@
public class TransactionException extends HibernateException {
- public TransactionException(String message, Exception root) {
+ public TransactionException(String message, Throwable root) {
super(message,root);
}
@@ -20,9 +20,3 @@
}
}
-
-
-
-
-
-
17 years, 9 months
Hibernate SVN: r10311 - branches/Branch_3_2/Hibernate3/src/org/hibernate/engine
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-08-22 17:29:27 -0400 (Tue, 22 Aug 2006)
New Revision: 10311
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/Cascade.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/CascadingAction.java
Log:
cleanup
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/Cascade.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/Cascade.java 2006-08-22 21:28:18 UTC (rev 10310)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/Cascade.java 2006-08-22 21:29:27 UTC (rev 10311)
@@ -20,31 +20,14 @@
import org.hibernate.util.CollectionHelper;
/**
- * Implements cascaded save / delete / update / lock / evict / replicate / persist / merge
+ * Delegate responsible for, in conjunction with the various
+ * {@link CascadingAction actions}, implementing cascade processing.
*
- * @see org.hibernate.type.AssociationType
* @author Gavin King
+ * @see CascadingAction
*/
public final class Cascade {
-
- private int cascadeTo;
- private EventSource eventSource;
- private CascadingAction action;
- public Cascade(
- final CascadingAction action,
- final int cascadeTo,
- final EventSource eventSource
- ) {
- this.cascadeTo = cascadeTo;
- this.eventSource = eventSource;
- this.action = action;
- }
-
- private static final Log log = LogFactory.getLog(Cascade.class);
-
- // The available cascade actions:
-
/**
* A cascade point that occurs just after the insertion of the parent entity and
* just before deletion
@@ -88,29 +71,107 @@
*/
public static final int BEFORE_MERGE = 0;
- // The allowable cascade styles for a property:
+ private static final Log log = LogFactory.getLog( Cascade.class );
+
+
+ private int cascadeTo;
+ private EventSource eventSource;
+ private CascadingAction action;
+
+ public Cascade(final CascadingAction action, final int cascadeTo, final EventSource eventSource) {
+ this.cascadeTo = cascadeTo;
+ this.eventSource = eventSource;
+ this.action = action;
+ }
+
/**
+ * Cascade an action from the parent entity instance to all its children.
+ *
+ * @param persister The parent's entity persister
+ * @param parent The parent reference.
+ * @throws HibernateException
+ */
+ public void cascade(final EntityPersister persister, final Object parent)
+ throws HibernateException {
+ cascade( persister, parent, null );
+ }
+
+ /**
+ * Cascade an action from the parent entity instance to all its children. This
+ * form is typicaly called from within cascade actions.
+ *
+ * @param persister The parent's entity persister
+ * @param parent The parent reference.
+ * @param anything Anything ;) Typically some form of cascade-local cache
+ * which is specific to each CascadingAction type
+ * @throws HibernateException
+ */
+ public void cascade(final EntityPersister persister, final Object parent, final Object anything)
+ throws HibernateException {
+
+ if ( persister.hasCascades() || action.requiresNoCascadeChecking() ) { // performance opt
+ if ( log.isTraceEnabled() ) {
+ log.trace( "processing cascade " + action + " for: " + persister.getEntityName() );
+ }
+
+ Type[] types = persister.getPropertyTypes();
+ CascadeStyle[] cascadeStyles = persister.getPropertyCascadeStyles();
+ EntityMode entityMode = eventSource.getEntityMode();
+ boolean hasUninitializedLazyProperties = persister.hasUninitializedLazyProperties( parent, entityMode );
+ for ( int i=0; i<types.length; i++) {
+ CascadeStyle style = cascadeStyles[i];
+ if ( hasUninitializedLazyProperties && persister.getPropertyLaziness()[i] && ! action.performOnLazyProperty() ) {
+ //do nothing to avoid a lazy property initialization
+ continue;
+ }
+
+ if ( style.doCascade( action ) ) {
+ cascadeProperty(
+ persister.getPropertyValue( parent, i, entityMode ),
+ types[i],
+ style,
+ anything,
+ false
+ );
+ }
+ else if ( action.requiresNoCascadeChecking() ) {
+ action.noCascade(
+ eventSource,
+ persister.getPropertyValue( parent, i, entityMode ),
+ parent,
+ persister,
+ i
+ );
+ }
+ }
+
+ if ( log.isTraceEnabled() ) {
+ log.trace( "done processing cascade " + action + " for: " + persister.getEntityName() );
+ }
+ }
+ }
+
+ /**
* Cascade an action to the child or children
*/
private void cascadeProperty(
- final Object child,
- final Type type,
- final CascadeStyle style,
- final Object anything,
- final boolean isCascadeDeleteEnabled)
- throws HibernateException {
+ final Object child,
+ final Type type,
+ final CascadeStyle style,
+ final Object anything,
+ final boolean isCascadeDeleteEnabled) throws HibernateException {
if (child!=null) {
if ( type.isAssociationType() ) {
AssociationType associationType = (AssociationType) type;
if ( cascadeAssociationNow( associationType ) ) {
- cascadeAssociation(
- child,
- type,
- style,
- anything,
- isCascadeDeleteEnabled
+ cascadeAssociation(
+ child,
+ type,
+ style,
+ anything,
+ isCascadeDeleteEnabled
);
}
}
@@ -126,20 +187,19 @@
}
private void cascadeComponent(
- final Object child,
- final AbstractComponentType componentType,
- final Object anything
- ) {
+ final Object child,
+ final AbstractComponentType componentType,
+ final Object anything) {
Object[] children = componentType.getPropertyValues(child, eventSource);
Type[] types = componentType.getSubtypes();
for ( int i=0; i<types.length; i++ ) {
CascadeStyle componentPropertyStyle = componentType.getCascadeStyle(i);
if ( componentPropertyStyle.doCascade(action) ) {
- cascadeProperty(
- children[i],
- types[i],
- componentPropertyStyle,
- anything,
+ cascadeProperty(
+ children[i],
+ types[i],
+ componentPropertyStyle,
+ anything,
false
);
}
@@ -147,12 +207,11 @@
}
private void cascadeAssociation(
- final Object child,
- final Type type,
+ final Object child,
+ final Type type,
final CascadeStyle style,
- final Object anything,
- final boolean isCascadeDeleteEnabled
- ) {
+ final Object anything,
+ final boolean isCascadeDeleteEnabled) {
if ( type.isEntityType() || type.isAnyType() ) {
cascadeToOne( child, type, style, anything, isCascadeDeleteEnabled );
}
@@ -160,17 +219,15 @@
cascadeCollection( child, style, anything, (CollectionType) type );
}
}
-
+
/**
* Cascade an action to a collection
*/
private void cascadeCollection(
- final Object child,
- final CascadeStyle style,
- final Object anything,
- final CollectionType type
- ) {
-
+ final Object child,
+ final CascadeStyle style,
+ final Object anything,
+ final CollectionType type) {
CollectionPersister persister = eventSource.getFactory()
.getCollectionPersister( type.getRole() );
Type elemType = persister.getElementType();
@@ -179,161 +236,93 @@
if ( cascadeTo==AFTER_INSERT_BEFORE_DELETE) {
cascadeTo = AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION;
}
-
+
//cascade to current collection elements
if ( elemType.isEntityType() || elemType.isAnyType() || elemType.isComponentType() ) {
cascadeCollectionElements(
- child,
- type,
- style,
+ child,
+ type,
+ style,
elemType,
- anything,
- persister.isCascadeDeleteEnabled()
+ anything,
+ persister.isCascadeDeleteEnabled()
);
}
-
+
cascadeTo = oldCascadeTo;
}
-
+
/**
* Cascade an action to a to-one association or any type
*/
private void cascadeToOne(
- final Object child,
- final Type type,
- final CascadeStyle style,
- final Object anything,
- final boolean isCascadeDeleteEnabled
- ) {
-
- final String entityName = type.isEntityType() ?
- ( (EntityType) type ).getAssociatedEntityName() : null;
-
+ final Object child,
+ final Type type,
+ final CascadeStyle style,
+ final Object anything,
+ final boolean isCascadeDeleteEnabled) {
+ final String entityName = type.isEntityType()
+ ? ( (EntityType) type ).getAssociatedEntityName()
+ : null;
if ( style.reallyDoCascade(action) ) { //not really necessary, but good for consistency...
action.cascade(eventSource, child, entityName, anything, isCascadeDeleteEnabled);
}
-
}
/**
- * Cascade an action from the parent entity instance to all its children
- */
- public void cascade(final EntityPersister persister, final Object parent)
- throws HibernateException {
- cascade(persister, parent, null);
- }
-
- /**
- * Cascade an action from the parent entity instance to all its children
- */
- public void cascade(
- final EntityPersister persister,
- final Object parent,
- final Object anything)
- throws HibernateException {
-
- if ( persister.hasCascades() || action.requiresNoCascadeChecking() ) { // performance opt
- if ( log.isTraceEnabled() ) {
- log.trace( "processing cascade " + action + " for: " + persister.getEntityName() );
- }
-
- Type[] types = persister.getPropertyTypes();
- CascadeStyle[] cascadeStyles = persister.getPropertyCascadeStyles();
- for ( int i=0; i<types.length; i++) {
- CascadeStyle style = cascadeStyles[i];
- EntityMode entityMode = eventSource.getEntityMode();
- if ( persister.getPropertyLaziness()[i]
- && ! action.performOnLazyProperty()
- && persister.hasUninitializedLazyProperties( parent, entityMode )
- //currently there is no way to lazy a property an not the others
- ) {
- //do nothing to avoid a lazy property initialization
- }
- else if ( style.doCascade(action) ) {
- cascadeProperty(
- persister.getPropertyValue( parent, i, entityMode ),
- types[i],
- style,
- anything,
- false
- );
- }
- else {
-
- if ( action.requiresNoCascadeChecking() ) {
- action.noCascade(
- eventSource,
- persister.getPropertyValue( parent, i, entityMode ),
- parent,
- persister,
- i
- );
- }
- }
- }
-
- if ( log.isTraceEnabled() ) {
- log.trace( "done processing cascade " + action + " for: " + persister.getEntityName() );
- }
- }
- }
-
- /**
* Cascade to the collection elements
*/
private void cascadeCollectionElements(
- final Object child,
- final CollectionType collectionType,
- final CascadeStyle style,
- final Type elemType,
- final Object anything,
- final boolean isCascadeDeleteEnabled)
- throws HibernateException {
-
+ final Object child,
+ final CollectionType collectionType,
+ final CascadeStyle style,
+ final Type elemType,
+ final Object anything,
+ final boolean isCascadeDeleteEnabled) throws HibernateException {
// we can't cascade to non-embedded elements
boolean embeddedElements = eventSource.getEntityMode()!=EntityMode.DOM4J ||
( (EntityType) collectionType.getElementType( eventSource.getFactory() ) ).isEmbeddedInXML();
-
- boolean reallyDoCascade = style.reallyDoCascade(action) &&
+
+ boolean reallyDoCascade = style.reallyDoCascade(action) &&
embeddedElements && child!=CollectionType.UNFETCHED_COLLECTION;
-
+
if ( reallyDoCascade ) {
if ( log.isTraceEnabled() ) {
log.trace( "cascade " + action + " for collection: " + collectionType.getRole() );
}
-
+
Iterator iter = action.getCascadableChildrenIterator(eventSource, collectionType, child);
while ( iter.hasNext() ) {
cascadeProperty(
- iter.next(),
+ iter.next(),
elemType,
- style,
- anything,
- isCascadeDeleteEnabled
+ style,
+ anything,
+ isCascadeDeleteEnabled
);
}
-
+
if ( log.isTraceEnabled() ) {
log.trace( "done cascade " + action + " for collection: " + collectionType.getRole() );
}
}
-
- final boolean deleteOrphans = style.hasOrphanDelete() &&
- action.deleteOrphans() &&
- elemType.isEntityType() &&
+
+ final boolean deleteOrphans = style.hasOrphanDelete() &&
+ action.deleteOrphans() &&
+ elemType.isEntityType() &&
child instanceof PersistentCollection; //a newly instantiated collection can't have orphans
-
+
if ( deleteOrphans ) { // handle orphaned entities!!
if ( log.isTraceEnabled() ) {
log.trace( "deleting orphans for collection: " + collectionType.getRole() );
}
-
+
// we can do the cast since orphan-delete does not apply to:
// 1. newly instantiated collections
// 2. arrays (we can't track orphans for detached arrays)
final String entityName = collectionType.getAssociatedEntityName( eventSource.getFactory() );
deleteOrphans( entityName, (PersistentCollection) child );
-
+
if ( log.isTraceEnabled() ) {
log.trace( "done deleting orphans for collection: " + collectionType.getRole() );
}
@@ -343,21 +332,19 @@
/**
* Delete any entities that were removed from the collection
*/
- private void deleteOrphans(String entityName, PersistentCollection pc)
- throws HibernateException {
-
- final Collection orphans;
+ private void deleteOrphans(String entityName, PersistentCollection pc) throws HibernateException {
//TODO: suck this logic into the collection!
+ final Collection orphans;
if ( pc.wasInitialized() ) {
CollectionEntry ce = eventSource.getPersistenceContext().getCollectionEntry(pc);
- orphans = ce==null ?
+ orphans = ce==null ?
CollectionHelper.EMPTY_COLLECTION :
ce.getOrphans(entityName, pc);
}
else {
orphans = pc.getQueuedOrphans(entityName);
}
-
+
final Iterator orphanIter = orphans.iterator();
while ( orphanIter.hasNext() ) {
Object orphan = orphanIter.next();
@@ -368,7 +355,6 @@
eventSource.delete( entityName, orphan, false, null );
}
}
-
}
}
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/CascadingAction.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/CascadingAction.java 2006-08-22 21:28:18 UTC (rev 10310)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/CascadingAction.java 2006-08-22 21:29:27 UTC (rev 10311)
@@ -20,28 +20,95 @@
/**
* A session action that may be cascaded from parent entity to its children
- *
+ *
* @author Gavin King
*/
public abstract class CascadingAction {
- private static final Log log = LogFactory.getLog(CascadingAction.class);
+ private static final Log log = LogFactory.getLog( CascadingAction.class );
+
+ // the CascadingAction contract ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
/**
- * cascade the action to the child object
+ * protected constructor
*/
- public abstract void cascade(EventSource session, Object child, String entityName, Object anything, boolean isCascadeDeleteEnabled)
- throws HibernateException;
+ CascadingAction() {
+ }
+
/**
- * Should this action be cascaded to the given (possibly uninitialized) collection?
+ * Cascade the action to the child object.
+ *
+ * @param session The session within which the cascade is occuring.
+ * @param child The child to which cascading should be performed.
+ * @param entityName The child's entity name
+ * @param anything Anything ;) Typically some form of cascade-local cache
+ * which is specific to each CascadingAction type
+ * @param isCascadeDeleteEnabled Are cascading deletes enabled.
+ * @throws HibernateException
*/
- public abstract Iterator getCascadableChildrenIterator(EventSource session, CollectionType collectionType, Object collection);
+ public abstract void cascade(
+ EventSource session,
+ Object child,
+ String entityName,
+ Object anything,
+ boolean isCascadeDeleteEnabled) throws HibernateException;
+
/**
- * Do we need to handle orphan delete for this action?
+ * Given a collection, get an iterator of the children upon which the
+ * current cascading action should be visited.
+ *
+ * @param session The session within which the cascade is occuring.
+ * @param collectionType The mapping type of the collection.
+ * @param collection The collection instance.
+ * @return The children iterator.
*/
+ public abstract Iterator getCascadableChildrenIterator(
+ EventSource session,
+ CollectionType collectionType,
+ Object collection);
+
+ /**
+ * Does this action potentially extrapolate to orphan deletes?
+ *
+ * @return True if this action can lead to deletions of orphans.
+ */
public abstract boolean deleteOrphans();
+
/**
+ * Does the specified cascading action require verification of no cascade validity?
+ *
+ * @return True if this action requires no-cascade verification; false otherwise.
+ */
+ public boolean requiresNoCascadeChecking() {
+ return false;
+ }
+
+ /**
+ * Called (in the case of {@link #requiresNoCascadeChecking} returning true) to validate
+ * that no cascade on the given property is considered a valid semantic.
+ *
+ * @param session The session witin which the cascade is occurring.
+ * @param child The property value
+ * @param parent The property value owner
+ * @param persister The entity persister for the owner
+ * @param propertyIndex The index of the property within the owner.
+ */
+ public void noCascade(EventSource session, Object child, Object parent, EntityPersister persister, int propertyIndex) {
+ }
+
+ /**
+ * Should this action be performed (or noCascade consulted) in the case of lazy properties.
+ */
+ public boolean performOnLazyProperty() {
+ return true;
+ }
+
+
+ // the CascadingAction implementations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ /**
* @see org.hibernate.Session#delete(Object)
*/
public static final CascadingAction DELETE = new CascadingAction() {
@@ -326,22 +393,25 @@
}
};
- CascadingAction() {}
- public boolean requiresNoCascadeChecking() {
- return false;
- }
+ // static helper methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- public void noCascade(EventSource session, Object child, Object parent, EntityPersister persister, int propertyIndex) {
- }
-
/**
- * Iterate all the collection elements, loading them from the database if necessary.
+ * Given a collection, get an iterator of all its children, loading them
+ * from the database if necessary.
+ *
+ * @param session The session within which the cascade is occuring.
+ * @param collectionType The mapping type of the collection.
+ * @param collection The collection instance.
+ * @return The children iterator.
*/
- private static Iterator getAllElementsIterator(EventSource session, CollectionType collectionType, Object collection) {
- return collectionType.getElementsIterator(collection, session);
+ private static Iterator getAllElementsIterator(
+ EventSource session,
+ CollectionType collectionType,
+ Object collection) {
+ return collectionType.getElementsIterator( collection, session );
}
+
/**
* Iterate just the elements of the collection that are already there. Don't load
* any new elements from the database.
@@ -362,7 +432,4 @@
return !(collection instanceof PersistentCollection) || ( (PersistentCollection) collection ).wasInitialized();
}
- public boolean performOnLazyProperty() {
- return true;
- }
}
\ No newline at end of file
17 years, 9 months