Search in sources :

Example 1 with UpdatableDocumentEntityWithCollectionsView

use of com.blazebit.persistence.view.testsuite.update.entity.mutable.model.UpdatableDocumentEntityWithCollectionsView in project blaze-persistence by Blazebit.

the class EntityViewUpdateMutableEntityCollectionsTest method testUpdateAddToCollectionAndModifyEntity.

@Test
public void testUpdateAddToCollectionAndModifyEntity() {
    // Given & When
    final UpdatableDocumentEntityWithCollectionsView docView = addToCollectionAndModifyEntity();
    // 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 a single relation insert is done and an update to the person is done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        builder.select(Person.class);
        builder.select(Person.class);
        if (isFullMode()) {
            builder.delete(Document.class, "people").insert(Document.class, "people");
        }
    } else {
        fullFetch(builder).select(Person.class);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    builder.update(Person.class).insert(Document.class, "people").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);
        afterBuilder.select(Person.class);
        if (isFullMode()) {
            afterBuilder.delete(Document.class, "people").insert(Document.class, "people").insert(Document.class, "people");
        }
    } else {
        fullFetch(afterBuilder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        afterBuilder.update(Document.class);
    }
    afterBuilder.validate();
    assertEquals(doc1.getPeople(), docView.getPeople());
    assertEquals("newPerson", p2.getName());
}
Also used : UpdatableDocumentEntityWithCollectionsView(com.blazebit.persistence.view.testsuite.update.entity.mutable.model.UpdatableDocumentEntityWithCollectionsView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateEntityCollectionsTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityCollectionsTest)

Example 2 with UpdatableDocumentEntityWithCollectionsView

use of com.blazebit.persistence.view.testsuite.update.entity.mutable.model.UpdatableDocumentEntityWithCollectionsView in project blaze-persistence by Blazebit.

the class EntityViewUpdateMutableEntityCollectionsTest method testUpdateSetCollectionToNull.

@Test
public void testUpdateSetCollectionToNull() {
    // Given & When
    final UpdatableDocumentEntityWithCollectionsView docView = setCollectionToNull();
    // Then
    // Assert that only the document is loaded
    // Since only an existing person was update, only a single update is generated
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (version || isFullMode()) {
            builder.update(Document.class);
        }
    } else {
        if (isFullMode()) {
            fullFetch(builder);
        } else {
            builder.select(Document.class);
        }
        if (version) {
            builder.update(Document.class);
        }
    }
    builder.delete(Document.class, "people").validate();
    // Since the collection is empty we don't have to care for collection element changes
    AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
    if (isFullMode()) {
        if (isQueryStrategy()) {
            afterBuilder.delete(Document.class, "people");
        } else {
            fullFetch(afterBuilder);
        }
        if (version || isQueryStrategy()) {
            afterBuilder.update(Document.class);
        }
    }
    afterBuilder.validate();
    assertNullCollection(docView.getPeople());
    assertEquals(0, doc1.getPeople().size());
}
Also used : UpdatableDocumentEntityWithCollectionsView(com.blazebit.persistence.view.testsuite.update.entity.mutable.model.UpdatableDocumentEntityWithCollectionsView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateEntityCollectionsTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityCollectionsTest)

Example 3 with UpdatableDocumentEntityWithCollectionsView

use of com.blazebit.persistence.view.testsuite.update.entity.mutable.model.UpdatableDocumentEntityWithCollectionsView 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());
    }
}
Also used : UpdatableDocumentEntityWithCollectionsView(com.blazebit.persistence.view.testsuite.update.entity.mutable.model.UpdatableDocumentEntityWithCollectionsView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) Test(org.junit.Test) AbstractEntityViewUpdateEntityCollectionsTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityCollectionsTest)

Example 4 with UpdatableDocumentEntityWithCollectionsView

use of com.blazebit.persistence.view.testsuite.update.entity.mutable.model.UpdatableDocumentEntityWithCollectionsView in project blaze-persistence by Blazebit.

the class EntityViewUpdateMutableEntityCollectionsTest method testUpdateAddToCollection.

@Test
public void testUpdateAddToCollection() {
    // Given & When
    final UpdatableDocumentEntityWithCollectionsView docView = addToCollection();
    // 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, but only a single relation insert is done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        builder.select(Person.class);
        builder.select(Person.class);
        if (isFullMode()) {
            builder.delete(Document.class, "people").insert(Document.class, "people");
        }
    } else {
        fullFetch(builder).select(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
    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);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        afterBuilder.update(Document.class);
    }
    afterBuilder.validate();
    assertEquals(doc1.getPeople(), docView.getPeople());
}
Also used : UpdatableDocumentEntityWithCollectionsView(com.blazebit.persistence.view.testsuite.update.entity.mutable.model.UpdatableDocumentEntityWithCollectionsView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateEntityCollectionsTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityCollectionsTest)

Example 5 with UpdatableDocumentEntityWithCollectionsView

use of com.blazebit.persistence.view.testsuite.update.entity.mutable.model.UpdatableDocumentEntityWithCollectionsView in project blaze-persistence by Blazebit.

the class EntityViewUpdateMutableEntityCollectionsTest method testUpdateAddToNewCollectionAndModifyEntity.

@Test
public void testUpdateAddToNewCollectionAndModifyEntity() {
    // Given & When
    final UpdatableDocumentEntityWithCollectionsView docView = addToNewCollectionAndModifyEntity();
    // 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 a single relation insert is done and an update to the person is done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        builder.select(Person.class);
        builder.select(Person.class);
        if (isFullMode()) {
            builder.delete(Document.class, "people").insert(Document.class, "people");
        }
    } else {
        fullFetch(builder).select(Person.class);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    builder.update(Person.class).insert(Document.class, "people").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);
        afterBuilder.select(Person.class);
        if (isFullMode()) {
            afterBuilder.delete(Document.class, "people").insert(Document.class, "people").insert(Document.class, "people");
        }
    } else {
        fullFetch(afterBuilder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        afterBuilder.update(Document.class);
    }
    afterBuilder.validate();
    assertEquals(doc1.getPeople(), docView.getPeople());
    assertEquals("newPerson", p2.getName());
}
Also used : UpdatableDocumentEntityWithCollectionsView(com.blazebit.persistence.view.testsuite.update.entity.mutable.model.UpdatableDocumentEntityWithCollectionsView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateEntityCollectionsTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityCollectionsTest)

Aggregations

AssertStatementBuilder (com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder)9 Document (com.blazebit.persistence.testsuite.entity.Document)9 AbstractEntityViewUpdateEntityCollectionsTest (com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityCollectionsTest)9 UpdatableDocumentEntityWithCollectionsView (com.blazebit.persistence.view.testsuite.update.entity.mutable.model.UpdatableDocumentEntityWithCollectionsView)9 Test (org.junit.Test)9 Person (com.blazebit.persistence.testsuite.entity.Person)2