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

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


  }

 

  private boolean nodeAtUriExists(UriRef nodeUri) {
    LockableMGraph mGraph = (LockableMGraph) getMGraph();
    Lock readLock = mGraph.getLock().readLock();
    readLock.lock();
    try {
      return mGraph.filter(nodeUri, null, null).hasNext()
          || mGraph.filter(null, null, nodeUri).hasNext();
    } finally {
      readLock.unlock();
    }
  }
View Full Code Here


    byte[] content = formFile.getContent();
    if (content == null || uri == null) {
      return Response.status(400).entity("Required form field is missing").
          type(MediaType.TEXT_PLAIN_TYPE).build();
    }
    LockableMGraph contentGraph = cgProvider.getContentGraph();
    Lock readLock = contentGraph.getLock().readLock();
    readLock.lock();
    try {
      if (contentGraph.filter(new UriRef(uri), RDF.type, null).hasNext()) {
        return Response.status(Response.Status.CONFLICT).
            entity("A resource with the specified URI already exists").
            type(MediaType.TEXT_PLAIN_TYPE).build();
      }
    } finally {
View Full Code Here

  @Override
  public void put(UriRef infoDiscoBitUri, MediaType mediaType,
      byte[] data) {

    GraphNode infoDiscoBitNode;
    final LockableMGraph mGraph = (LockableMGraph) getMGraph();
    infoDiscoBitNode = new GraphNode(infoDiscoBitUri, mGraph);
    CollectionCreator collectionCreator = new CollectionCreator(mGraph);
    collectionCreator.createContainingCollections(infoDiscoBitUri);
    Lock writeLock = mGraph.getLock().writeLock();
    writeLock.lock();
    try {
      infoDiscoBitNode.addProperty(RDF.type, DISCOBITS.InfoDiscoBit);
      TypedLiteral dataLiteral = LiteralFactory.getInstance().createTypedLiteral(data);
      infoDiscoBitNode.deleteProperties(DISCOBITS.infoBit);
View Full Code Here

    try {
      otimizationIndicator.createNewFile();
    } catch (IOException ex) {
      throw new RuntimeException(ex);
    }
    LockableMGraph result = new LockableMGraphWrapper(getMGraph(tcDir));
    mGraphMap.put(name, result);
    return result;
  }
View Full Code Here

   * @return true if field could be added
   */
  public boolean addSingleCustomField(UriRef dependency,
    String dependencyValue, String label, String description, String config,
      UriRef property, int length, int cardinality) {
    LockableMGraph contentGraph = cgProvider.getContentGraph();

    NonLiteral customfield = addBasicCustomField(contentGraph,
      property, cardinality, label, description, config, getCustomPropertyCollection(
        dependency, dependencyValue));
    Lock lock = contentGraph.getLock().writeLock();
    lock.lock();
    try {
      if(customfield != null){
        contentGraph.add(new TripleImpl( customfield , CUSTOMPROPERTY.length,
          LiteralFactory.getInstance().createTypedLiteral(length)));
        return true;
      } else {
        return false;
      }
View Full Code Here

   * @return true if field could be added
   */
  public boolean addMultipleCustomField(UriRef dependency,
      String dependencyValue, String label, String description, String config, UriRef property,
      String multiselect, String selectableValues, int cardinality) {
    LockableMGraph contentGraph = cgProvider.getContentGraph();

    NonLiteral customfield = addBasicCustomField(contentGraph, property,
      cardinality, label, description, config, getCustomPropertyCollection(dependency,
        dependencyValue));
    Lock lock = contentGraph.getLock().writeLock();
    lock.lock();
    try {
      if(customfield != null){
        Collection<Triple> tripleArray = new ArrayList<Triple>();
        String[] values = selectableValues.split(",");
        for (int i = 0; i < values.length; i++) {
          tripleArray
              .add(new TripleImpl(customfield, CUSTOMPROPERTY.value,
                  LiteralFactory.getInstance().createTypedLiteral(
                      values[i])));
        }
        tripleArray.add(new TripleImpl(customfield,
            CUSTOMPROPERTY.multiselectable, LiteralFactory.getInstance()
                .createTypedLiteral(multiselect)));
        contentGraph.addAll(tripleArray);
        return true;
      } else {
        return false;
      }
    } finally {
View Full Code Here

   *
   * @return the resource of the found collection
   */
  public NonLiteral getCustomPropertyCollection(UriRef dependency,
      String dependencyValue) {
    LockableMGraph contentGraph = cgProvider.getContentGraph();
    Lock lock = contentGraph.getLock().readLock();
    lock.lock();
    try {
      Iterator<Triple> collections = contentGraph.filter(null, RDF.type,
          CUSTOMPROPERTY.CustomFieldCollection);
      while (collections.hasNext()) {
        Iterator<Triple> collections2 = contentGraph
            .filter(collections.next().getSubject(),
                CUSTOMPROPERTY.dependency, dependency);
        while (collections2.hasNext()) {
          Iterator<Triple> collections3 = contentGraph.filter(
              collections2.next().getSubject(),
              CUSTOMPROPERTY.dependencyvalue, LiteralFactory
                  .getInstance().createTypedLiteral(
                      dependencyValue));
          if (collections3.hasNext()) {
            return collections3.next().getSubject();
          }
        }
      }
    } finally {
      lock.unlock();
    }
    lock = contentGraph.getLock().writeLock();
    lock.lock();
    try {
      Collection<Triple> tripleArray = new ArrayList<Triple>();
      NonLiteral cfc = new BNode();
      tripleArray.add(new TripleImpl(cfc, RDF.type,
          CUSTOMPROPERTY.CustomFieldCollection));
      tripleArray.add(new TripleImpl(cfc, CUSTOMPROPERTY.dependency,
          dependency));
      tripleArray.add(new TripleImpl(cfc, CUSTOMPROPERTY.dependencyvalue,
          LiteralFactory.getInstance()
              .createTypedLiteral(dependencyValue)));
      contentGraph.addAll(tripleArray);
      return getCustomPropertyCollection(dependency, dependencyValue);
    } finally {
      lock.unlock();
    }
  }
View Full Code Here

   * @param collection
   * @return all customfields of the collection
   */
  public ArrayList<NonLiteral>getCustomfieldsOfCollection(NonLiteral collection){
    ArrayList<NonLiteral> customfields = new ArrayList<NonLiteral>();
    LockableMGraph contentGraph = cgProvider.getContentGraph();
    Lock lock = contentGraph.getLock().readLock();
    lock.lock();
    try {
      Iterator <Triple> result= contentGraph.filter(collection, CUSTOMPROPERTY.customfield, null);
      while(result.hasNext()){
        customfields.add((NonLiteral) result.next().getObject());
      }
      return customfields;
    } finally {
View Full Code Here

   * @param collection
   * @return all properties of the collection
   */
  public ArrayList<UriRef>getPropertiesOfCollection(NonLiteral collection){
    ArrayList<UriRef> customproperties = new ArrayList<UriRef>();
    LockableMGraph contentGraph = cgProvider.getContentGraph();
    Lock lock = contentGraph.getLock().readLock();
    lock.lock();
    try {
      Iterator <Triple> result= contentGraph.filter(collection, CUSTOMPROPERTY.customfield, null);
      while(result.hasNext()){
        Iterator <Triple> property= contentGraph.filter(
            (NonLiteral)result.next().getObject(), CUSTOMPROPERTY.property, null);
        if(property.hasNext()){
          customproperties.add((UriRef)property.next().getObject());
        }
      }
View Full Code Here

   *
   * @return  returns whether the customfield could be deleted or not
   */
  public boolean deleteCustomField(UriRef dependency, String dependencyValue,
      UriRef property) {
    LockableMGraph contentGraph = cgProvider.getContentGraph();
    Collection<Triple> allCustomFieldTriples = new ArrayList<Triple>();
    Iterator<Triple> customfields = contentGraph.filter(
        getCustomPropertyCollection(dependency, dependencyValue),
        CUSTOMPROPERTY.customfield, null);
    boolean customFieldDelete = false;
    Lock lock = contentGraph.getLock().writeLock();
    lock.lock();
    try {
      while (customfields.hasNext()) {
        Iterator<Triple> customfields2 = contentGraph.filter(
            (NonLiteral) customfields.next().getObject(),
            CUSTOMPROPERTY.property, property);
        if (customfields2.hasNext()) {
          NonLiteral customField = customfields2.next().getSubject();
          Iterator<Triple> someCustomfieldTriples = contentGraph.filter(
              customField, null, null);
          while (someCustomfieldTriples.hasNext()) {
            allCustomFieldTriples.add(someCustomfieldTriples.next());
          }
          Iterator<Triple> otherCustomFieldTriples = contentGraph.filter(
              null, null, customField);
          while (otherCustomFieldTriples.hasNext()) {
            allCustomFieldTriples.add(otherCustomFieldTriples.next());
          }
          customFieldDelete =  true;
        }
      }
      contentGraph.removeAll(allCustomFieldTriples);
    } finally {
      lock.unlock();
    }   
    return customFieldDelete;

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.