本文整理匯總了Java中org.openrdf.repository.RepositoryException類的典型用法代碼示例。如果您正苦於以下問題:Java RepositoryException類的具體用法?Java RepositoryException怎麽用?Java RepositoryException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RepositoryException類屬於org.openrdf.repository包,在下文中一共展示了RepositoryException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: rewrite
import org.openrdf.repository.RepositoryException; //導入依賴的package包/類
/**
* Rewrite a given query to add inference.
*
* @param ql the query language used for the query
* @param query the query to rewrite
* @param baseuri a base URI to use for the query
* @return rewritten query that includes inference
* @throws MalformedQueryException if the query is malformed
* @throws RepositoryException if there was a problem while rewriting
*/
public Query rewrite(QueryLanguage ql, String query, String baseuri)
throws MalformedQueryException, RepositoryException {
// parse query using Sesame
QueryParserFactory f = QueryParserRegistry.getInstance().get(ql);
QueryParser parser = f.getParser();
ParsedQuery parsed = parser.parseQuery(query, baseuri);
// get SPARQL algebra expression from parsed query
TupleExpr expr = parsed.getTupleExpr();
// rewrite query using visitor pattern
RuleTransformationVisitor visitor
= new RuleTransformationVisitor(rules);
expr.visit(visitor);
// return new query based on rewritten algebra expression
return getExprQuery(parsed, expr);
}
示例2: addToGraphstore
import org.openrdf.repository.RepositoryException; //導入依賴的package包/類
/**
* Helper method for handleAdd.
*/
private void addToGraphstore(
RepositoryConnection conn,
InputStream in,
String base,
RDFFormat format,
Resource dctx,
boolean chunked) throws IOException, RDFParseException,
RDFHandlerException, RepositoryException {
if (chunked) {
RDFParser parser = getRDFParser(format);
parser.setRDFHandler(
new ChunkedCommitHandler(conn, chunksize, dctx));
parser.parse(in, base);
} else {
if (dctx != null) {
conn.add(in, base, format, dctx);
} else {
conn.add(in, base, format);
}
}
}
示例3: write
import org.openrdf.repository.RepositoryException; //導入依賴的package包/類
/**
* Called by JAX-RS upon building a response.
*
* @param out the {@link OutputStream} to write the triples to
* @throws IOException if there was an error during communication
* @throws WebApplicationException if there was an error while serialising
*/
@Override
public void write(OutputStream out)
throws IOException, WebApplicationException {
try {
// get an RDF writer to stream the triples
RDFWriter writer = factory.getWriter(out);
// export triples from graphs
conn.export(writer, contexts);
conn.close();
} catch (RepositoryException | RDFHandlerException ex) {
// server error
close(conn, ex);
throw new WebApplicationException(ex);
}
}
示例4: write
import org.openrdf.repository.RepositoryException; //導入依賴的package包/類
/**
* Called by JAX-RS upon building a response.
*
* @param out the {@link OutputStream} to write the triples to
* @throws IOException if there was an error during communication
* @throws WebApplicationException if there was an error while serialising
*/
@Override
public void write(OutputStream out)
throws IOException, WebApplicationException {
try {
RDFWriter writer = factory.getWriter(out);
// evaluate query and stream result
query.evaluate(writer);
conn.close();
} catch (RepositoryException |
QueryEvaluationException |
RDFHandlerException ex) {
// server error
close(conn, ex);
throw new WebApplicationException(ex);
}
}
示例5: handleStatement
import org.openrdf.repository.RepositoryException; //導入依賴的package包/類
/**
* Handles a statement.
*
* The statements will be added up until chunk size is reached.
* After a chunk of statements is added the transaction will be committed
* and new transaction will be started.
* @param stmnt
* @throws RDFHandlerException
*/
@Override
public void handleStatement(Statement stmnt) throws RDFHandlerException {
try {
// check if triple should be added to a specific graph
if (dctx != null) {
conn.add(stmnt, dctx);
} else {
conn.add(stmnt);
}
// check if chunk size is reached and transaction should be
// committed
count++;
if (count >= size) {
count = 0;
conn.commit();
conn.begin();
}
} catch (RepositoryException ex) {
throw new RDFHandlerException(ex);
}
}
示例6: before
import org.openrdf.repository.RepositoryException; //導入依賴的package包/類
@Before
public void before()
throws RepositoryException, IOException, RDFParseException,
MalformedQueryException, QueryResultParseException,
QueryResultHandlerException {
repo = new SailRepository(new MemoryStore());
repo.initialize();
conn = repo.getConnection();
vf = conn.getValueFactory();
conn.add(getResource(data), "file://", RDFFormat.TURTLE);
SPARQLResultsXMLParserFactory factory =
new SPARQLResultsXMLParserFactory();
parser = factory.getParser();
parser.setValueFactory(vf);
List<Rule> rules;
rules = Rules.fromOntology(getResource(data));
QueryRewriter rewriter = new QueryRewriter(conn, rules);
query = (TupleQuery) rewriter.rewrite(QueryLanguage.SPARQL, queryString);
nonInfQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
System.out.println("== QUERY (" + this.name + ") ==");
System.out.println(nonInfQuery);
System.out.println("== REWRITTEN QUERY (" + this.name + ") ==");
System.out.println(query);
}
示例7: setUp
import org.openrdf.repository.RepositoryException; //導入依賴的package包/類
@BeforeClass
public static void setUp() throws IOException, RepositoryException, RDFParseException {
int port;
try (final ServerSocket serverSocket = new ServerSocket(0)) {
port = serverSocket.getLocalPort();
}
server = CommunityServerBuilder.server()
.onPort(port)
.withThirdPartyJaxRsPackage("de.unikiel.inf.comsys.neo4j", "/rdf")
.build();
server.start();
GraphDatabaseService db = server.getDatabase().getGraph();
Repository rep = RepositoryRegistry.getInstance(db).getRepository();
conn = rep.getConnection();
InputStream testdata = RDFServerExtensionTest.class.getResourceAsStream("/sp2b.n3");
conn.add(testdata, "http://example.com/", RDFFormat.N3);
}
示例8: getAllPossibleProperties
import org.openrdf.repository.RepositoryException; //導入依賴的package包/類
protected static Collection<URI> getAllPossibleProperties( URI type, IEngine engine ) {
String query = "SELECT DISTINCT ?pred WHERE { ?s ?pred ?o . ?s a ?type . FILTER ( isLiteral( ?o ) ) }";
ListQueryAdapter<URI> qa = OneVarListQueryAdapter.getUriList( query, "pred" );
qa.bind( "type", type );
List<URI> props = new ArrayList<>();
props.add( Constants.ANYNODE );
try {
props.addAll( engine.query( qa ) );
}
catch ( RepositoryException | MalformedQueryException | QueryEvaluationException e ) {
log.error( e, e );
}
return props;
}
示例9: remove
import org.openrdf.repository.RepositoryException; //導入依賴的package包/類
@Override
public void remove( DbInfo t ) throws Exception {
RepositoryConnection rc = store.getConnection();
Resource idToRemove = getId( t, rc );
if ( null != idToRemove ) {
try{
rc.begin();
rc.remove( idToRemove, null, null );
rc.commit();
}
catch( RepositoryException re ){
rc.rollback();
throw re;
}
}
}
示例10: update
import org.openrdf.repository.RepositoryException; //導入依賴的package包/類
@Override
public void update( DbInfo data ) throws Exception {
RepositoryConnection rc = store.getConnection();
Resource id = getId( data, rc );
if ( null != id ) {
try{
rc.begin();
rc.remove( id, null, null );
rc.add( getCreateStatements( id, data, rc.getValueFactory() ) );
rc.commit();
}
catch( RepositoryException re ){
rc.rollback();
throw re;
}
}
}
示例11: getDbInfo
import org.openrdf.repository.RepositoryException; //導入依賴的package包/類
public static DbInfo getDbInfo( Resource id, RepositoryConnection rc )
throws RepositoryException {
DbInfo dbi = new DbInfo();
for ( Statement stmt : Iterations.asList( rc.getStatements( id, null, null, false ) ) ) {
URI pred = stmt.getPredicate();
String val = stmt.getObject().stringValue();
if ( DATA_PREDICATE.equals( pred ) ) {
dbi.setDataUrl( val );
}
else if ( INSIGHTS_PREDICATE.equals( pred ) ) {
dbi.setInsightsUrl( val );
}
else if ( RDFS.LABEL.equals( pred ) ) {
dbi.setName( val );
}
}
return dbi;
}
示例12: getId
import org.openrdf.repository.RepositoryException; //導入依賴的package包/類
public static Resource getId( DbInfo t, RepositoryConnection rc )
throws RepositoryException {
List<Statement> stmts = Iterations.asList( rc.getStatements( null, RDF.TYPE,
WEBDS.DBINFO, false ) );
Resource idToRemove = null;
for ( Statement s : stmts ) {
Resource sbj = s.getSubject();
List<Statement> individuals
= Iterations.asList( rc.getStatements( sbj, RDFS.LABEL, null, false ) );
for ( Statement ind : individuals ) {
if ( ind.getObject().stringValue().equals( t.getName() ) ) {
idToRemove = sbj;
}
}
}
return idToRemove;
}
示例13: update
import org.openrdf.repository.RepositoryException; //導入依賴的package包/類
@Override
public void update( User user ) throws Exception {
RepositoryConnection rc = store.getConnection();
try {
Map<URI, DbAccess> accesses = getAccesses( user );
Resource id = getId( user, rc );
if ( null != id ) {
rc.begin();
rc.remove( id, null, null );
rc.add( getCreateStatements( id, user, rc.getValueFactory() ) );
addAccesses( id, accesses, rc );
rc.commit();
}
}
catch ( RepositoryException e ) {
log.error( e, e );
try {
rc.rollback();
}
catch ( Exception x ) {
log.warn( x, x );
}
}
}
示例14: setAccesses
import org.openrdf.repository.RepositoryException; //導入依賴的package包/類
/**
* Sets the access level from the given map. To remove access from a DB, user
* {@link DbAccess#NONE}.
*
* @param user
* @param access a mapping of URIs (either {@link DbInfo#getDataUrl()} or
* {@link DbInfo#getInsightsUrl()}) and the access given
*/
public void setAccesses( User user, Map<URI, DbAccess> access ) {
RepositoryConnection rc = store.getConnection();
try {
rc.begin();
Resource id = getId( user, rc );
addAccesses( id, access, rc );
rc.commit();
}
catch ( RepositoryException e ) {
log.error( e, e );
try {
rc.rollback();
}
catch ( Exception x ) {
log.warn( x, x );
}
}
}
示例15: getUser
import org.openrdf.repository.RepositoryException; //導入依賴的package包/類
private static User getUser( Resource id, RepositoryConnection rc )
throws RepositoryException {
LinkedHashModel model = new LinkedHashModel( Iterations.asList(
rc.getStatements( id, null, null, false ) ) );
org.openrdf.model.Model namer = model.filter( id, FOAF.ACCOUNT, null );
RemoteUserImpl user = new RemoteUserImpl( namer.objectString() );
model.removeAll( namer );
for ( Statement stmt : model ) {
URI pred = stmt.getPredicate();
String val = stmt.getObject().stringValue();
for ( Map.Entry<UserProperty, URI> en : PROPMAP.entrySet() ) {
if ( en.getValue().equals( pred ) ) {
user.setProperty( en.getKey(), val );
}
}
}
return user;
}