public static UniGraph open(final Configuration configuration) throws Exception { return new UniGraph(configuration); }
public UniBulkStep(Traversal.Admin traversal, UniGraph graph) { super(traversal); this.maxBulk = graph.configuration().getInt("bulk.max", 100); this.startBulk = graph.configuration().getInt("bulk.start", this.maxBulk); this.multiplier = graph.configuration().getInt("bulk.multiplier", 2); }
public UniGraph(ControllerManager controllerManager, StrategyProvider strategyProvider) throws Exception { init(controllerManager, strategyProvider); }
private void validateProperties() { if (deferred) { DeferredVertexQuery query = new DeferredVertexQuery(Collections.singletonList(this), null, null, null, null); this.graph.getControllerManager().getControllers(DeferredVertexQuery.DeferredVertexController.class).forEach(deferredController -> deferredController.fetchProperties(query)); } }
public UniGraph(Configuration configuration) throws Exception { configuration.setProperty(Graph.GRAPH, UniGraph.class.getName()); this.configuration = configuration; PropertyTypeFactory.init(Arrays.asList(TextType.class.getCanonicalName(), DateType.class.getCanonicalName(), NumberType.class.getCanonicalName(), DoubleType.class.getCanonicalName(), FloatType.class.getCanonicalName(), IntType.class.getCanonicalName(), LongType.class.getCanonicalName())); List<PropertySchema.PropertySchemaBuilder> thirdPartyPropertySchemas = new ArrayList<>(); if(configuration.containsKey("propertySchemas")){ Stream.of(configuration.getStringArray("propertiesSchemas")).map(classString -> { try { return ((PropertySchema.PropertySchemaBuilder) Class.forName(classString).newInstance()); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new IllegalArgumentException("class: " + classString + " not found"); } }).forEach(thirdPartyPropertySchemas::add); } String traversalFilter = configuration.getString("traversalFilter", DefaultTraversalFilter.class.getCanonicalName()); TraversalFilter filter = Class.forName(traversalFilter).asSubclass(TraversalFilter.class).newInstance(); String configurationControllerManagerName = configuration.getString("controllerManager", ConfigurationControllerManager.class.getCanonicalName().toString()); ControllerManager configurationControllerManager = Class.forName(configurationControllerManagerName) .asSubclass(ControllerManager.class) .getConstructor(UniGraph.class, Configuration.class, List.class, TraversalFilter.class) .newInstance(this, configuration,thirdPartyPropertySchemas, filter); StrategyProvider strategyProvider = determineStrategyProvider(configuration); init(configurationControllerManager, strategyProvider); }
private <E extends Element, C extends Comparable> Iterator<E> query(Class<E> returnType, Object[] ids) { PredicatesHolder idPredicate = createIdPredicate(ids, returnType); SearchQuery<E> uniQuery = new SearchQuery<>(returnType, idPredicate, -1, null, null, null, null); return queryControllers.stream().<E>flatMap(controller -> ConversionUtils.asStream(controller.search(uniQuery))).iterator(); }
@Override public Iterator<Vertex> vertices(Object... ids) { return this.query(Vertex.class, ids); }
@Override public void remove() { RemoveQuery<UniElement> removeQuery = new RemoveQuery<>(Arrays.asList(this), null); this.graph.getControllerManager().getControllers(RemoveQuery.RemoveController.class).forEach(controller -> controller.remove(removeQuery)); }
public UniGraphStep(GraphStep<S, E> originalStep, ControllerManager controllerManager) { super(originalStep.getTraversal(), originalStep.getReturnClass(), originalStep.isStartStep(), originalStep.getIds()); originalStep.getLabels().forEach(this::addLabel); this.predicates = UniGraph.createIdPredicate(originalStep.getIds(), originalStep.getReturnClass()); this.stepDescriptor = new StepDescriptor(this); this.controllers = controllerManager.getControllers(SearchQuery.SearchController.class); this.setIteratorSupplier(this::query); limit = -1; this.propertyKeys = new HashSet<>(); }
@Override public Iterator<Edge> edges(Object... ids) { return this.query(Edge.class, ids); }
@Override public void removeProperty(Property property) { List<VertexProperty> props = this.properties.get(property.key()); props.remove(props.indexOf(property)); if (props.size() == 0) this.properties.remove(property.key()); PropertyQuery<UniElement> propertyQuery = new PropertyQuery<>(this, property, PropertyQuery.Action.Remove, null); this.graph.getControllerManager().getControllers(PropertyQuery.PropertyController.class).forEach(controller -> controller.property(propertyQuery)); }
@Override public Edge addEdge(final String label, final Vertex vertex, final Object... keyValues) { if (null == vertex) throw Graph.Exceptions.argumentCanNotBeNull("vertex"); ElementHelper.legalPropertyKeyValueArray(keyValues); ElementHelper.validateLabel(label); Map<String, Object> stringObjectMap = ConversionUtils.asMap(keyValues); stringObjectMap.put(T.label.toString(), label); return graph.getControllerManager().getControllers(AddEdgeQuery.AddEdgeController.class).stream() .map(controller -> controller.addEdge(new AddEdgeQuery(this, vertex, new HashMap<>(stringObjectMap), null))) .filter(e -> e != null) .findFirst().get(); }
@Override public <V> VertexProperty<V> property(String key, V value) { UniVertexProperty vertexProperty = (UniVertexProperty) addPropertyLocal(key, value); PropertyQuery<UniVertex> propertyQuery = new PropertyQuery<UniVertex>(this, vertexProperty, PropertyQuery.Action.Add, null); graph.getControllerManager().getControllers(PropertyQuery.PropertyController.class).forEach(controller -> controller.property(propertyQuery)); return vertexProperty; }
@Override public <V> Property<V> property(String key, V value) { UniProperty<V> vertexProperty = (UniProperty<V>) addPropertyLocal(key, value); PropertyQuery<UniElement> propertyQuery = new PropertyQuery<>(this, vertexProperty, PropertyQuery.Action.Add, null); this.graph.getControllerManager().getControllers(PropertyQuery.PropertyController.class).forEach(controller -> controller.property(propertyQuery)); return vertexProperty; }
@Override public Iterator<Edge> edges(Direction direction, String... edgeLabels) { PredicatesHolder predicatesHolder = (edgeLabels.length == 0) ? PredicatesHolderFactory.empty() : PredicatesHolderFactory.predicate(new HasContainer(T.label.getAccessor(), P.within(edgeLabels))); SearchVertexQuery searchVertexQuery = new SearchVertexQuery(Edge.class, Arrays.asList(this), direction, predicatesHolder, -1, null, null, null, null); return graph.getControllerManager().getControllers(SearchVertexQuery.SearchVertexController.class).stream() .<Iterator<Edge>>map(controller -> controller.search(searchVertexQuery)) .flatMap(ConversionUtils::asStream) .iterator(); }
public void removeProperty(Property property) { getPropertiesMap().remove(property.key()); PropertyQuery<UniElement> propertyQuery = new PropertyQuery<>(this, property, PropertyQuery.Action.Remove, null); this.graph.getControllerManager().getControllers(PropertyQuery.PropertyController.class).forEach(controller -> controller.property(propertyQuery)); }
@Override public void apply(Traversal.Admin<?, ?> traversal) { UniGraph uniGraph = ((UniGraph) traversal.getGraph().get()); TraversalHelper.getStepsOfClass(EdgeOtherVertexStep.class, traversal).forEach(edgeOtherVertexStep -> { UniGraphEdgeOtherVertexStep uniGraphEdgeOtherVertexStep = new UniGraphEdgeOtherVertexStep(traversal, uniGraph, uniGraph.getControllerManager()); edgeOtherVertexStep.getLabels().forEach(uniGraphEdgeOtherVertexStep::addLabel); TraversalHelper.replaceStep(edgeOtherVertexStep, uniGraphEdgeOtherVertexStep, traversal); }); TraversalHelper.getStepsOfClass(EdgeVertexStep.class, traversal).forEach(edgeVertexStep -> { UniGraphEdgeVertexStep uniGraphEdgeVertexStep = new UniGraphEdgeVertexStep(traversal, edgeVertexStep.getDirection(), uniGraph, uniGraph.getControllerManager()); edgeVertexStep.getLabels().forEach(uniGraphEdgeVertexStep::addLabel); TraversalHelper.replaceStep(edgeVertexStep, uniGraphEdgeVertexStep, traversal); }); } }
@Override public void apply(Traversal.Admin<?, ?> traversal) { if(TraversalHelper.onGraphComputer(traversal)) return; Graph graph = traversal.getGraph().get(); if(!(graph instanceof UniGraph)) { return; } UniGraph uniGraph = (UniGraph) graph; TraversalHelper.getStepsOfClass(GraphStep.class, traversal).forEach(graphStep -> { final UniGraphStep<?,?> uniGraphStep = new UniGraphStep<>(graphStep, uniGraph.getControllerManager()); TraversalHelper.replaceStep(graphStep, uniGraphStep, traversal); PredicatesUtil.collectPredicates(uniGraphStep, traversal); }); } }
UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager()); TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, traversal); if (vertexStep.returnsEdge()) PredicatesUtil.collectPredicates(uniGraphVertexStep, traversal); traversalParent.getLocalChildren().forEach(child -> { if(TraversalHelper.stepIndex(vertexStep, child) != -1) { UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager()); TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, child); if (vertexStep.returnsEdge()) PredicatesUtil.collectPredicates(uniGraphVertexStep, child); traversalParent.getGlobalChildren().forEach(child -> { if(TraversalHelper.stepIndex(vertexStep, child) != -1) { UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager()); TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, child); if (vertexStep.returnsEdge()) PredicatesUtil.collectPredicates(uniGraphVertexStep, child); traversalParent.getLocalChildren().forEach(child1 -> { if(TraversalHelper.stepIndex(vertexStep, child1) != -1) { UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager()); TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, child1); if (vertexStep.returnsEdge()) PredicatesUtil.collectPredicates(uniGraphVertexStep, child1); traversalParent.getGlobalChildren().forEach(child1 -> { if(TraversalHelper.stepIndex(vertexStep, child1) != -1) { UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager()); TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, child1); if (vertexStep.returnsEdge()) PredicatesUtil.collectPredicates(uniGraphVertexStep, child1);