Search in sources :

Example 1 with UnsupportedAtomTypeException

use of fr.lirmm.graphik.graal.api.core.UnsupportedAtomTypeException 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 2 with UnsupportedAtomTypeException

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

the class AdHocRdbmsStore method add.

// /////////////////////////////////////////////////////////////////////////
// PROTECTED METHODS
// /////////////////////////////////////////////////////////////////////////
/**
 * @param statement
 * @param atom
 * @throws AtomSetException
 */
@Override
protected Statement add(Statement statement, Atom atom) throws AtomSetException {
    if (!this.check(atom)) {
        // FIXME say why
        throw new UnsupportedAtomTypeException("");
    }
    try {
        for (Term t : atom.getTerms()) {
            if (this.getTerm(t.getLabel()) == null) {
                // FIXME Quick fix for
                // VARIABLE and
                // CONSTANT with same
                // label conflict
                this.add(statement, t);
            }
        }
        DBTable table = this.createPredicateTableIfNotExist(atom.getPredicate());
        Map<String, String> data = new TreeMap<String, String>();
        int i = -1;
        for (Term t : atom.getTerms()) {
            ++i;
            data.put("term" + i, '\'' + StringUtils.addSlashes(t.getIdentifier().toString()) + '\'');
        }
        String query = this.getDriver().getInsertOrIgnoreQuery(table, data);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(atom.toString() + " : " + query.toString());
        }
        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) Term(fr.lirmm.graphik.graal.api.core.Term) TreeMap(java.util.TreeMap)

Aggregations

AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)2 Term (fr.lirmm.graphik.graal.api.core.Term)2 UnsupportedAtomTypeException (fr.lirmm.graphik.graal.api.core.UnsupportedAtomTypeException)2 DBTable (fr.lirmm.graphik.graal.store.rdbms.util.DBTable)2 SQLException (java.sql.SQLException)2 TreeMap (java.util.TreeMap)2 DBColumn (fr.lirmm.graphik.graal.store.rdbms.util.DBColumn)1