Search in sources :

Example 1 with RdbmsConjunctiveQueryTranslator

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;
}
Also used : HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) RdbmsConjunctiveQueryTranslator(fr.lirmm.graphik.graal.store.rdbms.RdbmsConjunctiveQueryTranslator) SQLQuery(fr.lirmm.graphik.graal.store.rdbms.util.SQLQuery) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)

Aggregations

ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)1 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)1 RdbmsConjunctiveQueryTranslator (fr.lirmm.graphik.graal.store.rdbms.RdbmsConjunctiveQueryTranslator)1 SQLQuery (fr.lirmm.graphik.graal.store.rdbms.util.SQLQuery)1