diff --git a/titan-core/src/main/java/com/thinkaurelius/titan/core/schema/DefaultSchemaMaker.java b/titan-core/src/main/java/com/thinkaurelius/titan/core/schema/DefaultSchemaMaker.java index 8245cbd4ea..13f2b1da25 100644 --- a/titan-core/src/main/java/com/thinkaurelius/titan/core/schema/DefaultSchemaMaker.java +++ b/titan-core/src/main/java/com/thinkaurelius/titan/core/schema/DefaultSchemaMaker.java @@ -47,6 +47,10 @@ public default PropertyKey makePropertyKey(PropertyKeyMaker factory) { return factory.cardinality(defaultPropertyCardinality(factory.getName())).dataType(Object.class).make(); } + public default PropertyKey makePropertyKey(PropertyKeyMaker factory, Object value) { + return makePropertyKey(factory); + } + /** * Creates a new vertex label with the default settings against the provided {@link VertexLabelMaker}. * diff --git a/titan-core/src/main/java/com/thinkaurelius/titan/core/schema/SchemaInspector.java b/titan-core/src/main/java/com/thinkaurelius/titan/core/schema/SchemaInspector.java index 1acaf6e869..cb56562f85 100644 --- a/titan-core/src/main/java/com/thinkaurelius/titan/core/schema/SchemaInspector.java +++ b/titan-core/src/main/java/com/thinkaurelius/titan/core/schema/SchemaInspector.java @@ -53,6 +53,10 @@ public interface SchemaInspector { */ public PropertyKey getOrCreatePropertyKey(String name); + public default PropertyKey getOrCreatePropertyKey(String name, Object value) { + return getOrCreatePropertyKey(name); + } + /** * Returns the property key with the given name. If it does not exist, NULL is returned * diff --git a/titan-core/src/main/java/com/thinkaurelius/titan/graphdb/transaction/StandardTitanTx.java b/titan-core/src/main/java/com/thinkaurelius/titan/graphdb/transaction/StandardTitanTx.java index 7f6f96fd54..63fc981332 100644 --- a/titan-core/src/main/java/com/thinkaurelius/titan/graphdb/transaction/StandardTitanTx.java +++ b/titan-core/src/main/java/com/thinkaurelius/titan/graphdb/transaction/StandardTitanTx.java @@ -927,6 +927,17 @@ public PropertyKey getOrCreatePropertyKey(String name) { throw new IllegalArgumentException("The type of given name is not a key: " + name); } + @Override + public PropertyKey getOrCreatePropertyKey(String name, Object value) { + RelationType et = getRelationType(name); + if (et == null) { + return config.getAutoSchemaMaker().makePropertyKey(makePropertyKey(name), value); + } else if (et.isPropertyKey()) { + return (PropertyKey) et; + } else + throw new IllegalArgumentException("The type of given name is not a key: " + name); + } + @Override public EdgeLabel getEdgeLabel(String name) { RelationType el = getRelationType(name); diff --git a/titan-core/src/main/java/com/thinkaurelius/titan/graphdb/vertices/AbstractVertex.java b/titan-core/src/main/java/com/thinkaurelius/titan/graphdb/vertices/AbstractVertex.java index 01981956b4..a621deb3c8 100644 --- a/titan-core/src/main/java/com/thinkaurelius/titan/graphdb/vertices/AbstractVertex.java +++ b/titan-core/src/main/java/com/thinkaurelius/titan/graphdb/vertices/AbstractVertex.java @@ -132,14 +132,14 @@ public O valueOrNull(PropertyKey key) { */ public TitanVertexProperty property(final String key, final V value, final Object... keyValues) { - TitanVertexProperty p = tx().addProperty(it(), tx().getOrCreatePropertyKey(key), value); + TitanVertexProperty p = tx().addProperty(it(), tx().getOrCreatePropertyKey(key, value), value); ElementHelper.attachProperties(p,keyValues); return p; } @Override public TitanVertexProperty property(final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) { - TitanVertexProperty p = tx().addProperty(cardinality, it(), tx().getOrCreatePropertyKey(key), value); + TitanVertexProperty p = tx().addProperty(cardinality, it(), tx().getOrCreatePropertyKey(key, value), value); ElementHelper.attachProperties(p,keyValues); return p; }