Package org.apache.clerezza.rdf.core.access

Examples of org.apache.clerezza.rdf.core.access.LockableMGraph


    MGraph mGraph = new SimpleMGraph();
    RdfList rdfList = new RdfList(TypePrioritizer.typePriorityListUri, mGraph);
    rdfList.add(FOAF.Person);
    rdfList.add(FOAF.Group);
    rdfList.add(FOAF.Agent);
    final LockableMGraph systemGraph = new LockableMGraphWrapperForTesting(mGraph);
    typePrioritizer.bindSystemGraph(systemGraph);
  }
View Full Code Here


    }

    @Override
    public LockableMGraph getEnhancementGraph() {
        final UriRef graphUri = new UriRef(Constants.ENHANCEMENTS_GRAPH_URI);
        LockableMGraph enhancementGraph = null;
        try {
            enhancementGraph = tcManager.getMGraph(graphUri);
        } catch (NoSuchEntityException e) {
            log.error("Enhancement Graph must be exist");
        }
View Full Code Here

            throw new StoreException(msg, e);
        }
    }

    private void removeEnhancements(String id) throws StoreException {
        LockableMGraph enhancementGraph = getEnhancementGraph();
        String enhancementQuery = QueryGenerator.getEnhancementsOfContent(id);
        SelectQuery selectQuery = null;
        try {
            selectQuery = (SelectQuery) QueryParser.getInstance().parse(enhancementQuery);
        } catch (ParseException e) {
            String msg = "Cannot parse the SPARQL while trying to delete the enhancements of the ContentItem";
            log.error(msg, e);
            throw new StoreException(msg, e);
        }

        List<Triple> willBeRemoved = new ArrayList<Triple>();
        Lock l = enhancementGraph.getLock().writeLock();
        l.lock();
        try {
            ResultSet resultSet = tcManager.executeSparqlQuery(selectQuery, enhancementGraph);
            while (resultSet.hasNext()) {
                SolutionMapping mapping = resultSet.next();
                UriRef ref = (UriRef) mapping.get("enhID");
                Iterator<Triple> tripleItr = enhancementGraph.filter(ref, null, null);
                while (tripleItr.hasNext()) {
                    Triple triple = tripleItr.next();
                    willBeRemoved.add(triple);
                }
            }
            enhancementGraph.removeAll(willBeRemoved);
        } finally {
            l.unlock();
        }
    }
View Full Code Here

     */
    protected void save(Object data, String targetGraphID) throws IOException {
        log.debug("Attempt saving in target graph {}", targetGraphID);

        final long startSave = System.currentTimeMillis();
        LockableMGraph mGraph;
        UriRef graphUriRef = new UriRef(targetGraphID);

        // tcManager must be synchronized
        synchronized (tcManager) {
            try {
                // Check whether the graph already exists
                mGraph = tcManager.getMGraph(graphUriRef);
            } catch (NoSuchEntityException e) {
                mGraph = tcManager.createMGraph(graphUriRef);
            }
        }

        // We lock the graph before proceed
        Lock writeLock = mGraph.getLock().writeLock();
        boolean saved = false;
        if (data instanceof Model) {
            MGraph m = JenaToClerezzaConverter.jenaModelToClerezzaMGraph((Model) data);
            writeLock.lock();
            saved = mGraph.addAll(m);
            writeLock.unlock();
        } else if (data instanceof OWLOntology) {
            MGraph m = (MGraph) OWLAPIToClerezzaConverter.owlOntologyToClerezzaMGraph((OWLOntology) data);
            writeLock.lock();
            saved = mGraph.addAll(m);
            writeLock.unlock();
        }
        if (!saved) throw new IOException("Cannot save the result in clerezza!");
        final long endSave = System.currentTimeMillis();
        log.debug("Saved in time: {}ms", (endSave - startSave));
View Full Code Here

     * @param triples
     */
    @PUT
    public void putTriples(@QueryParam("name") UriRef name, TripleCollection triples) {
        AccessController.checkPermission(new WebAccessPermission());
        LockableMGraph mGraph;
        try {
            mGraph = tcManager.getMGraph(name);
        } catch (NoSuchEntityException e) {
            mGraph = tcManager.createMGraph(name);
        }
        Lock writeLock = mGraph.getLock().writeLock();
        writeLock.lock();
        try {
            mGraph.clear();
            mGraph.addAll(triples);
        } finally {
            writeLock.unlock();
        }
    }
View Full Code Here

            mode = "append";
        }
        InputStream is = new ByteArrayInputStream(graph);
        Graph parsedGraph = parser.parse(is, mediaType.toString());
        UriRef graphUri = new UriRef(graphName);
        LockableMGraph mGraph;
        boolean newGraph = false;
        try {
            mGraph = tcManager.getMGraph(graphUri);
        } catch (NoSuchEntityException e) {
            mGraph = tcManager.createMGraph(graphUri);
            newGraph = true;
        }
        Lock writeLock = mGraph.getLock().writeLock();
        writeLock.lock();
        try {
            if (!newGraph && mode.equals("replace")) {
                mGraph.clear();
            }
            mGraph.addAll(parsedGraph);
        } finally {
            writeLock.unlock();
        }
        String redirection = getFirstTextParameterValue(form, "redirection", false);
        if (redirection == null) {
View Full Code Here

     * @param permissionDescriptions
     */
    public void setRequiredReadPermissionStrings(UriRef tripleCollectionUri,
            Collection<String> permissionDescriptions) {
        readPermissionCache.remove(tripleCollectionUri);
        final LockableMGraph permissionMGraph = getOrCreatePermisionGraph();
        Lock l = permissionMGraph.getLock().writeLock();
        l.lock();
        try {
            removeExistingRequiredReadPermissions(tripleCollectionUri, permissionMGraph);
            final NonLiteral permissionList = createList(permissionDescriptions.iterator(), permissionMGraph);
            permissionMGraph.add(new TripleImpl(tripleCollectionUri,
                    readPermissionListProperty, permissionList));
        } finally {
            l.unlock();
        }
    }
View Full Code Here

     * @param permissionDescriptions
     */
    public void setRequiredReadWritePermissionStrings(UriRef tripleCollectionUri,
            Collection<String> permissionDescriptions) {
        readWritePermissionCache.remove(tripleCollectionUri);
        final LockableMGraph permissionMGraph = getOrCreatePermisionGraph();
        Lock l = permissionMGraph.getLock().writeLock();
        l.lock();
        try {
            removeExistingRequiredReadPermissions(tripleCollectionUri, permissionMGraph);
            final NonLiteral permissionList = createList(permissionDescriptions.iterator(), permissionMGraph);
            permissionMGraph.add(new TripleImpl(tripleCollectionUri,
                    readWritePermissionListProperty, permissionList));
        } finally {
            l.unlock();
        }
    }
View Full Code Here

    private Collection<String> getRequiredReadPermissionStrings(final UriRef tripleCollectionUri) {
        return getRequiredPermissionStrings(tripleCollectionUri, readPermissionListProperty);
    }
    private Collection<String> getRequiredPermissionStrings(final UriRef tripleCollectionUri, UriRef property) {
        try {
            final LockableMGraph permissionMGraph = tcManager.getMGraph(permissionGraphName);
            Lock l = permissionMGraph.getLock().readLock();
            l.lock();
            try {
                Triple t = permissionMGraph.filter(tripleCollectionUri, property, null).next();
                NonLiteral list = (NonLiteral) t.getObject();
                LinkedList<String> result = new LinkedList<String>();
                readList(list, permissionMGraph, result);
                return result;
            } catch (NoSuchElementException e) {
View Full Code Here

TOP

Related Classes of org.apache.clerezza.rdf.core.access.LockableMGraph

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.