本文整理汇总了Java中org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal.hasNext方法的典型用法代码示例。如果您正苦于以下问题:Java GraphTraversal.hasNext方法的具体用法?Java GraphTraversal.hasNext怎么用?Java GraphTraversal.hasNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal
的用法示例。
在下文中一共展示了GraphTraversal.hasNext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEntity
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入方法依赖的package包/类
/**
* Returns the entity with attributes only on the requested vertex. No parent attributes are included.
*/
public E getEntity(final ZoneEntity zone, final String identifier) {
try {
GraphTraversal<Vertex, Vertex> traversal = this.graphTraversal.V().has(ZONE_ID_KEY, zone.getName())
.has(getEntityIdKey(), identifier);
if (!traversal.hasNext()) {
return null;
}
Vertex vertex = traversal.next();
E entity = vertexToEntity(vertex);
// There should be only one entity with a given entity id.
Assert.isTrue(!traversal.hasNext(),
String.format("There are two entities with the same %s.", getEntityIdKey()));
return entity;
} finally {
this.graphTraversal.tx().commit();
}
}
示例2: printTimeline
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入方法依赖的package包/类
public void printTimeline(GraphTraversal<Vertex, Map<String, Map<String, Object>>> traversal) {
int count = 0;
resetTimer();
while (traversal.hasNext()) {
Map<String, Map<String, Object>> item = traversal.next();
Vertex user = (Vertex) item.get(userVertex);
Edge posts = (Edge) item.get(postsEdge);
Vertex statusUpdate = (Vertex) item.get(statusUpdateVertex);
LOGGER.info(
" {}: @{} {}: {}",
count++,
user.value(USER_NAME),
formatTimestamp(posts.value(CREATED_AT)),
statusUpdate.value(CONTENT)
);
}
LOGGER.info("Printed {} element(s) in {}ms", count, duration());
}
示例3: propertyUnique
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入方法依赖的package包/类
/**
* Sets the value of a property with the added restriction that no other vertex can have that property.
*
* @param key The key of the unique property to mutate
* @param value The new value of the unique property
*/
public void propertyUnique(P key, String value){
if(!tx().isBatchTx()) {
GraphTraversal<Vertex, Vertex> traversal = tx().getTinkerTraversal().V().has(key.name(), value);
if(traversal.hasNext()){
Vertex vertex = traversal.next();
if(!vertex.equals(element()) || traversal.hasNext()){
if(traversal.hasNext()) vertex = traversal.next();
throw PropertyNotUniqueException.cannotChangeProperty(element(), vertex, key, value);
}
}
}
property(key, value);
}
示例4: putRolePlayerEdge
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入方法依赖的package包/类
/**
* If the edge does not exist then it adds a {@link Schema.EdgeLabel#ROLE_PLAYER} edge from
* this {@link Relationship} to a target {@link Thing} which is playing some {@link Role}.
*
* If the edge does exist nothing is done.
*
* @param role The {@link Role} being played by the {@link Thing} in this {@link Relationship}
* @param toThing The {@link Thing} playing a {@link Role} in this {@link Relationship}
*/
public void putRolePlayerEdge(Role role, Thing toThing) {
//Checking if the edge exists
GraphTraversal<Vertex, Edge> traversal = vertex().tx().getTinkerTraversal().V().
has(Schema.VertexProperty.ID.name(), this.getId().getValue()).
outE(Schema.EdgeLabel.ROLE_PLAYER.getLabel()).
has(Schema.EdgeProperty.RELATIONSHIP_TYPE_LABEL_ID.name(), this.type().getLabelId().getValue()).
has(Schema.EdgeProperty.ROLE_LABEL_ID.name(), role.getLabelId().getValue()).
as("edge").
inV().
has(Schema.VertexProperty.ID.name(), toThing.getId()).
select("edge");
if(traversal.hasNext()){
return;
}
//Role player edge does not exist create a new one
EdgeElement edge = this.addEdge(ConceptVertex.from(toThing), Schema.EdgeLabel.ROLE_PLAYER);
edge.property(Schema.EdgeProperty.RELATIONSHIP_TYPE_LABEL_ID, this.type().getLabelId().getValue());
edge.property(Schema.EdgeProperty.ROLE_LABEL_ID, role.getLabelId().getValue());
Casting casting = Casting.create(edge, owner, role, toThing);
vertex().tx().txCache().trackForValidation(casting);
}
示例5: createXOManager
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入方法依赖的package包/类
@Before
public void createXOManager() throws SQLException, IOException, ServiceException {
AccountManagerTester.cleanupDatabase();
xoManager = xoManagerFactory.createXOManager();
GraphTraversal<Vertex, Vertex> vertices = ((Graph) ductileGraph).traversal().V();
int counter = 0;
while (vertices.hasNext()) {
Vertex vertex = vertices.next();
counter++;
Iterator<VertexProperty<Object>> properties = vertex.properties();
while (properties.hasNext()) {
VertexProperty<Object> property = properties.next();
System.out.println(property.key() + ": " + property.value());
}
}
assertEquals(7, counter);
}
示例6: getRootTraversal
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入方法依赖的package包/类
public GraphTraversal<Vertex, Vertex> getRootTraversal(Graph graph) {
if (rootVertexId != null) {
return graph.traversal().V(rootVertexId);
} else {
GraphTraversal<Vertex, Vertex> rootTraversal = graph.traversal().V().hasLabel("Root");
if (rootTraversal.hasNext()) {
rootVertexId = rootTraversal.next().id();
return getRootTraversal(graph);
} else {
return rootTraversal;
}
}
}
示例7: exists
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入方法依赖的package包/类
@Override
public boolean exists(final Long id) {
try {
GraphTraversal<Vertex, Vertex> traversal = this.graphTraversal.V(id);
return traversal.hasNext();
} finally {
this.graphTraversal.tx().commit();
}
}
示例8: findOne
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入方法依赖的package包/类
@Override
public E findOne(final Long id) {
try {
GraphTraversal<Vertex, Vertex> traversal = this.graphTraversal.V(id);
if (traversal.hasNext()) {
Vertex vertex = traversal.next();
return vertexToEntity(vertex);
}
return null;
} finally {
this.graphTraversal.tx().commit();
}
}
示例9: saveParentRelationship
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入方法依赖的package包/类
private void saveParentRelationship(final E entity, final Vertex vertex, final Parent parent) {
GraphTraversal<Vertex, Vertex> traversal = this.graphTraversal.V().has(ZONE_ID_KEY, entity.getZone().getName())
.has(getEntityIdKey(), parent.getIdentifier());
if (!traversal.hasNext()) {
throw new IllegalStateException(
String.format("No parent exists in zone '%s' with '%s' value of '%s'.", entity.getZone().getName(),
getEntityIdKey(), parent.getIdentifier()));
}
Edge parentEdge = vertex.addEdge(PARENT_EDGE_LABEL, traversal.next());
parent.getScopes().forEach(scope -> parentEdge.property(SCOPE_PROPERTY_KEY, JSON_UTILS.serialize(scope)));
}
示例10: checkVersionVertexExists
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入方法依赖的package包/类
public boolean checkVersionVertexExists(final int versionNumber) {
try {
Vertex versionVertex = null;
// Value has to be provided to the has() method for index to be used. Composite indexes only work on
// equality comparisons.
GraphTraversal<Vertex, Vertex> traversal = this.graphTraversal.V()
.has(VERSION_VERTEX_LABEL, VERSION_PROPERTY_KEY, versionNumber);
if (traversal.hasNext()) {
versionVertex = traversal.next();
// There should be only one version entity with a given version
Assert.isTrue(!traversal.hasNext(), "There are two schema version vertices in the graph");
}
return versionVertex != null;
} finally {
this.graphTraversal.tx().commit();
}
}
示例11: findByZone
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入方法依赖的package包/类
public List<E> findByZone(final ZoneEntity zoneEntity) {
try {
String zoneName = zoneEntity.getName();
GraphTraversal<Vertex, Vertex> traversal = this.graphTraversal.V()
.has(getEntityLabel(), ZONE_ID_KEY, zoneName).has(getEntityIdKey());
List<E> entities = new ArrayList<>();
while (traversal.hasNext()) {
entities.add(vertexToEntity(traversal.next()));
}
return entities;
} finally {
this.graphTraversal.tx().commit();
}
}
示例12: getEntityWithInheritedAttributes
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入方法依赖的package包/类
public E getEntityWithInheritedAttributes(final ZoneEntity zone, final String identifier,
final Set<Attribute> scopes) {
try {
GraphTraversal<Vertex, Vertex> traversal = this.graphTraversal.V().has(ZONE_ID_KEY, zone.getName())
.has(getEntityIdKey(), identifier);
if (!traversal.hasNext()) {
return null;
}
Vertex vertex = traversal.next();
E entity = vertexToEntity(vertex);
searchAttributesWithScopes(entity, vertex, scopes);
// There should be only one entity with a given entity id.
Assert.isTrue(!traversal.hasNext(),
String.format("There are two entities with the same %s.", getEntityIdKey()));
return entity;
} finally {
this.graphTraversal.tx().commit();
}
}
示例13: execute
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入方法依赖的package包/类
/**
* Execute this marvelous code, going from the Content to Users.
*
* Internally uses the RecommendationForNewUser class to build the recommendation as we want, pretty and
* simple.
*
* @param vertex
* @param messenger
* @param memory
*/
@Override
public void execute(Vertex vertex, Messenger<Tuple> messenger, Memory memory) {
try {
HadoopQueryRunner runner = new HadoopQueryRunner(g, vertex.value(Schema.USER_NAME));
GraphTraversal<Vertex, Edge> t = g.V(vertex.id()).inE(Schema.FOLLOWS);
while(t.hasNext()) {
Edge followsEdge = t.next();
long commonFollowedUsers = runner.countCommonFollowedUsers(followsEdge.outVertex());
long postsPerDaySince = runner.countPostsPerDaySince(sevenDaysAgo);
long weight = (3 * commonFollowedUsers + postsPerDaySince) / 4;
if(min == -10 || min > weight) {
min = (int) weight;
}
if(max < weight) {
max = (int) weight;
}
count++;
followsEdge.property(CreateWeightIndex.WEIGHT, weight);
}
} catch (Exception e){
e.printStackTrace();
LOGGER.error("while processing " + vertex.id() + ": " + e.getClass().toString() + "(" + e.getMessage() + ")");
return;
}
}
示例14: putEdge
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入方法依赖的package包/类
/**
* @param to the target {@link VertexElement}
* @param type the type of the edge to create
*/
public EdgeElement putEdge(VertexElement to, Schema.EdgeLabel type){
GraphTraversal<Vertex, Edge> traversal = tx().getTinkerTraversal().V().
has(Schema.VertexProperty.ID.name(), id().getValue()).
outE(type.getLabel()).as("edge").otherV().
has(Schema.VertexProperty.ID.name(), to.id().getValue()).select("edge");
if(!traversal.hasNext()) {
return addEdge(to, type);
} else {
return tx().factory().buildEdgeElement(traversal.next());
}
}
示例15: getConceptEdge
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入方法依赖的package包/类
private <T extends Concept> Optional<T> getConceptEdge(ConceptId id) {
String edgeId = id.getValue().substring(1);
GraphTraversal<Edge, Edge> traversal = getTinkerTraversal().E(edgeId);
if (traversal.hasNext()) {
return Optional.of(factory().buildConcept(factory().buildEdgeElement(traversal.next())));
}
return Optional.empty();
}