Java Code Examples for com.thinkaurelius.titan.core.VertexLabel

The following are top voted examples for showing how to use com.thinkaurelius.titan.core.VertexLabel. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: titan1withtp3.1   File: SchemaContainer.java   Source Code and License 6 votes vote down vote up
public SchemaContainer(TitanGraph graph) {
    vertexLabels = Maps.newHashMap();
    relationTypes = Maps.newHashMap();
    TitanManagement mgmt = graph.openManagement();

    try {
        for (VertexLabel vl : mgmt.getVertexLabels()) {
            VertexLabelDefinition vld = new VertexLabelDefinition(vl);
            vertexLabels.put(vld.getName(),vld);
        }

        for (EdgeLabel el : mgmt.getRelationTypes(EdgeLabel.class)) {
            EdgeLabelDefinition eld = new EdgeLabelDefinition(el);
            relationTypes.put(eld.getName(),eld);
        }
        for (PropertyKey pk : mgmt.getRelationTypes(PropertyKey.class)) {
            PropertyKeyDefinition pkd = new PropertyKeyDefinition(pk);
            relationTypes.put(pkd.getName(), pkd);
        }
    } finally {
        mgmt.rollback();
    }

}
 
Example 2
Project: titan1.0.1.kafka   File: SchemaContainer.java   Source Code and License 6 votes vote down vote up
public SchemaContainer(TitanGraph graph) {
    vertexLabels = Maps.newHashMap();
    relationTypes = Maps.newHashMap();
    TitanManagement mgmt = graph.openManagement();

    try {
        for (VertexLabel vl : mgmt.getVertexLabels()) {
            VertexLabelDefinition vld = new VertexLabelDefinition(vl);
            vertexLabels.put(vld.getName(),vld);
        }

        for (EdgeLabel el : mgmt.getRelationTypes(EdgeLabel.class)) {
            EdgeLabelDefinition eld = new EdgeLabelDefinition(el);
            relationTypes.put(eld.getName(),eld);
        }
        for (PropertyKey pk : mgmt.getRelationTypes(PropertyKey.class)) {
            PropertyKeyDefinition pkd = new PropertyKeyDefinition(pk);
            relationTypes.put(pkd.getName(), pkd);
        }
    } finally {
        mgmt.rollback();
    }

}
 
Example 3
Project: titan0.5.4-hbase1.1.1-custom   File: SchemaContainer.java   Source Code and License 6 votes vote down vote up
public SchemaContainer(TitanGraph graph) {
    vertexLabels = Maps.newHashMap();
    relationTypes = Maps.newHashMap();
    TitanManagement mgmt = graph.getManagementSystem();

    try {
        for (VertexLabel vl : mgmt.getVertexLabels()) {
            VertexLabelDefinition vld = new VertexLabelDefinition(vl);
            vertexLabels.put(vld.getName(),vld);
        }

        for (EdgeLabel el : mgmt.getRelationTypes(EdgeLabel.class)) {
            EdgeLabelDefinition eld = new EdgeLabelDefinition(el);
            relationTypes.put(eld.getName(),eld);
        }
        for (PropertyKey pk : mgmt.getRelationTypes(PropertyKey.class)) {
            PropertyKeyDefinition pkd = new PropertyKeyDefinition(pk);
            relationTypes.put(pkd.getName(), pkd);
        }
    } finally {
        mgmt.rollback();
    }

}
 
Example 4
Project: keti   File: GraphConfig.java   Source Code and License 5 votes vote down vote up
public static void createUniqueIndexForLabel(final Graph newGraph, final String indexName, final String indexKey,
        final String label) throws InterruptedException {
    newGraph.tx().rollback(); // Never create new indexes while a transaction is active
    TitanManagement mgmt = ((TitanGraph) newGraph).openManagement();
    if (!mgmt.containsGraphIndex(indexName)) {
        PropertyKey indexPropertyKey = mgmt.makePropertyKey(indexKey).dataType(Integer.class).make();
        VertexLabel versionLabel = mgmt.makeVertexLabel(label).make();
        // Create a unique composite index for the property key that indexes only vertices with a given label
        mgmt.buildIndex(indexName, Vertex.class).addKey(indexPropertyKey).indexOnly(versionLabel).unique()
                .buildCompositeIndex();
    }
    mgmt.commit();
    // Wait for the index to become available
    ManagementSystem.awaitGraphIndexStatus((TitanGraph) newGraph, indexName).status(SchemaStatus.ENABLED).call();
}
 
Example 5
Project: titan1withtp3.1   File: TitanGraphTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testIndexQueryWithLabelsAndContainsIN() {
    // This test is based on the steps to reproduce #882

    String labelName = "labelName";

    VertexLabel label = mgmt.makeVertexLabel(labelName).make();
    PropertyKey uid = mgmt.makePropertyKey("uid").dataType(String.class).make();
    TitanGraphIndex uidCompositeIndex = mgmt.buildIndex("uidIndex", Vertex.class).indexOnly(label).addKey(uid).unique().buildCompositeIndex();
    mgmt.setConsistency(uidCompositeIndex, ConsistencyModifier.LOCK);
    finishSchema();

    TitanVertex foo = graph.addVertex(labelName);
    TitanVertex bar = graph.addVertex(labelName);
    foo.property("uid", "foo");
    bar.property("uid", "bar");
    graph.tx().commit();

    Iterable<TitanVertex> vertexes = graph.query()
            .has("uid", Contain.IN, ImmutableList.of("foo", "bar"))
            .has(LABEL_NAME, labelName)
            .vertices();
    assertEquals(2, Iterables.size(vertexes));
    for (TitanVertex v : vertexes) {
        assertEquals(labelName, v.vertexLabel().name());
    }
}
 
Example 6
Project: titan1withtp3.1   File: TitanGraphTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testVertexTTLWithCompositeIndex() throws Exception {
    if (!features.hasCellTTL()) {
        return;
    }

    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
    PropertyKey time = mgmt.makePropertyKey("time").dataType(Long.class).make();
    TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex();
    TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(time).buildCompositeIndex();
    VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make();
    mgmt.setTTL(label1, Duration.ofSeconds(1));
    assertEquals(Duration.ZERO, mgmt.getTTL(name));
    assertEquals(Duration.ZERO, mgmt.getTTL(time));
    assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1));
    mgmt.commit();

    TitanVertex v1 = tx.addVertex(T.label, "event", "name", "some event", "time", System.currentTimeMillis());
    tx.commit();
    Object id = v1.id();

    v1 = getV(graph, id);
    assertNotNull(v1);
    assertNotEmpty(graph.query().has("name", "some event").vertices());

    Thread.sleep(1001);
    graph.tx().rollback();

    v1 = getV(graph, id);
    assertNull(v1);
    assertEmpty(graph.query().has("name", "some event").vertices());
}
 
Example 7
Project: titan1withtp3.1   File: TitanGraphTest.java   Source Code and License 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testSettingTTLOnNonStaticVertexLabel() throws Exception {
    if (!features.hasCellTTL()) {
        throw new IllegalArgumentException();
    }

    VertexLabel label1 = mgmt.makeVertexLabel("event").make();
    mgmt.setTTL(label1, Duration.ofSeconds(42));
}
 
Example 8
Project: titan1withtp3.1   File: TitanGraphTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testVertexTTLImplicitKey() throws Exception {
    Duration d;

    if (!features.hasCellTTL()) {
        return;
    }

    clopen(option(GraphDatabaseConfiguration.STORE_META_TTL, "edgestore"), true);

    int ttl1 = 1;
    VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make();
    mgmt.setTTL(label1, Duration.ofSeconds(ttl1));
    assertEquals(Duration.ofSeconds(ttl1), mgmt.getTTL(label1));
    mgmt.commit();

    TitanVertex v1 = tx.addVertex("event");
    TitanVertex v2 = tx.addVertex();
    tx.commit();

    /* TODO: this fails
    d = v1.getProperty("~ttl");
    assertEquals(1, d);
    d = v2.getProperty("~ttl");
    assertEquals(0, d);
    */

    Object v1id = v1.id();
    Object v2id = v2.id();
    v1 = getV(graph, v1id);
    v2 = getV(graph, v2id);

    d = v1.value("~ttl");
    assertEquals(Duration.ofSeconds(1), d);
    d = v2.value("~ttl");
    assertEquals(Duration.ZERO, d);
}
 
Example 9
Project: titan1withtp3.1   File: StandardVertexLabelMaker.java   Source Code and License 5 votes vote down vote up
@Override
public VertexLabel make() {
    Preconditions.checkArgument(!partitioned || !isStatic,"A vertex label cannot be partitioned and static at the same time");
    TypeDefinitionMap def = new TypeDefinitionMap();
    def.setValue(PARTITIONED, partitioned);
    def.setValue(STATIC, isStatic);

    return (VertexLabelVertex)tx.makeSchemaVertex(TitanSchemaCategory.VERTEXLABEL,name,def);
}
 
Example 10
Project: antioch   File: TitanService.java   Source Code and License 5 votes vote down vote up
private static boolean createIndexWhenAbsent(TitanManagement mgmt, VertexCompositeIndex compositeIndex) {
  String name = compositeIndex.name;
  if (!mgmt.containsGraphIndex(name)) {
    String property = compositeIndex.property;
    String label = compositeIndex.label;
    boolean unique = compositeIndex.unique;
    LOG.info("building {} index '{}' for label '{}' + property '{}'", unique ? "unique" : "non-unique", name, label, property);

    PropertyKey uuidKey = mgmt.containsPropertyKey(property)//
        ? mgmt.getPropertyKey(property)//
        : mgmt.makePropertyKey(property).dataType(String.class).make();

    IndexBuilder indexBuilder = mgmt.buildIndex(name, Vertex.class)//
        .addKey(uuidKey);

    if (label != null) {
      VertexLabel vertexLabel = mgmt.containsVertexLabel(label)//
          ? mgmt.getVertexLabel(label)//
          : mgmt.makeVertexLabel(label).make();
      indexBuilder = indexBuilder.indexOnly(vertexLabel);
    }

    if (unique) {
      indexBuilder = indexBuilder.unique();
    }

    TitanGraphIndex index = indexBuilder.buildCompositeIndex();
    mgmt.setConsistency(index, ConsistencyModifier.LOCK);

    return true;
  }
  return false;
}
 
Example 11
Project: titan1.0.1.kafka   File: TitanGraphTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testIndexQueryWithLabelsAndContainsIN() {
    // This test is based on the steps to reproduce #882

    String labelName = "labelName";

    VertexLabel label = mgmt.makeVertexLabel(labelName).make();
    PropertyKey uid = mgmt.makePropertyKey("uid").dataType(String.class).make();
    TitanGraphIndex uidCompositeIndex = mgmt.buildIndex("uidIndex", Vertex.class).indexOnly(label).addKey(uid).unique().buildCompositeIndex();
    mgmt.setConsistency(uidCompositeIndex, ConsistencyModifier.LOCK);
    finishSchema();

    TitanVertex foo = graph.addVertex(labelName);
    TitanVertex bar = graph.addVertex(labelName);
    foo.property("uid", "foo");
    bar.property("uid", "bar");
    graph.tx().commit();

    Iterable<TitanVertex> vertexes = graph.query()
            .has("uid", Contain.IN, ImmutableList.of("foo", "bar"))
            .has(LABEL_NAME, labelName)
            .vertices();
    assertEquals(2, Iterables.size(vertexes));
    for (TitanVertex v : vertexes) {
        assertEquals(labelName, v.vertexLabel().name());
    }
}
 
Example 12
Project: titan1.0.1.kafka   File: TitanGraphTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testVertexTTLWithCompositeIndex() throws Exception {
    if (!features.hasCellTTL()) {
        return;
    }

    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
    PropertyKey time = mgmt.makePropertyKey("time").dataType(Long.class).make();
    TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex();
    TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(time).buildCompositeIndex();
    VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make();
    mgmt.setTTL(label1, Duration.ofSeconds(1));
    assertEquals(Duration.ZERO, mgmt.getTTL(name));
    assertEquals(Duration.ZERO, mgmt.getTTL(time));
    assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1));
    mgmt.commit();

    TitanVertex v1 = tx.addVertex(T.label, "event", "name", "some event", "time", System.currentTimeMillis());
    tx.commit();
    Object id = v1.id();

    v1 = getV(graph, id);
    assertNotNull(v1);
    assertNotEmpty(graph.query().has("name", "some event").vertices());

    Thread.sleep(1001);
    graph.tx().rollback();

    v1 = getV(graph, id);
    assertNull(v1);
    assertEmpty(graph.query().has("name", "some event").vertices());
}
 
Example 13
Project: titan1.0.1.kafka   File: TitanGraphTest.java   Source Code and License 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testSettingTTLOnNonStaticVertexLabel() throws Exception {
    if (!features.hasCellTTL()) {
        throw new IllegalArgumentException();
    }

    VertexLabel label1 = mgmt.makeVertexLabel("event").make();
    mgmt.setTTL(label1, Duration.ofSeconds(42));
}
 
Example 14
Project: titan1.0.1.kafka   File: TitanGraphTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testVertexTTLImplicitKey() throws Exception {
    Duration d;

    if (!features.hasCellTTL()) {
        return;
    }

    clopen(option(GraphDatabaseConfiguration.STORE_META_TTL, "edgestore"), true);

    int ttl1 = 1;
    VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make();
    mgmt.setTTL(label1, Duration.ofSeconds(ttl1));
    assertEquals(Duration.ofSeconds(ttl1), mgmt.getTTL(label1));
    mgmt.commit();

    TitanVertex v1 = tx.addVertex("event");
    TitanVertex v2 = tx.addVertex();
    tx.commit();

    /* TODO: this fails
    d = v1.getProperty("~ttl");
    assertEquals(1, d);
    d = v2.getProperty("~ttl");
    assertEquals(0, d);
    */

    Object v1id = v1.id();
    Object v2id = v2.id();
    v1 = getV(graph, v1id);
    v2 = getV(graph, v2id);

    d = v1.value("~ttl");
    assertEquals(Duration.ofSeconds(1), d);
    d = v2.value("~ttl");
    assertEquals(Duration.ZERO, d);
}
 
Example 15
Project: titan1.0.1.kafka   File: StandardVertexLabelMaker.java   Source Code and License 5 votes vote down vote up
@Override
public VertexLabel make() {
    Preconditions.checkArgument(!partitioned || !isStatic,"A vertex label cannot be partitioned and static at the same time");
    TypeDefinitionMap def = new TypeDefinitionMap();
    def.setValue(PARTITIONED, partitioned);
    def.setValue(STATIC, isStatic);

    return (VertexLabelVertex)tx.makeSchemaVertex(TitanSchemaCategory.VERTEXLABEL,name,def);
}
 
Example 16
Project: titan0.5.4-hbase1.1.1-custom   File: FulgoraVertex.java   Source Code and License 5 votes vote down vote up
/**
 * Special handling to provide access to the label even though its a different vertex by accessing it directly
 * in the enclosing transaction which will cache all vertex labels
 * @return
 */
@Override
public VertexLabel getVertexLabel() {
    Long labelid = getProperty(BaseLabel.VertexLabelEdge.getName());
    if (labelid==null) return BaseVertexLabel.DEFAULT_VERTEXLABEL;
    else return (VertexLabelVertex)tx().getInternalVertex(labelid);
}
 
Example 17
Project: titan0.5.4-hbase1.1.1-custom   File: StandardVertexLabelMaker.java   Source Code and License 5 votes vote down vote up
@Override
public VertexLabel make() {
    Preconditions.checkArgument(!partitioned || !isStatic,"A vertex label cannot be partitioned and static at the same time");
    // Explicitly paritioned vertex labels are only supported when cluster.partition is true.
    // This check could be made slightly earlier in partition(), but it's safer to maintain
    // state invariants when they're declared in close proximity to each other.
    Preconditions.checkArgument(!partitioned || tx.getGraph().getConfiguration().isClusterPartitioned(),
            "Explicit graph partitioning is required for partitioned vertex labels");

    TypeDefinitionMap def = new TypeDefinitionMap();
    def.setValue(PARTITIONED, partitioned);
    def.setValue(STATIC, isStatic);

    return (VertexLabelVertex)tx.makeSchemaVertex(TitanSchemaCategory.VERTEXLABEL,name,def);
}
 
Example 18
Project: mizo   File: MizoTitanHBaseRelationParser.java   Source Code and License 4 votes vote down vote up
@Override
public VertexLabel getExistingVertexLabel(long l) {
    return null;
}
 
Example 19
Project: titan1withtp3.1   File: TitanGraphTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testSchemaNameChange() {
    PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
    EdgeLabel knows = mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.MULTI).make();
    mgmt.buildEdgeIndex(knows, "byTime", Direction.BOTH, time);
    mgmt.buildIndex("timeIndex", Vertex.class).addKey(time).buildCompositeIndex();
    mgmt.makeVertexLabel("people").make();
    finishSchema();

    //CREATE SMALL GRAPH
    TitanVertex v = tx.addVertex("people");
    v.property(VertexProperty.Cardinality.single, "time", 5);
    v.addEdge("knows", v, "time", 11);

    newTx();
    v = getOnlyElement(tx.query().has("time", 5).vertices());
    assertNotNull(v);
    assertEquals("people", v.label());
    assertEquals(5, v.<Integer>value("time").intValue());
    assertCount(1, v.query().direction(Direction.IN).labels("knows").edges());
    assertCount(1, v.query().direction(Direction.OUT).labels("knows").has("time", 11).edges());
    newTx();

    //UPDATE SCHEMA NAMES

    assertTrue(mgmt.containsRelationType("knows"));
    knows = mgmt.getEdgeLabel("knows");
    mgmt.changeName(knows, "know");
    assertEquals("know", knows.name());

    assertTrue(mgmt.containsRelationIndex(knows, "byTime"));
    RelationTypeIndex rindex = mgmt.getRelationIndex(knows, "byTime");
    assertEquals("byTime", rindex.name());
    mgmt.changeName(rindex, "overTime");
    assertEquals("overTime", rindex.name());

    assertTrue(mgmt.containsVertexLabel("people"));
    VertexLabel vl = mgmt.getVertexLabel("people");
    mgmt.changeName(vl, "person");
    assertEquals("person", vl.name());

    assertTrue(mgmt.containsGraphIndex("timeIndex"));
    TitanGraphIndex gindex = mgmt.getGraphIndex("timeIndex");
    mgmt.changeName(gindex, "byTime");
    assertEquals("byTime", gindex.name());

    finishSchema();

    //VERIFY UPDATES IN MGMT SYSTEM

    assertTrue(mgmt.containsRelationType("know"));
    assertFalse(mgmt.containsRelationType("knows"));
    knows = mgmt.getEdgeLabel("know");

    assertTrue(mgmt.containsRelationIndex(knows, "overTime"));
    assertFalse(mgmt.containsRelationIndex(knows, "byTime"));

    assertTrue(mgmt.containsVertexLabel("person"));
    assertFalse(mgmt.containsVertexLabel("people"));

    assertTrue(mgmt.containsGraphIndex("byTime"));
    assertFalse(mgmt.containsGraphIndex("timeIndex"));

    //VERIFY UPDATES IN TRANSACTION
    newTx();
    v = getOnlyElement(tx.query().has("time", 5).vertices());
    assertNotNull(v);
    assertEquals("person", v.label());
    assertEquals(5, v.<Integer>value("time").intValue());
    assertCount(1, v.query().direction(Direction.IN).labels("know").edges());
    assertCount(0, v.query().direction(Direction.IN).labels("knows").edges());
    assertCount(1, v.query().direction(Direction.OUT).labels("know").has("time", 11).edges());
}
 
Example 20
Project: titan1withtp3.1   File: TitanGraphTest.java   Source Code and License 4 votes vote down vote up
@Category({BrittleTests.class})
@Test
public void testPropertyTTLTiming() throws Exception {
    if (!features.hasCellTTL()) {
        return;
    }

    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
    PropertyKey place = mgmt.makePropertyKey("place").dataType(String.class).make();
    mgmt.setTTL(name, Duration.ofSeconds(42));
    mgmt.setTTL(place, Duration.ofSeconds(1));
    TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex();
    TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(place).buildCompositeIndex();
    VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make();
    mgmt.setTTL(label1, Duration.ofSeconds(2));
    assertEquals(Duration.ofSeconds(42), mgmt.getTTL(name));
    assertEquals(Duration.ofSeconds(1), mgmt.getTTL(place));
    assertEquals(Duration.ofSeconds(2), mgmt.getTTL(label1));
    mgmt.commit();

    TitanVertex v1 = tx.addVertex(T.label, "event", "name", "some event", "place", "somewhere");

    tx.commit();
    Object id = v1.id();

    v1 = getV(graph, id);
    assertNotNull(v1);
    assertNotEmpty(graph.query().has("name", "some event").has("place", "somewhere").vertices());
    assertNotEmpty(graph.query().has("name", "some event").vertices());

    Thread.sleep(1001);
    graph.tx().rollback();

    // short-lived property expires first
    v1 = getV(graph, id);
    assertNotNull(v1);
    assertEmpty(graph.query().has("name", "some event").has("place", "somewhere").vertices());
    assertNotEmpty(graph.query().has("name", "some event").vertices());

    Thread.sleep(1001);
    graph.tx().rollback();

    // vertex expires before defined TTL of the long-lived property
    assertEmpty(graph.query().has("name", "some event").has("place", "somewhere").vertices());
    assertEmpty(graph.query().has("name", "some event").vertices());
    v1 = getV(graph, id);
    assertNull(v1);
}
 
Example 21
Project: titan1withtp3.1   File: TitanIndexTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testVertexTTLWithMixedIndices() throws Exception {
    if (!features.hasCellTTL() || !indexFeatures.supportsDocumentTTL()) {
        return;
    }

    PropertyKey name = makeKey("name", String.class);
    PropertyKey time = makeKey("time", Long.class);
    PropertyKey text = makeKey("text", String.class);

    VertexLabel event = mgmt.makeVertexLabel("event").setStatic().make();
    final int eventTTLSeconds = (int) TestGraphConfigs.getTTL(TimeUnit.SECONDS);
    mgmt.setTTL(event, Duration.ofSeconds(eventTTLSeconds));

    mgmt.buildIndex("index1", Vertex.class).
            addKey(name, getStringMapping()).addKey(time).buildMixedIndex(INDEX);
    mgmt.buildIndex("index2", Vertex.class).indexOnly(event).
            addKey(text, getTextMapping()).buildMixedIndex(INDEX);

    assertEquals(Duration.ZERO, mgmt.getTTL(name));
    assertEquals(Duration.ZERO, mgmt.getTTL(time));
    assertEquals(Duration.ofSeconds(eventTTLSeconds), mgmt.getTTL(event));
    finishSchema();

    TitanVertex v1 = tx.addVertex("event");
    v1.property(VertexProperty.Cardinality.single, "name", "first event");
    v1.property(VertexProperty.Cardinality.single, "text", "this text will help to identify the first event");
    long time1 = System.currentTimeMillis();
    v1.property(VertexProperty.Cardinality.single, "time", time1);
    TitanVertex v2 = tx.addVertex("event");
    v2.property(VertexProperty.Cardinality.single, "name", "second event");
    v2.property(VertexProperty.Cardinality.single, "text", "this text won't match");
    long time2 = time1 + 1;
    v2.property(VertexProperty.Cardinality.single, "time", time2);

    evaluateQuery(tx.query().has("name", "first event").orderBy("time", decr),
            ElementCategory.VERTEX, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC, "index1");
    evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"),
            ElementCategory.VERTEX, 1, new boolean[]{true, true}, "index2");

    clopen();

    Object v1Id = v1.id();
    Object v2Id = v2.id();

    evaluateQuery(tx.query().has("name", "first event").orderBy("time", decr),
            ElementCategory.VERTEX, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC, "index1");
    evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"),
            ElementCategory.VERTEX, 1, new boolean[]{true, true}, "index2");

    v1 = getV(tx, v1Id);
    v2 = getV(tx, v1Id);
    assertNotNull(v1);
    assertNotNull(v2);

    Thread.sleep(TimeUnit.MILLISECONDS.convert((long) Math.ceil(eventTTLSeconds * 1.25), TimeUnit.SECONDS));

    clopen();

    Thread.sleep(TimeUnit.MILLISECONDS.convert((long) Math.ceil(eventTTLSeconds * 1.25), TimeUnit.SECONDS));

    evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"),
            ElementCategory.VERTEX, 0, new boolean[]{true, true}, "index2");
    evaluateQuery(tx.query().has("name", "first event").orderBy("time", decr),
            ElementCategory.VERTEX, 0, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC, "index1");


    v1 = getV(tx, v1Id);
    v2 = getV(tx, v2Id);
    assertNull(v1);
    assertNull(v2);
}
 
Example 22
Project: titan1withtp3.1   File: ManagementSystem.java   Source Code and License 4 votes vote down vote up
@Override
public VertexLabel getVertexLabel(String name) {
    return transaction.getVertexLabel(name);
}
 
Example 23
Project: titan1withtp3.1   File: ManagementSystem.java   Source Code and License 4 votes vote down vote up
@Override
public VertexLabel getOrCreateVertexLabel(String name) {
    return transaction.getOrCreateVertexLabel(name);
}
 
Example 24
Project: titan1withtp3.1   File: ManagementSystem.java   Source Code and License 4 votes vote down vote up
@Override
public Iterable<VertexLabel> getVertexLabels() {
    return Iterables.filter(QueryUtil.getVertices(transaction, BaseKey.SchemaCategory,
            TitanSchemaCategory.VERTEXLABEL), VertexLabel.class);
}
 
Example 25
Project: titan1withtp3.1   File: VertexLabelDefinition.java   Source Code and License 4 votes vote down vote up
public VertexLabelDefinition(VertexLabel vl) {
    this(vl.name(),vl.longId(),vl.isPartitioned(),vl.isStatic());
}
 
Example 26
Project: titan1.0.1.kafka   File: TitanGraphTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testSchemaNameChange() {
    PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
    EdgeLabel knows = mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.MULTI).make();
    mgmt.buildEdgeIndex(knows, "byTime", Direction.BOTH, time);
    mgmt.buildIndex("timeIndex", Vertex.class).addKey(time).buildCompositeIndex();
    mgmt.makeVertexLabel("people").make();
    finishSchema();

    //CREATE SMALL GRAPH
    TitanVertex v = tx.addVertex("people");
    v.property(VertexProperty.Cardinality.single, "time", 5);
    v.addEdge("knows", v, "time", 11);

    newTx();
    v = getOnlyElement(tx.query().has("time", 5).vertices());
    assertNotNull(v);
    assertEquals("people", v.label());
    assertEquals(5, v.<Integer>value("time").intValue());
    assertCount(1, v.query().direction(Direction.IN).labels("knows").edges());
    assertCount(1, v.query().direction(Direction.OUT).labels("knows").has("time", 11).edges());
    newTx();

    //UPDATE SCHEMA NAMES

    assertTrue(mgmt.containsRelationType("knows"));
    knows = mgmt.getEdgeLabel("knows");
    mgmt.changeName(knows, "know");
    assertEquals("know", knows.name());

    assertTrue(mgmt.containsRelationIndex(knows, "byTime"));
    RelationTypeIndex rindex = mgmt.getRelationIndex(knows, "byTime");
    assertEquals("byTime", rindex.name());
    mgmt.changeName(rindex, "overTime");
    assertEquals("overTime", rindex.name());

    assertTrue(mgmt.containsVertexLabel("people"));
    VertexLabel vl = mgmt.getVertexLabel("people");
    mgmt.changeName(vl, "person");
    assertEquals("person", vl.name());

    assertTrue(mgmt.containsGraphIndex("timeIndex"));
    TitanGraphIndex gindex = mgmt.getGraphIndex("timeIndex");
    mgmt.changeName(gindex, "byTime");
    assertEquals("byTime", gindex.name());

    finishSchema();

    //VERIFY UPDATES IN MGMT SYSTEM

    assertTrue(mgmt.containsRelationType("know"));
    assertFalse(mgmt.containsRelationType("knows"));
    knows = mgmt.getEdgeLabel("know");

    assertTrue(mgmt.containsRelationIndex(knows, "overTime"));
    assertFalse(mgmt.containsRelationIndex(knows, "byTime"));

    assertTrue(mgmt.containsVertexLabel("person"));
    assertFalse(mgmt.containsVertexLabel("people"));

    assertTrue(mgmt.containsGraphIndex("byTime"));
    assertFalse(mgmt.containsGraphIndex("timeIndex"));

    //VERIFY UPDATES IN TRANSACTION
    newTx();
    v = getOnlyElement(tx.query().has("time", 5).vertices());
    assertNotNull(v);
    assertEquals("person", v.label());
    assertEquals(5, v.<Integer>value("time").intValue());
    assertCount(1, v.query().direction(Direction.IN).labels("know").edges());
    assertCount(0, v.query().direction(Direction.IN).labels("knows").edges());
    assertCount(1, v.query().direction(Direction.OUT).labels("know").has("time", 11).edges());
}
 
Example 27
Project: titan1.0.1.kafka   File: TitanGraphTest.java   Source Code and License 4 votes vote down vote up
@Category({BrittleTests.class})
@Test
public void testPropertyTTLTiming() throws Exception {
    if (!features.hasCellTTL()) {
        return;
    }

    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
    PropertyKey place = mgmt.makePropertyKey("place").dataType(String.class).make();
    mgmt.setTTL(name, Duration.ofSeconds(42));
    mgmt.setTTL(place, Duration.ofSeconds(1));
    TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex();
    TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(place).buildCompositeIndex();
    VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make();
    mgmt.setTTL(label1, Duration.ofSeconds(2));
    assertEquals(Duration.ofSeconds(42), mgmt.getTTL(name));
    assertEquals(Duration.ofSeconds(1), mgmt.getTTL(place));
    assertEquals(Duration.ofSeconds(2), mgmt.getTTL(label1));
    mgmt.commit();

    TitanVertex v1 = tx.addVertex(T.label, "event", "name", "some event", "place", "somewhere");

    tx.commit();
    Object id = v1.id();

    v1 = getV(graph, id);
    assertNotNull(v1);
    assertNotEmpty(graph.query().has("name", "some event").has("place", "somewhere").vertices());
    assertNotEmpty(graph.query().has("name", "some event").vertices());

    Thread.sleep(1001);
    graph.tx().rollback();

    // short-lived property expires first
    v1 = getV(graph, id);
    assertNotNull(v1);
    assertEmpty(graph.query().has("name", "some event").has("place", "somewhere").vertices());
    assertNotEmpty(graph.query().has("name", "some event").vertices());

    Thread.sleep(1001);
    graph.tx().rollback();

    // vertex expires before defined TTL of the long-lived property
    assertEmpty(graph.query().has("name", "some event").has("place", "somewhere").vertices());
    assertEmpty(graph.query().has("name", "some event").vertices());
    v1 = getV(graph, id);
    assertNull(v1);
}
 
Example 28
Project: titan1.0.1.kafka   File: TitanIndexTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testVertexTTLWithMixedIndices() throws Exception {
    if (!features.hasCellTTL() || !indexFeatures.supportsDocumentTTL()) {
        return;
    }

    PropertyKey name = makeKey("name", String.class);
    PropertyKey time = makeKey("time", Long.class);
    PropertyKey text = makeKey("text", String.class);

    VertexLabel event = mgmt.makeVertexLabel("event").setStatic().make();
    final int eventTTLSeconds = (int) TestGraphConfigs.getTTL(TimeUnit.SECONDS);
    mgmt.setTTL(event, Duration.ofSeconds(eventTTLSeconds));

    mgmt.buildIndex("index1", Vertex.class).
            addKey(name, getStringMapping()).addKey(time).buildMixedIndex(INDEX);
    mgmt.buildIndex("index2", Vertex.class).indexOnly(event).
            addKey(text, getTextMapping()).buildMixedIndex(INDEX);

    assertEquals(Duration.ZERO, mgmt.getTTL(name));
    assertEquals(Duration.ZERO, mgmt.getTTL(time));
    assertEquals(Duration.ofSeconds(eventTTLSeconds), mgmt.getTTL(event));
    finishSchema();

    TitanVertex v1 = tx.addVertex("event");
    v1.property(VertexProperty.Cardinality.single, "name", "first event");
    v1.property(VertexProperty.Cardinality.single, "text", "this text will help to identify the first event");
    long time1 = System.currentTimeMillis();
    v1.property(VertexProperty.Cardinality.single, "time", time1);
    TitanVertex v2 = tx.addVertex("event");
    v2.property(VertexProperty.Cardinality.single, "name", "second event");
    v2.property(VertexProperty.Cardinality.single, "text", "this text won't match");
    long time2 = time1 + 1;
    v2.property(VertexProperty.Cardinality.single, "time", time2);

    evaluateQuery(tx.query().has("name", "first event").orderBy("time", decr),
            ElementCategory.VERTEX, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC, "index1");
    evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"),
            ElementCategory.VERTEX, 1, new boolean[]{true, true}, "index2");

    clopen();

    Object v1Id = v1.id();
    Object v2Id = v2.id();

    evaluateQuery(tx.query().has("name", "first event").orderBy("time", decr),
            ElementCategory.VERTEX, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC, "index1");
    evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"),
            ElementCategory.VERTEX, 1, new boolean[]{true, true}, "index2");

    v1 = getV(tx, v1Id);
    v2 = getV(tx, v1Id);
    assertNotNull(v1);
    assertNotNull(v2);

    Thread.sleep(TimeUnit.MILLISECONDS.convert((long) Math.ceil(eventTTLSeconds * 1.25), TimeUnit.SECONDS));

    clopen();

    Thread.sleep(TimeUnit.MILLISECONDS.convert((long) Math.ceil(eventTTLSeconds * 1.25), TimeUnit.SECONDS));

    evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"),
            ElementCategory.VERTEX, 0, new boolean[]{true, true}, "index2");
    evaluateQuery(tx.query().has("name", "first event").orderBy("time", decr),
            ElementCategory.VERTEX, 0, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC, "index1");


    v1 = getV(tx, v1Id);
    v2 = getV(tx, v2Id);
    assertNull(v1);
    assertNull(v2);
}
 
Example 29
Project: titan1.0.1.kafka   File: ManagementSystem.java   Source Code and License 4 votes vote down vote up
@Override
public VertexLabel getVertexLabel(String name) {
    return transaction.getVertexLabel(name);
}
 
Example 30
Project: titan1.0.1.kafka   File: ManagementSystem.java   Source Code and License 4 votes vote down vote up
@Override
public VertexLabel getOrCreateVertexLabel(String name) {
    return transaction.getOrCreateVertexLabel(name);
}
 
Example 31
Project: titan1.0.1.kafka   File: ManagementSystem.java   Source Code and License 4 votes vote down vote up
@Override
public Iterable<VertexLabel> getVertexLabels() {
    return Iterables.filter(QueryUtil.getVertices(transaction, BaseKey.SchemaCategory,
            TitanSchemaCategory.VERTEXLABEL), VertexLabel.class);
}
 
Example 32
Project: titan1.0.1.kafka   File: VertexLabelDefinition.java   Source Code and License 4 votes vote down vote up
public VertexLabelDefinition(VertexLabel vl) {
    this(vl.name(),vl.longId(),vl.isPartitioned(),vl.isStatic());
}
 
Example 33
Project: titan0.5.4-hbase1.1.1-custom   File: FaunusVertexLabel.java   Source Code and License 4 votes vote down vote up
@Override
public boolean equals(Object oth) {
    if (this==oth) return true;
    else if (oth==null || !(oth instanceof VertexLabel)) return false;
    return getName().equals(((VertexLabel)oth).getName());
}
 
Example 34
Project: titan0.5.4-hbase1.1.1-custom   File: VertexLabelDefinition.java   Source Code and License 4 votes vote down vote up
public VertexLabelDefinition(VertexLabel vl) {
    this(vl.getName(),vl.getLongId(),vl.isPartitioned(),vl.isStatic());
}
 
Example 35
Project: titan1withtp3.1   File: TitanManagement.java   Source Code and License 2 votes vote down vote up
/**
 * Returns an {@link Iterable} over all defined {@link VertexLabel}s.
 *
 * @return
 */
public Iterable<VertexLabel> getVertexLabels();
 
Example 36
Project: titan1withtp3.1   File: DefaultSchemaMaker.java   Source Code and License 2 votes vote down vote up
/**
 * Creates a new vertex label with the default settings against the provided {@link VertexLabelMaker}.
 *
 * @param factory VertexLabelMaker through which the vertex label is created
 * @return A new vertex label
 * @throws IllegalArgumentException if the name is already in use or if other configured values are invalid.
 */
public default VertexLabel makeVertexLabel(VertexLabelMaker factory) {
    return factory.make();
}
 
Example 37
Project: titan1withtp3.1   File: SchemaInspector.java   Source Code and License 2 votes vote down vote up
/**
 * Returns the vertex label with the given name. If such does not exist, NULL is returned.
 *
 * @param name
 * @return
 */
public VertexLabel getVertexLabel(String name);
 
Example 38
Project: titan1withtp3.1   File: SchemaInspector.java   Source Code and License 2 votes vote down vote up
/**
 * Returns the vertex label with the given name. If a vertex label with this name does not exist, the label is
 * automatically created through the registered {@link com.thinkaurelius.titan.core.schema.DefaultSchemaMaker}.
 * <p />
 * Attempting to automatically create a vertex label might cause an exception depending on the configuration.
 *
 * @param name
 * @return
 */
public VertexLabel getOrCreateVertexLabel(String name);
 
Example 39
Project: titan1withtp3.1   File: VertexLabelMaker.java   Source Code and License 2 votes vote down vote up
/**
 * Creates a {@link VertexLabel} according to the specifications of this builder.
 *
 * @return the created vertex label
 */
public VertexLabel make();
 
Example 40
Project: titan1.0.1.kafka   File: TitanManagement.java   Source Code and License 2 votes vote down vote up
/**
 * Returns an {@link Iterable} over all defined {@link VertexLabel}s.
 *
 * @return
 */
public Iterable<VertexLabel> getVertexLabels();