Search in sources :

Example 16 with DBTable

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

the class AbstractRdbmsStore method createPredicateTable.

/**
 * Create a table associated to the specified predicate and return the table
 * informations.
 *
 * @param predicate
 * @return the table informations.
 * @throws AtomSetException
 */
protected DBTable createPredicateTable(Predicate predicate) throws AtomSetException {
    String tableName = this.getFreshPredicateTableName(predicate);
    DBTable table = null;
    if (predicate.getArity() >= 1) {
        Statement stat = this.createStatement();
        table = generateNewDBTableData(tableName, predicate.getArity());
        String query = this.getConjunctiveQueryTranslator().translateCreateTable(table);
        try {
            stat.executeUpdate(query);
        } catch (SQLException e) {
            throw new AtomSetException("Error during table creation: " + query, e);
        }
        if (stat != null) {
            try {
                stat.close();
            } catch (SQLException e) {
                throw new AtomSetException(e);
            }
        }
        // add to the local map
        this.predicateMap.put(predicate, table);
    } else {
        throw new AtomSetException("Unsupported arity 0");
    }
    return table;
}
Also used : DBTable(fr.lirmm.graphik.graal.store.rdbms.util.DBTable) SQLException(java.sql.SQLException) Statement(java.sql.Statement) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException)

Example 17 with DBTable

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

the class AbstractRdbmsStore method getPredicateTable.

/**
 * Get the table informations associated to the specified predicate. If
 * there is no table for it, return null.
 *
 * @param predicate
 * @return the table informations associated to the specified predicate.
 * @throws AtomSetException
 */
protected DBTable getPredicateTable(Predicate predicate) throws AtomSetException {
    // look in the local map
    DBTable table = this.predicateMap.get(predicate);
    if (table == null) {
        // look in the database
        table = this.getPredicateTableIfExist(predicate);
        this.predicateMap.put(predicate, table);
    }
    return table;
}
Also used : DBTable(fr.lirmm.graphik.graal.store.rdbms.util.DBTable)

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