Hibernate SVN: r16099 - in core/branches/Branch_3_3: documentation/manual/src/main/docbook/en-US/content and 11 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-03-06 13:35:50 -0500 (Fri, 06 Mar 2009)
New Revision: 16099
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/sql/OracleJoinFragment.java
core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml
core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/configuration.xml
core/branches/Branch_3_3/etc/hibernate.properties
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/cut/CompositeUserTypeTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/dialect/functional/cache/SQLFunctionsInterSystemsTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/ComponentOwner.hbm.xml
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/GeneratedPropertyEntity.hbm.xml
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/PartiallyGeneratedComponentTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/TriggerGeneratedValuesWithCachingTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/TriggerGeneratedValuesWithoutCachingTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generatedkeys/select/MyEntity.hbm.xml
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generatedkeys/select/SelectGeneratorTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generatedkeys/seqidentity/SequenceIdentityTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/IJTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/SQLLoaderTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/rowid/RowIdTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/check/OracleCheckStyleTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/custom/oracle/OracleCustomSQLTest.java
Log:
HHH-3214 - Update unit tests and config files to use non-depracated Oracle dialects
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/sql/OracleJoinFragment.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/sql/OracleJoinFragment.java 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/sql/OracleJoinFragment.java 2009-03-06 18:35:50 UTC (rev 16099)
@@ -114,7 +114,7 @@
addLeftOuterJoinCondition( on );
}
else {
- throw new UnsupportedOperationException( "join type not supported by OracleJoinFragment (use Oracle9Dialect)" );
+ throw new UnsupportedOperationException( "join type not supported by OracleJoinFragment (use Oracle9iDialect/Oracle10gDialect)" );
}
}
Modified: core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml
===================================================================
--- core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml 2009-03-06 18:35:50 UTC (rev 16099)
@@ -3585,8 +3585,8 @@
...
<database-object>
<definition class="MyTriggerDefinition"/>
- <dialect-scope name="org.hibernate.dialect.Oracle9Dialect"/>
- <dialect-scope name="org.hibernate.dialect.OracleDialect"/>
+ <dialect-scope name="org.hibernate.dialect.Oracle9iDialect"/>
+ <dialect-scope name="org.hibernate.dialect.Oracle10gDialect"/>
</database-object>
</hibernate-mapping>]]></programlisting>
</sect1>
Modified: core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/configuration.xml
===================================================================
--- core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/configuration.xml 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/configuration.xml 2009-03-06 18:35:50 UTC (rev 16099)
@@ -1050,7 +1050,7 @@
other properties listed above. This means that you will not have to specify them manually.
</para>
- <table frame="topbot" id="sql-dialects" revision="2">
+ <table frame="topbot" id="sql-dialects" revision="3">
<title>Hibernate SQL Dialects (<literal>hibernate.dialect</literal>)</title>
<tgroup cols="2">
<!--
@@ -1089,9 +1089,12 @@
<entry>Oracle (any version)</entry> <entry><literal>org.hibernate.dialect.OracleDialect</literal></entry>
</row>
<row>
- <entry>Oracle 9i/10g</entry> <entry><literal>org.hibernate.dialect.Oracle9Dialect</literal></entry>
+ <entry>Oracle 9i</entry> <entry><literal>org.hibernate.dialect.Oracle9iDialect</literal></entry>
</row>
<row>
+ <entry>Oracle 10g</entry> <entry><literal>org.hibernate.dialect.Oracle10gDialect</literal></entry>
+ </row>
+ <row>
<entry>Sybase</entry> <entry><literal>org.hibernate.dialect.SybaseDialect</literal></entry>
</row>
<row>
Modified: core/branches/Branch_3_3/etc/hibernate.properties
===================================================================
--- core/branches/Branch_3_3/etc/hibernate.properties 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/etc/hibernate.properties 2009-03-06 18:35:50 UTC (rev 16099)
@@ -59,8 +59,9 @@
## Oracle
-#hibernate.dialect org.hibernate.dialect.OracleDialect
-#hibernate.dialect org.hibernate.dialect.Oracle9Dialect
+#hibernate.dialect org.hibernate.dialect.Oracle8iDialect
+#hibernate.dialect org.hibernate.dialect.Oracle9iDialect
+#hibernate.dialect org.hibernate.dialect.Oracle10gDialect
#hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver
#hibernate.connection.username ora
#hibernate.connection.password ora
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/cut/CompositeUserTypeTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/cut/CompositeUserTypeTest.java 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/cut/CompositeUserTypeTest.java 2009-03-06 18:35:50 UTC (rev 16099)
@@ -9,7 +9,6 @@
import org.hibernate.Session;
import org.hibernate.dialect.HSQLDialect;
-import org.hibernate.dialect.Oracle9Dialect;
import org.hibernate.junit.functional.FunctionalTestCase;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
@@ -45,7 +44,7 @@
result = s.createQuery("from Transaction tran where tran.value.amount > 1.0 and tran.value.currency = 'AUD'").list();
assertEquals( result.size(), 1 );
- if ( !(getDialect() instanceof HSQLDialect) && ! (getDialect() instanceof Oracle9Dialect) ) {
+ if ( !(getDialect() instanceof HSQLDialect) ) {
result = s.createQuery("from Transaction txn where txn.value = (1.5, 'AUD')").list();
assertEquals( result.size(), 1 );
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/dialect/functional/cache/SQLFunctionsInterSystemsTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/dialect/functional/cache/SQLFunctionsInterSystemsTest.java 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/dialect/functional/cache/SQLFunctionsInterSystemsTest.java 2009-03-06 18:35:50 UTC (rev 16099)
@@ -26,7 +26,6 @@
import org.hibernate.dialect.InterbaseDialect;
import org.hibernate.dialect.MckoiDialect;
import org.hibernate.dialect.MySQLDialect;
-import org.hibernate.dialect.Oracle9Dialect;
import org.hibernate.dialect.SybaseDialect;
import org.hibernate.dialect.TimesTenDialect;
import org.hibernate.dialect.function.SQLFunction;
@@ -176,7 +175,6 @@
}
public void testBroken() throws Exception {
- if (getDialect() instanceof Oracle9Dialect) return;
Session s = openSession();
Transaction t = s.beginTransaction();
Broken b = new Fixed();
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/ComponentOwner.hbm.xml
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/ComponentOwner.hbm.xml 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/ComponentOwner.hbm.xml 2009-03-06 18:35:50 UTC (rev 16099)
@@ -31,8 +31,8 @@
<drop>
<![CDATA[DROP TRIGGER t_iu_part_gen_comp]]>
</drop>
- <dialect-scope name="org.hibernate.dialect.Oracle9Dialect"/>
- <dialect-scope name="org.hibernate.dialect.OracleDialect"/>
+ <dialect-scope name="org.hibernate.dialect.Oracle9iDialect"/>
+ <dialect-scope name="org.hibernate.dialect.Oracle10gDialect"/>
</database-object>
</hibernate-mapping>
\ No newline at end of file
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/GeneratedPropertyEntity.hbm.xml
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/GeneratedPropertyEntity.hbm.xml 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/GeneratedPropertyEntity.hbm.xml 2009-03-06 18:35:50 UTC (rev 16099)
@@ -35,8 +35,8 @@
<drop>
<![CDATA[DROP TRIGGER t_iu_gen_prop]]>
</drop>
- <dialect-scope name="org.hibernate.dialect.Oracle9Dialect"/>
- <dialect-scope name="org.hibernate.dialect.OracleDialect"/>
+ <dialect-scope name="org.hibernate.dialect.Oracle9iDialect"/>
+ <dialect-scope name="org.hibernate.dialect.Oracle10gDialect"/>
</database-object>
</hibernate-mapping>
\ No newline at end of file
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/PartiallyGeneratedComponentTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/PartiallyGeneratedComponentTest.java 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/PartiallyGeneratedComponentTest.java 2009-03-06 18:35:50 UTC (rev 16099)
@@ -5,7 +5,7 @@
import org.hibernate.junit.functional.DatabaseSpecificFunctionalTestCase;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.Oracle9Dialect;
+import org.hibernate.dialect.Oracle9iDialect;
import org.hibernate.Session;
/**
@@ -27,7 +27,7 @@
}
public boolean appliesTo(Dialect dialect) {
- return dialect instanceof Oracle9Dialect;
+ return dialect instanceof Oracle9iDialect;
}
public void testPartialComponentGeneration() {
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/TriggerGeneratedValuesWithCachingTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/TriggerGeneratedValuesWithCachingTest.java 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/TriggerGeneratedValuesWithCachingTest.java 2009-03-06 18:35:50 UTC (rev 16099)
@@ -1,12 +1,11 @@
// $Id: TriggerGeneratedValuesWithCachingTest.java 10977 2006-12-12 23:28:04Z steve.ebersole(a)jboss.com $
package org.hibernate.test.generated;
-import org.hibernate.dialect.Oracle9Dialect;
+import org.hibernate.dialect.Oracle9iDialect;
import org.hibernate.dialect.Dialect;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
import junit.framework.Test;
-import junit.framework.TestSuite;
/**
* Implementation of TriggerGeneratedValuesWithoutCachingTest.
@@ -26,7 +25,7 @@
public boolean appliesTo(Dialect dialect) {
// currently have only defined triggers for oracle...
// TODO : add more triggers for dialects which allow mods in triggers...
- return ( dialect instanceof Oracle9Dialect );
+ return ( dialect instanceof Oracle9iDialect );
}
public static Test suite() {
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/TriggerGeneratedValuesWithoutCachingTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/TriggerGeneratedValuesWithoutCachingTest.java 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generated/TriggerGeneratedValuesWithoutCachingTest.java 2009-03-06 18:35:50 UTC (rev 16099)
@@ -4,7 +4,7 @@
import junit.framework.Test;
import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.Oracle9Dialect;
+import org.hibernate.dialect.Oracle9iDialect;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
/**
@@ -25,7 +25,7 @@
public boolean appliesTo(Dialect dialect) {
// currently have only defined triggers for oracle...
// TODO : add more triggers for dialects which allow mods in triggers...
- return ( dialect instanceof Oracle9Dialect );
+ return ( dialect instanceof Oracle9iDialect );
}
public String getCacheConcurrencyStrategy() {
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generatedkeys/select/MyEntity.hbm.xml
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generatedkeys/select/MyEntity.hbm.xml 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generatedkeys/select/MyEntity.hbm.xml 2009-03-06 18:35:50 UTC (rev 16099)
@@ -29,8 +29,8 @@
<drop>
<![CDATA[DROP TRIGGER t_i_my_entity]]>
</drop>
- <dialect-scope name="org.hibernate.dialect.Oracle9Dialect"/>
- <dialect-scope name="org.hibernate.dialect.OracleDialect"/>
+ <dialect-scope name="org.hibernate.dialect.Oracle9iDialect"/>
+ <dialect-scope name="org.hibernate.dialect.Oracle10gDialect"/>
</database-object>
</hibernate-mapping>
\ No newline at end of file
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generatedkeys/select/SelectGeneratorTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generatedkeys/select/SelectGeneratorTest.java 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generatedkeys/select/SelectGeneratorTest.java 2009-03-06 18:35:50 UTC (rev 16099)
@@ -3,9 +3,8 @@
import junit.framework.Test;
import org.hibernate.Session;
-import org.hibernate.dialect.DataDirectOracle9Dialect;
import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.Oracle9Dialect;
+import org.hibernate.dialect.Oracle9iDialect;
import org.hibernate.junit.functional.DatabaseSpecificFunctionalTestCase;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
@@ -24,7 +23,7 @@
}
public boolean appliesTo(Dialect dialect) {
- return ( dialect instanceof Oracle9Dialect );
+ return ( dialect instanceof Oracle9iDialect );
}
public static Test suite() {
@@ -32,10 +31,6 @@
}
public void testJDBC3GetGeneratedKeysSupportOnOracle() {
- if ( getDialect() instanceof DataDirectOracle9Dialect ) {
- reportSkip( "DataDirect drivers known to not support JDBC3 getGeneratedKeys for Oracle", "oracle getGeneratedKeys support" );
- return;
- }
Session session = openSession();
session.beginTransaction();
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generatedkeys/seqidentity/SequenceIdentityTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generatedkeys/seqidentity/SequenceIdentityTest.java 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/generatedkeys/seqidentity/SequenceIdentityTest.java 2009-03-06 18:35:50 UTC (rev 16099)
@@ -4,9 +4,8 @@
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
-import org.hibernate.dialect.DataDirectOracle9Dialect;
import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.Oracle9Dialect;
+import org.hibernate.dialect.Oracle9iDialect;
import org.hibernate.junit.functional.DatabaseSpecificFunctionalTestCase;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
@@ -25,7 +24,7 @@
public boolean appliesTo(Dialect dialect) {
// the DataDirect driver for Oracle known to not support
// JDBC3 getGeneratedKeys...
- return ( dialect instanceof Oracle9Dialect ) && ( ! ( dialect instanceof DataDirectOracle9Dialect ) ) ;
+ return ( dialect instanceof Oracle9iDialect );
}
public String[] getMappings() {
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2009-03-06 18:35:50 UTC (rev 16099)
@@ -13,6 +13,8 @@
import java.util.Map;
import junit.framework.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
@@ -27,14 +29,14 @@
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.MySQLDialect;
-import org.hibernate.dialect.Oracle9Dialect;
+import org.hibernate.dialect.Oracle8iDialect;
+
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.dialect.SQLServerDialect;
-import org.hibernate.dialect.SybaseDialect;
import org.hibernate.dialect.Sybase11Dialect;
import org.hibernate.dialect.SybaseASE15Dialect;
import org.hibernate.dialect.SybaseAnywhereDialect;
-import org.hibernate.dialect.Oracle8iDialect;
+import org.hibernate.dialect.SybaseDialect;
import org.hibernate.hql.ast.ASTQueryTranslatorFactory;
import org.hibernate.junit.functional.FunctionalTestCase;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
@@ -54,9 +56,6 @@
import org.hibernate.type.Type;
import org.hibernate.util.StringHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
* Tests the integration of the new AST parser into the loading of query results using
* the Hibernate persisters and loaders.
@@ -1242,7 +1241,7 @@
String dateStr1 = (String) session.createQuery("select str(current_date) from Animal").uniqueResult();
String dateStr2 = (String) session.createQuery("select str(year(current_date))||'-'||str(month(current_date))||'-'||str(day(current_date)) from Animal").uniqueResult();
System.out.println(dateStr1 + '=' + dateStr2);
- if ( ! ( getDialect() instanceof Oracle9Dialect || getDialect() instanceof Oracle8iDialect ) ) { //Oracle renders the name of the month :(
+ if ( ! ( getDialect() instanceof Oracle8iDialect ) ) { //Oracle renders the name of the month :(
String[] dp1 = StringHelper.split("-", dateStr1);
String[] dp2 = StringHelper.split("-", dateStr2);
for (int i=0; i<3; i++) {
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java 2009-03-06 18:35:50 UTC (rev 16099)
@@ -14,18 +14,16 @@
import org.hibernate.Hibernate;
import org.hibernate.QueryException;
-import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.MySQLDialect;
-import org.hibernate.dialect.Oracle9Dialect;
+import org.hibernate.dialect.Oracle8iDialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.dialect.SQLServerDialect;
-import org.hibernate.dialect.SybaseAnywhereDialect;
-import org.hibernate.dialect.SybaseDialect;
import org.hibernate.dialect.Sybase11Dialect;
import org.hibernate.dialect.SybaseASE15Dialect;
-import org.hibernate.dialect.Oracle8iDialect;
+import org.hibernate.dialect.SybaseAnywhereDialect;
+import org.hibernate.dialect.SybaseDialect;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.query.HQLQueryPlan;
@@ -38,9 +36,10 @@
import org.hibernate.hql.ast.QueryTranslatorImpl;
import org.hibernate.hql.ast.tree.ConstructorNode;
import org.hibernate.hql.ast.tree.DotNode;
+import org.hibernate.hql.ast.tree.FromReferenceNode;
import org.hibernate.hql.ast.tree.IndexNode;
import org.hibernate.hql.ast.tree.SelectClause;
-import org.hibernate.hql.ast.tree.FromReferenceNode;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
/**
* Tests cases where the AST based query translator and the 'classic' query translator generate identical SQL.
@@ -677,7 +676,6 @@
}
public void testGroupByFunction() {
- if ( getDialect() instanceof Oracle9Dialect ) return;
if ( getDialect() instanceof Oracle8iDialect ) return; // the new hiearchy...
if ( getDialect() instanceof PostgreSQLDialect ) return;
assertTranslation( "select count(*) from Human h group by year(h.birthdate)" );
@@ -856,7 +854,6 @@
public void testClassProperty() throws Exception {
// This test causes failures on theta-join dialects because the SQL is different.
// The queries are semantically the same however.
- if ( getDialect() instanceof Oracle9Dialect ) return;
if ( getDialect() instanceof Oracle8iDialect ) return;
assertTranslation( "from Animal a where a.mother.class = Reptile" );
}
@@ -1132,7 +1129,6 @@
// This test causes failures on theta-join dialects because the SQL is different. The old parser
// duplicates the condition, whereas the new parser does not. The queries are semantically the
// same however.
- if ( getDialect() instanceof Oracle9Dialect ) return;
if ( getDialect() instanceof Oracle8iDialect ) return;
assertTranslation( "select an.mother.bodyWeight from Animal an join an.mother m where an.mother.bodyWeight > 10" );
assertTranslation( "select an.mother.bodyWeight from Animal an where an.mother.bodyWeight > 10" );
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java 2009-03-06 18:35:50 UTC (rev 16099)
@@ -51,19 +51,18 @@
import org.hibernate.dialect.MckoiDialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.Oracle8iDialect;
-import org.hibernate.dialect.Oracle9Dialect;
-import org.hibernate.dialect.OracleDialect;
+//import org.hibernate.dialect.Oracle9Dialect;
+//import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.PointbaseDialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.dialect.SAPDBDialect;
-import org.hibernate.dialect.SQLServerDialect;
-import org.hibernate.dialect.SybaseDialect;
import org.hibernate.dialect.Sybase11Dialect;
import org.hibernate.dialect.SybaseASE15Dialect;
+import org.hibernate.dialect.SybaseDialect;
import org.hibernate.dialect.TimesTenDialect;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
-import org.hibernate.mapping.RootClass;
+//import org.hibernate.mapping.RootClass;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.type.Type;
import org.hibernate.util.JoinedIterator;
@@ -99,13 +98,6 @@
};
}
- public void configure(Configuration cfg) {
- super.configure( cfg );
- if ( Dialect.getDialect() instanceof OracleDialect ) {
- ( (RootClass) cfg.getClassMapping("org.hibernate.test.legacy.Foo") ).setForceDiscriminator(false);
- }
- }
-
public static Test suite() {
return new FunctionalTestClassTestSuite( FooBarTest.class );
}
@@ -682,7 +674,7 @@
s.find("from Foo foo where foo.integer not between 1 and 5 and foo.string not in ('cde', 'abc') and foo.string is not null and foo.integer<=3");
s.find("from Baz baz inner join baz.collectionComponent.nested.foos foo where foo.string is null");
- if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof MckoiDialect) && !(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof PointbaseDialect) /*&& !(dialect instanceof Oracle9Dialect)*/ ) {
+ if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof MckoiDialect) && !(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof PointbaseDialect) ) {
s.find("from Baz baz inner join baz.fooSet where '1' in (from baz.fooSet foo where foo.string is not null)");
s.find("from Baz baz where 'a' in elements(baz.collectionComponent.nested.foos) and 1.0 in elements(baz.collectionComponent.nested.floats)");
s.find("from Baz baz where 'b' in elements(baz.collectionComponent.nested.foos) and 1.0 in elements(baz.collectionComponent.nested.floats)");
@@ -2138,7 +2130,7 @@
s.find("select count(*) from Baz as baz where 1 in indices(baz.fooArray)");
s.find("select count(*) from Bar as bar where 'abc' in elements(bar.baz.fooArray)");
s.find("select count(*) from Bar as bar where 1 in indices(bar.baz.fooArray)");
- if ( !(getDialect() instanceof DB2Dialect) && !(getDialect() instanceof Oracle9Dialect) && !(getDialect() instanceof Oracle8iDialect ) && !( getDialect() instanceof SybaseDialect ) && !( getDialect() instanceof Sybase11Dialect ) && !( getDialect() instanceof SybaseASE15Dialect )) {
+ if ( !(getDialect() instanceof DB2Dialect) && !(getDialect() instanceof Oracle8iDialect ) && !( getDialect() instanceof SybaseDialect ) && !( getDialect() instanceof Sybase11Dialect ) && !( getDialect() instanceof SybaseASE15Dialect )) {
// SybaseAnywhereDialect supports implicit conversions from strings to ints
s.find("select count(*) from Bar as bar, bar.component.glarch.proxyArray as g where g.id in indices(bar.baz.fooArray)");
s.find("select max( elements(bar.baz.fooArray) ) from Bar as bar, bar.component.glarch.proxyArray as g where g.id in indices(bar.baz.fooArray)");
@@ -3304,73 +3296,81 @@
}
public void testScrollableIterator() throws Exception {
- if ( getDialect() instanceof DB2Dialect || getDialect() instanceof OracleDialect || getDialect() instanceof SybaseDialect || getDialect() instanceof HSQLDialect ) {
- Session s = openSession();
- Transaction txn = s.beginTransaction();
- s.save( new Foo() );
- s.save( new Foo() );
- s.save( new Foo() );
- s.save( new Bar() );
- Query query = s.createQuery("select f, f.integer from Foo f");
- assertTrue( query.getReturnTypes().length==2 );
- ScrollableResults iter = query.scroll();
- assertTrue( iter.next() );
- assertTrue( iter.scroll(1) );
- FooProxy f2 = (FooProxy) iter.get()[0];
- assertTrue( f2!=null );
- assertTrue( iter.scroll(-1) );
- Object f1 = iter.get(0);
- iter.next();
- assertTrue( f1!=null && iter.get(0)==f2 );
- iter.getInteger(1);
+ // skip if not one of these named dialects
+ boolean match = getDialect() instanceof DB2Dialect
+ || getDialect() instanceof SybaseDialect
+ || getDialect() instanceof HSQLDialect
+ || getDialect() instanceof Oracle8iDialect // 9i/10g too because of inheritence...
+ ;
+ if ( ! match ) {
+ return;
+ }
- assertTrue( !iter.scroll(100) );
- assertTrue( iter.first() );
- assertTrue( iter.scroll(3) );
- Object f4 = iter.get(0);
- assertTrue( f4!=null );
- assertTrue( !iter.next() );
- assertTrue( iter.first() );
- assertTrue( iter.get(0)==f1 );
- assertTrue( iter.last() );
- assertTrue( iter.get(0)==f4 );
- assertTrue( iter.previous() );
- txn.commit();
- s.close();
+ Session s = openSession();
+ Transaction txn = s.beginTransaction();
+ s.save( new Foo() );
+ s.save( new Foo() );
+ s.save( new Foo() );
+ s.save( new Bar() );
+ Query query = s.createQuery("select f, f.integer from Foo f");
+ assertTrue( query.getReturnTypes().length==2 );
+ ScrollableResults iter = query.scroll();
+ assertTrue( iter.next() );
+ assertTrue( iter.scroll(1) );
+ FooProxy f2 = (FooProxy) iter.get()[0];
+ assertTrue( f2!=null );
+ assertTrue( iter.scroll(-1) );
+ Object f1 = iter.get(0);
+ iter.next();
+ assertTrue( f1!=null && iter.get(0)==f2 );
+ iter.getInteger(1);
- s = openSession();
- txn = s.beginTransaction();
- query = s.createQuery("select f, f.integer from Foo f");
- assertTrue( query.getReturnTypes().length==2 );
- iter = query.scroll();
- assertTrue( iter.next() );
- assertTrue( iter.scroll(1) );
- f2 = (FooProxy) iter.get()[0];
- assertTrue( f2!=null );
- assertTrue( f2.getString()!=null && f2.getComponent().getImportantDates().length > 0 );
- assertTrue( iter.scroll(-1) );
- f1 = iter.get(0);
- iter.next();
- assertTrue( f1!=null && iter.get(0)==f2 );
- iter.getInteger(1);
+ assertTrue( !iter.scroll(100) );
+ assertTrue( iter.first() );
+ assertTrue( iter.scroll(3) );
+ Object f4 = iter.get(0);
+ assertTrue( f4!=null );
+ assertTrue( !iter.next() );
+ assertTrue( iter.first() );
+ assertTrue( iter.get(0)==f1 );
+ assertTrue( iter.last() );
+ assertTrue( iter.get(0)==f4 );
+ assertTrue( iter.previous() );
+ txn.commit();
+ s.close();
- assertTrue( !iter.scroll(100) );
- assertTrue( iter.first() );
- assertTrue( iter.scroll(3) );
- f4 = iter.get(0);
- assertTrue( f4!=null );
- assertTrue( !iter.next() );
- assertTrue( iter.first() );
- assertTrue( iter.get(0)==f1 );
- assertTrue( iter.last() );
- assertTrue( iter.get(0)==f4 );
- assertTrue( iter.previous() );
- assertTrue( s.delete("from Foo")==4 );
- s.flush();
- assertTrue( s.find("from java.lang.Object").size()==0 );
- txn.commit();
- s.close();
- }
+ s = openSession();
+ txn = s.beginTransaction();
+ query = s.createQuery("select f, f.integer from Foo f");
+ assertTrue( query.getReturnTypes().length==2 );
+ iter = query.scroll();
+ assertTrue( iter.next() );
+ assertTrue( iter.scroll(1) );
+ f2 = (FooProxy) iter.get()[0];
+ assertTrue( f2!=null );
+ assertTrue( f2.getString()!=null && f2.getComponent().getImportantDates().length > 0 );
+ assertTrue( iter.scroll(-1) );
+ f1 = iter.get(0);
+ iter.next();
+ assertTrue( f1!=null && iter.get(0)==f2 );
+ iter.getInteger(1);
+
+ assertTrue( !iter.scroll(100) );
+ assertTrue( iter.first() );
+ assertTrue( iter.scroll(3) );
+ f4 = iter.get(0);
+ assertTrue( f4!=null );
+ assertTrue( !iter.next() );
+ assertTrue( iter.first() );
+ assertTrue( iter.get(0)==f1 );
+ assertTrue( iter.last() );
+ assertTrue( iter.get(0)==f4 );
+ assertTrue( iter.previous() );
+ assertTrue( s.delete("from Foo")==4 );
+ s.flush();
+ assertTrue( s.find("from java.lang.Object").size()==0 );
+ txn.commit();
+ s.close();
}
public void testMultiColumnQueries() throws Exception {
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/IJTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/IJTest.java 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/IJTest.java 2009-03-06 18:35:50 UTC (rev 16099)
@@ -8,7 +8,6 @@
import org.hibernate.LockMode;
import org.hibernate.classic.Session;
import org.hibernate.dialect.HSQLDialect;
-import org.hibernate.dialect.OracleDialect;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
/**
@@ -29,7 +28,7 @@
}
public void testFormulaDiscriminator() throws Exception {
- if ( ( getDialect() instanceof OracleDialect ) || ( getDialect() instanceof HSQLDialect ) ) return;
+ if ( getDialect() instanceof HSQLDialect ) return;
Session s = getSessions().openSession();
I i = new I();
i.setName( "i" );
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java 2009-03-06 18:35:50 UTC (rev 16099)
@@ -22,7 +22,6 @@
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.MckoiDialect;
import org.hibernate.dialect.MySQLDialect;
-import org.hibernate.dialect.Oracle9Dialect;
import org.hibernate.dialect.SAPDBDialect;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.mapping.MetaAttribute;
@@ -316,7 +315,7 @@
assertTrue( "generated id returned", s.save(d2)!=null);
master.addDetail(d1);
master.addDetail(d2);
- if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof Oracle9Dialect) && !(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof MckoiDialect) && !(getDialect() instanceof org.hibernate.dialect.TimesTenDialect)) {
+ if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof MckoiDialect) && !(getDialect() instanceof org.hibernate.dialect.TimesTenDialect)) {
assertTrue(
"query",
s.find("from Detail d, Master m where m = d.master and size(m.outgoing) = 0 and size(m.incoming) = 0").size()==2
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java 2009-03-06 18:35:50 UTC (rev 16099)
@@ -23,14 +23,13 @@
import org.hibernate.dialect.InterbaseDialect;
import org.hibernate.dialect.MckoiDialect;
import org.hibernate.dialect.MySQLDialect;
-import org.hibernate.dialect.Oracle9Dialect;
-import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.SybaseDialect;
import org.hibernate.dialect.Sybase11Dialect;
import org.hibernate.dialect.SybaseASE15Dialect;
import org.hibernate.dialect.SybaseAnywhereDialect;
import org.hibernate.dialect.TimesTenDialect;
import org.hibernate.dialect.SQLServerDialect;
+import org.hibernate.dialect.Oracle9iDialect;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
@@ -84,7 +83,7 @@
s.find("select count(*) from Simple s").size() == 1
);
- if ( getDialect() instanceof OracleDialect) {
+ if ( getDialect() instanceof Oracle9iDialect ) {
// Check Oracle Dialect mix of dialect functions - no args (no parenthesis and single arg functions
java.util.List rset = s.find("select s.name, sysdate(), trunc(s.pay), round(s.pay) from Simple s");
assertNotNull("Name string should have been returned",(((Object[])rset.get(0))[0]));
@@ -162,11 +161,11 @@
Map parameters = new HashMap();
parameters.put("name", simple.getName());
parameters.put("count", new Integer(simple.getCount()));
-
+
Query q = s.createQuery("from Simple s where s.name=:name and s.count=:count");
q.setProperties(((Map)parameters));
assertTrue( q.list().get(0)==simple );
-
+
List l = new ArrayList();
l.add("Simple 1");
l.add("Slimeball");
@@ -185,7 +184,6 @@
s.close();
}
public void testBroken() throws Exception {
- if (getDialect() instanceof Oracle9Dialect) return;
Session s = openSession();
Transaction t = s.beginTransaction();
Broken b = new Fixed();
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/SQLLoaderTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/SQLLoaderTest.java 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/legacy/SQLLoaderTest.java 2009-03-06 18:35:50 UTC (rev 16099)
@@ -14,8 +14,6 @@
import org.hibernate.classic.Session;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.MySQLDialect;
-import org.hibernate.dialect.Oracle9Dialect;
-import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.dialect.TimesTenDialect;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
@@ -47,7 +45,6 @@
}
public void testTS() throws Exception {
- if (getDialect() instanceof Oracle9Dialect) return;
Session session = openSession();
Transaction txn = session.beginTransaction();
Simple sim = new Simple();
@@ -150,7 +147,6 @@
s.close();
if ( getDialect() instanceof MySQLDialect ) return;
- if ( getDialect() instanceof OracleDialect ) return; // todo : this fails on Oracle8 also
s = openSession();
@@ -341,11 +337,7 @@
session = openSession();
Query query;
- if ( getDialect() instanceof OracleDialect ) {
- // Oracle8 does not support X/Open extension functions :)
- query = session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA where upper(name) like upper('max')", "a", A.class);
- }
- else if( getDialect() instanceof TimesTenDialect) {
+ if( getDialect() instanceof TimesTenDialect) {
// TimesTen does not permit general expressions (like UPPER) in the second part of a LIKE expression,
// so we execute a similar test
query = session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA where {fn ucase(name)} like 'MAX'", "a", A.class);
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/rowid/RowIdTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/rowid/RowIdTest.java 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/rowid/RowIdTest.java 2009-03-06 18:35:50 UTC (rev 16099)
@@ -10,8 +10,8 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.engine.SessionFactoryImplementor;
-import org.hibernate.dialect.Oracle9Dialect;
import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.Oracle9iDialect;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.junit.functional.DatabaseSpecificFunctionalTestCase;
@@ -37,7 +37,7 @@
}
public boolean appliesTo(Dialect dialect) {
- return dialect instanceof Oracle9Dialect;
+ return dialect instanceof Oracle9iDialect;
}
public boolean createSchema() {
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/check/OracleCheckStyleTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/check/OracleCheckStyleTest.java 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/check/OracleCheckStyleTest.java 2009-03-06 18:35:50 UTC (rev 16099)
@@ -3,7 +3,7 @@
import junit.framework.Test;
import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.Oracle9Dialect;
+import org.hibernate.dialect.Oracle9iDialect;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
/**
@@ -21,7 +21,7 @@
}
public boolean appliesTo(Dialect dialect) {
- return dialect instanceof Oracle9Dialect;
+ return dialect instanceof Oracle9iDialect;
}
public static Test suite() {
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/custom/oracle/OracleCustomSQLTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/custom/oracle/OracleCustomSQLTest.java 2009-03-06 18:23:24 UTC (rev 16098)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/custom/oracle/OracleCustomSQLTest.java 2009-03-06 18:35:50 UTC (rev 16099)
@@ -3,9 +3,8 @@
import junit.framework.Test;
-import org.hibernate.dialect.DataDirectOracle9Dialect;
import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.Oracle9Dialect;
+import org.hibernate.dialect.Oracle9iDialect;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.test.sql.hand.custom.CustomStoredProcTestSupport;
@@ -29,7 +28,7 @@
}
public boolean appliesTo(Dialect dialect) {
- return ( dialect instanceof Oracle9Dialect ) && !( dialect instanceof DataDirectOracle9Dialect );
+ return ( dialect instanceof Oracle9iDialect );
}
}
15 years, 9 months
Hibernate SVN: r16098 - in core/trunk/cache-jbosscache2: src/main/resources/org/hibernate/cache/jbc2/builder and 8 other directories.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2009-03-06 13:23:24 -0500 (Fri, 06 Mar 2009)
New Revision: 16098
Added:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccInvalidatedTransactionalTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccReadOnlyExtraAPITestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccReadOnlyTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccReplicatedTransactionalTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccTransactionalExtraAPITestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccInvalidatedTransactionalTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccReadOnlyExtraAPITestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccReadOnlyTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccReplicatedTransactionalTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccTransactionalExtraAPITestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/MVCCEntityReplicationTest.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/MVCCJBossCacheTest.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/MVCCSessionRefreshTest.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/MVCCBulkOperationsTest.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/classloader/MVCCIsolatedClassLoaderTest.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/mvcc-treecache.xml
Modified:
core/trunk/cache-jbosscache2/pom.xml
core/trunk/cache-jbosscache2/src/main/resources/org/hibernate/cache/jbc2/builder/jbc2-configs.xml
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractRegionImplTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/optimistic-treecache.xml
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/pessimistic-treecache.xml
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/query/QueryRegionImplTestCase.java
core/trunk/cache-jbosscache2/src/test/resources/treecache.xml
Log:
[HHH-3585] Move to JBoss Cache 3
Modified: core/trunk/cache-jbosscache2/pom.xml
===================================================================
--- core/trunk/cache-jbosscache2/pom.xml 2009-03-06 16:29:18 UTC (rev 16097)
+++ core/trunk/cache-jbosscache2/pom.xml 2009-03-06 18:23:24 UTC (rev 16098)
@@ -13,8 +13,8 @@
<artifactId>hibernate-jbosscache2</artifactId>
<packaging>jar</packaging>
- <name>Hibernate JBossCache2.x Integration</name>
- <description>Integration of Hibernate with JBossCache (based on JBossCache2.x APIs)</description>
+ <name>Hibernate JBossCache3.x Integration</name>
+ <description>Integration of Hibernate with JBossCache 3 (based on JBossCache2.x+ APIs)</description>
<dependencies>
<dependency>
@@ -25,7 +25,7 @@
<dependency>
<groupId>org.jboss.cache</groupId>
<artifactId>jbosscache-core</artifactId>
- <version>2.2.0.GA</version>
+ <version>3.0.3.GA</version>
</dependency>
<!-- test dependencies -->
Modified: core/trunk/cache-jbosscache2/src/main/resources/org/hibernate/cache/jbc2/builder/jbc2-configs.xml
===================================================================
(Binary files differ)
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractRegionImplTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractRegionImplTestCase.java 2009-03-06 16:29:18 UTC (rev 16097)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractRegionImplTestCase.java 2009-03-06 18:23:24 UTC (rev 16098)
@@ -67,7 +67,7 @@
public void testActivationDeactivation() throws Exception {
// Set up a cache to monitor affects of starting the region
- Cache remoteCache = new DefaultCacheFactory().createCache(SharedCacheInstanceManager.DEFAULT_CACHE_RESOURCE, false);
+ Cache remoteCache = DefaultCacheFactory.getInstance().createCache(SharedCacheInstanceManager.DEFAULT_CACHE_RESOURCE, false);
// This test assumes replication; verify that's correct
assertEquals("Cache is REPL_SYNC", "REPL_SYNC", remoteCache.getConfiguration().getCacheModeString());
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java 2009-03-06 16:29:18 UTC (rev 16097)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java 2009-03-06 18:23:24 UTC (rev 16098)
@@ -56,9 +56,9 @@
import org.jboss.cache.NodeSPI;
import org.jboss.cache.transaction.BatchModeTransactionManager;
-/**
+/**
* Base class for tests of CollectionRegionAccessStrategy impls.
- *
+ *
* @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
* @version $Revision: 1 $
*/
@@ -68,44 +68,44 @@
public static final String KEY_BASE = "KEY";
public static final String VALUE1 = "VALUE1";
public static final String VALUE2 = "VALUE2";
-
+
protected static int testCount;
-
+
protected static Configuration localCfg;
protected static JBossCacheRegionFactory localRegionFactory;
protected static Cache localCache;
protected static Configuration remoteCfg;
protected static JBossCacheRegionFactory remoteRegionFactory;
protected static Cache remoteCache;
-
+
protected CollectionRegion localCollectionRegion;
protected CollectionRegionAccessStrategy localAccessStrategy;
protected CollectionRegion remoteCollectionRegion;
protected CollectionRegionAccessStrategy remoteAccessStrategy;
-
+
protected boolean invalidation;
protected boolean optimistic;
protected boolean synchronous;
-
+
protected Exception node1Exception;
protected Exception node2Exception;
-
+
protected AssertionFailedError node1Failure;
protected AssertionFailedError node2Failure;
-
+
public static Test getTestSetup(Class testClass, String configName) {
TestSuite suite = new TestSuite(testClass);
return new AccessStrategyTestSetup(suite, configName);
}
-
+
public static Test getTestSetup(Test test, String configName) {
return new AccessStrategyTestSetup(test, configName);
}
-
+
/**
* Create a new TransactionalAccessTestCase.
- *
+ *
* @param name
*/
public AbstractCollectionRegionAccessStrategyTestCase(String name) {
@@ -116,38 +116,38 @@
protected void setUp() throws Exception {
super.setUp();
-
+
// Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush();
-
+
invalidation = CacheHelper.isClusteredInvalidation(localCache);
synchronous = CacheHelper.isSynchronous(localCache);
optimistic = localCache.getConfiguration().getNodeLockingScheme() == org.jboss.cache.config.Configuration.NodeLockingScheme.OPTIMISTIC;
localCollectionRegion = localRegionFactory.buildCollectionRegion(REGION_NAME, localCfg.getProperties(), getCacheDataDescription());
localAccessStrategy = localCollectionRegion.buildAccessStrategy(getAccessType());
-
+
// Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush();
-
+
remoteCollectionRegion = remoteRegionFactory.buildCollectionRegion(REGION_NAME, remoteCfg.getProperties(), getCacheDataDescription());
remoteAccessStrategy = remoteCollectionRegion.buildAccessStrategy(getAccessType());
-
+
node1Exception = null;
node2Exception = null;
-
+
node1Failure = null;
node2Failure = null;
}
protected void tearDown() throws Exception {
-
+
super.tearDown();
-
+
if (localCollectionRegion != null)
localCollectionRegion.destroy();
if (remoteCollectionRegion != null)
remoteCollectionRegion.destroy();
-
+
try {
localCache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
localCache.removeNode(Fqn.ROOT);
@@ -155,7 +155,7 @@
catch (Exception e) {
log.error("Problem purging local cache" ,e);
}
-
+
try {
remoteCache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
remoteCache.removeNode(Fqn.ROOT);
@@ -163,46 +163,54 @@
catch (Exception e) {
log.error("Problem purging remote cache" ,e);
}
-
+
node1Exception = null;
node2Exception = null;
-
+
node1Failure = null;
node2Failure = null;
}
-
- protected static Configuration createConfiguration(String configName) {
+
+ protected static Configuration createConfiguration(String configName, String configResource) {
Configuration cfg = CacheTestUtil.buildConfiguration(REGION_PREFIX, MultiplexedJBossCacheRegionFactory.class, true, false);
cfg.setProperty(MultiplexingCacheInstanceManager.ENTITY_CACHE_RESOURCE_PROP, configName);
+ if (configResource != null) {
+ cfg.setProperty(MultiplexingCacheInstanceManager.CACHE_FACTORY_RESOURCE_PROP, configResource);
+ }
return cfg;
}
-
+
protected CacheDataDescription getCacheDataDescription() {
return new CacheDataDescriptionImpl(true, true, ComparableComparator.INSTANCE);
}
-
+
protected boolean isUsingOptimisticLocking() {
return optimistic;
}
-
+
+ public boolean isBlockingReads()
+ {
+ return !isUsingOptimisticLocking();
+ }
+
protected boolean isUsingInvalidation() {
return invalidation;
}
-
+
protected boolean isSynchronous() {
return synchronous;
}
-
+
protected Fqn getRegionFqn(String regionName, String regionPrefix) {
return BasicRegionAdapter.getTypeLastRegionFqn(regionName, regionPrefix, CollectionRegionImpl.TYPE);
}
-
+
/**
* This is just a setup test where we assert that the cache config is
* as we expected.
*/
public abstract void testCacheConfiguration();
-
+
/**
* Test method for {@link TransactionalAccess#getRegion()}.
*/
@@ -223,7 +231,7 @@
public void testPutFromLoadMinimal() throws Exception {
putFromLoadTest(true);
}
-
+
/**
* Simulate 2 nodes, both start, tx do a get, experience a cache miss,
* then 'read from db.' First does a putFromLoad, then an evict (to represent a change).
@@ -232,37 +240,37 @@
* both start a new tx and get. First should see the updated data;
* second should either see the updated data (isInvalidation()( == false)
* or null (isInvalidation() == true).
- *
+ *
* @param useMinimalAPI
* @throws Exception
*/
private void putFromLoadTest(final boolean useMinimalAPI) throws Exception {
-
+
final String KEY = KEY_BASE + testCount++;
-
+
final CountDownLatch writeLatch1 = new CountDownLatch(1);
final CountDownLatch writeLatch2 = new CountDownLatch(1);
final CountDownLatch completionLatch = new CountDownLatch(2);
-
- Thread node1 = new Thread() {
-
+
+ Thread node1 = new Thread() {
+
public void run() {
-
- try {
+
+ try {
long txTimestamp = System.currentTimeMillis();
BatchModeTransactionManager.getInstance().begin();
-
+
assertEquals("node1 starts clean", null, localAccessStrategy.get(KEY, txTimestamp));
-
+
writeLatch1.await();
-
+
if (useMinimalAPI) {
- localAccessStrategy.putFromLoad(KEY, VALUE2, txTimestamp, new Integer(2), true);
+ localAccessStrategy.putFromLoad(KEY, VALUE2, txTimestamp, new Integer(2), true);
}
else {
localAccessStrategy.putFromLoad(KEY, VALUE2, txTimestamp, new Integer(2));
}
-
+
BatchModeTransactionManager.getInstance().commit();
}
catch (Exception e) {
@@ -281,32 +289,32 @@
}
}
};
-
+
Thread node2 = new Thread() {
-
- public void run() {
-
- try {
+
+ public void run() {
+
+ try {
long txTimestamp = System.currentTimeMillis();
BatchModeTransactionManager.getInstance().begin();
-
+
assertNull("node2 starts clean", remoteAccessStrategy.get(KEY, txTimestamp));
-
+
// Let node1 write
writeLatch1.countDown();
// Wait for node1 to finish
writeLatch2.await();
-
+
// Let the first PFER propagate
sleep(200);
-
+
if (useMinimalAPI) {
- remoteAccessStrategy.putFromLoad(KEY, VALUE1, txTimestamp, new Integer(1), true);
+ remoteAccessStrategy.putFromLoad(KEY, VALUE1, txTimestamp, new Integer(1), true);
}
else {
remoteAccessStrategy.putFromLoad(KEY, VALUE1, txTimestamp, new Integer(1));
}
-
+
BatchModeTransactionManager.getInstance().commit();
}
catch (Exception e) {
@@ -323,26 +331,26 @@
}
}
};
-
+
node1.setDaemon(true);
node2.setDaemon(true);
-
+
node1.start();
- node2.start();
-
+ node2.start();
+
assertTrue("Threads completed", completionLatch.await(2, TimeUnit.SECONDS));
-
+
if (node1Failure != null)
throw node1Failure;
if (node2Failure != null)
throw node2Failure;
-
+
assertEquals("node1 saw no exceptions", null, node1Exception);
assertEquals("node2 saw no exceptions", null, node2Exception);
-
+
// let the final PFER propagate
sleep(100);
-
+
long txTimestamp = System.currentTimeMillis();
String msg1 = "Correct node1 value";
String msg2 = "Correct node2 value";
@@ -361,8 +369,8 @@
expected1 = VALUE2;
expected2 = VALUE2;
}
-
- assertEquals(msg1, expected1, localAccessStrategy.get(KEY, txTimestamp));
+
+ assertEquals(msg1, expected1, localAccessStrategy.get(KEY, txTimestamp));
assertEquals(msg2, expected2, remoteAccessStrategy.get(KEY, txTimestamp));
}
@@ -382,7 +390,7 @@
/**
* Test method for {@link TransactionalAccess#evict(java.lang.Object)}.
- *
+ *
* FIXME add testing of the "immediately without regard for transaction
* isolation" bit in the CollectionRegionAccessStrategy API.
*/
@@ -392,7 +400,7 @@
/**
* Test method for {@link TransactionalAccess#evictAll()}.
- *
+ *
* FIXME add testing of the "immediately without regard for transaction
* isolation" bit in the CollectionRegionAccessStrategy API.
*/
@@ -401,41 +409,41 @@
}
private void evictOrRemoveTest(boolean evict) {
-
+
final String KEY = KEY_BASE + testCount++;
-
+
assertNull("local is clean", localAccessStrategy.get(KEY, System.currentTimeMillis()));
assertNull("remote is clean", remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
-
+
localAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
assertEquals(VALUE1, localAccessStrategy.get(KEY, System.currentTimeMillis()));
remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
assertEquals(VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
-
+
// Wait for async propagation
sleep(250);
-
+
if (evict)
localAccessStrategy.evict(KEY);
else
localAccessStrategy.remove(KEY);
-
+
assertEquals(null, localAccessStrategy.get(KEY, System.currentTimeMillis()));
-
+
assertEquals(null, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
}
private void evictOrRemoveAllTest(boolean evict) {
-
+
final String KEY = KEY_BASE + testCount++;
-
+
Fqn regionFqn = getRegionFqn(REGION_NAME, REGION_PREFIX);
-
+
Node regionRoot = localCache.getRoot().getChild(regionFqn);
assertFalse(regionRoot == null);
assertEquals(0, getValidChildrenCount(regionRoot));
assertTrue(regionRoot.isResident());
-
+
if (isUsingOptimisticLocking()) {
assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
}
@@ -444,37 +452,37 @@
assertFalse(regionRoot == null);
assertEquals(0, getValidChildrenCount(regionRoot));
assertTrue(regionRoot.isResident());
-
+
if (isUsingOptimisticLocking()) {
assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
}
-
+
assertNull("local is clean", localAccessStrategy.get(KEY, System.currentTimeMillis()));
assertNull("remote is clean", remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
-
+
localAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
assertEquals(VALUE1, localAccessStrategy.get(KEY, System.currentTimeMillis()));
remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
assertEquals(VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
-
+
// Wait for async propagation
sleep(250);
-
+
if (isUsingOptimisticLocking()) {
regionRoot = localCache.getRoot().getChild(regionFqn);
assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
regionRoot = remoteCache.getRoot().getChild(regionFqn);
assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
}
-
+
if (evict)
localAccessStrategy.evictAll();
else
localAccessStrategy.removeAll();
-
+
// This should re-establish the region root node in the optimistic case
assertNull(localAccessStrategy.get(KEY, System.currentTimeMillis()));
-
+
regionRoot = localCache.getRoot().getChild(regionFqn);
if (isUsingOptimisticLocking()) {
assertFalse(regionRoot == null);
@@ -486,7 +494,7 @@
assertTrue("region root is removed", regionRoot == null || !regionRoot.isValid());
}
- // Re-establishing the region root on the local node doesn't
+ // Re-establishing the region root on the local node doesn't
// propagate it to other nodes. Do a get on the remote node to re-establish
// This only adds a node in the case of optimistic locking
assertEquals(null, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
@@ -498,15 +506,15 @@
assertTrue(regionRoot.isResident());
// Not invalidation, so we didn't insert a child above
assertEquals(0, getValidChildrenCount(regionRoot));
- }
+ }
else {
assertTrue("region root is removed", regionRoot == null || !regionRoot.isValid());
}
-
+
// Test whether the get above messes up the optimistic version
remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
assertEquals(VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
-
+
// Revalidate the region root
regionRoot = remoteCache.getRoot().getChild(regionFqn);
assertFalse(regionRoot == null);
@@ -514,14 +522,14 @@
assertTrue(regionRoot.isResident());
// Region root should have 1 child -- the one we added above
assertEquals(1, getValidChildrenCount(regionRoot));
-
+
// Wait for async propagation of the putFromLoad
sleep(250);
-
+
assertEquals("local is correct", (isUsingInvalidation() ? null : VALUE1), localAccessStrategy.get(KEY, System.currentTimeMillis()));
assertEquals("remote is correct", VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
}
-
+
private int getValidChildrenCount(Node node) {
int result = 0;
for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
@@ -529,9 +537,9 @@
result++;
}
}
- return result;
+ return result;
}
-
+
private void rollback() {
try {
BatchModeTransactionManager.getInstance().rollback();
@@ -539,58 +547,64 @@
catch (Exception e) {
log.error(e.getMessage(), e);
}
-
+
}
-
+
private static class AccessStrategyTestSetup extends TestSetup {
-
+
private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack";
-
- private String configName;
+
+ private final String configResource;
+ private final String configName;
private String preferIPv4Stack;
-
+
public AccessStrategyTestSetup(Test test, String configName) {
+ this(test, configName, null);
+ }
+
+ public AccessStrategyTestSetup(Test test, String configName, String configResource) {
super(test);
this.configName = configName;
+ this.configResource = configResource;
}
@Override
protected void setUp() throws Exception {
- super.setUp();
-
- // Try to ensure we use IPv4; otherwise cluster formation is very slow
+ super.setUp();
+
+ // Try to ensure we use IPv4; otherwise cluster formation is very slow
preferIPv4Stack = System.getProperty(PREFER_IPV4STACK);
System.setProperty(PREFER_IPV4STACK, "true");
-
- localCfg = createConfiguration(configName);
+
+ localCfg = createConfiguration(configName, configResource);
localRegionFactory = CacheTestUtil.startRegionFactory(localCfg);
localCache = localRegionFactory.getCacheInstanceManager().getCollectionCacheInstance();
-
- remoteCfg = createConfiguration(configName);
+
+ remoteCfg = createConfiguration(configName, configResource);
remoteRegionFactory = CacheTestUtil.startRegionFactory(remoteCfg);
remoteCache = remoteRegionFactory.getCacheInstanceManager().getCollectionCacheInstance();
}
@Override
- protected void tearDown() throws Exception {
+ protected void tearDown() throws Exception {
try {
super.tearDown();
}
finally {
if (preferIPv4Stack == null)
System.clearProperty(PREFER_IPV4STACK);
- else
- System.setProperty(PREFER_IPV4STACK, preferIPv4Stack);
+ else
+ System.setProperty(PREFER_IPV4STACK, preferIPv4Stack);
}
-
+
if (localRegionFactory != null)
localRegionFactory.stop();
-
+
if (remoteRegionFactory != null)
remoteRegionFactory.stop();
}
-
-
+
+
}
}
Copied: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccInvalidatedTransactionalTestCase.java (from rev 15807, core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccInvalidatedTransactionalTestCase.java)
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccInvalidatedTransactionalTestCase.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccInvalidatedTransactionalTestCase.java 2009-03-06 18:23:24 UTC (rev 16098)
@@ -0,0 +1,62 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache.jbc2.collection;
+
+import org.hibernate.test.util.CacheTestUtil;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Tests TRANSACTIONAL access when pessimistic locking and invalidation are used.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1 $
+ */
+public class MvccInvalidatedTransactionalTestCase extends AbstractTransactionalAccessTestCase {
+
+ /**
+ * Create a new PessimisticTransactionalAccessTestCase.
+ *
+ * @param name
+ */
+ public MvccInvalidatedTransactionalTestCase(String name) {
+ super(name);
+ }
+
+ public static Test suite() throws Exception {
+ TestSuite suite = CacheTestUtil.createFailureExpectedSuite(MvccInvalidatedTransactionalTestCase.class);
+ return getTestSetup(suite, "mvcc-entity");
+ }
+
+ @Override
+ public void testCacheConfiguration() {
+ assertTrue("Using Invalidation", isUsingInvalidation());
+ assertFalse("Using Optimistic locking", isUsingOptimisticLocking());
+ assertTrue("Synchronous mode", isSynchronous());
+ }
+
+ // Known failures
+
+}
Copied: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccReadOnlyExtraAPITestCase.java (from rev 15807, core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccReadOnlyExtraAPITestCase.java)
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccReadOnlyExtraAPITestCase.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccReadOnlyExtraAPITestCase.java 2009-03-06 18:23:24 UTC (rev 16098)
@@ -0,0 +1,72 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache.jbc2.collection;
+
+import org.hibernate.cache.access.CollectionRegionAccessStrategy;
+
+/**
+ * Tests for the "extra API" in EntityRegionAccessStrategy; in this
+ * version using pessimistic locking with READ_ONLY access.
+ * <p>
+ * By "extra API" we mean those methods that are superfluous to the
+ * function of the JBC integration, where the impl is a no-op or a static
+ * false return value, UnsupportedOperationException, etc.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1 $
+ */
+public class MvccReadOnlyExtraAPITestCase extends OptimisticReadOnlyExtraAPITestCase {
+
+ private static CollectionRegionAccessStrategy localAccessStrategy;
+
+ /**
+ * Create a new PessimisticAccessStrategyExtraAPITestCase.
+ *
+ * @param name
+ */
+ public MvccReadOnlyExtraAPITestCase(String name) {
+ super(name);
+ }
+
+ @Override
+ protected String getCacheConfigName() {
+ return "mvcc-entity";
+ }
+
+ @Override
+ protected CollectionRegionAccessStrategy getCollectionAccessStrategy() {
+ return localAccessStrategy;
+ }
+
+ @Override
+ protected void setCollectionAccessStrategy(CollectionRegionAccessStrategy strategy) {
+ localAccessStrategy = strategy;
+ }
+
+ @Override
+ public void testCacheConfiguration() {
+ assertFalse("Using Optimistic locking", isUsingOptimisticLocking());
+ }
+
+}
Copied: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccReadOnlyTestCase.java (from rev 15807, core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccReadOnlyTestCase.java)
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccReadOnlyTestCase.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccReadOnlyTestCase.java 2009-03-06 18:23:24 UTC (rev 16098)
@@ -0,0 +1,63 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache.jbc2.collection;
+
+import org.hibernate.test.util.CacheTestUtil;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Tests READ_ONLY access when pessimistic locking and invalidation are used.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1 $
+ */
+public class MvccReadOnlyTestCase extends AbstractReadOnlyAccessTestCase {
+
+ /**
+ * Create a new PessimisticTransactionalAccessTestCase.
+ *
+ * @param name
+ */
+ public MvccReadOnlyTestCase(String name) {
+ super(name);
+ }
+
+ public static Test suite() throws Exception {
+ TestSuite suite = CacheTestUtil.createFailureExpectedSuite(MvccReadOnlyTestCase.class);
+ return getTestSetup(suite, "mvcc-entity");
+ }
+
+ // Known failures
+
+ // Overrides
+
+ @Override
+ public void testCacheConfiguration() {
+ assertTrue("Using Invalidation", isUsingInvalidation());
+ assertFalse("Using Optimistic locking", isUsingOptimisticLocking());
+ }
+
+}
Copied: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccReplicatedTransactionalTestCase.java (from rev 15807, core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccReplicatedTransactionalTestCase.java)
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccReplicatedTransactionalTestCase.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccReplicatedTransactionalTestCase.java 2009-03-06 18:23:24 UTC (rev 16098)
@@ -0,0 +1,58 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache.jbc2.collection;
+
+import junit.framework.Test;
+
+/**
+ * Tests TRANSACTIONAL access when pessimistic locking and replication are used.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1 $
+ */
+public class MvccReplicatedTransactionalTestCase extends AbstractTransactionalAccessTestCase {
+
+ /**
+ * Create a new PessimisticTransactionalAccessTestCase.
+ *
+ * @param name
+ */
+ public MvccReplicatedTransactionalTestCase(String name) {
+ super(name);
+ }
+
+ public static Test suite() throws Exception {
+ return getTestSetup(MvccReplicatedTransactionalTestCase.class, "mvcc-shared");
+ }
+
+ @Override
+ public void testCacheConfiguration() {
+ assertFalse("Using Invalidation", isUsingInvalidation());
+ assertFalse("Using Optimistic locking", isUsingOptimisticLocking());
+ assertTrue("Synchronous mode", isSynchronous());
+ }
+
+
+
+}
Copied: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccTransactionalExtraAPITestCase.java (from rev 15807, core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccTransactionalExtraAPITestCase.java)
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccTransactionalExtraAPITestCase.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/MvccTransactionalExtraAPITestCase.java 2009-03-06 18:23:24 UTC (rev 16098)
@@ -0,0 +1,72 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache.jbc2.collection;
+
+import org.hibernate.cache.access.CollectionRegionAccessStrategy;
+
+/**
+ * Tests for the "extra API" in EntityRegionAccessStrategy; in this base
+ * version using Optimistic locking with TRANSACTIONAL access.
+ * <p>
+ * By "extra API" we mean those methods that are superfluous to the
+ * function of the JBC integration, where the impl is a no-op or a static
+ * false return value, UnsupportedOperationException, etc.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1 $
+ */
+public class MvccTransactionalExtraAPITestCase extends OptimisticTransactionalExtraAPITestCase {
+
+ private static CollectionRegionAccessStrategy localAccessStrategy;
+
+ /**
+ * Create a new PessimisticAccessStrategyExtraAPITestCase.
+ *
+ * @param name
+ */
+ public MvccTransactionalExtraAPITestCase(String name) {
+ super(name);
+ }
+
+ @Override
+ protected String getCacheConfigName() {
+ return "mvcc-entity";
+ }
+
+ @Override
+ protected CollectionRegionAccessStrategy getCollectionAccessStrategy() {
+ return localAccessStrategy;
+ }
+
+ @Override
+ protected void setCollectionAccessStrategy(CollectionRegionAccessStrategy strategy) {
+ localAccessStrategy = strategy;
+ }
+
+ @Override
+ public void testCacheConfiguration() {
+ assertFalse("Using Optimistic locking", isUsingOptimisticLocking());
+ }
+
+}
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java 2009-03-06 16:29:18 UTC (rev 16097)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java 2009-03-06 18:23:24 UTC (rev 16098)
@@ -55,9 +55,9 @@
import org.jboss.cache.NodeSPI;
import org.jboss.cache.transaction.BatchModeTransactionManager;
-/**
+/**
* Base class for tests of EntityRegionAccessStrategy impls.
- *
+ *
* @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
* @version $Revision: 1 $
*/
@@ -67,46 +67,54 @@
public static final String KEY_BASE = "KEY";
public static final String VALUE1 = "VALUE1";
public static final String VALUE2 = "VALUE2";
-
+
protected static int testCount;
-
+
protected static Configuration localCfg;
protected static JBossCacheRegionFactory localRegionFactory;
protected static Cache localCache;
protected static Configuration remoteCfg;
protected static JBossCacheRegionFactory remoteRegionFactory;
protected static Cache remoteCache;
-
+
protected static boolean invalidation;
protected static boolean optimistic;
protected static boolean synchronous;
-
+
protected EntityRegion localEntityRegion;
protected EntityRegionAccessStrategy localAccessStrategy;
protected EntityRegion remoteEntityRegion;
protected EntityRegionAccessStrategy remoteAccessStrategy;
-
+
protected Exception node1Exception;
protected Exception node2Exception;
-
+
protected AssertionFailedError node1Failure;
protected AssertionFailedError node2Failure;
-
-
+
+
public static Test getTestSetup(Class testClass, String configName) {
- TestSuite suite = new TestSuite(testClass);
- return new AccessStrategyTestSetup(suite, configName);
+ return getTestSetup(testClass, configName, null);
}
-
+
public static Test getTestSetup(Test test, String configName) {
- return new AccessStrategyTestSetup(test, configName);
+ return getTestSetup(test, configName, null);
}
-
-
+
+ public static Test getTestSetup(Class testClass, String configName, String configResource) {
+ TestSuite suite = new TestSuite(testClass);
+ return new AccessStrategyTestSetup(suite, configName, configResource);
+ }
+
+ public static Test getTestSetup(Test test, String configName, String configResource) {
+ return new AccessStrategyTestSetup(test, configName, configResource);
+ }
+
+
/**
* Create a new TransactionalAccessTestCase.
- *
+ *
* @param name
*/
public AbstractEntityRegionAccessStrategyTestCase(String name) {
@@ -117,35 +125,35 @@
protected void setUp() throws Exception {
super.setUp();
-
+
// Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush();
-
+
localEntityRegion = localRegionFactory.buildEntityRegion(REGION_NAME, localCfg.getProperties(), getCacheDataDescription());
localAccessStrategy = localEntityRegion.buildAccessStrategy(getAccessType());
-
+
// Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush();
-
+
remoteEntityRegion = remoteRegionFactory.buildEntityRegion(REGION_NAME, remoteCfg.getProperties(), getCacheDataDescription());
remoteAccessStrategy = remoteEntityRegion.buildAccessStrategy(getAccessType());
-
+
node1Exception = null;
node2Exception = null;
-
+
node1Failure = null;
node2Failure = null;
}
protected void tearDown() throws Exception {
-
+
super.tearDown();
-
+
if (localEntityRegion != null)
localEntityRegion.destroy();
if (remoteEntityRegion != null)
remoteEntityRegion.destroy();
-
+
try {
localCache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
localCache.removeNode(Fqn.ROOT);
@@ -153,7 +161,7 @@
catch (Exception e) {
log.error("Problem purging local cache" ,e);
}
-
+
try {
remoteCache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
remoteCache.removeNode(Fqn.ROOT);
@@ -161,36 +169,39 @@
catch (Exception e) {
log.error("Problem purging remote cache" ,e);
}
-
+
node1Exception = null;
node2Exception = null;
-
+
node1Failure = null;
node2Failure = null;
}
-
- protected static Configuration createConfiguration(String configName) {
+
+ protected static Configuration createConfiguration(String configName, String configResource) {
Configuration cfg = CacheTestUtil.buildConfiguration(REGION_PREFIX, MultiplexedJBossCacheRegionFactory.class, true, false);
cfg.setProperty(MultiplexingCacheInstanceManager.ENTITY_CACHE_RESOURCE_PROP, configName);
+ if (configResource != null) {
+ cfg.setProperty(MultiplexingCacheInstanceManager.CACHE_FACTORY_RESOURCE_PROP, configResource);
+ }
return cfg;
}
-
+
protected CacheDataDescription getCacheDataDescription() {
return new CacheDataDescriptionImpl(true, true, ComparableComparator.INSTANCE);
}
-
+
protected boolean isUsingOptimisticLocking() {
return optimistic;
}
-
+
protected boolean isUsingInvalidation() {
return invalidation;
}
-
+
protected boolean isSynchronous() {
return synchronous;
}
-
+
protected Fqn getRegionFqn(String regionName, String regionPrefix) {
return BasicRegionAdapter.getTypeLastRegionFqn(regionName, regionPrefix, EntityRegionImpl.TYPE);
}
@@ -201,24 +212,24 @@
throw node1Failure;
if (node2Failure != null)
throw node2Failure;
-
+
if (node1Exception != null) {
log.error("node1 saw an exception", node1Exception);
assertEquals("node1 saw no exceptions", null, node1Exception);
}
-
+
if (node2Exception != null) {
log.error("node2 saw an exception", node2Exception);
assertEquals("node2 saw no exceptions", null, node2Exception);
}
}
-
+
/**
* This is just a setup test where we assert that the cache config is
* as we expected.
*/
public abstract void testCacheConfiguration();
-
+
/**
* Test method for {@link TransactionalAccess#getRegion()}.
*/
@@ -239,7 +250,7 @@
public void testPutFromLoadMinimal() throws Exception {
putFromLoadTest(true);
}
-
+
/**
* Simulate 2 nodes, both start, tx do a get, experience a cache miss,
* then 'read from db.' First does a putFromLoad, then an update.
@@ -248,39 +259,39 @@
* both start a new tx and get. First should see the updated data;
* second should either see the updated data (isInvalidation() == false)
* or null (isInvalidation() == true).
- *
+ *
* @param useMinimalAPI
* @throws Exception
*/
private void putFromLoadTest(final boolean useMinimalAPI) throws Exception {
-
+
final String KEY = KEY_BASE + testCount++;
-
+
final CountDownLatch writeLatch1 = new CountDownLatch(1);
final CountDownLatch writeLatch2 = new CountDownLatch(1);
final CountDownLatch completionLatch = new CountDownLatch(2);
-
- Thread node1 = new Thread() {
-
+
+ Thread node1 = new Thread() {
+
public void run() {
-
- try {
+
+ try {
long txTimestamp = System.currentTimeMillis();
BatchModeTransactionManager.getInstance().begin();
-
+
assertNull("node1 starts clean", localAccessStrategy.get(KEY, txTimestamp));
-
+
writeLatch1.await();
-
+
if (useMinimalAPI) {
- localAccessStrategy.putFromLoad(KEY, VALUE1, txTimestamp, new Integer(1), true);
+ localAccessStrategy.putFromLoad(KEY, VALUE1, txTimestamp, new Integer(1), true);
}
else {
localAccessStrategy.putFromLoad(KEY, VALUE1, txTimestamp, new Integer(1));
}
-
+
localAccessStrategy.update(KEY, VALUE2, new Integer(2), new Integer(1));
-
+
BatchModeTransactionManager.getInstance().commit();
}
catch (Exception e) {
@@ -299,29 +310,29 @@
}
}
};
-
+
Thread node2 = new Thread() {
-
- public void run() {
-
- try {
+
+ public void run() {
+
+ try {
long txTimestamp = System.currentTimeMillis();
BatchModeTransactionManager.getInstance().begin();
-
+
assertNull("node1 starts clean", remoteAccessStrategy.get(KEY, txTimestamp));
-
+
// Let node1 write
writeLatch1.countDown();
// Wait for node1 to finish
writeLatch2.await();
-
+
if (useMinimalAPI) {
- remoteAccessStrategy.putFromLoad(KEY, VALUE1, txTimestamp, new Integer(1), true);
+ remoteAccessStrategy.putFromLoad(KEY, VALUE1, txTimestamp, new Integer(1), true);
}
else {
remoteAccessStrategy.putFromLoad(KEY, VALUE1, txTimestamp, new Integer(1));
}
-
+
BatchModeTransactionManager.getInstance().commit();
}
catch (Exception e) {
@@ -338,32 +349,32 @@
}
}
};
-
+
node1.setDaemon(true);
node2.setDaemon(true);
-
+
node1.start();
- node2.start();
-
+ node2.start();
+
assertTrue("Threads completed", completionLatch.await(2, TimeUnit.SECONDS));
-
+
assertThreadsRanCleanly();
-
+
long txTimestamp = System.currentTimeMillis();
assertEquals("Correct node1 value", VALUE2, localAccessStrategy.get(KEY, txTimestamp));
-
+
if (isUsingInvalidation()) {
if (isUsingOptimisticLocking())
- // The node is "deleted" but it's ghost data version prevents the stale node2 PFER
+ // The node is "deleted" but it's ghost data version prevents the stale node2 PFER
assertEquals("Correct node2 value", null, remoteAccessStrategy.get(KEY, txTimestamp));
else {
// no data version to prevent the PFER; we count on db locks preventing this
- assertEquals("Expected node2 value", VALUE1, remoteAccessStrategy.get(KEY, txTimestamp));
+ assertEquals("Expected node2 value", VALUE1, remoteAccessStrategy.get(KEY, txTimestamp));
}
}
else {
// The node1 update is replicated, preventing the node2 PFER
- assertEquals("Correct node2 value", VALUE2, remoteAccessStrategy.get(KEY, txTimestamp));
+ assertEquals("Correct node2 value", VALUE2, remoteAccessStrategy.get(KEY, txTimestamp));
}
}
@@ -371,28 +382,28 @@
* Test method for {@link TransactionalAccess#insert(java.lang.Object, java.lang.Object, java.lang.Object)}.
*/
public void testInsert() throws Exception {
-
+
final String KEY = KEY_BASE + testCount++;
-
+
final CountDownLatch readLatch = new CountDownLatch(1);
final CountDownLatch commitLatch = new CountDownLatch(1);
final CountDownLatch completionLatch = new CountDownLatch(2);
-
- Thread inserter = new Thread() {
-
+
+ Thread inserter = new Thread() {
+
public void run() {
-
- try {
+
+ try {
long txTimestamp = System.currentTimeMillis();
BatchModeTransactionManager.getInstance().begin();
-
+
assertNull("Correct initial value", localAccessStrategy.get(KEY, txTimestamp));
-
+
localAccessStrategy.insert(KEY, VALUE1, new Integer(1));
-
+
readLatch.countDown();
commitLatch.await();
-
+
BatchModeTransactionManager.getInstance().commit();
}
catch (Exception e) {
@@ -409,20 +420,20 @@
}
}
};
-
- Thread reader = new Thread() {
-
+
+ Thread reader = new Thread() {
+
public void run() {
-
- try {
+
+ try {
long txTimestamp = System.currentTimeMillis();
BatchModeTransactionManager.getInstance().begin();
-
+
readLatch.await();
- Object expected = isUsingOptimisticLocking() ? null : VALUE1;
-
+ Object expected = !isBlockingReads() ? null : VALUE1;
+
assertEquals("Correct initial value", expected, localAccessStrategy.get(KEY, txTimestamp));
-
+
BatchModeTransactionManager.getInstance().commit();
}
catch (Exception e) {
@@ -440,13 +451,13 @@
}
}
};
-
+
inserter.setDaemon(true);
reader.setDaemon(true);
inserter.start();
reader.start();
-
- if (isUsingOptimisticLocking())
+
+ if (! isBlockingReads())
assertTrue("Threads completed", completionLatch.await(1, TimeUnit.SECONDS));
else {
// Reader should be blocking for lock
@@ -454,48 +465,53 @@
commitLatch.countDown();
assertTrue("Threads completed", completionLatch.await(1, TimeUnit.SECONDS));
}
-
+
assertThreadsRanCleanly();
-
+
long txTimestamp = System.currentTimeMillis();
assertEquals("Correct node1 value", VALUE1, localAccessStrategy.get(KEY, txTimestamp));
Object expected = isUsingInvalidation() ? null : VALUE1;
assertEquals("Correct node2 value", expected, remoteAccessStrategy.get(KEY, txTimestamp));
}
+ public boolean isBlockingReads()
+ {
+ return !isUsingOptimisticLocking();
+ }
+
/**
* Test method for {@link TransactionalAccess#update(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object)}.
*/
public void testUpdate() throws Exception {
-
+
final String KEY = KEY_BASE + testCount++;
-
+
// Set up initial state
localAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
-
+
// Let the async put propagate
sleep(250);
-
+
final CountDownLatch readLatch = new CountDownLatch(1);
final CountDownLatch commitLatch = new CountDownLatch(1);
final CountDownLatch completionLatch = new CountDownLatch(2);
-
- Thread updater = new Thread() {
-
+
+ Thread updater = new Thread() {
+
public void run() {
-
- try {
+
+ try {
long txTimestamp = System.currentTimeMillis();
BatchModeTransactionManager.getInstance().begin();
-
+
assertEquals("Correct initial value", VALUE1, localAccessStrategy.get(KEY, txTimestamp));
-
+
localAccessStrategy.update(KEY, VALUE2, new Integer(2), new Integer(1));
-
+
readLatch.countDown();
commitLatch.await();
-
+
BatchModeTransactionManager.getInstance().commit();
}
catch (Exception e) {
@@ -512,22 +528,22 @@
}
}
};
-
- Thread reader = new Thread() {
-
- public void run() {
- try {
+
+ Thread reader = new Thread() {
+
+ public void run() {
+ try {
long txTimestamp = System.currentTimeMillis();
BatchModeTransactionManager.getInstance().begin();
-
+
readLatch.await();
-
+
// This will block w/ pessimistic locking and then
// read the new value; w/ optimistic it shouldn't
// block and will read the old value
- Object expected = isUsingOptimisticLocking() ? VALUE1 : VALUE2;
+ Object expected = !isBlockingReads() ? VALUE1 : VALUE2;
assertEquals("Correct value", expected, localAccessStrategy.get(KEY, txTimestamp));
-
+
BatchModeTransactionManager.getInstance().commit();
}
catch (Exception e) {
@@ -542,28 +558,28 @@
finally {
commitLatch.countDown();
completionLatch.countDown();
- }
+ }
}
};
-
+
updater.setDaemon(true);
reader.setDaemon(true);
updater.start();
reader.start();
-
- if (isUsingOptimisticLocking())
+
+ if (! isBlockingReads())
// Should complete promptly
assertTrue(completionLatch.await(1, TimeUnit.SECONDS));
- else {
+ else {
// Reader thread should be blocking
assertFalse(completionLatch.await(250, TimeUnit.MILLISECONDS));
// Let the writer commit down
commitLatch.countDown();
assertTrue(completionLatch.await(1, TimeUnit.SECONDS));
}
-
+
assertThreadsRanCleanly();
-
+
long txTimestamp = System.currentTimeMillis();
assertEquals("Correct node1 value", VALUE2, localAccessStrategy.get(KEY, txTimestamp));
Object expected = isUsingInvalidation() ? null : VALUE2;
@@ -586,7 +602,7 @@
/**
* Test method for {@link TransactionalAccess#evict(java.lang.Object)}.
- *
+ *
* FIXME add testing of the "immediately without regard for transaction
* isolation" bit in the EntityRegionAccessStrategy API.
*/
@@ -596,7 +612,7 @@
/**
* Test method for {@link TransactionalAccess#evictAll()}.
- *
+ *
* FIXME add testing of the "immediately without regard for transaction
* isolation" bit in the EntityRegionAccessStrategy API.
*/
@@ -605,43 +621,43 @@
}
private void evictOrRemoveTest(boolean evict) {
-
+
final String KEY = KEY_BASE + testCount++;
-
+
assertNull("local is clean", localAccessStrategy.get(KEY, System.currentTimeMillis()));
assertNull("remote is clean", remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
-
+
localAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
assertEquals(VALUE1, localAccessStrategy.get(KEY, System.currentTimeMillis()));
remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
assertEquals(VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
-
+
// Wait for async propagation
sleep(250);
-
+
if (evict)
localAccessStrategy.evict(KEY);
else
localAccessStrategy.remove(KEY);
-
+
assertEquals(null, localAccessStrategy.get(KEY, System.currentTimeMillis()));
-
+
// sleep(1000);
-
+
assertEquals(null, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
}
private void evictOrRemoveAllTest(boolean evict) {
-
+
final String KEY = KEY_BASE + testCount++;
-
+
Fqn regionFqn = getRegionFqn(REGION_NAME, REGION_PREFIX);
-
+
Node regionRoot = localCache.getRoot().getChild(regionFqn);
assertFalse(regionRoot == null);
assertEquals(0, getValidChildrenCount(regionRoot));
assertTrue(regionRoot.isResident());
-
+
if (isUsingOptimisticLocking()) {
assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
}
@@ -650,41 +666,41 @@
assertFalse(regionRoot == null);
assertEquals(0, getValidChildrenCount(regionRoot));
assertTrue(regionRoot.isResident());
-
+
if (isUsingOptimisticLocking()) {
assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
}
-
+
assertNull("local is clean", localAccessStrategy.get(KEY, System.currentTimeMillis()));
assertNull("remote is clean", remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
-
+
localAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
assertEquals(VALUE1, localAccessStrategy.get(KEY, System.currentTimeMillis()));
-
+
// Wait for async propagation
sleep(250);
-
+
remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
assertEquals(VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
-
+
// Wait for async propagation
sleep(250);
-
+
if (isUsingOptimisticLocking()) {
regionRoot = localCache.getRoot().getChild(regionFqn);
assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
regionRoot = remoteCache.getRoot().getChild(regionFqn);
assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
}
-
+
if (evict)
localAccessStrategy.evictAll();
else
localAccessStrategy.removeAll();
-
+
// This should re-establish the region root node in the optimistic case
assertNull(localAccessStrategy.get(KEY, System.currentTimeMillis()));
-
+
regionRoot = localCache.getRoot().getChild(regionFqn);
if (isUsingOptimisticLocking()) {
assertFalse(regionRoot == null);
@@ -696,7 +712,7 @@
assertTrue("region root is removed", regionRoot == null || !regionRoot.isValid());
}
- // Re-establishing the region root on the local node doesn't
+ // Re-establishing the region root on the local node doesn't
// propagate it to other nodes. Do a get on the remote node to re-establish
assertEquals(null, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
@@ -707,15 +723,15 @@
assertTrue(regionRoot.isResident());
// Not invalidation, so we didn't insert a child above
assertEquals(0, getValidChildrenCount(regionRoot));
- }
+ }
else {
assertTrue("region root is removed", regionRoot == null || !regionRoot.isValid());
}
-
+
// Test whether the get above messes up the optimistic version
remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
assertEquals(VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
-
+
// Revalidate the region root
regionRoot = remoteCache.getRoot().getChild(regionFqn);
assertFalse(regionRoot == null);
@@ -723,14 +739,14 @@
assertTrue(regionRoot.isResident());
// Region root should have 1 child -- the one we added above
assertEquals(1, getValidChildrenCount(regionRoot));
-
+
// Wait for async propagation
sleep(250);
-
+
assertEquals("local is correct", (isUsingInvalidation() ? null : VALUE1), localAccessStrategy.get(KEY, System.currentTimeMillis()));
assertEquals("remote is correct", VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
}
-
+
private int getValidChildrenCount(Node node) {
int result = 0;
for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
@@ -738,9 +754,9 @@
result++;
}
}
- return result;
+ return result;
}
-
+
protected void rollback() {
try {
BatchModeTransactionManager.getInstance().rollback();
@@ -748,19 +764,25 @@
catch (Exception e) {
log.error(e.getMessage(), e);
}
-
+
}
-
+
private static class AccessStrategyTestSetup extends TestSetup {
-
+
private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack";
-
- private String configName;
+
+ private final String configResource;
+ private final String configName;
private String preferIPv4Stack;
-
+
public AccessStrategyTestSetup(Test test, String configName) {
+ this(test, configName, null);
+ }
+
+ public AccessStrategyTestSetup(Test test, String configName, String configResource) {
super(test);
this.configName = configName;
+ this.configResource = configResource;
}
@Override
@@ -771,39 +793,39 @@
finally {
if (preferIPv4Stack == null)
System.clearProperty(PREFER_IPV4STACK);
- else
- System.setProperty(PREFER_IPV4STACK, preferIPv4Stack);
+ else
+ System.setProperty(PREFER_IPV4STACK, preferIPv4Stack);
}
-
- // Try to ensure we use IPv4; otherwise cluster formation is very slow
+
+ // Try to ensure we use IPv4; otherwise cluster formation is very slow
preferIPv4Stack = System.getProperty(PREFER_IPV4STACK);
System.setProperty(PREFER_IPV4STACK, "true");
-
- localCfg = createConfiguration(configName);
+
+ localCfg = createConfiguration(configName, configResource);
localRegionFactory = CacheTestUtil.startRegionFactory(localCfg);
localCache = localRegionFactory.getCacheInstanceManager().getEntityCacheInstance();
-
- remoteCfg = createConfiguration(configName);
+
+ remoteCfg = createConfiguration(configName, configResource);
remoteRegionFactory = CacheTestUtil.startRegionFactory(remoteCfg);
remoteCache = remoteRegionFactory.getCacheInstanceManager().getEntityCacheInstance();
-
+
invalidation = CacheHelper.isClusteredInvalidation(localCache);
synchronous = CacheHelper.isSynchronous(localCache);
optimistic = localCache.getConfiguration().getNodeLockingScheme() == org.jboss.cache.config.Configuration.NodeLockingScheme.OPTIMISTIC;
}
@Override
- protected void tearDown() throws Exception {
+ protected void tearDown() throws Exception {
super.tearDown();
-
+
if (localRegionFactory != null)
localRegionFactory.stop();
-
+
if (remoteRegionFactory != null)
remoteRegionFactory.stop();
}
-
-
+
+
}
}
Copied: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccInvalidatedTransactionalTestCase.java (from rev 15807, core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccInvalidatedTransactionalTestCase.java)
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccInvalidatedTransactionalTestCase.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccInvalidatedTransactionalTestCase.java 2009-03-06 18:23:24 UTC (rev 16098)
@@ -0,0 +1,68 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache.jbc2.entity;
+
+import org.hibernate.test.util.CacheTestUtil;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Tests TRANSACTIONAL access when MVCC locking and invalidation are used.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1 $
+ */
+public class MvccInvalidatedTransactionalTestCase extends AbstractTransactionalAccessTestCase {
+
+ /**
+ * Create a new PessimisticTransactionalAccessTestCase.
+ *
+ * @param name
+ */
+ public MvccInvalidatedTransactionalTestCase(String name) {
+ super(name);
+ }
+
+ public static Test suite() throws Exception {
+ TestSuite suite = CacheTestUtil.createFailureExpectedSuite(MvccInvalidatedTransactionalTestCase.class);
+ return getTestSetup(suite, "mvcc-entity");
+ }
+
+ // Known failures
+
+ // Overrides
+
+ @Override
+ public void testCacheConfiguration() {
+ assertTrue("Using Invalidation", isUsingInvalidation());
+ assertFalse("Using Optimistic locking", isUsingOptimisticLocking());
+ assertTrue("Synchronous mode", isSynchronous());
+ }
+
+ @Override
+ public boolean isBlockingReads() {
+ return false;
+ }
+}
Copied: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccReadOnlyExtraAPITestCase.java (from rev 15807, core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccReadOnlyExtraAPITestCase.java)
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccReadOnlyExtraAPITestCase.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccReadOnlyExtraAPITestCase.java 2009-03-06 18:23:24 UTC (rev 16098)
@@ -0,0 +1,71 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache.jbc2.entity;
+
+import org.hibernate.cache.access.EntityRegionAccessStrategy;
+
+/**
+ * Tests for the "extra API" in EntityRegionAccessStrategy; in this
+ * version using pessimistic locking with READ_ONLY access.
+ * <p>
+ * By "extra API" we mean those methods that are superfluous to the
+ * function of the JBC integration, where the impl is a no-op or a static
+ * false return value, UnsupportedOperationException, etc.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1 $
+ */
+public class MvccReadOnlyExtraAPITestCase extends OptimisticReadOnlyExtraAPITestCase {
+
+ private static EntityRegionAccessStrategy localAccessStrategy;
+
+ /**
+ * Create a new PessimisticAccessStrategyExtraAPITestCase.
+ *
+ * @param name
+ */
+ public MvccReadOnlyExtraAPITestCase(String name) {
+ super(name);
+ }
+
+ @Override
+ protected String getCacheConfigName() {
+ return "mvcc-entity";
+ }
+
+ @Override
+ protected EntityRegionAccessStrategy getEntityAccessStrategy() {
+ return localAccessStrategy;
+ }
+
+ @Override
+ protected void setEntityRegionAccessStrategy(EntityRegionAccessStrategy strategy) {
+ localAccessStrategy = strategy;
+ }
+
+ @Override
+ public void testCacheConfiguration() {
+ assertFalse("Using Optimistic locking", isUsingOptimisticLocking());
+ }
+}
Copied: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccReadOnlyTestCase.java (from rev 15807, core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccReadOnlyTestCase.java)
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccReadOnlyTestCase.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccReadOnlyTestCase.java 2009-03-06 18:23:24 UTC (rev 16098)
@@ -0,0 +1,68 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache.jbc2.entity;
+
+import org.hibernate.test.util.CacheTestUtil;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Tests READ_ONLY access when pessimistic locking and invalidation are used.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1 $
+ */
+public class MvccReadOnlyTestCase extends AbstractReadOnlyAccessTestCase {
+
+ /**
+ * Create a new PessimisticTransactionalAccessTestCase.
+ *
+ * @param name
+ */
+ public MvccReadOnlyTestCase(String name) {
+ super(name);
+ }
+
+ public static Test suite() throws Exception {
+ TestSuite suite = CacheTestUtil.createFailureExpectedSuite(MvccReadOnlyTestCase.class);
+ return getTestSetup(suite, "mvcc-entity");
+ }
+
+ // Known failures
+
+ // Overrides
+
+
+ @Override
+ public void testCacheConfiguration() {
+ assertTrue("Using Invalidation", isUsingInvalidation());
+ assertFalse("Using Optimistic locking", isUsingOptimisticLocking());
+ }
+
+ @Override
+ public boolean isBlockingReads() {
+ return false;
+ }
+}
Copied: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccReplicatedTransactionalTestCase.java (from rev 15807, core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccReplicatedTransactionalTestCase.java)
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccReplicatedTransactionalTestCase.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccReplicatedTransactionalTestCase.java 2009-03-06 18:23:24 UTC (rev 16098)
@@ -0,0 +1,62 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache.jbc2.entity;
+
+import junit.framework.Test;
+
+/**
+ * Tests TRANSACTIONAL access when pessimistic locking and replication are used.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1 $
+ */
+public class MvccReplicatedTransactionalTestCase extends AbstractTransactionalAccessTestCase {
+
+ /**
+ * Create a new PessimisticTransactionalAccessTestCase.
+ *
+ * @param name
+ */
+ public MvccReplicatedTransactionalTestCase(String name) {
+ super(name);
+ }
+
+ public static Test suite() throws Exception {
+ return getTestSetup(MvccReplicatedTransactionalTestCase.class, "mvcc-shared");
+ }
+
+ @Override
+ public void testCacheConfiguration() {
+ assertFalse("Using Invalidation", isUsingInvalidation());
+ assertFalse("Using Optimistic locking", isUsingOptimisticLocking());
+ assertTrue("Synchronous mode", isSynchronous());
+ }
+
+ @Override
+ public boolean isBlockingReads() {
+ return false;
+ }
+
+
+}
Copied: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccTransactionalExtraAPITestCase.java (from rev 15807, core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccTransactionalExtraAPITestCase.java)
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccTransactionalExtraAPITestCase.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/MvccTransactionalExtraAPITestCase.java 2009-03-06 18:23:24 UTC (rev 16098)
@@ -0,0 +1,71 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache.jbc2.entity;
+
+import org.hibernate.cache.access.EntityRegionAccessStrategy;
+
+/**
+ * Tests for the "extra API" in EntityRegionAccessStrategy; in this base
+ * version using Optimistic locking with TRANSACTIONAL access.
+ * <p>
+ * By "extra API" we mean those methods that are superfluous to the
+ * function of the JBC integration, where the impl is a no-op or a static
+ * false return value, UnsupportedOperationException, etc.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1 $
+ */
+public class MvccTransactionalExtraAPITestCase extends OptimisticTransactionalExtraAPITestCase {
+
+ private static EntityRegionAccessStrategy localAccessStrategy;
+
+ /**
+ * Create a new PessimisticAccessStrategyExtraAPITestCase.
+ *
+ * @param name
+ */
+ public MvccTransactionalExtraAPITestCase(String name) {
+ super(name);
+ }
+
+ @Override
+ protected String getCacheConfigName() {
+ return "mvcc-entity";
+ }
+
+ @Override
+ protected EntityRegionAccessStrategy getEntityAccessStrategy() {
+ return localAccessStrategy;
+ }
+
+ @Override
+ protected void setEntityRegionAccessStrategy(EntityRegionAccessStrategy strategy) {
+ localAccessStrategy = strategy;
+ }
+
+ @Override
+ public void testCacheConfiguration() {
+ assertFalse("Using Optimistic locking", isUsingOptimisticLocking());
+ }
+}
Copied: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/MVCCEntityReplicationTest.java (from rev 15807, core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/MVCCEntityReplicationTest.java)
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/MVCCEntityReplicationTest.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/MVCCEntityReplicationTest.java 2009-03-06 18:23:24 UTC (rev 16098)
@@ -0,0 +1,47 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache.jbc2.functional;
+
+
+/**
+ * Executes the superclass tests, but with Hibernate and JBoss Cache
+ * configured for optimistic locking.
+ *
+ * @author Brian Stansberry
+ */
+public class MVCCEntityReplicationTest extends PessimisticEntityReplicationTest
+{
+
+ public MVCCEntityReplicationTest(String name)
+ {
+ super(name);
+ }
+
+ @Override
+ protected String getEntityCacheConfigName()
+ {
+ return "mvcc-shared";
+ }
+
+}
Copied: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/MVCCJBossCacheTest.java (from rev 15807, core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/MVCCJBossCacheTest.java)
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/MVCCJBossCacheTest.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/MVCCJBossCacheTest.java 2009-03-06 18:23:24 UTC (rev 16098)
@@ -0,0 +1,64 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache.jbc2.functional;
+
+import junit.framework.Test;
+
+import org.hibernate.cache.RegionFactory;
+import org.hibernate.cache.jbc2.JBossCacheRegionFactory;
+import org.hibernate.cache.jbc2.builder.SharedCacheInstanceManager;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+
+/**
+ * Basic functional test of a pessimistic locking entity + query cache.
+ *
+ * @author Brian Stansberry
+ */
+public class MVCCJBossCacheTest extends AbstractQueryCacheFunctionalTestCase {
+
+ private static final String JBC_CONFIG = "org/hibernate/test/cache/jbc2/functional/mvcc-treecache.xml";
+
+ public MVCCJBossCacheTest(String x) {
+ super(x);
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite(MVCCJBossCacheTest.class);
+ }
+
+ protected Class<? extends RegionFactory> getCacheRegionFactory() {
+ return JBossCacheRegionFactory.class;
+ }
+
+ /**
+ * Apply any region-factory specific configurations.
+ *
+ * @param the Configuration to update.
+ */
+ protected void configureCacheFactory(Configuration cfg) {
+ cfg.setProperty(SharedCacheInstanceManager.CACHE_RESOURCE_PROP, JBC_CONFIG);
+ }
+
+}
Copied: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/MVCCSessionRefreshTest.java (from rev 15807, core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/MVCCSessionRefreshTest.java)
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/MVCCSessionRefreshTest.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/MVCCSessionRefreshTest.java 2009-03-06 18:23:24 UTC (rev 16098)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Brian Stansberry
+ */
+
+package org.hibernate.test.cache.jbc2.functional;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.cache.jbc2.functional.util.IsolatedCacheTestSetup;
+
+/**
+ * A SessionRefreshTest that uses an OPTIMISTIC cache config.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1 $
+ */
+public class MVCCSessionRefreshTest extends PessimisticSessionRefreshTest
+{
+
+ private static final String CACHE_CONFIG = "mvcc-entity";
+
+ /**
+ * Create a new OptimisticSessionRefreshTest.
+ *
+ * @param x
+ */
+ public MVCCSessionRefreshTest(String x)
+ {
+ super(x);
+ }
+
+ public static Test suite() throws Exception {
+ TestSuite suite = new TestSuite(MVCCSessionRefreshTest.class);
+ String[] acctClasses = { OUR_PACKAGE + ".Account", OUR_PACKAGE + ".AccountHolder" };
+ return new IsolatedCacheTestSetup(suite, acctClasses, CACHE_CONFIG);
+ }
+
+ @Override
+ protected String getEntityCacheConfigName() {
+ return CACHE_CONFIG;
+ }
+
+}
Copied: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/MVCCBulkOperationsTest.java (from rev 15807, core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/MVCCBulkOperationsTest.java)
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/MVCCBulkOperationsTest.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/MVCCBulkOperationsTest.java 2009-03-06 18:23:24 UTC (rev 16098)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.hibernate.test.cache.jbc2.functional.bulk;
+
+import junit.framework.Test;
+
+import org.hibernate.test.cache.jbc2.collection.OptimisticInvalidatedTransactionalTestCase;
+import org.hibernate.test.util.CacheTestUtil;
+
+
+/**
+ * Optimistic version of BulkOperationsUnitTestCase.
+ *
+ * @author Brian Stansberry
+ *
+ */
+public class MVCCBulkOperationsTest
+ extends PessimisticBulkOperationsTest
+{
+
+ public static Test suite() throws Exception {
+ return CacheTestUtil.createFailureExpectedSuite(MVCCBulkOperationsTest.class);
+ }
+
+ /**
+ * @param name
+ */
+ public MVCCBulkOperationsTest(String name)
+ {
+ super(name);
+ }
+
+ @Override
+ protected String getEntityCacheConfigName()
+ {
+ return "mvcc-entity";
+ }
+
+}
Copied: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/classloader/MVCCIsolatedClassLoaderTest.java (from rev 15807, core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/classloader/MVCCIsolatedClassLoaderTest.java)
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/classloader/MVCCIsolatedClassLoaderTest.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/classloader/MVCCIsolatedClassLoaderTest.java 2009-03-06 18:23:24 UTC (rev 16098)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Brian Stansberry
+ */
+
+package org.hibernate.test.cache.jbc2.functional.classloader;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.cache.jbc2.functional.util.IsolatedCacheTestSetup;
+
+/**
+ * Optimistic locking version of IsolatedClassLoaderTest.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1 $
+ */
+public class MVCCIsolatedClassLoaderTest extends PessimisticIsolatedClassLoaderTest
+{
+ private static final String CACHE_CONFIG = "mvcc-shared";
+
+ /**
+ * Create a new OptimisticIsolatedClassLoaderTest.
+ *
+ * @param name
+ */
+ public MVCCIsolatedClassLoaderTest(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite() throws Exception {
+ TestSuite suite = new TestSuite(MVCCIsolatedClassLoaderTest.class);
+ String[] acctClasses = { OUR_PACKAGE + ".Account", OUR_PACKAGE + ".AccountHolder" };
+ return new IsolatedCacheTestSetup(suite, acctClasses, CACHE_CONFIG);
+ }
+
+ protected String getEntityCacheConfigName() {
+ return CACHE_CONFIG;
+ }
+
+}
Copied: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/mvcc-treecache.xml (from rev 15807, core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/mvcc-treecache.xml)
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/mvcc-treecache.xml (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/mvcc-treecache.xml 2009-03-06 18:23:24 UTC (rev 16098)
@@ -0,0 +1,145 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ Hibernate, Relational Persistence for Idiomatic Java
+ ~
+ ~ Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Middleware LLC.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+
+<!-- ===================================================================== -->
+<!-- -->
+<!-- Sample TreeCache Service Configuration -->
+<!-- -->
+<!-- ===================================================================== -->
+
+<server>
+
+ <classpath codebase="./lib" archives="jboss-cache.jar, jgroups.jar"/>
+
+
+ <!-- ==================================================================== -->
+ <!-- Defines TreeCache configuration -->
+ <!-- ==================================================================== -->
+
+ <mbean code="org.jboss.cache.jmx.CacheJmxWrapper"
+ name="jboss.cache:service=TreeCache">
+
+ <depends>jboss:service=Naming</depends>
+ <depends>jboss:service=TransactionManager</depends>
+
+ <!--
+ Node locking scheme:
+ OPTIMISTIC
+ PESSIMISTIC
+ MVCC (default)
+ -->
+ <attribute name="NodeLockingScheme">MVCC</attribute>
+
+ <!--
+ TransactionManager configuration not required for Hibernate!
+ Hibernate will plug in its own transaction manager integration.
+ -->
+
+ <attribute name="IsolationLevel">READ_COMMITTED</attribute>
+
+ <!--
+ Valid modes are LOCAL
+ REPL_ASYNC
+ REPL_SYNC
+ -->
+ <attribute name="CacheMode">LOCAL</attribute>
+
+ <!-- Name of cluster. Needs to be the same for all clusters, in order
+ to find each other
+ -->
+ <attribute name="ClusterName">TreeCache-Cluster</attribute>
+
+ <attribute name="ClusterConfig">
+ <config>
+ <!-- UDP: if you have a multihomed machine,
+ set the bind_addr attribute to the appropriate NIC IP address -->
+ <!-- UDP: On Windows machines, because of the media sense feature
+ being broken with multicast (even after disabling media sense)
+ set the loopback attribute to true -->
+ <UDP mcast_addr="228.1.2.3" mcast_port="45566"
+ ip_ttl="64" ip_mcast="true"
+ mcast_send_buf_size="150000" mcast_recv_buf_size="80000"
+ ucast_send_buf_size="150000" ucast_recv_buf_size="80000"
+ loopback="false"/>
+ <PING timeout="2000" num_initial_members="3"/>
+ <MERGE2 min_interval="10000" max_interval="20000"/>
+ <FD shun="true"/>
+ <VERIFY_SUSPECT timeout="1500"/>
+ <pbcast.NAKACK gc_lag="50" retransmit_timeout="600,1200,2400,4800"/>
+ <pbcast.STABLE desired_avg_gossip="20000"/>
+ <UNICAST timeout="600,1200,2400" min_threshold="10"/>
+ <FRAG frag_size="8192"/>
+ <pbcast.GMS join_timeout="5000" shun="true" print_local_addr="true"/>
+ <pbcast.STATE_TRANSFER/>
+ </config>
+ </attribute>
+
+ <!-- Must be true if any entity deployment uses a scoped classloader -->
+ <attribute name="UseRegionBasedMarshalling">true</attribute>
+ <!-- Must match the value of "useRegionBasedMarshalling" -->
+ <attribute name="InactiveOnStartup">true</attribute>
+
+ <!--
+ The max amount of time (in milliseconds) we wait until the
+ initial state (ie. the contents of the cache) are retrieved from
+ existing members in a clustered environment
+ -->
+ <attribute name="StateRetrievalTimeout">20000</attribute>
+
+ <!--
+ Number of milliseconds to wait until all responses for a
+ synchronous call have been received.
+ -->
+ <attribute name="SyncReplTimeout">20000</attribute>
+
+ <!-- Max number of milliseconds to wait for a lock acquisition -->
+ <attribute name="LockAcquisitionTimeout">15000</attribute>
+
+ <!-- For now. disable asynchronous RPC marshalling/sending -->
+ <attribute name="SerializationExecutorPoolSize">0</attribute>
+
+ <!-- Specific eviction policy configurations. This is LRU -->
+ <attribute name="EvictionPolicyConfig">
+ <config>
+ <attribute name="wakeUpIntervalSeconds">5</attribute>
+ <!-- Name of the DEFAULT eviction policy class. -->
+ <attribute name="policyClass">org.jboss.cache.eviction.LRUPolicy</attribute>
+ <!-- Cache wide default -->
+ <region name="/_default_">
+ <attribute name="maxNodes">5000</attribute>
+ <attribute name="timeToLiveSeconds">1000</attribute>
+ </region>
+ <!-- Don't ever evict modification timestamps -->
+ <region name="/TS">
+ <attribute name="maxNodes">0</attribute>
+ <attribute name="timeToLiveSeconds">0</attribute>
+ </region>
+ </config>
+ </attribute>
+ </mbean>
+
+
+</server>
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/optimistic-treecache.xml
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/optimistic-treecache.xml 2009-03-06 16:29:18 UTC (rev 16097)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/optimistic-treecache.xml 2009-03-06 18:23:24 UTC (rev 16098)
@@ -56,7 +56,8 @@
<!--
Node locking scheme:
OPTIMISTIC
- PESSIMISTIC (default)
+ PESSIMISTIC
+ MVCC (default)
-->
<attribute name="NodeLockingScheme">OPTIMISTIC</attribute>
@@ -137,6 +138,9 @@
<!-- Must match the value of "useRegionBasedMarshalling" -->
<attribute name="InactiveOnStartup">true</attribute>
+ <!-- For now. disable asynchronous RPC marshalling/sending -->
+ <attribute name="SerializationExecutorPoolSize">0</attribute>
+
<!-- Specific eviction policy configurations. This is LRU -->
<attribute name="EvictionPolicyConfig">
<config>
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/pessimistic-treecache.xml
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/pessimistic-treecache.xml 2009-03-06 16:29:18 UTC (rev 16097)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/pessimistic-treecache.xml 2009-03-06 18:23:24 UTC (rev 16098)
@@ -45,7 +45,16 @@
<depends>jboss:service=Naming</depends>
<depends>jboss:service=TransactionManager</depends>
+
<!--
+ Node locking scheme:
+ OPTIMISTIC
+ PESSIMISTIC
+ MVCC (default)
+ -->
+ <attribute name="NodeLockingScheme">PESSIMISTIC</attribute>
+
+ <!--
TransactionManager configuration not required for Hibernate!
Hibernate will plug in its own transaction manager integration.
-->
@@ -110,6 +119,9 @@
<!-- Max number of milliseconds to wait for a lock acquisition -->
<attribute name="LockAcquisitionTimeout">15000</attribute>
+ <!-- For now. disable asynchronous RPC marshalling/sending -->
+ <attribute name="SerializationExecutorPoolSize">0</attribute>
+
<!-- Specific eviction policy configurations. This is LRU -->
<attribute name="EvictionPolicyConfig">
<config>
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/query/QueryRegionImplTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/query/QueryRegionImplTestCase.java 2009-03-06 16:29:18 UTC (rev 16097)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/query/QueryRegionImplTestCase.java 2009-03-06 18:23:24 UTC (rev 16098)
@@ -94,6 +94,10 @@
public void testPutDoesNotBlockGetPessimistic() throws Exception {
putDoesNotBlockGetTest("pessimistic-shared");
}
+
+ public void testPutDoesNotBlockGetMVCC() throws Exception {
+ putDoesNotBlockGetTest("mvcc-shared");
+ }
private void putDoesNotBlockGetTest(String configName) throws Exception {
@@ -190,6 +194,10 @@
getDoesNotBlockPutTest("pessimistic-shared-repeatable");
}
+ public void testGetDoesNotBlockPutMVCC() throws Exception {
+ getDoesNotBlockPutTest("mvcc-shared");
+ }
+
private void getDoesNotBlockPutTest(String configName) throws Exception {
Configuration cfg = createConfiguration(configName);
Modified: core/trunk/cache-jbosscache2/src/test/resources/treecache.xml
===================================================================
--- core/trunk/cache-jbosscache2/src/test/resources/treecache.xml 2009-03-06 16:29:18 UTC (rev 16097)
+++ core/trunk/cache-jbosscache2/src/test/resources/treecache.xml 2009-03-06 18:23:24 UTC (rev 16098)
@@ -51,9 +51,9 @@
<!-- Node locking scheme:
OPTIMISTIC
- PESSIMISTIC (default)
+ MVCC (default)
-->
- <attribute name="NodeLockingScheme">PESSIMISTIC</attribute>
+ <attribute name="NodeLockingScheme">MVCC</attribute>
<!--
READ_COMMITTED is as strong as necessary for most 2nd Level Cache usage.
@@ -108,6 +108,9 @@
<!-- Must match the value of "useRegionBasedMarshalling" -->
<attribute name="InactiveOnStartup">true</attribute>
+ <!-- For now. disable asynchronous RPC marshalling/sending -->
+ <attribute name="SerializationExecutorPoolSize">0</attribute>
+
<!-- Specific eviction policy configurations. This is LRU -->
<attribute name="EvictionPolicyConfig">
<config>
15 years, 9 months
Hibernate SVN: r16097 - in validator/trunk/hibernate-validator/src: test/java/org/hibernate/validation and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-03-06 11:29:18 -0500 (Fri, 06 Mar 2009)
New Revision: 16097
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/ValidationMessages.java
Removed:
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validation/ValidationMessages_de.properties
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/ValidationPerformace.java
Log:
HV-102 Updated interpolation according to latest algorithm.
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolator.java 2009-03-06 11:18:15 UTC (rev 16096)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolator.java 2009-03-06 16:29:18 UTC (rev 16097)
@@ -17,11 +17,11 @@
*/
package org.hibernate.validation.engine;
-import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.validation.ConstraintDescriptor;
@@ -45,16 +45,22 @@
/**
* Regular expression used to do message interpolation.
*/
- private static final Pattern messagePattern = Pattern.compile( "\\{([\\w\\.]+)\\}" );
+ private static final Pattern messageParameterPattern = Pattern.compile( "(\\{[\\w\\.]+\\})" );
/**
* The default locale for the current user.
*/
private final Locale defaultLocale;
- private final Map<Locale, ResourceBundle> userBundlesMap = new HashMap<Locale, ResourceBundle>();
+ /**
+ * User specified resource bundles hashed against their locale.
+ */
+ private final Map<Locale, ResourceBundle> userBundlesMap = new ConcurrentHashMap<Locale, ResourceBundle>();
- private final Map<Locale, ResourceBundle> defaultBundlesMap = new HashMap<Locale, ResourceBundle>();
+ /**
+ * Builtin resource bundles hashed against there locale.
+ */
+ private final Map<Locale, ResourceBundle> defaultBundlesMap = new ConcurrentHashMap<Locale, ResourceBundle>();
public ResourceBundleMessageInterpolator() {
this( null );
@@ -66,7 +72,9 @@
if ( resourceBundle == null ) {
ResourceBundle bundle = getFileBasedResourceBundle( defaultLocale );
- userBundlesMap.put( defaultLocale, bundle );
+ if ( bundle != null ) {
+ userBundlesMap.put( defaultLocale, bundle );
+ }
}
else {
@@ -76,17 +84,71 @@
defaultBundlesMap.put( defaultLocale, ResourceBundle.getBundle( DEFAULT_VALIDATION_MESSAGES, defaultLocale ) );
}
- public String interpolate(String message, ConstraintDescriptor constraintDescriptor, Object value) {
+ /**
+ * {@inheritDoc}
+ */
+ public String interpolate(String message, ConstraintDescriptor<?> constraintDescriptor, Object value) {
// probably no need for caching, but it could be done by parameters since the map
// is immutable and uniquely built per Validation definition, the comparaison has to be based on == and not equals though
- return replace( message, constraintDescriptor.getParameters(), defaultLocale );
+ return interpolateMessage( message, constraintDescriptor.getParameters(), defaultLocale );
}
- public String interpolate(String message, ConstraintDescriptor constraintDescriptor, Object value, Locale locale) {
- return replace( message, constraintDescriptor.getParameters(), locale );
+ /**
+ * {@inheritDoc}
+ */
+ public String interpolate(String message, ConstraintDescriptor<?> constraintDescriptor, Object value, Locale locale) {
+ return interpolateMessage( message, constraintDescriptor.getParameters(), locale );
}
/**
+ * Runs the message interpolation according to alogrithm specified in JSR 303.
+ * <br/>
+ * Note:
+ * <br/>
+ * Lookups in user bundles is recursive whereas lookups in default bundle are not!
+ *
+ * @param message the message to interpolate
+ * @param annotationParameters the parameters of the annotation for which to interpolate this message
+ * @param locale the <code>Locale</code> to use for the resource bundle.
+ *
+ * @return the interpolated message.
+ */
+ private String interpolateMessage(String message, Map<String, Object> annotationParameters, Locale locale) {
+ ResourceBundle userResourceBundle = findUserResourceBundle( locale );
+ ResourceBundle defaultResourceBundle = findDefaultResourceBundle( locale );
+
+ String userBundleResolvedMessage;
+ String resolvedMessage = message;
+ boolean evaluatedDefaultBundleOnce = false;
+ do {
+ // search the user bundle recursive (step1)
+ userBundleResolvedMessage = replaceVariables(
+ resolvedMessage, userResourceBundle, locale, true
+ );
+
+ // exit condition - we have at least tried to vaidate against the default bundle and there was no
+ // further replacements
+ if ( evaluatedDefaultBundleOnce
+ && !hasReplacementTakenPlace( userBundleResolvedMessage, resolvedMessage ) ) {
+ break;
+ }
+
+ // search the default bundle non recursive (step2)
+ resolvedMessage = replaceVariables( userBundleResolvedMessage, defaultResourceBundle, locale, false );
+
+ evaluatedDefaultBundleOnce = true;
+ } while ( true );
+
+ // resolve annotation attributes (step 4)
+ resolvedMessage = replaceAnnotationAttributes( resolvedMessage, annotationParameters );
+ return resolvedMessage;
+ }
+
+ private boolean hasReplacementTakenPlace(String origMessage, String newMessage) {
+ return !origMessage.equals( newMessage );
+ }
+
+ /**
* Search current thread classloader for the resource bundle. If not found, search validator (this) classloader.
*
* @param locale The locale of the bundle to load.
@@ -128,49 +190,65 @@
return rb;
}
- private String replace(String message, Map<String, Object> parameters, Locale locale) {
- Matcher matcher = messagePattern.matcher( message );
+ private String replaceVariables(String message, ResourceBundle bundle, Locale locale, boolean recurse) {
+ Matcher matcher = messageParameterPattern.matcher( message );
StringBuffer sb = new StringBuffer();
+ String resolvedParameterValue;
while ( matcher.find() ) {
- matcher.appendReplacement( sb, resolveParameter( matcher.group( 1 ), parameters, locale ) );
+ String parameter = matcher.group( 1 );
+ resolvedParameterValue = resolveParameter(
+ parameter, bundle, locale, recurse
+ );
+
+ matcher.appendReplacement( sb, resolvedParameterValue );
}
matcher.appendTail( sb );
return sb.toString();
}
- private String resolveParameter(String token, Map<String, Object> parameters, Locale locale) {
- Object variable = parameters.get( token );
- if ( variable != null ) {
- return variable.toString();
+ private String replaceAnnotationAttributes(String message, Map<String, Object> annotationParameters) {
+ Matcher matcher = messageParameterPattern.matcher( message );
+ StringBuffer sb = new StringBuffer();
+ while ( matcher.find() ) {
+ String resolvedParameterValue;
+ String parameter = matcher.group( 1 );
+ Object variable = annotationParameters.get( removeCurlyBrace( parameter ) );
+ if ( variable != null ) {
+ resolvedParameterValue = variable.toString();
+ }
+ else {
+ resolvedParameterValue = message;
+ }
+ matcher.appendReplacement( sb, resolvedParameterValue );
}
+ matcher.appendTail( sb );
+ return sb.toString();
+ }
- ResourceBundle userResourceBundle = findUserResourceBundle( locale );
- ResourceBundle defaultResourceBundle = findDefaultResourceBundle( locale );
-
- StringBuffer buffer = new StringBuffer();
- String string = null;
+ private String resolveParameter(String parameterName, ResourceBundle bundle, Locale locale, boolean recurse) {
+ String parameterValue;
try {
- string = userResourceBundle != null ? userResourceBundle.getString( token ) : null;
- }
- catch ( MissingResourceException e ) {
- //give a second chance with the default resource bundle
- }
- if ( string == null ) {
- try {
- string = defaultResourceBundle.getString( token );
+ if ( bundle != null ) {
+ parameterValue = bundle.getString( removeCurlyBrace( parameterName ) );
+ if ( recurse ) {
+ parameterValue = replaceVariables( parameterValue, bundle, locale, recurse );
+ }
}
- catch ( MissingResourceException e ) {
- //return the unchanged string
- buffer.append( "{" ).append( token ).append( '}' );
+ else {
+ parameterValue = parameterName;
}
}
- if ( string != null ) {
- // call resolve recusively!
- buffer.append( replace( string, parameters, locale ) );
+ catch ( MissingResourceException e ) {
+ // return parameter itself
+ parameterValue = parameterName;
}
- return buffer.toString();
+ return parameterValue;
}
+ private String removeCurlyBrace(String parameter) {
+ return parameter.substring( 1, parameter.length() - 1 );
+ }
+
private ResourceBundle findDefaultResourceBundle(Locale locale) {
if ( defaultBundlesMap.containsKey( locale ) ) {
return defaultBundlesMap.get( locale );
@@ -187,7 +265,9 @@
}
ResourceBundle bundle = getFileBasedResourceBundle( locale );
- userBundlesMap.put( locale, bundle );
+ if ( bundle != null ) {
+ userBundlesMap.put( locale, bundle );
+ }
return bundle;
}
}
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/ValidationMessages.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/ValidationMessages.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/ValidationMessages.java 2009-03-06 16:29:18 UTC (rev 16097)
@@ -0,0 +1,71 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.PropertyResourceBundle;
+import java.util.ResourceBundle;
+
+import org.slf4j.Logger;
+
+import org.hibernate.validation.util.LoggerFactory;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ValidationMessages extends ResourceBundle {
+
+ private static final Logger log = LoggerFactory.make();
+
+ private static final String DEFAULT_PROPERTIES_FILE_NAME = "/org/hibernate/validation/ValidationMessages.properties";
+
+ private Map<String, String> messages = new HashMap<String, String>();
+
+ public ValidationMessages() throws Exception {
+
+ log.info( "For test purposes are we proxying the buildin messages!" );
+ addTestPropertiesToBundle();
+ log.info( "Adding the following properties to default properties {}", messages );
+
+ loadDefaultValidationProperties();
+ }
+
+ private void addTestPropertiesToBundle() {
+ messages.put( "replace.in.default.bundle1", "{replace.in.default.bundle2}" );
+ messages.put( "replace.in.default.bundle2", "foobar" );
+ }
+
+ private void loadDefaultValidationProperties() throws IOException {
+ InputStream in = this.getClass()
+ .getResourceAsStream( DEFAULT_PROPERTIES_FILE_NAME );
+ PropertyResourceBundle propertyBundle = new PropertyResourceBundle( in );
+ setParent( propertyBundle );
+ }
+
+ protected Object handleGetObject(String key) {
+ return messages.get( key );
+ }
+
+ public Enumeration<String> getKeys() {
+ throw new RuntimeException( "Not needed for testing purposes." );
+ }
+}
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolatorTest.java 2009-03-06 11:18:15 UTC (rev 16096)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolatorTest.java 2009-03-06 16:29:18 UTC (rev 16097)
@@ -26,6 +26,7 @@
import java.util.ResourceBundle;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
+import javax.validation.constraints.Max;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
@@ -47,8 +48,7 @@
@Before
public void setUp() {
- interpolator = new ResourceBundleMessageInterpolator( new TestResources() );
-
+ // Create some annotations for testing using AnnotationProxies
AnnotationDescriptor<NotNull> descriptor = new AnnotationDescriptor<NotNull>( NotNull.class );
notNull = AnnotationFactory.create( descriptor );
@@ -62,6 +62,8 @@
notNull, new Class<?>[] { }, new ConstraintHelper()
);
+ interpolator = new ResourceBundleMessageInterpolator( new TestResourceBundle() );
+
String expected = "replacement worked";
String actual = interpolator.interpolate( "{foo}", descriptor, null );
assertEquals( "Wrong substitution", expected, actual );
@@ -84,6 +86,9 @@
ConstraintDescriptorImpl<NotNull> descriptor = new ConstraintDescriptorImpl<NotNull>(
notNull, new Class<?>[] { }, new ConstraintHelper()
);
+
+ interpolator = new ResourceBundleMessageInterpolator( new TestResourceBundle() );
+
String expected = "foo"; // missing {}
String actual = interpolator.interpolate( "foo", descriptor, null );
assertEquals( "Wrong substitution", expected, actual );
@@ -98,6 +103,9 @@
ConstraintDescriptorImpl<NotNull> descriptor = new ConstraintDescriptorImpl<NotNull>(
notNull, new Class<?>[] { }, new ConstraintHelper()
);
+
+ interpolator = new ResourceBundleMessageInterpolator( new TestResourceBundle() );
+
String expected = "{bar}"; // unkown token {}
String actual = interpolator.interpolate( "{bar}", descriptor, null );
assertEquals( "Wrong substitution", expected, actual );
@@ -108,6 +116,9 @@
ConstraintDescriptorImpl<NotNull> descriptor = new ConstraintDescriptorImpl<NotNull>(
notNull, new Class<?>[] { }, new ConstraintHelper()
);
+
+ interpolator = new ResourceBundleMessageInterpolator( new TestResourceBundle() );
+
String expected = "may not be null";
String actual = interpolator.interpolate( notNull.message(), descriptor, null );
assertEquals( "Wrong substitution", expected, actual );
@@ -122,12 +133,12 @@
@Test
public void testMessageInterpolationWithLocale() {
- interpolator = new ResourceBundleMessageInterpolator();
-
ConstraintDescriptorImpl<NotNull> descriptor = new ConstraintDescriptorImpl<NotNull>(
notNull, new Class<?>[] { }, new ConstraintHelper()
);
+ interpolator = new ResourceBundleMessageInterpolator();
+
String expected = "kann nicht null sein";
String actual = interpolator.interpolate( notNull.message(), descriptor, null, Locale.GERMAN );
assertEquals( "Wrong substitution", expected, actual );
@@ -135,12 +146,12 @@
@Test
public void testFallbackToDefaultLocale() {
- interpolator = new ResourceBundleMessageInterpolator();
-
ConstraintDescriptorImpl<NotNull> descriptor = new ConstraintDescriptorImpl<NotNull>(
notNull, new Class<?>[] { }, new ConstraintHelper()
);
+ interpolator = new ResourceBundleMessageInterpolator();
+
String expected = "may not be null";
String actual = interpolator.interpolate( notNull.message(), descriptor, null, Locale.JAPAN );
assertEquals( "Wrong substitution", expected, actual );
@@ -148,25 +159,53 @@
@Test
public void testUserResourceBundle() {
- interpolator = new ResourceBundleMessageInterpolator();
-
ConstraintDescriptorImpl<NotNull> descriptor = new ConstraintDescriptorImpl<NotNull>(
notNull, new Class<?>[] { }, new ConstraintHelper()
);
+ interpolator = new ResourceBundleMessageInterpolator();
+
String expected = "no puede ser null";
String actual = interpolator.interpolate( notNull.message(), descriptor, null, new Locale( "es", "ES" ) );
assertEquals( "Wrong substitution", expected, actual );
}
- class TestResources extends ResourceBundle implements Enumeration<String> {
+ /**
+ * HV-102
+ */
+ @Test
+ public void testRecursiveMessageInterpoliation() {
+ AnnotationDescriptor<Max> descriptor = new AnnotationDescriptor<Max>( Max.class );
+ descriptor.setValue( "message", "{replace.in.user.bundle1}" );
+ descriptor.setValue( "value", 10l);
+ Max max = AnnotationFactory.create( descriptor );
+
+
+ ConstraintDescriptorImpl<Max> constraintDescriptor = new ConstraintDescriptorImpl<Max>(
+ max, new Class<?>[] { }, new ConstraintHelper()
+ );
+
+ interpolator = new ResourceBundleMessageInterpolator( new TestResourceBundle() );
+
+ String expected = "{replace.in.default.bundle2}";
+ String actual = interpolator.interpolate( max.message(), constraintDescriptor, null );
+ assertEquals( "Within default bundle replacement parameter evauation should not be recursive!", expected, actual );
+ }
+
+ /**
+ * A dummy resource bundle which can be passed to the constructor of ResourceBundleMessageInterpolator to replace
+ * the user specified resource bundle.
+ */
+ class TestResourceBundle extends ResourceBundle implements Enumeration<String> {
private Map<String, String> testResources;
Iterator<String> iter;
- public TestResources() {
+ public TestResourceBundle() {
testResources = new HashMap<String, String>();
// add some test messages
testResources.put( "foo", "replacement worked" );
+ testResources.put( "replace.in.user.bundle1", "{replace.in.user.bundle2}" );
+ testResources.put( "replace.in.user.bundle2", "{replace.in.default.bundle1}" );
iter = testResources.keySet().iterator();
}
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/ValidationPerformace.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/ValidationPerformace.java 2009-03-06 11:18:15 UTC (rev 16096)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/ValidationPerformace.java 2009-03-06 16:29:18 UTC (rev 16097)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -24,6 +24,7 @@
import junit.framework.Test;
import org.hibernate.validation.engine.ValidatorImplTest;
+import org.hibernate.validation.engine.ResourceBundleMessageInterpolatorTest;
/**
* Work in progress. Timings have no relevance. Using this class one can verify if applied changes affect the
@@ -37,8 +38,8 @@
long maxTimeInMillis = 1000;
List<Class<?>> testClasses = new ArrayList<Class<?>>();
- testClasses.add( ValidatorImplTest.class );
- //testClasses.add( GroupTest.class );
+ //testClasses.add( ValidatorImplTest.class );
+ testClasses.add( ResourceBundleMessageInterpolatorTest.class );
//testClasses.add( ConstraintCompositionTest.class );
Test test = new JUnit4TestFactory( testClasses ).makeTestSuite();
return new TimedTest( test, maxTimeInMillis );
Deleted: validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validation/ValidationMessages_de.properties
===================================================================
--- validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validation/ValidationMessages_de.properties 2009-03-06 11:18:15 UTC (rev 16096)
+++ validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validation/ValidationMessages_de.properties 2009-03-06 16:29:18 UTC (rev 16097)
@@ -1,2 +0,0 @@
-# $Id: ValidationMessages.properties 15846 2009-02-02 11:56:15Z hardy.ferentschik $
-validator.notNull=kann nicht null sein
15 years, 9 months
Hibernate SVN: r16096 - validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report.
by hibernate-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2009-03-06 06:18:15 -0500 (Fri, 06 Mar 2009)
New Revision: 16096
Modified:
validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageReport.java
Log:
fix styling for chapter total row
Modified: validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageReport.java
===================================================================
--- validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageReport.java 2009-03-06 04:50:32 UTC (rev 16095)
+++ validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageReport.java 2009-03-06 11:18:15 UTC (rev 16096)
@@ -412,14 +412,7 @@
}
- if (odd)
- {
- sb.append("<tr style=\"background-color:#f7f7f7\">");
- }
- else
- {
- sb.append("<tr style=\"font-weight: bold;background-color:#dddddd\">");
- }
+ sb.append("<tr style=\"font-weight: bold;background-color:#dddddd\">");
sb.append("<td>");
sb.append("Total");
15 years, 10 months
Hibernate SVN: r16095 - core/branches/Branch_3_3.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-03-05 23:50:32 -0500 (Thu, 05 Mar 2009)
New Revision: 16095
Modified:
core/branches/Branch_3_3/
Log:
added atlassian-ide-plugin.xml to svn:ignore list
Property changes on: core/branches/Branch_3_3
___________________________________________________________________
Name: svn:ignore
- target
local
*.ipr
*.iws
*.iml
.classpath
.project
.nbattrs
*.log
*.properties
.clover
+ target
local
*.ipr
*.iws
*.iml
atlassian-ide-plugin.xml
.classpath
.project
.nbattrs
*.log
*.properties
.clover
15 years, 10 months
Hibernate SVN: r16094 - in core/trunk/core/src: test/java/org/hibernate and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-03-05 23:49:15 -0500 (Thu, 05 Mar 2009)
New Revision: 16094
Added:
core/trunk/core/src/test/java/org/hibernate/util/
core/trunk/core/src/test/java/org/hibernate/util/StringHelperTest.java
Modified:
core/trunk/core/src/main/java/org/hibernate/util/StringHelper.java
Log:
HHH-3800 - Allow chopping of class names in various logging scenarios
Modified: core/trunk/core/src/main/java/org/hibernate/util/StringHelper.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/util/StringHelper.java 2009-03-06 04:48:32 UTC (rev 16093)
+++ core/trunk/core/src/main/java/org/hibernate/util/StringHelper.java 2009-03-06 04:49:15 UTC (rev 16094)
@@ -125,7 +125,7 @@
if ( template == null ) {
return template; // returnign null!
}
- int loc = template == null ? -1 : template.indexOf( placeholder );
+ int loc = template.indexOf( placeholder );
if ( loc < 0 ) {
return template;
}
@@ -171,6 +171,9 @@
* @return The collapsed name.
*/
public static String collapse(String name) {
+ if ( name == null ) {
+ return null;
+ }
int breakPoint = name.lastIndexOf( '.' );
if ( breakPoint < 0 ) {
return name;
@@ -208,7 +211,7 @@
* @return The name itself, or the partially unqualified form if it begins with the qualifier base.
*/
public static String partiallyUnqualify(String name, String qualifierBase) {
- if ( ! name.startsWith( qualifierBase ) ) {
+ if ( name == null || ! name.startsWith( qualifierBase ) ) {
return name;
}
return name.substring( qualifierBase.length() + 1 ); // +1 to start after the following '.'
@@ -225,7 +228,7 @@
* @return The name itself if it does not begin with the qualifierBase, or the properly collapsed form otherwise.
*/
public static String collapseQualifierBase(String name, String qualifierBase) {
- if ( ! name.startsWith( qualifierBase ) ) {
+ if ( name == null || ! name.startsWith( qualifierBase ) ) {
return collapse( name );
}
return collapseQualifier( qualifierBase, true ) + name.substring( qualifierBase.length() );
@@ -408,10 +411,13 @@
}
/**
- * Generate a nice alias for the given class name or collection role
- * name and unique integer. Subclasses of Loader do <em>not</em> have
- * to use aliases of this form.
- * @return an alias of the form <tt>foo1_</tt>
+ * Generate a nice alias for the given class name or collection role name and unique integer. Subclasses of
+ * Loader do <em>not</em> have to use aliases of this form.
+ *
+ * @param description The base name (usually an entity-name or collection-role)
+ * @param unique A uniquing value
+ *
+ * @return an alias of the form <samp>foo1_</samp>
*/
public static String generateAlias(String description, int unique) {
return generateAliasRoot(description) +
Added: core/trunk/core/src/test/java/org/hibernate/util/StringHelperTest.java
===================================================================
--- core/trunk/core/src/test/java/org/hibernate/util/StringHelperTest.java (rev 0)
+++ core/trunk/core/src/test/java/org/hibernate/util/StringHelperTest.java 2009-03-06 04:49:15 UTC (rev 16094)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.util;
+
+import junit.framework.TestCase;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class StringHelperTest extends TestCase {
+ private static final String BASE_PACKAGE = "org.hibernate";
+ private static final String STRING_HELPER_FQN = "org.hibernate.util.StringHelper";
+ private static final String STRING_HELPER_NAME = StringHelper.unqualify( STRING_HELPER_FQN );
+
+ public void testNameCollapsing() {
+ assertNull( StringHelper.collapse( null ) );
+ assertEquals( STRING_HELPER_NAME, StringHelper.collapse( STRING_HELPER_NAME ) );
+ assertEquals( "o.h.u.StringHelper", StringHelper.collapse( STRING_HELPER_FQN ) );
+ }
+
+ public void testPartialNameUnqualification() {
+ assertNull( StringHelper.partiallyUnqualify( null, BASE_PACKAGE ) );
+ assertEquals( STRING_HELPER_NAME, StringHelper.partiallyUnqualify( STRING_HELPER_NAME, BASE_PACKAGE ) );
+ assertEquals( "util.StringHelper", StringHelper.partiallyUnqualify( STRING_HELPER_FQN, BASE_PACKAGE ) );
+ }
+
+ public void testBasePackageCollapsing() {
+ assertNull( StringHelper.collapseQualifierBase( null, BASE_PACKAGE ) );
+ assertEquals( STRING_HELPER_NAME, StringHelper.collapseQualifierBase( STRING_HELPER_NAME, BASE_PACKAGE ) );
+ assertEquals( "o.h.util.StringHelper", StringHelper.collapseQualifierBase( STRING_HELPER_FQN, BASE_PACKAGE ) );
+ }
+}
15 years, 10 months
Hibernate SVN: r16093 - in core/branches/Branch_3_3/core/src: test/java/org/hibernate and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-03-05 23:48:32 -0500 (Thu, 05 Mar 2009)
New Revision: 16093
Added:
core/branches/Branch_3_3/core/src/test/java/org/hibernate/util/
core/branches/Branch_3_3/core/src/test/java/org/hibernate/util/StringHelperTest.java
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/util/StringHelper.java
Log:
HHH-3800 - Allow chopping of class names in various logging scenarios
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/util/StringHelper.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/util/StringHelper.java 2009-03-06 03:01:35 UTC (rev 16092)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/util/StringHelper.java 2009-03-06 04:48:32 UTC (rev 16093)
@@ -99,13 +99,16 @@
public static String[] replace(String templates[], String placeholder, String replacement) {
String[] result = new String[templates.length];
for ( int i =0; i<templates.length; i++ ) {
- result[i] = replace( templates[i], placeholder, replacement );;
+ result[i] = replace( templates[i], placeholder, replacement );
}
return result;
}
public static String replace(String template, String placeholder, String replacement, boolean wholeWords) {
- int loc = template == null ? -1 : template.indexOf( placeholder );
+ if ( template == null ) {
+ return template; // returnign null!
+ }
+ int loc = template.indexOf( placeholder );
if ( loc < 0 ) {
return template;
}
@@ -125,7 +128,10 @@
public static String replaceOnce(String template, String placeholder, String replacement) {
- int loc = template == null ? -1 : template.indexOf( placeholder );
+ if ( template == null ) {
+ return template; // returnign null!
+ }
+ int loc = template.indexOf( placeholder );
if ( loc < 0 ) {
return template;
}
@@ -171,6 +177,9 @@
* @return The collapsed name.
*/
public static String collapse(String name) {
+ if ( name == null ) {
+ return null;
+ }
int breakPoint = name.lastIndexOf( '.' );
if ( breakPoint < 0 ) {
return name;
@@ -208,12 +217,29 @@
* @return The name itself, or the partially unqualified form if it begins with the qualifier base.
*/
public static String partiallyUnqualify(String name, String qualifierBase) {
- if ( ! name.startsWith( qualifierBase ) ) {
+ if ( name == null || ! name.startsWith( qualifierBase ) ) {
return name;
}
return name.substring( qualifierBase.length() + 1 ); // +1 to include the following '.'
}
+ /**
+ * Cross between {@link #collapse} and {@link #partiallyUnqualify}. Functions much like {@link #collapse}
+ * except that only the qualifierBase is collapsed. For example, with a base of 'org.hibernate' the name
+ * 'org.hibernate.util.StringHelper' would become 'o.h.util.StringHelper'.
+ *
+ * @param name The (potentially) qualified name.
+ * @param qualifierBase The qualifier base.
+ *
+ * @return The name itself if it does not begin with the qualifierBase, or the properly collapsed form otherwise.
+ */
+ public static String collapseQualifierBase(String name, String qualifierBase) {
+ if ( name == null || ! name.startsWith( qualifierBase ) ) {
+ return collapse( name );
+ }
+ return collapseQualifier( qualifierBase, true ) + name.substring( qualifierBase.length() );
+ }
+
public static String[] suffix(String[] columns, String suffix) {
if ( suffix == null ) return columns;
String[] qualified = new String[columns.length];
@@ -391,10 +417,13 @@
}
/**
- * Generate a nice alias for the given class name or collection role
- * name and unique integer. Subclasses of Loader do <em>not</em> have
- * to use aliases of this form.
- * @return an alias of the form <tt>foo1_</tt>
+ * Generate a nice alias for the given class name or collection role name and unique integer. Subclasses of
+ * Loader do <em>not</em> have to use aliases of this form.
+ *
+ * @param description The base name (usually an entity-name or collection-role)
+ * @param unique A uniquing value
+ *
+ * @return an alias of the form <samp>foo1_</samp>
*/
public static String generateAlias(String description, int unique) {
return generateAliasRoot(description) +
Added: core/branches/Branch_3_3/core/src/test/java/org/hibernate/util/StringHelperTest.java
===================================================================
--- core/branches/Branch_3_3/core/src/test/java/org/hibernate/util/StringHelperTest.java (rev 0)
+++ core/branches/Branch_3_3/core/src/test/java/org/hibernate/util/StringHelperTest.java 2009-03-06 04:48:32 UTC (rev 16093)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.util;
+
+import junit.framework.TestCase;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class StringHelperTest extends TestCase {
+ private static final String BASE_PACKAGE = "org.hibernate";
+ private static final String STRING_HELPER_FQN = "org.hibernate.util.StringHelper";
+ private static final String STRING_HELPER_NAME = StringHelper.unqualify( STRING_HELPER_FQN );
+
+ public void testNameCollapsing() {
+ assertNull( StringHelper.collapse( null ) );
+ assertEquals( STRING_HELPER_NAME, StringHelper.collapse( STRING_HELPER_NAME ) );
+ assertEquals( "o.h.u.StringHelper", StringHelper.collapse( STRING_HELPER_FQN ) );
+ }
+
+ public void testPartialNameUnqualification() {
+ assertNull( StringHelper.partiallyUnqualify( null, BASE_PACKAGE ) );
+ assertEquals( STRING_HELPER_NAME, StringHelper.partiallyUnqualify( STRING_HELPER_NAME, BASE_PACKAGE ) );
+ assertEquals( "util.StringHelper", StringHelper.partiallyUnqualify( STRING_HELPER_FQN, BASE_PACKAGE ) );
+ }
+
+ public void testBasePackageCollapsing() {
+ assertNull( StringHelper.collapseQualifierBase( null, BASE_PACKAGE ) );
+ assertEquals( STRING_HELPER_NAME, StringHelper.collapseQualifierBase( STRING_HELPER_NAME, BASE_PACKAGE ) );
+ assertEquals( "o.h.util.StringHelper", StringHelper.collapseQualifierBase( STRING_HELPER_FQN, BASE_PACKAGE ) );
+ }
+}
15 years, 10 months
Hibernate SVN: r16092 - core/trunk.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-03-05 22:01:35 -0500 (Thu, 05 Mar 2009)
New Revision: 16092
Modified:
core/trunk/
Log:
added atlassian-ide-plugin.xml to svn:ignore
Property changes on: core/trunk
___________________________________________________________________
Name: svn:ignore
- target
local
*.ipr
*.iws
*.iml
.classpath
.project
.settings
.nbattrs
*.log
*.properties
.clover
+ target
local
*.ipr
*.iws
*.iml
atlassian-ide-plugin.xml
.classpath
.project
.settings
.nbattrs
*.log
*.properties
.clover
15 years, 10 months
Hibernate SVN: r16091 - in core/trunk: testsuite/src/test/java/org/hibernate/test/stateless and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-03-05 17:12:56 -0500 (Thu, 05 Mar 2009)
New Revision: 16091
Added:
core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/
core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Mappings.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Resource.java
core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Task.java
core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/User.java
Modified:
core/trunk/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java
Log:
HHH-3528 - FETCH JOIN query doesn't work in a StatelessSession
Modified: core/trunk/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java 2009-03-05 21:56:10 UTC (rev 16090)
+++ core/trunk/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java 2009-03-05 22:12:56 UTC (rev 16091)
@@ -1,7 +1,5 @@
/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
@@ -20,7 +18,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.impl;
@@ -264,13 +261,21 @@
boolean eager,
boolean nullable) throws HibernateException {
errorIfClosed();
- EntityPersister persister = getFactory().getEntityPersister(entityName);
+ EntityPersister persister = getFactory().getEntityPersister( entityName );
+ // first, try to load it from the temp PC associated to this SS
+ Object loaded = temporaryPersistenceContext.getEntity( new EntityKey( id, persister, getEntityMode() ) );
+ if ( loaded != null ) {
+ // we found it in the temp PC. Should indicate we are in the midst of processing a result set
+ // containing eager fetches via join fetch
+ return loaded;
+ }
if ( !eager && persister.hasProxy() ) {
- return persister.createProxy(id, this);
+ // if the metadata allowed proxy creation and caller did not request forceful eager loading,
+ // generate a proxy
+ return persister.createProxy( id, this );
}
- Object loaded = temporaryPersistenceContext.getEntity( new EntityKey(id, persister, EntityMode.POJO) );
- //TODO: if not loaded, throw an exception
- return loaded==null ? get( entityName, id ) : loaded;
+ // otherwise immediately materialize it
+ return get( entityName, id );
}
public Iterator iterate(String query, QueryParameters queryParameters) throws HibernateException {
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Mappings.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Mappings.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Mappings.hbm.xml 2009-03-05 22:12:56 UTC (rev 16091)
@@ -0,0 +1,56 @@
+<?xml version="1.0"?>
+<!--
+ ~ Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Middleware LLC.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<!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.stateless.fetching">
+
+ <class name="User">
+ <id name="id" type="long">
+ <generator class="increment" />
+ </id>
+ <property name="name" type="string"/>
+ </class>
+
+ <class name="Resource">
+ <id name="id" type="long">
+ <generator class="increment" />
+ </id>
+ <property name="name" type="string"/>
+ <many-to-one name="owner"/>
+ </class>
+
+ <class name="Task">
+ <id name="id" type="long">
+ <generator class="increment" />
+ </id>
+ <property name="description" type="string"/>
+ <many-to-one name="user"/>
+ <many-to-one name="resource"/>
+ <property name="dueDate" type="timestamp"/>
+ <property name="startDate" type="timestamp"/>
+ <property name="completionDate" type="timestamp"/>
+ </class>
+
+</hibernate-mapping>
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Resource.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Resource.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Resource.java 2009-03-05 22:12:56 UTC (rev 16091)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.stateless.fetching;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Resource {
+ private Long id;
+ private String name;
+ private User owner;
+
+ public Resource() {
+ }
+
+ public Resource(String name, User owner) {
+ this.name = name;
+ this.owner = owner;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public User getOwner() {
+ return owner;
+ }
+
+ public void setOwner(User owner) {
+ this.owner = owner;
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java 2009-03-05 22:12:56 UTC (rev 16091)
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.stateless.fetching;
+
+import java.util.Date;
+
+import junit.framework.Test;
+
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.ImprovedNamingStrategy;
+import org.hibernate.cfg.DefaultNamingStrategy;
+import org.hibernate.util.StringHelper;
+import org.hibernate.Session;
+import org.hibernate.StatelessSession;
+import org.hibernate.Hibernate;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class StatelessSessionFetchingTest extends FunctionalTestCase {
+ private static final Logger log = LoggerFactory.getLogger( StatelessSessionFetchingTest.class );
+
+ public StatelessSessionFetchingTest(String name) {
+ super( name );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( StatelessSessionFetchingTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "stateless/fetching/Mappings.hbm.xml" };
+ }
+
+ // trying a new thing here in tests with this naming strategy to help alleviate table name clashes
+
+ private class TestingNamingStrategy extends DefaultNamingStrategy {
+ private final String prefix = determineUniquePrefix();
+
+ protected String applyPrefix(String baseTableName) {
+ String prefixed = prefix + '_' + baseTableName;
+ log.debug( "prefixed table name : {} -> {} ", baseTableName, prefixed );
+ return prefixed;
+ }
+
+ @Override
+ public String classToTableName(String className) {
+ return applyPrefix( super.classToTableName( className ) );
+ }
+
+ @Override
+ public String tableName(String tableName) {
+ if ( tableName.startsWith( "`" ) && tableName.endsWith( "`" ) ) {
+ return tableName;
+ }
+ if ( tableName.startsWith( prefix + '_' ) ) {
+ return tableName;
+ }
+ return applyPrefix( tableName );
+ }
+
+ @Override
+ public String collectionTableName(String ownerEntity, String ownerEntityTable, String associatedEntity, String associatedEntityTable, String propertyName) {
+ String tableName = super.collectionTableName( ownerEntity, ownerEntityTable, associatedEntity, associatedEntityTable, propertyName );
+ return applyPrefix( tableName );
+ }
+
+ @Override
+ public String logicalCollectionTableName(String tableName, String ownerEntityTable, String associatedEntityTable, String propertyName) {
+ String resolvedTableName = prefix + '_' + super.logicalCollectionTableName( tableName, ownerEntityTable, associatedEntityTable, propertyName );
+ System.out.println( "Logical collection table name : " + tableName + " -> " + resolvedTableName );
+ return resolvedTableName;
+ }
+
+ private String determineUniquePrefix() {
+ return StringHelper.collapseQualifier( getClass().getName(), false ).toUpperCase();
+ }
+ }
+
+ @Override
+ public void configure(Configuration cfg) {
+ super.configure( cfg );
+ cfg.setNamingStrategy( new TestingNamingStrategy() );
+ }
+
+ public void testDynamicFetch() {
+ Session s = openSession();
+ s.beginTransaction();
+ Date now = new Date();
+ User me = new User( "me" );
+ User you = new User( "you" );
+ Resource yourClock = new Resource( "clock", you );
+ Task task = new Task( me, "clean", yourClock, now ); // :)
+ s.save( me );
+ s.save( you );
+ s.save( yourClock );
+ s.save( task );
+ s.getTransaction().commit();
+ s.close();
+
+ StatelessSession ss = sfi().openStatelessSession();
+ ss.beginTransaction();
+ Task taskRef = ( Task ) ss.createQuery( "from Task t join fetch t.resource join fetch t.user" ).uniqueResult();
+ assertTrue( taskRef != null );
+ assertTrue( Hibernate.isInitialized( taskRef ) );
+ assertTrue( Hibernate.isInitialized( taskRef.getUser() ) );
+ assertTrue( Hibernate.isInitialized( taskRef.getResource() ) );
+ assertFalse( Hibernate.isInitialized( taskRef.getResource().getOwner() ) );
+ ss.getTransaction().commit();
+ ss.close();
+
+ cleanup();
+ }
+
+ private void cleanup() {
+ Session s = openSession();
+ s.beginTransaction();
+ s.createQuery( "delete Task" ).executeUpdate();
+ s.createQuery( "delete Resource" ).executeUpdate();
+ s.createQuery( "delete User" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Task.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Task.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Task.java 2009-03-05 22:12:56 UTC (rev 16091)
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.stateless.fetching;
+
+import java.util.Date;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Task {
+ private Long id;
+ private String description;
+ private User user;
+ private Resource resource;
+ private Date dueDate;
+ private Date startDate;
+ private Date completionDate;
+
+ public Task() {
+ }
+
+ public Task(User user, String description, Resource resource, Date dueDate) {
+ this( user, description, resource, dueDate, null, null );
+ }
+
+ public Task(User user, String description, Resource resource, Date dueDate, Date startDate, Date completionDate) {
+ this.user = user;
+ this.resource = resource;
+ this.description = description;
+ this.dueDate = dueDate;
+ this.startDate = startDate;
+ this.completionDate = completionDate;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public User getUser() {
+ return user;
+ }
+
+ public void setUser(User user) {
+ this.user = user;
+ }
+
+ public Resource getResource() {
+ return resource;
+ }
+
+ public void setResource(Resource resource) {
+ this.resource = resource;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Date getDueDate() {
+ return dueDate;
+ }
+
+ public void setDueDate(Date dueDate) {
+ this.dueDate = dueDate;
+ }
+
+ public Date getStartDate() {
+ return startDate;
+ }
+
+ public void setStartDate(Date startDate) {
+ this.startDate = startDate;
+ }
+
+ public Date getCompletionDate() {
+ return completionDate;
+ }
+
+ public void setCompletionDate(Date completionDate) {
+ this.completionDate = completionDate;
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/User.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/User.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/User.java 2009-03-05 22:12:56 UTC (rev 16091)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.stateless.fetching;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class User {
+ private Long id;
+ private String name;
+
+ public User() {
+ }
+
+ public User(String name) {
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
15 years, 10 months
Hibernate SVN: r16090 - in core/branches/Branch_3_3: testsuite/src/test/java/org/hibernate/test/stateless and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-03-05 16:56:10 -0500 (Thu, 05 Mar 2009)
New Revision: 16090
Added:
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Mappings.hbm.xml
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Resource.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Task.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/User.java
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java
Log:
HHH-3528 - FETCH JOIN query doesn't work in a StatelessSession
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java 2009-03-05 21:51:53 UTC (rev 16089)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java 2009-03-05 21:56:10 UTC (rev 16090)
@@ -1,7 +1,5 @@
/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
@@ -20,7 +18,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.impl;
@@ -263,13 +260,21 @@
boolean eager,
boolean nullable) throws HibernateException {
errorIfClosed();
- EntityPersister persister = getFactory().getEntityPersister(entityName);
+ EntityPersister persister = getFactory().getEntityPersister( entityName );
+ // first, try to load it from the temp PC associated to this SS
+ Object loaded = temporaryPersistenceContext.getEntity( new EntityKey( id, persister, getEntityMode() ) );
+ if ( loaded != null ) {
+ // we found it in the temp PC. Should indicate we are in the midst of processing a result set
+ // containing eager fetches via join fetch
+ return loaded;
+ }
if ( !eager && persister.hasProxy() ) {
- return persister.createProxy(id, this);
+ // if the metadata allowed proxy creation and caller did not request forceful eager loading,
+ // generate a proxy
+ return persister.createProxy( id, this );
}
- Object loaded = temporaryPersistenceContext.getEntity( new EntityKey(id, persister, EntityMode.POJO) );
- //TODO: if not loaded, throw an exception
- return loaded==null ? get( entityName, id ) : loaded;
+ // otherwise immediately materialize it
+ return get( entityName, id );
}
public Iterator iterate(String query, QueryParameters queryParameters) throws HibernateException {
Copied: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Mappings.hbm.xml (from rev 15071, core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/Document.hbm.xml)
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Mappings.hbm.xml (rev 0)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Mappings.hbm.xml 2009-03-05 21:56:10 UTC (rev 16090)
@@ -0,0 +1,56 @@
+<?xml version="1.0"?>
+<!--
+ ~ Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Middleware LLC.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<!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.stateless.fetching">
+
+ <class name="User">
+ <id name="id" type="long">
+ <generator class="increment" />
+ </id>
+ <property name="name" type="string"/>
+ </class>
+
+ <class name="Resource">
+ <id name="id" type="long">
+ <generator class="increment" />
+ </id>
+ <property name="name" type="string"/>
+ <many-to-one name="owner"/>
+ </class>
+
+ <class name="Task">
+ <id name="id" type="long">
+ <generator class="increment" />
+ </id>
+ <property name="description" type="string"/>
+ <many-to-one name="user"/>
+ <many-to-one name="resource"/>
+ <property name="dueDate" type="timestamp"/>
+ <property name="startDate" type="timestamp"/>
+ <property name="completionDate" type="timestamp"/>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Resource.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Resource.java (rev 0)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Resource.java 2009-03-05 21:56:10 UTC (rev 16090)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.stateless.fetching;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Resource {
+ private Long id;
+ private String name;
+ private User owner;
+
+ public Resource() {
+ }
+
+ public Resource(String name, User owner) {
+ this.name = name;
+ this.owner = owner;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public User getOwner() {
+ return owner;
+ }
+
+ public void setOwner(User owner) {
+ this.owner = owner;
+ }
+}
Added: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java (rev 0)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java 2009-03-05 21:56:10 UTC (rev 16090)
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.stateless.fetching;
+
+import java.util.Date;
+
+import junit.framework.Test;
+
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.ImprovedNamingStrategy;
+import org.hibernate.cfg.DefaultNamingStrategy;
+import org.hibernate.util.StringHelper;
+import org.hibernate.Session;
+import org.hibernate.StatelessSession;
+import org.hibernate.Hibernate;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class StatelessSessionFetchingTest extends FunctionalTestCase {
+ public StatelessSessionFetchingTest(String name) {
+ super( name );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( StatelessSessionFetchingTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "stateless/fetching/Mappings.hbm.xml" };
+ }
+
+ // trying a new thing here in tests with this naming strategy to help alleviate table name clashes
+
+ private class TestingNamingStrategy extends DefaultNamingStrategy {
+ private final String prefix = determineUniquePrefix();
+
+ @Override
+ public String classToTableName(String className) {
+ String resolvedTableName = prefix + '_' + super.classToTableName( className );
+ System.out.println( "Entity table name : " + className + " -> " + resolvedTableName );
+ return resolvedTableName;
+ }
+
+ @Override
+ public String tableName(String tableName) {
+ String resolvedTableName = prefix + '_' + super.tableName( tableName );
+ System.out.println( "Qualified table-name : " + tableName + " -> " + resolvedTableName );
+ return resolvedTableName;
+ }
+
+ @Override
+ public String collectionTableName(String ownerEntity, String ownerEntityTable, String associatedEntity, String associatedEntityTable, String propertyName) {
+ String resolvedTableName = prefix + '_' + super.collectionTableName( ownerEntity, ownerEntityTable, associatedEntity, associatedEntityTable, propertyName );
+ System.out.println( "Collection table name : " + ownerEntity + '.' + propertyName + " -> " + resolvedTableName );
+ return resolvedTableName;
+ }
+
+ @Override
+ public String logicalCollectionTableName(String tableName, String ownerEntityTable, String associatedEntityTable, String propertyName) {
+ String resolvedTableName = prefix + '_' + super.logicalCollectionTableName( tableName, ownerEntityTable, associatedEntityTable, propertyName );
+ System.out.println( "Logical collection table name : " + tableName + " -> " + resolvedTableName );
+ return resolvedTableName;
+ }
+
+ private String determineUniquePrefix() {
+ return StringHelper.collapseQualifier( getClass().getName(), false ).toUpperCase();
+ }
+ }
+
+ @Override
+ public void configure(Configuration cfg) {
+ super.configure( cfg );
+ cfg.setNamingStrategy( new TestingNamingStrategy() );
+ }
+
+ public void testDynamicFetch() {
+ Session s = openSession();
+ s.beginTransaction();
+ Date now = new Date();
+ User me = new User( "me" );
+ User you = new User( "you" );
+ Resource yourClock = new Resource( "clock", you );
+ Task task = new Task( me, "clean", yourClock, now ); // :)
+ s.save( me );
+ s.save( you );
+ s.save( yourClock );
+ s.save( task );
+ s.getTransaction().commit();
+ s.close();
+
+ StatelessSession ss = sfi().openStatelessSession();
+ ss.beginTransaction();
+ Task taskRef = ( Task ) ss.createQuery( "from Task t join fetch t.resource join fetch t.user" ).uniqueResult();
+ assertTrue( taskRef != null );
+ assertTrue( Hibernate.isInitialized( taskRef ) );
+ assertTrue( Hibernate.isInitialized( taskRef.getUser() ) );
+ assertTrue( Hibernate.isInitialized( taskRef.getResource() ) );
+ assertFalse( Hibernate.isInitialized( taskRef.getResource().getOwner() ) );
+ ss.getTransaction().commit();
+ ss.close();
+
+ cleanup();
+ }
+
+ private void cleanup() {
+ Session s = openSession();
+ s.beginTransaction();
+ s.createQuery( "delete Task" ).executeUpdate();
+ s.createQuery( "delete Resource" ).executeUpdate();
+ s.createQuery( "delete User" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+}
Added: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Task.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Task.java (rev 0)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/Task.java 2009-03-05 21:56:10 UTC (rev 16090)
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.stateless.fetching;
+
+import java.util.Date;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Task {
+ private Long id;
+ private String description;
+ private User user;
+ private Resource resource;
+ private Date dueDate;
+ private Date startDate;
+ private Date completionDate;
+
+ public Task() {
+ }
+
+ public Task(User user, String description, Resource resource, Date dueDate) {
+ this( user, description, resource, dueDate, null, null );
+ }
+
+ public Task(User user, String description, Resource resource, Date dueDate, Date startDate, Date completionDate) {
+ this.user = user;
+ this.resource = resource;
+ this.description = description;
+ this.dueDate = dueDate;
+ this.startDate = startDate;
+ this.completionDate = completionDate;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public User getUser() {
+ return user;
+ }
+
+ public void setUser(User user) {
+ this.user = user;
+ }
+
+ public Resource getResource() {
+ return resource;
+ }
+
+ public void setResource(Resource resource) {
+ this.resource = resource;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Date getDueDate() {
+ return dueDate;
+ }
+
+ public void setDueDate(Date dueDate) {
+ this.dueDate = dueDate;
+ }
+
+ public Date getStartDate() {
+ return startDate;
+ }
+
+ public void setStartDate(Date startDate) {
+ this.startDate = startDate;
+ }
+
+ public Date getCompletionDate() {
+ return completionDate;
+ }
+
+ public void setCompletionDate(Date completionDate) {
+ this.completionDate = completionDate;
+ }
+}
Added: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/User.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/User.java (rev 0)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/stateless/fetching/User.java 2009-03-05 21:56:10 UTC (rev 16090)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.stateless.fetching;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class User {
+ private Long id;
+ private String name;
+
+ public User() {
+ }
+
+ public User(String name) {
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
15 years, 10 months