Hibernate SVN: r18117 - core/trunk.
by hibernate-commits@lists.jboss.org
Author: galder.zamarreno(a)jboss.com
Date: 2009-12-03 04:02:31 -0500 (Thu, 03 Dec 2009)
New Revision: 18117
Modified:
core/trunk/pom.xml
Log:
[HHH-4631] (Infinispan integration module is causing build problems) Build issues sorted. Re-enabling infinispan module.
Modified: core/trunk/pom.xml
===================================================================
--- core/trunk/pom.xml 2009-12-02 19:41:21 UTC (rev 18116)
+++ core/trunk/pom.xml 2009-12-03 09:02:31 UTC (rev 18117)
@@ -31,6 +31,7 @@
<module>testing</module>
<module>testsuite</module>
<module>jdbc3-testing</module>
+ <module>cache-infinispan</module>
<!--
<module>tutorials</module>
-->
15 years
Hibernate SVN: r18116 - in core/trunk: core/src/main/java/org/hibernate/dialect and 14 other directories.
by hibernate-commits@lists.jboss.org
Author: smarlow(a)redhat.com
Date: 2009-12-02 14:41:21 -0500 (Wed, 02 Dec 2009)
New Revision: 18116
Modified:
core/trunk/core/src/main/java/org/hibernate/LockOptions.java
core/trunk/core/src/main/java/org/hibernate/Query.java
core/trunk/core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java
core/trunk/core/src/main/java/org/hibernate/dialect/Dialect.java
core/trunk/core/src/main/java/org/hibernate/engine/QueryParameters.java
core/trunk/core/src/main/java/org/hibernate/hql/classic/QueryTranslatorImpl.java
core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java
core/trunk/core/src/main/java/org/hibernate/impl/AbstractQueryImpl.java
core/trunk/core/src/main/java/org/hibernate/impl/QueryImpl.java
core/trunk/core/src/main/java/org/hibernate/impl/SQLQueryImpl.java
core/trunk/core/src/main/java/org/hibernate/impl/SessionImpl.java
core/trunk/core/src/main/java/org/hibernate/loader/AbstractEntityJoinWalker.java
core/trunk/core/src/main/java/org/hibernate/loader/JoinWalker.java
core/trunk/core/src/main/java/org/hibernate/loader/Loader.java
core/trunk/core/src/main/java/org/hibernate/loader/OuterJoinLoader.java
core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaJoinWalker.java
core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaLoader.java
core/trunk/core/src/main/java/org/hibernate/loader/custom/CustomLoader.java
core/trunk/core/src/main/java/org/hibernate/loader/entity/CascadeEntityJoinWalker.java
core/trunk/core/src/main/java/org/hibernate/loader/entity/EntityJoinWalker.java
core/trunk/core/src/main/java/org/hibernate/loader/hql/QueryLoader.java
core/trunk/core/src/main/java/org/hibernate/sql/ForUpdateFragment.java
core/trunk/core/src/main/java/org/hibernate/sql/Select.java
core/trunk/core/src/main/java/org/hibernate/util/ArrayHelper.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java
core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/unit/lockhint/AbstractLockHintTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java
Log:
HHH-4546 add JPA 2.0 locking. First pass of support of code around AbstractEntityPersister.getAppropriateLoader
Modified: core/trunk/core/src/main/java/org/hibernate/LockOptions.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/LockOptions.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/LockOptions.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -31,9 +31,27 @@
*/
public class LockOptions
{
-
+ /**
+ * NO_WAIT timeout value will not block for pessimistic locking
+ */
public static final int NO_WAIT = 0;
+ /**
+ * WAIT_FOREVER timeout value will block until pessimistic lock is obtained
+ */
public static final int WAIT_FOREVER = -1;
+ /**
+ * NONE represents LockMode.NONE (timeout + scope do not apply)
+ */
+ public static final LockOptions NONE = new LockOptions(LockMode.NONE);
+ /**
+ * READ represents LockMode.READ (timeout + scope do not apply)
+ */
+ public static final LockOptions READ = new LockOptions(LockMode.READ);
+ /**
+ * UPGRADE represents LockMode.UPGRADE (will wait forever for lock and
+ * scope of false meaning only entity is locked)
+ */
+ public static final LockOptions UPGRADE = new LockOptions(LockMode.UPGRADE);
private LockMode lockMode = LockMode.NONE;
@@ -111,4 +129,17 @@
return this;
}
+ /**
+ * Copy From to Dest
+ * @param from is copied from
+ * @param dest is copied to
+ * @return dest
+ */
+ public static LockOptions copy(LockOptions from, LockOptions dest) {
+ dest.setLockMode(from.getLockMode());
+ dest.setScope(from.getScope());
+ dest.setTimeOut(from.getTimeOut());
+ return dest;
+ }
+
}
Modified: core/trunk/core/src/main/java/org/hibernate/Query.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/Query.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/Query.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -207,9 +207,17 @@
public Query setFetchSize(int fetchSize);
/**
+ * Set the lock options for the objects idententified by the
+ * given alias that appears in the <tt>FROM</tt> clause.
+ * @param alias a query alias, or <tt>this</tt> for a collection filter
+ */
+ public Query setLockOptions(String alias, LockOptions lockOptions);
+
+ /**
* Set the lockmode for the objects idententified by the
* given alias that appears in the <tt>FROM</tt> clause.
* @param alias a query alias, or <tt>this</tt> for a collection filter
+ * @deprecated Instead use setLockOptions
*/
public Query setLockMode(String alias, LockMode lockMode);
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -34,6 +34,7 @@
import org.hibernate.Hibernate;
import org.hibernate.LockMode;
+import org.hibernate.LockOptions;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.function.CharIndexFunction;
import org.hibernate.dialect.function.NoArgSQLFunction;
@@ -168,13 +169,14 @@
}
}
- public String applyLocksToSql(String sql, Map aliasedLockModes, Map keyColumnNames) {
- Iterator itr = aliasedLockModes.entrySet().iterator();
+ public String applyLocksToSql(String sql, Map aliasedLockOptions, Map keyColumnNames) {
+ Iterator itr = aliasedLockOptions.entrySet().iterator();
StringBuffer buffer = new StringBuffer( sql );
int correction = 0;
while ( itr.hasNext() ) {
final Map.Entry entry = ( Map.Entry ) itr.next();
- final LockMode lockMode = ( LockMode ) entry.getValue();
+ final LockOptions lockOption = ( LockOptions ) entry.getValue();
+ final LockMode lockMode = lockOption.getLockMode();
if ( lockMode.greaterThan( LockMode.READ ) ) {
final String alias = ( String ) entry.getKey();
int start = -1, end = -1;
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/Dialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/Dialect.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/Dialect.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -43,6 +43,7 @@
import org.hibernate.LockMode;
import org.hibernate.MappingException;
import org.hibernate.QueryException;
+import org.hibernate.LockOptions;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.function.CastFunction;
import org.hibernate.dialect.function.SQLFunction;
@@ -970,6 +971,28 @@
}
/**
+ * Given LockOptions (lockMode, timeout), determine the appropriate for update fragment to use.
+qu *
+ * @param lockOptions contains the lock mode to apply.
+ * @return The appropriate for update fragment.
+ */
+ public String getForUpdateString(LockOptions lockOptions) {
+ LockMode lockMode = lockOptions.getLockMode();
+ if ( lockMode==LockMode.UPGRADE || lockMode==LockMode.PESSIMISTIC_READ || lockMode==LockMode.PESSIMISTIC_WRITE) {
+ return getForUpdateString();
+ }
+ else if ( lockMode==LockMode.UPGRADE_NOWAIT ) {
+ return getForUpdateNowaitString();
+ }
+ else if ( lockMode==LockMode.FORCE || lockMode==LockMode.PESSIMISTIC_FORCE_INCREMENT) {
+ return getForUpdateNowaitString();
+ }
+ else {
+ return "";
+ }
+ }
+
+ /**
* Given a lock mode, determine the appropriate for update fragment to use.
*
* @param lockMode The lock mode to apply.
@@ -1078,12 +1101,12 @@
* <tt>SELECT FOR UPDATE</tt> to achieve this in their own fashion.
*
* @param sql the SQL string to modify
- * @param aliasedLockModes a map of lock modes indexed by aliased table names.
+ * @param aliasedLockOptions a map of lock options indexed by aliased table names.
* @param keyColumnNames a map of key columns indexed by aliased table names.
* @return the modified SQL string.
*/
- public String applyLocksToSql(String sql, Map aliasedLockModes, Map keyColumnNames) {
- return sql + new ForUpdateFragment( this, aliasedLockModes, keyColumnNames ).toFragmentString();
+ public String applyLocksToSql(String sql, Map aliasedLockOptions, Map keyColumnNames) {
+ return sql + new ForUpdateFragment( this, aliasedLockOptions, keyColumnNames ).toFragmentString();
}
Modified: core/trunk/core/src/main/java/org/hibernate/engine/QueryParameters.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/QueryParameters.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/engine/QueryParameters.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -55,7 +55,7 @@
private Type[] positionalParameterTypes;
private Object[] positionalParameterValues;
private Map namedParameters;
- private Map lockModes;
+ private Map lockOptions;
private RowSelection rowSelection;
private boolean cacheable;
private String cacheRegion;
@@ -133,7 +133,7 @@
public QueryParameters(
final Type[] positionalParameterTypes,
final Object[] positionalParameterValues,
- final Map lockModes,
+ final Map lockOptions,
final RowSelection rowSelection,
final boolean cacheable,
final String cacheRegion,
@@ -145,7 +145,7 @@
positionalParameterTypes,
positionalParameterValues,
null,
- lockModes,
+ lockOptions,
rowSelection,
false,
cacheable,
@@ -161,7 +161,7 @@
final Type[] positionalParameterTypes,
final Object[] positionalParameterValues,
final Map namedParameters,
- final Map lockModes,
+ final Map lockOptions,
final RowSelection rowSelection,
final boolean readOnly,
final boolean cacheable,
@@ -173,7 +173,7 @@
this.positionalParameterTypes = positionalParameterTypes;
this.positionalParameterValues = positionalParameterValues;
this.namedParameters = namedParameters;
- this.lockModes = lockModes;
+ this.lockOptions = lockOptions;
this.rowSelection = rowSelection;
this.cacheable = cacheable;
this.cacheRegion = cacheRegion;
@@ -188,7 +188,7 @@
final Type[] positionalParameterTypes,
final Object[] positionalParameterValues,
final Map namedParameters,
- final Map lockModes,
+ final Map lockOptions,
final RowSelection rowSelection,
final boolean readOnly,
final boolean cacheable,
@@ -204,7 +204,7 @@
positionalParameterTypes,
positionalParameterValues,
namedParameters,
- lockModes,
+ lockOptions,
rowSelection,
readOnly,
cacheable,
@@ -258,12 +258,12 @@
rowSelection = selection;
}
- public Map getLockModes() {
- return lockModes;
+ public Map getLockOptions() {
+ return lockOptions;
}
- public void setLockModes(Map map) {
- lockModes = map;
+ public void setLockOptions(Map map) {
+ lockOptions = map;
}
public void traceParameters(SessionFactoryImplementor factory) throws HibernateException {
@@ -468,7 +468,7 @@
this.positionalParameterTypes,
this.positionalParameterValues,
this.namedParameters,
- this.lockModes,
+ this.lockOptions,
selection,
this.readOnly,
this.cacheable,
Modified: core/trunk/core/src/main/java/org/hibernate/hql/classic/QueryTranslatorImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/classic/QueryTranslatorImpl.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/hql/classic/QueryTranslatorImpl.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -46,6 +46,7 @@
import org.hibernate.MappingException;
import org.hibernate.QueryException;
import org.hibernate.ScrollableResults;
+import org.hibernate.LockOptions;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.JoinSequence;
import org.hibernate.engine.QueryParameters;
@@ -1036,40 +1037,40 @@
holderClass = clazz;
}
- protected LockMode[] getLockModes(Map lockModes) {
+ protected LockOptions[] getLockOptions(Map lockOptions) {
// unfortunately this stuff can't be cached because
// it is per-invocation, not constant for the
// QueryTranslator instance
- HashMap nameLockModes = new HashMap();
- if ( lockModes != null ) {
- Iterator iter = lockModes.entrySet().iterator();
+ HashMap nameLockOptions = new HashMap();
+ if ( lockOptions != null ) {
+ Iterator iter = lockOptions.entrySet().iterator();
while ( iter.hasNext() ) {
Map.Entry me = ( Map.Entry ) iter.next();
- nameLockModes.put( getAliasName( ( String ) me.getKey() ),
+ nameLockOptions.put( getAliasName( ( String ) me.getKey() ),
me.getValue() );
}
}
- LockMode[] lockModeArray = new LockMode[names.length];
+ LockOptions[] lockOptionsArray = new LockOptions[names.length];
for ( int i = 0; i < names.length; i++ ) {
- LockMode lm = ( LockMode ) nameLockModes.get( names[i] );
- if ( lm == null ) lm = LockMode.NONE;
- lockModeArray[i] = lm;
+ LockOptions lm = ( LockOptions ) nameLockOptions.get( names[i] );
+ if ( lm == null ) lm = LockOptions.NONE;
+ lockOptionsArray[i] = lm;
}
- return lockModeArray;
+ return lockOptionsArray;
}
- protected String applyLocks(String sql, Map lockModes, Dialect dialect) throws QueryException {
+ protected String applyLocks(String sql, Map lockOptions, Dialect dialect) throws QueryException {
// can't cache this stuff either (per-invocation)
final String result;
- if ( lockModes == null || lockModes.size() == 0 ) {
+ if ( lockOptions == null || lockOptions.size() == 0 ) {
result = sql;
}
else {
- Map aliasedLockModes = new HashMap();
- Iterator iter = lockModes.entrySet().iterator();
+ Map aliasedLockOptions = new HashMap();
+ Iterator iter = lockOptions.entrySet().iterator();
while ( iter.hasNext() ) {
Map.Entry me = ( Map.Entry ) iter.next();
- aliasedLockModes.put( getAliasName( ( String ) me.getKey() ), me.getValue() );
+ aliasedLockOptions.put( getAliasName( ( String ) me.getKey() ), me.getValue() );
}
Map keyColumnNames = null;
if ( dialect.forUpdateOfColumns() ) {
@@ -1078,7 +1079,7 @@
keyColumnNames.put( names[i], persisters[i].getIdentifierColumnNames() );
}
}
- result = dialect.applyLocksToSql( sql, aliasedLockModes, keyColumnNames );
+ result = dialect.applyLocksToSql( sql, aliasedLockOptions, keyColumnNames );
}
logQuery( queryString, result );
return result;
Modified: core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -47,6 +47,7 @@
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.LockMode;
+import org.hibernate.LockOptions;
import org.hibernate.jdbc.util.FormatStyle;
import org.hibernate.mapping.Table;
import org.hibernate.util.PropertiesHelper;
@@ -411,7 +412,7 @@
" from " + tableName + ' ' + alias +
" where " + StringHelper.qualify( alias, segmentColumnName ) + "=?";
HashMap lockMap = new HashMap();
- lockMap.put( alias, LockMode.UPGRADE );
+ lockMap.put( alias, LockOptions.UPGRADE );
Map updateTargetColumnsMap = Collections.singletonMap( alias, new String[] { valueColumnName } );
return dialect.applyLocksToSql( query, lockMap, updateTargetColumnsMap );
}
Modified: core/trunk/core/src/main/java/org/hibernate/impl/AbstractQueryImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/AbstractQueryImpl.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/impl/AbstractQueryImpl.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -227,7 +227,7 @@
return session;
}
- protected abstract Map getLockModes();
+ protected abstract Map getLockOptions();
// Parameter handling code ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -874,7 +874,7 @@
typeArray(),
valueArray(),
namedParams,
- getLockModes(),
+ getLockOptions(),
getSelection(),
readOnly,
cacheable,
Modified: core/trunk/core/src/main/java/org/hibernate/impl/QueryImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/QueryImpl.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/impl/QueryImpl.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -35,6 +35,7 @@
import org.hibernate.Query;
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
+import org.hibernate.LockOptions;
import org.hibernate.engine.QueryParameters;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.engine.query.ParameterMetadata;
@@ -47,7 +48,7 @@
*/
public class QueryImpl extends AbstractQueryImpl {
- private Map lockModes = new HashMap(2);
+ private Map lockOptions = new HashMap(2);
public QueryImpl(
String queryString,
@@ -125,12 +126,16 @@
}
public Query setLockMode(String alias, LockMode lockMode) {
- lockModes.put(alias, lockMode);
+ return setLockOptions( alias, new LockOptions(lockMode) );
+ }
+
+ public Query setLockOptions(String alias, LockOptions lockOption) {
+ lockOptions.put(alias, lockOption);
return this;
}
- protected Map getLockModes() {
- return lockModes;
+ protected Map getLockOptions() {
+ return lockOptions;
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/impl/SQLQueryImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/SQLQueryImpl.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/impl/SQLQueryImpl.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -41,6 +41,7 @@
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.MappingException;
+import org.hibernate.LockOptions;
import org.hibernate.engine.query.sql.NativeSQLQuerySpecification;
import org.hibernate.engine.ResultSetMappingDefinition;
import org.hibernate.engine.NamedSQLQueryDefinition;
@@ -253,7 +254,11 @@
throw new UnsupportedOperationException("cannot set the lock mode for a native SQL query");
}
- protected Map getLockModes() {
+ public Query setLockOptions(String alias, LockOptions lockOptions) {
+ throw new UnsupportedOperationException("cannot set lock options for a native SQL query");
+ }
+
+ protected Map getLockOptions() {
//we never need to apply locks to the SQL
return CollectionHelper.EMPTY_MAP;
}
Modified: core/trunk/core/src/main/java/org/hibernate/impl/SessionImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/SessionImpl.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/impl/SessionImpl.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -2221,9 +2221,7 @@
private final LockOptions lockOptions;
private LockRequestImpl(LockOptions lo) {
lockOptions = new LockOptions();
- lockOptions.setLockMode(lo.getLockMode());
- lockOptions.setScope(lo.getScope());
- lockOptions.setTimeOut(lo.getTimeOut());
+ LockOptions.copy(lo, lockOptions);
}
public LockMode getLockMode() {
Modified: core/trunk/core/src/main/java/org/hibernate/loader/AbstractEntityJoinWalker.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/AbstractEntityJoinWalker.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/loader/AbstractEntityJoinWalker.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -75,29 +75,6 @@
protected final void initAll(
final String whereString,
final String orderByString,
- final LockMode lockMode) throws MappingException {
- walkEntityTree( persister, getAlias() );
- List allAssociations = new ArrayList();
- allAssociations.addAll(associations);
- allAssociations.add(
- new OuterJoinableAssociation(
- persister.getEntityType(),
- null,
- null,
- alias,
- JoinFragment.LEFT_OUTER_JOIN,
- null,
- getFactory(),
- CollectionHelper.EMPTY_MAP
- )
- );
- initPersisters(allAssociations, lockMode);
- initStatementString( whereString, orderByString, lockMode);
- }
-
- protected final void initAll(
- final String whereString,
- final String orderByString,
final LockOptions lockOptions) throws MappingException {
walkEntityTree( persister, getAlias() );
List allAssociations = new ArrayList();
@@ -114,8 +91,8 @@
CollectionHelper.EMPTY_MAP
)
);
- initPersisters(allAssociations, lockOptions.getLockMode());
- initStatementString( whereString, orderByString, lockOptions.getLockMode());
+ initPersisters(allAssociations, lockOptions);
+ initStatementString( whereString, orderByString, lockOptions);
}
protected final void initProjection(
@@ -123,17 +100,17 @@
final String whereString,
final String orderByString,
final String groupByString,
- final LockMode lockMode) throws MappingException {
+ final LockOptions lockOptions) throws MappingException {
walkEntityTree( persister, getAlias() );
persisters = new Loadable[0];
- initStatementString(projectionString, whereString, orderByString, groupByString, lockMode);
+ initStatementString(projectionString, whereString, orderByString, groupByString, lockOptions);
}
private void initStatementString(
final String condition,
final String orderBy,
- final LockMode lockMode) throws MappingException {
- initStatementString(null, condition, orderBy, "", lockMode);
+ final LockOptions lockOptions) throws MappingException {
+ initStatementString(null, condition, orderBy, "", lockOptions);
}
private void initStatementString(
@@ -141,7 +118,7 @@
final String condition,
final String orderBy,
final String groupBy,
- final LockMode lockMode) throws MappingException {
+ final LockOptions lockOptions) throws MappingException {
final int joins = countEntityPersisters( associations );
suffixes = BasicLoader.generateSuffixes( joins + 1 );
@@ -149,14 +126,14 @@
JoinFragment ojf = mergeOuterJoins( associations );
Select select = new Select( getDialect() )
- .setLockMode( lockMode )
+ .setLockOptions( lockOptions )
.setSelectClause(
projection == null ?
persister.selectFragment( alias, suffixes[joins] ) + selectString( associations ) :
projection
)
.setFromClause(
- getDialect().appendLockHint( lockMode, persister.fromTableFragment( alias ) ) +
+ getDialect().appendLockHint( lockOptions.getLockMode(), persister.fromTableFragment( alias ) ) +
persister.fromJoinFragment( alias, true, true )
)
.setWhereClause( condition )
Modified: core/trunk/core/src/main/java/org/hibernate/loader/JoinWalker.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/JoinWalker.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/loader/JoinWalker.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -34,6 +34,7 @@
import org.hibernate.FetchMode;
import org.hibernate.LockMode;
import org.hibernate.MappingException;
+import org.hibernate.LockOptions;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.CascadeStyle;
import org.hibernate.engine.JoinHelper;
@@ -81,7 +82,7 @@
protected CollectionPersister[] collectionPersisters;
protected int[] collectionOwners;
protected String[] aliases;
- protected LockMode[] lockModeArray;
+ protected LockOptions[] lockOptionsArray;
protected String sql;
protected JoinWalker(
@@ -100,12 +101,12 @@
this.collectionSuffixes = collectionSuffixes;
}
- public LockMode[] getLockModeArray() {
- return lockModeArray;
+ public LockOptions[] getLockModeOptions() {
+ return lockOptionsArray;
}
- public void setLockModeArray(LockMode[] lockModeArray) {
- this.lockModeArray = lockModeArray;
+ public void setLockOptionsArray(LockOptions[] lockOptionsArray) {
+ this.lockOptionsArray = lockOptionsArray;
}
public String[] getSuffixes() {
@@ -978,7 +979,12 @@
}
}
+
protected void initPersisters(final List associations, final LockMode lockMode) throws MappingException {
+ initPersisters( associations, new LockOptions(lockMode));
+ }
+
+ protected void initPersisters(final List associations, final LockOptions lockOptions) throws MappingException {
final int joins = countEntityPersisters(associations);
final int collections = countCollectionPersisters(associations);
@@ -991,7 +997,7 @@
aliases = new String[joins];
owners = new int[joins];
ownerAssociationTypes = new EntityType[joins];
- lockModeArray = ArrayHelper.fillArray(lockMode, joins);
+ lockOptionsArray = ArrayHelper.fillArray(lockOptions, joins);
int i=0;
int j=0;
Modified: core/trunk/core/src/main/java/org/hibernate/loader/Loader.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/Loader.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/loader/Loader.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -47,6 +47,7 @@
import org.hibernate.ScrollableResults;
import org.hibernate.StaleObjectStateException;
import org.hibernate.WrongClassException;
+import org.hibernate.LockOptions;
import org.hibernate.cache.FilterKey;
import org.hibernate.cache.QueryCache;
import org.hibernate.cache.QueryKey;
@@ -173,18 +174,18 @@
}
/**
- * What lock mode does this load entities with?
+ * What lock options does this load entities with?
*
- * @param lockModes a collection of lock modes specified dynamically via the Query interface
+ * @param lockOptions a collection of lock options specified dynamically via the Query interface
*/
- protected abstract LockMode[] getLockModes(Map lockModes);
+ protected abstract LockOptions[] getLockOptions(Map lockOptions);
/**
* Append <tt>FOR UPDATE OF</tt> clause, if necessary. This
* empty superclass implementation merely returns its first
* argument.
*/
- protected String applyLocks(String sql, Map lockModes, Dialect dialect) throws HibernateException {
+ protected String applyLocks(String sql, Map lockOptions, Dialect dialect) throws HibernateException {
return sql;
}
@@ -219,7 +220,7 @@
protected String preprocessSQL(String sql, QueryParameters parameters, Dialect dialect)
throws HibernateException {
- sql = applyLocks( sql, parameters.getLockModes(), dialect );
+ sql = applyLocks( sql, parameters.getLockOptions(), dialect );
return getFactory().getSettings().isCommentsEnabled() ?
prependComment( sql, parameters ) : sql;
@@ -290,7 +291,7 @@
resultSet,
session,
queryParameters,
- getLockModes( queryParameters.getLockModes() ),
+ getLockOptions( queryParameters.getLockOptions() ),
null,
hydratedObjects,
new EntityKey[entitySpan],
@@ -336,7 +337,7 @@
resultSet,
session,
queryParameters,
- getLockModes( queryParameters.getLockModes() ),
+ getLockOptions( queryParameters.getLockOptions() ),
null,
hydratedObjects,
loadedKeys,
@@ -573,7 +574,7 @@
final ResultSet resultSet,
final SessionImplementor session,
final QueryParameters queryParameters,
- final LockMode[] lockModeArray,
+ final LockOptions[] lockOptionsArray,
final EntityKey optionalObjectKey,
final List hydratedObjects,
final EntityKey[] keys,
@@ -604,7 +605,7 @@
keys,
queryParameters.getOptionalObject(),
optionalObjectKey,
- lockModeArray,
+ lockOptionsArray,
hydratedObjects,
session
);
@@ -699,7 +700,7 @@
//
// Would need to change the way the max-row stuff is handled (i.e. behind an interface) so
// that I could do the control breaking at the means to know when to stop
- final LockMode[] lockModeArray = getLockModes( queryParameters.getLockModes() );
+ final LockOptions[] lockOptionsArray = getLockOptions( queryParameters.getLockOptions() );
final EntityKey optionalObjectKey = getOptionalObjectKey( queryParameters, session );
final boolean createSubselects = isSubselectLoadingEnabled();
@@ -723,7 +724,7 @@
rs,
session,
queryParameters,
- lockModeArray,
+ lockOptionsArray,
optionalObjectKey,
hydratedObjects,
keys,
@@ -1183,7 +1184,7 @@
final EntityKey[] keys,
final Object optionalObject,
final EntityKey optionalObjectKey,
- final LockMode[] lockModes,
+ final LockOptions[] lockOptions,
final List hydratedObjects,
final SessionImplementor session)
throws HibernateException, SQLException {
@@ -1220,7 +1221,7 @@
persisters[i],
key,
object,
- lockModes[i],
+ lockOptions[i],
session
);
}
@@ -1231,7 +1232,7 @@
persisters[i],
descriptors[i].getRowIdAlias(),
key,
- lockModes[i],
+ lockOptions[i],
optionalObjectKey,
optionalObject,
hydratedObjects,
@@ -1257,10 +1258,10 @@
final Loadable persister,
final EntityKey key,
final Object object,
- final LockMode lockMode,
+ final LockOptions lockOptions,
final SessionImplementor session)
throws HibernateException, SQLException {
-
+ LockMode lockMode = (lockOptions == null) ? null : lockOptions.getLockMode();
if ( !persister.isInstance( object, session.getEntityMode() ) ) {
throw new WrongClassException(
"loaded object was of wrong class " + object.getClass(),
@@ -1296,13 +1297,13 @@
final Loadable persister,
final String rowIdAlias,
final EntityKey key,
- final LockMode lockMode,
+ final LockOptions lockOptions,
final EntityKey optionalObjectKey,
final Object optionalObject,
final List hydratedObjects,
final SessionImplementor session)
throws HibernateException, SQLException {
-
+ LockMode lockMode = (lockOptions == null) ? null : lockOptions.getLockMode();
final String instanceClass = getInstanceClass(
rs,
i,
Modified: core/trunk/core/src/main/java/org/hibernate/loader/OuterJoinLoader.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/OuterJoinLoader.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/loader/OuterJoinLoader.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -28,6 +28,7 @@
import java.util.Set;
import org.hibernate.LockMode;
+import org.hibernate.LockOptions;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.LoadQueryInfluencers;
@@ -49,7 +50,7 @@
protected CollectionPersister[] collectionPersisters;
protected int[] collectionOwners;
protected String[] aliases;
- protected LockMode[] lockModeArray;
+ protected LockOptions[] lockOptionsArray;
protected int[] owners;
protected EntityType[] ownerAssociationTypes;
protected String sql;
@@ -93,8 +94,8 @@
return ownerAssociationTypes;
}
- protected LockMode[] getLockModes(Map lockModes) {
- return lockModeArray;
+ protected LockOptions[] getLockOptions(Map lockModes) {
+ return lockOptionsArray;
}
public LoadQueryInfluencers getLoadQueryInfluencers() {
@@ -117,7 +118,7 @@
persisters = walker.getPersisters();
collectionPersisters = walker.getCollectionPersisters();
ownerAssociationTypes = walker.getOwnerAssociationTypes();
- lockModeArray = walker.getLockModeArray();
+ lockOptionsArray = walker.getLockModeOptions();
suffixes = walker.getSuffixes();
collectionSuffixes = walker.getCollectionSuffixes();
owners = walker.getOwners();
Modified: core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaJoinWalker.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaJoinWalker.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaJoinWalker.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -32,6 +32,7 @@
import org.hibernate.FetchMode;
import org.hibernate.LockMode;
import org.hibernate.MappingException;
+import org.hibernate.LockOptions;
import org.hibernate.engine.CascadeStyle;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.LoadQueryInfluencers;
@@ -104,13 +105,13 @@
translator.getWhereCondition(),
translator.getOrderBy(),
translator.getGroupBy(),
- LockMode.NONE
+ LockOptions.NONE
);
}
else {
resultTypes = new Type[] { TypeFactory.manyToOne( persister.getEntityName() ) };
- initAll( translator.getWhereCondition(), translator.getOrderBy(), LockMode.NONE );
+ initAll( translator.getWhereCondition(), translator.getOrderBy(), LockOptions.NONE );
}
userAliasList.add( criteria.getAlias() ); //root entity comes *last*
Modified: core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaLoader.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaLoader.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaLoader.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -36,6 +36,7 @@
import org.hibernate.QueryException;
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
+import org.hibernate.LockOptions;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.QueryParameters;
import org.hibernate.engine.SessionFactoryImplementor;
@@ -143,38 +144,38 @@
return querySpaces;
}
- protected String applyLocks(String sqlSelectString, Map lockModes, Dialect dialect) throws QueryException {
- if ( lockModes == null || lockModes.isEmpty() ) {
+ protected String applyLocks(String sqlSelectString, Map lockOptions, Dialect dialect) throws QueryException {
+ if ( lockOptions == null || lockOptions.isEmpty() ) {
return sqlSelectString;
}
- final Map aliasedLockModes = new HashMap();
+ final Map aliasedLockOptions = new HashMap();
final Map keyColumnNames = dialect.forUpdateOfColumns() ? new HashMap() : null;
final String[] drivingSqlAliases = getAliases();
for ( int i = 0; i < drivingSqlAliases.length; i++ ) {
- final LockMode lockMode = ( LockMode ) lockModes.get( drivingSqlAliases[i] );
- if ( lockMode != null ) {
+ final LockOptions lockOption = ( LockOptions ) lockOptions.get( drivingSqlAliases[i] );
+ if ( lockOption != null ) {
final Lockable drivingPersister = ( Lockable ) getEntityPersisters()[i];
final String rootSqlAlias = drivingPersister.getRootTableAlias( drivingSqlAliases[i] );
- aliasedLockModes.put( rootSqlAlias, lockMode );
+ aliasedLockOptions.put( rootSqlAlias, lockOption );
if ( keyColumnNames != null ) {
keyColumnNames.put( rootSqlAlias, drivingPersister.getRootTableIdentifierColumnNames() );
}
}
}
- return dialect.applyLocksToSql( sqlSelectString, aliasedLockModes, keyColumnNames );
+ return dialect.applyLocksToSql( sqlSelectString, aliasedLockOptions, keyColumnNames );
}
- protected LockMode[] getLockModes(Map lockModes) {
+ protected LockOptions[] getLockOptions(Map lockOptions) {
final String[] entityAliases = getAliases();
if ( entityAliases == null ) {
return null;
}
final int size = entityAliases.length;
- LockMode[] lockModesArray = new LockMode[size];
+ LockOptions[] lockModesArray = new LockOptions[size];
for ( int i=0; i<size; i++ ) {
- LockMode lockMode = (LockMode) lockModes.get( entityAliases[i] );
- lockModesArray[i] = lockMode==null ? LockMode.NONE : lockMode;
+ LockOptions lockOption = (LockOptions) lockOptions.get( entityAliases[i] );
+ lockModesArray[i] = lockOption==null ? LockOptions.NONE : lockOption;
}
return lockModesArray;
}
Modified: core/trunk/core/src/main/java/org/hibernate/loader/custom/CustomLoader.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/custom/CustomLoader.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/loader/custom/CustomLoader.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -38,6 +38,7 @@
import org.hibernate.LockMode;
import org.hibernate.QueryException;
import org.hibernate.ScrollableResults;
+import org.hibernate.LockOptions;
import org.hibernate.engine.QueryParameters;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
@@ -78,7 +79,7 @@
private final int[] collectionOwners;
private final CollectionAliases[] collectionAliases;
- private final LockMode[] lockModes;
+ private final LockOptions[] lockOptions;
// private final String[] sqlAliases;
// private final String[] sqlAliasSuffixes;
private final ResultRowProcessor rowProcessor;
@@ -106,7 +107,7 @@
List collectionOwners = new ArrayList();
List collectionAliases = new ArrayList();
- List lockModes = new ArrayList();
+ List lockOptions = new ArrayList();
List resultColumnProcessors = new ArrayList();
List nonScalarReturnList = new ArrayList();
List resultTypes = new ArrayList();
@@ -133,7 +134,8 @@
RootReturn rootRtn = ( RootReturn ) rtn;
Queryable persister = ( Queryable ) factory.getEntityPersister( rootRtn.getEntityName() );
entityPersisters.add( persister );
- lockModes.add( rootRtn.getLockMode() );
+ // TODO: get lock options from rootRTN
+ lockOptions.add( new LockOptions(rootRtn.getLockMode()) );
resultColumnProcessors.add( new NonScalarResultColumnProcessor( returnableCounter++ ) );
nonScalarReturnList.add( rtn );
entityOwners.add( new Integer( -1 ) );
@@ -147,7 +149,8 @@
String role = collRtn.getOwnerEntityName() + "." + collRtn.getOwnerProperty();
QueryableCollection persister = ( QueryableCollection ) factory.getCollectionPersister( role );
collectionPersisters.add( persister );
- lockModes.add( collRtn.getLockMode() );
+ // TODO: get lock options from collRtn
+ lockOptions.add( new LockOptions(collRtn.getLockMode()) );
resultColumnProcessors.add( new NonScalarResultColumnProcessor( returnableCounter++ ) );
nonScalarReturnList.add( rtn );
collectionOwners.add( new Integer( -1 ) );
@@ -169,7 +172,8 @@
NonScalarReturn ownerDescriptor = fetchRtn.getOwner();
int ownerIndex = nonScalarReturnList.indexOf( ownerDescriptor );
entityOwners.add( new Integer( ownerIndex ) );
- lockModes.add( fetchRtn.getLockMode() );
+ // TODO: get lock options from fetchRtn
+ lockOptions.add( new LockOptions(fetchRtn.getLockMode()) );
Queryable ownerPersister = determineAppropriateOwnerPersister( ownerDescriptor );
EntityType fetchedType = ( EntityType ) ownerPersister.getPropertyType( fetchRtn.getOwnerProperty() );
String entityName = fetchedType.getAssociatedEntityName( getFactory() );
@@ -185,7 +189,8 @@
NonScalarReturn ownerDescriptor = fetchRtn.getOwner();
int ownerIndex = nonScalarReturnList.indexOf( ownerDescriptor );
collectionOwners.add( new Integer( ownerIndex ) );
- lockModes.add( fetchRtn.getLockMode() );
+ // TODO: get lock options from fetchRtn
+ lockOptions.add( new LockOptions(fetchRtn.getLockMode()) );
Queryable ownerPersister = determineAppropriateOwnerPersister( ownerDescriptor );
String role = ownerPersister.getEntityName() + '.' + fetchRtn.getOwnerProperty();
QueryableCollection persister = ( QueryableCollection ) factory.getCollectionPersister( role );
@@ -228,9 +233,9 @@
this.collectionAliases[i] = ( CollectionAliases ) collectionAliases.get( i );
}
- this.lockModes = new LockMode[ lockModes.size() ];
- for ( int i = 0; i < lockModes.size(); i++ ) {
- this.lockModes[i] = ( LockMode ) lockModes.get( i );
+ this.lockOptions = new LockOptions[ lockOptions.size() ];
+ for ( int i = 0; i < lockOptions.size(); i++ ) {
+ this.lockOptions[i] = ( LockOptions ) lockOptions.get( i );
}
this.resultTypes = ArrayHelper.toTypeArray( resultTypes );
@@ -288,8 +293,8 @@
return querySpaces;
}
- protected LockMode[] getLockModes(Map lockModesMap) {
- return lockModes;
+ protected LockOptions[] getLockOptions(Map lockModesMap) {
+ return lockOptions;
}
protected Loadable[] getEntityPersisters() {
Modified: core/trunk/core/src/main/java/org/hibernate/loader/entity/CascadeEntityJoinWalker.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/entity/CascadeEntityJoinWalker.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/loader/entity/CascadeEntityJoinWalker.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -27,6 +27,7 @@
import org.hibernate.FetchMode;
import org.hibernate.LockMode;
import org.hibernate.MappingException;
+import org.hibernate.LockOptions;
import org.hibernate.engine.CascadeStyle;
import org.hibernate.engine.CascadingAction;
import org.hibernate.engine.SessionFactoryImplementor;
@@ -48,7 +49,7 @@
//include the discriminator and class-level where, but not filters
.append( persister.filterFragment( getAlias(), CollectionHelper.EMPTY_MAP ) );
- initAll( whereCondition.toString(), "", LockMode.READ );
+ initAll( whereCondition.toString(), "", LockOptions.READ );
}
protected boolean isJoinedFetchEnabled(AssociationType type, FetchMode config, CascadeStyle cascadeStyle) {
Modified: core/trunk/core/src/main/java/org/hibernate/loader/entity/EntityJoinWalker.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/entity/EntityJoinWalker.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/loader/entity/EntityJoinWalker.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -73,11 +73,8 @@
SessionFactoryImplementor factory,
LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
super( persister, factory, loadQueryInfluencers );
+ LockOptions.copy(lockOptions, this.lockOptions);
- this.lockOptions.setLockMode(lockOptions.getLockMode());
- this.lockOptions.setTimeOut(lockOptions.getTimeOut());
- this.lockOptions.setScope(lockOptions.getScope());
-
StringBuffer whereCondition = whereString( getAlias(), uniqueKey, batchSize )
//include the discriminator and class-level where, but not filters
.append( persister.filterFragment( getAlias(), Collections.EMPTY_MAP ) );
Modified: core/trunk/core/src/main/java/org/hibernate/loader/hql/QueryLoader.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/hql/QueryLoader.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/loader/hql/QueryLoader.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -36,6 +36,7 @@
import org.hibernate.LockMode;
import org.hibernate.QueryException;
import org.hibernate.ScrollableResults;
+import org.hibernate.LockOptions;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.QueryParameters;
import org.hibernate.engine.SessionFactoryImplementor;
@@ -100,7 +101,7 @@
private ResultTransformer implicitResultTransformer;
private String[] queryReturnAliases;
- private LockMode[] defaultLockModes;
+ private LockOptions[] defaultLockOptions;
/**
@@ -197,8 +198,7 @@
}
//NONE, because its the requested lock mode, not the actual!
- defaultLockModes = ArrayHelper.fillArray(LockMode.NONE, size);
-
+ defaultLockOptions = ArrayHelper.fillArray( LockOptions.NONE, size );
}
// -- Loader implementation --
@@ -277,42 +277,42 @@
}
/**
- * @param lockModes a collection of lock modes specified dynamically via the Query interface
+ * @param lockOptions a collection of lock modes specified dynamically via the Query interface
*/
- protected LockMode[] getLockModes(Map lockModes) {
+ protected LockOptions[] getLockOptions(Map lockOptions) {
- if ( lockModes==null || lockModes.size()==0 ) {
- return defaultLockModes;
+ if ( lockOptions==null || lockOptions.size()==0 ) {
+ return defaultLockOptions;
}
else {
// unfortunately this stuff can't be cached because
// it is per-invocation, not constant for the
// QueryTranslator instance
- LockMode[] lockModeArray = new LockMode[entityAliases.length];
+ LockOptions[] lockOptionsArray = new LockOptions[entityAliases.length];
for ( int i = 0; i < entityAliases.length; i++ ) {
- LockMode lockMode = (LockMode) lockModes.get( entityAliases[i] );
- if ( lockMode == null ) {
+ LockOptions options = (LockOptions) lockOptions.get( entityAliases[i] );
+ if ( options == null ) {
//NONE, because its the requested lock mode, not the actual!
- lockMode = LockMode.NONE;
+ options = LockOptions.NONE;
}
- lockModeArray[i] = lockMode;
+ lockOptionsArray[i] = options;
}
- return lockModeArray;
+ return lockOptionsArray;
}
}
- protected String applyLocks(String sql, Map lockModes, Dialect dialect) throws QueryException {
- if ( lockModes == null || lockModes.size() == 0 ) {
+ protected String applyLocks(String sql, Map lockOptions, Dialect dialect) throws QueryException {
+ if ( lockOptions == null || lockOptions.size() == 0 ) {
return sql;
}
// 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 aliasedLockOptions = new HashMap();
final Map keyColumnNames = dialect.forUpdateOfColumns() ? new HashMap() : null;
- final Iterator iter = lockModes.entrySet().iterator();
+ final Iterator iter = lockOptions.entrySet().iterator();
while ( iter.hasNext() ) {
Map.Entry me = ( Map.Entry ) iter.next();
final String userAlias = ( String ) me.getKey();
@@ -329,12 +329,12 @@
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() );
+ aliasedLockOptions.put( sqlAlias, me.getValue() );
if ( keyColumnNames != null ) {
keyColumnNames.put( sqlAlias, drivingPersister.getRootTableIdentifierColumnNames() );
}
}
- return dialect.applyLocksToSql( sql, aliasedLockModes, keyColumnNames );
+ return dialect.applyLocksToSql( sql, aliasedLockOptions, keyColumnNames );
}
protected boolean upgradeLocks() {
Modified: core/trunk/core/src/main/java/org/hibernate/sql/ForUpdateFragment.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/sql/ForUpdateFragment.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/sql/ForUpdateFragment.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -29,6 +29,7 @@
import org.hibernate.LockMode;
import org.hibernate.QueryException;
+import org.hibernate.LockOptions;
import org.hibernate.dialect.Dialect;
import org.hibernate.util.StringHelper;
@@ -44,13 +45,14 @@
this.dialect = dialect;
}
- public ForUpdateFragment(Dialect dialect, Map lockModes, Map keyColumnNames) throws QueryException {
+ public ForUpdateFragment(Dialect dialect, Map lockOptions, Map keyColumnNames) throws QueryException {
this( dialect );
LockMode upgradeType = null;
- Iterator iter = lockModes.entrySet().iterator();
+ Iterator iter = lockOptions.entrySet().iterator();
while ( iter.hasNext() ) {
final Map.Entry me = ( Map.Entry ) iter.next();
- final LockMode lockMode = ( LockMode ) me.getValue();
+ final LockOptions lockOption = ( LockOptions ) me.getValue();
+ final LockMode lockMode = lockOption.getLockMode();
if ( LockMode.READ.lessThan( lockMode ) ) {
final String tableAlias = ( String ) me.getKey();
if ( dialect.forUpdateOfColumns() ) {
Modified: core/trunk/core/src/main/java/org/hibernate/sql/Select.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/sql/Select.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/sql/Select.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -25,6 +25,7 @@
package org.hibernate.sql;
import org.hibernate.LockMode;
+import org.hibernate.LockOptions;
import org.hibernate.dialect.Dialect;
import org.hibernate.util.StringHelper;
@@ -43,7 +44,7 @@
private String orderByClause;
private String groupByClause;
private String comment;
- private LockMode lockMode;
+ private LockOptions lockOptions = new LockOptions();
public final Dialect dialect;
private int guesstimatedBufferSize = 20;
@@ -91,8 +92,8 @@
buf.append(" order by ").append(orderByClause);
}
- if (lockMode!=null) {
- buf.append( dialect.getForUpdateString(lockMode) );
+ if (lockOptions.getLockMode()!=LockMode.NONE) {
+ buf.append( dialect.getForUpdateString(lockOptions) );
}
return dialect.transformSelectString( buf.toString() );
@@ -167,12 +168,42 @@
return this;
}
+ /**
+ * Get the current lock mode
+ * @return LockMode
+ * @deprecated Instead use getLockOptions
+ */
public LockMode getLockMode() {
- return lockMode;
+ return lockOptions.getLockMode();
}
-
+
+ /**
+ * Set the lock mode
+ * @param lockMode
+ * @return this object
+ * @deprecated Instead use setLockOptions
+ */
public Select setLockMode(LockMode lockMode) {
- this.lockMode = lockMode;
+ lockOptions.setLockMode(lockMode);
return this;
}
+
+ /**
+ * Get the current lock options
+ * @return LockOptions
+ */
+ public LockOptions getLockOptions() {
+ return lockOptions;
+ }
+
+ /**
+ * Set the lock options
+ * @param lockOptions
+ * @return this object
+ */
+ public Select setLockOptions(LockOptions lockOptions) {
+ LockOptions.copy(lockOptions, this.lockOptions);
+ return this;
+ }
+
}
Modified: core/trunk/core/src/main/java/org/hibernate/util/ArrayHelper.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/util/ArrayHelper.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/core/src/main/java/org/hibernate/util/ArrayHelper.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -84,8 +84,8 @@
return array;
}
- public static LockMode[] fillArray(LockOptions lockOptions, int length) {
- LockMode[] array = new LockMode[length];
+ public static LockOptions[] fillArray(LockOptions lockOptions, int length) {
+ LockOptions[] array = new LockOptions[length];
Arrays.fill(array, lockOptions);
return array;
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -46,6 +46,7 @@
import org.hibernate.FlushMode;
import org.hibernate.LockMode;
import org.hibernate.Query;
+import org.hibernate.LockOptions;
/**
* @author Adam Warski (adam at warski dot org)
@@ -146,7 +147,7 @@
private FlushMode flushMode;
private CacheMode cacheMode;
private Integer timeout;
- private LockMode lockMode;
+ private LockOptions lockOptions = new LockOptions(LockMode.NONE);
public AuditQuery setMaxResults(int maxResults) {
this.maxResults = maxResults;
@@ -188,11 +189,26 @@
return this;
}
+ /**
+ * Set lock mode
+ * @param lockMode
+ * @return this object
+ * @deprecated Instead use setLockOptions
+ */
public AuditQuery setLockMode(LockMode lockMode) {
- this.lockMode = lockMode;
+ lockOptions.setLockMode(lockMode);
return this;
}
+ /**
+ * Set lock options
+ * @param lockOptions
+ * @return this object
+ */
+ public AuditQuery setLockOptions(LockOptions lockOptions) {
+ LockOptions.copy(lockOptions, this.lockOptions);
+ return this;
+ }
protected void setQueryProperties(Query query) {
if (maxResults != null) query.setMaxResults(maxResults);
if (firstResult != null) query.setFirstResult(firstResult);
@@ -202,6 +218,8 @@
if (flushMode != null) query.setFlushMode(flushMode);
if (cacheMode != null) query.setCacheMode(cacheMode);
if (timeout != null) query.setTimeout(timeout);
- if (lockMode != null) query.setLockMode("e", lockMode);
+ if (lockOptions != null && lockOptions.getLockMode() != LockMode.NONE) {
+ query.setLockOptions("e", lockOptions);
+ }
}
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/unit/lockhint/AbstractLockHintTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/unit/lockhint/AbstractLockHintTest.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/unit/lockhint/AbstractLockHintTest.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -7,6 +7,7 @@
import org.hibernate.dialect.Dialect;
import org.hibernate.util.StringHelper;
import org.hibernate.LockMode;
+import org.hibernate.LockOptions;
/**
* {@inheritDoc}
@@ -55,9 +56,9 @@
}
public void verify() {
- HashMap lockModes = new HashMap();
- lockModes.put( aliasToLock, LockMode.UPGRADE );
- String actualProcessedSql = dialect.applyLocksToSql( rawSql, lockModes, Collections.EMPTY_MAP );
+ HashMap lockOptions = new HashMap();
+ lockOptions.put( aliasToLock, new LockOptions(LockMode.UPGRADE) );
+ String actualProcessedSql = dialect.applyLocksToSql( rawSql, lockOptions, Collections.EMPTY_MAP );
assertEquals( expectedProcessedSql, actualProcessedSql );
}
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java 2009-12-02 18:19:42 UTC (rev 18115)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java 2009-12-02 19:41:21 UTC (rev 18116)
@@ -34,6 +34,7 @@
import org.hibernate.QueryException;
import org.hibernate.ScrollableResults;
import org.hibernate.Transaction;
+import org.hibernate.LockOptions;
import org.hibernate.cfg.Environment;
import org.hibernate.classic.Session;
import org.hibernate.connection.ConnectionProvider;
@@ -1354,7 +1355,7 @@
s.save(baz);
Query q = s.createQuery("from Foo foo, Bar bar");
if ( !(getDialect() instanceof DB2Dialect) ) {
- q.setLockMode("bar", LockMode.UPGRADE);
+ q.setLockOptions("bar", LockOptions.UPGRADE);
}
Object[] result = (Object[]) q.uniqueResult();
Object b = result[0];
@@ -1368,7 +1369,7 @@
s.createQuery( "from Foo foo" ).list();
assertTrue( s.getCurrentLockMode(b)==LockMode.NONE );
q = s.createQuery("from Foo foo");
- q.setLockMode("foo", LockMode.READ);
+ q.setLockOptions("foo", LockOptions.READ);
q.list();
assertTrue( s.getCurrentLockMode(b)==LockMode.READ);
s.evict(baz);
@@ -1387,9 +1388,9 @@
tx = s.beginTransaction();
q = s.createQuery("from Foo foo, Bar bar, Bar bar2");
if ( !(getDialect() instanceof DB2Dialect) ) {
- q.setLockMode("bar", LockMode.UPGRADE);
+ q.setLockOptions("bar", LockOptions.UPGRADE);
}
- q.setLockMode("bar2", LockMode.READ);
+ q.setLockOptions("bar2", LockOptions.READ);
result = (Object[]) q.list().get(0);
if ( !(getDialect() instanceof DB2Dialect) ) {
assertTrue( s.getCurrentLockMode( result[0] )==LockMode.UPGRADE && s.getCurrentLockMode( result[1] )==LockMode.UPGRADE );
15 years
Hibernate SVN: r18115 - annotations/branches/v3_4_0_GA_CP.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2009-12-02 13:19:42 -0500 (Wed, 02 Dec 2009)
New Revision: 18115
Modified:
annotations/branches/v3_4_0_GA_CP/pom.xml
Log:
JBPAPP-3209 HHH-4625 Use of maven-injection-plugin intermittently leads to build failures
Modified: annotations/branches/v3_4_0_GA_CP/pom.xml
===================================================================
--- annotations/branches/v3_4_0_GA_CP/pom.xml 2009-12-02 18:18:09 UTC (rev 18114)
+++ annotations/branches/v3_4_0_GA_CP/pom.xml 2009-12-02 18:19:42 UTC (rev 18115)
@@ -125,7 +125,7 @@
<plugin>
<groupId>org.jboss.maven.plugins</groupId>
<artifactId>maven-injection-plugin</artifactId>
- <version>1.0.0</version>
+ <version>1.0.2</version>
<executions>
<execution>
<phase>compile</phase>
@@ -142,7 +142,6 @@
<constant>
<className>org.hibernate.cfg.annotations.Version</className>
<fieldName>VERSION</fieldName>
- >
</constant>
</targetMembers>
</bytecodeInjection>
15 years
Hibernate SVN: r18114 - core/branches/Branch_3_3_2_GA_CP/core.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2009-12-02 13:18:09 -0500 (Wed, 02 Dec 2009)
New Revision: 18114
Modified:
core/branches/Branch_3_3_2_GA_CP/core/pom.xml
Log:
JBPAPP-3209 HHH-4625 Use of maven-injection-plugin intermittently leads to build failures
Modified: core/branches/Branch_3_3_2_GA_CP/core/pom.xml
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/pom.xml 2009-12-02 12:09:56 UTC (rev 18113)
+++ core/branches/Branch_3_3_2_GA_CP/core/pom.xml 2009-12-02 18:18:09 UTC (rev 18114)
@@ -89,7 +89,7 @@
<plugin>
<groupId>org.jboss.maven.plugins</groupId>
<artifactId>maven-injection-plugin</artifactId>
- <version>1.0.0</version>
+ <version>1.0.2</version>
<executions>
<execution>
<phase>compile</phase>
@@ -105,7 +105,7 @@
<targetMembers>
<methodBodyReturn>
<className>org.hibernate.Version</className>
- <methodName>getVersionString</methodName>>
+ <methodName>getVersionString</methodName>
</methodBodyReturn>
</targetMembers>
</bytecodeInjection>
15 years
Hibernate SVN: r18113 - in core/trunk/envers/src/test: java/org/hibernate/envers/test/entities/manytomany/biowned and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-12-02 07:09:56 -0500 (Wed, 02 Dec 2009)
New Revision: 18113
Added:
core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/biowned/
core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/biowned/ListBiowning1Entity.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/biowned/ListBiowning2Entity.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytomany/biowned/
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytomany/biowned/BasicBiowned.java
Modified:
core/trunk/envers/src/test/resources/testng.xml
Log:
HHH-4634:
- testcase
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/biowned/ListBiowning1Entity.java (from rev 18068, core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/ListOwningEntity.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/biowned/ListBiowning1Entity.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/biowned/ListBiowning1Entity.java 2009-12-02 12:09:56 UTC (rev 18113)
@@ -0,0 +1,110 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.envers.test.entities.manytomany.biowned;
+
+import java.util.List;
+import java.util.ArrayList;
+import javax.persistence.*;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * Entity owning a many-to-many relation, where the other entity also owns the relation.
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@Audited
+public class ListBiowning1Entity {
+ @Id
+ private Integer id;
+
+ private String data;
+
+ @ManyToMany
+ @JoinTable(
+ name = "biowning",
+ joinColumns = @JoinColumn(name = "biowning1_id"),
+ inverseJoinColumns = @JoinColumn(name = "biowning2_id", insertable = false, updatable = false)
+ )
+ private List<ListBiowning2Entity> references = new ArrayList<ListBiowning2Entity>();
+
+ public ListBiowning1Entity() { }
+
+ public ListBiowning1Entity(Integer id, String data) {
+ this.id = id;
+ this.data = data;
+ }
+
+ public ListBiowning1Entity(String data) {
+ this.data = data;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public List<ListBiowning2Entity> getReferences() {
+ return references;
+ }
+
+ public void setReferences(List<ListBiowning2Entity> references) {
+ this.references = references;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ListBiowning1Entity)) return false;
+
+ ListBiowning1Entity that = (ListBiowning1Entity) o;
+
+ if (data != null ? !data.equals(that.data) : that.data != null) return false;
+ //noinspection RedundantIfStatement
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (data != null ? data.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "ListBiowning1Entity(id = " + id + ", data = " + data + ")";
+ }
+}
\ No newline at end of file
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/biowned/ListBiowning2Entity.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/biowned/ListBiowning2Entity.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/biowned/ListBiowning2Entity.java 2009-12-02 12:09:56 UTC (rev 18113)
@@ -0,0 +1,110 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.envers.test.entities.manytomany.biowned;
+
+import java.util.List;
+import java.util.ArrayList;
+import javax.persistence.*;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * Entity owning a many-to-many relation, where the other entity also owns the relation.
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@Audited
+public class ListBiowning2Entity {
+ @Id
+ private Integer id;
+
+ private String data;
+
+ @ManyToMany
+ @JoinTable(
+ name = "biowning",
+ joinColumns = @JoinColumn(name = "biowning2_id"),
+ inverseJoinColumns = @JoinColumn(name = "biowning1_id", insertable = false, updatable = false)
+ )
+ private List<ListBiowning1Entity> references = new ArrayList<ListBiowning1Entity>();
+
+ public ListBiowning2Entity() { }
+
+ public ListBiowning2Entity(Integer id, String data) {
+ this.id = id;
+ this.data = data;
+ }
+
+ public ListBiowning2Entity(String data) {
+ this.data = data;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public List<ListBiowning1Entity> getReferences() {
+ return references;
+ }
+
+ public void setReferences(List<ListBiowning1Entity> references) {
+ this.references = references;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ListBiowning2Entity)) return false;
+
+ ListBiowning2Entity that = (ListBiowning2Entity) o;
+
+ if (data != null ? !data.equals(that.data) : that.data != null) return false;
+ //noinspection RedundantIfStatement
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (data != null ? data.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "ListBiowning2Entity(id = " + id + ", data = " + data + ")";
+ }
+}
\ No newline at end of file
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytomany/biowned/BasicBiowned.java (from rev 18068, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytomany/BasicList.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytomany/biowned/BasicBiowned.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytomany/biowned/BasicBiowned.java 2009-12-02 12:09:56 UTC (rev 18113)
@@ -0,0 +1,211 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.envers.test.integration.manytomany.biowned;
+
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.entities.manytomany.biowned.ListBiowning1Entity;
+import org.hibernate.envers.test.entities.manytomany.biowned.ListBiowning2Entity;
+import org.hibernate.envers.test.tools.TestTools;
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeClass;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class BasicBiowned extends AbstractEntityTest {
+ private Integer o1_1_id;
+ private Integer o1_2_id;
+ private Integer o2_1_id;
+ private Integer o2_2_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ //cfg.addAnnotatedClass(ListBiowning1Entity.class);
+ //cfg.addAnnotatedClass(ListBiowning2Entity.class);
+ }
+
+ //@BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ ListBiowning1Entity o1_1 = new ListBiowning1Entity("o1_1");
+ ListBiowning1Entity o1_2 = new ListBiowning1Entity("o1_2");
+ ListBiowning2Entity o2_1 = new ListBiowning2Entity("o2_1");
+ ListBiowning2Entity o2_2 = new ListBiowning2Entity("o2_2");
+
+ // Revision 1
+ em.getTransaction().begin();
+
+ em.persist(o1_1);
+ em.persist(o1_2);
+ em.persist(o2_1);
+ em.persist(o2_2);
+
+ em.getTransaction().commit();
+
+ // Revision 2 (1_1 <-> 2_1; 1_2 <-> 2_2)
+
+ em.getTransaction().begin();
+
+ o1_1 = em.find(ListBiowning1Entity.class, o1_1.getId());
+ o1_2 = em.find(ListBiowning1Entity.class, o1_2.getId());
+ o2_1 = em.find(ListBiowning2Entity.class, o2_1.getId());
+ o2_2 = em.find(ListBiowning2Entity.class, o2_2.getId());
+
+ o1_1.getReferences().add(o2_1);
+ o1_2.getReferences().add(o2_2);
+
+ em.getTransaction().commit();
+
+ // Revision 3 (1_1 <-> 2_1, 2_2; 1_2 <-> 2_2)
+ em.getTransaction().begin();
+
+ o1_1 = em.find(ListBiowning1Entity.class, o1_1.getId());
+ o2_2 = em.find(ListBiowning2Entity.class, o2_2.getId());
+
+ o1_1.getReferences().add(o2_2);
+
+ em.getTransaction().commit();
+
+ // Revision 4 (1_1 <-> 2_1; 1_2 <-> 2_1)
+ em.getTransaction().begin();
+
+ o1_1 = em.find(ListBiowning1Entity.class, o1_1.getId());
+ o1_2 = em.find(ListBiowning1Entity.class, o1_2.getId());
+ o2_1 = em.find(ListBiowning2Entity.class, o2_1.getId());
+ o2_2 = em.find(ListBiowning2Entity.class, o2_2.getId());
+
+ o2_2.getReferences().remove(o1_1);
+ o2_1.getReferences().remove(o1_1);
+ o1_2.getReferences().add(o2_1);
+
+ em.getTransaction().commit();
+
+ // Revision 5 (1_2 <-> 2_1, 2_2)
+ em.getTransaction().begin();
+
+ o1_1 = em.find(ListBiowning1Entity.class, o1_1.getId());
+ o1_2 = em.find(ListBiowning1Entity.class, o1_2.getId());
+ o2_1 = em.find(ListBiowning2Entity.class, o2_1.getId());
+ o2_2 = em.find(ListBiowning2Entity.class, o2_2.getId());
+
+ o2_1.getReferences().remove(o1_1);
+ o1_1.getReferences().remove(o2_1);
+ o1_2.getReferences().add(o2_2);
+ o2_2.getReferences().add(o1_2);
+
+ em.getTransaction().commit();
+
+ //
+
+ o1_1_id = o1_1.getId();
+ o1_2_id = o1_2.getId();
+ o2_1_id = o2_1.getId();
+ o2_2_id = o2_2.getId();
+ }
+
+ @Test(enabled = false)
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2, 3, 4, 5).equals(getAuditReader().getRevisions(ListBiowning1Entity.class, o1_1_id));
+ assert Arrays.asList(1, 2, 4, 5).equals(getAuditReader().getRevisions(ListBiowning1Entity.class, o1_2_id));
+
+ assert Arrays.asList(1, 2, 4, 5).equals(getAuditReader().getRevisions(ListBiowning2Entity.class, o2_1_id));
+ assert Arrays.asList(1, 2, 3, 4, 5).equals(getAuditReader().getRevisions(ListBiowning2Entity.class, o2_2_id));
+ }
+
+ @Test(enabled = false)
+ public void testHistoryOfO1_1() {
+ ListBiowning2Entity o2_1 = getEntityManager().find(ListBiowning2Entity.class, o2_1_id);
+ ListBiowning2Entity o2_2 = getEntityManager().find(ListBiowning2Entity.class, o2_2_id);
+
+ ListBiowning1Entity rev1 = getAuditReader().find(ListBiowning1Entity.class, o1_1_id, 1);
+ ListBiowning1Entity rev2 = getAuditReader().find(ListBiowning1Entity.class, o1_1_id, 2);
+ ListBiowning1Entity rev3 = getAuditReader().find(ListBiowning1Entity.class, o1_1_id, 3);
+ ListBiowning1Entity rev4 = getAuditReader().find(ListBiowning1Entity.class, o1_1_id, 4);
+ ListBiowning1Entity rev5 = getAuditReader().find(ListBiowning1Entity.class, o1_1_id, 5);
+
+ assert TestTools.checkList(rev1.getReferences());
+ assert TestTools.checkList(rev2.getReferences(), o2_1);
+ assert TestTools.checkList(rev3.getReferences(), o2_1, o2_2);
+ assert TestTools.checkList(rev4.getReferences(), o2_1);
+ assert TestTools.checkList(rev5.getReferences());
+ }
+
+ @Test(enabled = false)
+ public void testHistoryOfO1_2() {
+ ListBiowning2Entity o2_1 = getEntityManager().find(ListBiowning2Entity.class, o2_1_id);
+ ListBiowning2Entity o2_2 = getEntityManager().find(ListBiowning2Entity.class, o2_2_id);
+
+ ListBiowning1Entity rev1 = getAuditReader().find(ListBiowning1Entity.class, o1_2_id, 1);
+ ListBiowning1Entity rev2 = getAuditReader().find(ListBiowning1Entity.class, o1_2_id, 2);
+ ListBiowning1Entity rev3 = getAuditReader().find(ListBiowning1Entity.class, o1_2_id, 3);
+ ListBiowning1Entity rev4 = getAuditReader().find(ListBiowning1Entity.class, o1_2_id, 4);
+ ListBiowning1Entity rev5 = getAuditReader().find(ListBiowning1Entity.class, o1_2_id, 5);
+
+ assert TestTools.checkList(rev1.getReferences());
+ assert TestTools.checkList(rev2.getReferences(), o2_2);
+ assert TestTools.checkList(rev3.getReferences(), o2_2);
+ assert TestTools.checkList(rev4.getReferences(), o2_1);
+ assert TestTools.checkList(rev5.getReferences(), o2_1, o2_2);
+ }
+
+ @Test(enabled = false)
+ public void testHistoryOfO2_1() {
+ ListBiowning1Entity o1_1 = getEntityManager().find(ListBiowning1Entity.class, o1_1_id);
+ ListBiowning1Entity o1_2 = getEntityManager().find(ListBiowning1Entity.class, o1_2_id);
+
+ ListBiowning2Entity rev1 = getAuditReader().find(ListBiowning2Entity.class, o1_1_id, 1);
+ ListBiowning2Entity rev2 = getAuditReader().find(ListBiowning2Entity.class, o1_1_id, 2);
+ ListBiowning2Entity rev3 = getAuditReader().find(ListBiowning2Entity.class, o1_1_id, 3);
+ ListBiowning2Entity rev4 = getAuditReader().find(ListBiowning2Entity.class, o1_1_id, 4);
+ ListBiowning2Entity rev5 = getAuditReader().find(ListBiowning2Entity.class, o1_1_id, 5);
+
+ assert TestTools.checkList(rev1.getReferences());
+ assert TestTools.checkList(rev2.getReferences(), o1_1);
+ assert TestTools.checkList(rev3.getReferences(), o1_1);
+ assert TestTools.checkList(rev4.getReferences(), o1_1, o1_2);
+ assert TestTools.checkList(rev5.getReferences(), o1_2);
+ }
+
+ @Test(enabled = false)
+ public void testHistoryOfO2_2() {
+ ListBiowning1Entity o1_1 = getEntityManager().find(ListBiowning1Entity.class, o1_1_id);
+ ListBiowning1Entity o1_2 = getEntityManager().find(ListBiowning1Entity.class, o1_2_id);
+
+ ListBiowning2Entity rev1 = getAuditReader().find(ListBiowning2Entity.class, o1_2_id, 1);
+ ListBiowning2Entity rev2 = getAuditReader().find(ListBiowning2Entity.class, o1_2_id, 2);
+ ListBiowning2Entity rev3 = getAuditReader().find(ListBiowning2Entity.class, o1_2_id, 3);
+ ListBiowning2Entity rev4 = getAuditReader().find(ListBiowning2Entity.class, o1_2_id, 4);
+ ListBiowning2Entity rev5 = getAuditReader().find(ListBiowning2Entity.class, o1_2_id, 5);
+
+ assert TestTools.checkList(rev1.getReferences());
+ assert TestTools.checkList(rev2.getReferences(), o1_2);
+ assert TestTools.checkList(rev3.getReferences(), o1_1, o1_2);
+ assert TestTools.checkList(rev4.getReferences());
+ assert TestTools.checkList(rev5.getReferences(), o1_2);
+ }
+}
\ No newline at end of file
Modified: core/trunk/envers/src/test/resources/testng.xml
===================================================================
--- core/trunk/envers/src/test/resources/testng.xml 2009-12-02 11:38:32 UTC (rev 18112)
+++ core/trunk/envers/src/test/resources/testng.xml 2009-12-02 12:09:56 UTC (rev 18113)
@@ -31,6 +31,7 @@
<package name="org.hibernate.envers.test.integration.interfaces.components" />
<package name="org.hibernate.envers.test.integration.interfaces.relation" />
<package name="org.hibernate.envers.test.integration.manytomany" />
+ <package name="org.hibernate.envers.test.integration.manytomany.biowned" />
<package name="org.hibernate.envers.test.integration.manytomany.sametable" />
<package name="org.hibernate.envers.test.integration.manytomany.ternary" />
<package name="org.hibernate.envers.test.integration.manytomany.unidirectional" />
15 years
Hibernate SVN: r18112 - in core/trunk/envers/src/test: java/org/hibernate/envers/test/entities/manytomany/sametable and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-12-02 06:38:32 -0500 (Wed, 02 Dec 2009)
New Revision: 18112
Added:
core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/
core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/Child1Entity.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/Child2Entity.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/ParentEntity.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytomany/sametable/
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytomany/sametable/BasicSametable.java
Modified:
core/trunk/envers/src/test/resources/testng.xml
Log:
HHH-4633:
- testcase
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/Child1Entity.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/Child1Entity.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/Child1Entity.java 2009-12-02 11:38:32 UTC (rev 18112)
@@ -0,0 +1,87 @@
+package org.hibernate.envers.test.entities.manytomany.sametable;
+
+import org.hibernate.annotations.WhereJoinTable;
+import org.hibernate.envers.Audited;
+
+import javax.persistence.*;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@Audited
+public class Child1Entity {
+ @Id
+ private Integer id;
+
+ private String child1Data;
+
+ public Child1Entity() {
+ }
+
+ public Child1Entity(String child1Data) {
+ this.child1Data = child1Data;
+ }
+
+ public Child1Entity(String child1Data, Integer id) {
+ this.child1Data = child1Data;
+ this.id = id;
+ }
+
+ @ManyToMany(fetch = FetchType.LAZY)
+ @JoinTable(
+ name = "children",
+ joinColumns = @JoinColumn(name = "child1_id"),
+ inverseJoinColumns = @JoinColumn(name = "parent_id", insertable = false, updatable = false)
+ )
+ @WhereJoinTable(clause = "child1_id is not null")
+ private List<ParentEntity> parents = new ArrayList<ParentEntity>();
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getChild1Data() {
+ return child1Data;
+ }
+
+ public void setChild1Data(String child1Data) {
+ this.child1Data = child1Data;
+ }
+
+ public List<ParentEntity> getParents() {
+ return parents;
+ }
+
+ public void setParents(List<ParentEntity> parents) {
+ this.parents = parents;
+ }
+
+ @SuppressWarnings({"RedundantIfStatement"})
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Child1Entity that = (Child1Entity) o;
+
+ if (child1Data != null ? !child1Data.equals(that.child1Data) : that.child1Data != null) return false;
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = id != null ? id.hashCode() : 0;
+ result = 31 * result + (child1Data != null ? child1Data.hashCode() : 0);
+ result = 31 * result + (parents != null ? parents.hashCode() : 0);
+ return result;
+ }
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/Child2Entity.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/Child2Entity.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/Child2Entity.java 2009-12-02 11:38:32 UTC (rev 18112)
@@ -0,0 +1,87 @@
+package org.hibernate.envers.test.entities.manytomany.sametable;
+
+import org.hibernate.annotations.WhereJoinTable;
+import org.hibernate.envers.Audited;
+
+import javax.persistence.*;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@Audited
+public class Child2Entity {
+ @Id
+ private Integer id;
+
+ private String child2Data;
+
+ public Child2Entity() {
+ }
+
+ public Child2Entity(String child2Data) {
+ this.child2Data = child2Data;
+ }
+
+ public Child2Entity(Integer id, String child2Data) {
+ this.id = id;
+ this.child2Data = child2Data;
+ }
+
+ @ManyToMany(fetch = FetchType.LAZY)
+ @JoinTable(
+ name = "children",
+ joinColumns = @JoinColumn(name = "child2_id"),
+ inverseJoinColumns = @JoinColumn(name = "parent_id", insertable = false, updatable = false)
+ )
+ @WhereJoinTable(clause = "child2_id is not null")
+ private List<ParentEntity> parents = new ArrayList<ParentEntity>();
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getChild2Data() {
+ return child2Data;
+ }
+
+ public void setChild2Data(String child2Data) {
+ this.child2Data = child2Data;
+ }
+
+ public List<ParentEntity> getParents() {
+ return parents;
+ }
+
+ public void setParents(List<ParentEntity> parents) {
+ this.parents = parents;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Child2Entity that = (Child2Entity) o;
+
+ if (child2Data != null ? !child2Data.equals(that.child2Data) : that.child2Data != null) return false;
+ //noinspection RedundantIfStatement
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = id != null ? id.hashCode() : 0;
+ result = 31 * result + (child2Data != null ? child2Data.hashCode() : 0);
+ result = 31 * result + (parents != null ? parents.hashCode() : 0);
+ return result;
+ }
+}
\ No newline at end of file
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/ParentEntity.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/ParentEntity.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/sametable/ParentEntity.java 2009-12-02 11:38:32 UTC (rev 18112)
@@ -0,0 +1,105 @@
+package org.hibernate.envers.test.entities.manytomany.sametable;
+
+import org.hibernate.envers.Audited;
+import org.hibernate.annotations.WhereJoinTable;
+
+import javax.persistence.*;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@Audited
+public class ParentEntity {
+ @Id
+ private Integer id;
+
+ private String parentData;
+
+ public ParentEntity() {
+ }
+
+ public ParentEntity(String parentData) {
+ this.parentData = parentData;
+ }
+
+ public ParentEntity(Integer id, String parentData) {
+ this.id = id;
+ this.parentData = parentData;
+ }
+
+ @ManyToMany(fetch = FetchType.LAZY)
+ @JoinTable(
+ name = "children",
+ joinColumns = @JoinColumn(name = "parent_id"),
+ inverseJoinColumns = @JoinColumn(name = "child1_id", insertable = false, updatable = false)
+ )
+ @WhereJoinTable(clause = "child1_id is not null")
+ private List<Child1Entity> children1 = new ArrayList<Child1Entity>();
+
+ @ManyToMany(fetch = FetchType.LAZY)
+ @JoinTable(
+ name = "children",
+ joinColumns = @JoinColumn(name = "parent_id"),
+ inverseJoinColumns = @JoinColumn(name = "child2_id", insertable = false, updatable = false)
+ )
+ @WhereJoinTable(clause = "child2_id is not null")
+ private List<Child2Entity> children2 = new ArrayList<Child2Entity>();
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getParentData() {
+ return parentData;
+ }
+
+ public void setParentData(String parentData) {
+ this.parentData = parentData;
+ }
+
+ public List<Child1Entity> getChildren1() {
+ return children1;
+ }
+
+ public void setChildren1(List<Child1Entity> children1) {
+ this.children1 = children1;
+ }
+
+ public List<Child2Entity> getChildren2() {
+ return children2;
+ }
+
+ public void setChildren2(List<Child2Entity> children2) {
+ this.children2 = children2;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ ParentEntity that = (ParentEntity) o;
+
+ if (parentData != null ? !parentData.equals(that.parentData) : that.parentData != null) return false;
+ //noinspection RedundantIfStatement
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = id != null ? id.hashCode() : 0;
+ result = 31 * result + (parentData != null ? parentData.hashCode() : 0);
+ result = 31 * result + (children1 != null ? children1.hashCode() : 0);
+ result = 31 * result + (children2 != null ? children2.hashCode() : 0);
+ return result;
+ }
+}
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytomany/sametable/BasicSametable.java (from rev 18068, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytomany/BasicList.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytomany/sametable/BasicSametable.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytomany/sametable/BasicSametable.java 2009-12-02 11:38:32 UTC (rev 18112)
@@ -0,0 +1,279 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.envers.test.integration.manytomany.sametable;
+
+import java.util.Arrays;
+import javax.persistence.EntityManager;
+
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.entities.manytomany.sametable.ParentEntity;
+import org.hibernate.envers.test.entities.manytomany.sametable.Child1Entity;
+import org.hibernate.envers.test.entities.manytomany.sametable.Child2Entity;
+import org.hibernate.envers.test.tools.TestTools;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ejb.Ejb3Configuration;
+
+/**
+ * Test which checks that auditing entities which contain multiple mappings to same tables work.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class BasicSametable extends AbstractEntityTest {
+ private Integer p1_id;
+ private Integer p2_id;
+ private Integer c1_1_id;
+ private Integer c1_2_id;
+ private Integer c2_1_id;
+ private Integer c2_2_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ //cfg.addAnnotatedClass(ParentEntity.class);
+ //cfg.addAnnotatedClass(Child1Entity.class);
+ //cfg.addAnnotatedClass(Child2Entity.class);
+ }
+
+ //@BeforeClass(enabled = false, dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ ParentEntity p1 = new ParentEntity("parent_1");
+ ParentEntity p2 = new ParentEntity("parent_2");
+
+ Child1Entity c1_1 = new Child1Entity("child1_1");
+ Child1Entity c1_2 = new Child1Entity("child1_2");
+
+ Child2Entity c2_1 = new Child2Entity("child2_1");
+ Child2Entity c2_2 = new Child2Entity("child2_2");
+
+ // Revision 1
+ em.getTransaction().begin();
+
+ em.persist(p1);
+ em.persist(p2);
+ em.persist(c1_1);
+ em.persist(c1_2);
+ em.persist(c2_1);
+ em.persist(c2_2);
+
+ em.getTransaction().commit();
+
+ // Revision 2 - (p1: c1_1, p2: c2_1)
+
+ em.getTransaction().begin();
+
+ p1 = em.find(ParentEntity.class, p1.getId());
+ p2 = em.find(ParentEntity.class, p2.getId());
+ c1_1 = em.find(Child1Entity.class, c1_1.getId());
+ c2_1 = em.find(Child2Entity.class, c2_1.getId());
+
+ p1.getChildren1().add(c1_1);
+ p2.getChildren2().add(c2_1);
+
+ em.getTransaction().commit();
+
+ // Revision 3 - (p1: c1_1, c1_2, c2_2, p2: c1_1, c2_1)
+ em.getTransaction().begin();
+
+ p1 = em.find(ParentEntity.class, p1.getId());
+ p2 = em.find(ParentEntity.class, p2.getId());
+ c1_1 = em.find(Child1Entity.class, c1_1.getId());
+ c1_2 = em.find(Child1Entity.class, c1_2.getId());
+ c2_2 = em.find(Child2Entity.class, c2_2.getId());
+
+ p1.getChildren1().add(c1_2);
+ p1.getChildren2().add(c2_2);
+
+ p2.getChildren1().add(c1_1);
+
+ em.getTransaction().commit();
+
+ // Revision 4 - (p1: c1_2, c2_2, p2: c1_1, c2_1, c2_2)
+ em.getTransaction().begin();
+
+ p1 = em.find(ParentEntity.class, p1.getId());
+ p2 = em.find(ParentEntity.class, p2.getId());
+ c1_1 = em.find(Child1Entity.class, c1_1.getId());
+ c2_2 = em.find(Child2Entity.class, c2_2.getId());
+
+ p1.getChildren1().remove(c1_1);
+ p2.getChildren2().add(c2_2);
+
+ em.getTransaction().commit();
+
+ // Revision 5 - (p1: c2_2, p2: c1_1, c2_1)
+ em.getTransaction().begin();
+
+ p1 = em.find(ParentEntity.class, p1.getId());
+ p2 = em.find(ParentEntity.class, p2.getId());
+ c1_2 = em.find(Child1Entity.class, c1_2.getId());
+ c2_2 = em.find(Child2Entity.class, c2_2.getId());
+
+ c2_2.getParents().remove(p2);
+ c1_2.getParents().remove(p1);
+
+ em.getTransaction().commit();
+
+ //
+
+ p1_id = p1.getId();
+ p2_id = p2.getId();
+ c1_1_id = c1_1.getId();
+ c1_2_id = c1_2.getId();
+ c2_1_id = c2_1.getId();
+ c2_2_id = c2_2.getId();
+ }
+
+ @Test(enabled = false)
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2, 3, 4, 5).equals(getAuditReader().getRevisions(ParentEntity.class, p1_id));
+ assert Arrays.asList(1, 2, 3, 4, 5).equals(getAuditReader().getRevisions(ParentEntity.class, p2_id));
+
+ assert Arrays.asList(1, 2, 3, 4).equals(getAuditReader().getRevisions(Child1Entity.class, c1_1_id));
+ assert Arrays.asList(1, 3, 5).equals(getAuditReader().getRevisions(Child1Entity.class, c1_2_id));
+
+ assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(Child1Entity.class, c2_1_id));
+ assert Arrays.asList(1, 3, 4, 5).equals(getAuditReader().getRevisions(Child1Entity.class, c2_2_id));
+ }
+
+ @Test(enabled = false)
+ public void testHistoryOfParent1() {
+ Child1Entity c1_1 = getEntityManager().find(Child1Entity.class, c1_1_id);
+ Child2Entity c2_2 = getEntityManager().find(Child2Entity.class, c2_2_id);
+
+ ParentEntity rev1 = getAuditReader().find(ParentEntity.class, p1_id, 1);
+ ParentEntity rev2 = getAuditReader().find(ParentEntity.class, p1_id, 2);
+ ParentEntity rev3 = getAuditReader().find(ParentEntity.class, p1_id, 3);
+ ParentEntity rev4 = getAuditReader().find(ParentEntity.class, p1_id, 4);
+ ParentEntity rev5 = getAuditReader().find(ParentEntity.class, p1_id, 5);
+
+ assert TestTools.checkList(rev1.getChildren1());
+ assert TestTools.checkList(rev2.getChildren1());
+ assert TestTools.checkList(rev3.getChildren1(), c1_1);
+ assert TestTools.checkList(rev4.getChildren1(), c1_1);
+ assert TestTools.checkList(rev5.getChildren1(), c1_1);
+
+ assert TestTools.checkList(rev1.getChildren2());
+ assert TestTools.checkList(rev2.getChildren2());
+ assert TestTools.checkList(rev3.getChildren2(), c2_2);
+ assert TestTools.checkList(rev4.getChildren2(), c2_2);
+ assert TestTools.checkList(rev5.getChildren2(), c2_2);
+ }
+
+ @Test(enabled = false)
+ public void testHistoryOfParent2() {
+ Child1Entity c1_1 = getEntityManager().find(Child1Entity.class, c1_1_id);
+ Child1Entity c1_2 = getEntityManager().find(Child1Entity.class, c1_2_id);
+ Child2Entity c2_1 = getEntityManager().find(Child2Entity.class, c2_1_id);
+ Child2Entity c2_2 = getEntityManager().find(Child2Entity.class, c2_2_id);
+
+ ParentEntity rev1 = getAuditReader().find(ParentEntity.class, p2_id, 1);
+ ParentEntity rev2 = getAuditReader().find(ParentEntity.class, p2_id, 2);
+ ParentEntity rev3 = getAuditReader().find(ParentEntity.class, p2_id, 3);
+ ParentEntity rev4 = getAuditReader().find(ParentEntity.class, p2_id, 4);
+ ParentEntity rev5 = getAuditReader().find(ParentEntity.class, p2_id, 5);
+
+ assert TestTools.checkList(rev1.getChildren1());
+ assert TestTools.checkList(rev2.getChildren1(), c1_1);
+ assert TestTools.checkList(rev3.getChildren1(), c1_1, c1_2);
+ assert TestTools.checkList(rev4.getChildren1(), c1_2);
+ assert TestTools.checkList(rev5.getChildren1());
+
+ assert TestTools.checkList(rev1.getChildren2());
+ assert TestTools.checkList(rev2.getChildren2(), c2_1);
+ assert TestTools.checkList(rev3.getChildren2(), c2_1);
+ assert TestTools.checkList(rev4.getChildren2(), c2_1, c2_2);
+ assert TestTools.checkList(rev5.getChildren2(), c2_1);
+ }
+
+ @Test(enabled = false)
+ public void testHistoryOfChild1_1() {
+ ParentEntity p1 = getEntityManager().find(ParentEntity.class, p1_id);
+ ParentEntity p2 = getEntityManager().find(ParentEntity.class, p2_id);
+
+ Child1Entity rev1 = getAuditReader().find(Child1Entity.class, c1_1_id, 1);
+ Child1Entity rev2 = getAuditReader().find(Child1Entity.class, c1_1_id, 2);
+ Child1Entity rev3 = getAuditReader().find(Child1Entity.class, c1_1_id, 3);
+ Child1Entity rev4 = getAuditReader().find(Child1Entity.class, c1_1_id, 4);
+ Child1Entity rev5 = getAuditReader().find(Child1Entity.class, c1_1_id, 5);
+
+ assert TestTools.checkList(rev1.getParents());
+ assert TestTools.checkList(rev2.getParents(), p1);
+ assert TestTools.checkList(rev3.getParents(), p1, p2);
+ assert TestTools.checkList(rev4.getParents(), p2);
+ assert TestTools.checkList(rev5.getParents(), p2);
+ }
+
+ @Test(enabled = false)
+ public void testHistoryOfChild1_2() {
+ ParentEntity p1 = getEntityManager().find(ParentEntity.class, p1_id);
+
+ Child1Entity rev1 = getAuditReader().find(Child1Entity.class, c1_2_id, 1);
+ Child1Entity rev2 = getAuditReader().find(Child1Entity.class, c1_2_id, 2);
+ Child1Entity rev3 = getAuditReader().find(Child1Entity.class, c1_2_id, 3);
+ Child1Entity rev4 = getAuditReader().find(Child1Entity.class, c1_2_id, 4);
+ Child1Entity rev5 = getAuditReader().find(Child1Entity.class, c1_2_id, 5);
+
+ assert TestTools.checkList(rev1.getParents());
+ assert TestTools.checkList(rev2.getParents());
+ assert TestTools.checkList(rev3.getParents(), p1);
+ assert TestTools.checkList(rev4.getParents(), p1);
+ assert TestTools.checkList(rev5.getParents());
+ }
+
+ @Test(enabled = false)
+ public void testHistoryOfChild2_1() {
+ ParentEntity p2 = getEntityManager().find(ParentEntity.class, p2_id);
+
+ Child2Entity rev1 = getAuditReader().find(Child2Entity.class, c2_1_id, 1);
+ Child2Entity rev2 = getAuditReader().find(Child2Entity.class, c2_1_id, 2);
+ Child2Entity rev3 = getAuditReader().find(Child2Entity.class, c2_1_id, 3);
+ Child2Entity rev4 = getAuditReader().find(Child2Entity.class, c2_1_id, 4);
+ Child2Entity rev5 = getAuditReader().find(Child2Entity.class, c2_1_id, 5);
+
+ assert TestTools.checkList(rev1.getParents());
+ assert TestTools.checkList(rev2.getParents(), p2);
+ assert TestTools.checkList(rev3.getParents(), p2);
+ assert TestTools.checkList(rev4.getParents(), p2);
+ assert TestTools.checkList(rev5.getParents(), p2);
+ }
+
+ @Test(enabled = false)
+ public void testHistoryOfChild2_2() {
+ ParentEntity p1 = getEntityManager().find(ParentEntity.class, p1_id);
+ ParentEntity p2 = getEntityManager().find(ParentEntity.class, p2_id);
+
+ Child2Entity rev1 = getAuditReader().find(Child2Entity.class, c2_2_id, 1);
+ Child2Entity rev2 = getAuditReader().find(Child2Entity.class, c2_2_id, 2);
+ Child2Entity rev3 = getAuditReader().find(Child2Entity.class, c2_2_id, 3);
+ Child2Entity rev4 = getAuditReader().find(Child2Entity.class, c2_2_id, 4);
+ Child2Entity rev5 = getAuditReader().find(Child2Entity.class, c2_2_id, 5);
+
+ assert TestTools.checkList(rev1.getParents());
+ assert TestTools.checkList(rev2.getParents());
+ assert TestTools.checkList(rev3.getParents(), p1);
+ assert TestTools.checkList(rev4.getParents(), p1, p2);
+ assert TestTools.checkList(rev5.getParents(), p1);
+ }
+}
\ No newline at end of file
Modified: core/trunk/envers/src/test/resources/testng.xml
===================================================================
--- core/trunk/envers/src/test/resources/testng.xml 2009-12-01 15:55:26 UTC (rev 18111)
+++ core/trunk/envers/src/test/resources/testng.xml 2009-12-02 11:38:32 UTC (rev 18112)
@@ -31,6 +31,7 @@
<package name="org.hibernate.envers.test.integration.interfaces.components" />
<package name="org.hibernate.envers.test.integration.interfaces.relation" />
<package name="org.hibernate.envers.test.integration.manytomany" />
+ <package name="org.hibernate.envers.test.integration.manytomany.sametable" />
<package name="org.hibernate.envers.test.integration.manytomany.ternary" />
<package name="org.hibernate.envers.test.integration.manytomany.unidirectional" />
<package name="org.hibernate.envers.test.integration.manytoone.unidirectional" />
15 years
Hibernate SVN: r18111 - core/trunk.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-12-01 10:55:26 -0500 (Tue, 01 Dec 2009)
New Revision: 18111
Modified:
core/trunk/pom.xml
Log:
HHH-4631 - Infinispan integration module is causing build problems
Modified: core/trunk/pom.xml
===================================================================
--- core/trunk/pom.xml 2009-12-01 07:31:01 UTC (rev 18110)
+++ core/trunk/pom.xml 2009-12-01 15:55:26 UTC (rev 18111)
@@ -83,7 +83,9 @@
</activation>
<modules>
<module>entitymanager</module>
+<!--
<module>cache-infinispan</module>
+-->
<module>jdbc4-testing</module>
</modules>
</profile>
15 years
Hibernate SVN: r18110 - core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-12-01 02:31:01 -0500 (Tue, 01 Dec 2009)
New Revision: 18110
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java
Log:
svn merge -r 18056:18109 https://svn.jboss.org/repos/hibernate/core/trunk/envers .
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-12-01 07:20:17 UTC (rev 18109)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-12-01 07:31:01 UTC (rev 18110)
@@ -45,6 +45,8 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.mapping.*;
import org.hibernate.type.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author Adam Warski (adam at warski dot org)
@@ -52,6 +54,8 @@
* @author Tomasz Bech
*/
public final class AuditMetadataGenerator {
+ private static final Logger log = LoggerFactory.getLogger(AuditMetadataGenerator.class);
+
private final Configuration cfg;
private final GlobalConfiguration globalCfg;
private final AuditEntitiesConfiguration verEntCfg;
@@ -349,6 +353,15 @@
if (!isAudited) {
String entityName = pc.getEntityName();
IdMappingData idMapper = idMetadataGenerator.addId(pc);
+
+ if (idMapper == null) {
+ // Unsupported id mapping, e.g. key-many-to-one. If the entity is used in auditing, an exception
+ // will be thrown later on.
+ log.debug("Unable to create auditing id mapping for entity " + entityName +
+ ", because of an unsupported Hibernate id mapping (e.g. key-many-to-one).");
+ return;
+ }
+
ExtendedPropertyMapper propertyMapper = null;
String parentEntityName = null;
EntityConfiguration entityCfg = new EntityConfiguration(entityName, idMapper, propertyMapper,
@@ -358,6 +371,8 @@
}
String entityName = pc.getEntityName();
+ log.debug("Generating first-pass auditing mapping for entity " + entityName + ".");
+
String auditEntityName = verEntCfg.getAuditEntityName(entityName);
String auditTableName = verEntCfg.getAuditTableName(entityName, pc.getTable().getName());
@@ -432,6 +447,7 @@
public void generateSecondPass(PersistentClass pc, ClassAuditingData auditingData,
EntityXmlMappingData xmlMappingData) {
String entityName = pc.getEntityName();
+ log.debug("Generating second-pass auditing mapping for entity " + entityName + ".");
CompositeMapperBuilder propertyMapper = entitiesConfigurations.get(entityName).getPropertyMapper();
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java 2009-12-01 07:20:17 UTC (rev 18109)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java 2009-12-01 07:31:01 UTC (rev 18110)
@@ -84,6 +84,11 @@
Property id_prop = pc.getIdentifierProperty();
Component id_mapper = pc.getIdentifierMapper();
+ // Checking if the id mapping is supported
+ if (id_mapper == null && id_prop == null) {
+ return null;
+ }
+
SimpleIdMapperBuilder mapper;
if (id_mapper != null) {
// Multiple id
15 years
Hibernate SVN: r18109 - core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-12-01 02:20:17 -0500 (Tue, 01 Dec 2009)
New Revision: 18109
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java
Log:
* Skipping auditing id mapping generation if the id mapping is unsupported (e.g. key-many-to-one)
* Some logging
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-12-01 04:54:05 UTC (rev 18108)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-12-01 07:20:17 UTC (rev 18109)
@@ -45,6 +45,8 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.mapping.*;
import org.hibernate.type.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author Adam Warski (adam at warski dot org)
@@ -52,6 +54,8 @@
* @author Tomasz Bech
*/
public final class AuditMetadataGenerator {
+ private static final Logger log = LoggerFactory.getLogger(AuditMetadataGenerator.class);
+
private final Configuration cfg;
private final GlobalConfiguration globalCfg;
private final AuditEntitiesConfiguration verEntCfg;
@@ -317,6 +321,15 @@
if (!isAudited) {
String entityName = pc.getEntityName();
IdMappingData idMapper = idMetadataGenerator.addId(pc);
+
+ if (idMapper == null) {
+ // Unsupported id mapping, e.g. key-many-to-one. If the entity is used in auditing, an exception
+ // will be thrown later on.
+ log.debug("Unable to create auditing id mapping for entity " + entityName +
+ ", because of an unsupported Hibernate id mapping (e.g. key-many-to-one).");
+ return;
+ }
+
ExtendedPropertyMapper propertyMapper = null;
String parentEntityName = null;
EntityConfiguration entityCfg = new EntityConfiguration(entityName, idMapper, propertyMapper,
@@ -326,6 +339,8 @@
}
String entityName = pc.getEntityName();
+ log.debug("Generating first-pass auditing mapping for entity " + entityName + ".");
+
String auditEntityName = verEntCfg.getAuditEntityName(entityName);
String auditTableName = verEntCfg.getAuditTableName(entityName, pc.getTable().getName());
@@ -395,6 +410,7 @@
public void generateSecondPass(PersistentClass pc, ClassAuditingData auditingData,
EntityXmlMappingData xmlMappingData) {
String entityName = pc.getEntityName();
+ log.debug("Generating second-pass auditing mapping for entity " + entityName + ".");
CompositeMapperBuilder propertyMapper = entitiesConfigurations.get(entityName).getPropertyMapper();
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java 2009-12-01 04:54:05 UTC (rev 18108)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java 2009-12-01 07:20:17 UTC (rev 18109)
@@ -84,6 +84,11 @@
Property id_prop = pc.getIdentifierProperty();
Component id_mapper = pc.getIdentifierMapper();
+ // Checking if the id mapping is supported
+ if (id_mapper == null && id_prop == null) {
+ return null;
+ }
+
SimpleIdMapperBuilder mapper;
if (id_mapper != null) {
// Multiple id
15 years
Hibernate SVN: r18108 - core/branches/Branch_3_3/core.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-11-30 23:54:05 -0500 (Mon, 30 Nov 2009)
New Revision: 18108
Modified:
core/branches/Branch_3_3/core/pom.xml
Log:
HHH-4625 - Use of maven-injection-plugin intermittently leads to build failures
Modified: core/branches/Branch_3_3/core/pom.xml
===================================================================
--- core/branches/Branch_3_3/core/pom.xml 2009-12-01 04:53:49 UTC (rev 18107)
+++ core/branches/Branch_3_3/core/pom.xml 2009-12-01 04:54:05 UTC (rev 18108)
@@ -97,7 +97,7 @@
<plugin>
<groupId>org.jboss.maven.plugins</groupId>
<artifactId>maven-injection-plugin</artifactId>
- <version>1.0.1</version>
+ <version>1.0.2</version>
<executions>
<execution>
<phase>compile</phase>
@@ -113,7 +113,7 @@
<targetMembers>
<methodBodyReturn>
<className>org.hibernate.Version</className>
- <methodName>getVersionString</methodName>>
+ <methodName>getVersionString</methodName>
</methodBodyReturn>
</targetMembers>
</bytecodeInjection>
15 years