@Override public Object apply(TitanProperty titanProperty) { return titanProperty.getValue(); } };
@Override public List<Object> apply(TitanProperty titanProperty) { return Lists.newArrayList(titanProperty.getValue()); } };
@Nullable @Override public Object apply(@Nullable TitanProperty titanProperty) { return titanProperty.getValue(); } });
@Override public boolean apply(@Nullable TitanProperty titanProperty) { return normalizedValue.equals(titanProperty.getValue()); } })))
@Override public synchronized void remove(TitanProperty property) { map.remove(property.getValue(),property); }
@Override public void add(TitanProperty property) { map.put(property.getValue(),property); }
@Override public void remove(TitanProperty property) { map.remove(property.getValue(),property); }
@Override public synchronized void add(TitanProperty property) { map.put(property.getValue(),property); }
@Override public <T> Collection<T> getPropertyValues(String key, Class<T> clazz) { TitanVertex tv = getAsTitanVertex(); Collection<T> result = new ArrayList<>(); for (TitanProperty property : tv.getProperties(key)) { result.add((T) property.getValue()); } return result; }
private RecordEntry(TitanProperty property) { this(property.getLongId(),property.getValue(),property.getPropertyKey()); } }
@Override public <O> O getProperty(PropertyKey key) { if (!((InternalRelationType)key).isHiddenType() && tx().getConfiguration().hasPropertyPrefetching()) { getProperties().iterator().hasNext(); } Iterator<TitanProperty> iter = query().type(key).properties().iterator(); if (key.getCardinality()== Cardinality.SINGLE) { if (iter.hasNext()) return (O)iter.next().getValue(); else return null; } else { List<Object> result = new ArrayList<Object>(); while (iter.hasNext()) { result.add(iter.next().getValue()); } return (O)result; } }
@Override public <O> O removeProperty(RelationType key) { assert key.isPropertyKey(); Object result = null; for (TitanProperty p : query().type(key).properties()) { result = p.getValue(); p.remove(); } return (O) result; }
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)); }
@Override public String getName() { if (name == null) { TitanProperty p; if (isLoaded()) { StandardTitanTx tx = tx(); p = (TitanProperty) Iterables.getOnlyElement(RelationConstructor.readRelation(this, tx.getGraph().getSchemaCache().getSchemaRelations(getLongId(), BaseKey.SchemaName, Direction.OUT), tx), null); } else { p = Iterables.getOnlyElement(query().type(BaseKey.SchemaName).properties(), null); } Preconditions.checkState(p!=null,"Could not find type for id: %s", getLongId()); name = p.getValue(); } assert name != null; return TitanSchemaCategory.getName(name); }
assert key.getDataType().equals(p.getValue().getClass()) : key + " -> " + p; values.add(new RecordEntry(p));
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; }
v = tx.getVertex(v.getLongId()); for (TitanProperty p : v.getProperties()) { assertNotNull(p.getValue()); assertNotNull(p.getPropertyKey());
p = Iterables.getOnlyElement(v.getProperties("name")); assertEquals(1,p.getProperty("sig")); assertEquals("John",p.getValue()); p.remove(); sign(v.addProperty("name","Bob"),txid); p = Iterables.getOnlyElement(v.getProperties(pkey)); assertEquals(1,p.getProperty("sig")); assertEquals(2,p.getValue()); sign(p,txid);
@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; }
@Test public void testBasic() { TitanKey weight = makeWeightPropertyKey("weight"); TitanVertex n1 = tx.addVertex(); n1.addProperty(weight, 10.5); clopen(); long nid = n1.getID(); assertTrue(tx.containsVertex(nid)); assertTrue(tx.containsVertex(weight.getID())); assertFalse(tx.containsVertex(nid + 64)); assertFalse(tx.containsVertex(weight.getID() + 64)); assertTrue(tx.containsType("weight")); weight = tx.getPropertyKey("weight"); assertEquals(weight.getDataType(), Double.class); assertEquals(weight.getName(), "weight"); n1 = tx.getVertex(nid); for (TitanProperty prop : n1.getProperties()) { Object o = prop.getValue(); } n1.query().relations(); assertEquals(10.5, n1.getProperty(weight)); }