Package org.openrdf.model

Examples of org.openrdf.model.Graph


   * @inheritDoc
   */
  public void remove(final Object theObj) {
    assertStateOk(theObj);

    Graph aData = assertContainsAndDescribe(theObj);

    try {
      preRemove(theObj);

      boolean isTopOperation = (mOp == null);
View Full Code Here


   */
  private Graph assertContainsAndDescribe(Object theObj) {
    assertStateOk(theObj);

    try {
      Graph aGraph = DataSourceUtil.describe(getDataSource(), theObj);

      if (aGraph.isEmpty()) {
        throw new IllegalArgumentException("Entity does not exist: " + theObj);
      }

      return aGraph;
    }
View Full Code Here

          // and you can't do a describe for the same reason.

          try {
            String aQuery = getBNodeConstructQuery(mSource, mResource, mProperty);
           
            Graph aGraph = mSource.graphQuery(aQuery);

            Optional<Resource> aPossibleListHead = Graphs.getResource(aGraph, mResource, mProperty);
           
            if (aPossibleListHead.isPresent() && Graphs.isList(aGraph, aPossibleListHead.get())) {
              List<Value> aList;
View Full Code Here

    try {

      OBJECT_M.put(theKeyObj, theObj);

      Graph aGraph = DataSourceUtil.describe(theSource, theObj);

      if (aGraph.size() == 0) {
        return theObj;
      }

      final Resource aTmpRes = EmpireUtil.asResource(aTmpSupportsRdfId);
      Set<URI> aProps = new HashSet<URI>();
     
      Iterator<Statement> sIter = aGraph.match(aTmpRes, null, null);

      while (sIter.hasNext()) {
        Statement aStmt = sIter.next();
        aProps.add(aStmt.getPredicate());
      }
     
     
      final SupportsRdfId aSupportsRdfId = asSupportsRdfId(theObj);
     
      final EmpireGenerated aEmpireGenerated = asEmpireGenerated(theObj);
     
      aEmpireGenerated.setAllTriples(aGraph);   
     
      OBJECT_M.put(theKeyObj, theObj);
      final Resource aRes = EmpireUtil.asResource(aSupportsRdfId);

      addNamespaces(theObj.getClass());

      Map<URI, AccessibleObject> theCachedMap = ACCESSORS_BY_CLASS.get(theObj.getClass());

            if (theCachedMap == null) {
                theCachedMap = cacheAccessibles(theObj.getClass(), aRes);
            }
      Set<URI> aUsedProps = new HashSet<URI>();

      for (URI aProp : aProps) {
        AccessibleObject aAccess = theCachedMap.get(aProp);

        if (aAccess == null && RDF.TYPE.equals(aProp)) {
          // TODO: the following block should be entirely removed (leaving continue only)
          // right now, leaving it until the code review: code review before removing the following block
         
          // my understanding is that the following block was only necessary when having a support for a single-typed objects,
          // which is no longer the case          
         
          // we can skip the rdf:type property.  it's basically assigned in the @RdfsClass annotation on the
          // java class, so we can figure it out later if need be. TODO: of course, if something has multiple types
          // that information is lost, which is not good.

         
          /*
          URI aType = (URI) aGraph.getValue(aRes, aProp);
          if (!TYPE_TO_CLASS.containsKey(aType) ||
            !TYPE_TO_CLASS.get(aType).isAssignableFrom(theObj.getClass())) {

            if (TYPE_TO_CLASS.containsKey(aType) && !TYPE_TO_CLASS.get(aType).getName().equals(theObj.getClass().getName())) {
              // TODO: this might just be an error
              LOGGER.warn("Asserted rdf:type of the individual does not match the rdf:type annotation on the object. " + aType + " " + TYPE_TO_CLASS.get(aType) + " " + theObj.getClass() + " " +TYPE_TO_CLASS.get(aType).isAssignableFrom(theObj.getClass())+ " " +TYPE_TO_CLASS.get(aType).equals(theObj.getClass()) + " " + TYPE_TO_CLASS.get(aType).getName().equals(theObj.getClass().getName()));
            }
            else {
              // if they're not equals() or isAssignableFrom, but have the same name, this is usually
              // means that the class loaders don't match.  so probably not an error, so no warning.
            }
          }
          */

          continue;
        }
        else if (aAccess == null) {
          // this must be data that is not covered by the bean (perhaps accessible by a different view/bean for a differnent type of an individual)         
          continue;
        }

        aUsedProps.add(aProp);
       
        ToObjectFunction aFunc = new ToObjectFunction(theSource, aRes, aAccess, aProp);

        Object aValue = aFunc.apply(GraphUtil.getObjects(aGraph, aRes, aProp));

        boolean aOldAccess = aAccess.isAccessible();

        try {
          setAccessible(aAccess, true);         
          set(aAccess, theObj, aValue);       
        }       
        catch (InvocationTargetException e) {
          // oh crap
          throw new InvalidRdfException(e);
        }
        catch (IllegalAccessException e) {
          // this should not happen since we toggle the accessibility of the field, but we'll re-throw regardless
          throw new InvalidRdfException(e);
        }
        catch (IllegalArgumentException e) {
          // this is "likely" to happen.  we'll get this exception if the rdf does not match the java.  for example
          // if something is specified to be an int in the java class, but it typed as a float (though down conversion
          // in that case might work) the set call will fail.
          // TODO: shouldnt this be an error?

          LOGGER.warn("Probable type mismatch: {} {}", aValue, aAccess);
        }
        catch (RuntimeException e) {
          // TODO: i dont like keying on a RuntimeException here to get the error condition, but since the
          // Function interface does not throw anything, this is the best we can do.  maybe consider a
          // version of the Function interface that has a throws clause, it would make this more clear.

          // this was probably an error converting from a Value to an Object
          throw new InvalidRdfException(e);
        }
        finally {
          setAccessible(aAccess, aOldAccess);
        }
      }
     
      sIter = aGraph.match(aTmpRes, null, null);
      Graph aInstanceTriples = Graphs.newGraph();

      while (sIter.hasNext()) {
        Statement aStmt = sIter.next();
       
        if (aUsedProps.contains(aStmt.getPredicate())) {
          aInstanceTriples.add(aStmt);
        }               
      }
     
      aEmpireGenerated.setInstanceTriples(aInstanceTriples);

View Full Code Here

  public List getResultList() {
    List aList = new ProxyAwareList();

    try {
      if (isConstruct()) {
        Graph aGraph = getSource().graphQuery(query());
        aList.add(aGraph);
      }
      else {
        ResultSet aResults = getSource().selectQuery(query());
View Full Code Here

     * Add this graph to the set of data to be added, to the specified named graph, when this operation is executed
     * @param theGraphURI the named graph the data should be added to
     * @param theGraph the data to add
     */
    public void add(final java.net.URI theGraphURI, final Graph theGraph) {
      Graph aGraph = mAdd.get(theGraphURI);

      if (aGraph == null) {
        aGraph = Graphs.newGraph();
      }

      aGraph.addAll(theGraph);

      mAdd.put(theGraphURI, aGraph);
    }
View Full Code Here

     * Add this graph to the set of data to be removed, from the specified named graph, when this operation is executed
     * @param theGraphURI the named graph the data should be removed from
     * @param theGraph the data to remove
     */
    public void remove(final java.net.URI theGraphURI, final Graph theGraph) {
      Graph aGraph = mRemove.get(theGraphURI);

      if (aGraph == null) {
        aGraph = Graphs.newGraph();
      }

      aGraph.addAll(theGraph);

      mRemove.put(theGraphURI, aGraph);
    }
View Full Code Here

    aObj.setLabel("foo");

    em.merge(aObj);

    Graph aGraph = Graphs.newGraph(aSource.getStatements(null, null, null));

    assertEquals(3, aGraph.size());
    assertEquals(1, Lists.newArrayList(aGraph.match(null, ValueFactoryImpl.getInstance().createURI("urn:label"), null)).size());

    em.remove(aObj);

    ParentEntity pe = InstanceGenerator.generateInstanceClass(ParentEntity.class).newInstance();
    pe.setEntity(aObj);

    em.persist(pe);

    aGraph = Graphs.newGraph(aSource.getStatements(null, null, null));

    assertEquals(5, aGraph.size());
    assertEquals(1, Lists.newArrayList(aGraph.match(null, ValueFactoryImpl.getInstance().createURI("urn:label"), null)).size());

    aObj.setLabel("foobarbaz");

    em.merge(pe);

    aGraph = Graphs.newGraph(aSource.getStatements(null, null, null));

    assertEquals(5, aGraph.size());
    assertEquals(1, Lists.newArrayList(aGraph.match(null, ValueFactoryImpl.getInstance().createURI("urn:label"), null)).size());
  }
View Full Code Here

    aObj.setLabel("foo");

    em.merge(aObj);

    Graph aGraph = Graphs.newGraph(aSource.getStatements(null, null, null));

    assertEquals(3, aGraph.size());
    assertEquals(1, Lists.newArrayList(aGraph.match(null, ValueFactoryImpl.getInstance().createURI("urn:label"), null)).size());

    em.remove(aObj);

    ParentEntity pe = InstanceGenerator.generateInstanceClass(ParentEntity.class).newInstance();
    pe.setEntity(aObj);

    em.persist(pe);

    em.refresh(pe);

    aGraph = Graphs.newGraph(aSource.getStatements(null, null, null));

    assertEquals(5, aGraph.size());
    assertEquals(1, Lists.newArrayList(aGraph.match(null, ValueFactoryImpl.getInstance().createURI("urn:label"), null)).size());

    aObj.setLabel("foobarbaz");

    em.merge(pe);

    aGraph = Graphs.newGraph(aSource.getStatements(null, null, null));

    assertEquals(5, aGraph.size());
    assertEquals(1, Lists.newArrayList(aGraph.match(null, ValueFactoryImpl.getInstance().createURI("urn:label"), null)).size());
  }
View Full Code Here

  @Test
  public void testTimesTwo() throws InvalidRdfException {
    TestDoubleImpl obj = new TestDoubleImpl();

    Graph g = RdfGenerator.asRdf(obj);

    int aResult = GraphUtil.getObjects(g, EmpireUtil.asResource(obj), ValueFactoryImpl.getInstance().createURI(PrefixMapping.GLOBAL.uri("test:foo"))).size();

    assertEquals(1, aResult);
  }
View Full Code Here

TOP

Related Classes of org.openrdf.model.Graph

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.