@Nullable @Override public Object apply(@Nullable TitanVertexProperty titanProperty) { return titanProperty.value(); } });
private void setStatusVertex(TitanSchemaVertex vertex, SchemaStatus status) { Preconditions.checkArgument(vertex instanceof RelationTypeVertex || vertex.asIndexType().isCompositeIndex()); //Delete current status for (TitanVertexProperty p : vertex.query().types(BaseKey.SchemaDefinitionProperty).properties()) { if (p.<TypeDefinitionDescription>valueOrNull(BaseKey.SchemaDefinitionDesc).getCategory() == TypeDefinitionCategory.STATUS) { if (p.value().equals(status)) return; else p.remove(); } } //Add new status TitanVertexProperty p = transaction.addProperty(vertex, BaseKey.SchemaDefinitionProperty, status); p.property(BaseKey.SchemaDefinitionDesc.name(), TypeDefinitionDescription.of(TypeDefinitionCategory.STATUS)); }
@Override public synchronized void remove(TitanVertexProperty property) { map.remove(property.value(),property); }
@Override public TypeDefinitionMap getDefinition() { TypeDefinitionMap def = definition; if (def == null) { def = new TypeDefinitionMap(); Iterable<TitanVertexProperty> ps; if (isLoaded()) { StandardTitanTx tx = tx(); ps = (Iterable)RelationConstructor.readRelation(this, tx.getGraph().getSchemaCache().getSchemaRelations(longId(), BaseKey.SchemaDefinitionProperty, Direction.OUT), tx); } else { ps = query().type(BaseKey.SchemaDefinitionProperty).properties(); } for (TitanVertexProperty property : ps) { TypeDefinitionDescription desc = property.valueOrNull(BaseKey.SchemaDefinitionDesc); Preconditions.checkArgument(desc!=null && desc.getCategory().isProperty()); def.setValue(desc.getCategory(), property.value()); } assert def.size()>0; definition = def; } assert def!=null; return def; }
@Override public void add(TitanVertexProperty property) { map.put(property.value(),property); }
@Override public void remove(TitanVertexProperty property) { map.remove(property.value(),property); }
@Override public synchronized void add(TitanVertexProperty property) { map.put(property.value(),property); }
private RecordEntry(TitanVertexProperty property) { this(property.longId(),property.value(),property.propertyKey()); } }
private int getPartitionIDbyKey(TitanVertex vertex) { Preconditions.checkState(idManager!=null && key!=null,"PropertyPlacementStrategy has not been initialized correctly"); assert idManager.getPartitionBound()<=Integer.MAX_VALUE; int partitionBound = (int)idManager.getPartitionBound(); TitanVertexProperty p = (TitanVertexProperty)Iterables.getFirst(vertex.query().keys(key).properties(),null); if (p==null) return -1; int hashPid = Math.abs(p.value().hashCode())%partitionBound; assert hashPid>=0 && hashPid<partitionBound; if (isExhaustedPartition(hashPid)) { //We keep trying consecutive partition ids until we find a non-exhausted one int newPid=hashPid; do { newPid = (newPid+1)%partitionBound; if (newPid==hashPid) //We have gone full circle - no more ids to try throw new IDPoolExhaustedException("Could not find non-exhausted partition"); } while (isExhaustedPartition(newPid)); return newPid; } else return hashPid; } }
@Override public String name() { if (name == null) { TitanVertexProperty<String> p; if (isLoaded()) { StandardTitanTx tx = tx(); p = (TitanVertexProperty) Iterables.getOnlyElement(RelationConstructor.readRelation(this, tx.getGraph().getSchemaCache().getSchemaRelations(longId(), 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", longId()); name = p.value(); } assert name != null; return TitanSchemaCategory.getName(name); }
assert key.dataType().equals(p.value().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(); TitanVertexProperty p = (TitanVertexProperty)rel; assert rel.isNew() || rel.isRemoved(); assert rel.getVertex(0).equals(vertex); IndexUpdate.Type updateType = getUpateType(rel); for (IndexType index : ((InternalRelationType)p.propertyKey()).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.propertyKey(),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.propertyKey()).getStatus()== SchemaStatus.DISABLED) continue; IndexUpdate update = getMixedIndexUpdate(vertex, p.propertyKey(), p.value(), (MixedIndexType) index, updateType); int ttl = getIndexTTL(vertex,p.propertyKey()); if (ttl>0 && updateType== IndexUpdate.Type.ADD) update.setTTL(ttl); updates.add(update); } } } return updates; }
propertyRemover = p -> p.remove(); else propertyRemover = p -> { if (((TitanVertexProperty)p).value().equals(normalizedValue)) p.remove(); };
assertCount(3, v.properties("any")); for (TitanVertexProperty prop : v.query().labels("any").properties()) { Object value = prop.value(); if (value instanceof String) assertEquals("Hello", value); else if (value instanceof Long) assertEquals(10l, value); assertCount(3, v.properties("any")); for (TitanVertexProperty prop : v.query().labels("any").properties()) { Object value = prop.value(); if (value instanceof String) assertEquals("Hello", value); else if (value instanceof Long) assertEquals(10l, value);
assert relation.isProperty(); Preconditions.checkArgument(relation.isProperty()); Object value = ((TitanVertexProperty) relation).value(); Preconditions.checkNotNull(value); PropertyKey key = (PropertyKey) type;
assertCount(2, v.properties("name")); for (TitanVertexProperty<String> prop : v.query().labels("name").properties()) { String nstr = prop.value(); assertTrue(nstr.equals("Bob") || nstr.equals("John")); double prec = prop.value().doubleValue(); assertEquals(prec * 2, prop.<Number>value("weight").doubleValue(), 0.00001); assertCount(2, v.properties("name")); for (TitanVertexProperty<String> prop : v.query().labels("name").properties()) { String nstr = prop.value(); assertTrue(nstr.equals("Bob") || nstr.equals("John")); double prec = prop.value().doubleValue(); assertEquals(prec * 2, prop.<Number>value("weight").doubleValue(), 0.00001);
@Nullable @Override public Object apply(@Nullable TitanVertexProperty titanProperty) { return titanProperty.value(); } });
if (p.<Long>value("time") < (numV / 2)) p.remove();