Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add signatures for value-based type defaults #1270

Open
wants to merge 1 commit into
base: titan10
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ public <O> O valueOrNull(PropertyKey key) {
*/

public<V> TitanVertexProperty<V> property(final String key, final V value, final Object... keyValues) {
TitanVertexProperty<V> p = tx().addProperty(it(), tx().getOrCreatePropertyKey(key), value);
TitanVertexProperty<V> p = tx().addProperty(it(), tx().getOrCreatePropertyKey(key, value), value);
ElementHelper.attachProperties(p,keyValues);
return p;
}

@Override
public <V> TitanVertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) {
TitanVertexProperty<V> p = tx().addProperty(cardinality, it(), tx().getOrCreatePropertyKey(key), value);
TitanVertexProperty<V> p = tx().addProperty(cardinality, it(), tx().getOrCreatePropertyKey(key, value), value);
ElementHelper.attachProperties(p,keyValues);
return p;
}
Expand Down