Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recreate OpenLiberty #29459 #30180

Merged
merged 9 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;

/**
* Recreate from io.openliberty.data.internal_fat_jpa
*
* The problem here is with the entity itself
* TODO: uncomment @Entity
* TODO: remove constructor from Point
*/
//@Entity
@Entity
public class Segment {

@GeneratedValue
Expand All @@ -39,14 +36,7 @@ public class Segment {

@Embeddable
public static record Point(int x, int y) {
/**
* Recreate
* Exception Description: The instance creation method [io.openliberty.jpa.data.tests.models.Segment$Point.<Default Constructor>],
* with no parameters, does not exist, or is not accessible.
*/
public Point() {
this(0, 0);
}

}

public static Segment of(int x1, int y1, int x2, int y2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,73 @@ public void testOLGH28913() throws Exception {

assertEquals(character.getHexadecimal(), result);
}

@Test
@Ignore("Reference issue:https://github.com/OpenLiberty/open-liberty/issues/29459")
public void testOLGH29459() throws Exception {
int x1 = 0, y1 = 0, x2 = 120, y2 = 209;
Segment segment = Segment.of(x1, y1, x2, y2);
List<Exception> exceptions = new ArrayList<>();

tx.begin();

try {
em.persist(segment);
tx.commit();
} catch (Exception e) {
if (tx.getStatus() == jakarta.transaction.Status.STATUS_ACTIVE) {
// Only rollback if it's not a RollbackException
if (!(e instanceof jakarta.transaction.RollbackException)) {
tx.rollback();
}
}
exceptions.add(e);
}

tx.begin();

try {
em.createNativeQuery("INSERT INTO Segment (id, pointA_x, pointA_y, pointB_x, pointB_y) VALUES (?, ?, ?, ?, ?)")
.setParameter(1, segment.id + 1)
.setParameter(2, segment.pointA.x())
.setParameter(3, segment.pointA.y())
.setParameter(4, segment.pointB.x())
.setParameter(5, segment.pointB.y())
.executeUpdate();
tx.commit();
} catch (Exception e) {
if (tx.getStatus() == jakarta.transaction.Status.STATUS_ACTIVE) {
// Only rollback if it's not a RollbackException
if (!(e instanceof jakarta.transaction.RollbackException)) {
tx.rollback();
}
}
exceptions.add(e);
}

if (!exceptions.isEmpty()) {
throw exceptions.get(0);
}

Segment retrievedSegment1 = em.find(Segment.class, segment.id);
Segment retrievedSegment2 = em.find(Segment.class, segment.id + 1);

// Assertions for the first segment
assertEquals(segment.id, retrievedSegment1.id);
assertEquals(x1, retrievedSegment1.pointA.x());
assertEquals(y1, retrievedSegment1.pointA.y());
assertEquals(x2, retrievedSegment1.pointB.x());
assertEquals(y2, retrievedSegment1.pointB.y());

// Assertions for the second segment (inserted with incremented ID)
assertEquals(Long.valueOf(segment.id + 1), Long.valueOf(retrievedSegment2.id));
assertEquals(x1, retrievedSegment2.pointA.x());
assertEquals(y1, retrievedSegment2.pointA.y());
assertEquals(x2, retrievedSegment2.pointB.x());
assertEquals(y2, retrievedSegment2.pointB.y());
}



@Test //Reference issue: https://github.com/OpenLiberty/open-liberty/issues/28908
public void testOLGH28908() throws Exception {
Expand Down