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());
}
}
}
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());
}
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);
}
});
}
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);
}
});
}
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));
}
Aggregations