@Override public Object apply(TitanProperty titanProperty) { return titanProperty.getValue(); } };
private RecordEntry(TitanProperty property) { this(property.getLongId(),property.getValue(),property.getPropertyKey()); } }
private void setStatusVertex(TitanSchemaVertex vertex, SchemaStatus status) { Preconditions.checkArgument(vertex instanceof RelationTypeVertex || vertex.asIndexType().isCompositeIndex()); //Delete current status for (TitanProperty p : vertex.getProperties(BaseKey.SchemaDefinitionProperty)) { if (p.<TypeDefinitionDescription>getProperty(BaseKey.SchemaDefinitionDesc).getCategory()==TypeDefinitionCategory.STATUS) { if (p.getValue().equals(status)) return; else p.remove(); } } //Add new status TitanProperty p = transaction.addProperty(vertex, BaseKey.SchemaDefinitionProperty, status); p.setProperty(BaseKey.SchemaDefinitionDesc,TypeDefinitionDescription.of(TypeDefinitionCategory.STATUS)); }
public Collection<IndexUpdate> getIndexUpdates(InternalVertex vertex, Collection<InternalRelation> updatedProperties) { if (updatedProperties.isEmpty()) return Collections.EMPTY_LIST; Set<IndexUpdate> updates = Sets.newHashSet(); for (InternalRelation rel : updatedProperties) { assert rel.isProperty(); TitanProperty p = (TitanProperty)rel; assert rel.isNew() || rel.isRemoved(); assert rel.getVertex(0).equals(vertex); IndexUpdate.Type updateType = getUpateType(rel); for (IndexType index : ((InternalRelationType)p.getPropertyKey()).getKeyIndexes()) { if (!indexAppliesTo(index,vertex)) continue; if (index.isCompositeIndex()) { //Gather composite indexes CompositeIndexType cIndex = (CompositeIndexType)index; IndexRecords updateRecords = indexMatches(vertex,cIndex,updateType==IndexUpdate.Type.DELETE,p.getPropertyKey(),new RecordEntry(p)); for (RecordEntry[] record : updateRecords) { IndexUpdate update = new IndexUpdate<StaticBuffer,Entry>(cIndex,updateType,getIndexKey(cIndex,record),getIndexEntry(cIndex,record,vertex), vertex); int ttl = getIndexTTL(vertex,getKeysOfRecords(record)); if (ttl>0 && updateType== IndexUpdate.Type.ADD) update.setTTL(ttl); updates.add(update); } } else { //Update mixed indexes if (((MixedIndexType)index).getField(p.getPropertyKey()).getStatus()== SchemaStatus.DISABLED) continue; IndexUpdate update = getMixedIndexUpdate(vertex, p.getPropertyKey(), p.getValue(), (MixedIndexType) index, updateType); int ttl = getIndexTTL(vertex,p.getPropertyKey()); if (ttl>0 && updateType== IndexUpdate.Type.ADD) update.setTTL(ttl); updates.add(update); } } } return updates; }
for (String s : values) { TitanProperty p = v.addProperty(foo, s); p.setProperty(weight,++i); p = v.addProperty(bar, s); p.setProperty(weight,i); int index = values.size(); for (TitanProperty p : v.getProperties(foo)) { assertTrue(values.contains(p.getValue())); int wint = p.getProperty(weight); sum+=wint; if (prop==foo) assertEquals(index,wint);
assertEquals(5.0,v.<Decimal>getProperty("weight").doubleValue(),0.00001); TitanProperty p = Iterables.getOnlyElement(v.getProperties("weight")); assertEquals(1,p.getProperty("sig")); sign(v.addProperty("weight",6.0),txid); p = Iterables.getOnlyElement(v.getProperties("name")); assertEquals(1,p.getProperty("sig")); assertEquals("John",p.getValue()); p.remove(); sign(v.addProperty("name","Bob"),txid); for (String pkey : new String[]{"value","valuef"}) { p = Iterables.getOnlyElement(v.getProperties(pkey)); assertEquals(1,p.getProperty("sig")); assertEquals(2,p.getValue()); sign(p,txid);
TitanVertex v2 = tx.addVertex(); TitanProperty p = v1.addProperty("name","xyz"); p.setProperty("time",15); Edge e = v1.addEdge("related",v2); e.setProperty("time",25); p = Iterables.getOnlyElement(v1.getProperties("name")); e = Iterables.getOnlyElement(v1.getEdges(Direction.OUT, "related")); assertEquals(3, p.getPropertyKeys().size()); assertEquals(3, p.getPropertyKeys().size()); p.setProperty("time", 115); e.setProperty("time",125); tx.commit(); p = Iterables.getOnlyElement(v1.getProperties("name")); e = Iterables.getOnlyElement(v1.getEdges(Direction.OUT, "related")); assertEquals(115,p.getProperty("time")); assertEquals(125, e.getProperty("time")); p.remove(); e.remove(); tx.commit();
assertEquals(6.0,v.<Decimal>getProperty("weight").doubleValue(),0.00001); TitanProperty p = Iterables.getOnlyElement(v.getProperties("weight")); assertEquals(wintx,p.getProperty("sig")); p = Iterables.getOnlyElement(v.getProperties("name")); assertEquals("Bob",p.getValue()); assertEquals(wintx,p.getProperty("sig")); p = Iterables.getOnlyElement(v.getProperties("value")); assertEquals(rs[2].getLongId(),p.getLongId()); assertEquals(wintx,p.getProperty("sig")); assertEquals(2,Iterables.size(v.getProperties("valuef"))); for (TitanProperty pp : v.getProperties("valuef")) { assertNotEquals(rs[3].getLongId(),pp.getLongId()); assertEquals(2,pp.getValue());
@Override public boolean apply(@Nullable TitanProperty titanProperty) { return titanProperty.getPropertyKey().equals(key); } });
long t = (i+77)%numV; TitanProperty p = v.addProperty(name,"v"+i); p.setProperty(weight,w); p.setProperty(time,t); if (p.<Long>getProperty(time)<(numV/2)) p.remove(); long t = i; TitanProperty p = v.addProperty(name,"v"+i); p.setProperty(weight,w); p.setProperty(time,t);
@Override public TypeDefinitionMap getDefinition() { TypeDefinitionMap def = definition; if (def == null) { def = new TypeDefinitionMap(); Iterable<TitanProperty> ps; if (isLoaded()) { StandardTitanTx tx = tx(); ps = (Iterable)RelationConstructor.readRelation(this, tx.getGraph().getSchemaCache().getSchemaRelations(getLongId(), BaseKey.SchemaDefinitionProperty, Direction.OUT), tx); } else { ps = query().type(BaseKey.SchemaDefinitionProperty).properties(); } for (TitanProperty property : ps) { TypeDefinitionDescription desc = property.getProperty(BaseKey.SchemaDefinitionDesc); Preconditions.checkArgument(desc!=null && desc.getCategory().isProperty()); def.setValue(desc.getCategory(), property.getValue()); } assert def.size()>0; definition = def; } assert def!=null; return def; }
assertEquals(e, graph.getEdge(e.getId().toString())); TitanProperty p = Iterables.getOnlyElement(n3.getProperties("uid")); p.remove(); n3.addProperty("uid", 353);
for (Map.Entry<TypeDefinitionCategory,Object> def : definition.entrySet()) { TitanProperty p = addProperty(schemaVertex, BaseKey.SchemaDefinitionProperty,def.getValue()); p.setProperty(BaseKey.SchemaDefinitionDesc,TypeDefinitionDescription.of(def.getKey()));
@Test public void testStaleVertex() { PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make(); PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make(); mgmt.buildIndex("byName", Vertex.class).addKey(name).unique().buildCompositeIndex(); finishSchema(); TitanVertex cartman = graph.addVertex(null); ElementHelper.setProperties(cartman,"name","cartman", "age", 10); TitanVertex stan = graph.addVertex(null); ElementHelper.setProperties(stan,"name","stan","age",8); graph.commit(); cartman = (TitanVertex)graph.getVertices("name", "cartman").iterator().next(); graph.commit(); //TitanProperty p = (TitanProperty) ((Iterable)graph.multiQuery(cartman).properties().values().iterator().next()).iterator().next(); TitanProperty p = cartman.getProperties().iterator().next(); System.out.println(p.getLongId()); graph.commit(); }
for (TitanProperty prop : v1.getProperties(name)) { if (features.hasTimestamps()) { Timestamp t = prop.getProperty("$timestamp"); assertEquals(100,t.sinceEpoch(unit)); assertEquals(TimeUnit.MICROSECONDS.convert(100,TimeUnit.SECONDS)+1,t.sinceEpoch(TimeUnit.MICROSECONDS)); Duration d = prop.getProperty("$ttl"); assertEquals(0l,d.getLength(unit)); assertTrue(d.isZeroLength());
v = tx.getVertex(v.getID()); for (TitanProperty p : v.getProperties()) { assertNotNull(p.getValue()); assertNotNull(p.getPropertyKey());
v.addProperty(name,"John"); TitanProperty p = v.addProperty(value,11); p.setProperty(weight,22); p = v.addProperty(value,33.3); p.setProperty(weight,66.6); p = v.addProperty(value,11); //same values are supported for list-properties p.setProperty(weight,22); assertEquals(2,v.<List>getProperty(name).size()); for (TitanProperty prop : v.getProperties(name)) { String nstr = prop.getValue(); assertTrue(nstr.equals("Bob") || nstr.equals("John")); assertEquals(prop.<Number>getValue().doubleValue()*2,prop.<Number>getProperty(weight).doubleValue(),0.00001); p.setProperty(weight,88.8); assertEquals(v,Iterables.getOnlyElement(tx.query().has(someid,Cmp.EQUAL,"Hello").vertices())); assertEquals(2,v.<List>getProperty(name).size()); for (TitanProperty prop : v.getProperties(name)) { String nstr = prop.getValue(); assertTrue(nstr.equals("Bob") || nstr.equals("John")); assertEquals(prop.<Number>getValue().doubleValue()*2,prop.<Number>getProperty(weight).doubleValue(),0.00001); p.setProperty(weight,88.8); assertEquals(v,Iterables.getOnlyElement(tx.query().has(someid,Cmp.EQUAL,"Hello").vertices()));