public static long getId(Element e) { return ((JanusGraphElement)e).longId(); }
public static IllegalStateException removedException(JanusGraphElement element) { Class elementClass = Vertex.class.isAssignableFrom(element.getClass())?Vertex.class: (Edge.class.isAssignableFrom(element.getClass())?Edge.class:VertexProperty.class); return Element.Exceptions.elementAlreadyRemoved(elementClass, element.id()); }
@Override public void remove() { if (current != null) current.remove(); else throw new UnsupportedOperationException(); }
@Override public boolean isDeleted(GraphCentricQuery query, JanusGraphElement result) { if (result == null || result.isRemoved()) return true; else if (query.getResultType() == ElementCategory.VERTEX) { Preconditions.checkArgument(result instanceof InternalVertex); InternalVertex v = ((InternalVertex) result).it(); return (v.hasAddedRelations() || v.hasRemovedRelations()) && !query.matches(result); } else if (query.getResultType() == ElementCategory.EDGE || query.getResultType()==ElementCategory.PROPERTY) { Preconditions.checkArgument(result.isLoaded() || result.isNew()); //Loaded relations are immutable so we don't need to check those //New relations could be modified in this transaction to now longer match the query, hence we need to //check for this case and consider the relations deleted return result.isNew() && !query.matches(result); } else throw new IllegalArgumentException("Unexpected type: " + query.getResultType()); }
private <E extends JanusGraphElement> Stream<Result<E>> execute(ElementCategory resultType, Class<E> resultClass) { Preconditions.checkNotNull(indexName); Preconditions.checkNotNull(query); if (tx.hasModifications()) log.warn("Modifications in this transaction might not be accurately reflected in this index query: {}",query); return serializer.executeQuery(this, resultType, tx.getTxHandle(),tx).map(r -> (Result<E>) new ResultImpl<>(tx.getConversionFunction(resultType).apply(r.getResult()), r.getScore())).filter(r -> !r.getElement().isRemoved()); }
String indexStore = ((MixedIndexType)update.getIndex()).getStoreName(); if (update.isAddition()) itx.add(indexStore, update.getKey(), update.getEntry(), update.getElement().isNew()); else itx.delete(indexStore,update.getKey(),update.getEntry().field,update.getEntry().value,update.getElement().isRemoved());
@Override public boolean equals(Object other) { if (other==null) return false; if (this==other) return true; if (!((this instanceof Vertex && other instanceof Vertex) || (this instanceof Edge && other instanceof Edge) || (this instanceof VertexProperty && other instanceof VertexProperty))) return false; //Same type => they are the same if they have identical ids. if (other instanceof AbstractElement) { return getCompareId()==((AbstractElement)other).getCompareId(); } else if (other instanceof JanusGraphElement) { return ((JanusGraphElement) other).hasId() && getCompareId()==((JanusGraphElement)other).longId(); } else { Object otherId = ((Element)other).id(); if (otherId instanceof RelationIdentifier) return ((RelationIdentifier) otherId).getRelationId()==getCompareId(); else return otherId.equals(getCompareId()); } }
private Entry getIndexEntry(CompositeIndexType index, RecordEntry[] record, JanusGraphElement element) { final DataOutput out = serializer.getDataOutput(1+8+8*record.length+4*8); out.putByte(FIRST_INDEX_COLUMN_BYTE); if (index.getCardinality()!=Cardinality.SINGLE) { VariableLong.writePositive(out,element.longId()); if (index.getCardinality()!=Cardinality.SET) { for (final RecordEntry re : record) { VariableLong.writePositive(out,re.relationId); } } } final int valuePosition=out.getPosition(); if (element instanceof JanusGraphVertex) { VariableLong.writePositive(out,element.longId()); } else { assert element instanceof JanusGraphRelation; final RelationIdentifier rid = (RelationIdentifier)element.id(); final long[] longs = rid.getLongRepresentation(); Preconditions.checkArgument(longs.length == 3 || longs.length == 4); for (final long aLong : longs) VariableLong.writePositive(out, aLong); } return new StaticArrayEntry(out.getStaticBuffer(),valuePosition); }
public void reindexElement(JanusGraphElement element, MixedIndexType index, Map<String,Map<String,List<IndexEntry>>> documentsPerStore) { if (!indexAppliesTo(index,element)) return; final List<IndexEntry> entries = Lists.newArrayList(); for (final ParameterIndexField field: index.getFieldKeys()) { final PropertyKey key = field.getFieldKey(); if (field.getStatus()==SchemaStatus.DISABLED) continue; if (element.properties(key.name()).hasNext()) { element.values(key.name()).forEachRemaining(value->entries.add(new IndexEntry(key2Field(field), value))); } } final Map<String, List<IndexEntry>> documents = documentsPerStore.computeIfAbsent(index.getStoreName(), k -> Maps.newHashMap()); getDocuments(documentsPerStore,index).put(element2String(element),entries); }
@Override public boolean evaluate(E element) { RelationType type; if (key instanceof String) { type = ((InternalElement) element).tx().getRelationType((String) key); if (type == null) return satisfiesCondition(null); } else { type = (RelationType) key; } Preconditions.checkNotNull(type); if (type.isPropertyKey()) { Iterator<Object> iterator = ElementHelper.getValues(element,(PropertyKey)type).iterator(); if (iterator.hasNext()) { while (iterator.hasNext()) { if (satisfiesCondition(iterator.next())) return true; } return false; } return satisfiesCondition(null); } else { assert ((InternalRelationType)type).multiplicity().isUnique(Direction.OUT); return satisfiesCondition(element.value(type.name())); } }
@Override public boolean exists() { try { return !((JanusGraphElement)element).isRemoved(); } catch(IllegalStateException e) { return false; } }
@Override public boolean isValidElement(Element element) { return super.isValidElement(element) && !((JanusGraphElement) element).isRemoved(); } }
/** * Returns a unique identifier for this entity. * <p> * The unique identifier may only be set when the transaction in which entity is created commits. * Some entities are never assigned a unique identifier if they depend on a parent entity. * <p> * JanusGraph allocates blocks of identifiers and automatically assigns identifiers to elements * automatically be default. This behavior can be partially overridden by setting * {@link org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration#ALLOW_SETTING_VERTEX_ID} * * @return The unique identifier for this entity * @throws IllegalStateException if the entity does not (yet) have a unique identifier * @see #hasId */ @Override default Object id() { return longId(); }
private static String element2String(JanusGraphElement element) { return element2String(element.id()); }