Skip to content

Commit

Permalink
Fixes #1088
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroecheler committed May 19, 2015
1 parent 9d1cb58 commit e818acc
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 34 deletions.
@@ -1,5 +1,6 @@
package com.thinkaurelius.titan.core.schema; package com.thinkaurelius.titan.core.schema;


import com.thinkaurelius.titan.core.Cardinality;
import com.thinkaurelius.titan.core.EdgeLabel; import com.thinkaurelius.titan.core.EdgeLabel;
import com.thinkaurelius.titan.core.PropertyKey; import com.thinkaurelius.titan.core.PropertyKey;
import com.thinkaurelius.titan.core.VertexLabel; import com.thinkaurelius.titan.core.VertexLabel;
Expand All @@ -25,7 +26,15 @@ public interface DefaultSchemaMaker {
* @return A new edge label * @return A new edge label
* @throws IllegalArgumentException if the name is already in use or if other configured values are invalid. * @throws IllegalArgumentException if the name is already in use or if other configured values are invalid.
*/ */
public EdgeLabel makeEdgeLabel(EdgeLabelMaker factory); public default EdgeLabel makeEdgeLabel(EdgeLabelMaker factory) {
return factory.directed().make();
}

/**
*
* @return the default cardinality of a property if created for the given key
*/
public Cardinality defaultPropertyCardinality(String key);


/** /**
* Creates a new property key with default settings against the provided {@link PropertyKeyMaker}. * Creates a new property key with default settings against the provided {@link PropertyKeyMaker}.
Expand All @@ -34,7 +43,9 @@ public interface DefaultSchemaMaker {
* @return A new property key * @return A new property key
* @throws IllegalArgumentException if the name is already in use or if other configured values are invalid. * @throws IllegalArgumentException if the name is already in use or if other configured values are invalid.
*/ */
public PropertyKey makePropertyKey(PropertyKeyMaker factory); public default PropertyKey makePropertyKey(PropertyKeyMaker factory) {
return factory.cardinality(defaultPropertyCardinality(factory.getName())).dataType(Object.class).make();
}


/** /**
* Creates a new vertex label with the default settings against the provided {@link VertexLabelMaker}. * Creates a new vertex label with the default settings against the provided {@link VertexLabelMaker}.
Expand All @@ -43,7 +54,9 @@ public interface DefaultSchemaMaker {
* @return A new vertex label * @return A new vertex label
* @throws IllegalArgumentException if the name is already in use or if other configured values are invalid. * @throws IllegalArgumentException if the name is already in use or if other configured values are invalid.
*/ */
public VertexLabel makeVertexLabel(VertexLabelMaker factory); public default VertexLabel makeVertexLabel(VertexLabelMaker factory) {
return factory.make();
}


/** /**
* Whether to ignore undefined types occurring in a query. * Whether to ignore undefined types occurring in a query.
Expand All @@ -54,4 +67,6 @@ public interface DefaultSchemaMaker {
*/ */
public boolean ignoreUndefinedQueryTypes(); public boolean ignoreUndefinedQueryTypes();




} }
Expand Up @@ -10,7 +10,7 @@
import com.thinkaurelius.titan.diskstorage.StandardIndexProvider; import com.thinkaurelius.titan.diskstorage.StandardIndexProvider;
import com.thinkaurelius.titan.diskstorage.StandardStoreManager; import com.thinkaurelius.titan.diskstorage.StandardStoreManager;
import com.thinkaurelius.titan.diskstorage.keycolumnvalue.ttl.TTLKCVSManager; import com.thinkaurelius.titan.diskstorage.keycolumnvalue.ttl.TTLKCVSManager;
import com.thinkaurelius.titan.graphdb.tinkerpop.BlueprintsDefaultSchemaMaker; import com.thinkaurelius.titan.graphdb.tinkerpop.TitanDefaultSchemaMaker;
import com.thinkaurelius.titan.graphdb.tinkerpop.Tp3DefaultSchemaMaker; import com.thinkaurelius.titan.graphdb.tinkerpop.Tp3DefaultSchemaMaker;
import com.thinkaurelius.titan.graphdb.database.management.ManagementSystem; import com.thinkaurelius.titan.graphdb.database.management.ManagementSystem;
import com.thinkaurelius.titan.graphdb.types.typemaker.DisableDefaultSchemaMaker; import com.thinkaurelius.titan.graphdb.types.typemaker.DisableDefaultSchemaMaker;
Expand Down Expand Up @@ -247,7 +247,7 @@ public class GraphDatabaseConfiguration {
public static final ConfigOption<String> AUTO_TYPE = new ConfigOption<String>(SCHEMA_NS,"default", public static final ConfigOption<String> AUTO_TYPE = new ConfigOption<String>(SCHEMA_NS,"default",
"Configures the DefaultSchemaMaker to be used by this graph. If set to 'none', automatic schema creation is disabled. " + "Configures the DefaultSchemaMaker to be used by this graph. If set to 'none', automatic schema creation is disabled. " +
"Defaults to a blueprints compatible schema maker with MULTI edge labels and SINGLE property keys", "Defaults to a blueprints compatible schema maker with MULTI edge labels and SINGLE property keys",
ConfigOption.Type.MASKABLE, "blueprints" , new Predicate<String>() { ConfigOption.Type.MASKABLE, "default" , new Predicate<String>() {
@Override @Override
public boolean apply(@Nullable String s) { public boolean apply(@Nullable String s) {
if (s==null) return false; if (s==null) return false;
Expand All @@ -263,7 +263,7 @@ public boolean apply(@Nullable String s) {


private static final Map<String, DefaultSchemaMaker> preregisteredAutoType = new HashMap<String, DefaultSchemaMaker>() {{ private static final Map<String, DefaultSchemaMaker> preregisteredAutoType = new HashMap<String, DefaultSchemaMaker>() {{
put("none", DisableDefaultSchemaMaker.INSTANCE); put("none", DisableDefaultSchemaMaker.INSTANCE);
put("blueprints", BlueprintsDefaultSchemaMaker.INSTANCE); put("default", TitanDefaultSchemaMaker.INSTANCE);
put("tp3", Tp3DefaultSchemaMaker.INSTANCE); put("tp3", Tp3DefaultSchemaMaker.INSTANCE);
}}; }};


Expand Down
Expand Up @@ -11,27 +11,18 @@
* *
* @author Matthias Broecheler (me@matthiasb.com) * @author Matthias Broecheler (me@matthiasb.com)
*/ */
public class BlueprintsDefaultSchemaMaker implements DefaultSchemaMaker { public class TitanDefaultSchemaMaker implements DefaultSchemaMaker {


public static final DefaultSchemaMaker INSTANCE = new BlueprintsDefaultSchemaMaker(); public static final DefaultSchemaMaker INSTANCE = new TitanDefaultSchemaMaker();


private BlueprintsDefaultSchemaMaker() { private TitanDefaultSchemaMaker() {
} }


@Override @Override
public EdgeLabel makeEdgeLabel(EdgeLabelMaker factory) { public Cardinality defaultPropertyCardinality(String key) {
return factory.directed().make(); return Cardinality.SINGLE;
} }


@Override
public PropertyKey makePropertyKey(PropertyKeyMaker factory) {
return factory.dataType(Object.class).make();
}

@Override
public VertexLabel makeVertexLabel(VertexLabelMaker factory) {
return factory.make();
}


@Override @Override
public boolean ignoreUndefinedQueryTypes() { public boolean ignoreUndefinedQueryTypes() {
Expand Down
Expand Up @@ -4,6 +4,7 @@
import com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreFeatures; import com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreFeatures;
import com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration; import com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration;
import com.thinkaurelius.titan.graphdb.database.StandardTitanGraph; import com.thinkaurelius.titan.graphdb.database.StandardTitanGraph;
import com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx;
import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.VertexProperty; import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory; import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
Expand Down Expand Up @@ -147,9 +148,9 @@ private class TitanVertexFeatures implements VertexFeatures {


@Override @Override
public VertexProperty.Cardinality getCardinality(final String key) { public VertexProperty.Cardinality getCardinality(final String key) {
TitanTransaction tx = TitanFeatures.this.graph.newTransaction(); StandardTitanTx tx = (StandardTitanTx)TitanFeatures.this.graph.newTransaction();
try { try {
if (!tx.containsPropertyKey(key)) return VertexProperty.Cardinality.list; //DEFAULT if (!tx.containsPropertyKey(key)) return tx.getConfiguration().getAutoSchemaMaker().defaultPropertyCardinality(key).convert();
return tx.getPropertyKey(key).cardinality().convert(); return tx.getPropertyKey(key).cardinality().convert();
} finally { } finally {
tx.rollback(); tx.rollback();
Expand Down
Expand Up @@ -20,18 +20,8 @@ private Tp3DefaultSchemaMaker() {
} }


@Override @Override
public EdgeLabel makeEdgeLabel(EdgeLabelMaker factory) { public Cardinality defaultPropertyCardinality(String key) {
return factory.directed().make(); return Cardinality.LIST;
}

@Override
public PropertyKey makePropertyKey(PropertyKeyMaker factory) {
return factory.cardinality(Cardinality.LIST).dataType(Object.class).make();
}

@Override
public VertexLabel makeVertexLabel(VertexLabelMaker factory) {
return factory.make();
} }


@Override @Override
Expand Down
Expand Up @@ -22,6 +22,11 @@ public EdgeLabel makeEdgeLabel(EdgeLabelMaker factory) {
throw new IllegalArgumentException("Edge Label with given name does not exist: " + factory.getName()); throw new IllegalArgumentException("Edge Label with given name does not exist: " + factory.getName());
} }


@Override
public Cardinality defaultPropertyCardinality(String key) {
return Cardinality.SINGLE;
}

@Override @Override
public PropertyKey makePropertyKey(PropertyKeyMaker factory) { public PropertyKey makePropertyKey(PropertyKeyMaker factory) {
throw new IllegalArgumentException("Property Key with given name does not exist: " + factory.getName()); throw new IllegalArgumentException("Property Key with given name does not exist: " + factory.getName());
Expand Down

0 comments on commit e818acc

Please sign in to comment.