Search in sources :

Example 1 with BookEntity

use of com.blazebit.persistence.testsuite.entity.BookEntity in project blaze-persistence by Blazebit.

the class NonPrimaryKeyJoinColumnTest method testNonPrimaryKeySingleValuedAssociationIdInUpdate.

// NOTE: No JPA provider supports the optimized natural id access and only EclipseLink and Hibernate seem to support natural ids
@Test
@Category({ NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoHibernate51.class, NoHibernate52.class, NoHibernate53.class, NoEclipselink.class, NoDatanucleus.class, NoOpenJPA.class })
public void testNonPrimaryKeySingleValuedAssociationIdInUpdate() {
    Person owner = new Person("p1");
    BookEntity bookEntity = new BookEntity();
    bookEntity.setOwner(owner);
    bookEntity.setIsbn("123");
    em.persist(owner);
    em.persist(bookEntity);
    UpdateCriteriaBuilder<BookISBNReferenceEntity> cb1 = cbf.update(em, BookISBNReferenceEntity.class, "r").setExpression("version", "r.version + 1").where("r.book.isbn").eq(bookEntity.getIsbn());
    UpdateCriteriaBuilder<BookISBNReferenceEntity> cb2 = cbf.update(em, BookISBNReferenceEntity.class, "r").setExpression("version", "r.version + 1").where("r.book").eq(bookEntity);
    assumeTrue(jpaProvider.supportsSingleValuedAssociationIdExpressions());
    assumeTrue(jpaProvider.supportsSingleValuedAssociationNaturalIdExpressions());
    assertEquals("UPDATE BookISBNReferenceEntity r SET r.version = r.version + 1 WHERE r.book.isbn = :param_0", cb1.getQueryString());
    assertEquals("UPDATE BookISBNReferenceEntity r SET r.version = r.version + 1 WHERE r.book = :param_0", cb2.getQueryString());
    cb1.executeUpdate();
    cb2.executeUpdate();
}
Also used : BookEntity(com.blazebit.persistence.testsuite.entity.BookEntity) BookISBNReferenceEntity(com.blazebit.persistence.testsuite.entity.BookISBNReferenceEntity) Person(com.blazebit.persistence.testsuite.entity.Person) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 2 with BookEntity

use of com.blazebit.persistence.testsuite.entity.BookEntity in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleImmutableSubviewIdViewCollectionsTest method assertSubviewEquals.

public static void assertSubviewEquals(Collection<BookEntity> persons, Collection<BookIdView> personSubviews) {
    if (persons == null) {
        assertNull(personSubviews);
        return;
    }
    assertNotNull(personSubviews);
    assertEquals(persons.size(), personSubviews.size());
    for (BookEntity p : persons) {
        boolean found = false;
        for (BookIdView pSub : personSubviews) {
            if (p.getId().equals(pSub.getId())) {
                found = true;
                break;
            }
        }
        if (!found) {
            Assert.fail("Could not find a book subview instance with the isbn: " + p.getIsbn());
        }
    }
}
Also used : BookEntity(com.blazebit.persistence.testsuite.entity.BookEntity) BookIdView(com.blazebit.persistence.view.testsuite.update.natural.model.BookIdView)

Example 3 with BookEntity

use of com.blazebit.persistence.testsuite.entity.BookEntity in project blaze-persistence by Blazebit.

the class AbstractBookEntityViewTest method prepareData.

@Override
protected void prepareData(EntityManager em) {
    Person p1 = new Person("pers1");
    BookEntity b1 = new BookEntity();
    b1.setOwner(p1);
    b1.setIsbn("123");
    BookEntity b2 = new BookEntity();
    b2.setOwner(p1);
    b2.setIsbn("456");
    BookEntity b3 = new BookEntity();
    b3.setOwner(p1);
    b3.setIsbn("789");
    e1 = new NaturalIdJoinTableEntity();
    e1.setVersion(1L);
    e1.setOwner(p1);
    e1.setIsbn("123");
    e1.getManyToManyBook().put("b1", b1);
    e1.getManyToManyBook().put("b2", b2);
    e1.getOneToManyBook().add(b1);
    e1.getOneToManyBook().add(b2);
    e2 = new BookISBNReferenceEntity();
    e2.setVersion(1L);
    e2.setBook(b1);
    e2.setBookNormal(b2);
    em.persist(p1);
    em.persist(b1);
    em.persist(b2);
    em.persist(b3);
    em.persist(e1);
    em.persist(e2);
}
Also used : BookEntity(com.blazebit.persistence.testsuite.entity.BookEntity) BookISBNReferenceEntity(com.blazebit.persistence.testsuite.entity.BookISBNReferenceEntity) Person(com.blazebit.persistence.testsuite.entity.Person) NaturalIdJoinTableEntity(com.blazebit.persistence.testsuite.entity.NaturalIdJoinTableEntity)

Example 4 with BookEntity

use of com.blazebit.persistence.testsuite.entity.BookEntity in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleImmutableSubviewCollectionsTest method assertSubviewEquals.

public static void assertSubviewEquals(Collection<BookEntity> persons, Collection<BookIsbnView> personSubviews) {
    if (persons == null) {
        assertNull(personSubviews);
        return;
    }
    assertNotNull(personSubviews);
    assertEquals(persons.size(), personSubviews.size());
    for (BookEntity p : persons) {
        boolean found = false;
        for (BookIsbnView pSub : personSubviews) {
            if (p.getIsbn().equals(pSub.getId())) {
                found = true;
                break;
            }
        }
        if (!found) {
            Assert.fail("Could not find a book subview instance with the isbn: " + p.getIsbn());
        }
    }
}
Also used : BookEntity(com.blazebit.persistence.testsuite.entity.BookEntity) BookIsbnView(com.blazebit.persistence.view.testsuite.update.natural.model.BookIsbnView)

Example 5 with BookEntity

use of com.blazebit.persistence.testsuite.entity.BookEntity in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleImmutableSubviewMapsTest method assertSubviewEquals.

public static void assertSubviewEquals(Map<String, BookEntity> persons, Map<String, BookIsbnView> personSubviews) {
    if (persons == null) {
        assertNull(personSubviews);
        return;
    }
    assertNotNull(personSubviews);
    assertEquals(persons.size(), personSubviews.size());
    for (Map.Entry<String, BookEntity> entry : persons.entrySet()) {
        BookEntity p = entry.getValue();
        boolean found = false;
        BookIsbnView pSub = personSubviews.get(entry.getKey());
        if (pSub != null) {
            if (p.getIsbn().equals(pSub.getId())) {
                found = true;
                break;
            }
        }
        if (!found) {
            Assert.fail("Could not find a person subview instance with the name: " + p.getIsbn());
        }
    }
}
Also used : BookEntity(com.blazebit.persistence.testsuite.entity.BookEntity) BookIsbnView(com.blazebit.persistence.view.testsuite.update.natural.model.BookIsbnView) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

BookEntity (com.blazebit.persistence.testsuite.entity.BookEntity)5 BookISBNReferenceEntity (com.blazebit.persistence.testsuite.entity.BookISBNReferenceEntity)2 Person (com.blazebit.persistence.testsuite.entity.Person)2 BookIsbnView (com.blazebit.persistence.view.testsuite.update.natural.model.BookIsbnView)2 NaturalIdJoinTableEntity (com.blazebit.persistence.testsuite.entity.NaturalIdJoinTableEntity)1 BookIdView (com.blazebit.persistence.view.testsuite.update.natural.model.BookIdView)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1 Category (org.junit.experimental.categories.Category)1