/** * 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(); }
@Override public PropertyKey makePropertyKey(PropertyKeyMaker factory, Object value) { String name = factory.getName(); Class actualClass = determineClass(value); return factory.cardinality(defaultPropertyCardinality(name)).dataType(actualClass).make(); }
@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); }
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; }
@Before public void setup() { GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true); JanusGraphManagement management = graph.openManagement(); management.makePropertyKey("shape").dataType(Geoshape.class).make(); management.commit(); }
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(); }
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; }
@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 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 testAllowDisablingSchemaConstraintForVertexProperty() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), false); mgmt.makeVertexLabel("user").make(); mgmt.makePropertyKey("test").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); finishSchema(); JanusGraphVertex v = tx.addVertex("user"); v.property("test", 10); }
@Test public void testBanListCardinalityForEdgeProperties() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); EdgeLabel edge = mgmt.makeEdgeLabel("knows").make(); try { PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.LIST).dataType(Integer.class).make(); mgmt.addProperties(edge, id); fail("This should never reached!"); } catch (IllegalArgumentException ignored) { } finishSchema(); }
@Test public void testBanSetCardinalityForEdgeProperties() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); EdgeLabel edge = mgmt.makeEdgeLabel("knows").make(); try { PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SET).dataType(Integer.class).make(); mgmt.addProperties(edge, id); fail("This should never reached!"); } catch (IllegalArgumentException ignored) { } finishSchema(); }
@Test public void testIndexShouldNotBeEnabledForExistingPropertyKeyWithoutLabelConstraint() { mgmt.makePropertyKey("alreadyExistingProperty").dataType(String.class).cardinality(Cardinality.SINGLE).make(); finishSchema(); PropertyKey existingPropertyKey = mgmt.getPropertyKey("alreadyExistingProperty"); mgmt.buildIndex("newIndex", Vertex.class).addKey(existingPropertyKey).buildCompositeIndex(); finishSchema(); assertNotEquals(SchemaStatus.ENABLED, mgmt.getGraphIndex("newIndex").getIndexStatus(existingPropertyKey)); }
@Test public void testSupportDirectCommitOfSchemaChangesForVertexProperties() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); GraphTraversalSource g = graph.traversal(); VertexLabel label = mgmt.makeVertexLabel("user").make(); PropertyKey prop = mgmt.makePropertyKey("id").dataType(Integer.class).make(); mgmt.addProperties(label, prop); mgmt.commit(); g.addV("user").property("id", 10).iterate(); }
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; }
@Test public void testAllowDisablingSchemaConstraintForEdgeProperty() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), false); mgmt.makeVertexLabel("user").make(); mgmt.makeEdgeLabel("knows").make(); mgmt.makePropertyKey("test").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); finishSchema(); JanusGraphVertex v1 = tx.addVertex("user"); JanusGraphVertex v2 = tx.addVertex("user"); v1.addEdge("knows", v2, "test", 10); }
@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)); }
@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 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)); }