Search in sources :

Example 21 with TitanManagement

use of com.thinkaurelius.titan.core.schema.TitanManagement in project titan by thinkaurelius.

the class AbstractTitanGraphProvider method createIndices.

private void createIndices(final TitanGraph g, final LoadGraphWith.GraphData graphData) {
    TitanManagement mgmt = g.openManagement();
    if (graphData.equals(LoadGraphWith.GraphData.GRATEFUL)) {
        VertexLabel artist = mgmt.makeVertexLabel("artist").make();
        VertexLabel song = mgmt.makeVertexLabel("song").make();
        PropertyKey name = mgmt.makePropertyKey("name").cardinality(Cardinality.LIST).dataType(String.class).make();
        PropertyKey songType = mgmt.makePropertyKey("songType").cardinality(Cardinality.LIST).dataType(String.class).make();
        PropertyKey performances = mgmt.makePropertyKey("performances").cardinality(Cardinality.LIST).dataType(Integer.class).make();
        mgmt.buildIndex("artistByName", Vertex.class).addKey(name).indexOnly(artist).buildCompositeIndex();
        mgmt.buildIndex("songByName", Vertex.class).addKey(name).indexOnly(song).buildCompositeIndex();
        mgmt.buildIndex("songByType", Vertex.class).addKey(songType).indexOnly(song).buildCompositeIndex();
        mgmt.buildIndex("songByPerformances", Vertex.class).addKey(performances).indexOnly(song).buildCompositeIndex();
    } else if (graphData.equals(LoadGraphWith.GraphData.MODERN)) {
        VertexLabel person = mgmt.makeVertexLabel("person").make();
        VertexLabel software = mgmt.makeVertexLabel("software").make();
        PropertyKey name = mgmt.makePropertyKey("name").cardinality(Cardinality.LIST).dataType(String.class).make();
        PropertyKey lang = mgmt.makePropertyKey("lang").cardinality(Cardinality.LIST).dataType(String.class).make();
        PropertyKey age = mgmt.makePropertyKey("age").cardinality(Cardinality.LIST).dataType(Integer.class).make();
        mgmt.buildIndex("personByName", Vertex.class).addKey(name).indexOnly(person).buildCompositeIndex();
        mgmt.buildIndex("softwareByName", Vertex.class).addKey(name).indexOnly(software).buildCompositeIndex();
        mgmt.buildIndex("personByAge", Vertex.class).addKey(age).indexOnly(person).buildCompositeIndex();
        mgmt.buildIndex("softwareByLang", Vertex.class).addKey(lang).indexOnly(software).buildCompositeIndex();
    } else if (graphData.equals(LoadGraphWith.GraphData.CLASSIC)) {
        PropertyKey name = mgmt.makePropertyKey("name").cardinality(Cardinality.LIST).dataType(String.class).make();
        PropertyKey lang = mgmt.makePropertyKey("lang").cardinality(Cardinality.LIST).dataType(String.class).make();
        PropertyKey age = mgmt.makePropertyKey("age").cardinality(Cardinality.LIST).dataType(Integer.class).make();
        mgmt.buildIndex("byName", Vertex.class).addKey(name).buildCompositeIndex();
        mgmt.buildIndex("byAge", Vertex.class).addKey(age).buildCompositeIndex();
        mgmt.buildIndex("byLang", Vertex.class).addKey(lang).buildCompositeIndex();
    } else {
    // TODO: add CREW work here.
    // TODO: add meta_property indices when meta_property graph is provided
    //throw new RuntimeException("Could not load graph with " + graphData);
    }
    mgmt.commit();
}
Also used : CacheVertex(com.thinkaurelius.titan.graphdb.vertices.CacheVertex) TitanSchemaVertex(com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex) PropertyKeyVertex(com.thinkaurelius.titan.graphdb.types.vertices.PropertyKeyVertex) PreloadedVertex(com.thinkaurelius.titan.graphdb.vertices.PreloadedVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) EdgeLabelVertex(com.thinkaurelius.titan.graphdb.types.vertices.EdgeLabelVertex) EmptyVertex(com.thinkaurelius.titan.graphdb.types.system.EmptyVertex) StandardVertex(com.thinkaurelius.titan.graphdb.vertices.StandardVertex) VertexLabelVertex(com.thinkaurelius.titan.graphdb.types.VertexLabelVertex) VertexLabel(com.thinkaurelius.titan.core.VertexLabel) TitanManagement(com.thinkaurelius.titan.core.schema.TitanManagement) PropertyKey(com.thinkaurelius.titan.core.PropertyKey)

Aggregations

TitanManagement (com.thinkaurelius.titan.core.schema.TitanManagement)21 Test (org.junit.Test)8 TitanGraphBaseTest (com.thinkaurelius.titan.graphdb.TitanGraphBaseTest)7 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)6 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)6 ScanMetrics (com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.ScanMetrics)5 StandardTitanGraph (com.thinkaurelius.titan.graphdb.database.StandardTitanGraph)5 RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)4 EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)3 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)3 RelationType (com.thinkaurelius.titan.core.RelationType)2 TitanException (com.thinkaurelius.titan.core.TitanException)2 TitanGraph (com.thinkaurelius.titan.core.TitanGraph)2 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)2 SchemaStatus (com.thinkaurelius.titan.core.schema.SchemaStatus)2 Timer (com.thinkaurelius.titan.diskstorage.util.time.Timer)2 HashMap (java.util.HashMap)2 Function (com.google.common.base.Function)1 TitanEdge (com.thinkaurelius.titan.core.TitanEdge)1 TitanTransaction (com.thinkaurelius.titan.core.TitanTransaction)1