Hibernate SVN: r10251 - trunk/Hibernate3/src/org/hibernate/dialect
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-08-11 15:41:36 -0400 (Fri, 11 Aug 2006)
New Revision: 10251
Modified:
trunk/Hibernate3/src/org/hibernate/dialect/SQLServerDialect.java
Log:
utilize combined trim emulation function template from sqlserver dialect
Modified: trunk/Hibernate3/src/org/hibernate/dialect/SQLServerDialect.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/dialect/SQLServerDialect.java 2006-08-11 19:38:25 UTC (rev 10250)
+++ trunk/Hibernate3/src/org/hibernate/dialect/SQLServerDialect.java 2006-08-11 19:41:36 UTC (rev 10251)
@@ -14,6 +14,7 @@
import org.hibernate.dialect.function.SQLFunctionTemplate;
import org.hibernate.dialect.function.StandardSQLFunction;
import org.hibernate.dialect.function.SQLFunction;
+import org.hibernate.dialect.function.AnsiTrimEmulationFunction;
/**
* A dialect for Microsoft SQL Server 2000
@@ -31,10 +32,11 @@
registerFunction( "locate", new StandardSQLFunction("charindex", Hibernate.INTEGER) );
registerFunction( "extract", new SQLFunctionTemplate( Hibernate.INTEGER, "datepart(?1, ?3)" ) );
- registerFunction( "trim", new TrimFunction() );
registerFunction( "mod", new SQLFunctionTemplate( Hibernate.INTEGER, "?1 % ?2" ) );
registerFunction( "bit_length", new SQLFunctionTemplate( Hibernate.INTEGER, "datalength(?1) * 8" ) );
+ registerFunction( "trim", new AnsiTrimEmulationFunction() );
+
registerKeyword("top");
}
@@ -109,133 +111,4 @@
return "select current_timestamp";
}
- /**
- * A SQLServer-specific version of the ANSI-SQL trim function as SQLServer
- * does not support such a thing.
- */
- public static class TrimFunction implements SQLFunction {
- private static final SQLFunction LEADING_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( ?1 )");
- private static final SQLFunction TRAILING_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "rtrim( ?1 )");
- private static final SQLFunction BOTH_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( rtrim( ?1 ) )");
- private static final SQLFunction BOTH_SPACE_TRIM_FROM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( rtrim( ?2 ) )");
-
- private static final SQLFunction LEADING_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "replace( replace( rtrim( replace( replace( ?1, ' ', '${space}$' ), ?2, ' ' ) ), ' ', ?2 ), '${space}$', ' ' )" );
- private static final SQLFunction TRAILING_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "replace( replace( ltrim( replace( replace( ?1, ' ', '${space}$' ), ?2, ' ' ) ), ' ', ?2 ), '${space}$', ' ' )" );
- private static final SQLFunction BOTH_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "replace( replace( ltrim( rtrim( replace( replace( ?1, ' ', '${space}$' ), ?2, ' ' ) ) ), ' ', ?2 ), '${space}$', ' ' )" );
-
- public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
- return Hibernate.STRING;
- }
-
- public boolean hasArguments() {
- return true;
- }
-
- public boolean hasParenthesesIfNoArguments() {
- return false;
- }
-
- public String render(List args, SessionFactoryImplementor factory) throws QueryException {
- // according to both the ANSI-SQL and EJB3 specs, trim can either take
- // exactly one parameter or a variable number of parameters between 1 and 4.
- // from the SQL spec:
- //
- // <trim function> ::=
- // TRIM <left paren> <trim operands> <right paren>
- //
- // <trim operands> ::=
- // [ [ <trim specification> ] [ <trim character> ] FROM ] <trim source>
- //
- // <trim specification> ::=
- // LEADING
- // | TRAILING
- // | BOTH
- //
- // If only <trim specification> is omitted, BOTH is assumed;
- // if <trim character> is omitted, space is assumed
- if ( args.size() == 1 ) {
- // we have the form: trim(trimSource)
- // so we trim leading and trailing spaces
- return BOTH_SPACE_TRIM.render( args, factory );
- }
- else if ( "from".equalsIgnoreCase( ( String ) args.get( 0 ) ) ) {
- // we have the form: trim(from trimSource).
- // This is functionally equivalent to trim(trimSource)
- return BOTH_SPACE_TRIM_FROM.render( args, factory );
- }
- else {
- // otherwise, a trim-specification and/or a trim-character
- // have been specified; we need to decide which options
- // are present and "do the right thing"
- boolean leading = true; // should leading trim-characters be trimmed?
- boolean trailing = true; // should trailing trim-characters be trimmed?
- String trimCharacter = null; // the trim-character
- String trimSource = null; // the trim-source
-
- // potentialTrimCharacterArgIndex = 1 assumes that a
- // trim-specification has been specified. we handle the
- // exception to that explicitly
- int potentialTrimCharacterArgIndex = 1;
- String firstArg = ( String ) args.get( 0 );
- if ( "leading".equalsIgnoreCase( firstArg ) ) {
- trailing = false;
- }
- else if ( "trailing".equalsIgnoreCase( firstArg ) ) {
- leading = false;
- }
- else if ( "both".equalsIgnoreCase( firstArg ) ) {
- }
- else {
- potentialTrimCharacterArgIndex = 0;
- }
-
- String potentialTrimCharacter = ( String ) args.get( potentialTrimCharacterArgIndex );
- if ( "from".equalsIgnoreCase( potentialTrimCharacter ) ) {
- trimCharacter = "' '";
- trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );
- }
- else if ( potentialTrimCharacterArgIndex + 1 >= args.size() ) {
- trimCharacter = "' '";
- trimSource = potentialTrimCharacter;
- }
- else {
- trimCharacter = potentialTrimCharacter;
- if ( "from".equalsIgnoreCase( ( String ) args.get( potentialTrimCharacterArgIndex + 1 ) ) ) {
- trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 2 );
- }
- else {
- trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );
- }
- }
-
- List argsToUse = null;
- argsToUse = new ArrayList();
- argsToUse.add( trimSource );
- argsToUse.add( trimCharacter );
-
- if ( trimCharacter.equals( "' '" ) ) {
- if ( leading && trailing ) {
- return BOTH_SPACE_TRIM.render( argsToUse, factory );
- }
- else if ( leading ) {
- return LEADING_SPACE_TRIM.render( argsToUse, factory );
- }
- else {
- return TRAILING_SPACE_TRIM.render( argsToUse, factory );
- }
- }
- else {
- if ( leading && trailing ) {
- return BOTH_TRIM.render( argsToUse, factory );
- }
- else if ( leading ) {
- return LEADING_TRIM.render( argsToUse, factory );
- }
- else {
- return TRAILING_TRIM.render( argsToUse, factory );
- }
- }
- }
- }
- }
}
17 years, 9 months
Hibernate SVN: r10250 - in branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect: . function
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-08-11 15:38:25 -0400 (Fri, 11 Aug 2006)
New Revision: 10250
Added:
branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/function/AnsiTrimEmulationFunction.java
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/DB2Dialect.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/DerbyDialect.java
Log:
ported fix for HHH-1949 to 3.2 branch
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/DB2Dialect.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/DB2Dialect.java 2006-08-11 19:37:17 UTC (rev 10249)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/DB2Dialect.java 2006-08-11 19:38:25 UTC (rev 10250)
@@ -12,6 +12,7 @@
import org.hibernate.dialect.function.SQLFunctionTemplate;
import org.hibernate.dialect.function.StandardSQLFunction;
import org.hibernate.dialect.function.VarArgsSQLFunction;
+import org.hibernate.dialect.function.AnsiTrimEmulationFunction;
/**
* An SQL dialect for DB2.
@@ -115,9 +116,9 @@
registerFunction( "posstr", new StandardSQLFunction( "posstr", Hibernate.INTEGER ) );
registerFunction( "substring", new StandardSQLFunction( "substr", Hibernate.STRING ) );
- registerFunction( "trim", new SQLFunctionTemplate( Hibernate.INTEGER, "ltrim(rtrim(?1))" ) );
registerFunction( "bit_length", new SQLFunctionTemplate( Hibernate.INTEGER, "length(?1)*8" ) );
-
+ registerFunction( "trim", new AnsiTrimEmulationFunction() );
+
registerFunction( "concat", new VarArgsSQLFunction(Hibernate.STRING, "", "||", "") );
registerFunction( "str", new SQLFunctionTemplate( Hibernate.STRING, "rtrim(char(?1))" ) );
@@ -130,14 +131,14 @@
registerKeyword("first");
registerKeyword("rows");
registerKeyword("only");
-
+
getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, NO_BATCH);
}
public String getLowercaseFunction() {
return "lcase";
}
-
+
public String getAddColumnString() {
return "add column";
}
@@ -198,7 +199,7 @@
}
return pagingSelect.toString();
}*/
-
+
/**
* Render the <tt>rownumber() over ( .... ) as rownumber_,</tt>
* bit, that goes in the select list
@@ -208,25 +209,25 @@
.append("rownumber() over(");
int orderByIndex = sql.toLowerCase().indexOf("order by");
-
+
if ( orderByIndex>0 && !hasDistinct(sql) ) {
rownumber.append( sql.substring(orderByIndex) );
}
-
+
rownumber.append(") as rownumber_,");
-
+
return rownumber.toString();
}
public String getLimitString(String sql, boolean hasOffset) {
-
+
int startOfSelect = sql.toLowerCase().indexOf("select");
-
+
StringBuffer pagingSelect = new StringBuffer( sql.length()+100 )
.append( sql.substring(0, startOfSelect) ) //add the comment
.append("select * from ( select ") //nest the main query in an outer select
.append( getRowNumber(sql) ); //add the rownnumber bit into the outer query select list
-
+
if ( hasDistinct(sql) ) {
pagingSelect.append(" row_.* from ( ") //add another (inner) nested select
.append( sql.substring(startOfSelect) ) //add the main query
@@ -235,9 +236,9 @@
else {
pagingSelect.append( sql.substring( startOfSelect + 6 ) ); //add the main query
}
-
+
pagingSelect.append(" ) as temp_ where rownumber_ ");
-
+
//add the restriction to the outer select
if (hasOffset) {
pagingSelect.append("between ?+1 and ?");
@@ -245,14 +246,14 @@
else {
pagingSelect.append("<= ?");
}
-
+
return pagingSelect.toString();
}
private static boolean hasDistinct(String sql) {
return sql.toLowerCase().indexOf("select distinct")>=0;
}
-
+
public String getForUpdateString() {
return " for read only with rs";
}
@@ -260,11 +261,11 @@
public boolean useMaxForLimit() {
return true;
}
-
+
public boolean supportsOuterJoinForUpdate() {
return false;
}
-
+
public boolean supportsNotNullUnique() {
return false;
}
@@ -290,7 +291,7 @@
}
return "nullif(" + literal + ',' + literal + ')';
}
-
+
public static void main(String[] args) {
System.out.println( new DB2Dialect().getLimitString("/*foo*/ select * from foos", true) );
System.out.println( new DB2Dialect().getLimitString("/*foo*/ select distinct * from foos", true) );
@@ -301,18 +302,18 @@
public boolean supportsUnionAll() {
return true;
}
-
+
public int registerResultSetOutParameter(CallableStatement statement, int col) throws SQLException {
return col;
}
-
+
public ResultSet getResultSet(CallableStatement ps) throws SQLException {
- boolean isResultSet = ps.execute();
+ boolean isResultSet = ps.execute();
// This assumes you will want to ignore any update counts
- while (!isResultSet && ps.getUpdateCount() != -1) {
- isResultSet = ps.getMoreResults();
- }
- ResultSet rs = ps.getResultSet();
+ while (!isResultSet && ps.getUpdateCount() != -1) {
+ isResultSet = ps.getMoreResults();
+ }
+ ResultSet rs = ps.getResultSet();
// You may still have other ResultSets or update counts left to process here
// but you can't do it now or the ResultSet you just got will be closed
return rs;
@@ -321,7 +322,7 @@
public boolean supportsCommentOn() {
return true;
}
-
+
public boolean supportsTemporaryTables() {
return true;
}
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/DerbyDialect.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/DerbyDialect.java 2006-08-11 19:37:17 UTC (rev 10249)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/DerbyDialect.java 2006-08-11 19:38:25 UTC (rev 10250)
@@ -2,11 +2,21 @@
package org.hibernate.dialect;
import org.hibernate.Hibernate;
+import org.hibernate.QueryException;
+import org.hibernate.HibernateException;
+import org.hibernate.engine.Mapping;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.type.Type;
import org.hibernate.dialect.function.VarArgsSQLFunction;
+import org.hibernate.dialect.function.SQLFunction;
+import org.hibernate.dialect.function.SQLFunctionTemplate;
import org.hibernate.id.TableHiLoGenerator;
import org.hibernate.sql.CaseFragment;
import org.hibernate.sql.DerbyCaseFragment;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* @author Simon Johnston
*
@@ -20,6 +30,7 @@
public DerbyDialect() {
super();
registerFunction( "concat", new VarArgsSQLFunction( Hibernate.STRING, "(","||",")" ) );
+ registerFunction( "trim", new DerbyTrimFunctionEmulation() );
}
/**
@@ -36,18 +47,18 @@
return new DerbyCaseFragment();
}
- public boolean dropConstraints() {
- return true;
+ public boolean dropConstraints() {
+ return true;
}
-
+
public Class getNativeIdentifierGeneratorClass() {
return TableHiLoGenerator.class;
}
-
+
public boolean supportsSequences() {
return false;
}
-
+
public boolean supportsLimit() {
return false;
}
@@ -58,5 +69,124 @@
public String getQuerySequencesString() {
return null ;
- }
+ }
+
+ /**
+ * A specialized function template to emulate the ANSI trim function on Derby DB
+ * since it does not support the full trim specification. However, we cannot even
+ * fully emulate it because there is not standard 'replace' function either. :(
+ */
+ public static class DerbyTrimFunctionEmulation implements SQLFunction {
+ private static final SQLFunction LEADING_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( ?1 )");
+ private static final SQLFunction TRAILING_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "rtrim( ?1 )");
+ private static final SQLFunction BOTH_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( rtrim( ?1 ) )");
+ private static final SQLFunction BOTH_SPACE_TRIM_FROM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( rtrim( ?2 ) )");
+
+ public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
+ return Hibernate.STRING;
+ }
+
+ public boolean hasArguments() {
+ return true;
+ }
+
+ public boolean hasParenthesesIfNoArguments() {
+ return false;
+ }
+
+ public String render(List args, SessionFactoryImplementor factory) throws QueryException {
+ // according to both the ANSI-SQL and EJB3 specs, trim can either take
+ // exactly one parameter or a variable number of parameters between 1 and 4.
+ // from the SQL spec:
+ //
+ // <trim function> ::=
+ // TRIM <left paren> <trim operands> <right paren>
+ //
+ // <trim operands> ::=
+ // [ [ <trim specification> ] [ <trim character> ] FROM ] <trim source>
+ //
+ // <trim specification> ::=
+ // LEADING
+ // | TRAILING
+ // | BOTH
+ //
+ // If only <trim specification> is omitted, BOTH is assumed;
+ // if <trim character> is omitted, space is assumed
+ if ( args.size() == 1 ) {
+ // we have the form: trim(trimSource)
+ // so we trim leading and trailing spaces
+ return BOTH_SPACE_TRIM.render( args, factory );
+ }
+ else if ( "from".equalsIgnoreCase( ( String ) args.get( 0 ) ) ) {
+ // we have the form: trim(from trimSource).
+ // This is functionally equivalent to trim(trimSource)
+ return BOTH_SPACE_TRIM_FROM.render( args, factory );
+ }
+ else {
+ // otherwise, a trim-specification and/or a trim-character
+ // have been specified; we need to decide which options
+ // are present and "do the right thing"
+ boolean leading = true; // should leading trim-characters be trimmed?
+ boolean trailing = true; // should trailing trim-characters be trimmed?
+ String trimCharacter = null; // the trim-character
+ String trimSource = null; // the trim-source
+
+ // potentialTrimCharacterArgIndex = 1 assumes that a
+ // trim-specification has been specified. we handle the
+ // exception to that explicitly
+ int potentialTrimCharacterArgIndex = 1;
+ String firstArg = ( String ) args.get( 0 );
+ if ( "leading".equalsIgnoreCase( firstArg ) ) {
+ trailing = false;
+ }
+ else if ( "trailing".equalsIgnoreCase( firstArg ) ) {
+ leading = false;
+ }
+ else if ( "both".equalsIgnoreCase( firstArg ) ) {
+ }
+ else {
+ potentialTrimCharacterArgIndex = 0;
+ }
+
+ String potentialTrimCharacter = ( String ) args.get( potentialTrimCharacterArgIndex );
+ if ( "from".equalsIgnoreCase( potentialTrimCharacter ) ) {
+ trimCharacter = "' '";
+ trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );
+ }
+ else if ( potentialTrimCharacterArgIndex + 1 >= args.size() ) {
+ trimCharacter = "' '";
+ trimSource = potentialTrimCharacter;
+ }
+ else {
+ trimCharacter = potentialTrimCharacter;
+ if ( "from".equalsIgnoreCase( ( String ) args.get( potentialTrimCharacterArgIndex + 1 ) ) ) {
+ trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 2 );
+ }
+ else {
+ trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );
+ }
+ }
+
+ List argsToUse = null;
+ argsToUse = new ArrayList();
+ argsToUse.add( trimSource );
+ argsToUse.add( trimCharacter );
+
+ if ( trimCharacter.equals( "' '" ) ) {
+ if ( leading && trailing ) {
+ return BOTH_SPACE_TRIM.render( argsToUse, factory );
+ }
+ else if ( leading ) {
+ return LEADING_SPACE_TRIM.render( argsToUse, factory );
+ }
+ else {
+ return TRAILING_SPACE_TRIM.render( argsToUse, factory );
+ }
+ }
+ else {
+ throw new HibernateException( "cannot specify trim character when using Derby as Derby does not support the ANSI trim function, not does it support a replace function to properly emmulate it" );
+ }
+ }
+ }
+ }
}
Added: branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/function/AnsiTrimEmulationFunction.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/function/AnsiTrimEmulationFunction.java 2006-08-11 19:37:17 UTC (rev 10249)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/function/AnsiTrimEmulationFunction.java 2006-08-11 19:38:25 UTC (rev 10250)
@@ -0,0 +1,146 @@
+package org.hibernate.dialect.function;
+
+import org.hibernate.Hibernate;
+import org.hibernate.QueryException;
+import org.hibernate.engine.Mapping;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.type.Type;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * A {@link SQLFunction} implementation that emulates the ANSI SQL trim function
+ * on dialects which do not support the full definition. However, this function
+ * definition does assume the availability of ltrim, rtrim, and replace functions
+ * which it uses in various combinations to emulate the desired ANSI trim()
+ * functionality.
+ *
+ * @author Steve Ebersole
+ */
+public class AnsiTrimEmulationFunction implements SQLFunction {
+
+ private static final SQLFunction LEADING_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( ?1 )");
+ private static final SQLFunction TRAILING_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "rtrim( ?1 )");
+ private static final SQLFunction BOTH_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( rtrim( ?1 ) )");
+ private static final SQLFunction BOTH_SPACE_TRIM_FROM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( rtrim( ?2 ) )");
+
+ private static final SQLFunction LEADING_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "replace( replace( rtrim( replace( replace( ?1, ' ', '${space}$' ), ?2, ' ' ) ), ' ', ?2 ), '${space}$', ' ' )" );
+ private static final SQLFunction TRAILING_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "replace( replace( ltrim( replace( replace( ?1, ' ', '${space}$' ), ?2, ' ' ) ), ' ', ?2 ), '${space}$', ' ' )" );
+ private static final SQLFunction BOTH_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "replace( replace( ltrim( rtrim( replace( replace( ?1, ' ', '${space}$' ), ?2, ' ' ) ) ), ' ', ?2 ), '${space}$', ' ' )" );
+
+ public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
+ return Hibernate.STRING;
+ }
+
+ public boolean hasArguments() {
+ return true;
+ }
+
+ public boolean hasParenthesesIfNoArguments() {
+ return false;
+ }
+
+ public String render(List args, SessionFactoryImplementor factory) throws QueryException {
+ // according to both the ANSI-SQL and EJB3 specs, trim can either take
+ // exactly one parameter or a variable number of parameters between 1 and 4.
+ // from the SQL spec:
+ //
+ // <trim function> ::=
+ // TRIM <left paren> <trim operands> <right paren>
+ //
+ // <trim operands> ::=
+ // [ [ <trim specification> ] [ <trim character> ] FROM ] <trim source>
+ //
+ // <trim specification> ::=
+ // LEADING
+ // | TRAILING
+ // | BOTH
+ //
+ // If only <trim specification> is omitted, BOTH is assumed;
+ // if <trim character> is omitted, space is assumed
+ if ( args.size() == 1 ) {
+ // we have the form: trim(trimSource)
+ // so we trim leading and trailing spaces
+ return BOTH_SPACE_TRIM.render( args, factory );
+ }
+ else if ( "from".equalsIgnoreCase( ( String ) args.get( 0 ) ) ) {
+ // we have the form: trim(from trimSource).
+ // This is functionally equivalent to trim(trimSource)
+ return BOTH_SPACE_TRIM_FROM.render( args, factory );
+ }
+ else {
+ // otherwise, a trim-specification and/or a trim-character
+ // have been specified; we need to decide which options
+ // are present and "do the right thing"
+ boolean leading = true; // should leading trim-characters be trimmed?
+ boolean trailing = true; // should trailing trim-characters be trimmed?
+ String trimCharacter = null; // the trim-character
+ String trimSource = null; // the trim-source
+
+ // potentialTrimCharacterArgIndex = 1 assumes that a
+ // trim-specification has been specified. we handle the
+ // exception to that explicitly
+ int potentialTrimCharacterArgIndex = 1;
+ String firstArg = ( String ) args.get( 0 );
+ if ( "leading".equalsIgnoreCase( firstArg ) ) {
+ trailing = false;
+ }
+ else if ( "trailing".equalsIgnoreCase( firstArg ) ) {
+ leading = false;
+ }
+ else if ( "both".equalsIgnoreCase( firstArg ) ) {
+ }
+ else {
+ potentialTrimCharacterArgIndex = 0;
+ }
+
+ String potentialTrimCharacter = ( String ) args.get( potentialTrimCharacterArgIndex );
+ if ( "from".equalsIgnoreCase( potentialTrimCharacter ) ) {
+ trimCharacter = "' '";
+ trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );
+ }
+ else if ( potentialTrimCharacterArgIndex + 1 >= args.size() ) {
+ trimCharacter = "' '";
+ trimSource = potentialTrimCharacter;
+ }
+ else {
+ trimCharacter = potentialTrimCharacter;
+ if ( "from".equalsIgnoreCase( ( String ) args.get( potentialTrimCharacterArgIndex + 1 ) ) ) {
+ trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 2 );
+ }
+ else {
+ trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );
+ }
+ }
+
+ List argsToUse = null;
+ argsToUse = new ArrayList();
+ argsToUse.add( trimSource );
+ argsToUse.add( trimCharacter );
+
+ if ( trimCharacter.equals( "' '" ) ) {
+ if ( leading && trailing ) {
+ return BOTH_SPACE_TRIM.render( argsToUse, factory );
+ }
+ else if ( leading ) {
+ return LEADING_SPACE_TRIM.render( argsToUse, factory );
+ }
+ else {
+ return TRAILING_SPACE_TRIM.render( argsToUse, factory );
+ }
+ }
+ else {
+ if ( leading && trailing ) {
+ return BOTH_TRIM.render( argsToUse, factory );
+ }
+ else if ( leading ) {
+ return LEADING_TRIM.render( argsToUse, factory );
+ }
+ else {
+ return TRAILING_TRIM.render( argsToUse, factory );
+ }
+ }
+ }
+ }
+}
17 years, 9 months
Hibernate SVN: r10249 - in trunk/Hibernate3/src/org/hibernate/dialect: . function
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-08-11 15:37:17 -0400 (Fri, 11 Aug 2006)
New Revision: 10249
Added:
trunk/Hibernate3/src/org/hibernate/dialect/function/AnsiTrimEmulationFunction.java
Modified:
trunk/Hibernate3/src/org/hibernate/dialect/DB2Dialect.java
Log:
HHH-1949 : ANSI SQL trim() function on DB2 and friends
Modified: trunk/Hibernate3/src/org/hibernate/dialect/DB2Dialect.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/dialect/DB2Dialect.java 2006-08-11 18:50:44 UTC (rev 10248)
+++ trunk/Hibernate3/src/org/hibernate/dialect/DB2Dialect.java 2006-08-11 19:37:17 UTC (rev 10249)
@@ -12,6 +12,7 @@
import org.hibernate.dialect.function.SQLFunctionTemplate;
import org.hibernate.dialect.function.StandardSQLFunction;
import org.hibernate.dialect.function.VarArgsSQLFunction;
+import org.hibernate.dialect.function.AnsiTrimEmulationFunction;
/**
* An SQL dialect for DB2.
@@ -115,9 +116,9 @@
registerFunction( "posstr", new StandardSQLFunction( "posstr", Hibernate.INTEGER ) );
registerFunction( "substring", new StandardSQLFunction( "substr", Hibernate.STRING ) );
- registerFunction( "trim", new SQLFunctionTemplate( Hibernate.INTEGER, "ltrim(rtrim(?1))" ) );
registerFunction( "bit_length", new SQLFunctionTemplate( Hibernate.INTEGER, "length(?1)*8" ) );
-
+ registerFunction( "trim", new AnsiTrimEmulationFunction() );
+
registerFunction( "concat", new VarArgsSQLFunction(Hibernate.STRING, "", "||", "") );
registerFunction( "str", new SQLFunctionTemplate( Hibernate.STRING, "rtrim(char(?1))" ) );
@@ -130,14 +131,14 @@
registerKeyword("first");
registerKeyword("rows");
registerKeyword("only");
-
+
getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, NO_BATCH);
}
public String getLowercaseFunction() {
return "lcase";
}
-
+
public String getAddColumnString() {
return "add column";
}
@@ -198,7 +199,7 @@
}
return pagingSelect.toString();
}*/
-
+
/**
* Render the <tt>rownumber() over ( .... ) as rownumber_,</tt>
* bit, that goes in the select list
@@ -208,25 +209,25 @@
.append("rownumber() over(");
int orderByIndex = sql.toLowerCase().indexOf("order by");
-
+
if ( orderByIndex>0 && !hasDistinct(sql) ) {
rownumber.append( sql.substring(orderByIndex) );
}
-
+
rownumber.append(") as rownumber_,");
-
+
return rownumber.toString();
}
public String getLimitString(String sql, boolean hasOffset) {
-
+
int startOfSelect = sql.toLowerCase().indexOf("select");
-
+
StringBuffer pagingSelect = new StringBuffer( sql.length()+100 )
.append( sql.substring(0, startOfSelect) ) //add the comment
.append("select * from ( select ") //nest the main query in an outer select
.append( getRowNumber(sql) ); //add the rownnumber bit into the outer query select list
-
+
if ( hasDistinct(sql) ) {
pagingSelect.append(" row_.* from ( ") //add another (inner) nested select
.append( sql.substring(startOfSelect) ) //add the main query
@@ -235,9 +236,9 @@
else {
pagingSelect.append( sql.substring( startOfSelect + 6 ) ); //add the main query
}
-
+
pagingSelect.append(" ) as temp_ where rownumber_ ");
-
+
//add the restriction to the outer select
if (hasOffset) {
pagingSelect.append("between ?+1 and ?");
@@ -245,14 +246,14 @@
else {
pagingSelect.append("<= ?");
}
-
+
return pagingSelect.toString();
}
private static boolean hasDistinct(String sql) {
return sql.toLowerCase().indexOf("select distinct")>=0;
}
-
+
public String getForUpdateString() {
return " for read only with rs";
}
@@ -260,11 +261,11 @@
public boolean useMaxForLimit() {
return true;
}
-
+
public boolean supportsOuterJoinForUpdate() {
return false;
}
-
+
public boolean supportsNotNullUnique() {
return false;
}
@@ -290,7 +291,7 @@
}
return "nullif(" + literal + ',' + literal + ')';
}
-
+
public static void main(String[] args) {
System.out.println( new DB2Dialect().getLimitString("/*foo*/ select * from foos", true) );
System.out.println( new DB2Dialect().getLimitString("/*foo*/ select distinct * from foos", true) );
@@ -301,18 +302,18 @@
public boolean supportsUnionAll() {
return true;
}
-
+
public int registerResultSetOutParameter(CallableStatement statement, int col) throws SQLException {
return col;
}
-
+
public ResultSet getResultSet(CallableStatement ps) throws SQLException {
- boolean isResultSet = ps.execute();
+ boolean isResultSet = ps.execute();
// This assumes you will want to ignore any update counts
- while (!isResultSet && ps.getUpdateCount() != -1) {
- isResultSet = ps.getMoreResults();
- }
- ResultSet rs = ps.getResultSet();
+ while (!isResultSet && ps.getUpdateCount() != -1) {
+ isResultSet = ps.getMoreResults();
+ }
+ ResultSet rs = ps.getResultSet();
// You may still have other ResultSets or update counts left to process here
// but you can't do it now or the ResultSet you just got will be closed
return rs;
@@ -321,7 +322,7 @@
public boolean supportsCommentOn() {
return true;
}
-
+
public boolean supportsTemporaryTables() {
return true;
}
Added: trunk/Hibernate3/src/org/hibernate/dialect/function/AnsiTrimEmulationFunction.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/dialect/function/AnsiTrimEmulationFunction.java 2006-08-11 18:50:44 UTC (rev 10248)
+++ trunk/Hibernate3/src/org/hibernate/dialect/function/AnsiTrimEmulationFunction.java 2006-08-11 19:37:17 UTC (rev 10249)
@@ -0,0 +1,146 @@
+package org.hibernate.dialect.function;
+
+import org.hibernate.Hibernate;
+import org.hibernate.QueryException;
+import org.hibernate.engine.Mapping;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.type.Type;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * A {@link SQLFunction} implementation that emulates the ANSI SQL trim function
+ * on dialects which do not support the full definition. However, this function
+ * definition does assume the availability of ltrim, rtrim, and replace functions
+ * which it uses in various combinations to emulate the desired ANSI trim()
+ * functionality.
+ *
+ * @author Steve Ebersole
+ */
+public class AnsiTrimEmulationFunction implements SQLFunction {
+
+ private static final SQLFunction LEADING_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( ?1 )");
+ private static final SQLFunction TRAILING_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "rtrim( ?1 )");
+ private static final SQLFunction BOTH_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( rtrim( ?1 ) )");
+ private static final SQLFunction BOTH_SPACE_TRIM_FROM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( rtrim( ?2 ) )");
+
+ private static final SQLFunction LEADING_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "replace( replace( rtrim( replace( replace( ?1, ' ', '${space}$' ), ?2, ' ' ) ), ' ', ?2 ), '${space}$', ' ' )" );
+ private static final SQLFunction TRAILING_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "replace( replace( ltrim( replace( replace( ?1, ' ', '${space}$' ), ?2, ' ' ) ), ' ', ?2 ), '${space}$', ' ' )" );
+ private static final SQLFunction BOTH_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "replace( replace( ltrim( rtrim( replace( replace( ?1, ' ', '${space}$' ), ?2, ' ' ) ) ), ' ', ?2 ), '${space}$', ' ' )" );
+
+ public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
+ return Hibernate.STRING;
+ }
+
+ public boolean hasArguments() {
+ return true;
+ }
+
+ public boolean hasParenthesesIfNoArguments() {
+ return false;
+ }
+
+ public String render(List args, SessionFactoryImplementor factory) throws QueryException {
+ // according to both the ANSI-SQL and EJB3 specs, trim can either take
+ // exactly one parameter or a variable number of parameters between 1 and 4.
+ // from the SQL spec:
+ //
+ // <trim function> ::=
+ // TRIM <left paren> <trim operands> <right paren>
+ //
+ // <trim operands> ::=
+ // [ [ <trim specification> ] [ <trim character> ] FROM ] <trim source>
+ //
+ // <trim specification> ::=
+ // LEADING
+ // | TRAILING
+ // | BOTH
+ //
+ // If only <trim specification> is omitted, BOTH is assumed;
+ // if <trim character> is omitted, space is assumed
+ if ( args.size() == 1 ) {
+ // we have the form: trim(trimSource)
+ // so we trim leading and trailing spaces
+ return BOTH_SPACE_TRIM.render( args, factory );
+ }
+ else if ( "from".equalsIgnoreCase( ( String ) args.get( 0 ) ) ) {
+ // we have the form: trim(from trimSource).
+ // This is functionally equivalent to trim(trimSource)
+ return BOTH_SPACE_TRIM_FROM.render( args, factory );
+ }
+ else {
+ // otherwise, a trim-specification and/or a trim-character
+ // have been specified; we need to decide which options
+ // are present and "do the right thing"
+ boolean leading = true; // should leading trim-characters be trimmed?
+ boolean trailing = true; // should trailing trim-characters be trimmed?
+ String trimCharacter = null; // the trim-character
+ String trimSource = null; // the trim-source
+
+ // potentialTrimCharacterArgIndex = 1 assumes that a
+ // trim-specification has been specified. we handle the
+ // exception to that explicitly
+ int potentialTrimCharacterArgIndex = 1;
+ String firstArg = ( String ) args.get( 0 );
+ if ( "leading".equalsIgnoreCase( firstArg ) ) {
+ trailing = false;
+ }
+ else if ( "trailing".equalsIgnoreCase( firstArg ) ) {
+ leading = false;
+ }
+ else if ( "both".equalsIgnoreCase( firstArg ) ) {
+ }
+ else {
+ potentialTrimCharacterArgIndex = 0;
+ }
+
+ String potentialTrimCharacter = ( String ) args.get( potentialTrimCharacterArgIndex );
+ if ( "from".equalsIgnoreCase( potentialTrimCharacter ) ) {
+ trimCharacter = "' '";
+ trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );
+ }
+ else if ( potentialTrimCharacterArgIndex + 1 >= args.size() ) {
+ trimCharacter = "' '";
+ trimSource = potentialTrimCharacter;
+ }
+ else {
+ trimCharacter = potentialTrimCharacter;
+ if ( "from".equalsIgnoreCase( ( String ) args.get( potentialTrimCharacterArgIndex + 1 ) ) ) {
+ trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 2 );
+ }
+ else {
+ trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );
+ }
+ }
+
+ List argsToUse = null;
+ argsToUse = new ArrayList();
+ argsToUse.add( trimSource );
+ argsToUse.add( trimCharacter );
+
+ if ( trimCharacter.equals( "' '" ) ) {
+ if ( leading && trailing ) {
+ return BOTH_SPACE_TRIM.render( argsToUse, factory );
+ }
+ else if ( leading ) {
+ return LEADING_SPACE_TRIM.render( argsToUse, factory );
+ }
+ else {
+ return TRAILING_SPACE_TRIM.render( argsToUse, factory );
+ }
+ }
+ else {
+ if ( leading && trailing ) {
+ return BOTH_TRIM.render( argsToUse, factory );
+ }
+ else if ( leading ) {
+ return LEADING_TRIM.render( argsToUse, factory );
+ }
+ else {
+ return TRAILING_TRIM.render( argsToUse, factory );
+ }
+ }
+ }
+ }
+}
17 years, 9 months
Hibernate SVN: r10248 - in branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument: . buildtime cases domain runtime
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-08-11 14:50:44 -0400 (Fri, 11 Aug 2006)
New Revision: 10248
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/AbstractExecutable.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/Executable.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestDirtyCheckExecutable.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestFetchAllExecutable.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestInjectFieldInterceptorExecutable.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestIsPropertyInitializedExecutable.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyExecutable.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyManyToOneExecutable.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestManyToOneProxyExecutable.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/domain/Entity.java
Removed:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractExecutable.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/Executable.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestDirtyCheckExecutable.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestFetchAllExecutable.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestInjectFieldInterceptorExecutable.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestIsPropertyInitializedExecutable.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyExecutable.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyManyToOneExecutable.java
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/buildtime/InstrumentTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/domain/Documents.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractTransformingClassLoaderInstrumentTestCase.java
Log:
ported fix for HHH-1740 to 3.2 branch
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/buildtime/InstrumentTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/buildtime/InstrumentTest.java 2006-08-11 18:49:33 UTC (rev 10247)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/buildtime/InstrumentTest.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -1,25 +1,25 @@
//$Id$
package org.hibernate.test.instrument.buildtime;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Iterator;
-
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.hibernate.Hibernate;
-import org.hibernate.LockMode;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
import org.hibernate.intercept.FieldInterceptionHelper;
import org.hibernate.test.TestCase;
-import org.hibernate.test.instrument.domain.Owner;
import org.hibernate.test.instrument.domain.Document;
-import org.hibernate.test.instrument.domain.Folder;
+import org.hibernate.test.instrument.cases.TestDirtyCheckExecutable;
+import org.hibernate.test.instrument.cases.TestFetchAllExecutable;
+import org.hibernate.test.instrument.cases.TestLazyExecutable;
+import org.hibernate.test.instrument.cases.TestLazyManyToOneExecutable;
+import org.hibernate.test.instrument.cases.TestInjectFieldInterceptorExecutable;
+import org.hibernate.test.instrument.cases.TestIsPropertyInitializedExecutable;
+import org.hibernate.test.instrument.cases.TestManyToOneProxyExecutable;
/**
+ * Tests for build-time instrumentation
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
public class InstrumentTest extends TestCase {
@@ -28,311 +28,46 @@
}
public void testDirtyCheck() {
- if ( !isRunnable() ) {
- return;
- }
- Session s = openSession();
- Transaction t = s.beginTransaction();
- Folder pics = new Folder();
- pics.setName("pics");
- Folder docs = new Folder();
- docs.setName("docs");
- s.persist(docs);
- s.persist(pics);
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- List list = s.createCriteria(Folder.class).list();
- for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
- Folder f = (Folder) iter.next();
- assertFalse( f.nameWasread );
- }
- t.commit();
- s.close();
-
- for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
- Folder f = (Folder) iter.next();
- assertFalse( f.nameWasread );
- }
-
- s = openSession();
- t = s.beginTransaction();
- s.createQuery("delete from Folder").executeUpdate();
- t.commit();
- s.close();
+ new TestDirtyCheckExecutable().execute();
}
public void testFetchAll() throws Exception {
- if ( !isRunnable() ) {
- return;
- }
- Session s = openSession();
- Owner o = new Owner();
- Document doc = new Document();
- Folder fol = new Folder();
- o.setName("gavin");
- doc.setName("Hibernate in Action");
- doc.setSummary("blah");
- doc.updateText("blah blah");
- fol.setName("books");
- doc.setOwner(o);
- doc.setFolder(fol);
- fol.getDocuments().add(doc);
- s.persist(o);
- s.persist(fol);
- s.flush();
- s.clear();
- doc = (Document) s.createQuery("from Document fetch all properties").uniqueResult();
- assertTrue( Hibernate.isPropertyInitialized( doc, "summary" ) );
- assertTrue( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );
- assertTrue( Hibernate.isPropertyInitialized( doc, "owner" ) );
- assertEquals( doc.getSummary(), "blah" );
- s.delete(doc);
- s.delete( doc.getOwner() );
- s.delete( doc.getFolder() );
- s.flush();
- s.connection().commit();
- s.close();
+ new TestFetchAllExecutable().execute();
}
public void testLazy() throws Exception {
- if ( !isRunnable() ) {
- return;
- }
- Session s = openSession();
- Transaction t = s.beginTransaction();
- Owner o = new Owner();
- Document doc = new Document();
- Folder fol = new Folder();
- o.setName("gavin");
- doc.setName("Hibernate in Action");
- doc.setSummary("blah");
- doc.updateText("blah blah");
- fol.setName("books");
- doc.setOwner(o);
- doc.setFolder(fol);
- fol.getDocuments().add(doc);
- s.save(o);
- s.save(fol);
- t.commit();
- s.close();
-
- getSessions().evict(Document.class);
-
- s = openSession();
- t = s.beginTransaction();
- doc = ( Document ) s.get( Document.class, doc.getId() );
- assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
- assertTrue(Hibernate.isPropertyInitialized(doc, "name"));
- assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- assertFalse(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
- assertFalse(Hibernate.isPropertyInitialized(doc, "folder"));
- assertFalse(Hibernate.isPropertyInitialized(doc, "owner"));
- doc.getUpperCaseName(); // should force initialization
- assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
- assertTrue(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
- assertTrue(Hibernate.isPropertyInitialized(doc, "folder"));
- assertTrue(Hibernate.isPropertyInitialized(doc, "owner"));
- t.commit();
- s.close();
-
- getSessions().evict(Document.class);
-
- s = openSession();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- doc.getName();
- assertEquals( doc.getText(), "blah blah" );
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- doc.getName();
- assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- assertFalse(Hibernate.isPropertyInitialized(doc, "summary"));
- assertEquals( doc.getText(), "blah blah" );
- assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- assertTrue(Hibernate.isPropertyInitialized(doc, "summary"));
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = ( Document ) s.createQuery("from Document").uniqueResult();
- doc.setName("HiA");
- s.flush();
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- assertEquals( doc.getName(), "HiA" );
- assertEquals( doc.getText(), "blah blah" );
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- doc.getText();
- doc.setName("HiA second edition");
- s.flush();
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
- assertTrue(Hibernate.isPropertyInitialized(doc, "name"));
- assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- assertFalse(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
- assertFalse(Hibernate.isPropertyInitialized(doc, "owner"));
- assertEquals( doc.getName(), "HiA second edition" );
- assertEquals( doc.getText(), "blah blah" );
- assertEquals( doc.getUpperCaseName(), "HIA SECOND EDITION" );
- assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
- assertTrue(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- s.connection().commit();
- s.close();
-
- assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
-
- s = openSession();
- s.lock(doc, LockMode.NONE);
- assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- assertEquals( doc.getText(), "blah blah" );
- assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- s.connection().commit();
- s.close();
-
- doc.setName("HiA2");
-
- assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
-
- s = openSession();
- s.saveOrUpdate(doc);
- s.flush();
- assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- assertEquals( doc.getText(), "blah blah" );
- assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- doc.updateText("blah blah blah blah");
- s.flush();
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- assertEquals( doc.getName(), "HiA2" );
- assertEquals( doc.getText(), "blah blah blah blah" );
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = (Document) s.load( Document.class, doc.getId() );
- doc.getName();
- assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- assertFalse(Hibernate.isPropertyInitialized(doc, "summary"));
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- //s.delete(doc);
- s.delete( doc.getFolder() );
- s.delete( doc.getOwner() );
- s.flush();
- s.connection().commit();
- s.close();
-
+ new TestLazyExecutable().execute();
}
public void testLazyManyToOne() {
- if ( !isRunnable() ) {
- return;
- }
- Session s = openSession();
- Transaction t = s.beginTransaction();
- Owner gavin = new Owner();
- Document hia = new Document();
- Folder fol = new Folder();
- gavin.setName("gavin");
- hia.setName("Hibernate in Action");
- hia.setSummary("blah");
- hia.updateText("blah blah");
- fol.setName("books");
- hia.setOwner(gavin);
- hia.setFolder(fol);
- fol.getDocuments().add(hia);
- s.persist(gavin);
- s.persist(fol);
- t.commit();
- s.close();
+ new TestLazyManyToOneExecutable().execute();
+ }
- s = openSession();
- t = s.beginTransaction();
- hia = (Document) s.createCriteria(Document.class).uniqueResult();
- assertEquals( hia.getFolder().getClass(), Folder.class);
- fol = hia.getFolder();
- assertTrue( Hibernate.isInitialized(fol) );
- t.commit();
- s.close();
+ public void testSetFieldInterceptor() {
+ new TestInjectFieldInterceptorExecutable().execute();
+ }
- s = openSession();
- t = s.beginTransaction();
- hia = (Document) s.createCriteria(Document.class).uniqueResult();
- assertSame( hia.getFolder(), s.load(Folder.class, fol.getId()) );
- assertTrue( Hibernate.isInitialized( hia.getFolder() ) );
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- fol = (Folder) s.get(Folder.class, fol.getId());
- hia = (Document) s.createCriteria(Document.class).uniqueResult();
- assertSame( fol, hia.getFolder() );
- fol = hia.getFolder();
- assertTrue( Hibernate.isInitialized(fol) );
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- fol = (Folder) s.load(Folder.class, fol.getId());
- hia = (Document) s.createCriteria(Document.class).uniqueResult();
- assertNotSame( fol, hia.getFolder() );
- fol = hia.getFolder();
- assertTrue( Hibernate.isInitialized(fol) );
- s.delete(hia.getFolder());
- s.delete(hia.getOwner());
- t.commit();
- s.close();
+ public void testPropertyInitialized() {
+ new TestIsPropertyInitializedExecutable().execute();
}
- public void testSetFieldInterceptor() {
- if ( !isRunnable() ) {
- return;
- }
- Document doc = new Document();
- FieldInterceptionHelper.injectFieldInterceptor( doc, "Document", new HashSet(), null );
- doc.getId();
+ public void testManyToOneProxy() {
+ new TestManyToOneProxyExecutable().execute();
}
protected String[] getMappings() {
return new String[] { "instrument/domain/Documents.hbm.xml" };
}
+ protected void runTest() throws Throwable {
+ if ( isRunnable() ) {
+ super.runTest();
+ }
+ else {
+ reportSkip( "domain classes not instrumented", "build-time instrumentation" );
+ }
+ }
+
public static Test suite() {
return new TestSuite(InstrumentTest.class);
}
@@ -340,5 +75,4 @@
public static boolean isRunnable() {
return FieldInterceptionHelper.isInstrumented( new Document() );
}
-}
-
+}
\ No newline at end of file
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/AbstractExecutable.java (from rev 10159, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractExecutable.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractExecutable.java 2006-07-26 13:36:20 UTC (rev 10159)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/AbstractExecutable.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -0,0 +1,28 @@
+package org.hibernate.test.instrument.cases;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+
+/**
+ * @author Steve Ebersole
+ */
+public abstract class AbstractExecutable implements Executable {
+
+ private SessionFactory factory;
+
+ public void prepare() {
+ factory = new Configuration()
+ .setProperty( Environment.HBM2DDL_AUTO, "create-drop" )
+ .addResource( "org/hibernate/test/instrument/domain/Documents.hbm.xml" )
+ .buildSessionFactory();
+ }
+
+ public void complete() {
+ factory.close();
+ }
+
+ protected SessionFactory getFactory() {
+ return factory;
+ }
+}
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/Executable.java (from rev 10159, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/Executable.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/Executable.java 2006-07-26 13:36:20 UTC (rev 10159)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/Executable.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -0,0 +1,10 @@
+package org.hibernate.test.instrument.cases;
+
+/**
+ * @author Steve Ebersole
+ */
+public interface Executable {
+ public void prepare();
+ public void execute();
+ public void complete();
+}
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestDirtyCheckExecutable.java (from rev 10159, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestDirtyCheckExecutable.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestDirtyCheckExecutable.java 2006-07-26 13:36:20 UTC (rev 10159)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestDirtyCheckExecutable.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -0,0 +1,50 @@
+package org.hibernate.test.instrument.cases;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.test.instrument.cases.AbstractExecutable;
+import org.hibernate.test.instrument.domain.Folder;
+
+import java.util.List;
+import java.util.Iterator;
+
+import junit.framework.Assert;
+
+/**
+ * @author Steve Ebersole
+ */
+public class TestDirtyCheckExecutable extends AbstractExecutable {
+ public void execute() {
+ Session s = getFactory().openSession();
+ Transaction t = s.beginTransaction();
+ Folder pics = new Folder();
+ pics.setName("pics");
+ Folder docs = new Folder();
+ docs.setName("docs");
+ s.persist(docs);
+ s.persist(pics);
+ t.commit();
+ s.close();
+
+ s = getFactory().openSession();
+ t = s.beginTransaction();
+ List list = s.createCriteria(Folder.class).list();
+ for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
+ Folder f = (Folder) iter.next();
+ Assert.assertFalse( f.nameWasread );
+ }
+ t.commit();
+ s.close();
+
+ for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
+ Folder f = (Folder) iter.next();
+ Assert.assertFalse( f.nameWasread );
+ }
+
+ s = getFactory().openSession();
+ t = s.beginTransaction();
+ s.createQuery("delete from Folder").executeUpdate();
+ t.commit();
+ s.close();
+ }
+}
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestFetchAllExecutable.java (from rev 10159, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestFetchAllExecutable.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestFetchAllExecutable.java 2006-07-26 13:36:20 UTC (rev 10159)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestFetchAllExecutable.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -0,0 +1,48 @@
+package org.hibernate.test.instrument.cases;
+
+import org.hibernate.Session;
+import org.hibernate.Hibernate;
+import org.hibernate.Transaction;
+import org.hibernate.test.instrument.domain.Owner;
+import org.hibernate.test.instrument.domain.Document;
+import org.hibernate.test.instrument.domain.Folder;
+import org.hibernate.test.instrument.cases.AbstractExecutable;
+import junit.framework.Assert;
+
+/**
+ * @author Steve Ebersole
+ */
+public class TestFetchAllExecutable extends AbstractExecutable {
+ public void execute() {
+ Session s = getFactory().openSession();
+ Transaction t = s.beginTransaction();
+ Owner o = new Owner();
+ Document doc = new Document();
+ Folder fol = new Folder();
+ o.setName("gavin");
+ doc.setName("Hibernate in Action");
+ doc.setSummary("blah");
+ doc.updateText("blah blah");
+ fol.setName("books");
+ doc.setOwner(o);
+ doc.setFolder(fol);
+ fol.getDocuments().add(doc);
+ s.persist(o);
+ s.persist(fol);
+ t.commit();
+ s.close();
+
+ s = getFactory().openSession();
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document fetch all properties").uniqueResult();
+ Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "summary" ) );
+ Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );
+ Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "owner" ) );
+ Assert.assertEquals( doc.getSummary(), "blah" );
+ s.delete(doc);
+ s.delete( doc.getOwner() );
+ s.delete( doc.getFolder() );
+ t.commit();
+ s.close();
+ }
+}
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestInjectFieldInterceptorExecutable.java (from rev 10159, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestInjectFieldInterceptorExecutable.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestInjectFieldInterceptorExecutable.java 2006-07-26 13:36:20 UTC (rev 10159)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestInjectFieldInterceptorExecutable.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -0,0 +1,18 @@
+package org.hibernate.test.instrument.cases;
+
+import org.hibernate.test.instrument.domain.Document;
+import org.hibernate.test.instrument.cases.AbstractExecutable;
+import org.hibernate.intercept.FieldInterceptionHelper;
+
+import java.util.HashSet;
+
+/**
+ * @author Steve Ebersole
+ */
+public class TestInjectFieldInterceptorExecutable extends AbstractExecutable {
+ public void execute() {
+ Document doc = new Document();
+ FieldInterceptionHelper.injectFieldInterceptor( doc, "Document", new HashSet(), null );
+ doc.getId();
+ }
+}
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestIsPropertyInitializedExecutable.java (from rev 10159, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestIsPropertyInitializedExecutable.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestIsPropertyInitializedExecutable.java 2006-07-26 13:36:20 UTC (rev 10159)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestIsPropertyInitializedExecutable.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -0,0 +1,49 @@
+//$Id: $
+package org.hibernate.test.instrument.cases;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.Hibernate;
+import org.hibernate.test.instrument.domain.Owner;
+import org.hibernate.test.instrument.domain.Document;
+import org.hibernate.test.instrument.domain.Folder;
+import org.hibernate.test.instrument.cases.AbstractExecutable;
+import junit.framework.Assert;
+
+/**
+ * @author Steve Ebersole
+ */
+public class TestIsPropertyInitializedExecutable extends AbstractExecutable {
+ public void execute() {
+ Session s = getFactory().openSession();
+ Transaction t = s.beginTransaction();
+ Owner o = new Owner();
+ Document doc = new Document();
+ Folder fol = new Folder();
+ o.setName("gavin");
+ doc.setName("Hibernate in Action");
+ doc.setSummary("blah");
+ doc.updateText("blah blah");
+ fol.setName("books");
+ doc.setOwner(o);
+ doc.setFolder(fol);
+ fol.getDocuments().add(doc);
+ Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "summary" ) );
+ s.persist(o);
+ s.persist(fol);
+ t.commit();
+ s.close();
+
+ s = getFactory().openSession();
+ t = s.beginTransaction();
+ doc = (Document) s.get( Document.class, doc.getId() );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "summary" ) );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "owner" ) );
+ s.delete(doc);
+ s.delete( doc.getOwner() );
+ s.delete( doc.getFolder() );
+ t.commit();
+ s.close();
+ }
+}
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyExecutable.java (from rev 10159, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyExecutable.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyExecutable.java 2006-07-26 13:36:20 UTC (rev 10159)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyExecutable.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -0,0 +1,197 @@
+package org.hibernate.test.instrument.cases;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.test.instrument.cases.AbstractExecutable;
+import org.hibernate.test.instrument.domain.Owner;
+import org.hibernate.test.instrument.domain.Document;
+import org.hibernate.test.instrument.domain.Folder;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.Hibernate;
+import org.hibernate.LockMode;
+import org.hibernate.CacheMode;
+import org.hibernate.SessionFactory;
+
+/**
+ * @author Steve Ebersole
+ */
+public class TestLazyExecutable extends AbstractExecutable {
+ public void execute() {
+ SessionFactory factory = getFactory();
+ Session s = factory.openSession();
+ Transaction t = s.beginTransaction();
+ Owner o = new Owner();
+ Document doc = new Document();
+ Folder fol = new Folder();
+ o.setName("gavin");
+ doc.setName("Hibernate in Action");
+ doc.setSummary("blah");
+ doc.updateText("blah blah");
+ fol.setName("books");
+ doc.setOwner(o);
+ doc.setFolder(fol);
+ fol.getDocuments().add(doc);
+ s.save(o);
+ s.save(fol);
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = ( Document ) s.get( Document.class, doc.getId() );
+ TestCase.assertTrue( Hibernate.isPropertyInitialized(doc, "weirdProperty"));
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "name"));
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "folder"));
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "owner"));
+ doc.getUpperCaseName(); // should force initialization
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "folder"));
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "owner"));
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document").uniqueResult();
+ doc.getName();
+ TestCase.assertEquals( doc.getText(), "blah blah" );
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document").uniqueResult();
+ doc.getName();
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "summary"));
+ TestCase.assertEquals( doc.getText(), "blah blah" );
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "summary"));
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document").uniqueResult();
+ doc.setName("HiA");
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document").uniqueResult();
+ TestCase.assertEquals( doc.getName(), "HiA" );
+ TestCase.assertEquals( doc.getText(), "blah blah" );
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document").uniqueResult();
+ doc.getText();
+ doc.setName("HiA second edition");
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document").uniqueResult();
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "name"));
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "owner"));
+ TestCase.assertEquals( doc.getName(), "HiA second edition" );
+ TestCase.assertEquals( doc.getText(), "blah blah" );
+ TestCase.assertEquals( doc.getUpperCaseName(), "HIA SECOND EDITION" );
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document").uniqueResult();
+ t.commit();
+ s.close();
+
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ s.lock(doc, LockMode.NONE);
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
+ TestCase.assertEquals( doc.getText(), "blah blah" );
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document").uniqueResult();
+ t.commit();
+ s.close();
+
+ doc.setName("HiA2");
+
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ s.saveOrUpdate(doc);
+ s.flush();
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
+ TestCase.assertEquals( doc.getText(), "blah blah" );
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
+ doc.updateText("blah blah blah blah");
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = ( Document ) s.createQuery("from Document").uniqueResult();
+ TestCase.assertEquals( doc.getName(), "HiA2" );
+ TestCase.assertEquals( doc.getText(), "blah blah blah blah" );
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.load( Document.class, doc.getId() );
+ doc.getName();
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "summary"));
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document").uniqueResult();
+ //s.delete(doc);
+ s.delete( doc.getFolder() );
+ s.delete( doc.getOwner() );
+ s.flush();
+ t.commit();
+ s.close();
+ }
+
+}
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyManyToOneExecutable.java (from rev 10159, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyManyToOneExecutable.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyManyToOneExecutable.java 2006-07-26 13:36:20 UTC (rev 10159)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyManyToOneExecutable.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -0,0 +1,74 @@
+package org.hibernate.test.instrument.cases;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.Hibernate;
+import org.hibernate.test.instrument.domain.Owner;
+import org.hibernate.test.instrument.domain.Document;
+import org.hibernate.test.instrument.domain.Folder;
+import org.hibernate.test.instrument.cases.AbstractExecutable;
+import junit.framework.Assert;
+
+/**
+ * @author Steve Ebersole
+ */
+public class TestLazyManyToOneExecutable extends AbstractExecutable {
+ public void execute() {
+ Session s = getFactory().openSession();
+ Transaction t = s.beginTransaction();
+ Owner gavin = new Owner();
+ Document hia = new Document();
+ Folder fol = new Folder();
+ gavin.setName("gavin");
+ hia.setName("Hibernate in Action");
+ hia.setSummary("blah");
+ hia.updateText("blah blah");
+ fol.setName("books");
+ hia.setOwner(gavin);
+ hia.setFolder(fol);
+ fol.getDocuments().add(hia);
+ s.persist(gavin);
+ s.persist(fol);
+ t.commit();
+ s.close();
+
+ s = getFactory().openSession();
+ t = s.beginTransaction();
+ hia = (Document) s.createCriteria(Document.class).uniqueResult();
+ Assert.assertEquals( hia.getFolder().getClass(), Folder.class);
+ fol = hia.getFolder();
+ Assert.assertTrue( Hibernate.isInitialized(fol) );
+ t.commit();
+ s.close();
+
+ s = getFactory().openSession();
+ t = s.beginTransaction();
+ hia = (Document) s.createCriteria(Document.class).uniqueResult();
+ Assert.assertSame( hia.getFolder(), s.load(Folder.class, fol.getId()) );
+ Assert.assertTrue( Hibernate.isInitialized( hia.getFolder() ) );
+ t.commit();
+ s.close();
+
+ s = getFactory().openSession();
+ t = s.beginTransaction();
+ fol = (Folder) s.get(Folder.class, fol.getId());
+ hia = (Document) s.createCriteria(Document.class).uniqueResult();
+ Assert.assertSame( fol, hia.getFolder() );
+ fol = hia.getFolder();
+ Assert.assertTrue( Hibernate.isInitialized(fol) );
+ t.commit();
+ s.close();
+
+ s = getFactory().openSession();
+ t = s.beginTransaction();
+ fol = (Folder) s.load(Folder.class, fol.getId());
+ hia = (Document) s.createCriteria(Document.class).uniqueResult();
+ Assert.assertNotSame( fol, hia.getFolder() );
+ fol = hia.getFolder();
+ Assert.assertTrue( Hibernate.isInitialized(fol) );
+ s.delete(hia.getFolder());
+ s.delete(hia.getOwner());
+ t.commit();
+ s.close();
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestManyToOneProxyExecutable.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestManyToOneProxyExecutable.java 2006-08-11 18:49:33 UTC (rev 10247)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestManyToOneProxyExecutable.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -0,0 +1,37 @@
+package org.hibernate.test.instrument.cases;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.Hibernate;
+import org.hibernate.test.instrument.domain.Entity;
+import junit.framework.Assert;
+
+/**
+ *
+ * @author Steve Ebersole
+ */
+public class TestManyToOneProxyExecutable extends AbstractExecutable {
+ public void execute() {
+ Session s = getFactory().openSession();
+ Transaction t = s.beginTransaction();
+ Entity parent = new Entity( "parent" );
+ s.save( parent );
+ Entity child = new Entity( "child", parent );
+ s.save( child );
+ t.commit();
+ s.close();
+
+ s = getFactory().openSession();
+ t = s.beginTransaction();
+ child = ( Entity ) s.get( Entity.class, child.getId() );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( child, "name" ) );
+ Assert.assertTrue( Hibernate.isPropertyInitialized( child, "parent" ) );
+ parent = child.getParent();
+ Assert.assertFalse( Hibernate.isPropertyInitialized( parent, "name" ) );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( child, "name" ) );
+ s.delete( child );
+ s.delete( parent );
+ t.commit();
+ s.close();
+ }
+}
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/domain/Documents.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/domain/Documents.hbm.xml 2006-08-11 18:49:33 UTC (rev 10247)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/domain/Documents.hbm.xml 2006-08-11 18:50:44 UTC (rev 10248)
@@ -16,43 +16,42 @@
(2) use of a formula to define a "derived property"
-->
-
<hibernate-mapping package="org.hibernate.test.instrument.domain" default-access="field">
<class name="Folder" table="folders">
<id name="id">
- <generator class="native"/>
+ <generator class="increment"/>
</id>
- <property name="name"
- not-null="true"
+ <property name="name"
+ not-null="true"
length="50"/>
<many-to-one name="parent"/>
- <bag name="subfolders"
- inverse="true"
+ <bag name="subfolders"
+ inverse="true"
cascade="save-update">
<key column="parent"/>
<one-to-many class="Folder"/>
</bag>
- <bag name="documents"
- inverse="true"
+ <bag name="documents"
+ inverse="true"
cascade="all-delete-orphan">
<key column="folder"/>
<one-to-many class="Document"/>
</bag>
</class>
-
+
<class name="Owner" table="owners" lazy="false">
<id name="id">
- <generator class="native"/>
+ <generator class="increment"/>
</id>
- <property name="name"
- not-null="true"
+ <property name="name"
+ not-null="true"
length="50"/>
</class>
-
+
<class name="Document" table="documents">
<id name="id">
- <generator class="native"/>
+ <generator class="increment"/>
</id>
<property name="name" not-null="true" length="50"/>
<property name="upperCaseName" formula="upper(name)" lazy="true"/>
@@ -62,6 +61,13 @@
<property name="text" not-null="true" length="2000" lazy="true"/>
<property name="lastTextModification" not-null="true" lazy="true" access="field"/>
</class>
-
-</hibernate-mapping>
+ <class name="Entity" table="entity">
+ <id name="id" column="ID" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="name" column="NAME" type="string" lazy="true"/>
+ <many-to-one name="parent" column="PRNT_ID" class="Entity" lazy="proxy"/>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/domain/Entity.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/domain/Entity.java 2006-08-11 18:49:33 UTC (rev 10247)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/domain/Entity.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -0,0 +1,44 @@
+package org.hibernate.test.instrument.domain;
+
+/**
+ * todo: describe Entity
+ *
+ * @author Steve Ebersole
+ */
+public class Entity {
+ private Long id;
+ private String name;
+ private Entity parent;
+
+ public Entity() {
+ }
+
+ public Entity(String name) {
+ this.name = name;
+ }
+
+ public Entity(String name, Entity parent) {
+ this.name = name;
+ this.parent = parent;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Entity getParent() {
+ return parent;
+ }
+
+ public void setParent(Entity parent) {
+ this.parent = parent;
+ }
+}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractExecutable.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractExecutable.java 2006-08-11 18:49:33 UTC (rev 10247)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractExecutable.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -1,29 +0,0 @@
-package org.hibernate.test.instrument.runtime;
-
-import org.hibernate.SessionFactory;
-import org.hibernate.test.instrument.runtime.Executable;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
-
-/**
- * @author Steve Ebersole
- */
-public abstract class AbstractExecutable implements Executable {
-
- private SessionFactory factory;
-
- public void prepare() {
- factory = new Configuration()
- .setProperty( Environment.HBM2DDL_AUTO, "create-drop" )
- .addResource( "org/hibernate/test/instrument/domain/Documents.hbm.xml" )
- .buildSessionFactory();
- }
-
- public void complete() {
- factory.close();
- }
-
- protected SessionFactory getFactory() {
- return factory;
- }
-}
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractTransformingClassLoaderInstrumentTestCase.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractTransformingClassLoaderInstrumentTestCase.java 2006-08-11 18:49:33 UTC (rev 10247)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractTransformingClassLoaderInstrumentTestCase.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -22,10 +22,11 @@
new BasicClassFilter( new String[] { "org.hibernate.test.instrument" }, null ),
new FieldFilter() {
public boolean shouldInstrumentField(String className, String fieldName) {
- return true;
+ return className.startsWith( "org.hibernate.test.instrument.domain" );
}
public boolean shouldTransformFieldAccess(String transformingClassName, String fieldOwnerClassName, String fieldName) {
- return true;
+ return fieldOwnerClassName.startsWith( "org.hibernate.test.instrument.domain" )
+ && transformingClassName.equals( fieldOwnerClassName );
}
}
)
@@ -42,30 +43,35 @@
// the tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public void testSetFieldInterceptor() {
- executeExecutable( "org.hibernate.test.instrument.runtime.TestInjectFieldInterceptorExecutable" );
+ executeExecutable( "org.hibernate.test.instrument.cases.TestInjectFieldInterceptorExecutable" );
}
public void testDirtyCheck() {
- executeExecutable( "org.hibernate.test.instrument.runtime.TestDirtyCheckExecutable" );
+ executeExecutable( "org.hibernate.test.instrument.cases.TestDirtyCheckExecutable" );
}
public void testFetchAll() throws Exception {
- executeExecutable( "org.hibernate.test.instrument.runtime.TestFetchAllExecutable" );
+ executeExecutable( "org.hibernate.test.instrument.cases.TestFetchAllExecutable" );
}
public void testLazy() {
- executeExecutable( "org.hibernate.test.instrument.runtime.TestLazyExecutable" );
+ executeExecutable( "org.hibernate.test.instrument.cases.TestLazyExecutable" );
}
public void testLazyManyToOne() {
- executeExecutable( "org.hibernate.test.instrument.runtime.TestLazyManyToOneExecutable" );
+ executeExecutable( "org.hibernate.test.instrument.cases.TestLazyManyToOneExecutable" );
}
public void testPropertyInitialized() {
- executeExecutable( "org.hibernate.test.instrument.runtime.TestIsPropertyInitializedExecutable" );
+ executeExecutable( "org.hibernate.test.instrument.cases.TestIsPropertyInitializedExecutable" );
}
+ public void testManyToOneProxy() {
+ executeExecutable( "org.hibernate.test.instrument.cases.TestManyToOneProxyExecutable" );
+ }
+
+
// reflection code to ensure isolation into the created classloader ~~~~~~~
private static final Class[] SIG = new Class[] {};
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/Executable.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/Executable.java 2006-08-11 18:49:33 UTC (rev 10247)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/Executable.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -1,10 +0,0 @@
-package org.hibernate.test.instrument.runtime;
-
-/**
- * @author Steve Ebersole
- */
-public interface Executable {
- public void prepare();
- public void execute();
- public void complete();
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestDirtyCheckExecutable.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestDirtyCheckExecutable.java 2006-08-11 18:49:33 UTC (rev 10247)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestDirtyCheckExecutable.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -1,50 +0,0 @@
-package org.hibernate.test.instrument.runtime;
-
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.test.instrument.runtime.AbstractExecutable;
-import org.hibernate.test.instrument.domain.Folder;
-
-import java.util.List;
-import java.util.Iterator;
-
-import junit.framework.Assert;
-
-/**
- * @author Steve Ebersole
- */
-public class TestDirtyCheckExecutable extends AbstractExecutable {
- public void execute() {
- Session s = getFactory().openSession();
- Transaction t = s.beginTransaction();
- Folder pics = new Folder();
- pics.setName("pics");
- Folder docs = new Folder();
- docs.setName("docs");
- s.persist(docs);
- s.persist(pics);
- t.commit();
- s.close();
-
- s = getFactory().openSession();
- t = s.beginTransaction();
- List list = s.createCriteria(Folder.class).list();
- for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
- Folder f = (Folder) iter.next();
- Assert.assertFalse( f.nameWasread );
- }
- t.commit();
- s.close();
-
- for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
- Folder f = (Folder) iter.next();
- Assert.assertFalse( f.nameWasread );
- }
-
- s = getFactory().openSession();
- t = s.beginTransaction();
- s.createQuery("delete from Folder").executeUpdate();
- t.commit();
- s.close();
- }
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestFetchAllExecutable.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestFetchAllExecutable.java 2006-08-11 18:49:33 UTC (rev 10247)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestFetchAllExecutable.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -1,47 +0,0 @@
-package org.hibernate.test.instrument.runtime;
-
-import org.hibernate.Session;
-import org.hibernate.Hibernate;
-import org.hibernate.Transaction;
-import org.hibernate.test.instrument.domain.Owner;
-import org.hibernate.test.instrument.domain.Document;
-import org.hibernate.test.instrument.domain.Folder;
-import junit.framework.Assert;
-
-/**
- * @author Steve Ebersole
- */
-public class TestFetchAllExecutable extends AbstractExecutable {
- public void execute() {
- Session s = getFactory().openSession();
- Transaction t = s.beginTransaction();
- Owner o = new Owner();
- Document doc = new Document();
- Folder fol = new Folder();
- o.setName("gavin");
- doc.setName("Hibernate in Action");
- doc.setSummary("blah");
- doc.updateText("blah blah");
- fol.setName("books");
- doc.setOwner(o);
- doc.setFolder(fol);
- fol.getDocuments().add(doc);
- s.persist(o);
- s.persist(fol);
- t.commit();
- s.close();
-
- s = getFactory().openSession();
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document fetch all properties").uniqueResult();
- Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "summary" ) );
- Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );
- Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "owner" ) );
- Assert.assertEquals( doc.getSummary(), "blah" );
- s.delete(doc);
- s.delete( doc.getOwner() );
- s.delete( doc.getFolder() );
- t.commit();
- s.close();
- }
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestInjectFieldInterceptorExecutable.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestInjectFieldInterceptorExecutable.java 2006-08-11 18:49:33 UTC (rev 10247)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestInjectFieldInterceptorExecutable.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -1,17 +0,0 @@
-package org.hibernate.test.instrument.runtime;
-
-import org.hibernate.test.instrument.domain.Document;
-import org.hibernate.intercept.FieldInterceptionHelper;
-
-import java.util.HashSet;
-
-/**
- * @author Steve Ebersole
- */
-public class TestInjectFieldInterceptorExecutable extends AbstractExecutable {
- public void execute() {
- Document doc = new Document();
- FieldInterceptionHelper.injectFieldInterceptor( doc, "Document", new HashSet(), null );
- doc.getId();
- }
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestIsPropertyInitializedExecutable.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestIsPropertyInitializedExecutable.java 2006-08-11 18:49:33 UTC (rev 10247)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestIsPropertyInitializedExecutable.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -1,48 +0,0 @@
-//$Id: $
-package org.hibernate.test.instrument.runtime;
-
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.Hibernate;
-import org.hibernate.test.instrument.domain.Owner;
-import org.hibernate.test.instrument.domain.Document;
-import org.hibernate.test.instrument.domain.Folder;
-import junit.framework.Assert;
-
-/**
- * @author Steve Ebersole
- */
-public class TestIsPropertyInitializedExecutable extends AbstractExecutable {
- public void execute() {
- Session s = getFactory().openSession();
- Transaction t = s.beginTransaction();
- Owner o = new Owner();
- Document doc = new Document();
- Folder fol = new Folder();
- o.setName("gavin");
- doc.setName("Hibernate in Action");
- doc.setSummary("blah");
- doc.updateText("blah blah");
- fol.setName("books");
- doc.setOwner(o);
- doc.setFolder(fol);
- fol.getDocuments().add(doc);
- Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "summary" ) );
- s.persist(o);
- s.persist(fol);
- t.commit();
- s.close();
-
- s = getFactory().openSession();
- t = s.beginTransaction();
- doc = (Document) s.get( Document.class, doc.getId() );
- Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "summary" ) );
- Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );
- Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "owner" ) );
- s.delete(doc);
- s.delete( doc.getOwner() );
- s.delete( doc.getFolder() );
- t.commit();
- s.close();
- }
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyExecutable.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyExecutable.java 2006-08-11 18:49:33 UTC (rev 10247)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyExecutable.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -1,197 +0,0 @@
-package org.hibernate.test.instrument.runtime;
-
-import org.hibernate.test.TestCase;
-import org.hibernate.test.instrument.runtime.AbstractExecutable;
-import org.hibernate.test.instrument.domain.Owner;
-import org.hibernate.test.instrument.domain.Document;
-import org.hibernate.test.instrument.domain.Folder;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.Hibernate;
-import org.hibernate.LockMode;
-import org.hibernate.CacheMode;
-import org.hibernate.SessionFactory;
-
-/**
- * @author Steve Ebersole
- */
-public class TestLazyExecutable extends AbstractExecutable {
- public void execute() {
- SessionFactory factory = getFactory();
- Session s = factory.openSession();
- Transaction t = s.beginTransaction();
- Owner o = new Owner();
- Document doc = new Document();
- Folder fol = new Folder();
- o.setName("gavin");
- doc.setName("Hibernate in Action");
- doc.setSummary("blah");
- doc.updateText("blah blah");
- fol.setName("books");
- doc.setOwner(o);
- doc.setFolder(fol);
- fol.getDocuments().add(doc);
- s.save(o);
- s.save(fol);
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = ( Document ) s.get( Document.class, doc.getId() );
- TestCase.assertTrue( Hibernate.isPropertyInitialized(doc, "weirdProperty"));
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "name"));
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "folder"));
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "owner"));
- doc.getUpperCaseName(); // should force initialization
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "folder"));
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "owner"));
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- doc.getName();
- TestCase.assertEquals( doc.getText(), "blah blah" );
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- doc.getName();
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "summary"));
- TestCase.assertEquals( doc.getText(), "blah blah" );
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "summary"));
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- doc.setName("HiA");
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- TestCase.assertEquals( doc.getName(), "HiA" );
- TestCase.assertEquals( doc.getText(), "blah blah" );
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- doc.getText();
- doc.setName("HiA second edition");
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "name"));
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "owner"));
- TestCase.assertEquals( doc.getName(), "HiA second edition" );
- TestCase.assertEquals( doc.getText(), "blah blah" );
- TestCase.assertEquals( doc.getUpperCaseName(), "HIA SECOND EDITION" );
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- t.commit();
- s.close();
-
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- s.lock(doc, LockMode.NONE);
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- TestCase.assertEquals( doc.getText(), "blah blah" );
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- t.commit();
- s.close();
-
- doc.setName("HiA2");
-
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- s.saveOrUpdate(doc);
- s.flush();
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- TestCase.assertEquals( doc.getText(), "blah blah" );
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- doc.updateText("blah blah blah blah");
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = ( Document ) s.createQuery("from Document").uniqueResult();
- TestCase.assertEquals( doc.getName(), "HiA2" );
- TestCase.assertEquals( doc.getText(), "blah blah blah blah" );
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.load( Document.class, doc.getId() );
- doc.getName();
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "summary"));
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- //s.delete(doc);
- s.delete( doc.getFolder() );
- s.delete( doc.getOwner() );
- s.flush();
- t.commit();
- s.close();
- }
-
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyManyToOneExecutable.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyManyToOneExecutable.java 2006-08-11 18:49:33 UTC (rev 10247)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyManyToOneExecutable.java 2006-08-11 18:50:44 UTC (rev 10248)
@@ -1,73 +0,0 @@
-package org.hibernate.test.instrument.runtime;
-
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.Hibernate;
-import org.hibernate.test.instrument.domain.Owner;
-import org.hibernate.test.instrument.domain.Document;
-import org.hibernate.test.instrument.domain.Folder;
-import junit.framework.Assert;
-
-/**
- * @author Steve Ebersole
- */
-public class TestLazyManyToOneExecutable extends AbstractExecutable {
- public void execute() {
- Session s = getFactory().openSession();
- Transaction t = s.beginTransaction();
- Owner gavin = new Owner();
- Document hia = new Document();
- Folder fol = new Folder();
- gavin.setName("gavin");
- hia.setName("Hibernate in Action");
- hia.setSummary("blah");
- hia.updateText("blah blah");
- fol.setName("books");
- hia.setOwner(gavin);
- hia.setFolder(fol);
- fol.getDocuments().add(hia);
- s.persist(gavin);
- s.persist(fol);
- t.commit();
- s.close();
-
- s = getFactory().openSession();
- t = s.beginTransaction();
- hia = (Document) s.createCriteria(Document.class).uniqueResult();
- Assert.assertEquals( hia.getFolder().getClass(), Folder.class);
- fol = hia.getFolder();
- Assert.assertTrue( Hibernate.isInitialized(fol) );
- t.commit();
- s.close();
-
- s = getFactory().openSession();
- t = s.beginTransaction();
- hia = (Document) s.createCriteria(Document.class).uniqueResult();
- Assert.assertSame( hia.getFolder(), s.load(Folder.class, fol.getId()) );
- Assert.assertTrue( Hibernate.isInitialized( hia.getFolder() ) );
- t.commit();
- s.close();
-
- s = getFactory().openSession();
- t = s.beginTransaction();
- fol = (Folder) s.get(Folder.class, fol.getId());
- hia = (Document) s.createCriteria(Document.class).uniqueResult();
- Assert.assertSame( fol, hia.getFolder() );
- fol = hia.getFolder();
- Assert.assertTrue( Hibernate.isInitialized(fol) );
- t.commit();
- s.close();
-
- s = getFactory().openSession();
- t = s.beginTransaction();
- fol = (Folder) s.load(Folder.class, fol.getId());
- hia = (Document) s.createCriteria(Document.class).uniqueResult();
- Assert.assertNotSame( fol, hia.getFolder() );
- fol = hia.getFolder();
- Assert.assertTrue( Hibernate.isInitialized(fol) );
- s.delete(hia.getFolder());
- s.delete(hia.getOwner());
- t.commit();
- s.close();
- }
-}
17 years, 9 months
Hibernate SVN: r10247 - branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-08-11 14:49:33 -0400 (Fri, 11 Aug 2006)
New Revision: 10247
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/Property.java
Log:
ported fix for HHH-1740 to 3.2 branch
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/Property.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/Property.java 2006-08-11 18:39:47 UTC (rev 10246)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/Property.java 2006-08-11 18:49:33 UTC (rev 10247)
@@ -201,7 +201,19 @@
// interception. So we need to make sure that we return
// true here for the case of many-to-one and one-to-one
// with lazy="no-proxy"
- return ( ( ToOne ) value ).isLazy();
+ //
+ // * impl note - lazy="no-proxy" currently forces both
+ // lazy and unwrap to be set to true. The other case we
+ // are extremely interested in here is that of lazy="proxy"
+ // where lazy is set to true, but unwrap is set to false.
+ // thus we use both here under the assumption that this
+ // return is really only ever used during persister
+ // construction to determine the lazy property/field fetch
+ // groupings. If that assertion changes then this check
+ // needs to change as well. Partially, this is an issue with
+ // the overloading of the term "lazy" here...
+ ToOne toOneValue = ( ToOne ) value;
+ return toOneValue.isLazy() && toOneValue.isUnwrapProxy();
}
return lazy;
}
17 years, 9 months
Hibernate SVN: r10246 - in trunk/Hibernate3/test/org/hibernate/test/instrument: . buildtime cases domain runtime
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-08-11 14:39:47 -0400 (Fri, 11 Aug 2006)
New Revision: 10246
Added:
trunk/Hibernate3/test/org/hibernate/test/instrument/cases/
trunk/Hibernate3/test/org/hibernate/test/instrument/cases/AbstractExecutable.java
trunk/Hibernate3/test/org/hibernate/test/instrument/cases/Executable.java
trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestDirtyCheckExecutable.java
trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestFetchAllExecutable.java
trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestInjectFieldInterceptorExecutable.java
trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestIsPropertyInitializedExecutable.java
trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyExecutable.java
trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyManyToOneExecutable.java
trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestManyToOneProxyExecutable.java
trunk/Hibernate3/test/org/hibernate/test/instrument/domain/Entity.java
Removed:
trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractExecutable.java
trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/Executable.java
trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestDirtyCheckExecutable.java
trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestFetchAllExecutable.java
trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestInjectFieldInterceptorExecutable.java
trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestIsPropertyInitializedExecutable.java
trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyExecutable.java
trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyManyToOneExecutable.java
Modified:
trunk/Hibernate3/test/org/hibernate/test/instrument/buildtime/InstrumentTest.java
trunk/Hibernate3/test/org/hibernate/test/instrument/domain/Documents.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractTransformingClassLoaderInstrumentTestCase.java
trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/JavassistInstrumentationTest.java
Log:
HHH-1740 : many-to-one (and one-to-one) with lazy="proxy" and bytecode instrumentation
Modified: trunk/Hibernate3/test/org/hibernate/test/instrument/buildtime/InstrumentTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/buildtime/InstrumentTest.java 2006-08-11 18:38:39 UTC (rev 10245)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/buildtime/InstrumentTest.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -1,22 +1,19 @@
//$Id$
package org.hibernate.test.instrument.buildtime;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Iterator;
-
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.hibernate.Hibernate;
-import org.hibernate.LockMode;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
import org.hibernate.intercept.FieldInterceptionHelper;
import org.hibernate.test.TestCase;
-import org.hibernate.test.instrument.domain.Owner;
import org.hibernate.test.instrument.domain.Document;
-import org.hibernate.test.instrument.domain.Folder;
+import org.hibernate.test.instrument.cases.TestDirtyCheckExecutable;
+import org.hibernate.test.instrument.cases.TestFetchAllExecutable;
+import org.hibernate.test.instrument.cases.TestLazyExecutable;
+import org.hibernate.test.instrument.cases.TestLazyManyToOneExecutable;
+import org.hibernate.test.instrument.cases.TestInjectFieldInterceptorExecutable;
+import org.hibernate.test.instrument.cases.TestIsPropertyInitializedExecutable;
+import org.hibernate.test.instrument.cases.TestManyToOneProxyExecutable;
/**
* @author Gavin King
@@ -28,311 +25,46 @@
}
public void testDirtyCheck() {
- if ( !isRunnable() ) {
- return;
- }
- Session s = openSession();
- Transaction t = s.beginTransaction();
- Folder pics = new Folder();
- pics.setName("pics");
- Folder docs = new Folder();
- docs.setName("docs");
- s.persist(docs);
- s.persist(pics);
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- List list = s.createCriteria(Folder.class).list();
- for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
- Folder f = (Folder) iter.next();
- assertFalse( f.nameWasread );
- }
- t.commit();
- s.close();
-
- for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
- Folder f = (Folder) iter.next();
- assertFalse( f.nameWasread );
- }
-
- s = openSession();
- t = s.beginTransaction();
- s.createQuery("delete from Folder").executeUpdate();
- t.commit();
- s.close();
+ new TestDirtyCheckExecutable().execute();
}
public void testFetchAll() throws Exception {
- if ( !isRunnable() ) {
- return;
- }
- Session s = openSession();
- Owner o = new Owner();
- Document doc = new Document();
- Folder fol = new Folder();
- o.setName("gavin");
- doc.setName("Hibernate in Action");
- doc.setSummary("blah");
- doc.updateText("blah blah");
- fol.setName("books");
- doc.setOwner(o);
- doc.setFolder(fol);
- fol.getDocuments().add(doc);
- s.persist(o);
- s.persist(fol);
- s.flush();
- s.clear();
- doc = (Document) s.createQuery("from Document fetch all properties").uniqueResult();
- assertTrue( Hibernate.isPropertyInitialized( doc, "summary" ) );
- assertTrue( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );
- assertTrue( Hibernate.isPropertyInitialized( doc, "owner" ) );
- assertEquals( doc.getSummary(), "blah" );
- s.delete(doc);
- s.delete( doc.getOwner() );
- s.delete( doc.getFolder() );
- s.flush();
- s.connection().commit();
- s.close();
+ new TestFetchAllExecutable().execute();
}
public void testLazy() throws Exception {
- if ( !isRunnable() ) {
- return;
- }
- Session s = openSession();
- Transaction t = s.beginTransaction();
- Owner o = new Owner();
- Document doc = new Document();
- Folder fol = new Folder();
- o.setName("gavin");
- doc.setName("Hibernate in Action");
- doc.setSummary("blah");
- doc.updateText("blah blah");
- fol.setName("books");
- doc.setOwner(o);
- doc.setFolder(fol);
- fol.getDocuments().add(doc);
- s.save(o);
- s.save(fol);
- t.commit();
- s.close();
-
- getSessions().evict(Document.class);
-
- s = openSession();
- t = s.beginTransaction();
- doc = ( Document ) s.get( Document.class, doc.getId() );
- assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
- assertTrue(Hibernate.isPropertyInitialized(doc, "name"));
- assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- assertFalse(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
- assertFalse(Hibernate.isPropertyInitialized(doc, "folder"));
- assertFalse(Hibernate.isPropertyInitialized(doc, "owner"));
- doc.getUpperCaseName(); // should force initialization
- assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
- assertTrue(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
- assertTrue(Hibernate.isPropertyInitialized(doc, "folder"));
- assertTrue(Hibernate.isPropertyInitialized(doc, "owner"));
- t.commit();
- s.close();
-
- getSessions().evict(Document.class);
-
- s = openSession();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- doc.getName();
- assertEquals( doc.getText(), "blah blah" );
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- doc.getName();
- assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- assertFalse(Hibernate.isPropertyInitialized(doc, "summary"));
- assertEquals( doc.getText(), "blah blah" );
- assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- assertTrue(Hibernate.isPropertyInitialized(doc, "summary"));
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = ( Document ) s.createQuery("from Document").uniqueResult();
- doc.setName("HiA");
- s.flush();
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- assertEquals( doc.getName(), "HiA" );
- assertEquals( doc.getText(), "blah blah" );
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- doc.getText();
- doc.setName("HiA second edition");
- s.flush();
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
- assertTrue(Hibernate.isPropertyInitialized(doc, "name"));
- assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- assertFalse(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
- assertFalse(Hibernate.isPropertyInitialized(doc, "owner"));
- assertEquals( doc.getName(), "HiA second edition" );
- assertEquals( doc.getText(), "blah blah" );
- assertEquals( doc.getUpperCaseName(), "HIA SECOND EDITION" );
- assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
- assertTrue(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- s.connection().commit();
- s.close();
-
- assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
-
- s = openSession();
- s.lock(doc, LockMode.NONE);
- assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- assertEquals( doc.getText(), "blah blah" );
- assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- s.connection().commit();
- s.close();
-
- doc.setName("HiA2");
-
- assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
-
- s = openSession();
- s.saveOrUpdate(doc);
- s.flush();
- assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- assertEquals( doc.getText(), "blah blah" );
- assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- doc.updateText("blah blah blah blah");
- s.flush();
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- assertEquals( doc.getName(), "HiA2" );
- assertEquals( doc.getText(), "blah blah blah blah" );
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = (Document) s.load( Document.class, doc.getId() );
- doc.getName();
- assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- assertFalse(Hibernate.isPropertyInitialized(doc, "summary"));
- s.connection().commit();
- s.close();
-
- s = openSession();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- //s.delete(doc);
- s.delete( doc.getFolder() );
- s.delete( doc.getOwner() );
- s.flush();
- s.connection().commit();
- s.close();
-
+ new TestLazyExecutable().execute();
}
public void testLazyManyToOne() {
- if ( !isRunnable() ) {
- return;
- }
- Session s = openSession();
- Transaction t = s.beginTransaction();
- Owner gavin = new Owner();
- Document hia = new Document();
- Folder fol = new Folder();
- gavin.setName("gavin");
- hia.setName("Hibernate in Action");
- hia.setSummary("blah");
- hia.updateText("blah blah");
- fol.setName("books");
- hia.setOwner(gavin);
- hia.setFolder(fol);
- fol.getDocuments().add(hia);
- s.persist(gavin);
- s.persist(fol);
- t.commit();
- s.close();
+ new TestLazyManyToOneExecutable().execute();
+ }
- s = openSession();
- t = s.beginTransaction();
- hia = (Document) s.createCriteria(Document.class).uniqueResult();
- assertEquals( hia.getFolder().getClass(), Folder.class);
- fol = hia.getFolder();
- assertTrue( Hibernate.isInitialized(fol) );
- t.commit();
- s.close();
+ public void testSetFieldInterceptor() {
+ new TestInjectFieldInterceptorExecutable().execute();
+ }
- s = openSession();
- t = s.beginTransaction();
- hia = (Document) s.createCriteria(Document.class).uniqueResult();
- assertSame( hia.getFolder(), s.load(Folder.class, fol.getId()) );
- assertTrue( Hibernate.isInitialized( hia.getFolder() ) );
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- fol = (Folder) s.get(Folder.class, fol.getId());
- hia = (Document) s.createCriteria(Document.class).uniqueResult();
- assertSame( fol, hia.getFolder() );
- fol = hia.getFolder();
- assertTrue( Hibernate.isInitialized(fol) );
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- fol = (Folder) s.load(Folder.class, fol.getId());
- hia = (Document) s.createCriteria(Document.class).uniqueResult();
- assertNotSame( fol, hia.getFolder() );
- fol = hia.getFolder();
- assertTrue( Hibernate.isInitialized(fol) );
- s.delete(hia.getFolder());
- s.delete(hia.getOwner());
- t.commit();
- s.close();
+ public void testPropertyInitialized() {
+ new TestIsPropertyInitializedExecutable().execute();
}
- public void testSetFieldInterceptor() {
- if ( !isRunnable() ) {
- return;
- }
- Document doc = new Document();
- FieldInterceptionHelper.injectFieldInterceptor( doc, "Document", new HashSet(), null );
- doc.getId();
+ public void testManyToOneProxy() {
+ new TestManyToOneProxyExecutable().execute();
}
protected String[] getMappings() {
return new String[] { "instrument/domain/Documents.hbm.xml" };
}
+ protected void runTest() throws Throwable {
+ if ( isRunnable() ) {
+ super.runTest();
+ }
+ else {
+ reportSkip( "domain classes not instrumented", "build-time instrumentation" );
+ }
+ }
+
public static Test suite() {
return new TestSuite(InstrumentTest.class);
}
Copied: trunk/Hibernate3/test/org/hibernate/test/instrument/cases/AbstractExecutable.java (from rev 10159, trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractExecutable.java)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractExecutable.java 2006-07-26 13:36:20 UTC (rev 10159)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/cases/AbstractExecutable.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -0,0 +1,28 @@
+package org.hibernate.test.instrument.cases;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+
+/**
+ * @author Steve Ebersole
+ */
+public abstract class AbstractExecutable implements Executable {
+
+ private SessionFactory factory;
+
+ public void prepare() {
+ factory = new Configuration()
+ .setProperty( Environment.HBM2DDL_AUTO, "create-drop" )
+ .addResource( "org/hibernate/test/instrument/domain/Documents.hbm.xml" )
+ .buildSessionFactory();
+ }
+
+ public void complete() {
+ factory.close();
+ }
+
+ protected SessionFactory getFactory() {
+ return factory;
+ }
+}
Copied: trunk/Hibernate3/test/org/hibernate/test/instrument/cases/Executable.java (from rev 10159, trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/Executable.java)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/Executable.java 2006-07-26 13:36:20 UTC (rev 10159)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/cases/Executable.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -0,0 +1,10 @@
+package org.hibernate.test.instrument.cases;
+
+/**
+ * @author Steve Ebersole
+ */
+public interface Executable {
+ public void prepare();
+ public void execute();
+ public void complete();
+}
Copied: trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestDirtyCheckExecutable.java (from rev 10159, trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestDirtyCheckExecutable.java)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestDirtyCheckExecutable.java 2006-07-26 13:36:20 UTC (rev 10159)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestDirtyCheckExecutable.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -0,0 +1,49 @@
+package org.hibernate.test.instrument.cases;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.test.instrument.domain.Folder;
+
+import java.util.List;
+import java.util.Iterator;
+
+import junit.framework.Assert;
+
+/**
+ * @author Steve Ebersole
+ */
+public class TestDirtyCheckExecutable extends AbstractExecutable {
+ public void execute() {
+ Session s = getFactory().openSession();
+ Transaction t = s.beginTransaction();
+ Folder pics = new Folder();
+ pics.setName("pics");
+ Folder docs = new Folder();
+ docs.setName("docs");
+ s.persist(docs);
+ s.persist(pics);
+ t.commit();
+ s.close();
+
+ s = getFactory().openSession();
+ t = s.beginTransaction();
+ List list = s.createCriteria(Folder.class).list();
+ for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
+ Folder f = (Folder) iter.next();
+ Assert.assertFalse( f.nameWasread );
+ }
+ t.commit();
+ s.close();
+
+ for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
+ Folder f = (Folder) iter.next();
+ Assert.assertFalse( f.nameWasread );
+ }
+
+ s = getFactory().openSession();
+ t = s.beginTransaction();
+ s.createQuery("delete from Folder").executeUpdate();
+ t.commit();
+ s.close();
+ }
+}
Copied: trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestFetchAllExecutable.java (from rev 10159, trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestFetchAllExecutable.java)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestFetchAllExecutable.java 2006-07-26 13:36:20 UTC (rev 10159)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestFetchAllExecutable.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -0,0 +1,47 @@
+package org.hibernate.test.instrument.cases;
+
+import org.hibernate.Session;
+import org.hibernate.Hibernate;
+import org.hibernate.Transaction;
+import org.hibernate.test.instrument.domain.Owner;
+import org.hibernate.test.instrument.domain.Document;
+import org.hibernate.test.instrument.domain.Folder;
+import junit.framework.Assert;
+
+/**
+ * @author Steve Ebersole
+ */
+public class TestFetchAllExecutable extends AbstractExecutable {
+ public void execute() {
+ Session s = getFactory().openSession();
+ Transaction t = s.beginTransaction();
+ Owner o = new Owner();
+ Document doc = new Document();
+ Folder fol = new Folder();
+ o.setName("gavin");
+ doc.setName("Hibernate in Action");
+ doc.setSummary("blah");
+ doc.updateText("blah blah");
+ fol.setName("books");
+ doc.setOwner(o);
+ doc.setFolder(fol);
+ fol.getDocuments().add(doc);
+ s.persist(o);
+ s.persist(fol);
+ t.commit();
+ s.close();
+
+ s = getFactory().openSession();
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document fetch all properties").uniqueResult();
+ Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "summary" ) );
+ Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );
+ Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "owner" ) );
+ Assert.assertEquals( doc.getSummary(), "blah" );
+ s.delete(doc);
+ s.delete( doc.getOwner() );
+ s.delete( doc.getFolder() );
+ t.commit();
+ s.close();
+ }
+}
Copied: trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestInjectFieldInterceptorExecutable.java (from rev 10159, trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestInjectFieldInterceptorExecutable.java)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestInjectFieldInterceptorExecutable.java 2006-07-26 13:36:20 UTC (rev 10159)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestInjectFieldInterceptorExecutable.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -0,0 +1,17 @@
+package org.hibernate.test.instrument.cases;
+
+import org.hibernate.test.instrument.domain.Document;
+import org.hibernate.intercept.FieldInterceptionHelper;
+
+import java.util.HashSet;
+
+/**
+ * @author Steve Ebersole
+ */
+public class TestInjectFieldInterceptorExecutable extends AbstractExecutable {
+ public void execute() {
+ Document doc = new Document();
+ FieldInterceptionHelper.injectFieldInterceptor( doc, "Document", new HashSet(), null );
+ doc.getId();
+ }
+}
Copied: trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestIsPropertyInitializedExecutable.java (from rev 10159, trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestIsPropertyInitializedExecutable.java)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestIsPropertyInitializedExecutable.java 2006-07-26 13:36:20 UTC (rev 10159)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestIsPropertyInitializedExecutable.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -0,0 +1,48 @@
+//$Id: $
+package org.hibernate.test.instrument.cases;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.Hibernate;
+import org.hibernate.test.instrument.domain.Owner;
+import org.hibernate.test.instrument.domain.Document;
+import org.hibernate.test.instrument.domain.Folder;
+import junit.framework.Assert;
+
+/**
+ * @author Steve Ebersole
+ */
+public class TestIsPropertyInitializedExecutable extends AbstractExecutable {
+ public void execute() {
+ Session s = getFactory().openSession();
+ Transaction t = s.beginTransaction();
+ Owner o = new Owner();
+ Document doc = new Document();
+ Folder fol = new Folder();
+ o.setName("gavin");
+ doc.setName("Hibernate in Action");
+ doc.setSummary("blah");
+ doc.updateText("blah blah");
+ fol.setName("books");
+ doc.setOwner(o);
+ doc.setFolder(fol);
+ fol.getDocuments().add(doc);
+ Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "summary" ) );
+ s.persist(o);
+ s.persist(fol);
+ t.commit();
+ s.close();
+
+ s = getFactory().openSession();
+ t = s.beginTransaction();
+ doc = (Document) s.get( Document.class, doc.getId() );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "summary" ) );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "owner" ) );
+ s.delete(doc);
+ s.delete( doc.getOwner() );
+ s.delete( doc.getFolder() );
+ t.commit();
+ s.close();
+ }
+}
Copied: trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyExecutable.java (from rev 10159, trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyExecutable.java)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyExecutable.java 2006-07-26 13:36:20 UTC (rev 10159)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyExecutable.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -0,0 +1,197 @@
+package org.hibernate.test.instrument.cases;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.test.instrument.cases.AbstractExecutable;
+import org.hibernate.test.instrument.domain.Owner;
+import org.hibernate.test.instrument.domain.Document;
+import org.hibernate.test.instrument.domain.Folder;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.Hibernate;
+import org.hibernate.LockMode;
+import org.hibernate.CacheMode;
+import org.hibernate.SessionFactory;
+
+/**
+ * @author Steve Ebersole
+ */
+public class TestLazyExecutable extends AbstractExecutable {
+ public void execute() {
+ SessionFactory factory = getFactory();
+ Session s = factory.openSession();
+ Transaction t = s.beginTransaction();
+ Owner o = new Owner();
+ Document doc = new Document();
+ Folder fol = new Folder();
+ o.setName("gavin");
+ doc.setName("Hibernate in Action");
+ doc.setSummary("blah");
+ doc.updateText("blah blah");
+ fol.setName("books");
+ doc.setOwner(o);
+ doc.setFolder(fol);
+ fol.getDocuments().add(doc);
+ s.save(o);
+ s.save(fol);
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = ( Document ) s.get( Document.class, doc.getId() );
+ TestCase.assertTrue( Hibernate.isPropertyInitialized(doc, "weirdProperty"));
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "name"));
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "folder"));
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "owner"));
+ doc.getUpperCaseName(); // should force initialization
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "folder"));
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "owner"));
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document").uniqueResult();
+ doc.getName();
+ TestCase.assertEquals( doc.getText(), "blah blah" );
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document").uniqueResult();
+ doc.getName();
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "summary"));
+ TestCase.assertEquals( doc.getText(), "blah blah" );
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "summary"));
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document").uniqueResult();
+ doc.setName("HiA");
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document").uniqueResult();
+ TestCase.assertEquals( doc.getName(), "HiA" );
+ TestCase.assertEquals( doc.getText(), "blah blah" );
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document").uniqueResult();
+ doc.getText();
+ doc.setName("HiA second edition");
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document").uniqueResult();
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "name"));
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "owner"));
+ TestCase.assertEquals( doc.getName(), "HiA second edition" );
+ TestCase.assertEquals( doc.getText(), "blah blah" );
+ TestCase.assertEquals( doc.getUpperCaseName(), "HIA SECOND EDITION" );
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document").uniqueResult();
+ t.commit();
+ s.close();
+
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ s.lock(doc, LockMode.NONE);
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
+ TestCase.assertEquals( doc.getText(), "blah blah" );
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document").uniqueResult();
+ t.commit();
+ s.close();
+
+ doc.setName("HiA2");
+
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ s.saveOrUpdate(doc);
+ s.flush();
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
+ TestCase.assertEquals( doc.getText(), "blah blah" );
+ TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
+ doc.updateText("blah blah blah blah");
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = ( Document ) s.createQuery("from Document").uniqueResult();
+ TestCase.assertEquals( doc.getName(), "HiA2" );
+ TestCase.assertEquals( doc.getText(), "blah blah blah blah" );
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.load( Document.class, doc.getId() );
+ doc.getName();
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
+ TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "summary"));
+ t.commit();
+ s.close();
+
+ s = factory.openSession();
+ s.setCacheMode( CacheMode.IGNORE );
+ t = s.beginTransaction();
+ doc = (Document) s.createQuery("from Document").uniqueResult();
+ //s.delete(doc);
+ s.delete( doc.getFolder() );
+ s.delete( doc.getOwner() );
+ s.flush();
+ t.commit();
+ s.close();
+ }
+
+}
Copied: trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyManyToOneExecutable.java (from rev 10159, trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyManyToOneExecutable.java)
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyManyToOneExecutable.java 2006-07-26 13:36:20 UTC (rev 10159)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyManyToOneExecutable.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -0,0 +1,74 @@
+package org.hibernate.test.instrument.cases;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.Hibernate;
+import org.hibernate.test.instrument.domain.Owner;
+import org.hibernate.test.instrument.domain.Document;
+import org.hibernate.test.instrument.domain.Folder;
+import org.hibernate.test.instrument.cases.AbstractExecutable;
+import junit.framework.Assert;
+
+/**
+ * @author Steve Ebersole
+ */
+public class TestLazyManyToOneExecutable extends AbstractExecutable {
+ public void execute() {
+ Session s = getFactory().openSession();
+ Transaction t = s.beginTransaction();
+ Owner gavin = new Owner();
+ Document hia = new Document();
+ Folder fol = new Folder();
+ gavin.setName("gavin");
+ hia.setName("Hibernate in Action");
+ hia.setSummary("blah");
+ hia.updateText("blah blah");
+ fol.setName("books");
+ hia.setOwner(gavin);
+ hia.setFolder(fol);
+ fol.getDocuments().add(hia);
+ s.persist(gavin);
+ s.persist(fol);
+ t.commit();
+ s.close();
+
+ s = getFactory().openSession();
+ t = s.beginTransaction();
+ hia = (Document) s.createCriteria(Document.class).uniqueResult();
+ Assert.assertEquals( hia.getFolder().getClass(), Folder.class);
+ fol = hia.getFolder();
+ Assert.assertTrue( Hibernate.isInitialized(fol) );
+ t.commit();
+ s.close();
+
+ s = getFactory().openSession();
+ t = s.beginTransaction();
+ hia = (Document) s.createCriteria(Document.class).uniqueResult();
+ Assert.assertSame( hia.getFolder(), s.load(Folder.class, fol.getId()) );
+ Assert.assertTrue( Hibernate.isInitialized( hia.getFolder() ) );
+ t.commit();
+ s.close();
+
+ s = getFactory().openSession();
+ t = s.beginTransaction();
+ fol = (Folder) s.get(Folder.class, fol.getId());
+ hia = (Document) s.createCriteria(Document.class).uniqueResult();
+ Assert.assertSame( fol, hia.getFolder() );
+ fol = hia.getFolder();
+ Assert.assertTrue( Hibernate.isInitialized(fol) );
+ t.commit();
+ s.close();
+
+ s = getFactory().openSession();
+ t = s.beginTransaction();
+ fol = (Folder) s.load(Folder.class, fol.getId());
+ hia = (Document) s.createCriteria(Document.class).uniqueResult();
+ Assert.assertNotSame( fol, hia.getFolder() );
+ fol = hia.getFolder();
+ Assert.assertTrue( Hibernate.isInitialized(fol) );
+ s.delete(hia.getFolder());
+ s.delete(hia.getOwner());
+ t.commit();
+ s.close();
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestManyToOneProxyExecutable.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestManyToOneProxyExecutable.java 2006-08-11 18:38:39 UTC (rev 10245)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestManyToOneProxyExecutable.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -0,0 +1,37 @@
+package org.hibernate.test.instrument.cases;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.Hibernate;
+import org.hibernate.test.instrument.domain.Entity;
+import junit.framework.Assert;
+
+/**
+ *
+ * @author Steve Ebersole
+ */
+public class TestManyToOneProxyExecutable extends AbstractExecutable {
+ public void execute() {
+ Session s = getFactory().openSession();
+ Transaction t = s.beginTransaction();
+ Entity parent = new Entity( "parent" );
+ s.save( parent );
+ Entity child = new Entity( "child", parent );
+ s.save( child );
+ t.commit();
+ s.close();
+
+ s = getFactory().openSession();
+ t = s.beginTransaction();
+ child = ( Entity ) s.get( Entity.class, child.getId() );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( child, "name" ) );
+ Assert.assertTrue( Hibernate.isPropertyInitialized( child, "parent" ) );
+ parent = child.getParent();
+ Assert.assertFalse( Hibernate.isPropertyInitialized( parent, "name" ) );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( child, "name" ) );
+ s.delete( child );
+ s.delete( parent );
+ t.commit();
+ s.close();
+ }
+}
Modified: trunk/Hibernate3/test/org/hibernate/test/instrument/domain/Documents.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/domain/Documents.hbm.xml 2006-08-11 18:38:39 UTC (rev 10245)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/domain/Documents.hbm.xml 2006-08-11 18:39:47 UTC (rev 10246)
@@ -21,7 +21,7 @@
<class name="Folder" table="folders">
<id name="id">
- <generator class="native"/>
+ <generator class="increment"/>
</id>
<property name="name"
not-null="true"
@@ -43,7 +43,7 @@
<class name="Owner" table="owners" lazy="false">
<id name="id">
- <generator class="native"/>
+ <generator class="increment"/>
</id>
<property name="name"
not-null="true"
@@ -52,7 +52,7 @@
<class name="Document" table="documents">
<id name="id">
- <generator class="native"/>
+ <generator class="increment"/>
</id>
<property name="name" not-null="true" length="50"/>
<property name="upperCaseName" formula="upper(name)" lazy="true"/>
@@ -62,6 +62,13 @@
<property name="text" not-null="true" length="2000" lazy="true"/>
<property name="lastTextModification" not-null="true" lazy="true" access="field"/>
</class>
-
+ <class name="Entity" table="entity">
+ <id name="id" column="ID" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="name" column="NAME" type="string" lazy="true"/>
+ <many-to-one name="parent" column="PRNT_ID" class="Entity" lazy="proxy"/>
+ </class>
+
</hibernate-mapping>
Added: trunk/Hibernate3/test/org/hibernate/test/instrument/domain/Entity.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/domain/Entity.java 2006-08-11 18:38:39 UTC (rev 10245)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/domain/Entity.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -0,0 +1,44 @@
+package org.hibernate.test.instrument.domain;
+
+/**
+ * todo: describe Entity
+ *
+ * @author Steve Ebersole
+ */
+public class Entity {
+ private Long id;
+ private String name;
+ private Entity parent;
+
+ public Entity() {
+ }
+
+ public Entity(String name) {
+ this.name = name;
+ }
+
+ public Entity(String name, Entity parent) {
+ this.name = name;
+ this.parent = parent;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Entity getParent() {
+ return parent;
+ }
+
+ public void setParent(Entity parent) {
+ this.parent = parent;
+ }
+}
Deleted: trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractExecutable.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractExecutable.java 2006-08-11 18:38:39 UTC (rev 10245)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractExecutable.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -1,29 +0,0 @@
-package org.hibernate.test.instrument.runtime;
-
-import org.hibernate.SessionFactory;
-import org.hibernate.test.instrument.runtime.Executable;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
-
-/**
- * @author Steve Ebersole
- */
-public abstract class AbstractExecutable implements Executable {
-
- private SessionFactory factory;
-
- public void prepare() {
- factory = new Configuration()
- .setProperty( Environment.HBM2DDL_AUTO, "create-drop" )
- .addResource( "org/hibernate/test/instrument/domain/Documents.hbm.xml" )
- .buildSessionFactory();
- }
-
- public void complete() {
- factory.close();
- }
-
- protected SessionFactory getFactory() {
- return factory;
- }
-}
Modified: trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractTransformingClassLoaderInstrumentTestCase.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractTransformingClassLoaderInstrumentTestCase.java 2006-08-11 18:38:39 UTC (rev 10245)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/AbstractTransformingClassLoaderInstrumentTestCase.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -22,10 +22,11 @@
new BasicClassFilter( new String[] { "org.hibernate.test.instrument" }, null ),
new FieldFilter() {
public boolean shouldInstrumentField(String className, String fieldName) {
- return true;
+ return className.startsWith( "org.hibernate.test.instrument.domain" );
}
public boolean shouldTransformFieldAccess(String transformingClassName, String fieldOwnerClassName, String fieldName) {
- return true;
+ return fieldOwnerClassName.startsWith( "org.hibernate.test.instrument.domain" )
+ && transformingClassName.equals( fieldOwnerClassName );
}
}
)
@@ -42,30 +43,35 @@
// the tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public void testSetFieldInterceptor() {
- executeExecutable( "org.hibernate.test.instrument.runtime.TestInjectFieldInterceptorExecutable" );
+ executeExecutable( "org.hibernate.test.instrument.cases.TestInjectFieldInterceptorExecutable" );
}
public void testDirtyCheck() {
- executeExecutable( "org.hibernate.test.instrument.runtime.TestDirtyCheckExecutable" );
+ executeExecutable( "org.hibernate.test.instrument.cases.TestDirtyCheckExecutable" );
}
public void testFetchAll() throws Exception {
- executeExecutable( "org.hibernate.test.instrument.runtime.TestFetchAllExecutable" );
+ executeExecutable( "org.hibernate.test.instrument.cases.TestFetchAllExecutable" );
}
public void testLazy() {
- executeExecutable( "org.hibernate.test.instrument.runtime.TestLazyExecutable" );
+ executeExecutable( "org.hibernate.test.instrument.cases.TestLazyExecutable" );
}
public void testLazyManyToOne() {
- executeExecutable( "org.hibernate.test.instrument.runtime.TestLazyManyToOneExecutable" );
+ executeExecutable( "org.hibernate.test.instrument.cases.TestLazyManyToOneExecutable" );
}
public void testPropertyInitialized() {
- executeExecutable( "org.hibernate.test.instrument.runtime.TestIsPropertyInitializedExecutable" );
+ executeExecutable( "org.hibernate.test.instrument.cases.TestIsPropertyInitializedExecutable" );
}
+ public void testManyToOneProxy() {
+ executeExecutable( "org.hibernate.test.instrument.cases.TestManyToOneProxyExecutable" );
+ }
+
+
// reflection code to ensure isolation into the created classloader ~~~~~~~
private static final Class[] SIG = new Class[] {};
Deleted: trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/Executable.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/Executable.java 2006-08-11 18:38:39 UTC (rev 10245)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/Executable.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -1,10 +0,0 @@
-package org.hibernate.test.instrument.runtime;
-
-/**
- * @author Steve Ebersole
- */
-public interface Executable {
- public void prepare();
- public void execute();
- public void complete();
-}
Modified: trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/JavassistInstrumentationTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/JavassistInstrumentationTest.java 2006-08-11 18:38:39 UTC (rev 10245)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/JavassistInstrumentationTest.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -17,4 +17,32 @@
public static Test suite() {
return new TestSuite( JavassistInstrumentationTest.class );
}
+
+ public void testSetFieldInterceptor() {
+ super.testSetFieldInterceptor();
+ }
+
+ public void testDirtyCheck() {
+ super.testDirtyCheck();
+ }
+
+ public void testFetchAll() throws Exception {
+ super.testFetchAll();
+ }
+
+ public void testLazy() {
+ super.testLazy();
+ }
+
+ public void testLazyManyToOne() {
+ super.testLazyManyToOne();
+ }
+
+ public void testPropertyInitialized() {
+ super.testPropertyInitialized();
+ }
+
+ public void testManyToOneProxy() {
+ super.testManyToOneProxy();
+ }
}
Deleted: trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestDirtyCheckExecutable.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestDirtyCheckExecutable.java 2006-08-11 18:38:39 UTC (rev 10245)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestDirtyCheckExecutable.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -1,50 +0,0 @@
-package org.hibernate.test.instrument.runtime;
-
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.test.instrument.runtime.AbstractExecutable;
-import org.hibernate.test.instrument.domain.Folder;
-
-import java.util.List;
-import java.util.Iterator;
-
-import junit.framework.Assert;
-
-/**
- * @author Steve Ebersole
- */
-public class TestDirtyCheckExecutable extends AbstractExecutable {
- public void execute() {
- Session s = getFactory().openSession();
- Transaction t = s.beginTransaction();
- Folder pics = new Folder();
- pics.setName("pics");
- Folder docs = new Folder();
- docs.setName("docs");
- s.persist(docs);
- s.persist(pics);
- t.commit();
- s.close();
-
- s = getFactory().openSession();
- t = s.beginTransaction();
- List list = s.createCriteria(Folder.class).list();
- for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
- Folder f = (Folder) iter.next();
- Assert.assertFalse( f.nameWasread );
- }
- t.commit();
- s.close();
-
- for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
- Folder f = (Folder) iter.next();
- Assert.assertFalse( f.nameWasread );
- }
-
- s = getFactory().openSession();
- t = s.beginTransaction();
- s.createQuery("delete from Folder").executeUpdate();
- t.commit();
- s.close();
- }
-}
Deleted: trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestFetchAllExecutable.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestFetchAllExecutable.java 2006-08-11 18:38:39 UTC (rev 10245)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestFetchAllExecutable.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -1,47 +0,0 @@
-package org.hibernate.test.instrument.runtime;
-
-import org.hibernate.Session;
-import org.hibernate.Hibernate;
-import org.hibernate.Transaction;
-import org.hibernate.test.instrument.domain.Owner;
-import org.hibernate.test.instrument.domain.Document;
-import org.hibernate.test.instrument.domain.Folder;
-import junit.framework.Assert;
-
-/**
- * @author Steve Ebersole
- */
-public class TestFetchAllExecutable extends AbstractExecutable {
- public void execute() {
- Session s = getFactory().openSession();
- Transaction t = s.beginTransaction();
- Owner o = new Owner();
- Document doc = new Document();
- Folder fol = new Folder();
- o.setName("gavin");
- doc.setName("Hibernate in Action");
- doc.setSummary("blah");
- doc.updateText("blah blah");
- fol.setName("books");
- doc.setOwner(o);
- doc.setFolder(fol);
- fol.getDocuments().add(doc);
- s.persist(o);
- s.persist(fol);
- t.commit();
- s.close();
-
- s = getFactory().openSession();
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document fetch all properties").uniqueResult();
- Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "summary" ) );
- Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );
- Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "owner" ) );
- Assert.assertEquals( doc.getSummary(), "blah" );
- s.delete(doc);
- s.delete( doc.getOwner() );
- s.delete( doc.getFolder() );
- t.commit();
- s.close();
- }
-}
Deleted: trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestInjectFieldInterceptorExecutable.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestInjectFieldInterceptorExecutable.java 2006-08-11 18:38:39 UTC (rev 10245)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestInjectFieldInterceptorExecutable.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -1,17 +0,0 @@
-package org.hibernate.test.instrument.runtime;
-
-import org.hibernate.test.instrument.domain.Document;
-import org.hibernate.intercept.FieldInterceptionHelper;
-
-import java.util.HashSet;
-
-/**
- * @author Steve Ebersole
- */
-public class TestInjectFieldInterceptorExecutable extends AbstractExecutable {
- public void execute() {
- Document doc = new Document();
- FieldInterceptionHelper.injectFieldInterceptor( doc, "Document", new HashSet(), null );
- doc.getId();
- }
-}
Deleted: trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestIsPropertyInitializedExecutable.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestIsPropertyInitializedExecutable.java 2006-08-11 18:38:39 UTC (rev 10245)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestIsPropertyInitializedExecutable.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -1,48 +0,0 @@
-//$Id: $
-package org.hibernate.test.instrument.runtime;
-
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.Hibernate;
-import org.hibernate.test.instrument.domain.Owner;
-import org.hibernate.test.instrument.domain.Document;
-import org.hibernate.test.instrument.domain.Folder;
-import junit.framework.Assert;
-
-/**
- * @author Steve Ebersole
- */
-public class TestIsPropertyInitializedExecutable extends AbstractExecutable {
- public void execute() {
- Session s = getFactory().openSession();
- Transaction t = s.beginTransaction();
- Owner o = new Owner();
- Document doc = new Document();
- Folder fol = new Folder();
- o.setName("gavin");
- doc.setName("Hibernate in Action");
- doc.setSummary("blah");
- doc.updateText("blah blah");
- fol.setName("books");
- doc.setOwner(o);
- doc.setFolder(fol);
- fol.getDocuments().add(doc);
- Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "summary" ) );
- s.persist(o);
- s.persist(fol);
- t.commit();
- s.close();
-
- s = getFactory().openSession();
- t = s.beginTransaction();
- doc = (Document) s.get( Document.class, doc.getId() );
- Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "summary" ) );
- Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );
- Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "owner" ) );
- s.delete(doc);
- s.delete( doc.getOwner() );
- s.delete( doc.getFolder() );
- t.commit();
- s.close();
- }
-}
Deleted: trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyExecutable.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyExecutable.java 2006-08-11 18:38:39 UTC (rev 10245)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyExecutable.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -1,197 +0,0 @@
-package org.hibernate.test.instrument.runtime;
-
-import org.hibernate.test.TestCase;
-import org.hibernate.test.instrument.runtime.AbstractExecutable;
-import org.hibernate.test.instrument.domain.Owner;
-import org.hibernate.test.instrument.domain.Document;
-import org.hibernate.test.instrument.domain.Folder;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.Hibernate;
-import org.hibernate.LockMode;
-import org.hibernate.CacheMode;
-import org.hibernate.SessionFactory;
-
-/**
- * @author Steve Ebersole
- */
-public class TestLazyExecutable extends AbstractExecutable {
- public void execute() {
- SessionFactory factory = getFactory();
- Session s = factory.openSession();
- Transaction t = s.beginTransaction();
- Owner o = new Owner();
- Document doc = new Document();
- Folder fol = new Folder();
- o.setName("gavin");
- doc.setName("Hibernate in Action");
- doc.setSummary("blah");
- doc.updateText("blah blah");
- fol.setName("books");
- doc.setOwner(o);
- doc.setFolder(fol);
- fol.getDocuments().add(doc);
- s.save(o);
- s.save(fol);
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = ( Document ) s.get( Document.class, doc.getId() );
- TestCase.assertTrue( Hibernate.isPropertyInitialized(doc, "weirdProperty"));
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "name"));
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "folder"));
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "owner"));
- doc.getUpperCaseName(); // should force initialization
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "folder"));
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "owner"));
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- doc.getName();
- TestCase.assertEquals( doc.getText(), "blah blah" );
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- doc.getName();
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "summary"));
- TestCase.assertEquals( doc.getText(), "blah blah" );
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "summary"));
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- doc.setName("HiA");
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- TestCase.assertEquals( doc.getName(), "HiA" );
- TestCase.assertEquals( doc.getText(), "blah blah" );
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- doc.getText();
- doc.setName("HiA second edition");
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "name"));
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "owner"));
- TestCase.assertEquals( doc.getName(), "HiA second edition" );
- TestCase.assertEquals( doc.getText(), "blah blah" );
- TestCase.assertEquals( doc.getUpperCaseName(), "HIA SECOND EDITION" );
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- t.commit();
- s.close();
-
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- s.lock(doc, LockMode.NONE);
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- TestCase.assertEquals( doc.getText(), "blah blah" );
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- t.commit();
- s.close();
-
- doc.setName("HiA2");
-
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- s.saveOrUpdate(doc);
- s.flush();
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- TestCase.assertEquals( doc.getText(), "blah blah" );
- TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
- doc.updateText("blah blah blah blah");
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = ( Document ) s.createQuery("from Document").uniqueResult();
- TestCase.assertEquals( doc.getName(), "HiA2" );
- TestCase.assertEquals( doc.getText(), "blah blah blah blah" );
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.load( Document.class, doc.getId() );
- doc.getName();
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
- TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "summary"));
- t.commit();
- s.close();
-
- s = factory.openSession();
- s.setCacheMode( CacheMode.IGNORE );
- t = s.beginTransaction();
- doc = (Document) s.createQuery("from Document").uniqueResult();
- //s.delete(doc);
- s.delete( doc.getFolder() );
- s.delete( doc.getOwner() );
- s.flush();
- t.commit();
- s.close();
- }
-
-}
Deleted: trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyManyToOneExecutable.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyManyToOneExecutable.java 2006-08-11 18:38:39 UTC (rev 10245)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/runtime/TestLazyManyToOneExecutable.java 2006-08-11 18:39:47 UTC (rev 10246)
@@ -1,73 +0,0 @@
-package org.hibernate.test.instrument.runtime;
-
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.Hibernate;
-import org.hibernate.test.instrument.domain.Owner;
-import org.hibernate.test.instrument.domain.Document;
-import org.hibernate.test.instrument.domain.Folder;
-import junit.framework.Assert;
-
-/**
- * @author Steve Ebersole
- */
-public class TestLazyManyToOneExecutable extends AbstractExecutable {
- public void execute() {
- Session s = getFactory().openSession();
- Transaction t = s.beginTransaction();
- Owner gavin = new Owner();
- Document hia = new Document();
- Folder fol = new Folder();
- gavin.setName("gavin");
- hia.setName("Hibernate in Action");
- hia.setSummary("blah");
- hia.updateText("blah blah");
- fol.setName("books");
- hia.setOwner(gavin);
- hia.setFolder(fol);
- fol.getDocuments().add(hia);
- s.persist(gavin);
- s.persist(fol);
- t.commit();
- s.close();
-
- s = getFactory().openSession();
- t = s.beginTransaction();
- hia = (Document) s.createCriteria(Document.class).uniqueResult();
- Assert.assertEquals( hia.getFolder().getClass(), Folder.class);
- fol = hia.getFolder();
- Assert.assertTrue( Hibernate.isInitialized(fol) );
- t.commit();
- s.close();
-
- s = getFactory().openSession();
- t = s.beginTransaction();
- hia = (Document) s.createCriteria(Document.class).uniqueResult();
- Assert.assertSame( hia.getFolder(), s.load(Folder.class, fol.getId()) );
- Assert.assertTrue( Hibernate.isInitialized( hia.getFolder() ) );
- t.commit();
- s.close();
-
- s = getFactory().openSession();
- t = s.beginTransaction();
- fol = (Folder) s.get(Folder.class, fol.getId());
- hia = (Document) s.createCriteria(Document.class).uniqueResult();
- Assert.assertSame( fol, hia.getFolder() );
- fol = hia.getFolder();
- Assert.assertTrue( Hibernate.isInitialized(fol) );
- t.commit();
- s.close();
-
- s = getFactory().openSession();
- t = s.beginTransaction();
- fol = (Folder) s.load(Folder.class, fol.getId());
- hia = (Document) s.createCriteria(Document.class).uniqueResult();
- Assert.assertNotSame( fol, hia.getFolder() );
- fol = hia.getFolder();
- Assert.assertTrue( Hibernate.isInitialized(fol) );
- s.delete(hia.getFolder());
- s.delete(hia.getOwner());
- t.commit();
- s.close();
- }
-}
17 years, 9 months
Hibernate SVN: r10245 - trunk/Hibernate3/src/org/hibernate/mapping
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-08-11 14:38:39 -0400 (Fri, 11 Aug 2006)
New Revision: 10245
Modified:
trunk/Hibernate3/src/org/hibernate/mapping/Property.java
Log:
HHH-1740 : many-to-one (and one-to-one) with lazy="proxy" and bytecode instrumentation
Modified: trunk/Hibernate3/src/org/hibernate/mapping/Property.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/mapping/Property.java 2006-08-11 18:33:27 UTC (rev 10244)
+++ trunk/Hibernate3/src/org/hibernate/mapping/Property.java 2006-08-11 18:38:39 UTC (rev 10245)
@@ -201,6 +201,17 @@
// interception. So we need to make sure that we return
// true here for the case of many-to-one and one-to-one
// with lazy="no-proxy"
+ //
+ // * impl note - lazy="no-proxy" currently forces both
+ // lazy and unwrap to be set to true. The other case we
+ // are extremely interested in here is that of lazy="proxy"
+ // where lazy is set to true, but unwrap is set to false.
+ // thus we use both here under the assumption that this
+ // return is really only ever used during persister
+ // construction to determine the lazy property/field fetch
+ // groupings. If that assertion changes then this check
+ // needs to change as well. Partially, this is an issue with
+ // the overloading of the term "lazy" here...
ToOne toOneValue = ( ToOne ) value;
return toOneValue.isLazy() && toOneValue.isUnwrapProxy();
}
17 years, 9 months
Hibernate SVN: r10244 - trunk/Hibernate3/src/org/hibernate/mapping
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-08-11 14:33:27 -0400 (Fri, 11 Aug 2006)
New Revision: 10244
Modified:
trunk/Hibernate3/src/org/hibernate/mapping/Property.java
Log:
HHH-1740 : many-to-one (and one-to-one) with lazy="proxy" and bytecode instrumentation
Modified: trunk/Hibernate3/src/org/hibernate/mapping/Property.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/mapping/Property.java 2006-08-11 04:58:44 UTC (rev 10243)
+++ trunk/Hibernate3/src/org/hibernate/mapping/Property.java 2006-08-11 18:33:27 UTC (rev 10244)
@@ -201,7 +201,8 @@
// interception. So we need to make sure that we return
// true here for the case of many-to-one and one-to-one
// with lazy="no-proxy"
- return ( ( ToOne ) value ).isLazy();
+ ToOne toOneValue = ( ToOne ) value;
+ return toOneValue.isLazy() && toOneValue.isUnwrapProxy();
}
return lazy;
}
17 years, 9 months