public ODatabaseDocumentTx getRawGraph() { return getContext(true).rawGraph; }
protected Iterable<OrientIndex<? extends OrientElement>> getManualIndices() { return getContext(true).manualIndices.values(); }
public Iterable<Index<? extends Element>> getIndices() { final OrientGraphContext context = getContext(true); final List<Index<? extends Element>> list = new ArrayList<Index<? extends Element>>(); for (Index<?> index : context.manualIndices.values()) { list.add(index); } return list; }
public Iterable<Edge> getEdgesOfClass(final String iClassName, final boolean iPolymorphic) { getContext(true); return new OrientElementScanIterable<Edge>(this, iClassName, iPolymorphic); }
public Iterable<Vertex> getVerticesOfClass(final String iClassName, final boolean iPolymorphic) { getContext(true); return new OrientElementScanIterable<Vertex>(this, iClassName, iPolymorphic); }
@SuppressWarnings({ "unchecked", "rawtypes" }) private OrientIndex<?> loadIndex(final OIndex<?> rawIndex) { final OrientIndex<?> index = new OrientIndex(this, rawIndex); // REGISTER THE INDEX getContext(true).manualIndices.put(index.getIndexName(), index); return index; }
@SuppressWarnings("unchecked") public <T extends Element> Index<T> getIndex(final String indexName, final Class<T> indexClass) { final OrientGraphContext context = getContext(true); Index<? extends Element> index = context.manualIndices.get(indexName); if (null == index) { return null; } if (indexClass.isAssignableFrom(index.getIndexClass())) return (Index<T>) index; else throw ExceptionFactory.indexDoesNotSupportClass(indexName, indexClass); }
private void removeContext() { final OrientGraphContext context = getContext(false); if (context != null) { for (Index<? extends Element> idx : context.manualIndices.values()) ((OrientIndex<?>) idx).close(); context.manualIndices.clear(); if (!context.rawGraph.isClosed()) { context.rawGraph.commit(); context.rawGraph.close(); } synchronized (contexts) { contexts.remove(context); } threadContext.set(null); } }
protected void setCurrentGraphInThreadLocal() { if (threadMode == THREAD_MODE.MANUAL) return; final ODatabaseRecord tlDb = ODatabaseRecordThreadLocal.INSTANCE .getIfDefined(); if (threadMode == THREAD_MODE.ALWAYS_AUTOSET || tlDb == null) { final OrientGraphContext ctx = getContext(true); if (ctx != null && (tlDb == null || tlDb != ctx.rawGraph)) // SET IT ODatabaseRecordThreadLocal.INSTANCE.set(getRawGraph()); } } }
@SuppressWarnings({ "unchecked", "rawtypes" }) public <T extends Element> Index<T> createIndex(final String indexName, final Class<T> indexClass, final Parameter... indexParameters) { final OrientGraphContext context = getContext(true); commitAnyActiveTx("create index '" + indexName + "'"); synchronized (contexts) { if (context.manualIndices.containsKey(indexName)) throw ExceptionFactory.indexAlreadyExists(indexName); final OrientIndex<? extends OrientElement> index = new OrientIndex<OrientElement>( this, indexName, indexClass, null); // ADD THE INDEX IN ALL CURRENT CONTEXTS for (OrientGraphContext ctx : contexts) ctx.manualIndices.put(index.getIndexName(), index); // SAVE THE CONFIGURATION INTO THE GLOBAL CONFIG saveIndexConfiguration(); return (Index<T>) index; } }
public Iterable<Vertex> getVertices(final String iKey, Object iValue) { if (iKey.equals("@class")) return getVerticesOfClass(iValue.toString()); final String indexName; final String key; int pos = iKey.indexOf('.'); if (pos > -1) { indexName = iKey; key = iKey.substring(iKey.indexOf('.') + 1); } else { indexName = OrientVertex.CLASS_NAME + "." + iKey; key = iKey; } final OIndex<?> idx = getContext(true).rawGraph.getMetadata() .getIndexManager().getIndex(indexName); if (idx != null) { iValue = convertKey(idx, iValue); Object indexValue = idx.get(iValue); if (indexValue != null && !(indexValue instanceof Iterable<?>)) indexValue = Arrays.asList(indexValue); return new OrientElementIterable<Vertex>(this, (Iterable<?>) indexValue); } // NO INDEX: EXECUTE A QUERY return query().has(key, iValue).vertices(); }
public Iterable<Edge> getEdges(final String iKey, Object iValue) { if (iKey.equals("@class")) return getEdgesOfClass(iValue.toString()); final String indexName; final String key; int pos = iKey.indexOf('.'); if (pos > -1) { indexName = iKey; key = iKey.substring(iKey.indexOf('.') + 1); } else { indexName = OrientEdge.CLASS_NAME + "." + iKey; key = iKey; } final OIndex<?> idx = getContext(true).rawGraph.getMetadata() .getIndexManager().getIndex(indexName); if (idx != null) { iValue = convertKey(idx, iValue); Object indexValue = (Iterable<?>) idx.get(iValue); if (indexValue != null && !(indexValue instanceof Iterable<?>)) indexValue = Arrays.asList(indexValue); return new OrientElementIterable<Edge>(this, (Iterable<?>) indexValue); } // NO INDEX: EXECUTE A QUERY return query().has(key, iValue).edges(); }