Search in sources :

Example 1 with Version

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

the class InheritanceTest method assertVersionsEquals.

public static void assertVersionsEquals(Set<Version> versions, Set<Long> versionIds) {
    if (versions == null) {
        assertNull(versionIds);
        return;
    }
    assertNotNull(versionIds);
    assertEquals(versions.size(), versionIds.size());
    for (Version v : versions) {
        if (!versionIds.contains(v.getId())) {
            Assert.fail("Could not find a version id: " + v.getId());
        }
    }
}
Also used : Version(com.blazebit.persistence.testsuite.entity.Version)

Example 2 with Version

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

the class MappingIndexTest method test.

private <T extends DocumentViewWithMappingIndex> void test(Class<T> clazz, Integer batchSize) {
    EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration();
    cfg.setProperty(ConfigurationProperties.PROXY_EAGER_LOADING, "true");
    cfg.setProperty(ConfigurationProperties.UPDATER_EAGER_LOADING, "true");
    build(cfg, clazz, VersionViewWithMappingIndex.class, VersionKeyView.class, VersionStaticKeyView.class);
    CriteriaBuilder<Document> criteria = cbf.create(em, Document.class, "d").orderByAsc("id");
    EntityViewSetting<T, CriteriaBuilder<T>> setting = EntityViewSetting.create(clazz);
    if (batchSize != null) {
        setting.setProperty(ConfigurationProperties.DEFAULT_BATCH_SIZE + ".versions", batchSize);
        setting.setProperty(ConfigurationProperties.DEFAULT_BATCH_SIZE + ".versionMap", batchSize);
        setting.setProperty(ConfigurationProperties.DEFAULT_BATCH_SIZE + ".versionMap2", batchSize);
        setting.setProperty(ConfigurationProperties.DEFAULT_BATCH_SIZE + ".multiVersions", batchSize);
        setting.setProperty(ConfigurationProperties.DEFAULT_BATCH_SIZE + ".multiVersionMap", batchSize);
        setting.setProperty(ConfigurationProperties.DEFAULT_BATCH_SIZE + ".multiVersionMap2", batchSize);
    }
    CriteriaBuilder<T> cb = evm.applySetting(setting, criteria);
    List<T> results = cb.getResultList();
    List<Version> versions = new ArrayList<>(doc1.getVersions());
    versions.sort(Comparator.comparing(Version::getIdx));
    List<Version> versionsIdSorted = new ArrayList<>(doc1.getVersions());
    versionsIdSorted.sort(Comparator.comparing(Version::getId));
    assertEquals(2, results.size());
    assertEquals("doc1", results.get(0).getName());
    assertEquals(2, results.get(0).getVersions().size());
    assertEquals(2, results.get(0).getVersionMap().size());
    assertEquals(2, results.get(0).getVersionMap2().size());
    assertEquals(1, results.get(0).getMultiVersions().size());
    assertEquals(1, results.get(0).getMultiVersionMap().size());
    assertEquals(1, results.get(0).getMultiVersionMap2().size());
    assertEquals(versions.get(0).getId(), results.get(0).getVersions().get(0).getId());
    assertEquals(versions.get(1).getId(), results.get(0).getVersions().get(1).getId());
    assertEquals(versions.get(0).getId(), results.get(0).getVersionMap().get(1).getId());
    assertEquals(versions.get(1).getId(), results.get(0).getVersionMap().get(2).getId());
    assertEquals(versions.get(0).getId(), results.get(0).getVersionMap2().get(VersionKeyView.of(1)).getId());
    assertEquals(versions.get(1).getId(), results.get(0).getVersionMap2().get(VersionKeyView.of(2)).getId());
    assertEquals(versionsIdSorted.get(0).getId(), results.get(0).getMultiVersions().get(0).first().getId());
    assertEquals(versionsIdSorted.get(1).getId(), results.get(0).getMultiVersions().get(0).last().getId());
    assertEquals(versionsIdSorted.get(0).getId(), results.get(0).getMultiVersionMap().get(0).first().getId());
    assertEquals(versionsIdSorted.get(1).getId(), results.get(0).getMultiVersionMap().get(0).last().getId());
    assertEquals(versionsIdSorted.get(0).getId(), results.get(0).getMultiVersionMap2().get(VersionStaticKeyView.of(0)).first().getId());
    assertEquals(versionsIdSorted.get(1).getId(), results.get(0).getMultiVersionMap2().get(VersionStaticKeyView.of(0)).last().getId());
    assertEquals("doc2", results.get(1).getName());
    assertEquals(0, results.get(1).getVersions().size());
    assertEquals(0, results.get(1).getVersionMap().size());
    assertEquals(0, results.get(1).getVersionMap2().size());
    assertEquals(0, results.get(1).getMultiVersions().size());
    assertEquals(0, results.get(1).getMultiVersionMap().size());
    assertEquals(0, results.get(1).getMultiVersionMap2().size());
}
Also used : CriteriaBuilder(com.blazebit.persistence.CriteriaBuilder) EntityViewConfiguration(com.blazebit.persistence.view.spi.EntityViewConfiguration) Version(com.blazebit.persistence.testsuite.entity.Version) ArrayList(java.util.ArrayList) Document(com.blazebit.persistence.testsuite.entity.Document)

Example 3 with Version

use of com.blazebit.persistence.testsuite.entity.Version 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);
        }
    });
}
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 4 with Version

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

the class ListaggTest 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 5 with Version

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

the class ListaggTest method testDescNullsLast.

// NOTE: DB2 crashes when executing this test
@Test
@Category({ NoDB2.class })
public void testDescNullsLast() {
    BlazeCriteriaBuilder cb = BlazeCriteria.get(cbf);
    BlazeCriteriaQuery<Tuple> tupleQuery = cb.createTupleQuery();
    BlazeRoot<Document> doc = tupleQuery.from(Document.class, "doc");
    BlazeSetJoin<Document, Version> versions = doc.join(Document_.versions, JoinType.LEFT);
    tupleQuery.multiselect(cb.listagg(versions.get(Version_.url), cb.literal(", ")).withinGroup(cb.desc(versions.get(Version_.url), false)));
    tupleQuery.groupBy(doc.get(Document_.owner));
    Tuple actual = tupleQuery.createCriteriaBuilder(em).getResultList().get(0);
    assertEquals("b, a", actual.get(0));
}
Also used : Version(com.blazebit.persistence.testsuite.entity.Version) Document(com.blazebit.persistence.testsuite.entity.Document) Tuple(javax.persistence.Tuple) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractCoreTest(com.blazebit.persistence.testsuite.AbstractCoreTest)

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