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();
}
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());
}
}
}
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);
}
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());
}
}
}
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());
}
}
}
Aggregations