Hibernate SVN: r11124 - branches/Branch_3_2/Hibernate3/src/org/hibernate/id.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-01-31 18:46:25 -0500 (Wed, 31 Jan 2007)
New Revision: 11124
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/id/TableHiLoGenerator.java
Log:
HHH-2397 : TableHiLo overflow
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/id/TableHiLoGenerator.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/id/TableHiLoGenerator.java 2007-01-31 23:46:11 UTC (rev 11123)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/id/TableHiLoGenerator.java 2007-01-31 23:46:25 UTC (rev 11124)
@@ -50,15 +50,16 @@
returnClass = type.getReturnedClass();
}
- public synchronized Serializable generate(SessionImplementor session, Object obj)
+ public synchronized Serializable generate(SessionImplementor session, Object obj)
throws HibernateException {
if (maxLo < 1) {
//keep the behavior consistent even for boundary usages
- int val = ( (Integer) super.generate(session, obj) ).intValue();
+ long val = ( (Number) super.generate(session, obj) ).longValue();
+ if (val == 0) val = ( (Number) super.generate(session, obj) ).longValue();
return IdentifierGeneratorFactory.createNumber( val, returnClass );
}
if (lo>maxLo) {
- int hival = ( (Integer) super.generate(session, obj) ).intValue();
+ long hival = ( (Number) super.generate(session, obj) ).longValue();
lo = (hival == 0) ? 1 : 0;
hi = hival * (maxLo+1);
log.debug("new hi value: " + hival);
17 years, 10 months
Hibernate SVN: r11123 - trunk/Hibernate3/src/org/hibernate/id.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-01-31 18:46:11 -0500 (Wed, 31 Jan 2007)
New Revision: 11123
Modified:
trunk/Hibernate3/src/org/hibernate/id/TableHiLoGenerator.java
Log:
HHH-2393 : generated properties resultset
Modified: trunk/Hibernate3/src/org/hibernate/id/TableHiLoGenerator.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/id/TableHiLoGenerator.java 2007-01-31 20:16:47 UTC (rev 11122)
+++ trunk/Hibernate3/src/org/hibernate/id/TableHiLoGenerator.java 2007-01-31 23:46:11 UTC (rev 11123)
@@ -54,11 +54,12 @@
throws HibernateException {
if (maxLo < 1) {
//keep the behavior consistent even for boundary usages
- int val = ( (Integer) super.generate(session, obj) ).intValue();
+ long val = ( (Number) super.generate(session, obj) ).longValue();
+ if (val == 0) val = ( (Number) super.generate(session, obj) ).longValue();
return IdentifierGeneratorFactory.createNumber( val, returnClass );
}
if (lo>maxLo) {
- int hival = ( (Integer) super.generate(session, obj) ).intValue();
+ long hival = ( (Number) super.generate(session, obj) ).longValue();
lo = (hival == 0) ? 1 : 0;
hi = hival * (maxLo+1);
log.debug("new hi value: " + hival);
17 years, 10 months
Hibernate SVN: r11118 - in trunk/Hibernate3/src/org/hibernate: persister/entity and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-01-30 23:51:36 -0500 (Tue, 30 Jan 2007)
New Revision: 11118
Modified:
trunk/Hibernate3/src/org/hibernate/jdbc/AbstractBatcher.java
trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
Log:
HHH-2393 : generated properties resultset
Modified: trunk/Hibernate3/src/org/hibernate/jdbc/AbstractBatcher.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/jdbc/AbstractBatcher.java 2007-01-31 04:51:09 UTC (rev 11117)
+++ trunk/Hibernate3/src/org/hibernate/jdbc/AbstractBatcher.java 2007-01-31 04:51:36 UTC (rev 11118)
@@ -197,16 +197,16 @@
}
public void closeQueryStatement(PreparedStatement ps, ResultSet rs) throws SQLException {
- statementsToClose.remove(ps);
- if (rs!=null) resultSetsToClose.remove(rs);
+ statementsToClose.remove( ps );
try {
- if (rs!=null) {
+ if ( rs != null ) {
+ resultSetsToClose.remove( rs );
logCloseResults();
rs.close();
}
}
finally {
- closeQueryStatement(ps);
+ closeQueryStatement( ps );
}
}
Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2007-01-31 04:51:09 UTC (rev 11117)
+++ trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2007-01-31 04:51:36 UTC (rev 11118)
@@ -3692,30 +3692,26 @@
try {
PreparedStatement ps = session.getBatcher().prepareSelectStatement( selectionSQL );
+ ResultSet rs = null;
try {
getIdentifierType().nullSafeSet( ps, id, 1, session );
- ResultSet rs = session.getBatcher().getResultSet( ps );
- try {
- if ( !rs.next() ) {
- throw new HibernateException(
- "Unable to locate row for retrieval of generated properties: " +
- MessageHelper.infoString( this, id, getFactory() )
- );
+ rs = session.getBatcher().getResultSet( ps );
+ if ( !rs.next() ) {
+ throw new HibernateException(
+ "Unable to locate row for retrieval of generated properties: " +
+ MessageHelper.infoString( this, id, getFactory() )
+ );
+ }
+ for ( int i = 0; i < getPropertySpan(); i++ ) {
+ if ( includeds[i] != ValueInclusion.NONE ) {
+ Object hydratedState = getPropertyTypes()[i].hydrate( rs, getPropertyAliases( "", i ), session, entity );
+ state[i] = getPropertyTypes()[i].resolve( hydratedState, session, entity );
+ setPropertyValue( entity, i, state[i], session.getEntityMode() );
}
- for ( int i = 0; i < getPropertySpan(); i++ ) {
- if ( includeds[i] != ValueInclusion.NONE ) {
- Object hydratedState = getPropertyTypes()[i].hydrate( rs, getPropertyAliases( "", i ), session, entity );
- state[i] = getPropertyTypes()[i].resolve( hydratedState, session, entity );
- setPropertyValue( entity, i, state[i], session.getEntityMode() );
- }
- }
}
- finally {
- rs.close();
- }
}
finally {
- session.getBatcher().closeStatement(ps);
+ session.getBatcher().closeQueryStatement( ps, rs );
}
}
catch( SQLException sqle ) {
17 years, 10 months
Hibernate SVN: r11117 - in branches/Branch_3_2/Hibernate3/src/org/hibernate: persister/entity and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-01-30 23:51:09 -0500 (Tue, 30 Jan 2007)
New Revision: 11117
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/AbstractBatcher.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
Log:
HHH-2393 : generated properties resultset
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/AbstractBatcher.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/AbstractBatcher.java 2007-01-30 14:30:55 UTC (rev 11116)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/AbstractBatcher.java 2007-01-31 04:51:09 UTC (rev 11117)
@@ -197,16 +197,16 @@
}
public void closeQueryStatement(PreparedStatement ps, ResultSet rs) throws SQLException {
- statementsToClose.remove(ps);
- if (rs!=null) resultSetsToClose.remove(rs);
+ statementsToClose.remove( ps );
try {
- if (rs!=null) {
+ if ( rs != null ) {
+ resultSetsToClose.remove( rs );
logCloseResults();
rs.close();
}
}
finally {
- closeQueryStatement(ps);
+ closeQueryStatement( ps );
}
}
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2007-01-30 14:30:55 UTC (rev 11116)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2007-01-31 04:51:09 UTC (rev 11117)
@@ -3692,30 +3692,26 @@
try {
PreparedStatement ps = session.getBatcher().prepareSelectStatement( selectionSQL );
+ ResultSet rs = null;
try {
getIdentifierType().nullSafeSet( ps, id, 1, session );
- ResultSet rs = session.getBatcher().getResultSet( ps );
- try {
- if ( !rs.next() ) {
- throw new HibernateException(
- "Unable to locate row for retrieval of generated properties: " +
- MessageHelper.infoString( this, id, getFactory() )
- );
+ rs = session.getBatcher().getResultSet( ps );
+ if ( !rs.next() ) {
+ throw new HibernateException(
+ "Unable to locate row for retrieval of generated properties: " +
+ MessageHelper.infoString( this, id, getFactory() )
+ );
+ }
+ for ( int i = 0; i < getPropertySpan(); i++ ) {
+ if ( includeds[i] != ValueInclusion.NONE ) {
+ Object hydratedState = getPropertyTypes()[i].hydrate( rs, getPropertyAliases( "", i ), session, entity );
+ state[i] = getPropertyTypes()[i].resolve( hydratedState, session, entity );
+ setPropertyValue( entity, i, state[i], session.getEntityMode() );
}
- for ( int i = 0; i < getPropertySpan(); i++ ) {
- if ( includeds[i] != ValueInclusion.NONE ) {
- Object hydratedState = getPropertyTypes()[i].hydrate( rs, getPropertyAliases( "", i ), session, entity );
- state[i] = getPropertyTypes()[i].resolve( hydratedState, session, entity );
- setPropertyValue( entity, i, state[i], session.getEntityMode() );
- }
- }
}
- finally {
- rs.close();
- }
}
finally {
- session.getBatcher().closeStatement(ps);
+ session.getBatcher().closeQueryStatement( ps, rs );
}
}
catch( SQLException sqle ) {
17 years, 10 months
Hibernate SVN: r11116 - in trunk/Hibernate3/src/org/hibernate: loader/hql and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-01-30 09:30:55 -0500 (Tue, 30 Jan 2007)
New Revision: 11116
Modified:
trunk/Hibernate3/src/org/hibernate/loader/criteria/CriteriaLoader.java
trunk/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java
trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
trunk/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java
trunk/Hibernate3/src/org/hibernate/persister/entity/Lockable.java
Log:
HHH-2392 : HQL/Criteria + lockmode (joined-subclass)
Modified: trunk/Hibernate3/src/org/hibernate/loader/criteria/CriteriaLoader.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/loader/criteria/CriteriaLoader.java 2007-01-30 14:29:39 UTC (rev 11115)
+++ trunk/Hibernate3/src/org/hibernate/loader/criteria/CriteriaLoader.java 2007-01-30 14:30:55 UTC (rev 11116)
@@ -21,6 +21,7 @@
import org.hibernate.loader.OuterJoinLoader;
import org.hibernate.persister.entity.Loadable;
import org.hibernate.persister.entity.OuterJoinLoadable;
+import org.hibernate.persister.entity.Lockable;
import org.hibernate.transform.ResultTransformer;
import org.hibernate.type.Type;
@@ -125,16 +126,18 @@
return sqlSelectString;
}
- Map keyColumnNames = null;
- Loadable[] persisters = getEntityPersisters();
- String[] entityAliases = getAliases();
- if ( dialect.forUpdateOfColumns() ) {
- keyColumnNames = new HashMap();
- for ( int i=0; i<entityAliases.length; i++ ) {
- keyColumnNames.put( entityAliases[i], persisters[i].getIdentifierColumnNames() );
+ final Map aliasedLockModes = new HashMap();
+ final Map keyColumnNames = dialect.forUpdateOfColumns() ? new HashMap() : null;
+ final String[] drivingSqlAliases = getAliases();
+ for ( int i = 0; i < drivingSqlAliases.length; i++ ) {
+ final Lockable drivingPersister = ( Lockable ) getEntityPersisters()[i];
+ final String sqlAlias = drivingPersister.getRootTableAlias( drivingSqlAliases[i] );
+ aliasedLockModes.put( sqlAlias, lockModes.get( drivingSqlAliases[i] ) );
+ if ( keyColumnNames != null ) {
+ keyColumnNames.put( sqlAlias, drivingPersister.getRootTableIdentifierColumnNames() );
}
}
- return dialect.applyLocksToSql( sqlSelectString, lockModes, keyColumnNames );
+ return dialect.applyLocksToSql( sqlSelectString, aliasedLockModes, keyColumnNames );
}
protected LockMode[] getLockModes(Map lockModes) {
Modified: trunk/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java 2007-01-30 14:29:39 UTC (rev 11115)
+++ trunk/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java 2007-01-30 14:30:55 UTC (rev 11116)
@@ -23,6 +23,7 @@
import org.hibernate.hql.ast.QueryTranslatorImpl;
import org.hibernate.hql.ast.tree.FromElement;
import org.hibernate.hql.ast.tree.SelectClause;
+import org.hibernate.hql.ast.tree.QueryNode;
import org.hibernate.impl.IteratorImpl;
import org.hibernate.loader.BasicLoader;
import org.hibernate.param.ParameterSpecification;
@@ -30,6 +31,7 @@
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.entity.Loadable;
import org.hibernate.persister.entity.Queryable;
+import org.hibernate.persister.entity.Lockable;
import org.hibernate.transform.ResultTransformer;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
@@ -280,34 +282,35 @@
if ( lockModes == null || lockModes.size() == 0 ) {
return sql;
}
- else {
- // can't cache this stuff either (per-invocation)
- //we are given a map of user alias -> lock mode
- //create a new map of sql alias -> lock mode
- final Map aliasedLockModes = new HashMap();
- final Iterator iter = lockModes.entrySet().iterator();
- while ( iter.hasNext() ) {
- Map.Entry me = ( Map.Entry ) iter.next();
- final String userAlias = ( String ) me.getKey();
- final String sqlAlias = (String) sqlAliasByEntityAlias.get( userAlias );
- if (sqlAlias==null) {
- throw new IllegalArgumentException("alias not found: " + userAlias);
- }
- aliasedLockModes.put( sqlAlias, me.getValue() );
- }
- //if necessary, create a map of sql alias -> key columns
- Map keyColumnNames = null;
- if ( dialect.forUpdateOfColumns() ) {
- final Loadable[] persisters = getEntityPersisters();
- keyColumnNames = new HashMap();
- for ( int i = 0; i < sqlAliases.length; i++ ) {
- keyColumnNames.put( sqlAliases[i], persisters[i].getIdentifierColumnNames() );
- }
+ // can't cache this stuff either (per-invocation)
+ // we are given a map of user-alias -> lock mode
+ // create a new map of sql-alias -> lock mode
+ final Map aliasedLockModes = new HashMap();
+ final Map keyColumnNames = dialect.forUpdateOfColumns() ? new HashMap() : null;
+ final Iterator iter = lockModes.entrySet().iterator();
+ while ( iter.hasNext() ) {
+ Map.Entry me = ( Map.Entry ) iter.next();
+ final String userAlias = ( String ) me.getKey();
+ final String drivingSqlAlias = ( String ) sqlAliasByEntityAlias.get( userAlias );
+ if ( drivingSqlAlias == null ) {
+ throw new IllegalArgumentException( "could not locate alias to apply lock mode : " + userAlias );
}
-
- return dialect.applyLocksToSql( sql, aliasedLockModes, keyColumnNames );
+ // at this point we have (drivingSqlAlias) the SQL alias of the driving table
+ // corresponding to the given user alias. However, the driving table is not
+ // (necessarily) the table against which we want to apply locks. Mainly,
+ // the exception case here is joined-subclass hierarchies where we instead
+ // want to apply the lock against the root table (for all other strategies,
+ // it just happens that driving and root are the same).
+ final QueryNode select = ( QueryNode ) queryTranslator.getSqlAST();
+ final Lockable drivingPersister = ( Lockable ) select.getFromClause().getFromElement( userAlias ).getQueryable();
+ final String sqlAlias = drivingPersister.getRootTableAlias( drivingSqlAlias );
+ aliasedLockModes.put( sqlAlias, me.getValue() );
+ if ( keyColumnNames != null ) {
+ keyColumnNames.put( sqlAlias, drivingPersister.getRootTableIdentifierColumnNames() );
+ }
}
+ return dialect.applyLocksToSql( sql, aliasedLockModes, keyColumnNames );
}
protected boolean upgradeLocks() {
Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2007-01-30 14:29:39 UTC (rev 11115)
+++ trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2007-01-30 14:30:55 UTC (rev 11116)
@@ -1338,6 +1338,10 @@
return getSubclassTableName( 0 );
}
+ public String getRootTableAlias(String drivingAlias) {
+ return drivingAlias;
+ }
+
public String[] getRootTableIdentifierColumnNames() {
return getRootTableKeyColumnNames();
}
Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java 2007-01-30 14:29:39 UTC (rev 11115)
+++ trunk/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java 2007-01-30 14:30:55 UTC (rev 11116)
@@ -573,6 +573,10 @@
return naturalOrderTableNames[0];
}
+ public String getRootTableAlias(String drivingAlias) {
+ return generateTableAlias( drivingAlias, getTableId( getRootTableName(), tableNames ) );
+ }
+
public Declarer getSubclassPropertyDeclarer(String propertyPath) {
if ( "class".equals( propertyPath ) ) {
// special case where we need to force incloude all subclass joins
Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/Lockable.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/persister/entity/Lockable.java 2007-01-30 14:29:39 UTC (rev 11115)
+++ trunk/Hibernate3/src/org/hibernate/persister/entity/Lockable.java 2007-01-30 14:30:55 UTC (rev 11116)
@@ -1,7 +1,11 @@
package org.hibernate.persister.entity;
/**
- * Contract for things that can be locked via a {@link org.hibernate.dialect.lock.LockingStrategy}
+ * Contract for things that can be locked via a {@link org.hibernate.dialect.lock.LockingStrategy}.
+ * <p/>
+ * Currently only the root table gets locked, except for the case of HQL and Criteria queries
+ * against dialects which do not support either (1) FOR UPDATE OF or (2) support hint locking
+ * (in which case *all* queried tables would be locked).
*
* @author Steve Ebersole
* @since 3.2
@@ -15,6 +19,16 @@
public String getRootTableName();
/**
+ * Get the SQL alias this persister would use for the root table
+ * given the passed driving alias.
+ *
+ * @param drivingAlias The driving alias; or the alias for the table
+ * mapped by this persister in the hierarchy.
+ * @return The root table alias.
+ */
+ public String getRootTableAlias(String drivingAlias);
+
+ /**
* Get the names of columns on the root table used to persist the identifier.
*
* @return The root table identifier column names.
17 years, 10 months
Hibernate SVN: r11115 - in branches/Branch_3_2/Hibernate3/src/org/hibernate: loader/hql and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-01-30 09:29:39 -0500 (Tue, 30 Jan 2007)
New Revision: 11115
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/loader/criteria/CriteriaLoader.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/Lockable.java
Log:
HHH-2392 : HQL/Criteria + lockmode (joined-subclass)
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/loader/criteria/CriteriaLoader.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/loader/criteria/CriteriaLoader.java 2007-01-30 11:30:23 UTC (rev 11114)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/loader/criteria/CriteriaLoader.java 2007-01-30 14:29:39 UTC (rev 11115)
@@ -19,8 +19,8 @@
import org.hibernate.engine.SessionImplementor;
import org.hibernate.impl.CriteriaImpl;
import org.hibernate.loader.OuterJoinLoader;
-import org.hibernate.persister.entity.Loadable;
import org.hibernate.persister.entity.OuterJoinLoadable;
+import org.hibernate.persister.entity.Lockable;
import org.hibernate.transform.ResultTransformer;
import org.hibernate.type.Type;
@@ -125,16 +125,18 @@
return sqlSelectString;
}
- Map keyColumnNames = null;
- Loadable[] persisters = getEntityPersisters();
- String[] entityAliases = getAliases();
- if ( dialect.forUpdateOfColumns() ) {
- keyColumnNames = new HashMap();
- for ( int i=0; i<entityAliases.length; i++ ) {
- keyColumnNames.put( entityAliases[i], persisters[i].getIdentifierColumnNames() );
+ final Map aliasedLockModes = new HashMap();
+ final Map keyColumnNames = dialect.forUpdateOfColumns() ? new HashMap() : null;
+ final String[] drivingSqlAliases = getAliases();
+ for ( int i = 0; i < drivingSqlAliases.length; i++ ) {
+ final Lockable drivingPersister = ( Lockable ) getEntityPersisters()[i];
+ final String sqlAlias = drivingPersister.getRootTableAlias( drivingSqlAliases[i] );
+ aliasedLockModes.put( sqlAlias, lockModes.get( drivingSqlAliases[i] ) );
+ if ( keyColumnNames != null ) {
+ keyColumnNames.put( sqlAlias, drivingPersister.getRootTableIdentifierColumnNames() );
}
}
- return dialect.applyLocksToSql( sqlSelectString, lockModes, keyColumnNames );
+ return dialect.applyLocksToSql( sqlSelectString, aliasedLockModes, keyColumnNames );
}
protected LockMode[] getLockModes(Map lockModes) {
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java 2007-01-30 11:30:23 UTC (rev 11114)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java 2007-01-30 14:29:39 UTC (rev 11115)
@@ -23,6 +23,7 @@
import org.hibernate.hql.ast.QueryTranslatorImpl;
import org.hibernate.hql.ast.tree.FromElement;
import org.hibernate.hql.ast.tree.SelectClause;
+import org.hibernate.hql.ast.tree.QueryNode;
import org.hibernate.impl.IteratorImpl;
import org.hibernate.loader.BasicLoader;
import org.hibernate.param.ParameterSpecification;
@@ -30,6 +31,7 @@
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.entity.Loadable;
import org.hibernate.persister.entity.Queryable;
+import org.hibernate.persister.entity.Lockable;
import org.hibernate.transform.ResultTransformer;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
@@ -280,34 +282,35 @@
if ( lockModes == null || lockModes.size() == 0 ) {
return sql;
}
- else {
- // can't cache this stuff either (per-invocation)
- //we are given a map of user alias -> lock mode
- //create a new map of sql alias -> lock mode
- final Map aliasedLockModes = new HashMap();
- final Iterator iter = lockModes.entrySet().iterator();
- while ( iter.hasNext() ) {
- Map.Entry me = ( Map.Entry ) iter.next();
- final String userAlias = ( String ) me.getKey();
- final String sqlAlias = (String) sqlAliasByEntityAlias.get( userAlias );
- if (sqlAlias==null) {
- throw new IllegalArgumentException("alias not found: " + userAlias);
- }
- aliasedLockModes.put( sqlAlias, me.getValue() );
- }
- //if necessary, create a map of sql alias -> key columns
- Map keyColumnNames = null;
- if ( dialect.forUpdateOfColumns() ) {
- final Loadable[] persisters = getEntityPersisters();
- keyColumnNames = new HashMap();
- for ( int i = 0; i < sqlAliases.length; i++ ) {
- keyColumnNames.put( sqlAliases[i], persisters[i].getIdentifierColumnNames() );
- }
+ // can't cache this stuff either (per-invocation)
+ // we are given a map of user-alias -> lock mode
+ // create a new map of sql-alias -> lock mode
+ final Map aliasedLockModes = new HashMap();
+ final Map keyColumnNames = dialect.forUpdateOfColumns() ? new HashMap() : null;
+ final Iterator iter = lockModes.entrySet().iterator();
+ while ( iter.hasNext() ) {
+ Map.Entry me = ( Map.Entry ) iter.next();
+ final String userAlias = ( String ) me.getKey();
+ final String drivingSqlAlias = ( String ) sqlAliasByEntityAlias.get( userAlias );
+ if ( drivingSqlAlias == null ) {
+ throw new IllegalArgumentException( "could not locate alias to apply lock mode : " + userAlias );
}
-
- return dialect.applyLocksToSql( sql, aliasedLockModes, keyColumnNames );
+ // at this point we have (drivingSqlAlias) the SQL alias of the driving table
+ // corresponding to the given user alias. However, the driving table is not
+ // (necessarily) the table against which we want to apply locks. Mainly,
+ // the exception case here is joined-subclass hierarchies where we instead
+ // want to apply the lock against the root table (for all other strategies,
+ // it just happens that driving and root are the same).
+ final QueryNode select = ( QueryNode ) queryTranslator.getSqlAST();
+ final Lockable drivingPersister = ( Lockable ) select.getFromClause().getFromElement( userAlias ).getQueryable();
+ final String sqlAlias = drivingPersister.getRootTableAlias( drivingSqlAlias );
+ aliasedLockModes.put( sqlAlias, me.getValue() );
+ if ( keyColumnNames != null ) {
+ keyColumnNames.put( sqlAlias, drivingPersister.getRootTableIdentifierColumnNames() );
+ }
}
+ return dialect.applyLocksToSql( sql, aliasedLockModes, keyColumnNames );
}
protected boolean upgradeLocks() {
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2007-01-30 11:30:23 UTC (rev 11114)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2007-01-30 14:29:39 UTC (rev 11115)
@@ -1338,6 +1338,10 @@
return getSubclassTableName( 0 );
}
+ public String getRootTableAlias(String drivingAlias) {
+ return drivingAlias;
+ }
+
public String[] getRootTableIdentifierColumnNames() {
return getRootTableKeyColumnNames();
}
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java 2007-01-30 11:30:23 UTC (rev 11114)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java 2007-01-30 14:29:39 UTC (rev 11115)
@@ -573,6 +573,10 @@
return naturalOrderTableNames[0];
}
+ public String getRootTableAlias(String drivingAlias) {
+ return generateTableAlias( drivingAlias, getTableId( getRootTableName(), tableNames ) );
+ }
+
public Declarer getSubclassPropertyDeclarer(String propertyPath) {
if ( "class".equals( propertyPath ) ) {
// special case where we need to force incloude all subclass joins
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/Lockable.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/Lockable.java 2007-01-30 11:30:23 UTC (rev 11114)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/Lockable.java 2007-01-30 14:29:39 UTC (rev 11115)
@@ -1,7 +1,11 @@
package org.hibernate.persister.entity;
/**
- * Contract for things that can be locked via a {@link org.hibernate.dialect.lock.LockingStrategy}
+ * Contract for things that can be locked via a {@link org.hibernate.dialect.lock.LockingStrategy}.
+ * <p/>
+ * Currently only the root table gets locked, except for the case of HQL and Criteria queries
+ * against dialects which do not support either (1) FOR UPDATE OF or (2) support hint locking
+ * (in which case *all* queried tables would be locked).
*
* @author Steve Ebersole
* @since 3.2
@@ -15,6 +19,16 @@
public String getRootTableName();
/**
+ * Get the SQL alias this persister would use for the root table
+ * given the passed driving alias.
+ *
+ * @param drivingAlias The driving alias; or the alias for the table
+ * mapped by this persister in the hierarchy.
+ * @return The root table alias.
+ */
+ public String getRootTableAlias(String drivingAlias);
+
+ /**
* Get the names of columns on the root table used to persist the identifier.
*
* @return The root table identifier column names.
17 years, 10 months
Hibernate SVN: r11114 - in branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate: search/test/bridge and 8 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-30 06:30:23 -0500 (Tue, 30 Jan 2007)
New Revision: 11114
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/HANTestCase.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/SearchTestCase.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/HANTestCase.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Address.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/MarsAddress.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Martian.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/MartianPk.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Music.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Rock.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Tv.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/TvOwner.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Venusian.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/VenusianPk.java
Removed:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/TestCase.java
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/FSDirectoryTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/RamDirectoryTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/TransactionTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/bridge/BridgeTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/fieldAccess/FieldAccessTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/query/LuceneQueryTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/session/MassIndexTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/AsyncWorkerTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/WorkerTestCase.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/EmbeddedObjectTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/HibernateAnnotationIntegrationTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/NonHibernateAnnotationsIntegrationTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/DigitsTest.java
Log:
Test refactoring to avoid depedencies
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/FSDirectoryTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/FSDirectoryTest.java 2007-01-30 10:17:25 UTC (rev 11113)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/FSDirectoryTest.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -24,7 +24,7 @@
/**
* @author Gavin King
*/
-public class FSDirectoryTest extends TestCase {
+public class FSDirectoryTest extends SearchTestCase {
protected void setUp() throws Exception {
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/HANTestCase.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/HANTestCase.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/HANTestCase.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -0,0 +1,158 @@
+//$Id: $
+package org.hibernate.search.test;
+
+import java.io.InputStream;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.Session;
+import org.hibernate.HibernateException;
+import org.hibernate.Interceptor;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.cfg.Configuration;
+
+/**
+ * copy from HAN
+ * @author Emmanuel Bernard
+ */
+public abstract class HANTestCase extends junit.framework.TestCase {
+
+ private static SessionFactory sessions;
+ private static AnnotationConfiguration cfg;
+ private static Dialect dialect;
+ private static Class lastTestClass;
+ private Session session;
+
+ public HANTestCase() {
+ super();
+ }
+
+ public HANTestCase(String x) {
+ super( x );
+ }
+
+ protected void buildSessionFactory(Class[] classes, String[] packages, String[] xmlFiles) throws Exception {
+
+ if ( getSessions() != null ) getSessions().close();
+ try {
+ setCfg( new AnnotationConfiguration() );
+ configure( cfg );
+ if ( recreateSchema() ) {
+ cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
+ }
+ for ( int i = 0; i < packages.length; i++ ) {
+ getCfg().addPackage( packages[i] );
+ }
+ for ( int i = 0; i < classes.length; i++ ) {
+ getCfg().addAnnotatedClass( classes[i] );
+ }
+ for ( int i = 0; i < xmlFiles.length; i++ ) {
+ InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFiles[i] );
+ getCfg().addInputStream( is );
+ }
+ setDialect( Dialect.getDialect() );
+ setSessions( getCfg().buildSessionFactory( /*new TestInterceptor()*/ ) );
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ protected void setUp() throws Exception {
+ if ( getSessions() == null || lastTestClass != getClass() ) {
+ buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
+ lastTestClass = getClass();
+ }
+ }
+
+ protected void runTest() throws Throwable {
+ try {
+ super.runTest();
+ if ( session != null && session.isOpen() ) {
+ if ( session.isConnected() ) session.connection().rollback();
+ session.close();
+ session = null;
+ fail( "unclosed session" );
+ }
+ else {
+ session = null;
+ }
+ }
+ catch (Throwable e) {
+ try {
+ if ( session != null && session.isOpen() ) {
+ if ( session.isConnected() ) session.connection().rollback();
+ session.close();
+ }
+ }
+ catch (Exception ignore) {
+ }
+ try {
+ if ( sessions != null ) {
+ sessions.close();
+ sessions = null;
+ }
+ }
+ catch (Exception ignore) {
+ }
+ throw e;
+ }
+ }
+
+ public Session openSession() throws HibernateException {
+ session = getSessions().openSession();
+ return session;
+ }
+
+ public Session openSession(Interceptor interceptor) throws HibernateException {
+ session = getSessions().openSession( interceptor );
+ return session;
+ }
+
+ protected abstract Class[] getMappings();
+
+ protected String[] getAnnotatedPackages() {
+ return new String[]{};
+ }
+
+ protected String[] getXmlFiles() {
+ return new String[]{};
+ }
+
+ private void setSessions(SessionFactory sessions) {
+ HANTestCase.sessions = sessions;
+ }
+
+ protected SessionFactory getSessions() {
+ return sessions;
+ }
+
+ private void setDialect(Dialect dialect) {
+ HANTestCase.dialect = dialect;
+ }
+
+ protected Dialect getDialect() {
+ return dialect;
+ }
+
+ protected static void setCfg(AnnotationConfiguration cfg) {
+ HANTestCase.cfg = cfg;
+ }
+
+ protected static AnnotationConfiguration getCfg() {
+ return cfg;
+ }
+
+ protected void configure(Configuration cfg) {
+ //cfg.setNamingStrategy( AlternativeNamingStrategy.INSTANCE );
+ //cfg.getSessionEventListenerConfig().setFlushEventListener( new EJB3FlushEventListener() );
+ //cfg.getSessionEventListenerConfig().setAutoFlushEventListener( new EJB3AutoFlushEventListener() );
+ }
+
+ protected boolean recreateSchema() {
+ return true;
+ }
+
+}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/RamDirectoryTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/RamDirectoryTest.java 2007-01-30 10:17:25 UTC (rev 11113)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/RamDirectoryTest.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -1,23 +1,13 @@
//$Id: $
package org.hibernate.search.test;
-import java.io.File;
-import java.util.List;
-
import org.hibernate.Session;
import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.TermDocs;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.Hits;
-import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
/**
* @author Emmanuel Bernard
*/
-public class RamDirectoryTest extends TestCase {
+public class RamDirectoryTest extends SearchTestCase {
public void testMultipleEntitiesPerIndex() throws Exception {
Copied: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/SearchTestCase.java (from rev 11111, branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/TestCase.java)
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/SearchTestCase.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/SearchTestCase.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -0,0 +1,50 @@
+//$Id: $
+package org.hibernate.search.test;
+
+import org.apache.lucene.analysis.StopAnalyzer;
+import org.apache.lucene.store.Directory;
+import org.hibernate.HibernateException;
+import org.hibernate.event.PostDeleteEventListener;
+import org.hibernate.event.PostInsertEventListener;
+import org.hibernate.event.PostUpdateEventListener;
+import org.hibernate.impl.SessionFactoryImpl;
+import org.hibernate.search.Environment;
+import org.hibernate.search.event.FullTextIndexEventListener;
+import org.hibernate.search.store.RAMDirectoryProvider;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public abstract class SearchTestCase extends HANTestCase {
+ protected void setUp() throws Exception {
+ //super.setUp(); //we need a fresh session factory each time for index set up
+ buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
+ }
+
+ protected Directory getDirectory(Class clazz) {
+ return getLuceneEventListener().getSearchFactory().getDocumentBuilders().get( clazz ).getDirectoryProvider().getDirectory();
+ }
+
+ private FullTextIndexEventListener getLuceneEventListener() {
+ PostInsertEventListener[] listeners = ( (SessionFactoryImpl) getSessions() ).getEventListeners().getPostInsertEventListeners();
+ FullTextIndexEventListener listener = null;
+ //FIXME this sucks since we mandante the event listener use
+ for (PostInsertEventListener candidate : listeners) {
+ if (candidate instanceof FullTextIndexEventListener ) {
+ listener = (FullTextIndexEventListener) candidate;
+ break;
+ }
+ }
+ if (listener == null) throw new HibernateException("Lucene event listener not initialized");
+ return listener;
+ }
+
+ protected void configure(org.hibernate.cfg.Configuration cfg) {
+ cfg.setProperty( "hibernate.search.default.directory_provider", RAMDirectoryProvider.class.getName() );
+ cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
+ //FullTextIndexEventListener del = new FullTextIndexEventListener();
+ cfg.getEventListeners().setPostDeleteEventListeners( new PostDeleteEventListener[]{ new FullTextIndexEventListener() } );
+ cfg.getEventListeners().setPostUpdateEventListeners( new PostUpdateEventListener[]{ new FullTextIndexEventListener() } );
+ cfg.getEventListeners().setPostInsertEventListeners( new PostInsertEventListener[]{ new FullTextIndexEventListener() } );
+ }
+}
Deleted: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/TestCase.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/TestCase.java 2007-01-30 10:17:25 UTC (rev 11113)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/TestCase.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -1,50 +0,0 @@
-//$Id: $
-package org.hibernate.search.test;
-
-import org.apache.lucene.analysis.StopAnalyzer;
-import org.apache.lucene.store.Directory;
-import org.hibernate.event.PostDeleteEventListener;
-import org.hibernate.event.PostInsertEventListener;
-import org.hibernate.event.PostUpdateEventListener;
-import org.hibernate.search.Environment;
-import org.hibernate.search.store.RAMDirectoryProvider;
-import org.hibernate.search.event.FullTextIndexEventListener;
-import org.hibernate.HibernateException;
-import org.hibernate.impl.SessionFactoryImpl;
-
-/**
- * @author Emmanuel Bernard
- */
-public abstract class TestCase extends org.hibernate.test.annotations.TestCase {
- protected void setUp() throws Exception {
- //super.setUp(); //we need a fresh session factory each time for index set up
- buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
- }
-
- protected Directory getDirectory(Class clazz) {
- return getLuceneEventListener().getSearchFactory().getDocumentBuilders().get( clazz ).getDirectoryProvider().getDirectory();
- }
-
- private FullTextIndexEventListener getLuceneEventListener() {
- PostInsertEventListener[] listeners = ( (SessionFactoryImpl) getSessions() ).getEventListeners().getPostInsertEventListeners();
- FullTextIndexEventListener listener = null;
- //FIXME this sucks since we mandante the event listener use
- for (PostInsertEventListener candidate : listeners) {
- if (candidate instanceof FullTextIndexEventListener ) {
- listener = (FullTextIndexEventListener) candidate;
- break;
- }
- }
- if (listener == null) throw new HibernateException("Lucene event listener not initialized");
- return listener;
- }
-
- protected void configure(org.hibernate.cfg.Configuration cfg) {
- cfg.setProperty( "hibernate.search.default.directory_provider", RAMDirectoryProvider.class.getName() );
- cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
- //FullTextIndexEventListener del = new FullTextIndexEventListener();
- cfg.getEventListeners().setPostDeleteEventListeners( new PostDeleteEventListener[]{ new FullTextIndexEventListener() } );
- cfg.getEventListeners().setPostUpdateEventListeners( new PostUpdateEventListener[]{ new FullTextIndexEventListener() } );
- cfg.getEventListeners().setPostInsertEventListeners( new PostInsertEventListener[]{ new FullTextIndexEventListener() } );
- }
-}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/TransactionTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/TransactionTest.java 2007-01-30 10:17:25 UTC (rev 11113)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/TransactionTest.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -9,7 +9,7 @@
/**
* @author Emmanuel Bernard
*/
-public class TransactionTest extends TestCase {
+public class TransactionTest extends SearchTestCase {
public void testTransactionCommit() throws Exception {
Session s = getSessions().openSession();
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/bridge/BridgeTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/bridge/BridgeTest.java 2007-01-30 10:17:25 UTC (rev 11113)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/bridge/BridgeTest.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -10,7 +10,7 @@
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
-import org.hibernate.search.test.TestCase;
+import org.hibernate.search.test.SearchTestCase;
import org.hibernate.search.Environment;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
@@ -22,7 +22,7 @@
/**
* @author Emmanuel Bernard
*/
-public class BridgeTest extends TestCase {
+public class BridgeTest extends SearchTestCase {
public void testDefaultAndNullBridges() throws Exception {
Cloud cloud = new Cloud();
cloud.setDate( null );
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/fieldAccess/FieldAccessTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/fieldAccess/FieldAccessTest.java 2007-01-30 10:17:25 UTC (rev 11113)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/fieldAccess/FieldAccessTest.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -3,7 +3,7 @@
import java.util.List;
-import org.hibernate.search.test.TestCase;
+import org.hibernate.search.test.SearchTestCase;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.hibernate.Session;
@@ -14,7 +14,7 @@
/**
* @author Emmanuel Bernard
*/
-public class FieldAccessTest extends TestCase {
+public class FieldAccessTest extends SearchTestCase {
public void testFields() throws Exception {
Document doc = new Document( "Hibernate in Action", "Object/relational mapping with Hibernate", "blah blah blah" );
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java 2007-01-30 10:17:25 UTC (rev 11113)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -1,7 +1,7 @@
//$Id: $
package org.hibernate.search.test.inheritance;
-import org.hibernate.search.test.TestCase;
+import org.hibernate.search.test.SearchTestCase;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.hibernate.Transaction;
@@ -14,7 +14,7 @@
/**
* @author Emmanuel Bernard
*/
-public class InheritanceTest extends TestCase {
+public class InheritanceTest extends SearchTestCase {
public void testInheritance() throws Exception {
FullTextSession s = Search.createFullTextSession( openSession() );
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/query/LuceneQueryTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/query/LuceneQueryTest.java 2007-01-30 10:17:25 UTC (rev 11113)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/query/LuceneQueryTest.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -4,7 +4,7 @@
import java.util.List;
import java.util.Iterator;
-import org.hibernate.search.test.TestCase;
+import org.hibernate.search.test.SearchTestCase;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.hibernate.Transaction;
@@ -18,7 +18,7 @@
/**
* @author Emmanuel Bernard
*/
-public class LuceneQueryTest extends TestCase {
+public class LuceneQueryTest extends SearchTestCase {
public void testList() throws Exception {
FullTextSession s = Search.createFullTextSession( openSession() );
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/session/MassIndexTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/session/MassIndexTest.java 2007-01-30 10:17:25 UTC (rev 11113)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/session/MassIndexTest.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -3,7 +3,7 @@
import java.util.List;
-import org.hibernate.search.test.TestCase;
+import org.hibernate.search.test.SearchTestCase;
import org.hibernate.search.impl.FullTextSessionImpl;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
@@ -14,7 +14,7 @@
/**
* @author Emmanuel Bernard
*/
-public class MassIndexTest extends TestCase {
+public class MassIndexTest extends SearchTestCase {
public void testTransactional() throws Exception {
FullTextSession s = Search.createFullTextSession( openSession() );
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/AsyncWorkerTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/AsyncWorkerTest.java 2007-01-30 10:17:25 UTC (rev 11113)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/AsyncWorkerTest.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -1,10 +1,6 @@
//$Id: $
package org.hibernate.search.test.worker;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ExecutorService;
-
-import org.hibernate.search.test.TestCase;
import org.hibernate.search.store.RAMDirectoryProvider;
import org.hibernate.search.Environment;
import org.hibernate.search.event.FullTextIndexEventListener;
@@ -12,9 +8,6 @@
import org.hibernate.event.PostDeleteEventListener;
import org.hibernate.event.PostUpdateEventListener;
import org.hibernate.event.PostInsertEventListener;
-import org.hibernate.SessionFactory;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
import org.apache.lucene.analysis.StopAnalyzer;
/**
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/WorkerTestCase.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/WorkerTestCase.java 2007-01-30 10:17:25 UTC (rev 11113)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/WorkerTestCase.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -4,23 +4,15 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import org.hibernate.search.test.TestCase;
-import org.hibernate.search.store.RAMDirectoryProvider;
-import org.hibernate.search.Environment;
-import org.hibernate.search.event.FullTextIndexEventListener;
+import org.hibernate.search.test.SearchTestCase;
import org.hibernate.SessionFactory;
import org.hibernate.Session;
import org.hibernate.Transaction;
-import org.hibernate.event.PostDeleteEventListener;
-import org.hibernate.event.PostUpdateEventListener;
-import org.hibernate.event.PostInsertEventListener;
-import org.hibernate.cfg.Configuration;
-import org.apache.lucene.analysis.StopAnalyzer;
/**
* @author Emmanuel Bernard
*/
-public class WorkerTestCase extends TestCase {
+public class WorkerTestCase extends SearchTestCase {
public void testConcurrency() throws Exception {
ExecutorService es = Executors.newFixedThreadPool( 15 );
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/HANTestCase.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/HANTestCase.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/HANTestCase.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -0,0 +1,160 @@
+//$Id: $
+package org.hibernate.validator.test;
+
+import java.io.InputStream;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.Session;
+import org.hibernate.HibernateException;
+import org.hibernate.Interceptor;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.cfg.Configuration;
+
+/**
+ * Copy from HAN
+ *
+ * @author Emmanuel Bernard
+ */
+public abstract class HANTestCase extends junit.framework.TestCase {
+
+ private static SessionFactory sessions;
+ private static AnnotationConfiguration cfg;
+ private static Dialect dialect;
+ private static Class lastTestClass;
+ private Session session;
+
+ public HANTestCase() {
+ super();
+ }
+
+ public HANTestCase(String x) {
+ super( x );
+ }
+
+ protected void buildSessionFactory(Class[] classes, String[] packages, String[] xmlFiles) throws Exception {
+
+ if ( getSessions() != null ) getSessions().close();
+ try {
+ setCfg( new AnnotationConfiguration() );
+ configure( cfg );
+ if ( recreateSchema() ) {
+ cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
+ }
+ for ( int i = 0; i < packages.length; i++ ) {
+ getCfg().addPackage( packages[i] );
+ }
+ for ( int i = 0; i < classes.length; i++ ) {
+ getCfg().addAnnotatedClass( classes[i] );
+ }
+ for ( int i = 0; i < xmlFiles.length; i++ ) {
+ InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFiles[i] );
+ getCfg().addInputStream( is );
+ }
+ setDialect( Dialect.getDialect() );
+ setSessions( getCfg().buildSessionFactory( /*new TestInterceptor()*/ ) );
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ protected void setUp() throws Exception {
+ if ( getSessions() == null || lastTestClass != getClass() ) {
+ buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
+ lastTestClass = getClass();
+ }
+ }
+
+ protected void runTest() throws Throwable {
+ try {
+ super.runTest();
+ if ( session != null && session.isOpen() ) {
+ if ( session.isConnected() ) session.connection().rollback();
+ session.close();
+ session = null;
+ fail( "unclosed session" );
+ }
+ else {
+ session = null;
+ }
+ }
+ catch (Throwable e) {
+ try {
+ if ( session != null && session.isOpen() ) {
+ if ( session.isConnected() ) session.connection().rollback();
+ session.close();
+ }
+ }
+ catch (Exception ignore) {
+ }
+ try {
+ if ( sessions != null ) {
+ sessions.close();
+ sessions = null;
+ }
+ }
+ catch (Exception ignore) {
+ }
+ throw e;
+ }
+ }
+
+ public Session openSession() throws HibernateException {
+ session = getSessions().openSession();
+ return session;
+ }
+
+ public Session openSession(Interceptor interceptor) throws HibernateException {
+ session = getSessions().openSession( interceptor );
+ return session;
+ }
+
+ protected abstract Class[] getMappings();
+
+ protected String[] getAnnotatedPackages() {
+ return new String[]{};
+ }
+
+ protected String[] getXmlFiles() {
+ return new String[]{};
+ }
+
+ private void setSessions(SessionFactory sessions) {
+ HANTestCase.sessions = sessions;
+ }
+
+ protected SessionFactory getSessions() {
+ return sessions;
+ }
+
+ private void setDialect(Dialect dialect) {
+ HANTestCase.dialect = dialect;
+ }
+
+ protected Dialect getDialect() {
+ return dialect;
+ }
+
+ protected static void setCfg(AnnotationConfiguration cfg) {
+ HANTestCase.cfg = cfg;
+ }
+
+ protected static AnnotationConfiguration getCfg() {
+ return cfg;
+ }
+
+ protected void configure(Configuration cfg) {
+ //cfg.setNamingStrategy( AlternativeNamingStrategy.INSTANCE );
+ //cfg.getSessionEventListenerConfig().setFlushEventListener( new EJB3FlushEventListener() );
+ //cfg.getSessionEventListenerConfig().setAutoFlushEventListener( new EJB3AutoFlushEventListener() );
+ }
+
+ protected boolean recreateSchema() {
+ return true;
+ }
+
+}
+
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Address.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Address.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Address.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -0,0 +1,108 @@
+//$Id: Address.java 9755 2006-04-17 19:44:22Z epbernard $
+package org.hibernate.validator.test.haintegration;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Transient;
+
+import org.hibernate.validator.AssertTrue;
+import org.hibernate.validator.Length;
+import org.hibernate.validator.Min;
+import org.hibernate.validator.NotNull;
+import org.hibernate.validator.Pattern;
+import org.hibernate.validator.Range;
+
+/**
+ * @author Gavin King
+ */
+@Entity
+public class Address {
+ @NotNull
+ public static String blacklistedZipCode;
+
+ private String line1;
+ private String line2;
+ private String zip;
+ private String state;
+ @Length(max = 20)
+ @NotNull
+ private String country;
+ private long id;
+ private boolean internalValid = true;
+ @Range(min = -2, max = 50, message = "{floor.out.of.range} (escaping #{el})")
+ public int floor;
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+ @NotNull
+ public String getLine1() {
+ return line1;
+ }
+
+ public void setLine1(String line1) {
+ this.line1 = line1;
+ }
+
+ public String getLine2() {
+ return line2;
+ }
+
+ public void setLine2(String line2) {
+ this.line2 = line2;
+ }
+
+ @Length(max = 3)
+ @NotNull
+ public String getState() {
+ return state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ @Length(max = 5, message = "{long}")
+ @Pattern(regex = "[0-9]+")
+ @NotNull
+ public String getZip() {
+ return zip;
+ }
+
+ public void setZip(String zip) {
+ this.zip = zip;
+ }
+
+ @AssertTrue
+ @Transient
+ public boolean isValid() {
+ return true;
+ }
+
+ @AssertTrue
+ @Transient
+ private boolean isInternalValid() {
+ return internalValid;
+ }
+
+ public void setInternalValid(boolean internalValid) {
+ this.internalValid = internalValid;
+ }
+
+ @Id
+ @Min(1)
+ @Range(max = 2000)
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/EmbeddedObjectTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/EmbeddedObjectTest.java 2007-01-30 10:17:25 UTC (rev 11113)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/EmbeddedObjectTest.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -3,18 +3,18 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
import org.hibernate.event.PreInsertEventListener;
import org.hibernate.event.PreUpdateEventListener;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.test.annotations.TestCase;
import org.hibernate.validator.ClassValidator;
import org.hibernate.validator.event.ValidatePreInsertEventListener;
import org.hibernate.validator.event.ValidatePreUpdateEventListener;
+import org.hibernate.validator.test.HANTestCase;
/**
* @author Emmanuel Bernard
*/
-public class EmbeddedObjectTest extends TestCase {
+public class EmbeddedObjectTest extends HANTestCase {
public void testNotNullEmbeddedObject() throws Exception {
CreditCard cc = new CreditCard();
User username = new User();
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/HibernateAnnotationIntegrationTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/HibernateAnnotationIntegrationTest.java 2007-01-30 10:17:25 UTC (rev 11113)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/HibernateAnnotationIntegrationTest.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -8,10 +8,10 @@
import org.hibernate.event.PreUpdateEventListener;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.PersistentClass;
-import org.hibernate.test.annotations.TestCase;
+import org.hibernate.validator.Environment;
import org.hibernate.validator.InvalidStateException;
-import org.hibernate.validator.Environment;
import org.hibernate.validator.event.ValidateEventListener;
+import org.hibernate.validator.test.HANTestCase;
/**
* Test the validate framework integration with the Hibernate
@@ -19,7 +19,7 @@
*
* @author Emmanuel Bernard
*/
-public class HibernateAnnotationIntegrationTest extends TestCase {
+public class HibernateAnnotationIntegrationTest extends HANTestCase {
public void testApply() throws Exception {
PersistentClass classMapping = getCfg().getClassMapping( Address.class.getName() );
//new ClassValidator( Address.class, ResourceBundle.getBundle("messages", Locale.ENGLISH) ).apply( classMapping );
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/MarsAddress.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/MarsAddress.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/MarsAddress.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -0,0 +1,34 @@
+//$Id: MarsAddress.java 8593 2005-11-17 18:12:11Z epbernard $
+package org.hibernate.validator.test.haintegration;
+
+import javax.persistence.Embeddable;
+
+import org.hibernate.validator.Length;
+import org.hibernate.validator.NotNull;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Embeddable
+public class MarsAddress {
+ private String continent;
+ private String canal;
+
+ @NotNull
+ public String getContinent() {
+ return continent;
+ }
+
+ public void setContinent(String continent) {
+ this.continent = continent;
+ }
+
+ @Length(min = 5)
+ public String getCanal() {
+ return canal;
+ }
+
+ public void setCanal(String canal) {
+ this.canal = canal;
+ }
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Martian.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Martian.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Martian.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -0,0 +1,32 @@
+//$Id: Martian.java 7797 2005-08-10 10:40:48Z epbernard $
+package org.hibernate.validator.test.haintegration;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Martian {
+ private MartianPk id;
+ private MarsAddress address;
+
+ @Id
+ public MartianPk getId() {
+ return id;
+ }
+
+ public void setId(MartianPk id) {
+ this.id = id;
+ }
+
+ public MarsAddress getAddress() {
+ return address;
+ }
+
+ public void setAddress(MarsAddress address) {
+ this.address = address;
+ }
+
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/MartianPk.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/MartianPk.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/MartianPk.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -0,0 +1,52 @@
+//$Id: MartianPk.java 8593 2005-11-17 18:12:11Z epbernard $
+package org.hibernate.validator.test.haintegration;
+
+import java.io.Serializable;
+import javax.persistence.Embeddable;
+
+import org.hibernate.validator.Length;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Embeddable
+public class MartianPk implements Serializable {
+ private String name;
+ private String colony;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Length(max = 4)
+ public String getColony() {
+ return colony;
+ }
+
+ public void setColony(String colony) {
+ this.colony = colony;
+ }
+
+ public boolean equals(Object o) {
+ if ( this == o ) return true;
+ if ( o == null || getClass() != o.getClass() ) return false;
+
+ final MartianPk martianPk = (MartianPk) o;
+
+ if ( !colony.equals( martianPk.colony ) ) return false;
+ if ( !name.equals( martianPk.name ) ) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = name.hashCode();
+ result = 29 * result + colony.hashCode();
+ return result;
+ }
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Music.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Music.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Music.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -0,0 +1,14 @@
+//$Id: Music.java 9795 2006-04-26 06:41:18Z epbernard $
+package org.hibernate.validator.test.haintegration;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Music {
+ @Id
+ public String name;
+}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/NonHibernateAnnotationsIntegrationTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/NonHibernateAnnotationsIntegrationTest.java 2007-01-30 10:17:25 UTC (rev 11113)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/NonHibernateAnnotationsIntegrationTest.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -1,13 +1,13 @@
//$Id: $
package org.hibernate.validator.test.haintegration;
-import org.hibernate.test.annotations.TestCase;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Column;
import org.hibernate.event.PreInsertEventListener;
import org.hibernate.event.PreUpdateEventListener;
import org.hibernate.cfg.Configuration;
import org.hibernate.validator.Environment;
+import org.hibernate.validator.test.HANTestCase;
import org.hibernate.validator.event.ValidateEventListener;
/**
@@ -15,7 +15,7 @@
*
* @author Emmanuel Bernard
*/
-public class NonHibernateAnnotationsIntegrationTest extends TestCase {
+public class NonHibernateAnnotationsIntegrationTest extends HANTestCase {
public void testNotApply() throws Exception {
PersistentClass classMapping = getCfg().getClassMapping( Address.class.getName() );
//new ClassValidator( Address.class, ResourceBundle.getBundle("messages", Locale.ENGLISH) ).apply( classMapping );
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Rock.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Rock.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Rock.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -0,0 +1,15 @@
+//$Id: Rock.java 9795 2006-04-26 06:41:18Z epbernard $
+package org.hibernate.validator.test.haintegration;
+
+import javax.persistence.Entity;
+
+import org.hibernate.validator.NotNull;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Rock extends Music {
+ @NotNull
+ public Integer bit;
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Tv.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Tv.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Tv.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -0,0 +1,30 @@
+//$Id: Tv.java 10384 2006-08-31 04:10:44Z epbernard $
+package org.hibernate.validator.test.haintegration;
+
+import java.util.Date;
+import java.math.BigInteger;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+import org.hibernate.validator.Future;
+import org.hibernate.validator.Length;
+import org.hibernate.validator.Min;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Tv {
+ @Id
+ @Length(max = 2)
+ public String serial;
+ public int size;
+ @Length(max = 2)
+ public String name;
+ @Future
+ public Date expDate;
+ @Length(min = 0)
+ public String description;
+ @Min(1000)
+ public BigInteger lifetime;
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/TvOwner.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/TvOwner.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/TvOwner.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -0,0 +1,22 @@
+//$Id: TvOwner.java 9795 2006-04-26 06:41:18Z epbernard $
+package org.hibernate.validator.test.haintegration;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+import org.hibernate.validator.NotNull;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class TvOwner {
+ @Id
+ @GeneratedValue
+ public Integer id;
+ @ManyToOne
+ @NotNull
+ public Tv tv;
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Venusian.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Venusian.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Venusian.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -0,0 +1,38 @@
+//$Id: Venusian.java 9795 2006-04-26 06:41:18Z epbernard $
+package org.hibernate.validator.test.haintegration;
+
+import java.io.Serializable;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+
+import org.hibernate.validator.Length;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+(a)IdClass(VenusianPk.class)
+public class Venusian implements Serializable {
+ private String region;
+ private String name;
+
+ @Id
+ @Length(min = 3)
+ public String getRegion() {
+ return region;
+ }
+
+ public void setRegion(String region) {
+ this.region = region;
+ }
+
+ @Id
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/VenusianPk.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/VenusianPk.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/VenusianPk.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -0,0 +1,47 @@
+//$Id: VenusianPk.java 7797 2005-08-10 10:40:48Z epbernard $
+package org.hibernate.validator.test.haintegration;
+
+import java.io.Serializable;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class VenusianPk implements Serializable {
+ private String region;
+ private String name;
+
+ public String getRegion() {
+ return region;
+ }
+
+ public void setRegion(String region) {
+ this.region = region;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public boolean equals(Object o) {
+ if ( this == o ) return true;
+ if ( o == null || getClass() != o.getClass() ) return false;
+
+ final VenusianPk that = (VenusianPk) o;
+
+ if ( !name.equals( that.name ) ) return false;
+ if ( !region.equals( that.region ) ) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = region.hashCode();
+ result = 29 * result + name.hashCode();
+ return result;
+ }
+}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/DigitsTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/DigitsTest.java 2007-01-30 10:17:25 UTC (rev 11113)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/DigitsTest.java 2007-01-30 11:30:23 UTC (rev 11114)
@@ -8,15 +8,15 @@
import org.hibernate.event.PreUpdateEventListener;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.PersistentClass;
-import org.hibernate.test.annotations.TestCase;
import org.hibernate.validator.ClassValidator;
import org.hibernate.validator.InvalidValue;
+import org.hibernate.validator.test.HANTestCase;
import org.hibernate.validator.event.ValidateEventListener;
/**
* @author Emmanuel Bernard
*/
-public class DigitsTest extends TestCase {
+public class DigitsTest extends HANTestCase {
public void testDigits() throws Exception {
Car car = new Car();
17 years, 10 months
Hibernate SVN: r11113 - branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-30 05:17:25 -0500 (Tue, 30 Jan 2007)
New Revision: 11113
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/DigitsValidator.java
Log:
typo
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/DigitsValidator.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/DigitsValidator.java 2007-01-30 10:17:00 UTC (rev 11112)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/DigitsValidator.java 2007-01-30 10:17:25 UTC (rev 11113)
@@ -10,7 +10,7 @@
/**
* Validate a Digit to check if it matches the according pattern
*
- * @authod Norman Richards
+ * @author Norman Richards
* @author Emmanuel Bernard
*/
public class DigitsValidator implements Validator<Digits>, PropertyConstraint {
17 years, 10 months
Hibernate SVN: r11112 - in branches/Branch_3_2/HibernateExt/metadata/doc: api and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-30 05:17:00 -0500 (Tue, 30 Jan 2007)
New Revision: 11112
Added:
branches/Branch_3_2/HibernateExt/metadata/doc/api/
branches/Branch_3_2/HibernateExt/metadata/doc/api/package.html
Log:
add package (need to fill it up though)
Added: branches/Branch_3_2/HibernateExt/metadata/doc/api/package.html
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/doc/api/package.html (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/doc/api/package.html 2007-01-30 10:17:00 UTC (rev 11112)
@@ -0,0 +1 @@
+<body></body>
17 years, 10 months
Hibernate SVN: r11111 - branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-27 18:37:06 -0500 (Sat, 27 Jan 2007)
New Revision: 11111
Added:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/JPAValidateListener.java
Removed:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/JPAValidateEventListener.java
Log:
ANN-546 better name
Deleted: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/JPAValidateEventListener.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/JPAValidateEventListener.java 2007-01-27 16:24:20 UTC (rev 11110)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/JPAValidateEventListener.java 2007-01-27 23:37:06 UTC (rev 11111)
@@ -1,47 +0,0 @@
-//$Id: $
-package org.hibernate.validator.event;
-
-import java.lang.ref.WeakReference;
-import java.util.Map;
-import java.util.WeakHashMap;
-import javax.persistence.PrePersist;
-import javax.persistence.PreUpdate;
-
-import org.hibernate.validator.ClassValidator;
-
-/**
- * @author Emmanuel Bernard
- */
-public class JPAValidateEventListener {
- //No need for weakReference if the event listener is loaded by the same CL than
- //the entities, but in a shared env this is not the case
- //TODO check that this can be hot redeployable
- private static final Map<Class, WeakReference<ClassValidator>> validators;
- private static final ClassValidator<JPAValidateEventListener> NO_VALIDATOR;
- static {
- validators = new WeakHashMap<Class, WeakReference<ClassValidator>>();
- NO_VALIDATOR = new ClassValidator<JPAValidateEventListener>(JPAValidateEventListener.class);
- }
-
- @PrePersist
- @PreUpdate
- @SuppressWarnings( "unchecked" )
- public void onChange(Object object) {
- if (object == null) return;
- Class entity = object.getClass();
- WeakReference<ClassValidator> weakValidator = validators.get(entity);
- ClassValidator validator = weakValidator != null ? weakValidator.get() : null;
- if ( validator == null ) {
- //initialize
- //TODO reuse the same reflection manager?
- validator = new ClassValidator(entity);
- if ( ! validator.hasValidationRules() ) {
- validator = NO_VALIDATOR;
- }
- validators.put( entity, new WeakReference<ClassValidator>(validator) );
- }
- if ( validator != NO_VALIDATOR ) {
- validator.assertValid( object );
- }
- }
-}
Copied: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/JPAValidateListener.java (from rev 11110, branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/JPAValidateEventListener.java)
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/JPAValidateListener.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/JPAValidateListener.java 2007-01-27 23:37:06 UTC (rev 11111)
@@ -0,0 +1,47 @@
+//$Id: $
+package org.hibernate.validator.event;
+
+import java.lang.ref.WeakReference;
+import java.util.Map;
+import java.util.WeakHashMap;
+import javax.persistence.PrePersist;
+import javax.persistence.PreUpdate;
+
+import org.hibernate.validator.ClassValidator;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class JPAValidateListener {
+ //No need for weakReference if the event listener is loaded by the same CL than
+ //the entities, but in a shared env this is not the case
+ //TODO check that this can be hot redeployable
+ private static final Map<Class, WeakReference<ClassValidator>> validators;
+ private static final ClassValidator<JPAValidateListener> NO_VALIDATOR;
+ static {
+ validators = new WeakHashMap<Class, WeakReference<ClassValidator>>();
+ NO_VALIDATOR = new ClassValidator<JPAValidateListener>( JPAValidateListener.class);
+ }
+
+ @PrePersist
+ @PreUpdate
+ @SuppressWarnings( "unchecked" )
+ public void onChange(Object object) {
+ if (object == null) return;
+ Class entity = object.getClass();
+ WeakReference<ClassValidator> weakValidator = validators.get(entity);
+ ClassValidator validator = weakValidator != null ? weakValidator.get() : null;
+ if ( validator == null ) {
+ //initialize
+ //TODO reuse the same reflection manager?
+ validator = new ClassValidator(entity);
+ if ( ! validator.hasValidationRules() ) {
+ validator = NO_VALIDATOR;
+ }
+ validators.put( entity, new WeakReference<ClassValidator>(validator) );
+ }
+ if ( validator != NO_VALIDATOR ) {
+ validator.assertValid( object );
+ }
+ }
+}
17 years, 10 months