================================================================================ Merge Diffs: /ade/ailitche_toplink_main/tldev/source/essentials/oracle/toplink/essentials/internal/expressions/SQLUpdateAllStatement.java vs. /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/ailitche/ailitche_ri_gf_1448/ade_storage/000001/AB0952363AC40CBFE034080020E8C54E.9 Report generated at Tue Nov 21 12:43:57 2006 -------------------------------------------------------------------------------- *** /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/ailitche/ailitche_ri_gf_1448/ade_storage/000001/AB0952363AC40CBFE034080020E8C54E.9 Tue Nov 21 12:03:00 2006 --- /ade/ailitche_toplink_main/tldev/source/essentials/oracle/toplink/essentials/internal/expressions/SQLUpdateAllStatement.java Tue Nov 21 12:43:57 2006 *************** *** 18,24 **** * own identifying information: Portions Copyright [yyyy] * [name of copyright owner] */ ! // Copyright (c) 1998, 2006, Oracle. All rights reserved. package oracle.toplink.essentials.internal.expressions; import java.io.*; --- 18,24 ---- * own identifying information: Portions Copyright [yyyy] * [name of copyright owner] */ ! // Copyright (c) 1998, 2006, Oracle. All rights reserved. package oracle.toplink.essentials.internal.expressions; import java.io.*; *************** *** 43,48 **** --- 43,49 ---- protected SQLCall selectCallForExist; protected String tableAliasInSelectCallForExist; protected Collection primaryKeyFields; + protected boolean shouldExtractWhereClauseFromSelectCallForExist; public void setSelectCallForExist(SQLCall selectCallForExist) { this.selectCallForExist = selectCallForExist; *************** *** 74,79 **** --- 75,87 ---- public HashMap getDatabaseFieldsToTableAliases() { return databaseFieldsToTableAliases; } + public void setShouldExtractWhereClauseFromSelectCallForExist(boolean shouldExtractWhereClauseFromSelectCallForExist) { + this.shouldExtractWhereClauseFromSelectCallForExist = shouldExtractWhereClauseFromSelectCallForExist; + } + public boolean shouldExtractWhereClauseFromSelectCallForExist() { + return shouldExtractWhereClauseFromSelectCallForExist; + } + /** * Append the string containing the SQL insert string for the given table. *************** *** 88,99 **** writer.write(call.getSQLString()); if(selectCallForExist != null) { ! writer.write(" WHERE EXISTS("); ! // EXIST Example: selectCall.sqlString: ! // "SELECT t0.EMP_ID FROM EMPLOYEE t0, SALARY t1 WHERE (((t0.F_NAME LIKE 'a') AND (t1.SALARY = 0)) AND (t1.EMP_ID = t0.EMP_ID))" ! writeSelect(writer, selectCallForExist, tableAliasInSelectCallForExist, call); ! // closing bracket for EXISTS ! writer.write(")"); } call.setSQLString(writer.toString()); --- 96,119 ---- writer.write(call.getSQLString()); if(selectCallForExist != null) { ! if(shouldExtractWhereClauseFromSelectCallForExist) { ! // Should get here only in case selectCallForExist doesn't have aliases and ! // targets the same table as the statement. ! // Instead of making selectCallForExist part of " WHERE EXIST(" ! // just extract its where clause. ! // Example: selectCallForExist.sqlString: ! // "SELECT PROJ_ID FROM PROJECT WHERE (LEADER_ID IS NULL) ! writeWhere(writer, selectCallForExist, call); ! // The result is: ! // "WHERE (LEADER_ID IS NULL)" ! } else { ! writer.write(" WHERE EXISTS("); ! // EXIST Example: selectCall.sqlString: ! // "SELECT t0.EMP_ID FROM EMPLOYEE t0, SALARY t1 WHERE (((t0.F_NAME LIKE 'a') AND (t1.SALARY = 0)) AND (t1.EMP_ID = t0.EMP_ID))" ! writeSelect(writer, selectCallForExist, tableAliasInSelectCallForExist, call); ! // closing bracket for EXISTS ! writer.write(")"); ! } } call.setSQLString(writer.toString()); *************** *** 161,173 **** } protected void writeSelect(Writer writer, SQLCall selectCall, String tableAliasInSelectCall, SQLCall call) throws IOException { ! writer.write(selectCall.getSQLString()); // Auto join // Example: AND t0.EMP_ID = EMP_ID Iterator it = getPrimaryKeyFieldsForAutoJoin().iterator(); while(it.hasNext()) { ! writer.write(" AND "); String fieldName = ((DatabaseField)it.next()).getName(); if(tableAliasInSelectCall != null) { writer.write(tableAliasInSelectCall); --- 181,202 ---- } protected void writeSelect(Writer writer, SQLCall selectCall, String tableAliasInSelectCall, SQLCall call) throws IOException { ! String str = selectCall.getSQLString(); ! writer.write(str); ! ! boolean hasWhereClause = str.toUpperCase().indexOf(" WHERE ") >= 0; // Auto join // Example: AND t0.EMP_ID = EMP_ID Iterator it = getPrimaryKeyFieldsForAutoJoin().iterator(); while(it.hasNext()) { ! if(!hasWhereClause) { ! // there is no where clause - should print WHERE ! writer.write(" WHERE "); ! hasWhereClause = true; ! } else { ! writer.write(" AND "); ! } String fieldName = ((DatabaseField)it.next()).getName(); if(tableAliasInSelectCall != null) { writer.write(tableAliasInSelectCall); *************** *** 183,186 **** --- 212,235 ---- call.getParameters().addAll(selectCall.getParameters()); call.getParameterTypes().addAll(selectCall.getParameterTypes()); } + + protected boolean writeWhere(Writer writer, SQLCall selectCall, SQLCall call) throws IOException { + String selectStr = selectCallForExist.getSQLString(); + + int index = selectStr.toUpperCase().indexOf(" WHERE "); + if(index < 0) { + // no where clause - nothing to do + return false; + } + + // print the where clause + String str = selectStr.substring(index); + writer.write(str); + + // add parameters + call.getParameters().addAll(selectCall.getParameters()); + call.getParameterTypes().addAll(selectCall.getParameterTypes()); + + return true; + } } ================================================================================ Merge Diffs: /ade/ailitche_toplink_main/tldev/source/essentials/oracle/toplink/essentials/internal/queryframework/ExpressionQueryMechanism.java vs. /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/ailitche/ailitche_ri_gf_1448/ade_storage/000002/AB0952363AC40CBFE034080020E8C54E.33 Report generated at Tue Nov 21 12:43:57 2006 -------------------------------------------------------------------------------- *** /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/ailitche/ailitche_ri_gf_1448/ade_storage/000002/AB0952363AC40CBFE034080020E8C54E.33 Tue Nov 21 12:04:06 2006 --- /ade/ailitche_toplink_main/tldev/source/essentials/oracle/toplink/essentials/internal/queryframework/ExpressionQueryMechanism.java Tue Nov 21 12:43:57 2006 *************** *** 581,598 **** updateAllStatement.setUpdateClauses(databaseFieldsToValuesCopy); updateAllStatement.setDatabaseFieldsToTableAliases(databaseFieldsToTableAliases); ! if(selectCallForExist != null) { ! updateAllStatement.setSelectCallForExist(selectCallForExist); ! updateAllStatement.setTableAliasInSelectCallForExist(getAliasTableName(selectStatementForExist, table)); ! updateAllStatement.setPrimaryKeyFieldsForAutoJoin(primaryKeyFields); ! } else { ! updateAllStatement.setWhereClause(getSelectionCriteria()); ! if(updateAllStatement.getWhereClause() != null) { ! updateAllStatement.setWhereClause((Expression)updateAllStatement.getWhereClause().clone()); ! updateAllStatement.getWhereClause().getBuilder().setSession(getSession().getRootSession(null)); ! updateAllStatement.getWhereClause().getBuilder().setQueryClass(getQuery().getReferenceClass()); ! } ! } return updateAllStatement; } --- 581,590 ---- updateAllStatement.setUpdateClauses(databaseFieldsToValuesCopy); updateAllStatement.setDatabaseFieldsToTableAliases(databaseFieldsToTableAliases); ! updateAllStatement.setSelectCallForExist(selectCallForExist); ! updateAllStatement.setShouldExtractWhereClauseFromSelectCallForExist(!selectStatementForExist.requiresAliases() && table.equals(selectStatementForExist.getTables().firstElement())); ! updateAllStatement.setTableAliasInSelectCallForExist(getAliasTableName(selectStatementForExist, table)); ! updateAllStatement.setPrimaryKeyFieldsForAutoJoin(primaryKeyFields); return updateAllStatement; } *************** *** 1612,1624 **** // Main Case: Descriptor is mapped to more than one table and/or the query references other tables boolean isMainCase = selectStatementForExist.requiresAliases(); ! if(isMainCase && getSelectionCriteria() != null) { if(getSession().getPlatform().shouldAlwaysUseTempStorageForModifyAll()) { prepareUpdateAllUsingTempStorage(tables_databaseFieldsToValues, tablesToPrimaryKeyFields); return; } - selectCallForExist = (SQLCall)selectStatementForExist.buildCall(getSession()); } // ExpressionIterator to search for valueExpressions that require select statements. // Those are expressions that --- 1604,1616 ---- // Main Case: Descriptor is mapped to more than one table and/or the query references other tables boolean isMainCase = selectStatementForExist.requiresAliases(); ! if(isMainCase) { if(getSession().getPlatform().shouldAlwaysUseTempStorageForModifyAll()) { prepareUpdateAllUsingTempStorage(tables_databaseFieldsToValues, tablesToPrimaryKeyFields); return; } } + selectCallForExist = (SQLCall)selectStatementForExist.buildCall(getSession()); // ExpressionIterator to search for valueExpressions that require select statements. // Those are expressions that ================================================================================ Merge Diffs: /ade/ailitche_toplink_main/tltest/source/entity-persistence-tests/src/java/oracle/toplink/essentials/testing/tests/cmp3/advanced/EntityManagerJUnitTestSuite.java vs. /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/ailitche/ailitche_ri_gf_1448/ade_storage/000003/AB0952363AC40CBFE034080020E8C54E.59 Report generated at Tue Nov 21 12:43:57 2006 -------------------------------------------------------------------------------- *** /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/ailitche/ailitche_ri_gf_1448/ade_storage/000003/AB0952363AC40CBFE034080020E8C54E.59 Tue Nov 21 12:05:31 2006 --- /ade/ailitche_toplink_main/tltest/source/entity-persistence-tests/src/java/oracle/toplink/essentials/testing/tests/cmp3/advanced/EntityManagerJUnitTestSuite.java Tue Nov 21 12:43:57 2006 *************** *** 30,35 **** --- 30,36 ---- import java.io.StringWriter; import java.util.ArrayList; + import java.util.HashMap; import java.util.List; import java.util.Collection; *************** *** 3238,3243 **** --- 3239,3595 ---- } } + protected void createProjectsWithName(String name, Employee teamLeader) { + EntityManager em = createEntityManager(); + try { + em.getTransaction().begin(); + + SmallProject sp = new SmallProject(); + sp.setName(name); + + LargeProject lp = new LargeProject(); + lp.setName(name); + + em.persist(sp); + em.persist(lp); + + if(teamLeader != null) { + SmallProject sp2 = new SmallProject(); + sp2.setName(name); + sp2.setTeamLeader(teamLeader); + + LargeProject lp2 = new LargeProject(); + lp2.setName(name); + lp2.setTeamLeader(teamLeader); + + em.persist(sp2); + em.persist(lp2); + } + + em.getTransaction().commit(); + } catch (RuntimeException ex) { + if(em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + throw ex; + } finally { + em.close(); + } + } + + protected void deleteProjectsWithName(String name) { + EntityManager em = createEntityManager(); + try { + em.getTransaction().begin(); + + em.createQuery("DELETE FROM Project p WHERE p.name = '"+name+"'").executeUpdate(); + + em.getTransaction().commit(); + } catch (RuntimeException ex) { + if(em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + throw ex; + } finally { + em.close(); + } + } + + public void testUpdateAllSmallProjects() { + internalTestUpdateAllProjects(SmallProject.class); + } + public void testUpdateAllLargeProjects() { + internalTestUpdateAllProjects(LargeProject.class); + } + public void testUpdateAllProjects() { + internalTestUpdateAllProjects(Project.class); + } + protected void internalTestUpdateAllProjects(Class cls) { + String className = Helper.getShortClassName(cls); + String name = "testUpdateAllProjects"; + String newName = "testUpdateAllProjectsNEW"; + HashMap map = null; + boolean ok = false; + + try { + // setup + // populate Projects - necessary only if no SmallProject and/or LargeProject objects already exist. + createProjectsWithName(name, null); + // save the original names of projects: will set them back in cleanup + // to restore the original state. + EntityManager em = createEntityManager(); + List projects = em.createQuery("SELECT OBJECT(p) FROM Project p").getResultList(); + map = new HashMap(projects.size()); + for(int i=0; i 0) { + fail(errorMsg); + } else { + ok = true; + } + } finally { + // clean-up + try { + if(map != null) { + EntityManager em = createEntityManager(); + List projects = em.createQuery("SELECT OBJECT(p) FROM Project p").getResultList(); + em.getTransaction().begin(); + try { + for(int i=0; i 0) { + fail(errorMsg); + } else { + ok = true; + } + } finally { + // clean-up + // make sure no projects with the specified names left + try { + deleteProjectsWithName(name); + deleteProjectsWithName(newName); + } catch (RuntimeException ex) { + // eat clean-up exception in case the test failed + if(ok) { + throw ex; + } + } + } + } + + public void testUpdateAllSmallProjectsWithNullTeamLeader() { + internalTestUpdateAllProjectsWithNullTeamLeader(SmallProject.class); + } + public void testUpdateAllLargeProjectsWithNullTeamLeader() { + internalTestUpdateAllProjectsWithNullTeamLeader(LargeProject.class); + } + public void testUpdateAllProjectsWithNullTeamLeader() { + internalTestUpdateAllProjectsWithNullTeamLeader(Project.class); + } + protected void internalTestUpdateAllProjectsWithNullTeamLeader(Class cls) { + String className = Helper.getShortClassName(cls); + String name = "testUpdateAllProjects"; + String newName = "testUpdateAllProjectsNEW"; + Employee empTemp = null; + boolean ok = false; + + try { + // setup + // make sure no projects with the specified names exist + deleteProjectsWithName(name); + deleteProjectsWithName(newName); + EntityManager em = createEntityManager(); + Employee emp = null; + List employees = em.createQuery("SELECT OBJECT(e) FROM Employee e").getResultList(); + if(employees.size() > 0) { + emp = (Employee)employees.get(0); + } else { + em.getTransaction().begin(); + try { + emp = new Employee(); + emp.setFirstName(name); + emp.setLastName("TeamLeader"); + em.persist(emp); + em.getTransaction().commit(); + empTemp = emp; + } catch (RuntimeException ex) { + if(em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + throw ex; + } + } + em.close(); + // populate Projects + createProjectsWithName(name, emp); + + // test + em = createEntityManager(); + em.getTransaction().begin(); + try { + em.createQuery("UPDATE "+className+" p set p.name = '"+newName+"' WHERE p.name = '"+name+"' AND p.teamLeader IS NULL").executeUpdate(); + em.getTransaction().commit(); + } catch (RuntimeException ex) { + if(em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + throw ex; + } finally { + em.close(); + } + + // verify + em = createEntityManager(); + String errorMsg = ""; + List projects = em.createQuery("SELECT OBJECT(p) FROM Project p WHERE p.name = '"+newName+"' OR p.name = '"+name+"'").getResultList(); + for(int i=0; i 0) { + fail(errorMsg); + } else { + ok = true; + } + } finally { + // clean-up + // make sure no projects with the specified names exist + try { + deleteProjectsWithName(name); + deleteProjectsWithName(newName); + if(empTemp != null) { + EntityManager em = createEntityManager(); + em.getTransaction().begin(); + try { + em.createQuery("DELETE FROM Employee e WHERE e.id = '"+empTemp.getId()+"'").executeUpdate(); + em.getTransaction().commit(); + } catch (RuntimeException ex) { + if(em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + throw ex; + } finally { + em.close(); + } + } + } catch (RuntimeException ex) { + // eat clean-up exception in case the test failed + if(ok) { + throw ex; + } + } + } + } + public static void main(String[] args) { // Now run JUnit. junit.swingui.TestRunner.main(args); ================================================================================ Merge Diffs: /ade/ailitche_toplink_main/tldev/source/essentials/oracle/toplink/essentials/internal/expressions/SQLUpdateAllStatement.java vs. /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/ailitche/ailitche_ri_gf_1448/ade_storage/000001/AB0952363AC40CBFE034080020E8C54E.9 Report generated at Tue Nov 21 12:50:14 2006 -------------------------------------------------------------------------------- *** /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/ailitche/ailitche_ri_gf_1448/ade_storage/000001/AB0952363AC40CBFE034080020E8C54E.9 Tue Nov 21 12:03:00 2006 --- /ade/ailitche_toplink_main/tldev/source/essentials/oracle/toplink/essentials/internal/expressions/SQLUpdateAllStatement.java Tue Nov 21 12:43:57 2006 *************** *** 18,24 **** * own identifying information: Portions Copyright [yyyy] * [name of copyright owner] */ ! // Copyright (c) 1998, 2006, Oracle. All rights reserved. package oracle.toplink.essentials.internal.expressions; import java.io.*; --- 18,24 ---- * own identifying information: Portions Copyright [yyyy] * [name of copyright owner] */ ! // Copyright (c) 1998, 2006, Oracle. All rights reserved. package oracle.toplink.essentials.internal.expressions; import java.io.*; *************** *** 43,48 **** --- 43,49 ---- protected SQLCall selectCallForExist; protected String tableAliasInSelectCallForExist; protected Collection primaryKeyFields; + protected boolean shouldExtractWhereClauseFromSelectCallForExist; public void setSelectCallForExist(SQLCall selectCallForExist) { this.selectCallForExist = selectCallForExist; *************** *** 74,79 **** --- 75,87 ---- public HashMap getDatabaseFieldsToTableAliases() { return databaseFieldsToTableAliases; } + public void setShouldExtractWhereClauseFromSelectCallForExist(boolean shouldExtractWhereClauseFromSelectCallForExist) { + this.shouldExtractWhereClauseFromSelectCallForExist = shouldExtractWhereClauseFromSelectCallForExist; + } + public boolean shouldExtractWhereClauseFromSelectCallForExist() { + return shouldExtractWhereClauseFromSelectCallForExist; + } + /** * Append the string containing the SQL insert string for the given table. *************** *** 88,99 **** writer.write(call.getSQLString()); if(selectCallForExist != null) { ! writer.write(" WHERE EXISTS("); ! // EXIST Example: selectCall.sqlString: ! // "SELECT t0.EMP_ID FROM EMPLOYEE t0, SALARY t1 WHERE (((t0.F_NAME LIKE 'a') AND (t1.SALARY = 0)) AND (t1.EMP_ID = t0.EMP_ID))" ! writeSelect(writer, selectCallForExist, tableAliasInSelectCallForExist, call); ! // closing bracket for EXISTS ! writer.write(")"); } call.setSQLString(writer.toString()); --- 96,119 ---- writer.write(call.getSQLString()); if(selectCallForExist != null) { ! if(shouldExtractWhereClauseFromSelectCallForExist) { ! // Should get here only in case selectCallForExist doesn't have aliases and ! // targets the same table as the statement. ! // Instead of making selectCallForExist part of " WHERE EXIST(" ! // just extract its where clause. ! // Example: selectCallForExist.sqlString: ! // "SELECT PROJ_ID FROM PROJECT WHERE (LEADER_ID IS NULL) ! writeWhere(writer, selectCallForExist, call); ! // The result is: ! // "WHERE (LEADER_ID IS NULL)" ! } else { ! writer.write(" WHERE EXISTS("); ! // EXIST Example: selectCall.sqlString: ! // "SELECT t0.EMP_ID FROM EMPLOYEE t0, SALARY t1 WHERE (((t0.F_NAME LIKE 'a') AND (t1.SALARY = 0)) AND (t1.EMP_ID = t0.EMP_ID))" ! writeSelect(writer, selectCallForExist, tableAliasInSelectCallForExist, call); ! // closing bracket for EXISTS ! writer.write(")"); ! } } call.setSQLString(writer.toString()); *************** *** 161,173 **** } protected void writeSelect(Writer writer, SQLCall selectCall, String tableAliasInSelectCall, SQLCall call) throws IOException { ! writer.write(selectCall.getSQLString()); // Auto join // Example: AND t0.EMP_ID = EMP_ID Iterator it = getPrimaryKeyFieldsForAutoJoin().iterator(); while(it.hasNext()) { ! writer.write(" AND "); String fieldName = ((DatabaseField)it.next()).getName(); if(tableAliasInSelectCall != null) { writer.write(tableAliasInSelectCall); --- 181,202 ---- } protected void writeSelect(Writer writer, SQLCall selectCall, String tableAliasInSelectCall, SQLCall call) throws IOException { ! String str = selectCall.getSQLString(); ! writer.write(str); ! ! boolean hasWhereClause = str.toUpperCase().indexOf(" WHERE ") >= 0; // Auto join // Example: AND t0.EMP_ID = EMP_ID Iterator it = getPrimaryKeyFieldsForAutoJoin().iterator(); while(it.hasNext()) { ! if(!hasWhereClause) { ! // there is no where clause - should print WHERE ! writer.write(" WHERE "); ! hasWhereClause = true; ! } else { ! writer.write(" AND "); ! } String fieldName = ((DatabaseField)it.next()).getName(); if(tableAliasInSelectCall != null) { writer.write(tableAliasInSelectCall); *************** *** 183,186 **** --- 212,235 ---- call.getParameters().addAll(selectCall.getParameters()); call.getParameterTypes().addAll(selectCall.getParameterTypes()); } + + protected boolean writeWhere(Writer writer, SQLCall selectCall, SQLCall call) throws IOException { + String selectStr = selectCallForExist.getSQLString(); + + int index = selectStr.toUpperCase().indexOf(" WHERE "); + if(index < 0) { + // no where clause - nothing to do + return false; + } + + // print the where clause + String str = selectStr.substring(index); + writer.write(str); + + // add parameters + call.getParameters().addAll(selectCall.getParameters()); + call.getParameterTypes().addAll(selectCall.getParameterTypes()); + + return true; + } } ================================================================================ Merge Diffs: /ade/ailitche_toplink_main/tldev/source/essentials/oracle/toplink/essentials/internal/queryframework/ExpressionQueryMechanism.java vs. /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/ailitche/ailitche_ri_gf_1448/ade_storage/000002/AB0952363AC40CBFE034080020E8C54E.33 Report generated at Tue Nov 21 12:50:14 2006 -------------------------------------------------------------------------------- *** /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/ailitche/ailitche_ri_gf_1448/ade_storage/000002/AB0952363AC40CBFE034080020E8C54E.33 Tue Nov 21 12:04:06 2006 --- /ade/ailitche_toplink_main/tldev/source/essentials/oracle/toplink/essentials/internal/queryframework/ExpressionQueryMechanism.java Tue Nov 21 12:43:57 2006 *************** *** 581,598 **** updateAllStatement.setUpdateClauses(databaseFieldsToValuesCopy); updateAllStatement.setDatabaseFieldsToTableAliases(databaseFieldsToTableAliases); ! if(selectCallForExist != null) { ! updateAllStatement.setSelectCallForExist(selectCallForExist); ! updateAllStatement.setTableAliasInSelectCallForExist(getAliasTableName(selectStatementForExist, table)); ! updateAllStatement.setPrimaryKeyFieldsForAutoJoin(primaryKeyFields); ! } else { ! updateAllStatement.setWhereClause(getSelectionCriteria()); ! if(updateAllStatement.getWhereClause() != null) { ! updateAllStatement.setWhereClause((Expression)updateAllStatement.getWhereClause().clone()); ! updateAllStatement.getWhereClause().getBuilder().setSession(getSession().getRootSession(null)); ! updateAllStatement.getWhereClause().getBuilder().setQueryClass(getQuery().getReferenceClass()); ! } ! } return updateAllStatement; } --- 581,590 ---- updateAllStatement.setUpdateClauses(databaseFieldsToValuesCopy); updateAllStatement.setDatabaseFieldsToTableAliases(databaseFieldsToTableAliases); ! updateAllStatement.setSelectCallForExist(selectCallForExist); ! updateAllStatement.setShouldExtractWhereClauseFromSelectCallForExist(!selectStatementForExist.requiresAliases() && table.equals(selectStatementForExist.getTables().firstElement())); ! updateAllStatement.setTableAliasInSelectCallForExist(getAliasTableName(selectStatementForExist, table)); ! updateAllStatement.setPrimaryKeyFieldsForAutoJoin(primaryKeyFields); return updateAllStatement; } *************** *** 1612,1624 **** // Main Case: Descriptor is mapped to more than one table and/or the query references other tables boolean isMainCase = selectStatementForExist.requiresAliases(); ! if(isMainCase && getSelectionCriteria() != null) { if(getSession().getPlatform().shouldAlwaysUseTempStorageForModifyAll()) { prepareUpdateAllUsingTempStorage(tables_databaseFieldsToValues, tablesToPrimaryKeyFields); return; } - selectCallForExist = (SQLCall)selectStatementForExist.buildCall(getSession()); } // ExpressionIterator to search for valueExpressions that require select statements. // Those are expressions that --- 1604,1616 ---- // Main Case: Descriptor is mapped to more than one table and/or the query references other tables boolean isMainCase = selectStatementForExist.requiresAliases(); ! if(isMainCase) { if(getSession().getPlatform().shouldAlwaysUseTempStorageForModifyAll()) { prepareUpdateAllUsingTempStorage(tables_databaseFieldsToValues, tablesToPrimaryKeyFields); return; } } + selectCallForExist = (SQLCall)selectStatementForExist.buildCall(getSession()); // ExpressionIterator to search for valueExpressions that require select statements. // Those are expressions that ================================================================================ Merge Diffs: /ade/ailitche_toplink_main/tltest/source/entity-persistence-tests/src/java/oracle/toplink/essentials/testing/tests/cmp3/advanced/EntityManagerJUnitTestSuite.java vs. /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/ailitche/ailitche_ri_gf_1448/ade_storage/000003/AB0952363AC40CBFE034080020E8C54E.59 Report generated at Tue Nov 21 12:50:14 2006 -------------------------------------------------------------------------------- *** /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/ailitche/ailitche_ri_gf_1448/ade_storage/000003/AB0952363AC40CBFE034080020E8C54E.59 Tue Nov 21 12:05:31 2006 --- /ade/ailitche_toplink_main/tltest/source/entity-persistence-tests/src/java/oracle/toplink/essentials/testing/tests/cmp3/advanced/EntityManagerJUnitTestSuite.java Tue Nov 21 12:43:57 2006 *************** *** 30,35 **** --- 30,36 ---- import java.io.StringWriter; import java.util.ArrayList; + import java.util.HashMap; import java.util.List; import java.util.Collection; *************** *** 3238,3243 **** --- 3239,3595 ---- } } + protected void createProjectsWithName(String name, Employee teamLeader) { + EntityManager em = createEntityManager(); + try { + em.getTransaction().begin(); + + SmallProject sp = new SmallProject(); + sp.setName(name); + + LargeProject lp = new LargeProject(); + lp.setName(name); + + em.persist(sp); + em.persist(lp); + + if(teamLeader != null) { + SmallProject sp2 = new SmallProject(); + sp2.setName(name); + sp2.setTeamLeader(teamLeader); + + LargeProject lp2 = new LargeProject(); + lp2.setName(name); + lp2.setTeamLeader(teamLeader); + + em.persist(sp2); + em.persist(lp2); + } + + em.getTransaction().commit(); + } catch (RuntimeException ex) { + if(em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + throw ex; + } finally { + em.close(); + } + } + + protected void deleteProjectsWithName(String name) { + EntityManager em = createEntityManager(); + try { + em.getTransaction().begin(); + + em.createQuery("DELETE FROM Project p WHERE p.name = '"+name+"'").executeUpdate(); + + em.getTransaction().commit(); + } catch (RuntimeException ex) { + if(em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + throw ex; + } finally { + em.close(); + } + } + + public void testUpdateAllSmallProjects() { + internalTestUpdateAllProjects(SmallProject.class); + } + public void testUpdateAllLargeProjects() { + internalTestUpdateAllProjects(LargeProject.class); + } + public void testUpdateAllProjects() { + internalTestUpdateAllProjects(Project.class); + } + protected void internalTestUpdateAllProjects(Class cls) { + String className = Helper.getShortClassName(cls); + String name = "testUpdateAllProjects"; + String newName = "testUpdateAllProjectsNEW"; + HashMap map = null; + boolean ok = false; + + try { + // setup + // populate Projects - necessary only if no SmallProject and/or LargeProject objects already exist. + createProjectsWithName(name, null); + // save the original names of projects: will set them back in cleanup + // to restore the original state. + EntityManager em = createEntityManager(); + List projects = em.createQuery("SELECT OBJECT(p) FROM Project p").getResultList(); + map = new HashMap(projects.size()); + for(int i=0; i 0) { + fail(errorMsg); + } else { + ok = true; + } + } finally { + // clean-up + try { + if(map != null) { + EntityManager em = createEntityManager(); + List projects = em.createQuery("SELECT OBJECT(p) FROM Project p").getResultList(); + em.getTransaction().begin(); + try { + for(int i=0; i 0) { + fail(errorMsg); + } else { + ok = true; + } + } finally { + // clean-up + // make sure no projects with the specified names left + try { + deleteProjectsWithName(name); + deleteProjectsWithName(newName); + } catch (RuntimeException ex) { + // eat clean-up exception in case the test failed + if(ok) { + throw ex; + } + } + } + } + + public void testUpdateAllSmallProjectsWithNullTeamLeader() { + internalTestUpdateAllProjectsWithNullTeamLeader(SmallProject.class); + } + public void testUpdateAllLargeProjectsWithNullTeamLeader() { + internalTestUpdateAllProjectsWithNullTeamLeader(LargeProject.class); + } + public void testUpdateAllProjectsWithNullTeamLeader() { + internalTestUpdateAllProjectsWithNullTeamLeader(Project.class); + } + protected void internalTestUpdateAllProjectsWithNullTeamLeader(Class cls) { + String className = Helper.getShortClassName(cls); + String name = "testUpdateAllProjects"; + String newName = "testUpdateAllProjectsNEW"; + Employee empTemp = null; + boolean ok = false; + + try { + // setup + // make sure no projects with the specified names exist + deleteProjectsWithName(name); + deleteProjectsWithName(newName); + EntityManager em = createEntityManager(); + Employee emp = null; + List employees = em.createQuery("SELECT OBJECT(e) FROM Employee e").getResultList(); + if(employees.size() > 0) { + emp = (Employee)employees.get(0); + } else { + em.getTransaction().begin(); + try { + emp = new Employee(); + emp.setFirstName(name); + emp.setLastName("TeamLeader"); + em.persist(emp); + em.getTransaction().commit(); + empTemp = emp; + } catch (RuntimeException ex) { + if(em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + throw ex; + } + } + em.close(); + // populate Projects + createProjectsWithName(name, emp); + + // test + em = createEntityManager(); + em.getTransaction().begin(); + try { + em.createQuery("UPDATE "+className+" p set p.name = '"+newName+"' WHERE p.name = '"+name+"' AND p.teamLeader IS NULL").executeUpdate(); + em.getTransaction().commit(); + } catch (RuntimeException ex) { + if(em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + throw ex; + } finally { + em.close(); + } + + // verify + em = createEntityManager(); + String errorMsg = ""; + List projects = em.createQuery("SELECT OBJECT(p) FROM Project p WHERE p.name = '"+newName+"' OR p.name = '"+name+"'").getResultList(); + for(int i=0; i 0) { + fail(errorMsg); + } else { + ok = true; + } + } finally { + // clean-up + // make sure no projects with the specified names exist + try { + deleteProjectsWithName(name); + deleteProjectsWithName(newName); + if(empTemp != null) { + EntityManager em = createEntityManager(); + em.getTransaction().begin(); + try { + em.createQuery("DELETE FROM Employee e WHERE e.id = '"+empTemp.getId()+"'").executeUpdate(); + em.getTransaction().commit(); + } catch (RuntimeException ex) { + if(em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + throw ex; + } finally { + em.close(); + } + } + } catch (RuntimeException ex) { + // eat clean-up exception in case the test failed + if(ok) { + throw ex; + } + } + } + } + public static void main(String[] args) { // Now run JUnit. junit.swingui.TestRunner.main(args);