use of com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntitySimpleEmbeddable2 in project blaze-persistence by Blazebit.
the class EmbeddableTestEntityViewTest method setUp.
@Before
public void setUp() {
cleanDatabase();
transactional(new TxVoidWork() {
@Override
public void work(EntityManager em) {
IntIdEntity intIdEntity1 = new IntIdEntity("1");
entity1 = new EmbeddableTestEntity2();
entity1.setId(new EmbeddableTestEntityId2(intIdEntity1, "1"));
entity1.getEmbeddableSet().add(new EmbeddableTestEntitySimpleEmbeddable2("1"));
entity1.getEmbeddableMap().put("key1", new EmbeddableTestEntitySimpleEmbeddable2("1"));
entity1.getEmbeddable().setName("1");
entity1.getEmbeddable().setManyToOne(null);
entity1.getEmbeddable().getElementCollection().put("1", intIdEntity1);
IntIdEntity intIdEntity2 = new IntIdEntity("2");
entity2 = new EmbeddableTestEntity2();
entity2.setId(new EmbeddableTestEntityId2(intIdEntity2, "2"));
entity2.getEmbeddableSet().add(new EmbeddableTestEntitySimpleEmbeddable2("2"));
entity2.getEmbeddableMap().put("key2", new EmbeddableTestEntitySimpleEmbeddable2("2"));
entity2.getEmbeddable().setName("2");
entity2.getEmbeddable().setManyToOne(entity1);
entity2.getEmbeddable().getElementCollection().put("2", intIdEntity2);
em.persist(intIdEntity1);
em.persist(intIdEntity2);
em.persist(entity1);
em.persist(entity2);
}
});
entity1 = cbf.create(em, EmbeddableTestEntity2.class).fetch("id.intIdEntity", "embeddableSet", "embeddableMap", "embeddable.manyToOne", "embeddable.oneToMany", "embeddable.elementCollection").where("id").eq(entity1.getId()).getSingleResult();
entity2 = cbf.create(em, EmbeddableTestEntity2.class).fetch("id.intIdEntity", "embeddableSet", "embeddableMap", "embeddable.manyToOne", "embeddable.oneToMany", "embeddable.elementCollection").where("id").eq(entity2.getId()).getSingleResult();
}
use of com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntitySimpleEmbeddable2 in project blaze-persistence by Blazebit.
the class EmbeddableTestEntityViewTest method assertEqualViewEquals.
private void assertEqualViewEquals(EmbeddableTestEntity2 entity, EmbeddableTestEntityView view) {
assertEquals(entity.getId(), view.getId());
assertEquals(entity.getId().getIntIdEntity(), view.getIdIntIdEntity());
assertEquals(entity.getId().getIntIdEntity().getId(), view.getIdIntIdEntityId());
assertEquals(entity.getId().getIntIdEntity().getName(), view.getIdIntIdEntityName());
assertEquals(entity.getId().getKey(), view.getIdKey());
assertEquals(entity.getEmbeddable().getName(), view.getEmbeddable().getName());
assertEquals(entity.getEmbeddable().getManyToOne(), view.getEmbeddableManyToOne());
assertEquals(entity.getEmbeddable().getOneToMany(), view.getEmbeddableOneToMany());
assertEquals(entity.getEmbeddable().getElementCollection(), view.getEmbeddableElementCollection());
Set<String> set1 = new HashSet<String>();
for (EmbeddableTestEntitySimpleEmbeddable2 elem : entity.getEmbeddableSet()) {
set1.add(elem.getName());
}
Set<String> set2 = new HashSet<String>();
for (EmbeddableTestEntitySimpleEmbeddableSubView elem : view.getEmbeddableSet()) {
set2.add(elem.getName());
}
assertEquals(set1, set2);
Map<String, String> map1 = new HashMap<String, String>();
for (Map.Entry<String, EmbeddableTestEntitySimpleEmbeddable2> entry : entity.getEmbeddableMap().entrySet()) {
map1.put(entry.getKey(), entry.getValue().getName());
}
Map<String, String> map2 = new HashMap<String, String>();
for (Map.Entry<String, EmbeddableTestEntitySimpleEmbeddableSubView> entry : view.getEmbeddableMap().entrySet()) {
map2.put(entry.getKey(), entry.getValue().getName());
}
assertEquals(map1, map2);
}
use of com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntitySimpleEmbeddable2 in project blaze-persistence by Blazebit.
the class EmbeddableTestEntityViewTest method assertEqualViewEquals.
private void assertEqualViewEquals(EmbeddableTestEntity2 entity, EmbeddableTestEntityViewWithSubview view) {
assertEquals(entity.getId(), view.getId());
if (entity.getId().getIntIdEntity() == null) {
assertNull(view.getIdIntIdEntity());
} else {
assertEquals(entity.getId().getIntIdEntity().getId(), view.getIdIntIdEntity().getId());
}
assertEquals(entity.getId().getIntIdEntity().getId(), view.getIdIntIdEntityId());
assertEquals(entity.getId().getIntIdEntity().getName(), view.getIdIntIdEntityName());
assertEquals(entity.getId().getKey(), view.getIdKey());
assertEquals(entity.getEmbeddable().getName(), view.getEmbeddable().getName());
if (entity.getEmbeddable().getManyToOne() == null) {
assertNull(view.getEmbeddableManyToOneView());
} else {
assertEquals(entity.getEmbeddable().getManyToOne().getId(), view.getEmbeddableManyToOneView().getId());
}
assertEquals(entity.getEmbeddable().getOneToMany().size(), view.getEmbeddableOneToManyView().size());
OUTER: for (EmbeddableTestEntity2 child : entity.getEmbeddable().getOneToMany()) {
for (EmbeddableTestEntitySubView childView : view.getEmbeddableOneToManyView()) {
if (child.getId().equals(childView.getId())) {
continue OUTER;
}
}
fail("Couldn't find child view with id: " + child.getId());
}
assertEquals(entity.getEmbeddable().getElementCollection().size(), view.getEmbeddableElementCollectionView().size());
for (Map.Entry<String, IntIdEntity> childEntry : entity.getEmbeddable().getElementCollection().entrySet()) {
IntIdEntityView childView = view.getEmbeddableElementCollectionView().get(childEntry.getKey());
assertEquals(childEntry.getValue().getId(), childView.getId());
}
Set<String> set1 = new HashSet<String>();
for (EmbeddableTestEntitySimpleEmbeddable2 elem : entity.getEmbeddableSet()) {
set1.add(elem.getName());
}
Set<String> set2 = new HashSet<String>();
for (EmbeddableTestEntitySimpleEmbeddableSubView elem : view.getEmbeddableSet()) {
set2.add(elem.getName());
}
assertEquals(set1, set2);
Map<String, String> map1 = new HashMap<String, String>();
for (Map.Entry<String, EmbeddableTestEntitySimpleEmbeddable2> entry : entity.getEmbeddableMap().entrySet()) {
map1.put(entry.getKey(), entry.getValue().getName());
}
Map<String, String> map2 = new HashMap<String, String>();
for (Map.Entry<String, EmbeddableTestEntitySimpleEmbeddableSubView> entry : view.getEmbeddableMap().entrySet()) {
map2.put(entry.getKey(), entry.getValue().getName());
}
assertEquals(map1, map2);
}
use of com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntitySimpleEmbeddable2 in project blaze-persistence by Blazebit.
the class EmbeddedFetchTest method setUpOnce.
@Override
public void setUpOnce() {
cleanDatabase();
transactional(new TxVoidWork() {
@Override
public void work(EntityManager em) {
IntIdEntity id1 = new IntIdEntity("i1");
IntIdEntity id2 = new IntIdEntity("i2");
IntIdEntity id3 = new IntIdEntity("i3");
IntIdEntity id4 = new IntIdEntity("i4");
em.persist(id1);
em.persist(id2);
em.persist(id3);
em.persist(id4);
doc1 = new EmbeddableTestEntity2(id1, "doc1");
doc2 = new EmbeddableTestEntity2(id2, "doc2");
doc3 = new EmbeddableTestEntity2(id3, "doc3");
doc4 = new EmbeddableTestEntity2(id4, "doc4");
doc1.getEmbeddableSet().add(new EmbeddableTestEntitySimpleEmbeddable2("doc1"));
doc2.getEmbeddableSet().add(new EmbeddableTestEntitySimpleEmbeddable2("doc2"));
doc3.getEmbeddableSet().add(new EmbeddableTestEntitySimpleEmbeddable2("doc3"));
doc4.getEmbeddableSet().add(new EmbeddableTestEntitySimpleEmbeddable2("doc4"));
doc1.getEmbeddableMap().put("doc1", new EmbeddableTestEntitySimpleEmbeddable2("doc1"));
doc2.getEmbeddableMap().put("doc2", new EmbeddableTestEntitySimpleEmbeddable2("doc2"));
doc3.getEmbeddableMap().put("doc3", new EmbeddableTestEntitySimpleEmbeddable2("doc3"));
doc4.getEmbeddableMap().put("doc4", new EmbeddableTestEntitySimpleEmbeddable2("doc4"));
em.persist(doc1);
em.persist(doc2);
em.persist(doc3);
em.persist(doc4);
doc1.getEmbeddable().setManyToOne(doc2);
doc2.getEmbeddable().setManyToOne(doc2);
doc3.getEmbeddable().setManyToOne(doc2);
doc4.getEmbeddable().setManyToOne(doc2);
doc1.getEmbeddable().getOneToMany().add(doc3);
doc2.getEmbeddable().getOneToMany().add(doc3);
doc3.getEmbeddable().getOneToMany().add(doc3);
doc4.getEmbeddable().getOneToMany().add(doc3);
doc1.getEmbeddable().getElementCollection().put("doc1", id1);
doc2.getEmbeddable().getElementCollection().put("doc2", id2);
doc3.getEmbeddable().getElementCollection().put("doc3", id3);
doc4.getEmbeddable().getElementCollection().put("doc4", id4);
}
});
}
Aggregations