use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.
the class ConfigurationManagementGraphTest method shouldCloseAllTxsIfIndexExists.
@Test
public void shouldCloseAllTxsIfIndexExists() {
final StandardJanusGraph graph = (StandardJanusGraph) JanusGraphFactory.open("inmemory");
// Emulate ConfigurationManagementGraph indices already exists
JanusGraphManagement management = graph.openManagement();
PropertyKey key = management.makePropertyKey("some_property").dataType(String.class).make();
management.buildIndex("Created_Using_Template_Index", Vertex.class).addKey(key).buildCompositeIndex();
management.buildIndex("Template_Index", Vertex.class).addKey(key).buildCompositeIndex();
management.buildIndex("Graph_Name_Index", Vertex.class).addKey(key).buildCompositeIndex();
management.commit();
new ConfigurationManagementGraph(graph);
assertEquals(0, graph.getOpenTransactions().size());
}
use of org.janusgraph.core.schema.JanusGraphManagement in project grakn by graknlabs.
the class TxFactoryJanus method makeIndicesVertexCentric.
private static void makeIndicesVertexCentric(JanusGraphManagement management) {
ResourceBundle keys = ResourceBundle.getBundle("indices-edges");
Set<String> edgeLabels = keys.keySet();
for (String edgeLabel : edgeLabels) {
String[] propertyKeyStrings = keys.getString(edgeLabel).split(",");
// Get all the property keys we need
Set<PropertyKey> propertyKeys = stream(propertyKeyStrings).map(keyId -> {
PropertyKey key = management.getPropertyKey(keyId);
if (key == null) {
throw new RuntimeException("Trying to create edge index on label [" + edgeLabel + "] but the property [" + keyId + "] does not exist");
}
return key;
}).collect(Collectors.toSet());
// Get the edge and indexing information
RelationType relationType = management.getRelationType(edgeLabel);
EdgeLabel label = management.getEdgeLabel(edgeLabel);
// Create index on each property key
for (PropertyKey key : propertyKeys) {
if (management.getRelationIndex(relationType, edgeLabel + "by" + key.name()) == null) {
management.buildEdgeIndex(label, edgeLabel + "by" + key.name(), Direction.BOTH, Order.decr, key);
}
}
// Create index on all property keys
String propertyKeyId = propertyKeys.stream().map(Namifiable::name).collect(Collectors.joining("_"));
if (management.getRelationIndex(relationType, edgeLabel + "by" + propertyKeyId) == null) {
PropertyKey[] allKeys = propertyKeys.toArray(new PropertyKey[propertyKeys.size()]);
management.buildEdgeIndex(label, edgeLabel + "by" + propertyKeyId, Direction.BOTH, Order.decr, allKeys);
}
}
}
use of org.janusgraph.core.schema.JanusGraphManagement in project grakn by graknlabs.
the class TxFactoryJanus method makeIndicesComposite.
private static void makeIndicesComposite(JanusGraphManagement management) {
ResourceBundle keys = ResourceBundle.getBundle("indices-composite");
Set<String> keyString = keys.keySet();
for (String propertyKeyLabel : keyString) {
String indexLabel = "by" + propertyKeyLabel;
JanusGraphIndex index = management.getGraphIndex(indexLabel);
if (index == null) {
boolean isUnique = Boolean.parseBoolean(keys.getString(propertyKeyLabel));
PropertyKey key = management.getPropertyKey(propertyKeyLabel);
JanusGraphManagement.IndexBuilder indexBuilder = management.buildIndex(indexLabel, Vertex.class).addKey(key);
if (isUnique) {
indexBuilder.unique();
}
indexBuilder.buildCompositeIndex();
}
}
}
use of org.janusgraph.core.schema.JanusGraphManagement in project grakn by graknlabs.
the class TxFactoryJanus method buildJanusIndexes.
private static void buildJanusIndexes(JanusGraph graph) {
JanusGraphManagement management = graph.openManagement();
makeVertexLabels(management);
makeEdgeLabels(management);
makePropertyKeys(management);
makeIndicesVertexCentric(management);
makeIndicesComposite(management);
management.commit();
}
use of org.janusgraph.core.schema.JanusGraphManagement in project grakn by graknlabs.
the class TxFactoryJanusTest method testGraphConfig.
@Test
public void testGraphConfig() throws InterruptedException {
JanusGraphManagement management = sharedGraph.openManagement();
// Test Composite Indices
String byId = "by" + Schema.VertexProperty.ID.name();
String byIndex = "by" + Schema.VertexProperty.INDEX.name();
String byValueString = "by" + Schema.VertexProperty.VALUE_STRING.name();
String byValueLong = "by" + Schema.VertexProperty.VALUE_LONG.name();
String byValueDouble = "by" + Schema.VertexProperty.VALUE_DOUBLE.name();
String byValueBoolean = "by" + Schema.VertexProperty.VALUE_BOOLEAN.name();
assertEquals(byId, management.getGraphIndex(byId).toString());
assertEquals(byIndex, management.getGraphIndex(byIndex).toString());
assertEquals(byValueString, management.getGraphIndex(byValueString).toString());
assertEquals(byValueLong, management.getGraphIndex(byValueLong).toString());
assertEquals(byValueDouble, management.getGraphIndex(byValueDouble).toString());
assertEquals(byValueBoolean, management.getGraphIndex(byValueBoolean).toString());
// Text Edge Indices
ResourceBundle keys = ResourceBundle.getBundle("indices-edges");
Set<String> keyString = keys.keySet();
for (String label : keyString) {
assertNotNull(management.getEdgeLabel(label));
}
// Test Properties
Arrays.stream(Schema.VertexProperty.values()).forEach(property -> assertNotNull(management.getPropertyKey(property.name())));
Arrays.stream(Schema.EdgeProperty.values()).forEach(property -> assertNotNull(management.getPropertyKey(property.name())));
// Test Labels
Arrays.stream(Schema.BaseType.values()).forEach(label -> assertNotNull(management.getVertexLabel(label.name())));
}
Aggregations