private RecordEntry(TitanVertexProperty property) { this(property.longId(),property.value(),property.propertyKey()); } }
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 default TitanTransaction graph() { return element().graph(); }
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; }
@Nullable @Override public Object apply(@Nullable TitanVertexProperty titanProperty) { return titanProperty.value(); } });
@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 boolean apply(@Nullable TitanVertexProperty titanProperty) { return titanProperty.propertyKey().equals(key); } });
@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("name", "cartman", "age", 10); TitanVertex stan = graph.addVertex("name", "stan", "age", 8); graph.tx().commit(); cartman = getOnlyElement(graph.query().has("name", "cartman").vertices()); graph.tx().commit(); TitanVertexProperty p = (TitanVertexProperty) cartman.properties().next(); assertTrue(((Long) p.longId()) > 0); graph.tx().commit(); }
@Override public default PropertyKey propertyKey() { return (PropertyKey)getType(); }
for (Map.Entry<TypeDefinitionCategory,Object> def : definition.entrySet()) { TitanVertexProperty p = addProperty(schemaVertex, BaseKey.SchemaDefinitionProperty, def.getValue()); p.property(BaseKey.SchemaDefinitionDesc.name(), TypeDefinitionDescription.of(def.getKey()));
@Override public void add(TitanVertexProperty property) { map.put(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; }
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; }
@Override public synchronized Iterable<TitanVertexProperty> get(final Object value, final PropertyKey key) { List<TitanVertexProperty> result = new ArrayList<TitanVertexProperty>(4); for (TitanVertexProperty p : map.get(value)) { if (p.propertyKey().equals(key)) result.add(p); } return result; } }
@Override public default PropertyKey propertyKey() { return (PropertyKey)getType(); }
for (Map.Entry<TypeDefinitionCategory,Object> def : definition.entrySet()) { TitanVertexProperty p = addProperty(schemaVertex, BaseKey.SchemaDefinitionProperty, def.getValue()); p.property(BaseKey.SchemaDefinitionDesc.name(), TypeDefinitionDescription.of(def.getKey()));
@Override public void remove(TitanVertexProperty property) { map.remove(property.value(),property); }