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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations