use of fr.lirmm.graphik.graal.store.rdbms.RdbmsConjunctiveQueryTranslator in project graal by graphik-team.
the class SqlUCQHomomorphism method preprocessing.
private static SQLQuery preprocessing(UnionOfConjunctiveQueries queries, RdbmsStore store) throws HomomorphismException {
boolean emptyQuery = false;
CloseableIterator<ConjunctiveQuery> it = queries.iterator();
StringBuilder ucq = new StringBuilder();
RdbmsConjunctiveQueryTranslator translator = store.getConjunctiveQueryTranslator();
try {
if (!it.hasNext())
return SQLQuery.hasSchemaErrorInstance();
while (it.hasNext()) {
SQLQuery query = translator.translate(it.next());
if (!query.hasSchemaError()) {
if (ucq.length() > 0)
ucq.append("\nUNION\n");
ucq.append(query.toString());
} else if (query.isEmpty()) {
emptyQuery = true;
}
}
} catch (Exception e) {
throw new HomomorphismException("Error during query translation to SQL", e);
}
SQLQuery query = new SQLQuery(ucq.toString());
if (query.isEmpty() && !emptyQuery) {
return SQLQuery.hasSchemaErrorInstance();
}
return query;
}
Aggregations