本文整理汇总了Java中com.tinkerpop.blueprints.Graph.addVertex方法的典型用法代码示例。如果您正苦于以下问题:Java Graph.addVertex方法的具体用法?Java Graph.addVertex怎么用?Java Graph.addVertex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.tinkerpop.blueprints.Graph
的用法示例。
在下文中一共展示了Graph.addVertex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findOrCreateVertex
import com.tinkerpop.blueprints.Graph; //导入方法依赖的package包/类
/**
* Helper method to find an existing vertex. First the local cache is checked, then the in-memory (uncommitted)
* graph object, the finally the database.
*
* @param g
* @param vertexName
* @return
*/
private Vertex findOrCreateVertex(final Graph g, final String vertexName) {
String resolvedVertexName = classmap.resolveVertex(vertexName);
boolean usingClasses = !vertexName.equals(resolvedVertexName);
Vertex vertex = (Vertex) vertexCache.get(vertexName);
if (vertex == null) {
// FIXME Properly query for vertices in DB if getByID misses
if (!usingClasses) {
vertex = g.getVertex(resolvedVertexName);
}
if (vertex == null) {
vertex = g.addVertex(resolvedVertexName);
if (usingClasses) {
vertex.setProperty(GraphSectionImpl.ELEMENT_NAME_PROPERTY, vertexName);
}
}
}
vertexProps.updateVertexProperties(vertexName, vertex);
vertexCache.put(vertexName, vertex);
return vertex;
}
示例2: testPreloadAllProperties
import com.tinkerpop.blueprints.Graph; //导入方法依赖的package包/类
@Test
public void testPreloadAllProperties() {
AccumuloGraphConfiguration cfg =
AccumuloGraphTestUtils.generateGraphConfig("preloadAllProperties");
cfg.setPropertyCacheTimeout(null, TIMEOUT);
cfg.setPreloadAllProperties(true);
Graph graph = open(cfg);
AccumuloVertex v = (AccumuloVertex) graph.addVertex("V");
v.setProperty(NON_CACHED, true);
v.setProperty(CACHED, true);
v = (AccumuloVertex) graph.getVertex("V");
assertEquals(true, v.getPropertyInMemory(NON_CACHED));
assertEquals(true, v.getPropertyInMemory(CACHED));
graph.shutdown();
}
示例3: testPreloadSomeProperties
import com.tinkerpop.blueprints.Graph; //导入方法依赖的package包/类
@Test
public void testPreloadSomeProperties() {
AccumuloGraphConfiguration cfg =
AccumuloGraphTestUtils.generateGraphConfig("preloadSomeProperties");
cfg.setPropertyCacheTimeout(null, TIMEOUT);
cfg.setPreloadedProperties(new String[]{CACHED});
Graph graph = open(cfg);
AccumuloVertex v = (AccumuloVertex) graph.addVertex("V");
v.setProperty(NON_CACHED, true);
v.setProperty(CACHED, true);
v = (AccumuloVertex) graph.getVertex("V");
assertEquals(null, v.getPropertyInMemory(NON_CACHED));
assertEquals(true, v.getPropertyInMemory(CACHED));
graph.shutdown();
}
示例4: testVertexOutputFormatMap
import com.tinkerpop.blueprints.Graph; //导入方法依赖的package包/类
@Test
public void testVertexOutputFormatMap() throws Exception {
final String INSTANCE_NAME = "_mapreduce_instance2";
final String TEST_TABLE_1 = "_mapreduce_table_2";
if (!System.getProperty("os.name").startsWith("Windows")) {
Graph g = GraphFactory.open(new AccumuloGraphConfiguration().setInstanceName(INSTANCE_NAME).setUser("root").setPassword("".getBytes())
.setGraphName(TEST_TABLE_1).setInstanceType(InstanceType.Mock).setCreate(true).getConfiguration());
for (int i = 0; i < 100; i++) {
g.addVertex(i + "");
}
assertEquals(0, MRTester.main(new String[] {}));
assertNull(e1);
assertNull(e2);
assertEquals(g.getVertex("1").getProperty("NAME"), "BANANA1");
}
}
示例5: testVertexInputMap
import com.tinkerpop.blueprints.Graph; //导入方法依赖的package包/类
@Test
public void testVertexInputMap() throws Exception {
final String INSTANCE_NAME = "_mapreduce_instance";
final String TEST_TABLE_NAME = "_mapreduce_table_vertexInputMap";
if (!System.getProperty("os.name").startsWith("Windows")) {
Graph g = GraphFactory.open(new AccumuloGraphConfiguration().setInstanceName(INSTANCE_NAME)
.setUser("root").setPassword("".getBytes())
.setGraphName(TEST_TABLE_NAME).setInstanceType(InstanceType.Mock)
.setCreate(true).getConfiguration());
for (int i = 0; i < 100; i++) {
g.addVertex(i + "");
}
assertEquals(0, MRTester.main(new String[]{"root", "",
TEST_TABLE_NAME, INSTANCE_NAME, "false"}));
assertNull(e1);
assertNull(e2);
g.shutdown();
}
}
示例6: testEdgeInputMap
import com.tinkerpop.blueprints.Graph; //导入方法依赖的package包/类
@Test
public void testEdgeInputMap() throws Exception {
final String INSTANCE_NAME = "_mapreduce_instance";
final String TEST_TABLE_NAME = "_mapreduce_table_edgeInputMap";
if (!System.getProperty("os.name").startsWith("Windows")) {
Graph g = GraphFactory.open(new AccumuloGraphConfiguration().setInstanceName(INSTANCE_NAME)
.setUser("root").setPassword("".getBytes())
.setGraphName(TEST_TABLE_NAME).setInstanceType(InstanceType.Mock)
.setAutoFlush(true).setCreate(true).getConfiguration());
for (int i = 0; i < 100; i++) {
Vertex v1 = g.addVertex(i+"");
Vertex v2 = g.addVertex(i+"a");
g.addEdge(null, v1, v2, "knows");
}
assertEquals(0, MRTester.main(new String[]{"root", "",
TEST_TABLE_NAME, INSTANCE_NAME, "true"}));
assertNull(e1);
assertNull(e2);
g.shutdown();
}
}
示例7: testElementCacheSize
import com.tinkerpop.blueprints.Graph; //导入方法依赖的package包/类
@Test
public void testElementCacheSize() throws Exception {
AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils
.generateGraphConfig("elementCacheSize");
Graph graph = GraphFactory.open(cfg.getConfiguration());
Vertex[] verts = new Vertex[10];
for (int i = 0; i < verts.length; i++) {
verts[i] = graph.addVertex(i);
}
Edge[] edges = new Edge[9];
for (int i = 0; i < edges.length; i++) {
edges[i] = graph.addEdge(null,
verts[0], verts[i+1], "edge");
}
sizeTests(verts);
sizeTests(edges);
graph.shutdown();
}
示例8: createUser
import com.tinkerpop.blueprints.Graph; //导入方法依赖的package包/类
public boolean createUser( UserSecurity user ) {
Graph graph = (Graph) connection.get();
logger.debug("createUser: " + user.getEmail() );
try {
// check if user already registered
try {
if( getUserIdByEmail( user.getEmail() ) != null ) {
throw new UserExistingException( user.getEmail() );
}
}
// continue if no user found
catch( UserNotFoundException e) {}
// create user vertex
Vertex v = graph.addVertex(null);
// type user
v.setProperty( GremlinDAOSpec.UNIVERSAL_PROPERTY_TYPE, GremlinDAOSpec.USER_CLASS );
v.setProperty( GremlinDAOSpec.USER_PROPERTY_FIRST_NAME, user.getFirstname() );
v.setProperty( GremlinDAOSpec.USER_PROPERTY_LAST_NAME, user.getLastname() );
v.setProperty( GremlinDAOSpec.USER_PROPERTY_EMAIL, user.getEmail() );
v.setProperty( GremlinDAOSpec.USER_PROPERTY_PASSWORD, user.getPassword() );
v.setProperty( GremlinDAOSpec.USER_PROPERTY_ROLE, user.getRole() );
return true;
}
finally {
graph.shutdown();
}
}
示例9: addNode
import com.tinkerpop.blueprints.Graph; //导入方法依赖的package包/类
public static Vertex addNode(Graph graph, Map<String, String> properties)
{
Vertex newVertex = graph.addVertex(0);
for (Entry<String, String> entrySet : properties.entrySet())
{
newVertex.setProperty(entrySet.getKey(), entrySet.getValue());
}
return newVertex;
}
示例10: invoke
import com.tinkerpop.blueprints.Graph; //导入方法依赖的package包/类
@Override
public void invoke(Graph graph) {
Vertex association = graph.addVertex(9);
association.setProperty(CommonProperties.IRI, "http://x.org/a_assn");
association.setProperty(NodeProperties.LABEL, "assn");
association.addEdge("http://purl.org/oban/association_has_subject", graph.getVertex(3));
association.addEdge("http://purl.org/oban/association_has_object", graph.getVertex(4));
// Add evidence
Vertex evidence1 = graph.addVertex(11);
evidence1.setProperty(CommonProperties.IRI, "http://x.org/a_evidence");
evidence1.setProperty(NodeProperties.LABEL, "ev1");
association.addEdge("http://purl.obolibrary.org/obo/RO_0002558", evidence1);
}
示例11: createGraph
import com.tinkerpop.blueprints.Graph; //导入方法依赖的package包/类
public static Graph createGraph( EngineMetaInterface meta ) {
if ( meta == null ) {
return null;
}
Graph g = new TinkerGraph();
if ( meta instanceof TransMeta ) {
TransMeta transMeta = (TransMeta) meta;
// Add nodes
List<StepMeta> steps = transMeta.getSteps();
if ( steps != null ) {
for ( StepMeta step : steps ) {
Vertex v = g.addVertex( step.getName() );
v.setProperty( PROPERTY_NAME, step.getName() );
v.setProperty( PROPERTY_PLUGINID, step.getStepID() );
Point location = step.getLocation();
v.setProperty( PROPERTY_X, location.x );
v.setProperty( PROPERTY_Y, location.y );
v.setProperty( PROPERTY_REF, step );
}
}
int numHops = transMeta.nrTransHops();
for ( int i = 0; i < numHops; i++ ) {
TransHopMeta hop = transMeta.getTransHop( i );
StepMeta fromStep = hop.getFromStep();
StepMeta toStep = hop.getToStep();
Vertex fromV = g.getVertex( fromStep.getName() );
Vertex toV = g.getVertex( toStep.getName() );
g.addEdge( null, fromV, toV, EDGE_HOPSTO );
}
}
return g;
}
示例12: CompleteLattice
import com.tinkerpop.blueprints.Graph; //导入方法依赖的package包/类
/**
* Construct a complete lattice assigned to a designated graph (backend).
* @param graph assignment
* @param top element
*/
protected CompleteLattice(final Graph graph, PartiallyOrdered top) {
checkNotNull(graph, top);
this.graph = graph;
order = 0;
color = 0;
this.top = graph.addVertex(null);
this.top.setProperty(LABEL, top);
this.top.setProperty(COLOR, color);
bottom = this.top;
size = 1;
}
示例13: testNonStringIds
import com.tinkerpop.blueprints.Graph; //导入方法依赖的package包/类
@Test
public void testNonStringIds() throws Exception {
Graph graph = AccumuloGraphTestUtils.makeGraph("nonStringIds");
Object[] ids = new Object[] {
10, 20, 30L, 40L,
50.0f, 60.0f, 70.0d, 80.0d,
(byte) 'a', (byte) 'b', 'c', 'd',
"str1", "str2",
new GenericObject("str3"), new GenericObject("str4"),
};
Object[] edgeIds = new Object[] {
100, 200, 300L, 400L,
500.0f, 600.0f, 700.0d, 800.0d,
(byte) 'e', (byte) 'f', 'g', 'h',
"str5", "str6",
new GenericObject("str7"), new GenericObject("str8"),
};
for (int i = 0; i < ids.length; i++) {
assertNull(graph.getVertex(ids[i]));
Vertex v = graph.addVertex(ids[i]);
assertNotNull(v);
assertNotNull(graph.getVertex(ids[i]));
}
assertEquals(ids.length, count(graph.getVertices()));
for (int i = 1; i < edgeIds.length; i++) {
assertNull(graph.getEdge(edgeIds[i-1]));
Edge e = graph.addEdge(edgeIds[i-1],
graph.getVertex(ids[i-1]),
graph.getVertex(ids[i]), "label");
assertNotNull(e);
assertNotNull(graph.getEdge(edgeIds[i-1]));
}
assertEquals(edgeIds.length-1, count(graph.getEdges()));
graph.shutdown();
}
示例14: testSkipExistenceChecks
import com.tinkerpop.blueprints.Graph; //导入方法依赖的package包/类
@Test
public void testSkipExistenceChecks() throws Exception {
AccumuloGraphConfiguration cfg =
AccumuloGraphTestUtils.generateGraphConfig("skipExistenceChecks");
cfg.setSkipExistenceChecks(true);
Graph graph = makeGraph(cfg);
String id;
id = "doubleAdd";
assertNotNull(graph.addVertex(id));
assertNotNull(graph.addVertex(id));
Vertex vAdd = graph.getVertex(id);
assertNotNull(vAdd);
graph.removeVertex(vAdd);
assertNotNull(graph.getVertex(id));
id = "doubleRemove";
Vertex vRemove = graph.addVertex(id);
assertNotNull(vRemove);
graph.removeVertex(vRemove);
assertNotNull(graph.getVertex(id));
// MDL 24 Dec 2014: removeVertex still does checks.
//graph.removeVertex(vRemove);
//assertNotNull(graph.getVertex(id));
id = "notExist";
assertNotNull(graph.getVertex(id));
graph.shutdown();
}
示例15: testElementCacheTimeout
import com.tinkerpop.blueprints.Graph; //导入方法依赖的package包/类
@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();
}