use of io.crnk.jpa.model.OtherRelatedEntity in project crnk-framework by crnk-project.
the class JpaQuerySpecEndToEndTest method addTestWithManyRelations.
private TestEntity addTestWithManyRelations() {
ResourceRepositoryV2<OtherRelatedEntity, Long> otherRepo = client.getQuerySpecRepository(OtherRelatedEntity.class);
ResourceRepositoryV2<RelatedEntity, Long> relatedRepo = client.getQuerySpecRepository(RelatedEntity.class);
RelationshipRepositoryV2<TestEntity, Long, RelatedEntity, Long> relRepo = client.getQuerySpecRepository(TestEntity.class, RelatedEntity.class);
RelationshipRepositoryV2<RelatedEntity, Long, OtherRelatedEntity, Long> otherRelRepo = client.getQuerySpecRepository(RelatedEntity.class, OtherRelatedEntity.class);
TestEntity test = new TestEntity();
test.setId(2L);
test.setStringValue("test");
testRepo.create(test);
RelatedEntity related1 = new RelatedEntity();
related1.setId(101L);
related1.setStringValue("related1");
relatedRepo.create(related1);
RelatedEntity related2 = new RelatedEntity();
related2.setId(102L);
related2.setStringValue("related2");
relatedRepo.create(related2);
RelatedEntity related3 = new RelatedEntity();
related3.setId(103L);
related3.setStringValue("related3");
relatedRepo.create(related3);
OtherRelatedEntity other1 = new OtherRelatedEntity();
other1.setId(101L);
other1.setStringValue("related1");
otherRepo.create(other1);
OtherRelatedEntity other2 = new OtherRelatedEntity();
other2.setId(102L);
other2.setStringValue("related2");
otherRepo.create(other2);
OtherRelatedEntity other3 = new OtherRelatedEntity();
other3.setId(103L);
other3.setStringValue("related3");
otherRepo.create(other3);
List<Long> relatedIds = Arrays.asList(related1.getId(), related2.getId(), related3.getId());
relRepo.addRelations(test, relatedIds, TestEntity.ATTR_manyRelatedValues);
otherRelRepo.setRelation(related1, other1.getId(), RelatedEntity.ATTR_otherEntity);
otherRelRepo.setRelation(related2, other2.getId(), RelatedEntity.ATTR_otherEntity);
otherRelRepo.setRelation(related3, other3.getId(), RelatedEntity.ATTR_otherEntity);
return test;
}
Aggregations