本文整理汇总了Java中com.thinkaurelius.titan.core.PropertyKey类的典型用法代码示例。如果您正苦于以下问题:Java PropertyKey类的具体用法?Java PropertyKey怎么用?Java PropertyKey使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PropertyKey类属于com.thinkaurelius.titan.core包,在下文中一共展示了PropertyKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createUniqueCompositeIndex
import com.thinkaurelius.titan.core.PropertyKey; //导入依赖的package包/类
public static void createUniqueCompositeIndex(final Graph newGraph, final String indexName,
final String[] propertyKeyNames, final Class<?> propertyKeyType) throws InterruptedException {
Assert.notEmpty(propertyKeyNames);
newGraph.tx().rollback(); // Never create new indexes while a transaction is active
TitanManagement mgmt = ((TitanGraph) newGraph).openManagement();
IndexBuilder indexBuilder = mgmt.buildIndex(indexName, Vertex.class);
if (!mgmt.containsGraphIndex(indexName)) {
for (String propertyKeyName : propertyKeyNames) {
PropertyKey indexPropertyKey = getOrCreatePropertyKey(propertyKeyName, propertyKeyType, mgmt);
indexBuilder.addKey(indexPropertyKey);
}
indexBuilder.unique().buildCompositeIndex();
}
mgmt.commit();
// Wait for the index to become available
ManagementSystem.awaitGraphIndexStatus((TitanGraph) newGraph, indexName).status(SchemaStatus.ENABLED).call();
}
示例2: testForceIndexUsage
import com.thinkaurelius.titan.core.PropertyKey; //导入依赖的package包/类
@Test
public void testForceIndexUsage() {
PropertyKey age = makeKey("age", Integer.class);
PropertyKey time = makeKey("time", Long.class);
mgmt.buildIndex("time", Vertex.class).addKey(time).buildCompositeIndex();
finishSchema();
for (int i = 1; i <= 10; i++) {
TitanVertex v = tx.addVertex("time", i, "age", i);
}
//Graph query with and with-out index support
assertCount(1, tx.query().has("time", 5).vertices());
assertCount(1, tx.query().has("age", 6).vertices());
clopen(option(FORCE_INDEX_USAGE), true);
//Query with-out index support should now throw exception
assertCount(1, tx.query().has("time", 5).vertices());
try {
assertCount(1, tx.query().has("age", 6).vertices());
fail();
} catch (Exception e) {
}
}
示例3: getQuery
import com.thinkaurelius.titan.core.PropertyKey; //导入依赖的package包/类
public static GraphCentricQueryBuilder getQuery(CompositeIndexType index, Object[] values, StandardTitanTx tx) {
Preconditions.checkArgument(index != null && values != null && values.length > 0 && tx != null);
Preconditions.checkArgument(values.length==index.getFieldKeys().length);
GraphCentricQueryBuilder gb = tx.query();
IndexField[] fields = index.getFieldKeys();
for (int i = 0; i <fields.length; i++) {
IndexField f = fields[i];
Object value = values[i];
Preconditions.checkNotNull(value);
PropertyKey key = f.getFieldKey();
Preconditions.checkArgument(key.getDataType().equals(value.getClass()),"Incompatible data types for: " + value);
gb.has(key, Cmp.EQUAL,value);
}
if (index.hasSchemaTypeConstraint()) {
gb.has(ImplicitKey.LABEL,Cmp.EQUAL,index.getSchemaTypeConstraint().getName());
}
return gb;
}
示例4: Titan0Graph
import com.thinkaurelius.titan.core.PropertyKey; //导入依赖的package包/类
public Titan0Graph() {
//determine multi-properties once at startup
TitanManagement mgmt = null;
try {
mgmt = Titan0GraphDatabase.getGraphInstance().getManagementSystem();
Iterable<PropertyKey> keys = mgmt.getRelationTypes(PropertyKey.class);
multiProperties = Collections.synchronizedSet(new HashSet<String>());
for(PropertyKey key : keys) {
if (key.getCardinality() != Cardinality.SINGLE) {
multiProperties.add(key.getName());
}
}
} finally {
if (mgmt != null) {
mgmt.rollback();
}
}
}
示例5: testContainsWithMultipleValues
import com.thinkaurelius.titan.core.PropertyKey; //导入依赖的package包/类
@Test
// this tests a case when there as AND with a single CONTAINS condition inside AND(name:(was here))
// which (in case of Solr) spans multiple conditions such as AND(AND(name:was, name:here))
// so we need to make sure that we don't apply AND twice.
public void testContainsWithMultipleValues() throws Exception {
PropertyKey name = makeKey("name", String.class);
mgmt.buildIndex("store1", Vertex.class).addKey(name).buildMixedIndex(INDEX);
mgmt.commit();
TitanVertex v1 = tx.addVertex();
v1.property("name", "hercules was here");
tx.commit();
Thread.sleep(2000);
TitanVertex r = Iterables.<TitanVertex>get(graph.query().has("name", Text.CONTAINS, "hercules here").vertices(), 0);
Assert.assertEquals(r.property("name").value(), "hercules was here");
}
示例6: testWidcardQuery
import com.thinkaurelius.titan.core.PropertyKey; //导入依赖的package包/类
/**
* Tests indexing using _all virtual field
*/
@Test
public void testWidcardQuery() {
if (supportsWildcardQuery()) {
PropertyKey p1 = makeKey("p1", String.class);
PropertyKey p2 = makeKey("p2", String.class);
mgmt.buildIndex("mixedIndex", Vertex.class).addKey(p1).addKey(p2).buildMixedIndex(INDEX);
finishSchema();
clopen();
TitanVertex v1 = graph.addVertex();
v1.property("p1", "test1");
v1.property("p2", "test2");
clopen();//Flush the index
assertEquals(v1, graph.indexQuery("mixedIndex", "v.*:\"test1\"").vertices().iterator().next().getElement());
assertEquals(v1, graph.indexQuery("mixedIndex", "v.*:\"test2\"").vertices().iterator().next().getElement());
}
}
示例7: setPropertyDirect
import com.thinkaurelius.titan.core.PropertyKey; //导入依赖的package包/类
@Override
public void setPropertyDirect(PropertyKey key, Object value) {
Preconditions.checkArgument(!(key instanceof ImplicitKey), "Cannot use implicit type [%s] when setting property", key.name());
if (properties == EMPTY_PROPERTIES) {
if (tx().getConfiguration().isSingleThreaded()) {
properties = new HashMap<PropertyKey, Object>(5);
} else {
synchronized (this) {
if (properties == EMPTY_PROPERTIES) {
properties = Collections.synchronizedMap(new HashMap<PropertyKey, Object>(5));
}
}
}
}
properties.put(key, value);
}
示例8: Titan1Graph
import com.thinkaurelius.titan.core.PropertyKey; //导入依赖的package包/类
public Titan1Graph() {
//determine multi-properties once at startup
TitanManagement mgmt = null;
try {
mgmt = Titan1GraphDatabase.getGraphInstance().openManagement();
Iterable<PropertyKey> keys = mgmt.getRelationTypes(PropertyKey.class);
multiProperties = new HashSet<>();
for (PropertyKey key : keys) {
if (key.cardinality() != Cardinality.SINGLE) {
multiProperties.add(key.name());
}
}
} finally {
if (mgmt != null) {
mgmt.rollback();
}
}
}
示例9: getQuery
import com.thinkaurelius.titan.core.PropertyKey; //导入依赖的package包/类
public static GraphCentricQueryBuilder getQuery(CompositeIndexType index, Object[] values, StandardTitanTx tx) {
Preconditions.checkArgument(index != null && values != null && values.length > 0 && tx != null);
Preconditions.checkArgument(values.length==index.getFieldKeys().length);
GraphCentricQueryBuilder gb = tx.query();
IndexField[] fields = index.getFieldKeys();
for (int i = 0; i <fields.length; i++) {
IndexField f = fields[i];
Object value = values[i];
Preconditions.checkNotNull(value);
PropertyKey key = f.getFieldKey();
Preconditions.checkArgument(key.dataType().equals(value.getClass()),"Incompatible data types for: " + value);
gb.has(key, Cmp.EQUAL,value);
}
if (index.hasSchemaTypeConstraint()) {
gb.has(ImplicitKey.LABEL,Cmp.EQUAL,index.getSchemaTypeConstraint().name());
}
return gb;
}
示例10: testStaleVertex
import com.thinkaurelius.titan.core.PropertyKey; //导入依赖的package包/类
@Test
public void testStaleVertex() {
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make();
mgmt.buildIndex("byName", Vertex.class).addKey(name).unique().buildCompositeIndex();
finishSchema();
TitanVertex cartman = graph.addVertex("name", "cartman", "age", 10);
TitanVertex stan = graph.addVertex("name", "stan", "age", 8);
graph.tx().commit();
cartman = getOnlyElement(graph.query().has("name", "cartman").vertices());
graph.tx().commit();
TitanVertexProperty p = (TitanVertexProperty) cartman.properties().next();
assertTrue(((Long) p.longId()) > 0);
graph.tx().commit();
}
示例11: createIndex
import com.thinkaurelius.titan.core.PropertyKey; //导入依赖的package包/类
public static void createIndex(final Graph newGraph, final String indexName, final String indexKey)
throws InterruptedException {
newGraph.tx().rollback(); // Never create new indexes while a transaction is active
TitanManagement mgmt = ((TitanGraph) newGraph).openManagement();
if (!mgmt.containsGraphIndex(indexName)) {
PropertyKey indexPropertyKey = mgmt.makePropertyKey(indexKey).dataType(String.class).make();
mgmt.buildIndex(indexName, Vertex.class).addKey(indexPropertyKey).buildCompositeIndex();
}
mgmt.commit();
// Wait for the index to become available
ManagementSystem.awaitGraphIndexStatus((TitanGraph) newGraph, indexName).status(SchemaStatus.ENABLED).call();
}
示例12: createUniqueIndexForLabel
import com.thinkaurelius.titan.core.PropertyKey; //导入依赖的package包/类
public static void createUniqueIndexForLabel(final Graph newGraph, final String indexName, final String indexKey,
final String label) throws InterruptedException {
newGraph.tx().rollback(); // Never create new indexes while a transaction is active
TitanManagement mgmt = ((TitanGraph) newGraph).openManagement();
if (!mgmt.containsGraphIndex(indexName)) {
PropertyKey indexPropertyKey = mgmt.makePropertyKey(indexKey).dataType(Integer.class).make();
VertexLabel versionLabel = mgmt.makeVertexLabel(label).make();
// Create a unique composite index for the property key that indexes only vertices with a given label
mgmt.buildIndex(indexName, Vertex.class).addKey(indexPropertyKey).indexOnly(versionLabel).unique()
.buildCompositeIndex();
}
mgmt.commit();
// Wait for the index to become available
ManagementSystem.awaitGraphIndexStatus((TitanGraph) newGraph, indexName).status(SchemaStatus.ENABLED).call();
}
示例13: getOrCreatePropertyKey
import com.thinkaurelius.titan.core.PropertyKey; //导入依赖的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;
}
示例14: createEdgeIndex
import com.thinkaurelius.titan.core.PropertyKey; //导入依赖的package包/类
public static void createEdgeIndex(final Graph newGraph, final String indexName, final String label,
final String indexKey) throws InterruptedException {
newGraph.tx().rollback(); // Never create new indexes while a transaction is active
TitanManagement mgmt = ((TitanGraph) newGraph).openManagement();
EdgeLabel edgeLabel = mgmt.getOrCreateEdgeLabel(label);
if (!mgmt.containsRelationIndex(edgeLabel, indexName)) {
PropertyKey indexPropertyKey = getOrCreatePropertyKey(indexKey, String.class, mgmt);
mgmt.buildEdgeIndex(edgeLabel, indexName, Direction.OUT, indexPropertyKey);
}
mgmt.commit();
// Wait for the index to become available
ManagementSystem.awaitRelationIndexStatus((TitanGraph) newGraph, indexName, label).status(SchemaStatus.ENABLED)
.call();
}
示例15: getPropertyKeysDirect
import com.thinkaurelius.titan.core.PropertyKey; //导入依赖的package包/类
@Override
public Iterable<PropertyKey> getPropertyKeysDirect() {
RelationCache map = getPropertyMap();
List<PropertyKey> types = new ArrayList<>(map.numProperties());
for (LongObjectCursor<Object> entry : map) {
types.add(tx().getExistingPropertyKey(entry.key));
}
return types;
}