Search in sources :

Example 6 with AtomSetException

use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.

the class NaturalRDBMSStore method match.

// /////////////////////////////////////////////////////////////////////////
// METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public CloseableIterator<Atom> match(Atom atom) throws AtomSetException {
    if (!this.check(atom)) {
        return Iterators.<Atom>emptyIterator();
    }
    ConjunctiveQuery query = DefaultConjunctiveQueryFactory.instance().create(new LinkedListAtomSet(atom));
    SqlHomomorphism solver = SqlHomomorphism.instance();
    try {
        return new SubstitutionIterator2AtomIterator(atom, solver.execute(query, this));
    } catch (HomomorphismException e) {
        throw new AtomSetException(e);
    }
}
Also used : HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) SqlHomomorphism(fr.lirmm.graphik.graal.store.rdbms.homomorphism.SqlHomomorphism) SubstitutionIterator2AtomIterator(fr.lirmm.graphik.graal.core.stream.SubstitutionIterator2AtomIterator) Atom(fr.lirmm.graphik.graal.api.core.Atom) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)

Example 7 with AtomSetException

use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.

the class NaturalRDBMSStore method add.

// /////////////////////////////////////////////////////////////////////////
// PROTECTED AND PRIVATE METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
protected Statement add(Statement statement, Atom atom) throws AtomSetException {
    if (!this.check(atom)) {
        // FIXME say why
        throw new UnsupportedAtomTypeException("");
    }
    try {
        DBTable table = this.createPredicateTableIfNotExist(atom.getPredicate());
        Iterator<DBColumn> cols = table.getColumns().iterator();
        Map<String, String> data = new TreeMap<String, String>();
        for (Term t : atom.getTerms()) {
            DBColumn col = cols.next();
            data.put(col.getName(), this.getConjunctiveQueryTranslator().formatFromColumnType(col, t));
        }
        String query = this.getDriver().getInsertOrIgnoreQuery(table, data);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(atom.toString() + " : " + query);
        }
        statement.addBatch(query);
    } catch (SQLException e) {
        throw new AtomSetException(e);
    }
    return statement;
}
Also used : UnsupportedAtomTypeException(fr.lirmm.graphik.graal.api.core.UnsupportedAtomTypeException) DBTable(fr.lirmm.graphik.graal.store.rdbms.util.DBTable) SQLException(java.sql.SQLException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) DBColumn(fr.lirmm.graphik.graal.store.rdbms.util.DBColumn) Term(fr.lirmm.graphik.graal.api.core.Term) TreeMap(java.util.TreeMap)

Example 8 with AtomSetException

use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.

the class Neo4jStore method getPredicates.

@Override
public Set<Predicate> getPredicates() throws AtomSetException {
    TreeSet<Predicate> set = new TreeSet<Predicate>();
    CloseableIterator<Predicate> it = this.predicatesIterator();
    try {
        while (it.hasNext()) {
            set.add(it.next());
        }
    } catch (IteratorException e) {
        throw new AtomSetException("An errors occurs while iterating predicates", e);
    }
    return set;
}
Also used : IteratorException(fr.lirmm.graphik.util.stream.IteratorException) TreeSet(java.util.TreeSet) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) Predicate(fr.lirmm.graphik.graal.api.core.Predicate)

Example 9 with AtomSetException

use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.

the class AbstractRdbmsStore method add.

// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public boolean add(Atom atom) throws AtomSetException {
    boolean res = false;
    Statement statement = null;
    try {
        statement = this.createStatement();
        this.add(statement, atom);
        int[] ret = statement.executeBatch();
        for (int i : ret) {
            if (i > 0) {
                res = true;
                break;
            }
        }
    } catch (SQLException e) {
        throw new AtomSetException("Error while adding an atom", e);
    } finally {
        if (statement != null) {
            try {
                this.getConnection().commit();
                statement.close();
            } catch (SQLException e) {
                throw new AtomSetException("Error while adding an atom", e);
            }
        }
    }
    return res;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException)

Example 10 with AtomSetException

use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.

the class AbstractRdbmsStore method removeAll.

@Override
public boolean removeAll(CloseableIterator<? extends Atom> stream) throws AtomSetException {
    try {
        int c = 0;
        Statement statement = this.createStatement();
        while (stream.hasNext()) {
            this.remove(statement, stream.next());
            if (++c % MAX_BATCH_SIZE == 0) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("batch commit, size=" + MAX_BATCH_SIZE);
                }
                statement.executeBatch();
                statement.close();
            }
        }
        if (!statement.isClosed()) {
            statement.executeBatch();
            statement.close();
        }
        this.getConnection().commit();
    } catch (Exception e) {
        throw new AtomSetException(e);
    }
    return true;
}
Also used : Statement(java.sql.Statement) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) SQLException(java.sql.SQLException) IteratorException(fr.lirmm.graphik.util.stream.IteratorException)

Aggregations

AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)69 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)26 SQLException (java.sql.SQLException)26 Atom (fr.lirmm.graphik.graal.api.core.Atom)25 Term (fr.lirmm.graphik.graal.api.core.Term)23 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)12 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)11 Statement (java.sql.Statement)11 DBTable (fr.lirmm.graphik.graal.store.rdbms.util.DBTable)10 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)9 BacktrackException (fr.lirmm.graphik.graal.homomorphism.BacktrackException)9 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)7 TreeSet (java.util.TreeSet)7 SQLQuery (fr.lirmm.graphik.graal.store.rdbms.util.SQLQuery)6 CloseableIteratorAdapter (fr.lirmm.graphik.util.stream.CloseableIteratorAdapter)6 RuleApplicationException (fr.lirmm.graphik.graal.api.forward_chaining.RuleApplicationException)5 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)5 TreeMap (java.util.TreeMap)5 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)4 Variable (fr.lirmm.graphik.graal.api.core.Variable)4