Ejemplo n.º 1
0
  @Override
  public <T extends Element> Set<String> getIndexedKeys(Class<T> elementClass) {
    autoStartTransaction();

    com.sparsity.dex.gdb.TypeList tlist = null;
    com.sparsity.dex.gdb.Graph rawGraph = getRawGraph();
    if (Vertex.class.isAssignableFrom(elementClass)) {
      tlist = rawGraph.findNodeTypes();
    } else if (Edge.class.isAssignableFrom(elementClass)) {
      tlist = rawGraph.findEdgeTypes();
    } else {
      throw ExceptionFactory.classIsNotIndexable(elementClass);
    }
    Set<String> ret = new HashSet<String>();
    for (Integer type : tlist) {
      com.sparsity.dex.gdb.AttributeList alist = rawGraph.findAttributes(type);
      for (Integer attr : alist) {
        com.sparsity.dex.gdb.Attribute adata = rawGraph.getAttribute(attr);
        if (adata.getKind() == AttributeKind.Indexed || adata.getKind() == AttributeKind.Unique) {
          ret.add(adata.getName());
        }
      }
      alist.delete();
      alist = null;
    }
    tlist.delete();
    tlist = null;
    return ret;
  }
Ejemplo n.º 2
0
  /*
   * (non-Javadoc)
   *
   * @see com.tinkerpop.blueprints.Graph#getEdges()
   */
  @Override
  public CloseableIterable<Edge> getEdges() {
    autoStartTransaction();

    com.sparsity.dex.gdb.Graph rawGraph = getRawGraph();
    com.sparsity.dex.gdb.TypeList tlist = rawGraph.findEdgeTypes();
    List<Iterable<Edge>> edges = new ArrayList<Iterable<Edge>>();
    for (Integer type : tlist) {
      com.sparsity.dex.gdb.Objects objs = rawGraph.select(type);
      edges.add(new DexIterable<Edge>(this, objs, Edge.class));
    }
    tlist.delete();
    tlist = null;
    return new MultiIterable<Edge>(edges);
  }
Ejemplo n.º 3
0
  /**
   * Returns an iterable to all the edges in the graph that have a particular key/value property.
   *
   * <p>In case key is {@link StringFactory#LABEL}, it returns an iterable of all the edges having
   * the given value as the label (therefore, belonging to the given type).
   *
   * <p>In case {@link #label} is null, it will return all edges having a particular key/value no
   * matters the type. In case {@link #label} is not null, it will return all edges having a
   * particular key/value belonging to the given type.
   *
   * @see com.tinkerpop.blueprints.Graph#getEdges(String, Object)
   * @see #label
   */
  @Override
  public CloseableIterable<Edge> getEdges(final String key, final Object value) {
    autoStartTransaction();

    com.sparsity.dex.gdb.Graph rawGraph = getRawGraph();

    if (key.compareTo(StringFactory.LABEL) == 0) { // label is "indexed"

      int type = rawGraph.findType(value.toString());
      if (type != com.sparsity.dex.gdb.Type.InvalidType) {
        com.sparsity.dex.gdb.Type tdata = rawGraph.getType(type);
        if (tdata.getObjectType() == ObjectType.Edge) {
          com.sparsity.dex.gdb.Objects objs = rawGraph.select(type);
          return new DexIterable<Edge>(this, objs, Edge.class);
        }
      }
      return null;
    }

    String label = this.label.get();
    if (label == null) { // all vertex types

      com.sparsity.dex.gdb.TypeList tlist = rawGraph.findEdgeTypes();
      List<Iterable<Edge>> edges = new ArrayList<Iterable<Edge>>();
      for (Integer type : tlist) {
        int attr = rawGraph.findAttribute(type, key);
        if (com.sparsity.dex.gdb.Attribute.InvalidAttribute != attr) {
          com.sparsity.dex.gdb.Attribute adata = rawGraph.getAttribute(attr);
          if (adata.getKind() == AttributeKind.Basic) { // "table" scan
            com.sparsity.dex.gdb.Objects objs = rawGraph.select(type);
            edges.add(
                new PropertyFilteredIterable<Edge>(
                    key, value, new DexIterable<Edge>(this, objs, Edge.class)));
          } else { // use the index
            edges.add(new DexIterable<Edge>(this, this.rawGet(adata, value), Edge.class));
          }
        }
      }
      tlist.delete();
      tlist = null;

      if (edges.size() > 0) return new MultiIterable<Edge>(edges);
      else throw new IllegalArgumentException("The given attribute '" + key + "' does not exist");

    } else { // restricted to a type

      int type = rawGraph.findType(label);
      if (type == com.sparsity.dex.gdb.Type.InvalidType) {
        throw new IllegalArgumentException("Unnexisting edge label: " + label);
      }
      com.sparsity.dex.gdb.Type tdata = rawGraph.getType(type);
      if (tdata.getObjectType() != com.sparsity.dex.gdb.ObjectType.Edge) {
        throw new IllegalArgumentException("Given label is not a edge label: " + label);
      }

      int attr = rawGraph.findAttribute(type, key);
      if (com.sparsity.dex.gdb.Attribute.InvalidAttribute == attr) {
        throw new IllegalArgumentException(
            "The given attribute '"
                + key
                + "' does not exist for the given edge label '"
                + label
                + "'");
      }

      com.sparsity.dex.gdb.Attribute adata = rawGraph.getAttribute(attr);
      if (adata.getKind() == AttributeKind.Basic) { // "table" scan
        com.sparsity.dex.gdb.Objects objs = rawGraph.select(type);
        return new PropertyFilteredIterable<Edge>(
            key, value, new DexIterable<Edge>(this, objs, Edge.class));
      } else { // use the index
        return new DexIterable<Edge>(this, this.rawGet(adata, value), Edge.class);
      }
    }
  }