Skip to content

Commit

Permalink
Merge pull request #30180 from anija-anil/eclJakrtaDataIssues
Browse files Browse the repository at this point in the history
Recreate OpenLiberty #29459
  • Loading branch information
anija-anil authored Dec 10, 2024
2 parents 699f03d + d39fd51 commit db26ddc
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 13 deletions.
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

0 comments on commit db26ddc

Please sign in to comment.