com.tinkerpop.blueprints.Element Java Examples
The following examples show how to use
com.tinkerpop.blueprints.Element.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ElementTableWrapper.java From AccumuloGraph with Apache License 2.0 | 6 votes |
/** * Read the given property from the backing table * for the given element id. * @param id * @param key * @return */ public <V> V readProperty(Element element, String key) { Scanner s = getScanner(); s.setRange(new Range(element.getId().toString())); Text colf = StringFactory.LABEL.equals(key) ? new Text(Constants.LABEL) : new Text(key); s.fetchColumnFamily(colf); V value = null; Iterator<Entry<Key, Value>> iter = s.iterator(); if (iter.hasNext()) { value = AccumuloByteSerializer.deserialize(iter.next().getValue().get()); } s.close(); return value; }
Example #2
Source File: BaseIndexValuesTableWrapper.java From AccumuloGraph with Apache License 2.0 | 6 votes |
/** * Add the property to this index. * * <p/>Note that this requires a round-trip to Accumulo to see * if the property exists if the provided key has an index. * So for best performance, create indices after bulk ingest. * <p/>If the force parameter is true, set the property regardless * of whether indexing is enabled for the given key. This is needed * for {@link IndexableGraph} operations. * @param element * @param key * @param value * @param force */ public void setPropertyForIndex(Element element, String key, Object value, boolean force) { AccumuloGraphUtils.validateProperty(key, value); if (force || globals.getConfig().getAutoIndex() || globals.getIndexMetadataWrapper() .getIndexedKeys(elementType).contains(key)) { BatchWriter writer = getWriter(); Object oldValue = element.getProperty(key); if (oldValue != null && !oldValue.equals(value)) { Mutators.apply(writer, new IndexValueMutator.Delete(element, key, oldValue)); } Mutators.apply(writer, new IndexValueMutator.Add(element, key, value)); globals.checkedFlush(); } }
Example #3
Source File: HasElementIds.java From antiquity with GNU General Public License v3.0 | 6 votes |
@Override protected boolean matchesSafely(T t) { for (Element e : t) { if (id == ID.ID) { ids.add(e.getId()); } else { if (!(e instanceof HistoricVersionedElement)) { throw new IllegalStateException("HARD_ID must be used with historic elements only"); } else { HistoricVersionedElement he = (HistoricVersionedElement)e; ids.add(((HistoricVersionedElement) e).getHardId()); } } } if (type == TYPE.CONTAINS) { return ids.containsAll(expected); } else if (type == TYPE.EXACTLY_MATCHES) { return (ids.containsAll(expected) && expected.containsAll(ids)); } throw new IllegalStateException(("comparison type is unsupported.")); }
Example #4
Source File: DConfiguration.java From org.openntf.domino with Apache License 2.0 | 6 votes |
public Class<?> getType(final Class<?> typeHoldingTypeField, final String typeValue, final Element elem) { Class<?> result = null; DGraph graph = config_.getGraph(); DElementStore store = graph.findElementStore(elem); TypeRegistry reg = storeTypeMap_.get(store); // System.out.println("TEMP DEBUG Attempting to resolve type name " + typeValue + " with an element"); if (reg == null) { result = getType(typeHoldingTypeField, typeValue); } else { result = reg.getType(typeHoldingTypeField, typeValue); // System.out.println("TEMP DEBUG Used local element store for " + typeHoldingTypeField.getName() + " value " + typeValue // + " in registry " + System.identityHashCode(reg) + " resulting in type " // + (result == null ? "null" : result.getName())); } if (result == null) { result = findClassByName(typeValue); } // System.out.println("TEMP DEBUG Returning type " + result.getName()); return result; }
Example #5
Source File: DFramedTransactionalGraph.java From org.openntf.domino with Apache License 2.0 | 6 votes |
public <F> Iterable<F> getElements(final String classname) { org.openntf.domino.graph2.DElementStore store = null; DGraph base = (DGraph) this.getBaseGraph(); Class<?> chkClass = getClassFromName(classname); if (chkClass != null) { store = base.findElementStore(chkClass); if (store != null) { String formulaFilter = org.openntf.domino.graph2.DGraph.Utils.getFramedElementFormula(chkClass); Iterable<Element> elements = (org.openntf.domino.graph2.impl.DElementIterable) store.getElements(formulaFilter); if (elements instanceof List) { // int size = ((List) elements).size(); // System.out.println("TEMP DEBUG Found a list of size " + size + " for kind " + classname); } return this.frameElements(elements, (Class<F>) chkClass); } else { // System.out.println("TEMP DEBUG Unable to find an element store for type " + classname); return null; } } else { throw new IllegalArgumentException("Class " + classname + " not registered in graph"); } }
Example #6
Source File: IndexMetadataTableWrapper.java From AccumuloGraph with Apache License 2.0 | 6 votes |
public <T extends Element> Set<String> getIndexedKeys(Class<T> elementClass) { if (elementClass == null) { throw ExceptionFactory.classForElementCannotBeNull(); } IndexedItemsListParser parser = new IndexedItemsListParser(elementClass); Scanner scan = null; try { scan = getScanner(); scan.fetchColumnFamily(new Text(IndexMetadataEntryType.__INDEX_KEY__.name())); Set<String> keys = new HashSet<String>(); for (IndexedItem item : parser.parse(scan)) { keys.add(item.getKey()); } return keys; } finally { if (scan != null) { scan.close(); } } }
Example #7
Source File: AbstractPropertyHandler.java From org.openntf.domino with Apache License 2.0 | 6 votes |
private Object processFormula(final Formula formula, final Element element) { Object result = null; if (element instanceof DElement) { Map<String, Object> rawDoc = ((DElement) element).getDelegate(); if (rawDoc instanceof Document) { result = formula.getValue((Document) rawDoc); if (result instanceof Vector) { Vector<Object> v = (Vector) result; if (v.size() == 1) { result = v.get(0); } } } } return result; }
Example #8
Source File: DFramedTransactionalGraph.java From org.openntf.domino with Apache License 2.0 | 6 votes |
public <F> F frame(final Element element, final Class<F> kind) { // Class<F> klazz = kind; // DConfiguration config = (DConfiguration) this.getConfig(); // config.getTypeManager().initElement(klazz, this, element); // for (FrameInitializer initializer : getConfig().getFrameInitializers()) { // if (!(initializer instanceof JavaFrameInitializer)) { // initializer.initElement(klazz, this, element); // } // } F result = null; if (element instanceof Edge) { result = frame((Edge) element, kind); } else if (element instanceof Vertex) { result = frame((Vertex) element, kind); } else { throw new IllegalStateException("Cannot frame an element of type " + element.getClass().getName()); } // for (FrameInitializer initializer : getConfig().getFrameInitializers()) { // if (initializer instanceof JavaFrameInitializer) { // ((JavaFrameInitializer) initializer).initElement(klazz, this, result); // } // } return result; }
Example #9
Source File: DFramedTransactionalGraph.java From org.openntf.domino with Apache License 2.0 | 6 votes |
public <F> Iterable<F> getFilteredElements(final String classname, final List<CharSequence> keys, final List<CaseInsensitiveString> values) { // System.out.println("Getting a filtered list of elements of type " + classname); org.openntf.domino.graph2.DElementStore store = null; DGraph base = (DGraph) this.getBaseGraph(); Class<?> chkClass = getClassFromName(classname); if (chkClass != null) { store = base.findElementStore(chkClass); if (store != null) { List<String> keystrs = CaseInsensitiveString.toStrings(keys); List<Object> valobj = new ArrayList<Object>(values); String formulaFilter = org.openntf.domino.graph2.DGraph.Utils.getFramedElementFormula(keystrs, valobj, chkClass); long startTime = new Date().getTime(); Iterable<Element> elements = (org.openntf.domino.graph2.impl.DElementIterable) store.getElements(formulaFilter); long endTime = new Date().getTime(); System.out .println("TEMP DEBUG Retrieved elements for type " + classname + " in " + (endTime - startTime) + "ms. Framing..."); return this.frameElements(elements, null); } else { return null; } } else { throw new IllegalArgumentException("Class " + classname + " not registered in graph"); } }
Example #10
Source File: DominoElement.java From org.openntf.domino with Apache License 2.0 | 6 votes |
public static Object getReflectiveProperty(final IDominoElement element, final String prop) { if (prop == null || prop.isEmpty()) throw new IllegalArgumentException("Cannot set a null or empty property on a DominoElement"); Object result = false; Class<? extends Element> elemClass = element.getClass(); Method getter = BeanUtils.findGetter(elemClass, prop); if (getter != null) { try { result = getter.invoke(element, (Object[]) null); } catch (Exception e) { DominoUtils.handleException(e); System.out.println("Unable to invoke " + getter.getName() + " on a " + element.getClass() + " for property: " + prop); } } else { IDominoProperties domProp = IDominoProperties.Reflect.findMappedProperty(elemClass, prop); if (domProp != null) { result = element.getProperty(domProp); } else { result = element.getProperty(prop); } } return result; }
Example #11
Source File: MapReduceElement.java From AccumuloGraph with Apache License 2.0 | 6 votes |
public boolean equals(Object object) { if (object == this) { return true; } else if (object == null) { return false; } else if (!object.getClass().equals(getClass())) { return false; } else { Element element = (Element) object; if (id == null) { return element.getId() == null; } else { return id.equals(element.getId()); } } }
Example #12
Source File: KeyIndexableGraphHelper.java From org.openntf.domino with Apache License 2.0 | 6 votes |
/** * For those graphs that do no support automatic reindexing of elements when a key is provided for indexing, this method can be used to simulate that behavior. * The elements in the graph are iterated and their properties (for the provided keys) are removed and then added. * Be sure that the key indices have been created prior to calling this method so that they can pick up the property mutations calls. * Finally, if the graph is a TransactionalGraph, then a 1000 mutation buffer is used for each commit. * * @param graph the graph containing the provided elements * @param elements the elements to index into the key indices * @param keys the keys of the key indices * @return the number of element properties that were indexed */ public static long reIndexElements(final Graph graph, final Iterable<? extends Element> elements, final Set<String> keys) { final boolean isTransactional = graph instanceof TransactionalGraph; long counter = 0; for (final Element element : elements) { for (final String key : keys) { final Object value = element.removeProperty(key); if (null != value) { counter++; element.setProperty(key, value); if (isTransactional && (counter % 1000 == 0)) { ((TransactionalGraph) graph).commit(); } } } } if (isTransactional) { ((TransactionalGraph) graph).commit(); } return counter; }
Example #13
Source File: ElementCacheTest.java From AccumuloGraph with Apache License 2.0 | 5 votes |
@Test public void testElementCacheTimeout() throws Exception { AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils .generateGraphConfig("elementCacheTimeout"); Graph graph = GraphFactory.open(cfg.getConfiguration()); ElementCache<Element> cache = new ElementCache<Element>(10, 1000); Vertex v1 = graph.addVertex(1); Vertex v2 = graph.addVertex(2); assertNull(cache.retrieve(1)); assertNull(cache.retrieve(2)); cache.cache(v1); assertNotNull(cache.retrieve(v1.getId())); Thread.sleep(1500); assertNull(cache.retrieve(v1.getId())); Edge e = graph.addEdge(null, v1, v2, "label"); assertNull(cache.retrieve(e.getId())); cache.cache(e); assertNotNull(cache.retrieve(e.getId())); Thread.sleep(1500); assertNull(cache.retrieve(e.getId())); graph.shutdown(); }
Example #14
Source File: ElementHelper.java From org.openntf.domino with Apache License 2.0 | 5 votes |
/** * Clear all the properties from an iterable of elements. * * @param elements the elements to remove properties from */ public static void removeProperties(final Iterable<Element> elements) { for (final Element element : elements) { final List<String> keys = new ArrayList<String>(); keys.addAll(element.getPropertyKeys()); for (final String key : keys) { element.removeProperty(key); } } }
Example #15
Source File: AutoIndexTest.java From AccumuloGraph with Apache License 2.0 | 5 votes |
@Test public void testVertexAutoIndex() throws Exception { AccumuloGraph graph = (AccumuloGraph) GraphFactory.open(AccumuloGraphTestUtils .generateGraphConfig("VertexAutoIndexTest").setAutoIndex(true).getConfiguration()); String id = "1234"; String key = "name"; String value = "bananaman"; Vertex v1 = graph.addVertex(id); v1.setProperty(key, value); Iterable<Element> elements = graph.getGlobals() .getVertexKeyIndexWrapper().readElementsFromIndex(key, value); int count = 0; for (Element element : elements) { assertTrue(element instanceof Vertex); assertEquals(id, element.getId()); assertEquals(value, element.getProperty(key)); count++; } assertEquals(1, count); graph.removeVertex(v1); elements = graph.getGlobals() .getVertexKeyIndexWrapper().readElementsFromIndex(key, value); assertEquals(0, count(elements)); }
Example #16
Source File: ElementUtils.java From antiquity with GNU General Public License v3.0 | 5 votes |
/** * Returns {@link Element}'s properties as an immutable map. * * @return An immutable map of the specified {@link Element} properties * exlcuding the specified keys */ public static Map<String, Object> getPropertiesAsMap(Element element, Set<String> excludedKeys) { Builder<String, Object> props = ImmutableMap.builder(); for (String key : element.getPropertyKeys()) { if ((excludedKeys != null) && excludedKeys.contains(key)) { continue; } props.put(key, element.getProperty(key)); } return props.build(); }
Example #17
Source File: DFramedTransactionalGraph.java From org.openntf.domino with Apache License 2.0 | 5 votes |
@Override public Object call() throws Exception { Object result = null; DGraph base = (DGraph) parent_.getBaseGraph(); org.openntf.domino.graph2.DElementStore store = null; if (id_ instanceof NoteCoordinate) { store = base.findElementStore(id_); } else { // System.out.println("Resolving an id of type " + (id_ == null ? "null" : id_.getClass().getName())); String typeid = parent_.getTypedId(id_); if (typeid == null) { store = base.findElementStore(kind_); } else { store = base.findElementStore(typeid); } } Element elem = store.getElement(id_); if (null == elem) { result = null; } else if (elem instanceof Edge) { result = parent_.frame((Edge) elem, kind_); } else if (elem instanceof Vertex) { result = parent_.frame((Vertex) elem, kind_); } else { throw new IllegalStateException("Key " + String.valueOf(id_) + " returned an element of type " + elem.getClass().getName()); } return result; }
Example #18
Source File: IdFilterPipe.java From org.openntf.domino with Apache License 2.0 | 5 votes |
protected Element processNextStart() { while (true) { final Element s = this.starts.next(); if (this.predicate.evaluate(s.getId(), this.id)) return s; } }
Example #19
Source File: DominoGraph.java From org.openntf.domino with Apache License 2.0 | 5 votes |
public static SortedSet<? extends Element> sortElements(final Iterable<? extends Element> elements, final String[] sortproperties) { // StringBuilder sb = new StringBuilder(); // for (String prop : sortproperties) { // sb.append(prop + ", "); // } // System.out.println("Sorting elements from String properties: " + sb.toString()); Comparator<Element> comp = new ElementComparator(sortproperties); SortedSet<Element> result = new TreeSet<Element>(comp); for (Object e : elements) { if (e instanceof Element) { result.add((Element) e); } } return Collections.unmodifiableSortedSet(result); }
Example #20
Source File: IdGraph.java From org.openntf.domino with Apache License 2.0 | 5 votes |
public <T extends Element> Index<T> createIndex(final String indexName, final Class<T> indexClass, final Parameter... indexParameters) { verifyBaseGraphIsIndexableGraph(); return isVertexClass(indexClass) ? (Index<T>) new IdVertexIndex((Index<Vertex>) ((IndexableGraph) baseGraph).createIndex(indexName, indexClass, indexParameters), this) : (Index<T>) new IdEdgeIndex((Index<Edge>) ((IndexableGraph) baseGraph).createIndex(indexName, indexClass, indexParameters), this); }
Example #21
Source File: AdjacencyHandler.java From org.openntf.domino with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") @Override public Object processElement(final Adjacency annotation, final Method method, final Object[] arguments, final FramedGraph framedGraph, final Element element, final Direction direction) { if (element instanceof Vertex) { return processVertexAdjacency(annotation, method, arguments, framedGraph, (Vertex) element); } else { throw new UnsupportedOperationException(); } }
Example #22
Source File: DElementIterable.java From org.openntf.domino with Apache License 2.0 | 5 votes |
@Override public Element next() { Element result = null; NoteCoordinate nc = getIterator().next(); if (nc != null) { result = elementStore_.getElement(nc); } return result; }
Example #23
Source File: ElementHelper.java From org.openntf.domino with Apache License 2.0 | 5 votes |
/** * Determines whether the property key/value for the specified element can be legally set. * This is typically used as a pre-condition check prior to setting a property. * * @param element the element for the property to be set * @param key the key of the property * @param value the value of the property * @throws IllegalArgumentException whether the triple is legal and if not, a clear reason message is provided */ public static final void validateProperty(final Element element, final String key, final Object value) throws IllegalArgumentException { if (null == value) throw ExceptionFactory.propertyValueCanNotBeNull(); if (null == key) throw ExceptionFactory.propertyKeyCanNotBeNull(); if (key.equals(StringFactory.ID)) throw ExceptionFactory.propertyKeyIdIsReserved(); if (element instanceof Edge && key.equals(StringFactory.LABEL)) throw ExceptionFactory.propertyKeyLabelIsReservedForEdges(); if (key.isEmpty()) throw ExceptionFactory.propertyKeyCanNotBeEmpty(); }
Example #24
Source File: AdjacencyUniqueHandler.java From org.openntf.domino with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") @Override public Object processElement(final AdjacencyUnique annotation, final Method method, final Object[] arguments, final FramedGraph framedGraph, final Element element, final Direction direction) { if (element instanceof Vertex) { return processVertexAdjacency(annotation, method, arguments, framedGraph, (Vertex) element); } else { throw new UnsupportedOperationException(); } }
Example #25
Source File: DElementIterable.java From org.openntf.domino with Apache License 2.0 | 5 votes |
@Override public int lastIndexOf(final Object o) { if (o instanceof Element) { Object rawid = ((Element) o).getId(); if (rawid instanceof NoteCoordinate) { return index_.lastIndexOf(rawid); } } return 0; }
Example #26
Source File: ElementHelper.java From org.openntf.domino with Apache License 2.0 | 5 votes |
/** * Set the properties of the provided element using the provided key value pairs. * The var args of Objects must be divisible by 2. All odd elements in the array must be a String key. * * @param element the element to set the properties of * @param keysValues the key value pairs of the properties */ public static void setProperties(final Element element, final Object... keysValues) { if (keysValues.length % 2 != 0) throw new IllegalArgumentException("The object var args must be divisible by 2"); for (int i = 0; i < keysValues.length; i = i + 2) { element.setProperty((String) keysValues[i], keysValues[i + 1]); } }
Example #27
Source File: DElementIterable.java From org.openntf.domino with Apache License 2.0 | 5 votes |
@Override public Element previous() { Element result = null; NoteCoordinate nc = getIterator().previous(); if (nc != null) { result = elementStore_.getElement(nc); } return result; }
Example #28
Source File: IDominoProperties.java From org.openntf.domino with Apache License 2.0 | 5 votes |
public static IDominoProperties findMappedProperty(final Class<? extends Element> cls, final String prop) { IDominoProperties result = null; for (IDominoProperties curProp : getMappedProperties(cls)) { if (curProp.getName().equalsIgnoreCase(prop)) { result = curProp; break; } } return result; }
Example #29
Source File: ElementUtils.java From antiquity with GNU General Public License v3.0 | 5 votes |
/** * Get a single element. * * @param it iterable of elements. * @param <E> must be of {@link Element} type. * @return single element. * @throws IllegalStateException if multiple elements found. */ @SuppressWarnings("unchecked") public static <E extends Element> E getSingleElement(Iterable<E> it) { Iterator<?> iter = it.iterator(); E e = null; if (iter.hasNext()) { e = (E) iter.next(); } if (iter.hasNext()) throw new IllegalStateException(String.format("Multiple elements found.")); return e; }
Example #30
Source File: DominoGraph.java From org.openntf.domino with Apache License 2.0 | 5 votes |
public void startTransaction(final Element elem) { putCache(elem); if (getTxn() == null) { getRawDatabase().startTransaction(); // setTxn(getRawDatabase().startTransaction()); } }