use of com.blazebit.persistence.testsuite.entity.Version in project blaze-persistence by Blazebit.
the class AbstractEntityViewOrphanRemoveDocumentTest method prepareData.
@Override
protected void prepareData(EntityManager em) {
doc1 = new Document("doc1", null, new Version());
doc1.setVersion(1L);
doc1.setLastModified(new Date(EPOCH_2K));
doc1.getNameObject().setPrimaryName("doc1");
doc1.getNames().add(new NameObject("doc1", "doc1"));
doc1.getNameMap().put("doc1", new NameObject("doc1", "doc1"));
doc1.getNameContainers().add(new NameObjectContainer("doc1", new NameObject("doc1", "doc1")));
doc1.getNameContainerMap().put("doc1", new NameObjectContainer("doc1", new NameObject("doc1", "doc1")));
p1 = new Person("pers1");
p1.getNameObject().setPrimaryName("pers1");
p1.getLocalized().put(1, "localized1");
p2 = new Person("pers2");
p2.getNameObject().setPrimaryName("pers2");
p2.getLocalized().put(1, "localized2");
p3 = new Person("pers3");
p3.getNameObject().setPrimaryName("pers3");
p3.getLocalized().put(1, "localized3");
p4 = new Person("pers4");
p4.getNameObject().setPrimaryName("pers4");
p4.getLocalized().put(1, "localized4");
p5 = new Person("pers5");
p5.getNameObject().setPrimaryName("pers5");
p5.getLocalized().put(1, "localized5");
p6 = new Person("pers6");
p6.getNameObject().setPrimaryName("pers6");
p6.getLocalized().put(1, "localized6");
p7 = new Person("pers7");
p7.getNameObject().setPrimaryName("pers7");
p7.getLocalized().put(1, "localized7");
p8 = new Person("pers8");
p8.getNameObject().setPrimaryName("pers8");
p8.getLocalized().put(1, "localized8");
p9 = new Person("pers9");
p9.getNameObject().setPrimaryName("pers9");
p9.getLocalized().put(1, "localized9");
doc1.setOwner(p1);
doc1.setResponsiblePerson(p2);
doc1.getPeople().add(p3);
doc1.getPeople().add(p4);
doc1.getContacts().put(1, p5);
doc1.getContacts().put(2, p6);
doc1.getStrings().add("asd");
doc1.getStringMap().put("doc1", "doc1");
em.persist(p1);
em.persist(p2);
em.persist(p3);
em.persist(p4);
em.persist(p5);
em.persist(p6);
em.persist(p7);
em.persist(p8);
em.persist(p9);
em.persist(doc1);
p2.setFriend(p7);
p4.setFriend(p8);
p6.setFriend(p9);
}
use of com.blazebit.persistence.testsuite.entity.Version in project blaze-persistence by Blazebit.
the class EntityViewRemoveNestedSubviewCollectionsTest method testRemoveById.
@Test
public void testRemoveById() {
// Given
clearQueries();
// When
remove(UpdatableDocumentWithCollectionsView.class, doc1.getId());
// Then
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (!isQueryStrategy()) {
// Hibernate loads the entities before deleting?
builder.select(Version.class);
// Hibernate flushes the changes done to the document because Person#1 was deleted => responsiblePerson set to NULL
builder.update(Document.class);
// Select for deletion because of possible cycle
// document.people.id
builder.select(Document.class);
}
if (isQueryStrategy()) {
// Need to select the version id to be able to delete the localized set
builder.select(Version.class);
}
deleteDocumentOwned(builder, true);
deletePersonOwned(builder, false);
deletePersonOwned(builder, true);
// document.people
if (isQueryStrategy()) {
// People ids are returned instead of queried if possible
if (dbmsDialect.supportsReturningColumns()) {
// But unfortunately current Hibernate versions also try to do the delete implicitly
builder.assertDelete().forRelation(Document.class, "people").and();
} else {
// The JPQL that joins people unfortunately joins all tables, though the collection table alone would suffice
builder.assertSelect().forEntity(Document.class).forRelation(Document.class, "people").fetching(Person.class).and();
}
} else {
builder.assertSelect().fetching(Document.class, "people").fetching(Person.class).and();
}
// If possible, the deletion of document.people returns document.people.friend
if (!isQueryStrategy() || !dbmsDialect.supportsReturningColumns()) {
builder.select(Person.class);
}
builder.delete(Person.class).update(Document.class).delete(Person.class).update(Document.class).delete(Version.class).delete(Version.class, "localized").delete(Document.class).validate();
clearPersistenceContextAndReload();
assertNull(doc1);
assertNull(p1);
assertNull(p3);
}
use of com.blazebit.persistence.testsuite.entity.Version in project blaze-persistence by Blazebit.
the class EntityViewRemoveNestedSubviewMapsTest method testSimpleRemove.
@Test
public void testSimpleRemove() {
// Given
final UpdatableDocumentWithMapsView docView = getDoc1View();
clearQueries();
// When
remove(docView);
// Then
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (!isQueryStrategy()) {
// Hibernate loads the entities before deleting?
builder.select(Person.class).select(Person.class).select(Document.class).select(Version.class);
}
if (isQueryStrategy()) {
// Need to select the version id to be able to delete the localized set
builder.select(Version.class);
}
deleteDocumentOwned(builder);
deletePersonOwned(builder);
deletePersonOwned(builder);
// document.contacts.friend
builder.delete(Person.class).update(Document.class).delete(Person.class).update(Document.class).delete(Version.class).delete(Version.class, "localized").delete(Document.class).validate();
clearPersistenceContextAndReload();
assertNull(doc1);
assertNull(p1);
assertNull(p3);
}
use of com.blazebit.persistence.testsuite.entity.Version in project blaze-persistence by Blazebit.
the class EntityViewRemoveNestedSubviewTest method testSimpleRemove.
@Test
public void testSimpleRemove() {
// Given
final UpdatableDocumentView docView = getDoc1View();
clearQueries();
// When
remove(docView);
// Then
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (!isQueryStrategy()) {
// Hibernate loads the entities before deleting?
builder.select(Person.class).select(Person.class).select(Document.class).select(Version.class);
}
if (isQueryStrategy()) {
// Need to select the version id to be able to delete the localized set
builder.select(Version.class);
}
deleteDocumentOwned(builder);
deletePersonOwned(builder, true);
deletePersonOwned(builder, true);
// document.responsiblePerson.friend
builder.delete(Person.class).update(Document.class).delete(Person.class).update(Document.class).delete(Version.class).delete(Version.class, "localized").delete(Document.class).validate();
clearPersistenceContextAndReload();
assertNull(doc1);
assertNull(p1);
assertNull(p3);
}
use of com.blazebit.persistence.testsuite.entity.Version in project blaze-persistence by Blazebit.
the class InheritanceTest method setUpOnce.
@Override
public void setUpOnce() {
cleanDatabase();
transactional(new TxVoidWork() {
@Override
public void work(EntityManager em) {
doc1 = new Document("doc1", new Person("owner1"), new Version(), new Version());
doc2 = new Document("doc2", new Person("owner2"));
doc3 = new Document("doc3", new Person("owner3"));
doc4 = new Document("doc4", new Person("owner4"), new Version(), new Version());
doc5 = new Document("doc5", new Person("owner5"));
doc6 = new Document("doc6", new Person("owner6"));
// New
doc1.setAge(1);
doc2.setAge(1);
doc3.setAge(1);
// Base
doc4.setAge(15);
// Old
doc5.setAge(16);
doc6.setAge(16);
// NewSub1
doc1.setDefaultContact(null);
doc2.setDefaultContact(null);
// NewSub2
doc3.setDefaultContact(1);
// Base
doc4.setDefaultContact(1);
doc4.setLastModified(Timestamp.valueOf("2000-01-01 00:00:00"));
// UsedOld
doc5.setLastModified(Timestamp.valueOf("2000-01-01 00:00:00"));
// Old
doc6.setLastModified(null);
Person o1 = new Person("pers1");
Person o2 = new Person("pers2");
Person o3 = new Person("pers3");
Person o4 = new Person("pers4");
Person o5 = new Person("pers5");
Person o6 = new Person("pers6");
doc2.getContacts().put(1, o1);
doc2.getContacts().put(1, o2);
doc5.getContacts().put(1, o3);
doc5.getContacts().put(1, o4);
doc6.getContacts().put(1, o5);
doc6.getContacts().put(1, o6);
em.persist(o1);
em.persist(o2);
em.persist(o3);
em.persist(o4);
em.persist(o5);
em.persist(o6);
o1.setPartnerDocument(doc3);
o2.setPartnerDocument(doc3);
o3.setPartnerDocument(doc4);
o4.setPartnerDocument(doc4);
o5.setPartnerDocument(doc5);
o6.setPartnerDocument(doc5);
doc1.getPeople().add(o1);
doc2.getPeople().add(o2);
doc3.getPeople().add(o3);
doc4.getPeople().add(o4);
doc5.getPeople().add(o5);
doc6.getPeople().add(o6);
em.persist(doc1);
em.persist(doc2);
em.persist(doc3);
em.persist(doc4);
em.persist(doc5);
em.persist(doc6);
}
});
}
Aggregations