Skip to content

Commit

Permalink
My failed attemp to fix supportsRemoveVertices()
Browse files Browse the repository at this point in the history
  • Loading branch information
velo committed Nov 20, 2015
1 parent 9380715 commit 7ba363b
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 12 deletions.
Expand Up @@ -86,10 +86,6 @@ public static class OrientVertexFeatures extends OrientElementFeatures implement
private OrientVertexFeatures() {
}

public boolean supportsRemoveVertices() {
return false;
}

@Override
public boolean supportsMultiProperties() {
return false;
Expand Down
Expand Up @@ -3,6 +3,7 @@
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.db.record.ORecordElement;
import com.orientechnologies.orient.core.db.record.ridbag.ORidBag;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.record.impl.ODocument;

import org.apache.tinkerpop.gremlin.structure.Direction;
Expand Down Expand Up @@ -92,19 +93,25 @@ else if (direction.equals(Direction.IN))

public void remove() {
ODocument doc = getRawDocument();
if (doc.getInternalStatus() == ORecordElement.STATUS.NOT_LOADED) {
if (doc.getInternalStatus() == ORecordElement.STATUS.NOT_LOADED)
doc.load();
}

removeLink(Direction.IN);
removeLink(Direction.OUT);
doc.getDatabase().delete(doc.getIdentity());
removeLink(Direction.IN, vIn);
removeLink(Direction.OUT, vOut);
ORID id = id();
doc.getDatabase().delete(id);
rawElement = new RemovedOIdentifiable(id);
}

@SuppressWarnings("unchecked")
private void removeLink( Direction direction) {
private void removeLink( Direction direction, OIdentifiable rawVertex ) {
final String fieldName = OrientVertex.getConnectionFieldName(direction, this.label());
ODocument doc = this.getVertex(direction).getRawDocument();
ODocument doc;
if (rawVertex instanceof ODocument) {
doc = (ODocument) rawVertex;
} else {
doc = this.getVertex(direction).getRawDocument();
}
Object found = doc.field(fieldName);
if(found instanceof ORidBag) {
ORidBag bag = (ORidBag)found;
Expand All @@ -113,7 +120,7 @@ private void removeLink( Direction direction) {
}
else if (found instanceof Collection<?>) {
((Collection<Object>) found).remove(this.getRawElement());
if(((Collection<Object>) found).size() == 0) doc.removeField(fieldName);
if(((Collection<Object>) found).isEmpty()) doc.removeField(fieldName);
} else
throw new IllegalStateException("Relationship content is invalid on field " + fieldName + ". Found: " + found);
doc.save();
Expand Down
Expand Up @@ -216,6 +216,7 @@ public void remove() {
}

doc.getDatabase().delete(doc.getIdentity());
rawElement = new RemovedOIdentifiable(id());
}


Expand Down
@@ -0,0 +1,59 @@
package org.apache.tinkerpop.gremlin.orientdb;

import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Element;

import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.record.ORecord;
import com.orientechnologies.orient.core.storage.OStorage.LOCKING_STRATEGY;

public final class RemovedOIdentifiable implements OIdentifiable {

private final ORID id;

public RemovedOIdentifiable(ORID id) {
this.id = id;
}

@Override
public int compareTo(OIdentifiable o) {
throw Element.Exceptions.elementAlreadyRemoved(Edge.class, id);
}

@Override
public int compare(OIdentifiable o1, OIdentifiable o2) {
throw Element.Exceptions.elementAlreadyRemoved(Edge.class, id);
}

@Override
public ORID getIdentity() {
throw Element.Exceptions.elementAlreadyRemoved(Edge.class, id);
}

@Override
public <T extends ORecord> T getRecord() {
throw Element.Exceptions.elementAlreadyRemoved(Edge.class, id);
}

@Override
public void lock(boolean iExclusive) {
throw Element.Exceptions.elementAlreadyRemoved(Edge.class, id);
}

@Override
public boolean isLocked() {
throw Element.Exceptions.elementAlreadyRemoved(Edge.class, id);
}

@Override
public LOCKING_STRATEGY lockingStrategy() {
throw Element.Exceptions.elementAlreadyRemoved(Edge.class, id);
}

@Override
public void unlock() {
throw Element.Exceptions.elementAlreadyRemoved(Edge.class, id);
}

}

0 comments on commit 7ba363b

Please sign in to comment.