{
String union = " UNION ALL ";
StringBuilder sb = new StringBuilder(1024);
sb.append("(");
for (Number pred : triples.getPredicateIds()) {
TripleTable predicate;
try {
predicate = triples.getPredicateTable(pred);
}
catch (SQLException e) {
throw new AssertionError(e);
}
TransactionTable table = findTable(pred);
if ((table == null || table.isEmpty()) && predicate.isEmpty()) {
continue;
}
sb.append("SELECT ctx, subj, ");
if (predicate.isPredColumnPresent()) {
sb.append(" pred,");
}
else {
sb.append(pred).append(" AS pred,");
}
sb.append(" obj");
sb.append("\nFROM ");
sb.append(predicate.getNameWhenReady());
sb.append(union);
predicate.blockUntilReady();
}
if (sb.length() < union.length()) {
return getEmptyTableName();
}
sb.delete(sb.length() - union.length(), sb.length());