Package org.openrdf.repository

Examples of org.openrdf.repository.RepositoryConnection


                    log.info("refreshed resource {}",resource);

                    URI context = cacheProvider.getTripleRepository().getValueFactory().createURI(CTX_CACHE);


                    RepositoryConnection lmfConnection = cacheProvider.getTripleRepository().getConnection();
                    RepositoryConnection respConnection = response.getTriples().getConnection();

                    lmfConnection.remove(resource,null,null,context);


                    RepositoryResult<Statement> triples = respConnection.getStatements(null,null,null,true);
                    while(triples.hasNext()) {
                        Statement triple = triples.next();
                        try {
                            lmfConnection.add(triple,context);
                        } catch (RuntimeException ex) {
                            log.warn("not adding triple {}: an exception occurred ({})",triple,ex.getMessage());
                        }
                    }
                    lmfConnection.commit();

                    lmfConnection.close();
                    respConnection.close();

                    CacheEntry newEntry = new CacheEntry();
                    newEntry.setResource(resource);
                    newEntry.setExpiryDate(response.getExpires());
                    newEntry.setLastRetrieved(new Date());
View Full Code Here


        test.add(NamespaceEnum.rdf+"type", representationType);
    }
   
    @Test
    public void testBNodeSupport() throws YardException, RepositoryException {
        RepositoryConnection con = repo.getConnection();
        org.openrdf.model.ValueFactory sesameFactory = con.getValueFactory();
        URI subject = sesameFactory.createURI("urn:test.sesameyard:bnodesupport.subject");
        URI property = sesameFactory.createURI("urn:test.sesameyard:bnodesupport.property");
        URI value = sesameFactory.createURI("urn:test.sesameyard:bnodesupport.value");
        URI property2 = sesameFactory.createURI("urn:test.sesameyard:bnodesupport.property2");
        URI loop1 = sesameFactory.createURI("urn:test.sesameyard:bnodesupport.loop1");
        URI loop2 = sesameFactory.createURI("urn:test.sesameyard:bnodesupport.loop2");
        BNode bnode1 = sesameFactory.createBNode();
        BNode bnode2 = sesameFactory.createBNode();
        con.add(subject, property, bnode1);
        con.add(bnode1, property2, value);
        con.add(bnode1, loop1, bnode2);
        con.add(bnode2, loop2, bnode1);
        con.commit();
        con.close();
        Yard yard = getYard();
        Representation rep = yard.getRepresentation(subject.stringValue());
        Assert.assertTrue(rep instanceof RdfRepresentation);
        Model model = ((RdfRepresentation)rep).getModel();
        //Assert for the indirect statements to be present in the model
View Full Code Here

        unionYard = new SesameYard(repo, unionYardConfig);
       
        yards = Arrays.asList(yard1,yard2,unionYard);
       
        //add the test data (to the Repository to also test pre-existing data)
        RepositoryConnection con = repo.getConnection();
        con.begin();
        URI entity1 = sesameFactory.createURI("http://www.test.org/entity1");
        con.add(entity1,rdfType,skosConcept,CONTEXT1);
        con.add(entity1,skosPrefLabel,sesameFactory.createLiteral("test context one", EN),CONTEXT1);
        con.add(entity1,skosPrefLabel,sesameFactory.createLiteral("Test Context Eins", DE),CONTEXT1);
        expectedEntities.put(entity1, Arrays.asList(yard1,unionYard));
       
        URI entity2 = sesameFactory.createURI("http://www.test.org/entity2");
        con.add(entity2,rdfType,skosConcept,CONTEXT2);
        con.add(entity2,skosPrefLabel,sesameFactory.createLiteral("test context two", EN),CONTEXT2);
        con.add(entity2,skosPrefLabel,sesameFactory.createLiteral("Test Context Zwei", DE),CONTEXT2);
        expectedEntities.put(entity2, Arrays.asList(yard2,unionYard));
        con.commit();
        con.close();
    }
View Full Code Here

            throw new IllegalArgumentException("The parsed representation id MUST NOT be NULL!");
        }
        if(id.isEmpty()){
            throw new IllegalArgumentException("The parsed representation id MUST NOT be EMTPY!");
        }
        RepositoryConnection con = null;
        try {
            con = repository.getConnection();
            con.begin();
            Representation rep = getRepresentation(con, sesameFactory.createURI(id), true);
            con.commit();
            return rep;
        } catch (RepositoryException e) {
            throw new YardException("Unable to get Representation "+id, e);
        } finally {
            if(con != null){
                try {
                    con.close();
                } catch (RepositoryException ignore) {}
            }
        }
    }
View Full Code Here

            throw new IllegalArgumentException("The parsed id MUST NOT be NULL!");
        }
        if(id.isEmpty()){
            throw new IllegalArgumentException("The parsed id MUST NOT be EMPTY!");
        }
        RepositoryConnection con = null;
        try {
            con = repository.getConnection();
            con.begin();
            boolean state = isRepresentation(con, sesameFactory.createURI(id));
            con.commit();
            return state;
        } catch (RepositoryException e) {
            throw new YardException("Unable to check for Representation "+id, e);
        } finally {
            if(con != null){
                try {
                    con.close();
                } catch (RepositoryException ignore) {}
            }
        }
    }
View Full Code Here

    @Override
    public void remove(String id) throws YardException, IllegalArgumentException {
        if(id == null) {
            throw new IllegalArgumentException("The parsed Representation id MUST NOT be NULL!");
        }
        RepositoryConnection con = null;
        try {
            con = repository.getConnection();
            con.begin();
            remove(con, sesameFactory.createURI(id));
            con.commit();
        } catch (RepositoryException e) {
            throw new YardException("Unable to remove for Representation "+id, e);
        } finally {
            if(con != null){
                try {
                    con.close();
                } catch (RepositoryException ignore) {}
            }
        }
    }
View Full Code Here

    @Override
    public final void remove(Iterable<String> ids) throws IllegalArgumentException, YardException {
        if(ids == null){
            throw new IllegalArgumentException("The parsed Iterable over the IDs to remove MUST NOT be NULL!");
        }
        RepositoryConnection con = null;
        try {
            con = repository.getConnection();
            con.begin();
            for(String id : ids){
                if(id != null){
                    remove(con, sesameFactory.createURI(id));
                }
            }
            con.commit();
        } catch (RepositoryException e) {
            throw new YardException("Unable to remove parsed Representations", e);
        } finally {
            if(con != null){
                try {
                    con.close();
                } catch (RepositoryException ignore) {}
            }
        }
    }
View Full Code Here

            }
        }
    }
    @Override
    public final void removeAll() throws YardException {
        RepositoryConnection con = null;
        try {
            con = repository.getConnection();
            con.begin();
            con.clear(contexts); //removes everything
            con.commit();
        } catch (RepositoryException e) {
            throw new YardException("Unable to remove parsed Representations", e);
        } finally {
            if(con != null){
                try {
                    con.close();
                } catch (RepositoryException ignore) {}
            }
        }
    }
View Full Code Here

            throw new IllegalArgumentException("The parsed Iterable over the Representations to update MUST NOT be NULL!");
        }
        return store(representations,false);
    }
    protected final Iterable<Representation> store(Iterable<Representation> representations,boolean allowCreate) throws IllegalArgumentException, YardException{
        RepositoryConnection con = null;
        try {
            con = repository.getConnection();
            con.begin();
            ArrayList<Representation> added = new ArrayList<Representation>();
            for(Representation representation : representations){
                if(representation != null){
                    Representation stored = store(con, representation,allowCreate,false); //reassign
                    //to check if the store was successful
                    if(stored != null){
                        added.add(stored);
                    } else { //can only be the case if allowCreate==false (update was called)
                        log.warn(String.format("Unable to update Representation %s in Yard %s because it is not present!",
                            representation.getId(),getId()));
                    }
                } //ignore null values in the parsed Iterable!
            }
            con.commit();
            return added;
        } catch (RepositoryException e) {
            throw new YardException("Unable to remove parsed Representations", e);
        } catch (IllegalArgumentException e) {
            try {
                //to avoid Exception logs in case store(..) throws an Exception
                //in the case allowCreate and canNotCreateIsError do not allow
                //the store operation
                con.rollback();
            } catch (RepositoryException ignore) {}
            throw e;
        } finally {
            if(con != null){
                try {
                    con.close();
                } catch (RepositoryException ignore) {}
            }
        }
    }
View Full Code Here

     * @return the representation as added to the yard
     * @throws IllegalArgumentException
     * @throws YardException
     */
    protected final Representation store(Representation representation,boolean allowCreate,boolean canNotCreateIsError) throws IllegalArgumentException, YardException{
        RepositoryConnection con = null;
        try {
            con = repository.getConnection();
            con.begin();
            Representation added = store(con,representation,allowCreate,canNotCreateIsError);
            con.commit();
            return added;
        } catch (RepositoryException e) {
            throw new YardException("Unable to remove parsed Representations", e);
        } catch (IllegalArgumentException e) {
            try {
                //to avoid Exception logs in case store(..) throws an Exception
                //in the case allowCreate and canNotCreateIsError do not allow
                //the store operation
                con.rollback();
            } catch (RepositoryException ignore) {}
            throw e;
        } finally {
            if(con != null){
                try {
                    con.close();
                } catch (RepositoryException ignore) {}
            }
        }
    }       
View Full Code Here

TOP

Related Classes of org.openrdf.repository.RepositoryConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.