String searchCondition = buildSearchCondition();
String stateCondition = buildStateCondition();
String otherSourceCondition = buildSourceConditionsOtherThanSearch();
String otherTargetCondition = buildTargetConditionsOtherThanSearch();
QueryBuilder query =
QueryBuilder
.select(selectStatement)
.from("HTextFlow tf")
.leftJoin("tf.targets tfts")
.with(eq("tfts.index", Locale.placeHolder()))
.where(and(obsoleteCondition, docIdCondition,
searchCondition, stateCondition,
otherSourceCondition, otherTargetCondition))
.orderBy("tf.pos");
return query.toQueryString();
}