Index: resource/eclipselink-annotation-model/persistence.xml =================================================================== --- resource/eclipselink-annotation-model/persistence.xml (revision 6615) +++ resource/eclipselink-annotation-model/persistence.xml (working copy) @@ -66,6 +66,7 @@ + Index: src/org/eclipse/persistence/testing/models/jpa/advanced/AdvancedTableCreator.java =================================================================== --- src/org/eclipse/persistence/testing/models/jpa/advanced/AdvancedTableCreator.java (revision 6615) +++ src/org/eclipse/persistence/testing/models/jpa/advanced/AdvancedTableCreator.java (working copy) @@ -51,7 +51,13 @@ addTableDefinition(buildCONCURRENCYBTable()); addTableDefinition(buildCONCURRENCYCTable()); addTableDefinition(buildREADONLYISOLATED()); - + addTableDefinition(buildENTITYBTable()); + addTableDefinition(buildENTITYCTable()); + addTableDefinition(buildENTITYATable()); + addTableDefinition(buildENTITYDTable()); + addTableDefinition(buildADVENTITYAENTITYDTable()); + addTableDefinition(buildENTITYETable()); + addTableDefinition(buildADVENTITYAENTITYETable()); } public static TableDefinition buildADDRESSTable() { @@ -1488,4 +1494,231 @@ return table; } + + public static TableDefinition buildENTITYBTable() { + TableDefinition table = new TableDefinition(); + table.setName("ADV_ENTYB"); + + FieldDefinition fieldID = new FieldDefinition(); + fieldID.setName("ID"); + fieldID.setTypeName("NUMERIC"); + fieldID.setSize(15); + fieldID.setSubSize(0); + fieldID.setIsPrimaryKey(true); + fieldID.setIsIdentity(true); + fieldID.setUnique(false); + fieldID.setShouldAllowNull(false); + table.addField(fieldID); + + FieldDefinition fieldNAME = new FieldDefinition(); + fieldNAME.setName("NAME"); + fieldNAME.setTypeName("VARCHAR2"); + fieldNAME.setSize(60); + fieldNAME.setSubSize(0); + fieldNAME.setIsPrimaryKey(false); + fieldNAME.setIsIdentity(false); + fieldNAME.setUnique(false); + fieldNAME.setShouldAllowNull(true); + table.addField(fieldNAME); + + return table; + } + + public static TableDefinition buildENTITYATable() { + TableDefinition table = new TableDefinition(); + table.setName("ADV_ENTYA"); + + FieldDefinition fieldID = new FieldDefinition(); + fieldID.setName("ID"); + fieldID.setTypeName("NUMERIC"); + fieldID.setSize(15); + fieldID.setSubSize(0); + fieldID.setIsPrimaryKey(true); + fieldID.setIsIdentity(true); + fieldID.setUnique(false); + fieldID.setShouldAllowNull(false); + table.addField(fieldID); + + FieldDefinition fieldNAME = new FieldDefinition(); + fieldNAME.setName("NAME"); + fieldNAME.setTypeName("VARCHAR2"); + fieldNAME.setSize(60); + fieldNAME.setSubSize(0); + fieldNAME.setIsPrimaryKey(false); + fieldNAME.setIsIdentity(false); + fieldNAME.setUnique(false); + fieldNAME.setShouldAllowNull(true); + table.addField(fieldNAME); + + FieldDefinition fieldEntyB = new FieldDefinition(); + fieldEntyB.setName("ENTYB_ID"); + fieldEntyB.setTypeName("NUMERIC"); + fieldEntyB.setSize(15); + fieldEntyB.setSubSize(0); + fieldEntyB.setIsPrimaryKey(false); + fieldEntyB.setIsIdentity(false); + fieldEntyB.setUnique(false); + fieldEntyB.setForeignKeyFieldName("ADV_ENTYB.ID"); + table.addField(fieldEntyB); + + FieldDefinition fieldEntyC = new FieldDefinition(); + fieldEntyC.setName("ENTYC_ID"); + fieldEntyC.setTypeName("NUMERIC"); + fieldEntyC.setSize(15); + fieldEntyC.setSubSize(0); + fieldEntyC.setIsPrimaryKey(false); + fieldEntyC.setIsIdentity(false); + fieldEntyC.setUnique(false); + fieldEntyC.setForeignKeyFieldName("ADV_ENTYC.ID"); + table.addField(fieldEntyC); + + return table; + } + + public static TableDefinition buildENTITYDTable() { + TableDefinition table = new TableDefinition(); + table.setName("ADV_ENTYD"); + + FieldDefinition fieldID = new FieldDefinition(); + fieldID.setName("ID"); + fieldID.setTypeName("NUMERIC"); + fieldID.setSize(15); + fieldID.setSubSize(0); + fieldID.setIsPrimaryKey(true); + fieldID.setIsIdentity(true); + fieldID.setUnique(false); + fieldID.setShouldAllowNull(false); + table.addField(fieldID); + + FieldDefinition fieldNAME = new FieldDefinition(); + fieldNAME.setName("NAME"); + fieldNAME.setTypeName("VARCHAR2"); + fieldNAME.setSize(60); + fieldNAME.setSubSize(0); + fieldNAME.setIsPrimaryKey(false); + fieldNAME.setIsIdentity(false); + fieldNAME.setUnique(false); + fieldNAME.setShouldAllowNull(true); + table.addField(fieldNAME); + + return table; + } + + public static TableDefinition buildENTITYCTable() { + TableDefinition table = new TableDefinition(); + table.setName("ADV_ENTYC"); + + FieldDefinition fieldID = new FieldDefinition(); + fieldID.setName("ID"); + fieldID.setTypeName("NUMERIC"); + fieldID.setSize(15); + fieldID.setSubSize(0); + fieldID.setIsPrimaryKey(true); + fieldID.setIsIdentity(true); + fieldID.setUnique(false); + fieldID.setShouldAllowNull(false); + table.addField(fieldID); + + FieldDefinition fieldNAME = new FieldDefinition(); + fieldNAME.setName("NAME"); + fieldNAME.setTypeName("VARCHAR2"); + fieldNAME.setSize(60); + fieldNAME.setSubSize(0); + fieldNAME.setIsPrimaryKey(false); + fieldNAME.setIsIdentity(false); + fieldNAME.setUnique(false); + fieldNAME.setShouldAllowNull(true); + table.addField(fieldNAME); + + return table; + } + + public static TableDefinition buildADVENTITYAENTITYDTable() { + TableDefinition table = new TableDefinition(); + + table.setName("ADV_ENTYA_ADV_ENTYD"); + + FieldDefinition fieldORDERID = new FieldDefinition(); + fieldORDERID.setName("EntyA_ID"); + fieldORDERID.setTypeName("NUMERIC"); + fieldORDERID.setSize(15); + fieldORDERID.setShouldAllowNull(false); + fieldORDERID.setIsPrimaryKey(false); + fieldORDERID.setUnique(false); + fieldORDERID.setIsIdentity(false); + fieldORDERID.setForeignKeyFieldName("ADV_ENTYA.ID"); + table.addField(fieldORDERID); + + FieldDefinition fieldAUDITORID = new FieldDefinition(); + fieldAUDITORID.setName("entyDs_ID"); + fieldAUDITORID.setTypeName("NUMERIC"); + fieldAUDITORID.setSize(15); + fieldAUDITORID.setShouldAllowNull(false); + fieldAUDITORID.setIsPrimaryKey(false); + fieldAUDITORID.setUnique(true); + fieldAUDITORID.setIsIdentity(false); + fieldAUDITORID.setForeignKeyFieldName("ADV_ENTYD.ID"); + table.addField(fieldAUDITORID); + + return table; + } + + public static TableDefinition buildENTITYETable() { + TableDefinition table = new TableDefinition(); + table.setName("ADV_ENTYE"); + + FieldDefinition fieldID = new FieldDefinition(); + fieldID.setName("ID"); + fieldID.setTypeName("NUMERIC"); + fieldID.setSize(15); + fieldID.setSubSize(0); + fieldID.setIsPrimaryKey(true); + fieldID.setIsIdentity(true); + fieldID.setUnique(false); + fieldID.setShouldAllowNull(false); + table.addField(fieldID); + + FieldDefinition fieldNAME = new FieldDefinition(); + fieldNAME.setName("NAME"); + fieldNAME.setTypeName("VARCHAR2"); + fieldNAME.setSize(60); + fieldNAME.setSubSize(0); + fieldNAME.setIsPrimaryKey(false); + fieldNAME.setIsIdentity(false); + fieldNAME.setUnique(false); + fieldNAME.setShouldAllowNull(true); + table.addField(fieldNAME); + + return table; + } + + public static TableDefinition buildADVENTITYAENTITYETable() { + TableDefinition table = new TableDefinition(); + + table.setName("ADV_ENTYA_ADV_ENTYE"); + + FieldDefinition fieldORDERID = new FieldDefinition(); + fieldORDERID.setName("EntyA_ID"); + fieldORDERID.setTypeName("NUMERIC"); + fieldORDERID.setSize(15); + fieldORDERID.setShouldAllowNull(false); + fieldORDERID.setIsPrimaryKey(false); + fieldORDERID.setUnique(false); + fieldORDERID.setIsIdentity(false); + fieldORDERID.setForeignKeyFieldName("ADV_ENTYA.ID"); + table.addField(fieldORDERID); + + FieldDefinition fieldAUDITORID = new FieldDefinition(); + fieldAUDITORID.setName("entyEs_ID"); + fieldAUDITORID.setTypeName("NUMERIC"); + fieldAUDITORID.setSize(15); + fieldAUDITORID.setShouldAllowNull(false); + fieldAUDITORID.setIsPrimaryKey(false); + fieldAUDITORID.setUnique(true); + fieldAUDITORID.setIsIdentity(false); + fieldAUDITORID.setForeignKeyFieldName("ADV_ENTYE.ID"); + table.addField(fieldAUDITORID); + + return table; + } } Index: src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyA.java =================================================================== --- src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyA.java (revision 0) +++ src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyA.java (revision 0) @@ -0,0 +1,136 @@ +package org.eclipse.persistence.testing.models.jpa.advanced.entities; + +import java.util.Collection; + +import static javax.persistence.CascadeType.*; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.OneToOne; +import javax.persistence.OneToMany; +import javax.persistence.ManyToMany; +import javax.persistence.JoinColumn; +import javax.persistence.Table; + +@Entity +@Table(name = "ADV_ENTYA") +public class EntyA{ + + @Id + @GeneratedValue + protected int id; + + protected String name; + + @OneToOne(cascade=PERSIST) + protected EntyB entyB; + + @OneToOne(optional=false) + @JoinColumn(name="ENTYC_ID", unique=true, nullable=false, updatable=false) + protected EntyC entyC; + + @OneToMany(cascade={PERSIST}) + protected Collection entyDs; + + @ManyToMany(cascade={PERSIST, MERGE}) + protected Collection entyEs; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the entyB + */ + public EntyB getEntyB() { + return entyB; + } + + /** + * @param entyB the entyB to set + */ + public void setEntyB(EntyB entyB) { + this.entyB = entyB; + } + + /** + * @return the entyC + */ + + public EntyC getEntyC() { + return entyC; + } + + /** + * @param entyC the entyC to set + */ + + public void setEntyC(EntyC entyC) { + this.entyC = entyC; + } + + /** + * @return the entyD + */ + public Collection getEntyDs() { + return entyDs; + } + + public void addEntyD(EntyD entyD) { + getEntyDs().add(entyD); + } + + public void removeEntyD(EntyD entyD) { + getEntyDs().remove(entyD); + } + + /** + * @param entyD the entyD to set + */ + public void setEntyDs(Collection entyDs) { + this.entyDs = entyDs; + } + + /** + * @return the entyE + */ + public Collection getEntyEs() { + return entyEs; + } + + public void addEntyE(EntyE entyE) { + getEntyEs().add(entyE); + } + + /** + * @param entyE the entyE to set + */ + public void setEntyEs(Collection entyEs) { + this.entyEs = entyEs; + } + +} Index: src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyB.java =================================================================== --- src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyB.java (revision 0) +++ src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyB.java (revision 0) @@ -0,0 +1,46 @@ +package org.eclipse.persistence.testing.models.jpa.advanced.entities; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "ADV_ENTYB") +public class EntyB { + + @Id + @GeneratedValue + protected int id; + + protected String name; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + +} Index: src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyC.java =================================================================== --- src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyC.java (revision 0) +++ src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyC.java (revision 0) @@ -0,0 +1,65 @@ +package org.eclipse.persistence.testing.models.jpa.advanced.entities; + +import static javax.persistence.CascadeType.*; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "ADV_ENTYC") +public class EntyC { + + @Id + @GeneratedValue + protected int id; + + protected String name; + + @OneToOne(optional=false, mappedBy="entyC") + protected EntyA entyA; + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the entyA + */ + + public EntyA getEntyA() { + return entyA; + } + + /** + * @param entyA the entyA to set + */ + + public void setEntyA(EntyA entyA) { + this.entyA = entyA; + } +} Index: src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyD.java =================================================================== --- src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyD.java (revision 0) +++ src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyD.java (revision 0) @@ -0,0 +1,47 @@ +package org.eclipse.persistence.testing.models.jpa.advanced.entities; + +import static javax.persistence.CascadeType.*; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "ADV_ENTYD") +public class EntyD { + + @Id + @GeneratedValue + protected int id; + + protected String name; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + +} Index: src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyE.java =================================================================== --- src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyE.java (revision 0) +++ src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyE.java (revision 0) @@ -0,0 +1,47 @@ +package org.eclipse.persistence.testing.models.jpa.advanced.entities; + +import static javax.persistence.CascadeType.*; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "ADV_ENTYE") +public class EntyE { + + @Id + @GeneratedValue + protected int id; + + protected String name; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + +} Index: src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyA.java =================================================================== --- src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyA.java (revision 0) +++ src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyA.java (revision 0) @@ -0,0 +1,136 @@ +package org.eclipse.persistence.testing.models.jpa.advanced.entities; + +import java.util.Collection; + +import static javax.persistence.CascadeType.*; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.OneToOne; +import javax.persistence.OneToMany; +import javax.persistence.ManyToMany; +import javax.persistence.JoinColumn; +import javax.persistence.Table; + +@Entity +@Table(name = "ADV_ENTYA") +public class EntyA{ + + @Id + @GeneratedValue + protected int id; + + protected String name; + + @OneToOne(cascade=PERSIST) + protected EntyB entyB; + + @OneToOne(optional=false) + @JoinColumn(name="ENTYC_ID", unique=true, nullable=false, updatable=false) + protected EntyC entyC; + + @OneToMany(cascade={PERSIST}) + protected Collection entyDs; + + @ManyToMany(cascade={PERSIST, MERGE}) + protected Collection entyEs; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the entyB + */ + public EntyB getEntyB() { + return entyB; + } + + /** + * @param entyB the entyB to set + */ + public void setEntyB(EntyB entyB) { + this.entyB = entyB; + } + + /** + * @return the entyC + */ + + public EntyC getEntyC() { + return entyC; + } + + /** + * @param entyC the entyC to set + */ + + public void setEntyC(EntyC entyC) { + this.entyC = entyC; + } + + /** + * @return the entyD + */ + public Collection getEntyDs() { + return entyDs; + } + + public void addEntyD(EntyD entyD) { + getEntyDs().add(entyD); + } + + public void removeEntyD(EntyD entyD) { + getEntyDs().remove(entyD); + } + + /** + * @param entyD the entyD to set + */ + public void setEntyDs(Collection entyDs) { + this.entyDs = entyDs; + } + + /** + * @return the entyE + */ + public Collection getEntyEs() { + return entyEs; + } + + public void addEntyE(EntyE entyE) { + getEntyEs().add(entyE); + } + + /** + * @param entyE the entyE to set + */ + public void setEntyEs(Collection entyEs) { + this.entyEs = entyEs; + } + +} Index: src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyB.java =================================================================== --- src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyB.java (revision 0) +++ src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyB.java (revision 0) @@ -0,0 +1,46 @@ +package org.eclipse.persistence.testing.models.jpa.advanced.entities; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "ADV_ENTYB") +public class EntyB { + + @Id + @GeneratedValue + protected int id; + + protected String name; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + +} Index: src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyC.java =================================================================== --- src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyC.java (revision 0) +++ src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyC.java (revision 0) @@ -0,0 +1,65 @@ +package org.eclipse.persistence.testing.models.jpa.advanced.entities; + +import static javax.persistence.CascadeType.*; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "ADV_ENTYC") +public class EntyC { + + @Id + @GeneratedValue + protected int id; + + protected String name; + + @OneToOne(optional=false, mappedBy="entyC") + protected EntyA entyA; + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the entyA + */ + + public EntyA getEntyA() { + return entyA; + } + + /** + * @param entyA the entyA to set + */ + + public void setEntyA(EntyA entyA) { + this.entyA = entyA; + } +} Index: src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyD.java =================================================================== --- src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyD.java (revision 0) +++ src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyD.java (revision 0) @@ -0,0 +1,47 @@ +package org.eclipse.persistence.testing.models.jpa.advanced.entities; + +import static javax.persistence.CascadeType.*; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "ADV_ENTYD") +public class EntyD { + + @Id + @GeneratedValue + protected int id; + + protected String name; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + +} Index: src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyE.java =================================================================== --- src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyE.java (revision 0) +++ src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyE.java (revision 0) @@ -0,0 +1,47 @@ +package org.eclipse.persistence.testing.models.jpa.advanced.entities; + +import static javax.persistence.CascadeType.*; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "ADV_ENTYE") +public class EntyE { + + @Id + @GeneratedValue + protected int id; + + protected String name; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + +} Index: src/org/eclipse/persistence/testing/tests/jpa/advanced/PessimisticLockingExtendedScopeTestSuite.java =================================================================== --- src/org/eclipse/persistence/testing/tests/jpa/advanced/PessimisticLockingExtendedScopeTestSuite.java (revision 0) +++ src/org/eclipse/persistence/testing/tests/jpa/advanced/PessimisticLockingExtendedScopeTestSuite.java (revision 0) @@ -0,0 +1,629 @@ +/******************************************************************************* + * Copyright (c) 1998, 2010 Oracle. 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: + * Oracle - initial API and implementation from Oracle TopLink + ******************************************************************************/ +package org.eclipse.persistence.testing.tests.jpa.advanced; + +import org.eclipse.persistence.testing.framework.junit.JUnitTestCase; +import org.eclipse.persistence.testing.models.jpa.advanced.*; +import org.eclipse.persistence.testing.models.jpa.advanced.entities.*; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import junit.framework.Test; +import junit.framework.TestSuite; + +import javax.persistence.EntityManager; +import javax.persistence.LockModeType; +import javax.persistence.PessimisticLockScope; +import javax.persistence.PersistenceException; +import javax.persistence.Query; + +import org.eclipse.persistence.descriptors.ClassDescriptor; +import org.eclipse.persistence.config.QueryHints; +import org.eclipse.persistence.sessions.server.ServerSession; + +/** + *

+ * Purpose: Test Pessimistic Locking Extended Scope functionality. + *

+ * Description: Test the relationship will be locked or unlocked under different situations + *

+ */ + public class PessimisticLockingExtendedScopeTestSuite extends JUnitTestCase { + + public PessimisticLockingExtendedScopeTestSuite() { + super(); + } + + public PessimisticLockingExtendedScopeTestSuite(String name) { + super(name); + } + + public static Test suite() { + TestSuite suite = new TestSuite("PessimisticLocking ExtendedScope TestSuite"); + suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testSetup")); + suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testPESSMISTIC_ES1")); + suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testPESSMISTIC_ES2")); + suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testPESSMISTIC_ES3")); + suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testPESSMISTIC_ES4")); + suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testPESSMISTIC_ES5")); + suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testPESSMISTIC_ES6")); + suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testPESSMISTIC_ES7")); + suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testPESSMISTIC_ES8")); + suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testPESSMISTIC_ES9")); + return suite; + } + + public void testSetup() { + ServerSession session = JUnitTestCase.getServerSession(); + new AdvancedTableCreator().replaceTables(session); + //make the entity EquipmentCode read-write for the following tests + ClassDescriptor descriptor = session.getDescriptor(EquipmentCode.class); + boolean shouldBeReadOnly = descriptor.shouldBeReadOnly(); + descriptor.setShouldBeReadOnly(false); + clearCache(); + } + + //Entity relationships for which the locked entity contains the foreign key will be locked with bidirectional one-to-one mapping without mappedBy (Scenario 1.1) + public void testPESSMISTIC_ES1() throws Exception{ + // Cannot create parallel entity managers in the server. + if (! isOnServer() && isSelectForUpateSupported()) { + EntityManager em = createEntityManager(); + EntyA a = null; + EntyC c = null; + try{ + beginTransaction(em); + a = new EntyA(); + c = new EntyC(); + em.persist(c); + a.setName("test"); + a.setEntyC(c); + em.persist(a); + commitTransaction(em); + }catch (RuntimeException ex){ + throw ex; + }finally{ + if (isTransactionActive(em)){ + rollbackTransaction(em); + } + closeEntityManager(em); + } + + Exception lockTimeOutException = null; + LockModeType lockMode = LockModeType.PESSIMISTIC_WRITE; + Map properties = new HashMap(); + properties.put(QueryHints.PESSIMISTIC_LOCK_SCOPE, PessimisticLockScope.EXTENDED); + EntityManager em1= createEntityManager(); + + try{ + beginTransaction(em1); + a = em1.find(EntyA.class, a.getId()); + em1.lock(a, lockMode, properties); + EntityManager em2 = createEntityManager(); + try{ + beginTransaction(em2); + a = em2.find(EntyA.class, a.getId()); + a.setEntyC(null); + commitTransaction(em2); + }catch(javax.persistence.RollbackException ex){ + ex.printStackTrace(); + if (ex.getMessage().indexOf("org.eclipse.persistence.exceptions.DatabaseException") == -1){ + ex.printStackTrace(); + fail("it's not the right exception"); + } + }finally{ + if (isTransactionActive(em2)){ + rollbackTransaction(em2); + } + closeEntityManager(em2); + } + }catch (Exception ex){ + throw ex; + }finally{ + if (isTransactionActive(em1)){ + rollbackTransaction(em1); + } + closeEntityManager(em1); + } + } + } + + //Entity relationships for which the locked entity contains the foreign key will be locked with unidirectional one-to-one mapping(Scenario 1.2) + public void testPESSMISTIC_ES2() throws Exception{ + // Cannot create parallel entity managers in the server. + if (! isOnServer() && isSelectForUpateSupported()) { + EntityManager em = createEntityManager(); + EntyA a = null; + EntyB b = null; + try{ + beginTransaction(em); + a = new EntyA(); + b = new EntyB(); + a.setEntyB(b); + em.persist(a); + commitTransaction(em); + }catch (RuntimeException ex){ + throw ex; + }finally{ + if (isTransactionActive(em)){ + rollbackTransaction(em); + } + closeEntityManager(em); + } + + Exception lockTimeOutException = null; + LockModeType lockMode = LockModeType.PESSIMISTIC_WRITE; + Map properties = new HashMap(); + properties.put(QueryHints.PESSIMISTIC_LOCK_SCOPE, PessimisticLockScope.EXTENDED); + EntityManager em1= createEntityManager(); + + try{ + beginTransaction(em1); + a = em1.find(EntyA.class, a.getId()); + em1.lock(a, lockMode, properties); + EntityManager em2 = createEntityManager(); + try{ + beginTransaction(em2); + a = em2.find(EntyA.class, a.getId()); + a.setEntyB(null); + commitTransaction(em2); + }catch(javax.persistence.RollbackException ex){ + if (ex.getMessage().indexOf("org.eclipse.persistence.exceptions.DatabaseException") == -1){ + ex.printStackTrace(); + fail("it's not the right exception"); + } + }finally{ + if (isTransactionActive(em2)){ + rollbackTransaction(em2); + } + closeEntityManager(em2); + } + }catch (Exception ex){ + throw ex; + }finally{ + if (isTransactionActive(em1)){ + rollbackTransaction(em1); + } + closeEntityManager(em1); + } + } + } + + //Entity relationships for which the locked entity contains the foreign key will be locked with unidirectional many-to-one mapping(Scenario 1.3) + public void testPESSMISTIC_ES3() throws Exception{ + // Cannot create parallel entity managers in the server. + if (! isOnServer() && isSelectForUpateSupported()) { + EntityManager em = createEntityManager(); + Equipment eq = null; + EquipmentCode eqCode = null; + try{ + beginTransaction(em); + eq = new Equipment(); + eqCode = new EquipmentCode(); + eqCode.setCode("A"); + em.persist(eqCode); + eq.setEquipmentCode(eqCode); + em.persist(eq); + commitTransaction(em); + }catch (RuntimeException ex){ + throw ex; + }finally{ + if (isTransactionActive(em)){ + rollbackTransaction(em); + } + closeEntityManager(em); + } + + Exception lockTimeOutException = null; + LockModeType lockMode = LockModeType.PESSIMISTIC_WRITE; + Map properties = new HashMap(); + properties.put(QueryHints.PESSIMISTIC_LOCK_SCOPE, PessimisticLockScope.EXTENDED); + EntityManager em1= createEntityManager(); + + try{ + beginTransaction(em1); + eq = em1.find(Equipment.class, eq.getId()); + em1.lock(eq, lockMode, properties); + EntityManager em2 = createEntityManager(); + try{ + beginTransaction(em2); + eq = em2.find(Equipment.class, eq.getId()); + eq.setEquipmentCode(null); + commitTransaction(em2); + }catch(javax.persistence.RollbackException ex){ + if (ex.getMessage().indexOf("org.eclipse.persistence.exceptions.DatabaseException") == -1){ + ex.printStackTrace(); + fail("it's not the right exception"); + } + }finally{ + if (isTransactionActive(em2)){ + rollbackTransaction(em2); + } + closeEntityManager(em2); + } + }catch (Exception ex){ + throw ex; + }finally{ + if (isTransactionActive(em1)){ + rollbackTransaction(em1); + } + closeEntityManager(em1); + } + } + } + + //Entity relationships for which the locked entity contains the foreign key will be locked with bidirectional many-to-one mapping(Scenario 1.4) + public void testPESSMISTIC_ES4() throws Exception{ + // Cannot create parallel entity managers in the server. + if (! isOnServer() && isSelectForUpateSupported()) { + EntityManager em = createEntityManager(); + Employee emp = null; + Address ads = null; + try{ + beginTransaction(em); + emp = new Employee(); + ads = new Address("SomeStreet", "somecity", "province", "country", "postalcode"); + emp.setAddress(ads); + em.persist(emp); + commitTransaction(em); + }catch (RuntimeException ex){ + throw ex; + }finally{ + if (isTransactionActive(em)){ + rollbackTransaction(em); + } + closeEntityManager(em); + } + + Exception lockTimeOutException = null; + LockModeType lockMode = LockModeType.PESSIMISTIC_WRITE; + Map properties = new HashMap(); + properties.put(QueryHints.PESSIMISTIC_LOCK_SCOPE, PessimisticLockScope.EXTENDED); + EntityManager em1= createEntityManager(); + + try{ + beginTransaction(em1); + emp = em1.find(Employee.class, emp.getId()); + em1.lock(emp, lockMode, properties); + EntityManager em2 = createEntityManager(); + try{ + beginTransaction(em2); + emp = em2.find(Employee.class, emp.getId()); + Address address = null; + emp.setAddress(address); + commitTransaction(em2); + }catch(javax.persistence.RollbackException ex){ + if (ex.getMessage().indexOf("org.eclipse.persistence.exceptions.DatabaseException") == -1){ + ex.printStackTrace(); + fail("it's not the right exception"); + } + }finally{ + if (isTransactionActive(em2)){ + rollbackTransaction(em2); + } + closeEntityManager(em2); + } + }catch (Exception ex){ + throw ex; + }finally{ + if (isTransactionActive(em1)){ + rollbackTransaction(em1); + } + closeEntityManager(em1); + } + } + } + + //Relationships owned by the entity that are contained in join tables will be locked with Unidirectional OneToMany mapping (Scenario 2.2) + public void testPESSMISTIC_ES5() throws Exception{ + // Cannot create parallel entity managers in the server. + if (! isOnServer() && isSelectForUpateSupported()) { + EntityManager em = createEntityManager(); + EntyA entyA = null; + EntyD entyD = null; + try{ + beginTransaction(em); + entyA = new EntyA(); + em.persist(entyA); + entyA.getEntyDs().add(new EntyD()); + commitTransaction(em); + }catch (RuntimeException ex){ + throw ex; + }finally{ + if (isTransactionActive(em)){ + rollbackTransaction(em); + } + closeEntityManager(em); + } + + Exception lockTimeOutException = null; + LockModeType lockMode = LockModeType.PESSIMISTIC_WRITE; + Map properties = new HashMap(); + properties.put(QueryHints.PESSIMISTIC_LOCK_SCOPE, PessimisticLockScope.EXTENDED); + EntityManager em1= createEntityManager(); + try{ + beginTransaction(em1); + entyA = em1.find(EntyA.class, entyA.getId()); + em1.lock(entyA, lockMode, properties); + EntityManager em2 = createEntityManager(); + try{ + beginTransaction(em2); + entyA = em2.find(EntyA.class, entyA.getId()); + entyA.setEntyDs(null); + commitTransaction(em2); + }catch(javax.persistence.RollbackException ex){ + if (ex.getMessage().indexOf("org.eclipse.persistence.exceptions.DatabaseException") == -1){ + ex.printStackTrace(); + fail("it's not the right exception"); + } + }finally{ + if (isTransactionActive(em2)){ + rollbackTransaction(em2); + } + closeEntityManager(em2); + } + }catch (Exception ex){ + throw ex; + }finally{ + if (isTransactionActive(em1)){ + rollbackTransaction(em1); + } + closeEntityManager(em1); + } + } + } + + //Relationships owned by the entity that are contained in join tables will be locked with Unidirectional ManyToMany mapping (Scenario 2.3) + public void testPESSMISTIC_ES6() throws Exception{ + // Cannot create parallel entity managers in the server. + if (! isOnServer() && isSelectForUpateSupported()) { + EntityManager em = createEntityManager(); + EntyA entyA = null; + EntyE entyE1, entyE2 = null; + try{ + beginTransaction(em); + Collection entyEs = new ArrayList(); + entyA = new EntyA(); + entyE1 = new EntyE(); + entyE2 = new EntyE(); + entyEs.add(entyE1); + entyEs.add(entyE2); + entyA.setEntyEs(entyEs); + em.persist(entyA); + commitTransaction(em); + }catch (RuntimeException ex){ + throw ex; + }finally{ + if (isTransactionActive(em)){ + rollbackTransaction(em); + } + closeEntityManager(em); + } + + Exception lockTimeOutException = null; + LockModeType lockMode = LockModeType.PESSIMISTIC_WRITE; + Map properties = new HashMap(); + properties.put(QueryHints.PESSIMISTIC_LOCK_SCOPE, PessimisticLockScope.EXTENDED); + EntityManager em1= createEntityManager(); + try{ + beginTransaction(em1); + entyA = em1.find(EntyA.class, entyA.getId()); + em1.lock(entyA, lockMode, properties); + EntityManager em2 = createEntityManager(); + try{ + beginTransaction(em2); + entyA = em2.find(EntyA.class, entyA.getId()); + entyA.setEntyEs(null); + commitTransaction(em2); + }catch(javax.persistence.RollbackException ex){ + if (ex.getMessage().indexOf("org.eclipse.persistence.exceptions.DatabaseException") == -1){ + ex.printStackTrace(); + fail("it's not the right exception"); + } + }finally{ + if (isTransactionActive(em2)){ + rollbackTransaction(em2); + } + closeEntityManager(em2); + } + }catch (Exception ex){ + throw ex; + }finally{ + if (isTransactionActive(em1)){ + rollbackTransaction(em1); + } + closeEntityManager(em1); + } + } + } + + //Bidirectional OneToOne Relationship with target entity has foreign key, entity does not contain the foreign key will not be locked (Scenario 3.1) + public void testPESSMISTIC_ES7() throws Exception{ + // Cannot create parallel entity managers in the server. + if (! isOnServer() && isSelectForUpateSupported()) { + EntityManager em = createEntityManager(); + EntyA a = null; + EntyC c = null; + try{ + beginTransaction(em); + a = new EntyA(); + c = new EntyC(); + em.persist(c); + a.setEntyC(c); + em.persist(a); + commitTransaction(em); + }catch (RuntimeException ex){ + throw ex; + }finally{ + if (isTransactionActive(em)){ + rollbackTransaction(em); + } + closeEntityManager(em); + } + + Exception lockTimeOutException = null; + LockModeType lockMode = LockModeType.PESSIMISTIC_WRITE; + Map properties = new HashMap(); + properties.put(QueryHints.PESSIMISTIC_LOCK_SCOPE, PessimisticLockScope.NORMAL); + EntityManager em1= createEntityManager(); + + try{ + beginTransaction(em1); + c = em1.find(EntyC.class, c.getId()); + em1.lock(c, lockMode, properties); + EntityManager em2 = createEntityManager(); + try{ + beginTransaction(em2); + c = em2.find(EntyC.class, c.getId()); + c.setEntyA(null); + commitTransaction(em2); + }catch(javax.persistence.RollbackException ex){ + fail("it should not throw the exception!!!"); + }finally{ + if (isTransactionActive(em2)){ + rollbackTransaction(em2); + } + closeEntityManager(em2); + } + }catch (Exception ex){ + throw ex; + }finally{ + if (isTransactionActive(em1)){ + rollbackTransaction(em1); + } + closeEntityManager(em1); + } + } + } + + //Unidirectional OneToMany Relationship, in which entity does not contain the foreign key will not be locked (Scenario 3.2) + public void testPESSMISTIC_ES8() throws Exception{ + // Cannot create parallel entity managers in the server. + if (! isOnServer() && isSelectForUpateSupported()) { + EntityManager em = createEntityManager(); + Employee emp = null; + try{ + beginTransaction(em); + emp = new Employee(); + emp.getDealers().add(new Dealer("Honda", "Kanata")); + em.persist(emp); + commitTransaction(em); + }catch (RuntimeException ex){ + throw ex; + }finally{ + if (isTransactionActive(em)){ + rollbackTransaction(em); + } + closeEntityManager(em); + } + + Exception lockTimeOutException = null; + LockModeType lockMode = LockModeType.PESSIMISTIC_WRITE; + Map properties = new HashMap(); + properties.put(QueryHints.PESSIMISTIC_LOCK_SCOPE, PessimisticLockScope.NORMAL); + EntityManager em1= createEntityManager(); + + try{ + beginTransaction(em1); + emp = em1.find(Employee.class, emp.getId()); + em1.lock(emp, lockMode, properties); + EntityManager em2 = createEntityManager(); + try{ + beginTransaction(em2); + emp = em1.find(Employee.class, emp.getId()); + emp.setDealers(null); + commitTransaction(em2); + }catch(javax.persistence.RollbackException ex){ + fail("it should not throw the exception!!!"); + }finally{ + if (isTransactionActive(em2)){ + rollbackTransaction(em2); + } + closeEntityManager(em2); + } + }catch (Exception ex){ + fail("it should not throw the exception!!!"); + throw ex; + }finally{ + if (isTransactionActive(em1)){ + rollbackTransaction(em1); + } + closeEntityManager(em1); + } + } + } + + //Bidirectional ManyToMany Relationship, in which entity does not contain the foreign key will not be locked by default (Scenario 3.3) + public void testPESSMISTIC_ES9() throws Exception{ + // Cannot create parallel entity managers in the server. + if (! isOnServer() && isSelectForUpateSupported()) { + EntityManager em = createEntityManager(); + Employee emp = null; + try{ + beginTransaction(em); + emp = new Employee(); + SmallProject smallProject = new SmallProject(); + smallProject.setName("New High School Set Up"); + emp.addProject(smallProject); + LargeProject largeProject = new LargeProject(); + largeProject.setName("Downtown Light Rail"); + largeProject.setBudget(5000); + emp.addProject(largeProject); + em.persist(emp); + commitTransaction(em); + }catch (RuntimeException ex){ + throw ex; + }finally{ + if (isTransactionActive(em)){ + rollbackTransaction(em); + } + closeEntityManager(em); + } + + Exception lockTimeOutException = null; + LockModeType lockMode = LockModeType.PESSIMISTIC_WRITE; + Map properties = new HashMap(); + properties.put(QueryHints.PESSIMISTIC_LOCK_SCOPE, PessimisticLockScope.NORMAL); + EntityManager em1= createEntityManager(); + + try{ + beginTransaction(em1); + emp = em1.find(Employee.class, emp.getId()); + em1.lock(emp, lockMode, properties); + EntityManager em2 = createEntityManager(); + try{ + beginTransaction(em2); + emp = em1.find(Employee.class, emp.getId()); + emp.setProjects(null); + commitTransaction(em2); + }catch(javax.persistence.RollbackException ex){ + fail("it should not throw the exception!!!"); + }finally{ + if (isTransactionActive(em2)){ + rollbackTransaction(em2); + } + closeEntityManager(em2); + } + }catch (Exception ex){ + fail("it should not throw the exception!!!"); + throw ex; + }finally{ + if (isTransactionActive(em1)){ + rollbackTransaction(em1); + } + closeEntityManager(em1); + } + } + } +} Index: src/org/eclipse/persistence/testing/tests/jpa/FullRegressionTestSuite.java =================================================================== --- src/org/eclipse/persistence/testing/tests/jpa/FullRegressionTestSuite.java (revision 6615) +++ src/org/eclipse/persistence/testing/tests/jpa/FullRegressionTestSuite.java (working copy) @@ -36,6 +36,7 @@ import org.eclipse.persistence.testing.tests.jpa.advanced.concurrency.LifecycleJUnitTest; import org.eclipse.persistence.testing.tests.jpa.advanced.fetchgroup.AdvancedFetchGroupJunitTest; import org.eclipse.persistence.testing.tests.jpa.advanced.ReportQueryAdvancedJUnitTest; +import org.eclipse.persistence.testing.tests.jpa.advanced.PessimisticLockingExtendedScopeTestSuite; import org.eclipse.persistence.testing.tests.jpa.inheritance.LifecycleCallbackJunitTest; import org.eclipse.persistence.testing.tests.jpa.inheritance.DeleteAllQueryInheritanceJunitTest; @@ -105,6 +106,7 @@ suite.addTest(AdvancedJunitTest.suite()); suite.addTest(AdvancedCompositePKJunitTest.suite()); suite.addTest(AdvancedFetchGroupJunitTest.suite()); + suite.addTest(PessimisticLockingExtendedScopeTestSuite.suite()); fullSuite.addTest(suite); // FieldAccess advanced model