Search in sources :

Example 1 with DBTable

use of fr.lirmm.graphik.graal.store.rdbms.util.DBTable in project graal by graphik-team.

the class AbstractRdbmsStore method removePredicate.

protected void removePredicate(Statement stat, Predicate p) throws AtomSetException {
    try {
        DBTable table = this.getPredicateTable(p);
        String query = String.format("DROP TABLE %s", table.getName());
        stat.execute(query);
        this.predicateMap.remove(p);
    } catch (SQLException e) {
        throw new AtomSetException(e);
    }
}
Also used : DBTable(fr.lirmm.graphik.graal.store.rdbms.util.DBTable) SQLException(java.sql.SQLException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException)

Example 2 with DBTable

use of fr.lirmm.graphik.graal.store.rdbms.util.DBTable in project graal by graphik-team.

the class AdHocConjunctiveQueryTranslator method translateTermsByPredicatePositionQuery.

@Override
public SQLQuery translateTermsByPredicatePositionQuery(Predicate p, int position) throws AtomSetException {
    DBTable table = this.store.getPredicateTable(p);
    if (table == null) {
        return SQLQuery.hasSchemaErrorInstance();
    }
    String query = String.format(TERMS_BY_PREDICATE_POSITION_FORMAT, position, table.getName(), position);
    return new SQLQuery(query);
}
Also used : DBTable(fr.lirmm.graphik.graal.store.rdbms.util.DBTable) SQLQuery(fr.lirmm.graphik.graal.store.rdbms.util.SQLQuery)

Example 3 with DBTable

use of fr.lirmm.graphik.graal.store.rdbms.util.DBTable in project graal by graphik-team.

the class AdHocRdbmsStore method getPredicateTableIfExist.

@Override
protected DBTable getPredicateTableIfExist(Predicate predicate) throws AtomSetException {
    DBTable table = null;
    try {
        this.getPredicateTableStatement.setString(1, predicate.getIdentifier().toString());
        this.getPredicateTableStatement.setInt(2, predicate.getArity());
        ResultSet results = this.getPredicateTableStatement.executeQuery();
        if (results.next()) {
            String predicateTableName = results.getString("predicate_table_name");
            table = this.getDriver().getTable(predicateTableName);
        }
        results.close();
    } catch (SQLException e) {
        throw new AtomSetException(e);
    }
    return table;
}
Also used : DBTable(fr.lirmm.graphik.graal.store.rdbms.util.DBTable) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException)

Example 4 with DBTable

use of fr.lirmm.graphik.graal.store.rdbms.util.DBTable 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)

Example 5 with DBTable

use of fr.lirmm.graphik.graal.store.rdbms.util.DBTable in project graal by graphik-team.

the class AbstractRdbmsConjunctiveQueryTranslator method translateRemove.

// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public SQLQuery translateRemove(Atom atom) throws AtomSetException {
    DBTable table = this.store.getPredicateTableIfExist(atom.getPredicate());
    if (table == null)
        return SQLQuery.hasSchemaErrorInstance();
    StringBuilder query = new StringBuilder("DELETE FROM ");
    query.append(table);
    query.append(" WHERE ");
    List<DBColumn> columns = table.getColumns();
    int termIndex = 0;
    for (Term t : atom.getTerms()) {
        if (termIndex != 0) {
            query.append(" and ");
        }
        query.append(columns.get(termIndex).getName()).append(" = '").append(t.getLabel()).append("'");
        ++termIndex;
    }
    return new SQLQuery(query.toString());
}
Also used : DBTable(fr.lirmm.graphik.graal.store.rdbms.util.DBTable) DBColumn(fr.lirmm.graphik.graal.store.rdbms.util.DBColumn) Term(fr.lirmm.graphik.graal.api.core.Term) SQLQuery(fr.lirmm.graphik.graal.store.rdbms.util.SQLQuery)

Aggregations

DBTable (fr.lirmm.graphik.graal.store.rdbms.util.DBTable)17 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)10 Term (fr.lirmm.graphik.graal.api.core.Term)9 SQLQuery (fr.lirmm.graphik.graal.store.rdbms.util.SQLQuery)9 SQLException (java.sql.SQLException)9 DBColumn (fr.lirmm.graphik.graal.store.rdbms.util.DBColumn)7 TreeMap (java.util.TreeMap)4 Atom (fr.lirmm.graphik.graal.api.core.Atom)3 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)3 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)2 UnsupportedAtomTypeException (fr.lirmm.graphik.graal.api.core.UnsupportedAtomTypeException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)1 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)1 ConversionException (fr.lirmm.graphik.util.stream.converter.ConversionException)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 LinkedList (java.util.LinkedList)1