Search in sources :

Example 21 with SailException

use of org.openrdf.sail.SailException in project backstage by zepheira.

the class Database method createTypeRecord.

private TypeRecord createTypeRecord(URI type, SailConnection sc) {
    String id = getTypeId(type, sc);
    String label = SailUtilities.getStringObject(sc, type, RDFS.LABEL, id);
    Properties properties = new Properties();
    CloseableIteration<? extends Statement, SailException> i = null;
    try {
        i = sc.getStatements(type, null, null, true);
    } catch (SailException e) {
        _logger.error("Failed to get all statements in order to get type record", e);
        return null;
    }
    if (i != null) {
        try {
            while (i.hasNext()) {
                Statement s = i.next();
                URI p = s.getPredicate();
                Value o = s.getObject();
                if (!p.equals(RDFS.LABEL) && !p.equals(ExhibitOntology.ID)) {
                    properties.put(p.getLocalName(), SailUtilities.valueToString(o));
                }
            }
        } catch (SailException e) {
            _logger.warn("Failed to iterate through statements", e);
        } finally {
            try {
                i.close();
            } catch (SailException e) {
                _logger.warn("Failed to close statement iterator", e);
            }
        }
    }
    return new TypeRecord(type, id, label, properties);
}
Also used : Statement(org.openrdf.model.Statement) Value(org.openrdf.model.Value) SailException(org.openrdf.sail.SailException) Properties(java.util.Properties) URI(org.openrdf.model.URI)

Example 22 with SailException

use of org.openrdf.sail.SailException in project backstage by zepheira.

the class Database method abbreviateItems.

protected synchronized void abbreviateItems() {
    if (_abbreviatedItems) {
        return;
    }
    _abbreviatedItems = true;
    getRepository();
    SailConnection sc = null;
    try {
        sc = _sail.getConnection();
    } catch (SailException e) {
        _logger.error("Failed to open sail connection in order to compute cached information", e);
    }
    if (sc != null) {
        try {
            CloseableIteration<? extends Statement, SailException> i;
            try {
                i = sc.getStatements(null, RDF.TYPE, null, true);
            } catch (SailException e) {
                _logger.error("Failed to get all statements in order to abbreviate items", e);
                return;
            }
            try {
                while (i.hasNext()) {
                    Statement s = i.next();
                    Resource r = s.getSubject();
                    if (r instanceof URI) {
                        getItemId((URI) r, sc);
                    }
                }
            } catch (SailException e) {
                _logger.warn("Failed to iterate through statements", e);
            } finally {
                try {
                    i.close();
                } catch (SailException e) {
                    _logger.warn("Failed to close statement iterator", e);
                }
            }
        } finally {
            try {
                sc.close();
            } catch (SailException e) {
                _logger.warn("Failed to close sail connection", e);
            }
        }
    }
}
Also used : SailConnection(org.openrdf.sail.SailConnection) Statement(org.openrdf.model.Statement) Resource(org.openrdf.model.Resource) SailException(org.openrdf.sail.SailException) URI(org.openrdf.model.URI)

Example 23 with SailException

use of org.openrdf.sail.SailException in project backstage by zepheira.

the class Database method internalBuildTypeRecords.

private void internalBuildTypeRecords(SailConnection sc) {
    _typeRecords = new LinkedList<TypeRecord>();
    _typeIDToRecord = new HashMap<String, TypeRecord>();
    getRepository();
    CloseableIteration<? extends Statement, SailException> i;
    try {
        i = sc.getStatements(null, RDF.TYPE, null, true);
    } catch (SailException e) {
        _logger.error("Failed to get all statements in order to get type records", e);
        return;
    }
    Set<URI> types = new HashSet<URI>();
    try {
        while (i.hasNext()) {
            Statement s = i.next();
            types.add((URI) s.getObject());
        }
    } catch (SailException e) {
        _logger.warn("Failed to iterate through statements", e);
    } finally {
        try {
            i.close();
        } catch (SailException e) {
            _logger.warn("Failed to close statement iterator", e);
        }
    }
    for (URI type : types) {
        TypeRecord r = createTypeRecord(type, sc);
        if (r != null) {
            _typeRecords.add(r);
            _typeIDToRecord.put(r.id, r);
        }
    }
}
Also used : Statement(org.openrdf.model.Statement) SailException(org.openrdf.sail.SailException) URI(org.openrdf.model.URI) HashSet(java.util.HashSet)

Aggregations

SailException (org.openrdf.sail.SailException)23 SailConnection (org.openrdf.sail.SailConnection)10 Statement (org.openrdf.model.Statement)8 URI (org.openrdf.model.URI)8 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 Namespace (org.openrdf.model.Namespace)4 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)4 SailConnectionTripleSource (net.fortytwo.sesametools.SailConnectionTripleSource)3 Resource (org.openrdf.model.Resource)3 TripleSource (org.openrdf.query.algebra.evaluation.TripleSource)3 NotifyingSailConnection (org.openrdf.sail.NotifyingSailConnection)3 Edge (com.tinkerpop.blueprints.Edge)2 Vertex (com.tinkerpop.blueprints.Vertex)2 Properties (java.util.Properties)2 Value (org.openrdf.model.Value)2 ValueFactory (org.openrdf.model.ValueFactory)2 EvaluationStrategyImpl (org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl)2 Graph (com.tinkerpop.blueprints.Graph)1 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)1