本文整理汇总了Java中com.thinkaurelius.titan.core.schema.TitanManagement.getPropertyKey方法的典型用法代码示例。如果您正苦于以下问题:Java TitanManagement.getPropertyKey方法的具体用法?Java TitanManagement.getPropertyKey怎么用?Java TitanManagement.getPropertyKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.thinkaurelius.titan.core.schema.TitanManagement
的用法示例。
在下文中一共展示了TitanManagement.getPropertyKey方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOrCreatePropertyKey
import com.thinkaurelius.titan.core.schema.TitanManagement; //导入方法依赖的package包/类
private static PropertyKey getOrCreatePropertyKey(final String keyName, final Class<?> keyType,
final TitanManagement mgmt) {
PropertyKey propertyKey = mgmt.getPropertyKey(keyName);
if (null == propertyKey) {
propertyKey = mgmt.makePropertyKey(keyName).dataType(keyType).make();
}
return propertyKey;
}
示例2: testRepairRelationIndex
import com.thinkaurelius.titan.core.schema.TitanManagement; //导入方法依赖的package包/类
@Test
public void testRepairRelationIndex() throws InterruptedException, BackendException, ExecutionException {
tx.commit();
mgmt.commit();
// Load the "Graph of the Gods" sample data (WITHOUT mixed index coverage)
GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true);
// Create and enable a relation index on lives edges by reason
TitanManagement m = graph.openManagement();
PropertyKey reason = m.getPropertyKey("reason");
EdgeLabel lives = m.getEdgeLabel("lives");
m.buildEdgeIndex(lives, "livesByReason", Direction.BOTH, Order.decr, reason);
m.commit();
graph.tx().commit();
// Block until the SchemaStatus transitions to REGISTERED
assertTrue(ManagementSystem.awaitRelationIndexStatus(graph, "livesByReason", "lives")
.status(SchemaStatus.REGISTERED).call().getSucceeded());
m = graph.openManagement();
RelationTypeIndex index = m.getRelationIndex(m.getRelationType("lives"), "livesByReason");
m.updateIndex(index, SchemaAction.ENABLE_INDEX);
m.commit();
graph.tx().commit();
// Block until the SchemaStatus transitions to ENABLED
assertTrue(ManagementSystem.awaitRelationIndexStatus(graph, "livesByReason", "lives")
.status(SchemaStatus.ENABLED).call().getSucceeded());
// Run a query that hits the index but erroneously returns nothing because we haven't repaired yet
//assertFalse(graph.query().has("reason", "no fear of death").edges().iterator().hasNext());
// Repair
MapReduceIndexManagement mri = new MapReduceIndexManagement(graph);
m = graph.openManagement();
index = m.getRelationIndex(m.getRelationType("lives"), "livesByReason");
ScanMetrics metrics = mri.updateIndex(index, SchemaAction.REINDEX).get();
assertEquals(8, metrics.getCustom(IndexRepairJob.ADDED_RECORDS_COUNT));
}
示例3: createIndexWhenAbsent
import com.thinkaurelius.titan.core.schema.TitanManagement; //导入方法依赖的package包/类
private static boolean createIndexWhenAbsent(TitanManagement mgmt, VertexCompositeIndex compositeIndex) {
String name = compositeIndex.name;
if (!mgmt.containsGraphIndex(name)) {
String property = compositeIndex.property;
String label = compositeIndex.label;
boolean unique = compositeIndex.unique;
LOG.info("building {} index '{}' for label '{}' + property '{}'", unique ? "unique" : "non-unique", name, label, property);
PropertyKey uuidKey = mgmt.containsPropertyKey(property)//
? mgmt.getPropertyKey(property)//
: mgmt.makePropertyKey(property).dataType(String.class).make();
IndexBuilder indexBuilder = mgmt.buildIndex(name, Vertex.class)//
.addKey(uuidKey);
if (label != null) {
VertexLabel vertexLabel = mgmt.containsVertexLabel(label)//
? mgmt.getVertexLabel(label)//
: mgmt.makeVertexLabel(label).make();
indexBuilder = indexBuilder.indexOnly(vertexLabel);
}
if (unique) {
indexBuilder = indexBuilder.unique();
}
TitanGraphIndex index = indexBuilder.buildCompositeIndex();
mgmt.setConsistency(index, ConsistencyModifier.LOCK);
return true;
}
return false;
}
示例4: main
import com.thinkaurelius.titan.core.schema.TitanManagement; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Configuration conf = new PropertiesConfiguration( getRelativeResourcePath( "titan-cassandra-es.properties" ) );
// start elastic search on startup
Node node = new NodeBuilder().node();
TitanGraph graph = TitanFactory.open(conf);
/* Comment if you do not want to reload the graph every time */
graph.close();
TitanCleanup.clear(graph);
graph = TitanFactory.open(conf);
GraphOfTheGodsFactory.load(graph);
/* graph loaded */
// create own indexes
TitanManagement mgmt = graph.openManagement();
PropertyKey name = mgmt.getPropertyKey("name");
PropertyKey age = mgmt.getPropertyKey("age");
mgmt.buildIndex( "byNameComposite", Vertex.class ).addKey(name).buildCompositeIndex();
// index consisting of multiple properties
mgmt.buildIndex( "byNameAndAgeComposite", Vertex.class ).addKey(name).addKey(age).buildCompositeIndex();
mgmt.commit();
// wait for the index to become available
ManagementSystem.awaitGraphIndexStatus(graph, "byNameComposite").call();
ManagementSystem.awaitGraphIndexStatus(graph, "byNameAndAgeComposite").call();
// create new vertex
Vertex me = graph.addVertex("theOneAndOnly");
me.property( "name", "me" );
me.property( "age", 1 );
graph.tx().commit();
System.out.println("Created the one and only!");
// re index the existing data (not required, just for demo purposes)
mgmt = graph.openManagement();
mgmt.updateIndex( mgmt.getGraphIndex("byNameComposite"), SchemaAction.REINDEX ).get();
mgmt.updateIndex( mgmt.getGraphIndex("byNameAndAgeComposite"), SchemaAction.REINDEX ).get();
mgmt.commit();
GraphTraversalSource g = graph.traversal();
GremlinPipeline<GraphTraversal<?, ?>, ?> pipe = new GremlinPipeline();
// read our new vertex
pipe.start( g.V().has( "name", "me" ) );
Vertex v = (Vertex)pipe.next();
System.out.println();
System.out.println( "Label: " + v.label() );
System.out.println( "Name: " + v.property("name").value() );
System.out.println( "Age: " + v.property("age").value() );
System.out.println();
// read different vertex
pipe.start( g.V().has( "name", "hercules" ) );
Vertex herclues = (Vertex)pipe.next();
System.out.println( "Label: " + herclues.label() );
System.out.println( "Name: " + herclues.property("name").value() );
System.out.println( "Age: " + herclues.property("age").value() );
// print some edges
Iterator<Edge> it = herclues.edges( Direction.OUT );
while( it.hasNext() ) {
Edge e = it.next();
System.out.println( "Out: " + e.label() + " --> " + e.inVertex().property("name").value() );
}
System.out.println();
// close graph
graph.close();
// close elastic search on shutdown
node.close();
System.exit(0);
}
示例5: testRepairGraphIndex
import com.thinkaurelius.titan.core.schema.TitanManagement; //导入方法依赖的package包/类
@Test
public void testRepairGraphIndex() throws InterruptedException, BackendException, ExecutionException {
tx.commit();
mgmt.commit();
// Load the "Graph of the Gods" sample data (WITHOUT mixed index coverage)
GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true);
// Create and enable a graph index on age
TitanManagement m = graph.openManagement();
PropertyKey age = m.getPropertyKey("age");
m.buildIndex("verticesByAge", Vertex.class).addKey(age).buildCompositeIndex();
m.commit();
graph.tx().commit();
// Block until the SchemaStatus transitions to REGISTERED
assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "verticesByAge")
.status(SchemaStatus.REGISTERED).call().getSucceeded());
m = graph.openManagement();
TitanGraphIndex index = m.getGraphIndex("verticesByAge");
m.updateIndex(index, SchemaAction.ENABLE_INDEX);
m.commit();
graph.tx().commit();
// Block until the SchemaStatus transitions to ENABLED
assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "verticesByAge")
.status(SchemaStatus.ENABLED).call().getSucceeded());
// Run a query that hits the index but erroneously returns nothing because we haven't repaired yet
assertFalse(graph.query().has("age", 10000).vertices().iterator().hasNext());
// Repair
MapReduceIndexManagement mri = new MapReduceIndexManagement(graph);
m = graph.openManagement();
index = m.getGraphIndex("verticesByAge");
ScanMetrics metrics = mri.updateIndex(index, SchemaAction.REINDEX).get();
assertEquals(6, metrics.getCustom(IndexRepairJob.ADDED_RECORDS_COUNT));
// Test the index
Iterable<TitanVertex> hits = graph.query().has("age", 4500).vertices();
assertNotNull(hits);
assertEquals(1, Iterables.size(hits));
TitanVertex v = Iterables.getOnlyElement(hits);
assertNotNull(v);
assertEquals("neptune", v.value("name"));
}
示例6: main
import com.thinkaurelius.titan.core.schema.TitanManagement; //导入方法依赖的package包/类
public static void main(String args[]) {
//Load database
//URL url = TitanImporter.class.getClassLoader().getResource("bdb.conf");
URL url = TitanImporter.class.getClassLoader().getResource("bdbMWE.conf");
if (url == null) {
System.err.println("Missing resource bdb.conf");
return;
}
String confPath = url.getPath();
TitanGraph g = TitanFactory.open(confPath);
TitanManagement m = g.getManagementSystem();
// m.set("index.search.elasticsearch.client-only",false);
// m.set("index.search.elasticsearch.local-mode",true);
// m.commit();
// g.commit();
// g.shutdown();
//
// g = TitanFactory.open(confPath);
Logger logger = LoggerFactory.getLogger(Main.class);
logger.debug("make id property");
m.makePropertyKey(IdGraph.ID).dataType(Long.class).cardinality(Cardinality.SINGLE).make();
m.commit();
g.commit();
logger.debug("make index");
m = g.getManagementSystem();
PropertyKey id = m.getPropertyKey(IdGraph.ID);
m.buildIndex("byvid", Vertex.class).addKey(id).unique().buildCompositeIndex();
logger.info("index status {}", m.getGraphIndex("byvid").getIndexStatus(m.getPropertyKey(IdGraph.ID)));
m.commit();
m = g.getManagementSystem();
logger.info("index status {}", m.getGraphIndex("byvid").getIndexStatus(m.getPropertyKey(IdGraph.ID)));
m.commit();
g.commit();
m = g.getManagementSystem();
m.updateIndex(m.getGraphIndex("byvid"), SchemaAction.REGISTER_INDEX);
logger.info("set register trigger");
m.commit();
g.commit();
m = g.getManagementSystem();
logger.info("index status {}", m.getGraphIndex("byvid").getIndexStatus(m.getPropertyKey(IdGraph.ID)));
m.commit();
m = g.getManagementSystem();
logger.info("index status {}", m.getGraphIndex("byvid").getIndexStatus(m.getPropertyKey(IdGraph.ID)));
m.updateIndex(m.getGraphIndex("byvid"), SchemaAction.ENABLE_INDEX);
m.commit();
m = g.getManagementSystem();
logger.info("index status {}", m.getGraphIndex("byvid").getIndexStatus(m.getPropertyKey(IdGraph.ID)));
m.commit();
Vertex p = g.addVertexWithLabel("person");
p.setProperty(IdGraph.ID, 11);
Iterable<Vertex> vL = g.query().has(IdGraph.ID, 11).vertices();
for (Vertex v : vL)
logger.info("found: {}", v.toString());
// TitanImporter ti = new TitanImporter();
// try {
// ti.init(confPath, WorkloadEnum.INTERACTIVE);
// } catch (DBgenImporter.ConnectionException e) {
// e.printStackTrace();
// }
// File dir = new File(System.getProperty("validationFolderName"));
// if (!dir.exists())
// System.err.println("Validation data folder not found ");
// try {
// ti.importData(dir);
// } catch (IOException e) {
// e.printStackTrace();
// } catch (SchemaViolationException e) {
// e.printStackTrace();
// }
// ti.shutdown();
}