I have an Person table which contains below information.
Person table | type |
---|---|
personId | INT |
Name | VarChar |
fatherId | INT --refer to personId in same table(Person) |
MotherId | INT --refer to personId in same table(Person) |
More columns | other details |
I have to implement a method similar to the below older implementation below using ASYN programming that returns a family tree.
Older Implementation
My POJO class
public class FamilyTree
Person person;
FamilyTree fatherFamily;
FamilyTree motherFamily;
public FamilyTree (Person person, FamilyTree father, FamilyTree mother){
this.person = person;
this.fatherFamily = father;
this.motherFamily = mother;
}
public static FamilyTree buildFamilyTree(int personId){
Person person = PersonRepository.GetPersonById(personId);
FamilyTree fatherTree = (person.getFatherId == null || person.getFatherId(isEmpty())? null:buildFamilyTree(person.getFatherId());
FamilyTree motherTree = (person.getMotherId == null || person.getMotherId(isEmpty())?null:buildFamilyTree(person.getMotherId());
return new FamilyTree(person, fatherTree, motherTree);
}
How do I implement this with Mutiny and Quarkus reactive SQL without causing block IO exceptions?
New implementation class of what I need is:
@ApplicationScoped
public class FamilyTreeRepostiory{
@Inject
OraclePool client;
public Uni<Person> getPersonById(int personId){
String sql = "select * from person where personId=?";
Tuple tuple = Tuple.of(personId);
return client.preparedQuery(sql).execute(tuple).onItem().transform(Rowset::iterator)
.onItem.transform(iterator-> iterator.hasNext()?Person.convertPerson(iterator.next()):null);
}
public Uni<FamilyTree> getFamilyTree(int personId){
Uni<Person> person = getPersonById(personId);
//help with this implementation is needed.
return familyTree ;
}
}