Bug# 429232 - Instance of UnitOfWork is stored in ExpressionBuilder inside ConcurrentFixedCache.
Signed-off-by: Tomas Kraus <tomas.kraus@oracle.com>
Reviewed-by: Gordon Yorke
diff --git a/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/expressions/ExpressionBuilderTestSuite.java b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/expressions/ExpressionBuilderTestSuite.java
new file mode 100644
index 0000000..e23f50b
--- /dev/null
+++ b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/expressions/ExpressionBuilderTestSuite.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ * Tomas Kraus - Initial API and implementation.
+ ******************************************************************************/
+package org.eclipse.persistence.testing.tests.expressions;
+
+import org.eclipse.persistence.expressions.ExpressionBuilder;
+import org.eclipse.persistence.internal.sessions.AbstractSession;
+import org.eclipse.persistence.internal.sessions.UnitOfWorkImpl;
+import org.eclipse.persistence.sessions.UnitOfWork;
+import org.eclipse.persistence.testing.framework.TestCase;
+import org.eclipse.persistence.testing.framework.TestErrorException;
+
+/**
+ * Test ExpressionBuilder class and instance methods.
+ */
+public class ExpressionBuilderTestSuite extends TestCase {
+
+ public ExpressionBuilderTestSuite() {
+ super();
+ setName(getName());
+ setDescription("Test ExpressionBuilder class and instance methods");
+ }
+
+ public void setup() {
+ }
+
+ // Execute all tests in suite.
+ public void test() {
+ testUnitOfWorkInExpressionBuilder();
+ }
+
+ // Bug# 429232 - Instance of UnitOfWork is stored in ExpressionBuilder inside ConcurrentFixedCache
+ // Make sure that [ExpressionBuilder].setSession() will not store UnitOfWork inside builder even
+ // when UnitOfWork is passed as an argument.
+ public void testUnitOfWorkInExpressionBuilder() {
+ ExpressionBuilder builder = new ExpressionBuilder();
+ UnitOfWorkImpl uow = (UnitOfWorkImpl)getSession().acquireUnitOfWork();
+ builder.setSession(uow);
+ AbstractSession session = builder.getSession();
+ if (session instanceof UnitOfWork) {
+ throw new TestErrorException("Session stored in ExpressionBuilder shall not be UnitOfWork.");
+ }
+ }
+
+}
diff --git a/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/expressions/ExpressionTestSuite.java b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/expressions/ExpressionTestSuite.java
index 1d4fe11..fce7895 100644
--- a/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/expressions/ExpressionTestSuite.java
+++ b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/expressions/ExpressionTestSuite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 1998, 2013 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2015 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
@@ -1708,6 +1708,8 @@
addTest(new LowerCaseForCaseInsensitiveTest(LowerCaseForCaseInsensitiveTest.EqualsIgnoreCase));
addTest(new LowerCaseForCaseInsensitiveTest(LowerCaseForCaseInsensitiveTest.LikeIgnoreCase));
addTest(new LowerCaseForCaseInsensitiveTest(LowerCaseForCaseInsensitiveTest.ContainsSubstringIgnoringCase));
+ // ExpressionBuilder test suite
+ addTest(new ExpressionBuilderTestSuite());
}
//SRG test set is maintained by QA only, do NOT add any new tests into it.
diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/expressions/ExpressionBuilder.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/expressions/ExpressionBuilder.java
index bd3aa14..f9c8875 100644
--- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/expressions/ExpressionBuilder.java
+++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/expressions/ExpressionBuilder.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 1998, 2013 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2015 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
@@ -23,6 +23,7 @@
import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.internal.expressions.*;
import org.eclipse.persistence.queries.DatabaseQuery;
+import org.eclipse.persistence.sessions.UnitOfWork;
/**
* <P>
@@ -410,9 +411,10 @@
/**
* INTERNAL:
* Set the session in which we expect this expression to be translated.
+ * Stored session shall always be root session.
*/
public void setSession(AbstractSession session) {
- this.session = session;
+ this.session = session.getRootSession(null);
}
/**