Search in sources :

Example 11 with Version

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

the class GroupConcatTest method setUpOnce.

@Override
public void setUpOnce() {
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            Person p = new Person("Pers1");
            p.setAge(20L);
            em.persist(p);
            Version v1 = new Version();
            Document doc1 = new Document("Doc1", p, v1);
            em.persist(doc1);
            em.persist(v1);
            Version v2 = new Version();
            v2.setUrl("b");
            Document doc2 = new Document("Doc1", p, v2);
            em.persist(doc2);
            em.persist(v2);
            Version v3 = new Version();
            v3.setUrl("a");
            Document doc3 = new Document("Doc2", p, v3);
            em.persist(doc3);
            em.persist(v3);
        }
    });
}
Also used : EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) Version(com.blazebit.persistence.testsuite.entity.Version) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person)

Example 12 with Version

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

the class EntityViewRemoveNestedSubviewCollectionsTest method testSimpleRemove.

@Test
public void testSimpleRemove() {
    // Given
    final UpdatableDocumentWithCollectionsView 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.people.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);
}
Also used : UpdatableDocumentWithCollectionsView(com.blazebit.persistence.view.testsuite.update.remove.cascade.nested.model.UpdatableDocumentWithCollectionsView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Version(com.blazebit.persistence.testsuite.entity.Version) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) Test(org.junit.Test) AbstractEntityViewRemoveDocumentTest(com.blazebit.persistence.view.testsuite.update.remove.cascade.AbstractEntityViewRemoveDocumentTest)

Example 13 with Version

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

the class EntityViewRemoveNestedSubviewMapsTest method testRemoveById.

@Test
public void testRemoveById() {
    // Given
    clearQueries();
    // When
    remove(UpdatableDocumentWithMapsView.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.contacts.id
        builder.select(Document.class);
    }
    deleteDocumentOwned(builder, true);
    deletePersonOwned(builder, false);
    deletePersonOwned(builder, true);
    // document.contacts
    if (isQueryStrategy()) {
        // Contacts 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, "contacts").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, "contacts").fetching(Person.class).and();
        }
    } else {
        builder.assertSelect().fetching(Document.class, "contacts").fetching(Person.class).and();
    }
    // If possible, the deletion of document.contacts returns document.contacts.friend
    if (!isQueryStrategy() || !dbmsDialect.supportsReturningColumns()) {
        builder.select(Person.class);
    }
    if (isQueryStrategy()) {
        // Need to select the version id to be able to delete the localized set
        builder.select(Version.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);
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Version(com.blazebit.persistence.testsuite.entity.Version) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) Test(org.junit.Test) AbstractEntityViewRemoveDocumentTest(com.blazebit.persistence.view.testsuite.update.remove.cascade.AbstractEntityViewRemoveDocumentTest)

Example 14 with Version

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

the class EntityViewRemoveNestedSubviewTest method testRemoveById.

@Test
public void testRemoveById() {
    // Given
    clearQueries();
    // When
    remove(UpdatableDocumentView.class, doc1.getId());
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (!isQueryStrategy()) {
        // Hibernate loads the entities before deleting?
        builder.select(Version.class).select(Person.class);
    }
    deleteDocumentOwned(builder, false);
    deletePersonOwned(builder, false);
    deletePersonOwned(builder, true);
    // In the query strategy, we use a returning clause to avoid a select statement
    if (!isQueryStrategy() || !dbmsDialect.supportsReturningColumns()) {
        // document.responsiblePerson.id
        builder.select(Document.class);
        // responsiblePerson.friend
        builder.select(Person.class);
    }
    if (isQueryStrategy()) {
        // Need to select the version id to be able to delete the localized set
        builder.select(Version.class);
    }
    // document.responsiblePerson
    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);
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Version(com.blazebit.persistence.testsuite.entity.Version) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) Test(org.junit.Test) AbstractEntityViewRemoveDocumentTest(com.blazebit.persistence.view.testsuite.update.remove.cascade.AbstractEntityViewRemoveDocumentTest)

Example 15 with Version

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

the class AbstractEntityViewRemoveDocumentTest 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")));
    doc2 = new Document("doc2");
    doc2.setVersion(1L);
    doc2.setLastModified(new Date(EPOCH_2K));
    doc2.setNameObject(new NameObject("doc2", "doc2"));
    doc2.getNames().add(new NameObject("doc2", "doc2"));
    doc2.getNameMap().put("doc1", new NameObject("doc2", "doc2"));
    doc2.getNameContainers().add(new NameObjectContainer("doc2", new NameObject("doc2", "doc2")));
    doc2.getNameContainerMap().put("doc2", new NameObjectContainer("doc2", new NameObject("doc2", "doc2")));
    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("pers3");
    p5.getNameObject().setPrimaryName("pers3");
    p5.getLocalized().put(1, "localized3");
    p6 = new Person("pers4");
    p6.getNameObject().setPrimaryName("pers4");
    p6.getLocalized().put(1, "localized4");
    doc1.setOwner(p5);
    doc1.setResponsiblePerson(p1);
    doc1.getPeople().add(p1);
    doc1.getContacts().put(1, p1);
    doc1.getContacts2().put(2, p1);
    doc1.getStrings().add("asd");
    doc1.getStringMap().put("doc1", "doc1");
    doc1.getVersions().iterator().next().getLocalized().put(1, "1");
    doc2.setOwner(p6);
    doc2.setResponsiblePerson(p2);
    em.persist(p1);
    em.persist(p2);
    em.persist(p3);
    em.persist(p4);
    em.persist(p5);
    em.persist(p6);
    em.persist(doc1);
    em.persist(doc2);
    p1.setFriend(p3);
    p2.setFriend(p4);
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject) Version(com.blazebit.persistence.testsuite.entity.Version) NameObjectContainer(com.blazebit.persistence.testsuite.entity.NameObjectContainer) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) Date(java.util.Date)

Aggregations

Version (com.blazebit.persistence.testsuite.entity.Version)25 Document (com.blazebit.persistence.testsuite.entity.Document)24 Person (com.blazebit.persistence.testsuite.entity.Person)22 TxVoidWork (com.blazebit.persistence.testsuite.tx.TxVoidWork)14 EntityManager (javax.persistence.EntityManager)14 Test (org.junit.Test)9 AssertStatementBuilder (com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder)6 AbstractEntityViewRemoveDocumentTest (com.blazebit.persistence.view.testsuite.update.remove.cascade.AbstractEntityViewRemoveDocumentTest)6 Tuple (javax.persistence.Tuple)3 NameObject (com.blazebit.persistence.testsuite.entity.NameObject)2 NameObjectContainer (com.blazebit.persistence.testsuite.entity.NameObjectContainer)2 Date (java.util.Date)2 CriteriaBuilder (com.blazebit.persistence.CriteriaBuilder)1 AbstractCoreTest (com.blazebit.persistence.testsuite.AbstractCoreTest)1 EntityViewConfiguration (com.blazebit.persistence.view.spi.EntityViewConfiguration)1 UpdatableDocumentView (com.blazebit.persistence.view.testsuite.update.remove.cascade.nested.model.UpdatableDocumentView)1 UpdatableDocumentWithCollectionsView (com.blazebit.persistence.view.testsuite.update.remove.cascade.nested.model.UpdatableDocumentWithCollectionsView)1 UpdatableDocumentWithMapsView (com.blazebit.persistence.view.testsuite.update.remove.cascade.nested.model.UpdatableDocumentWithMapsView)1 ArrayList (java.util.ArrayList)1 Category (org.junit.experimental.categories.Category)1