Moved code to ensure that build are finished to the Java side to solve
bug where query was kept on running even though the model was not built
yet.