use of com.blazebit.persistence.testsuite.entity.Person in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableEntityCollectionsTest method testUpdateAddNewEntityToCollection.
@Test
public void testUpdateAddNewEntityToCollection() {
// Given & When
final UpdatableDocumentEntityWithCollectionsView docView = addNewEntityToCollection();
// Then
// Assert that the document and the people are loaded i.e. a full fetch
// In addition, the new person is loaded because of the merge invocation
// Finally the person is persisted and a single relation insert is done
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
builder.select(Person.class);
if (isFullMode()) {
builder.delete(Document.class, "people").insert(Document.class, "people");
}
} else {
fullFetch(builder);
}
builder.insert(Person.class);
if (version || isQueryStrategy() && isFullMode()) {
builder.update(Document.class);
}
builder.insert(Document.class, "people").validate();
// Unfortunately, even after an update, we have to reload the entity to merge again
// This time we even have to re-load owned associations because they aren't lazy and could be dirty
AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
if (isQueryStrategy()) {
afterBuilder.select(Person.class);
afterBuilder.select(Person.class);
if (isFullMode()) {
afterBuilder.delete(Document.class, "people").insert(Document.class, "people").insert(Document.class, "people");
}
} else {
fullFetch(afterBuilder);
}
afterBuilder.assertSelect().fetching(Person.class, "favoriteDocuments").fetching(Document.class).and().assertSelect().fetching(Person.class, "localized").and().select(Document.class);
if (version || isQueryStrategy() && isFullMode()) {
afterBuilder.update(Document.class);
}
if (doesJpaMergeOfRecentlyPersistedEntityForceUpdate()) {
afterBuilder.update(Person.class);
}
afterBuilder.validate();
assertEquals(doc1.getPeople(), docView.getPeople());
Iterator<Person> iter = doc1.getPeople().iterator();
Person nextPerson = iter.next();
if (nextPerson.getId().equals(p1.getId())) {
assertEquals("pers1", nextPerson.getName());
assertEquals("newPerson", iter.next().getName());
} else {
assertEquals("newPerson", nextPerson.getName());
assertEquals("pers1", iter.next().getName());
}
}
use of com.blazebit.persistence.testsuite.entity.Person in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableEntityMapsTest method testUpdateModifyEntityInCollection.
@Test
public void testUpdateModifyEntityInCollection() {
// Given & When
final UpdatableDocumentEntityWithMapsView docView = modifyEntityInCollection();
// Then
// Assert that the document and the people are loaded i.e. a full fetch
// Since only an existing person was update, only a single update is generated
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
builder.select(Person.class);
if (isFullMode()) {
builder.delete(Document.class, "contacts").insert(Document.class, "contacts");
}
} else {
fullFetch(builder);
}
if (version || isQueryStrategy() && isFullMode()) {
builder.update(Document.class);
}
builder.update(Person.class).validate();
// Unfortunately, even after an update, we have to reload the entity to merge again
AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
if (isQueryStrategy()) {
afterBuilder.select(Person.class);
if (isFullMode()) {
afterBuilder.delete(Document.class, "contacts").insert(Document.class, "contacts");
}
} else {
fullFetch(afterBuilder);
}
if (version || isQueryStrategy() && isFullMode()) {
afterBuilder.update(Document.class);
}
afterBuilder.validate();
assertEquals(doc1.getContacts(), docView.getContacts());
assertEquals("newPerson", p1.getName());
}
use of com.blazebit.persistence.testsuite.entity.Person in project blaze-persistence by Blazebit.
the class SingletonCollectionsTest method setUpOnce.
@Override
public void setUpOnce() {
cleanDatabase();
transactional(new TxVoidWork() {
@Override
public void work(EntityManager em) {
doc1 = new Document("doc1");
doc2 = new Document("doc2");
doc3 = new Document("doc3");
doc4 = new Document("doc4");
Person o1 = new Person("pers1");
Person o2 = new Person("pers2");
Person o3 = new Person("pers3");
doc1.setOwner(o1);
doc2.setOwner(o2);
doc3.setOwner(o2);
doc4.setOwner(o2);
em.persist(o1);
em.persist(o2);
em.persist(o3);
em.persist(doc1);
em.persist(doc2);
em.persist(doc3);
em.persist(doc4);
}
});
}
use of com.blazebit.persistence.testsuite.entity.Person in project blaze-persistence by Blazebit.
the class MappingIndexTest method setUpOnce.
@Override
public void setUpOnce() {
cleanDatabase();
transactional(new TxVoidWork() {
@Override
public void work(EntityManager em) {
Person p = new Person("p");
doc1 = new Document("doc1", p, new Version(2), new Version(1));
doc2 = new Document("doc2", p);
em.persist(doc1);
em.persist(doc2);
}
});
}
use of com.blazebit.persistence.testsuite.entity.Person in project blaze-persistence by Blazebit.
the class ProxyFactoryTest method testClassProxy.
@Test
public void testClassProxy() throws Exception {
ViewType<DocumentClassView> viewType = getViewMetamodel().view(DocumentClassView.class);
Class<? extends DocumentClassView> proxyClass = proxyFactory.getProxy(evm, (ManagedViewTypeImplementor<DocumentClassView>) viewType);
// The parameter order is _id, contacts, firstContactPerson, id, name
Constructor<? extends DocumentClassView> constructor = proxyClass.getConstructor(Long.class, Map.class, Person.class, Person.class, String.class, Long.class, Integer.class);
Map<Integer, Person> expectedContacts = new HashMap<Integer, Person>();
Person expectedFirstContactPerson = new Person("pers");
Long expectedId = 1L;
String expectedName = "doc";
long expectedAge = 10;
Person expectedMyContactPerson = new Person("my-pers");
Integer expectedContactPersonNumber = 2;
DocumentClassView instance = constructor.newInstance(expectedId, expectedContacts, expectedFirstContactPerson, expectedMyContactPerson, expectedName, expectedAge, expectedContactPersonNumber);
assertTrue(expectedContacts == instance.getContacts());
assertTrue(expectedFirstContactPerson == instance.getFirstContactPerson());
assertTrue(expectedId == instance.getId());
assertTrue(expectedMyContactPerson == instance.getMyContactPerson());
assertTrue(expectedName == instance.getName());
assertTrue(expectedAge == instance.getAge());
assertTrue(expectedContactPersonNumber == instance.getContactPersonNumber());
expectedContacts = new HashMap<Integer, Person>();
expectedId = 2L;
instance.setContacts(expectedContacts);
instance.setId(expectedId);
assertTrue(expectedContacts == instance.getContacts());
assertTrue(expectedId == instance.getId());
}
Aggregations