Java Code Examples for com.thinkaurelius.titan.core.schema.TitanManagement#IndexBuilder

The following examples show how to use com.thinkaurelius.titan.core.schema.TitanManagement#IndexBuilder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ManagementSystem.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
public TitanManagement.IndexBuilder indexOnly(TitanSchemaType schemaType) {
    Preconditions.checkNotNull(schemaType);
    Preconditions.checkArgument(elementCategory.isValidConstraint(schemaType), "Need to specify a valid schema type for this index definition: %s", schemaType);
    constraint = schemaType;
    return this;
}
 
Example 2
Source File: Titan1GraphManagement.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void createVertexIndex(String propertyName, String backingIndex, List<AtlasPropertyKey> propertyKeys) {

    TitanManagement.IndexBuilder indexBuilder = management.buildIndex(propertyName, Vertex.class);
    for (AtlasPropertyKey key : propertyKeys) {
        PropertyKey titanKey = TitanObjectFactory.createPropertyKey(key);
        indexBuilder.addKey(titanKey);
    }
    indexBuilder.buildMixedIndex(backingIndex);
}
 
Example 3
Source File: Titan1GraphManagement.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public void createExactMatchVertexIndex(String propertyName, boolean enforceUniqueness,
                                  List<AtlasPropertyKey> propertyKeys) {

    TitanManagement.IndexBuilder indexBuilder = management.buildIndex(propertyName, Vertex.class);
    for (AtlasPropertyKey key : propertyKeys) {
        PropertyKey titanKey = TitanObjectFactory.createPropertyKey(key);
        indexBuilder.addKey(titanKey);
    }
    if (enforceUniqueness) {
        indexBuilder.unique();
    }
    indexBuilder.buildCompositeIndex();
}
 
Example 4
Source File: Titan0GraphManagement.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void createExactMatchIndex(String propertyName, boolean enforceUniqueness,
        List<AtlasPropertyKey> propertyKeys) {

    TitanManagement.IndexBuilder indexBuilder = management.buildIndex(propertyName, Vertex.class);
    for(AtlasPropertyKey key : propertyKeys) {
        PropertyKey titanKey = TitanObjectFactory.createPropertyKey(key);
        indexBuilder.addKey(titanKey);
    }
    if (enforceUniqueness) {
        indexBuilder.unique();
    }
    indexBuilder.buildCompositeIndex();
}
 
Example 5
Source File: Titan0GraphManagement.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void createVertexIndex(String propertyName, String backingIndex, List<AtlasPropertyKey> propertyKeys) {

    TitanManagement.IndexBuilder indexBuilder = management.buildIndex(propertyName, Vertex.class);
    for(AtlasPropertyKey key : propertyKeys) {
        PropertyKey titanKey = TitanObjectFactory.createPropertyKey(key);
        indexBuilder.addKey(titanKey);
    }
    indexBuilder.buildMixedIndex(backingIndex);
}
 
Example 6
Source File: GraphOfTheGodsFactory.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public static void load(final TitanGraph graph, String mixedIndexName, boolean uniqueNameCompositeIndex) {

        //Create Schema
        TitanManagement mgmt = graph.openManagement();
        final PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
        TitanManagement.IndexBuilder nameIndexBuilder = mgmt.buildIndex("name", Vertex.class).addKey(name);
        if (uniqueNameCompositeIndex)
            nameIndexBuilder.unique();
        TitanGraphIndex namei = nameIndexBuilder.buildCompositeIndex();
        mgmt.setConsistency(namei, ConsistencyModifier.LOCK);
        final PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make();
        if (null != mixedIndexName)
            mgmt.buildIndex("vertices", Vertex.class).addKey(age).buildMixedIndex(mixedIndexName);

        final PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).make();
        final PropertyKey reason = mgmt.makePropertyKey("reason").dataType(String.class).make();
        final PropertyKey place = mgmt.makePropertyKey("place").dataType(Geoshape.class).make();
        if (null != mixedIndexName)
            mgmt.buildIndex("edges", Edge.class).addKey(reason).addKey(place).buildMixedIndex(mixedIndexName);

        mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make();
        mgmt.makeEdgeLabel("mother").multiplicity(Multiplicity.MANY2ONE).make();
        EdgeLabel battled = mgmt.makeEdgeLabel("battled").signature(time).make();
        mgmt.buildEdgeIndex(battled, "battlesByTime", Direction.BOTH, Order.decr, time);
        mgmt.makeEdgeLabel("lives").signature(reason).make();
        mgmt.makeEdgeLabel("pet").make();
        mgmt.makeEdgeLabel("brother").make();

        mgmt.makeVertexLabel("titan").make();
        mgmt.makeVertexLabel("location").make();
        mgmt.makeVertexLabel("god").make();
        mgmt.makeVertexLabel("demigod").make();
        mgmt.makeVertexLabel("human").make();
        mgmt.makeVertexLabel("monster").make();

        mgmt.commit();

        TitanTransaction tx = graph.newTransaction();
        // vertices

        Vertex saturn = tx.addVertex(T.label, "titan", "name", "saturn", "age", 10000);

        Vertex sky = tx.addVertex(T.label, "location", "name", "sky");

        Vertex sea = tx.addVertex(T.label, "location", "name", "sea");

        Vertex jupiter = tx.addVertex(T.label, "god", "name", "jupiter", "age", 5000);

        Vertex neptune = tx.addVertex(T.label, "god", "name", "neptune", "age", 4500);

        Vertex hercules = tx.addVertex(T.label, "demigod", "name", "hercules", "age", 30);

        Vertex alcmene = tx.addVertex(T.label, "human", "name", "alcmene", "age", 45);

        Vertex pluto = tx.addVertex(T.label, "god", "name", "pluto", "age", 4000);

        Vertex nemean = tx.addVertex(T.label, "monster", "name", "nemean");

        Vertex hydra = tx.addVertex(T.label, "monster", "name", "hydra");

        Vertex cerberus = tx.addVertex(T.label, "monster", "name", "cerberus");

        Vertex tartarus = tx.addVertex(T.label, "location", "name", "tartarus");

        // edges

        jupiter.addEdge("father", saturn);
        jupiter.addEdge("lives", sky, "reason", "loves fresh breezes");
        jupiter.addEdge("brother", neptune);
        jupiter.addEdge("brother", pluto);

        neptune.addEdge("lives", sea).property("reason", "loves waves");
        neptune.addEdge("brother", jupiter);
        neptune.addEdge("brother", pluto);

        hercules.addEdge("father", jupiter);
        hercules.addEdge("mother", alcmene);
        hercules.addEdge("battled", nemean, "time", 1, "place", Geoshape.point(38.1f, 23.7f));
        hercules.addEdge("battled", hydra, "time", 2, "place", Geoshape.point(37.7f, 23.9f));
        hercules.addEdge("battled", cerberus, "time", 12, "place", Geoshape.point(39f, 22f));

        pluto.addEdge("brother", jupiter);
        pluto.addEdge("brother", neptune);
        pluto.addEdge("lives", tartarus, "reason", "no fear of death");
        pluto.addEdge("pet", cerberus);

        cerberus.addEdge("lives", tartarus);

        // commit the transaction to disk
        tx.commit();
    }
 
Example 7
Source File: ManagementSystem.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public TitanManagement.IndexBuilder buildIndex(String indexName, Class<? extends Element> elementType) {
    return new IndexBuilder(indexName, ElementCategory.getByClazz(elementType));
}
 
Example 8
Source File: ManagementSystem.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public TitanManagement.IndexBuilder addKey(PropertyKey key) {
    Preconditions.checkArgument(key != null && (key instanceof PropertyKeyVertex), "Key must be a user defined key: %s", key);
    keys.put(key, null);
    return this;
}
 
Example 9
Source File: ManagementSystem.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public TitanManagement.IndexBuilder addKey(PropertyKey key, Parameter... parameters) {
    Preconditions.checkArgument(key != null && (key instanceof PropertyKeyVertex), "Key must be a user defined key: %s", key);
    keys.put(key, parameters);
    return this;
}
 
Example 10
Source File: ManagementSystem.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public TitanManagement.IndexBuilder unique() {
    unique = true;
    return this;
}