com.thinkaurelius.titan.core.Multiplicity Java Examples
The following examples show how to use
com.thinkaurelius.titan.core.Multiplicity.
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: EdgeSerializerTest.java From titan1withtp3.1 with Apache License 2.0 | 6 votes |
@Test public void testValueOrdering() { StandardTitanGraph graph = (StandardTitanGraph) StorageSetup.getInMemoryGraph(); TitanManagement mgmt = graph.openManagement(); EdgeLabel father = mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make(); for (int i=1;i<=5;i++) mgmt.makePropertyKey("key" + i).dataType(Integer.class).make(); mgmt.commit(); TitanVertex v1 = graph.addVertex(), v2 = graph.addVertex(); TitanEdge e1 = v1.addEdge("father",v2); for (int i=1;i<=5;i++) e1.property("key"+i,i); graph.tx().commit(); e1.remove(); graph.tx().commit(); }
Example #2
Source File: TestCoreElements.java From titan1withtp3.1 with Apache License 2.0 | 6 votes |
@Test public void testMultiplicityCardinality() { assertEquals(Multiplicity.MULTI,Multiplicity.convert(Cardinality.LIST)); assertEquals(Multiplicity.SIMPLE,Multiplicity.convert(Cardinality.SET)); assertEquals(Multiplicity.MANY2ONE,Multiplicity.convert(Cardinality.SINGLE)); assertEquals(Multiplicity.MULTI.getCardinality(),Cardinality.LIST); assertEquals(Multiplicity.SIMPLE.getCardinality(),Cardinality.SET); assertEquals(Multiplicity.MANY2ONE.getCardinality(),Cardinality.SINGLE); assertFalse(Multiplicity.MULTI.isConstrained()); assertTrue(Multiplicity.SIMPLE.isConstrained()); assertTrue(Multiplicity.ONE2ONE.isConstrained()); assertTrue(Multiplicity.ONE2ONE.isConstrained(Direction.BOTH)); assertTrue(Multiplicity.SIMPLE.isConstrained(Direction.BOTH)); assertFalse(Multiplicity.MULTI.isUnique(Direction.OUT)); assertTrue(Multiplicity.MANY2ONE.isUnique(Direction.OUT)); }
Example #3
Source File: StandardRelationTypeMaker.java From titan1withtp3.1 with Apache License 2.0 | 6 votes |
public StandardRelationTypeMaker(final StandardTitanTx tx, String name, final IndexSerializer indexSerializer, final AttributeHandler attributeHandler) { Preconditions.checkNotNull(tx); Preconditions.checkNotNull(indexSerializer); Preconditions.checkNotNull(attributeHandler); this.tx = tx; this.indexSerializer = indexSerializer; this.attributeHandler = attributeHandler; name(name); //Default assignments isInvisible = false; sortKey = new ArrayList<>(4); sortOrder = Order.ASC; signature = new ArrayList<>(4); multiplicity = Multiplicity.MULTI; }
Example #4
Source File: PropertyKeyDefinition.java From titan1withtp3.1 with Apache License 2.0 | 4 votes |
public PropertyKeyDefinition(String name, long id, Multiplicity multiplicity, Class dataType) { super(name, id, multiplicity); this.dataType = dataType; }
Example #5
Source File: TitanEventualGraphTest.java From titan1withtp3.1 with Apache License 2.0 | 4 votes |
/** * Tests that consistency modes are correctly interpreted in the absence of locks (or tx isolation) */ @Test public void testConsistencyModifier() throws InterruptedException { PropertyKey sig = makeKey("sig",Integer.class); PropertyKey weight = makeKey("weight",Double.class); PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SET).make(); PropertyKey value = mgmt.makePropertyKey("value").dataType(Integer.class).cardinality(Cardinality.LIST).make(); PropertyKey valuef = mgmt.makePropertyKey("valuef").dataType(Integer.class).cardinality(Cardinality.LIST).make(); mgmt.setConsistency(valuef,ConsistencyModifier.FORK); EdgeLabel em = mgmt.makeEdgeLabel("em").multiplicity(Multiplicity.MULTI).make(); EdgeLabel emf = mgmt.makeEdgeLabel("emf").multiplicity(Multiplicity.MULTI).make(); mgmt.setConsistency(emf,ConsistencyModifier.FORK); EdgeLabel es = mgmt.makeEdgeLabel("es").multiplicity(Multiplicity.SIMPLE).make(); EdgeLabel o2o = mgmt.makeEdgeLabel("o2o").multiplicity(Multiplicity.ONE2ONE).make(); EdgeLabel o2m = mgmt.makeEdgeLabel("o2m").multiplicity(Multiplicity.ONE2MANY).make(); finishSchema(); TitanVertex u = tx.addVertex(), v = tx.addVertex(); TitanRelation[] rs = new TitanRelation[9]; final int txid = 1; rs[0]=sign(v.property("weight",5.0),txid); rs[1]=sign(v.property("name","John"),txid); rs[2]=sign(v.property("value",2),txid); rs[3]=sign(v.property("valuef",2),txid); rs[6]=sign(v.addEdge("es",u),txid); rs[7]=sign(v.addEdge("o2o",u),txid); rs[8]=sign(v.addEdge("o2m",u),txid); rs[4]=sign(v.addEdge("em",u),txid); rs[5]=sign(v.addEdge("emf",u),txid); newTx(); long vid = getId(v), uid = getId(u); TitanTransaction tx1 = graph.newTransaction(); TitanTransaction tx2 = graph.newTransaction(); final int wintx = 20; processTx(tx1,wintx-10,vid,uid); processTx(tx2,wintx,vid,uid); tx1.commit(); Thread.sleep(5); tx2.commit(); //tx2 should win using time-based eventual consistency newTx(); v = getV(tx,vid); assertEquals(6.0,v.<Double>value("weight").doubleValue(),0.00001); VertexProperty p = getOnlyElement(v.properties("weight")); assertEquals(wintx,p.<Integer>value("sig").intValue()); p = getOnlyElement(v.properties("name")); assertEquals("Bob",p.value()); assertEquals(wintx,p.<Integer>value("sig").intValue()); p = getOnlyElement(v.properties("value")); assertEquals(rs[2].longId(),getId(p)); assertEquals(wintx,p.<Integer>value("sig").intValue()); assertCount(2,v.properties("valuef")); for (Iterator<VertexProperty<Object>> ppiter = v.properties("valuef"); ppiter.hasNext(); ) { VertexProperty pp = ppiter.next(); assertNotEquals(rs[3].longId(),getId(pp)); assertEquals(2,pp.value()); } Edge e = getOnlyElement(v.query().direction(OUT).labels("es").edges()); assertEquals(wintx,e.<Integer>value("sig").intValue()); assertNotEquals(rs[6].longId(),getId(e)); e = getOnlyElement(v.query().direction(OUT).labels("o2o").edges()); assertEquals(wintx,e.<Integer>value("sig").intValue()); assertEquals(rs[7].longId(), getId(e)); e = getOnlyElement(v.query().direction(OUT).labels("o2m").edges()); assertEquals(wintx,e.<Integer>value("sig").intValue()); assertNotEquals(rs[8].longId(),getId(e)); e = getOnlyElement(v.query().direction(OUT).labels("em").edges()); assertEquals(wintx,e.<Integer>value("sig").intValue()); assertEquals(rs[4].longId(), getId(e)); for (Edge ee : v.query().direction(OUT).labels("emf").edges()) { assertNotEquals(rs[5].longId(),getId(ee)); assertEquals(uid,ee.inVertex().id()); } }
Example #6
Source File: PropertyKeyDefinition.java From titan1withtp3.1 with Apache License 2.0 | 4 votes |
public PropertyKeyDefinition(String name, long id, Cardinality cardinality, Class dataType) { this(name,id,Multiplicity.convert(cardinality),dataType); }
Example #7
Source File: EdgeLabelDefinition.java From titan1withtp3.1 with Apache License 2.0 | 4 votes |
public EdgeLabelDefinition(String name, long id, Multiplicity multiplicity, boolean unidirected) { super(name, id, multiplicity); this.unidirected = unidirected; }
Example #8
Source File: RelationTypeDefinition.java From titan1withtp3.1 with Apache License 2.0 | 4 votes |
public Multiplicity getMultiplicity() { return multiplicity; }
Example #9
Source File: RelationTypeDefinition.java From titan1withtp3.1 with Apache License 2.0 | 4 votes |
public RelationTypeDefinition(String name, long id, Multiplicity multiplicity) { super(name, id); this.multiplicity = multiplicity; }
Example #10
Source File: BaseLabel.java From titan1withtp3.1 with Apache License 2.0 | 4 votes |
@Override public Multiplicity multiplicity() { return multiplicity; }
Example #11
Source File: BaseLabel.java From titan1withtp3.1 with Apache License 2.0 | 4 votes |
private BaseLabel(String name, int id, Direction uniDirectionality, Multiplicity multiplicity) { super(name, id, TitanSchemaCategory.EDGELABEL); this.directionality = uniDirectionality; this.multiplicity = multiplicity; }
Example #12
Source File: ImplicitKey.java From titan1withtp3.1 with Apache License 2.0 | 4 votes |
@Override public Multiplicity multiplicity() { return Multiplicity.convert(cardinality()); }
Example #13
Source File: BaseKey.java From titan1withtp3.1 with Apache License 2.0 | 4 votes |
@Override public Multiplicity multiplicity() { return Multiplicity.convert(cardinality()); }
Example #14
Source File: RelationTypeVertex.java From titan1withtp3.1 with Apache License 2.0 | 4 votes |
@Override public Multiplicity multiplicity() { return getDefinition().getValue(TypeDefinitionCategory.MULTIPLICITY, Multiplicity.class); }
Example #15
Source File: StandardRelationTypeMaker.java From titan1withtp3.1 with Apache License 2.0 | 4 votes |
protected Multiplicity getMultiplicity() { return multiplicity; }
Example #16
Source File: GraphOfTheGodsFactory.java From titan1withtp3.1 with Apache License 2.0 | 4 votes |
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 #17
Source File: InternalRelationType.java From titan1withtp3.1 with Apache License 2.0 | votes |
public Multiplicity multiplicity();