-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 1950: Duplicate objects in UnitOfWorkImpl.primaryKeyToNewObjects (
#1956) - use IdentityHashSet instead of ArrayList for primaryKeyToNewObjects to prevent duplicates in the future - added unit tests Signed-off-by: Patrick Schmitt <[email protected]>
- Loading branch information
Showing
4 changed files
with
104 additions
and
8 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
...e/persistence/testing/tests/unitofwork/UOWPrimaryKeyToNewObjectsDuplicateObjectsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2023 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 v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
package org.eclipse.persistence.testing.tests.unitofwork; | ||
|
||
import org.eclipse.persistence.internal.sessions.UnitOfWorkImpl; | ||
import org.eclipse.persistence.sessions.Session; | ||
import org.eclipse.persistence.testing.framework.TestCase; | ||
import org.eclipse.persistence.testing.models.employee.domain.Employee; | ||
|
||
import java.util.IdentityHashMap; | ||
|
||
/** | ||
* This test is in response to issue 1950: Duplicate objects in UnitOfWorkImpl.primaryKeyToNewObjects | ||
* | ||
* When a new object is registered for persist by calling registerNewObjectForPersist | ||
* the object is potentially added twice to primaryKeyToNewObjects. Once during assignSequenceNumber and | ||
* then in registerNewObjectClone. This test verifies that the object is contained only once in primaryKeyToNewObjects. | ||
*/ | ||
public class UOWPrimaryKeyToNewObjectsDuplicateObjectsTest extends TestCase { | ||
public UOWPrimaryKeyToNewObjectsDuplicateObjectsTest() { | ||
setDescription("This test verifies that no duplicates exist in primaryKeyToNewObjects after registering a new object"); | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
getAbstractSession().rollbackTransaction(); | ||
getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); | ||
} | ||
|
||
@Override | ||
public void setup() { | ||
getAbstractSession().beginTransaction(); | ||
} | ||
|
||
@Override | ||
public void test() { | ||
Session session = getSession(); | ||
UnitOfWorkImpl uow = (UnitOfWorkImpl) session.acquireUnitOfWork(); | ||
Employee emp = new Employee(); | ||
emp.setFirstName("UOWPrimaryKeyToNewObjectsDuplicateObjectsTest"); | ||
uow.registerNewObjectForPersist(emp, new IdentityHashMap<>()); | ||
// there should be only one object in primaryKeyToNewObjects | ||
assertEquals("Unexpected amount of entities in primaryKeyToNewObjects", 1, | ||
uow.getPrimaryKeyToNewObjects().get(emp.getId()).size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters