@Nullable @Override public Object apply(final JanusGraphVertexProperty janusgraphProperty) { return janusgraphProperty.value(); } });
private void setStatusVertex(JanusGraphSchemaVertex vertex, SchemaStatus status) { Preconditions.checkArgument(vertex instanceof RelationTypeVertex || vertex.asIndexType().isCompositeIndex()); //Delete current status for (JanusGraphVertexProperty 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 JanusGraphVertexProperty p = transaction.addProperty(vertex, BaseKey.SchemaDefinitionProperty, status); p.property(BaseKey.SchemaDefinitionDesc.name(), TypeDefinitionDescription.of(TypeDefinitionCategory.STATUS)); }
@Override public void remove(JanusGraphVertexProperty property) { map.remove(property.value(),property); }
@Override public TypeDefinitionMap getDefinition() { TypeDefinitionMap def = definition; if (def == null) { def = new TypeDefinitionMap(); Iterable<JanusGraphVertexProperty> ps; if (isLoaded()) { StandardJanusGraphTx 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 (JanusGraphVertexProperty 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 synchronized void remove(JanusGraphVertexProperty property) { map.remove(property.value(),property); }
@Override public synchronized void add(JanusGraphVertexProperty property) { map.put(property.value(),property); }
@Override public void add(JanusGraphVertexProperty property) { map.put(property.value(),property); }
private RecordEntry(JanusGraphVertexProperty property) { this(property.longId(),property.value(),property.propertyKey()); } }
private int getPartitionIDbyKey(JanusGraphVertex vertex) { Preconditions.checkState(idManager!=null && key!=null, "PropertyPlacementStrategy has not been initialized correctly"); assert idManager.getPartitionBound()<=Integer.MAX_VALUE; int partitionBound = (int)idManager.getPartitionBound(); final JanusGraphVertexProperty p = 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) { JanusGraphVertexProperty<String> p; if (isLoaded()) { StandardJanusGraphTx tx = tx(); p = (JanusGraphVertexProperty) 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 JanusGraphSchemaCategory.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.emptyList(); final Set<IndexUpdate> updates = Sets.newHashSet(); for (final InternalRelation rel : updatedProperties) { assert rel.isProperty(); final JanusGraphVertexProperty p = (JanusGraphVertexProperty)rel; assert rel.isNew() || rel.isRemoved(); assert rel.getVertex(0).equals(vertex); final IndexUpdate.Type updateType = getUpdateType(rel); for (final IndexType index : ((InternalRelationType)p.propertyKey()).getKeyIndexes()) { if (!indexAppliesTo(index,vertex)) continue; if (index.isCompositeIndex()) { //Gather composite indexes final CompositeIndexType cIndex = (CompositeIndexType)index; final IndexRecords updateRecords = indexMatches(vertex,cIndex,updateType==IndexUpdate.Type.DELETE,p.propertyKey(),new RecordEntry(p)); for (final RecordEntry[] record : updateRecords) { final IndexUpdate update = new IndexUpdate<>(cIndex, updateType, getIndexKey(cIndex, record), getIndexEntry(cIndex, record, vertex), vertex); final 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; final IndexUpdate update = getMixedIndexUpdate(vertex, p.propertyKey(), p.value(), (MixedIndexType) index, updateType); final int ttl = getIndexTTL(vertex,p.propertyKey()); if (ttl>0 && updateType== IndexUpdate.Type.ADD) update.setTTL(ttl); updates.add(update); } } } return updates; }
propertyRemover = JanusGraphElement::remove; else propertyRemover = p -> { if (((JanusGraphVertexProperty)p).value().equals(normalizedValue)) p.remove(); };
assert relation.isProperty(); Preconditions.checkArgument(relation.isProperty()); Object value = ((JanusGraphVertexProperty) relation).value(); Preconditions.checkNotNull(value); PropertyKey key = (PropertyKey) type;
assertCount(3, v.properties("any")); for (Object prop : v.query().labels("any").properties()) { Object value = ((JanusGraphVertexProperty<?>) prop).value(); if (value instanceof String) assertEquals("Hello", value); else if (value instanceof Long) assertEquals(10L, value); assertCount(3, v.properties("any")); for (Object prop : v.query().labels("any").properties()) { Object value = ((JanusGraphVertexProperty<?>) prop).value(); if (value instanceof String) assertEquals("Hello", value); else if (value instanceof Long) assertEquals(10L, value);
assertCount(2, v.properties("name")); for (Object prop : v.query().labels("name").properties()) { String nameString = ((JanusGraphVertexProperty<String>) prop).value(); assertTrue(nameString.equals("Bob") || nameString.equals("John")); for (Object o : v.query().labels("value").properties()) { JanusGraphVertexProperty<Double> prop = (JanusGraphVertexProperty<Double>) o; double prec = prop.value(); assertEquals(prec * 2, prop.<Number>value("weight").doubleValue(), 0.00001); for (Object o : v.query().labels("name").properties()) { JanusGraphVertexProperty<String> prop = (JanusGraphVertexProperty<String>) o; String nameString = prop.value(); assertTrue(nameString.equals("Bob") || nameString.equals("John")); for (Object o : v.query().labels("value").properties()) { JanusGraphVertexProperty<Double> prop = (JanusGraphVertexProperty<Double>) o; double prec = prop.value(); assertEquals(prec * 2, prop.<Number>value("weight").doubleValue(), 0.00001);
if (p.<Long>value("time") < (numV / 2)) p.remove();