public PropertyKey makeVertexIndexedUniqueKey(String name, Class dataType) { final PropertyKey key = mgmt.makePropertyKey(name).dataType(dataType).cardinality(Cardinality.SINGLE).make(); mgmt.buildIndex(name,Vertex.class).addKey(key).unique().buildCompositeIndex(); return key; }
/** * Creates a new property key with default settings against the provided {@link PropertyKeyMaker}. * * @param factory PropertyKeyMaker through which the property key is created * @return A new property key * @throws IllegalArgumentException if the name is already in use or if other configured values are invalid. */ default PropertyKey makePropertyKey(PropertyKeyMaker factory) { return factory.cardinality(defaultPropertyCardinality(factory.getName())).dataType(Object.class).make(); }
public PropertyKey makeKey(String name, Class dataType) { return mgmt.makePropertyKey(name).dataType(dataType).cardinality(Cardinality.SINGLE).make(); }
@Test public void testIndexShouldNotBeEnabledForExistingPropertyKeyAndConstrainedToExistingEdgeLabel() { mgmt.makePropertyKey("alreadyExistingProperty").dataType(String.class).cardinality(Cardinality.SINGLE).make(); mgmt.makeEdgeLabel("alreadyExistingLabel").make(); finishSchema(); PropertyKey existingPropertyKey = mgmt.getPropertyKey("alreadyExistingProperty"); EdgeLabel existingLabel = mgmt.getEdgeLabel("alreadyExistingLabel"); mgmt.buildIndex("newIndex", Edge.class).addKey(existingPropertyKey).indexOnly(existingLabel).buildCompositeIndex(); finishSchema(); assertNotEquals(SchemaStatus.ENABLED, mgmt.getGraphIndex("newIndex").getIndexStatus(existingPropertyKey)); }
@Test public void testIndexShouldNotBeEnabledForExistingPropertyKeyAndConstrainedToExistingVertexLabel() { mgmt.makePropertyKey("alreadyExistingProperty").dataType(String.class).cardinality(Cardinality.SINGLE).make(); mgmt.makeVertexLabel("alreadyExistingLabel").make(); finishSchema(); PropertyKey existingPropertyKey = mgmt.getPropertyKey("alreadyExistingProperty"); VertexLabel existingLabel = mgmt.getVertexLabel("alreadyExistingLabel"); mgmt.buildIndex("newIndex", Vertex.class).addKey(existingPropertyKey).indexOnly(existingLabel).buildCompositeIndex(); finishSchema(); assertNotEquals(SchemaStatus.ENABLED, mgmt.getGraphIndex("newIndex").getIndexStatus(existingPropertyKey)); }
private void createStrictSchemaForEdgeProperties() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); VertexLabel user = mgmt.makeVertexLabel("user").make(); EdgeLabel edge = mgmt.makeEdgeLabel("knows").make(); PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); mgmt.makePropertyKey("test").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); mgmt.addProperties(edge, id); mgmt.addConnection(edge, user, user); finishSchema(); }
@Test public void testOrPartialIndex() { final PropertyKey nameProperty = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make(); mgmt.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); final PropertyKey lengthProperty = mgmt.makePropertyKey("length").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); mgmt.buildIndex("otheridx", Vertex.class).addKey(nameProperty, getStringMapping()).addKey(lengthProperty).buildMixedIndex(INDEX); finishSchema(); clopen(); testOr(graph); }
@Test public void testAllowSingleCardinalityForEdgeProperties() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); EdgeLabel edge = mgmt.makeEdgeLabel("knows").make(); PropertyKey propertyKey1 = mgmt.makePropertyKey("propertyKey1").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); mgmt.addProperties(edge, propertyKey1); PropertyKey propertyKey2 = mgmt.makePropertyKey("propertyKey2").dataType(Integer.class).make(); mgmt.addProperties(edge, propertyKey2); finishSchema(); }
private void createStrictSchemaForVertexProperties() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); VertexLabel label = mgmt.makeVertexLabel("user").make(); PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); mgmt.makePropertyKey("test").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); mgmt.addProperties(label, id); finishSchema(); }
private void createStrictSchemaForConnections() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); VertexLabel user = mgmt.makeVertexLabel("user").make(); VertexLabel company = mgmt.makeVertexLabel("company").make(); EdgeLabel edge = mgmt.makeEdgeLabel("knows").make(); mgmt.makeEdgeLabel("buys").make(); mgmt.addConnection(edge, user, company); finishSchema(); }
public EdgeLabel makeLabel(String name) { return mgmt.makeEdgeLabel(name).make(); }
/** * Creates a new edge label with default settings against the provided {@link EdgeLabelMaker}. * * @param factory EdgeLabelMaker through which the edge label is created * @return A new edge label * @throws IllegalArgumentException if the name is already in use or if other configured values are invalid. */ default EdgeLabel makeEdgeLabel(EdgeLabelMaker factory) { return factory.directed().make(); }
private String getIndexType(JanusGraphIndex index) { String type; if (index.isCompositeIndex()) { type = "Composite"; } else if (index.isMixedIndex()) { type = "Mixed"; } else { type = "Unknown"; } return type; }
/** * Creates a new property key with default settings against the provided {@link PropertyKeyMaker} and value. * * @param factory PropertyKeyMaker through which the property key is created * @param value the value of the property. The default implementation does not use this parameter. * @return A new property key * @throws IllegalArgumentException if the name is already in use or if other configured values are invalid. */ default PropertyKey makePropertyKey(PropertyKeyMaker factory, Object value) { return makePropertyKey(factory); }
/** * Add a constraint on which vertices the given edge label can connect using the schema manager. * * @param edgeLabel to which the constraint applies. * @param outVLabel specifies the outgoing vertex for this connection. * @param inVLabel specifies the incoming vertex for this connection. * @param manager is used to update the schema. * @see org.janusgraph.core.schema.SchemaManager */ default void makeConnectionConstraint(EdgeLabel edgeLabel, VertexLabel outVLabel, VertexLabel inVLabel, SchemaManager manager) { manager.addConnection(edgeLabel, outVLabel, inVLabel); }
/** * Add property constraints for a given edge label using the schema manager. * * @param edgeLabel to which the constraint applies. * @param key defines the property which should be added to the edge label as a constraint. * @param manager is used to update the schema. * @see org.janusgraph.core.schema.SchemaManager */ default void makePropertyConstraintForEdge(EdgeLabel edgeLabel, PropertyKey key, SchemaManager manager) { manager.addProperties(edgeLabel, key); }
@Test public void testIndexShouldBeEnabledForExistingPropertyKeyAndConstrainedToNewEdgeLabel() { mgmt.makePropertyKey("alreadyExistingProperty").dataType(String.class).cardinality(Cardinality.SINGLE).make(); finishSchema(); PropertyKey existingPropertyKey = mgmt.getPropertyKey("alreadyExistingProperty"); EdgeLabel newLabel = mgmt.makeEdgeLabel("newLabel").make(); mgmt.buildIndex("newIndex", Edge.class).addKey(existingPropertyKey).indexOnly(newLabel).buildCompositeIndex(); finishSchema(); assertEquals(SchemaStatus.ENABLED, mgmt.getGraphIndex("newIndex").getIndexStatus(existingPropertyKey)); }
@Test public void testIndexShouldBeEnabledForExistingPropertyKeyAndConstrainedToNewVertexLabel() { mgmt.makePropertyKey("alreadyExistingProperty").dataType(String.class).cardinality(Cardinality.SINGLE).make(); finishSchema(); PropertyKey existingPropertyKey = mgmt.getPropertyKey("alreadyExistingProperty"); VertexLabel newLabel = mgmt.makeVertexLabel("newLabel").make(); mgmt.buildIndex("newIndex", Vertex.class).addKey(existingPropertyKey).indexOnly(newLabel).buildCompositeIndex(); finishSchema(); assertEquals(SchemaStatus.ENABLED, mgmt.getGraphIndex("newIndex").getIndexStatus(existingPropertyKey)); }
private GraphTraversalSource prepareGraphForDirectCommitTests() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); GraphTraversalSource g = graph.traversal(); VertexLabel user = mgmt.makeVertexLabel("user").make(); EdgeLabel edge = mgmt.makeEdgeLabel("knows").make(); PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); mgmt.addProperties(edge, id); mgmt.addConnection(edge, user, user); mgmt.commit(); return g; }
public PropertyKey makeVertexIndexedKey(String name, Class dataType) { final PropertyKey key = mgmt.makePropertyKey(name).dataType(dataType).cardinality(Cardinality.SINGLE).make(); mgmt.buildIndex(name,Vertex.class).addKey(key).buildCompositeIndex(); return key; }