use of com.tinkerpop.blueprints.Direction in project orientdb by orientechnologies.
the class OrientGraphNoTx method removeEdgesInternal.
@Override
void removeEdgesInternal(final OrientVertex vertex, final ODocument iVertex, final OIdentifiable iVertexToRemove, final boolean iAlsoInverse, final boolean useVertexFieldsForEdgeLabels, final boolean autoScaleEdgeType) {
Exception lastException = null;
boolean forceReload = false;
final int maxRetries = getMaxRetries();
for (int retry = 0; retry < maxRetries; ++retry) {
try {
for (String fieldName : iVertex.fieldNames()) {
final OPair<Direction, String> connection = vertex.getConnection(Direction.BOTH, fieldName);
if (connection == null)
// SKIP THIS FIELD
continue;
removeEdges(this, iVertex, fieldName, iVertexToRemove, iAlsoInverse, useVertexFieldsForEdgeLabels, autoScaleEdgeType, forceReload);
}
// OK
return;
} catch (Exception e) {
forceReload = true;
lastException = e;
}
}
if (lastException instanceof RuntimeException)
// CANNOT REVERT CHANGES, RETRY
throw (RuntimeException) lastException;
throw OException.wrapException(new OrientGraphModificationException("Error on removing edges after vertex (" + iVertex.getIdentity() + ") delete in non tx environment"), lastException);
}
use of com.tinkerpop.blueprints.Direction in project pentaho-metaverse by pentaho.
the class BlueprintsGraphMetaverseReader method findLink.
@Override
public IMetaverseLink findLink(String leftNodeID, String linkType, String rightNodeID, Direction direction) {
Vertex vertex = getGraph().getVertex(leftNodeID);
if (vertex == null) {
return null;
}
Iterable<Edge> edges = linkType == null ? vertex.getEdges(direction) : vertex.getEdges(direction, linkType);
IMetaverseLink link = new MetaverseLink();
IMetaverseNode node1 = new MetaverseNode(vertex);
Direction opDirection = direction == Direction.IN ? Direction.OUT : Direction.IN;
Vertex vertex2 = null;
if (rightNodeID != null) {
Iterator<Edge> it = edges.iterator();
while (it.hasNext()) {
Edge edge = it.next();
if (rightNodeID.equals((String) edge.getVertex(opDirection).getId())) {
vertex2 = edge.getVertex(opDirection);
IMetaverseNode node2 = new MetaverseNode(vertex2);
String label = edge.getLabel();
link.setLabel(label);
String localized = Messages.getString(MetaverseUtil.MESSAGE_PREFIX_LINKTYPE + label);
if (!localized.startsWith("!")) {
link.setProperty(DictionaryConst.PROPERTY_TYPE_LOCALIZED, localized);
}
if (direction == Direction.OUT) {
link.setFromNode(node1);
link.setToNode(node2);
} else {
link.setFromNode(node2);
link.setToNode(node1);
}
return link;
}
}
}
return null;
}
use of com.tinkerpop.blueprints.Direction in project atlas by apache.
the class Titan0GraphManagement method createEdgeIndex.
@Override
public void createEdgeIndex(String label, String indexName, AtlasEdgeDirection edgeDirection, List<AtlasPropertyKey> propertyKeys) {
EdgeLabel edgeLabel = management.getEdgeLabel(label);
if (edgeLabel == null) {
edgeLabel = management.makeEdgeLabel(label).make();
}
Direction direction = TitanObjectFactory.createDirection(edgeDirection);
PropertyKey[] keys = TitanObjectFactory.createPropertyKeys(propertyKeys);
management.buildEdgeIndex(edgeLabel, indexName, direction, keys);
}
use of com.tinkerpop.blueprints.Direction in project titan by thinkaurelius.
the class StandardTitanGraph method commit.
public void commit(final Collection<InternalRelation> addedRelations, final Collection<InternalRelation> deletedRelations, final StandardTitanTx tx) {
// Setup
log.debug("Saving transaction. Added {}, removed {}", addedRelations.size(), deletedRelations.size());
final BackendTransaction mutator = tx.getTxHandle();
final boolean acquireLocks = tx.getConfiguration().hasAcquireLocks();
// 1. Assign TitanVertex IDs
if (!tx.getConfiguration().hasAssignIDsImmediately())
idAssigner.assignIDs(addedRelations);
Callable<List<StaticBuffer>> persist = new Callable<List<StaticBuffer>>() {
@Override
public List<StaticBuffer> call() throws Exception {
// 2. Collect deleted edges
ListMultimap<InternalVertex, InternalRelation> mutations = ArrayListMultimap.create();
if (deletedRelations != null && !deletedRelations.isEmpty()) {
for (InternalRelation del : deletedRelations) {
Preconditions.checkArgument(del.isRemoved());
for (int pos = 0; pos < del.getLen(); pos++) {
InternalVertex vertex = del.getVertex(pos);
if (pos == 0 || !del.isLoop())
mutations.put(vertex, del);
Direction dir = EdgeDirection.fromPosition(pos);
if (acquireLocks && del.getType().isUnique(dir) && ((InternalType) del.getType()).uniqueLock(dir)) {
Entry entry = edgeSerializer.writeRelation(del, pos, tx);
mutator.acquireEdgeLock(IDHandler.getKey(vertex.getID()), entry.getColumn(), entry.getValue());
}
}
// Update Indexes
if (del.isProperty()) {
if (acquireLocks)
indexSerializer.lockKeyedProperty((TitanProperty) del, mutator);
}
}
}
ListMultimap<InternalType, InternalRelation> otherEdgeTypes = ArrayListMultimap.create();
// 3. Sort Added Edges
for (InternalRelation relation : addedRelations) {
Preconditions.checkArgument(relation.isNew());
TitanType type = relation.getType();
// Give special treatment to edge type definitions
if (SystemTypeManager.prepersistedSystemTypes.contains(type)) {
InternalType itype = (InternalType) relation.getVertex(0);
otherEdgeTypes.put(itype, relation);
} else {
// STANDARD TitanRelation
for (int pos = 0; pos < relation.getLen(); pos++) {
InternalVertex vertex = relation.getVertex(pos);
if (pos == 0 || !relation.isLoop())
mutations.put(vertex, relation);
Direction dir = EdgeDirection.fromPosition(pos);
if (acquireLocks && relation.getType().isUnique(dir) && !vertex.isNew() && ((InternalType) relation.getType()).uniqueLock(dir)) {
Entry entry = edgeSerializer.writeRelation(relation, pos, tx);
mutator.acquireEdgeLock(IDHandler.getKey(vertex.getID()), entry.getColumn(), null);
}
}
}
// Update Indexes
if (relation.isProperty()) {
if (acquireLocks)
indexSerializer.lockKeyedProperty((TitanProperty) relation, mutator);
}
}
// 3. Persist
List<StaticBuffer> mutatedVertexKeys = new ArrayList<StaticBuffer>();
if (!otherEdgeTypes.isEmpty()) {
mutatedVertexKeys.addAll(persist(otherEdgeTypes, tx));
mutator.flush();
// Register new keys with indexprovider
for (InternalType itype : otherEdgeTypes.keySet()) {
if (itype.isPropertyKey() && itype.isNew())
indexSerializer.newPropertyKey((TitanKey) itype, mutator);
}
}
if (!mutations.isEmpty())
mutatedVertexKeys.addAll(persist(mutations, tx));
mutator.commit();
return mutatedVertexKeys;
}
@Override
public String toString() {
return "PersistingTransaction";
}
};
List<StaticBuffer> mutatedVertexKeys = BackendOperation.execute(persist, maxWriteRetryAttempts, retryStorageWaitTime);
for (StaticBuffer vertexKey : mutatedVertexKeys) edgeStoreCache.invalidate(vertexKey);
}
use of com.tinkerpop.blueprints.Direction in project titan by thinkaurelius.
the class EdgeSerializer method parseRelation.
private RelationCache parseRelation(long vertexid, Entry data, boolean parseHeaderOnly, StandardTitanTx tx) {
assert vertexid > 0;
ReadBuffer column = data.getReadColumn();
ReadBuffer value = data.getReadValue();
LongObjectOpenHashMap properties = parseHeaderOnly ? null : new LongObjectOpenHashMap(4);
long[] typeAndDir = IDHandler.readEdgeType(column);
int dirID = (int) typeAndDir[1];
long typeId = typeAndDir[0];
Direction dir;
RelationType rtype;
switch(dirID) {
case PROPERTY_DIR:
dir = Direction.OUT;
rtype = RelationType.PROPERTY;
break;
case EDGE_OUT_DIR:
dir = Direction.OUT;
rtype = RelationType.EDGE;
break;
case EDGE_IN_DIR:
dir = Direction.IN;
rtype = RelationType.EDGE;
break;
default:
throw new IllegalArgumentException("Invalid dirID read from disk: " + dirID);
}
TitanType titanType = tx.getExistingType(typeId);
InternalType def = (InternalType) titanType;
long[] keysig = def.getSortKey();
if (!parseHeaderOnly && !titanType.isUnique(dir)) {
ReadBuffer sortKeyReader = def.getSortOrder() == Order.DESC ? column.invert() : column;
readInlineTypes(keysig, properties, sortKeyReader, tx);
}
long relationIdDiff, vertexIdDiff = 0;
if (titanType.isUnique(dir)) {
if (rtype == RelationType.EDGE)
vertexIdDiff = VariableLong.read(value);
relationIdDiff = VariableLong.read(value);
} else {
// Move position to end to read backwards
column.movePosition(column.length() - column.getPosition() - 1);
relationIdDiff = VariableLong.readBackward(column);
if (rtype == RelationType.EDGE)
vertexIdDiff = VariableLong.readBackward(column);
}
assert relationIdDiff + vertexid > 0;
long relationId = relationIdDiff + vertexid;
Object other;
switch(rtype) {
case EDGE:
Preconditions.checkArgument(titanType.isEdgeLabel());
other = vertexid + vertexIdDiff;
break;
case PROPERTY:
Preconditions.checkArgument(titanType.isPropertyKey());
TitanKey key = ((TitanKey) titanType);
other = hasGenericDataType(key) ? serializer.readClassAndObject(value) : serializer.readObjectNotNull(value, key.getDataType());
break;
default:
throw new AssertionError();
}
assert other != null;
if (!parseHeaderOnly) {
// value signature & sort key if unique
if (titanType.isUnique(dir)) {
readInlineTypes(keysig, properties, value, tx);
}
readInlineTypes(def.getSignature(), properties, value, tx);
// Third: read rest
while (value.hasRemaining()) {
TitanType type = tx.getExistingType(IDHandler.readInlineEdgeType(value));
Object pvalue = readInline(value, type);
assert pvalue != null;
properties.put(type.getID(), pvalue);
}
}
return new RelationCache(dir, typeId, relationId, other, properties);
}
Aggregations