Skip to content

Commit

Permalink
Fixed issue #3425
Browse files Browse the repository at this point in the history
  • Loading branch information
lvca committed Jan 19, 2015
1 parent b9a00e0 commit ef7ae2d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 47 deletions.
@@ -1,22 +1,22 @@
/* /*
* *
* * Copyright 2014 Orient Technologies LTD (info(at)orientechnologies.com) * * Copyright 2014 Orient Technologies LTD (info(at)orientechnologies.com)
* * * *
* * Licensed under the Apache License, Version 2.0 (the "License"); * * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License. * * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at * * You may obtain a copy of the License at
* * * *
* * http://www.apache.org/licenses/LICENSE-2.0 * * http://www.apache.org/licenses/LICENSE-2.0
* * * *
* * Unless required by applicable law or agreed to in writing, software * * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS, * * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and * * See the License for the specific language governing permissions and
* * limitations under the License. * * limitations under the License.
* * * *
* * For more information: http://www.orientechnologies.com * * For more information: http://www.orientechnologies.com
* *
*/ */


package com.tinkerpop.blueprints.impls.orient; package com.tinkerpop.blueprints.impls.orient;


Expand Down Expand Up @@ -155,7 +155,7 @@ private static void removeLightweightConnection(final ODocument iVertex, final S
} }


public OrientEdgeType getType() { public OrientEdgeType getType() {
final OrientBaseGraph graph = getGraph(); final OrientBaseGraph graph = getGraph();
return isLightweight() ? null : new OrientEdgeType(graph, ((ODocument) rawElement.getRecord()).getSchemaClass()); return isLightweight() ? null : new OrientEdgeType(graph, ((ODocument) rawElement.getRecord()).getSchemaClass());
} }


Expand All @@ -167,7 +167,7 @@ public OrientEdgeType getType() {
*/ */
@Override @Override
public OrientVertex getVertex(final Direction direction) { public OrientVertex getVertex(final Direction direction) {
final OrientBaseGraph graph = getGraph(); final OrientBaseGraph graph = getGraph();
if (graph != null) if (graph != null)
graph.setCurrentGraphInThreadLocal(); graph.setCurrentGraphInThreadLocal();


Expand All @@ -183,7 +183,7 @@ else if (direction.equals(Direction.IN))
* (Blueprints Extension) Returns the outgoing vertex in form of record. * (Blueprints Extension) Returns the outgoing vertex in form of record.
*/ */
public OIdentifiable getOutVertex() { public OIdentifiable getOutVertex() {
final OrientBaseGraph graph = getGraph(); final OrientBaseGraph graph = getGraph();
if (vOut != null) if (vOut != null)
// LIGHTWEIGHT EDGE // LIGHTWEIGHT EDGE
return vOut; return vOut;
Expand All @@ -206,7 +206,7 @@ public OIdentifiable getOutVertex() {
* (Blueprints Extension) Returns the incoming vertex in form of record. * (Blueprints Extension) Returns the incoming vertex in form of record.
*/ */
public OIdentifiable getInVertex() { public OIdentifiable getInVertex() {
final OrientBaseGraph graph = getGraph(); final OrientBaseGraph graph = getGraph();
if (vIn != null) if (vIn != null)
// LIGHTWEIGHT EDGE // LIGHTWEIGHT EDGE
return vIn; return vIn;
Expand All @@ -232,7 +232,7 @@ public OIdentifiable getInVertex() {
*/ */
@Override @Override
public String getLabel() { public String getLabel() {
final OrientBaseGraph graph = getGraph(); final OrientBaseGraph graph = getGraph();
if (label != null) if (label != null)
// LIGHTWEIGHT EDGE // LIGHTWEIGHT EDGE
return label; return label;
Expand Down Expand Up @@ -262,8 +262,7 @@ else if (rawElement != null) {
public boolean equals(final Object object) { public boolean equals(final Object object) {
if (rawElement == null && object instanceof OrientEdge) { if (rawElement == null && object instanceof OrientEdge) {
final OrientEdge other = (OrientEdge) object; final OrientEdge other = (OrientEdge) object;
return vOut.equals(other.vOut) && vIn.equals(other.vIn) return vOut.equals(other.vOut) && vIn.equals(other.vIn) && (Objects.equals(label, other.label));
&& (Objects.equals(label, other.label));
} }
return super.equals(object); return super.equals(object);
} }
Expand All @@ -273,7 +272,7 @@ public boolean equals(final Object object) {
*/ */
@Override @Override
public Object getId() { public Object getId() {
final OrientBaseGraph graph = getGraph(); final OrientBaseGraph graph = getGraph();
if (rawElement == null) if (rawElement == null)
// CREATE A TEMPORARY ID // CREATE A TEMPORARY ID
return vOut.getIdentity() + "->" + vIn.getIdentity(); return vOut.getIdentity() + "->" + vIn.getIdentity();
Expand All @@ -293,7 +292,7 @@ public Object getId() {
*/ */
@Override @Override
public <T> T getProperty(final String key) { public <T> T getProperty(final String key) {
final OrientBaseGraph graph = getGraph(); final OrientBaseGraph graph = getGraph();
graph.setCurrentGraphInThreadLocal(); graph.setCurrentGraphInThreadLocal();


if (rawElement == null) if (rawElement == null)
Expand All @@ -313,7 +312,7 @@ public boolean isLightweight() {
*/ */
@Override @Override
public Set<String> getPropertyKeys() { public Set<String> getPropertyKeys() {
final OrientBaseGraph graph = getGraph(); final OrientBaseGraph graph = getGraph();
if (rawElement == null) if (rawElement == null)
// LIGHTWEIGHT EDGE // LIGHTWEIGHT EDGE
return Collections.emptySet(); return Collections.emptySet();
Expand All @@ -340,7 +339,7 @@ public Set<String> getPropertyKeys() {
*/ */
@Override @Override
public void setProperty(final String key, final Object value) { public void setProperty(final String key, final Object value) {
final OrientBaseGraph graph = getGraph(); final OrientBaseGraph graph = getGraph();
graph.setCurrentGraphInThreadLocal(); graph.setCurrentGraphInThreadLocal();


if (rawElement == null) if (rawElement == null)
Expand All @@ -359,7 +358,7 @@ public void setProperty(final String key, final Object value) {
*/ */
@Override @Override
public <T> T removeProperty(String key) { public <T> T removeProperty(String key) {
final OrientBaseGraph graph = getGraph(); final OrientBaseGraph graph = getGraph();
graph.setCurrentGraphInThreadLocal(); graph.setCurrentGraphInThreadLocal();


if (rawElement != null) if (rawElement != null)
Expand All @@ -373,7 +372,7 @@ public <T> T removeProperty(String key) {
*/ */
@Override @Override
public void remove() { public void remove() {
final OrientBaseGraph graph = getGraph(); final OrientBaseGraph graph = getGraph();
if (!isLightweight()) if (!isLightweight())
checkClass(); checkClass();


Expand All @@ -388,26 +387,38 @@ public void remove() {


// OUT VERTEX // OUT VERTEX
final OIdentifiable inVertexEdge = vIn != null ? vIn : rawElement; final OIdentifiable inVertexEdge = vIn != null ? vIn : rawElement;
final ODocument outVertex = getOutVertex().getRecord();


final String edgeClassName = OrientBaseGraph.encodeClassName(getLabel()); final String edgeClassName = OrientBaseGraph.encodeClassName(getLabel());


final boolean useVertexFieldsForEdgeLabels = settings.isUseVertexFieldsForEdgeLabels(); final boolean useVertexFieldsForEdgeLabels = settings.isUseVertexFieldsForEdgeLabels();


final String outFieldName = OrientVertex.getConnectionFieldName(Direction.OUT, edgeClassName, useVertexFieldsForEdgeLabels); final OIdentifiable outVertex = getOutVertex();
final boolean outVertexChanged = dropEdgeFromVertex(inVertexEdge, outVertex, outFieldName, outVertex.field(outFieldName)); ODocument outVertexRecord = null;
boolean outVertexChanged = false;

if (outVertex != null) {
outVertexRecord = outVertex.getRecord();
final String outFieldName = OrientVertex.getConnectionFieldName(Direction.OUT, edgeClassName, useVertexFieldsForEdgeLabels);
outVertexChanged = dropEdgeFromVertex(inVertexEdge, outVertexRecord, outFieldName, outVertexRecord.field(outFieldName));
}


// IN VERTEX // IN VERTEX
final OIdentifiable outVertexEdge = vOut != null ? vOut : rawElement; final OIdentifiable outVertexEdge = vOut != null ? vOut : rawElement;
final ODocument inVertex = getInVertex().getRecord();


final String inFieldName = OrientVertex.getConnectionFieldName(Direction.IN, edgeClassName, useVertexFieldsForEdgeLabels); final OIdentifiable inVertex = getInVertex();
final boolean inVertexChanged = dropEdgeFromVertex(outVertexEdge, inVertex, inFieldName, inVertex.field(inFieldName)); ODocument inVertexRecord = null;
boolean inVertexChanged = false;

if (inVertex != null) {
inVertexRecord = inVertex.getRecord();
final String inFieldName = OrientVertex.getConnectionFieldName(Direction.IN, edgeClassName, useVertexFieldsForEdgeLabels);
inVertexChanged = dropEdgeFromVertex(outVertexEdge, inVertexRecord, inFieldName, inVertexRecord.field(inFieldName));
}


if (outVertexChanged) if (outVertexChanged)
outVertex.save(); outVertexRecord.save();
if (inVertexChanged) if (inVertexChanged)
inVertex.save(); inVertexRecord.save();


if (rawElement != null) if (rawElement != null)
// NON-LIGHTWEIGHT EDGE // NON-LIGHTWEIGHT EDGE
Expand All @@ -433,7 +444,7 @@ public String getElementType() {
* Returns a string representation of the edge. * Returns a string representation of the edge.
*/ */
public String toString() { public String toString() {
final OrientBaseGraph graph = getGraph(); final OrientBaseGraph graph = getGraph();
if (graph != null) if (graph != null)
graph.setCurrentGraphInThreadLocal(); graph.setCurrentGraphInThreadLocal();


Expand Down Expand Up @@ -468,7 +479,7 @@ public ODocument getRecord() {
* properties. * properties.
*/ */
public void convertToDocument() { public void convertToDocument() {
final OrientBaseGraph graph = getGraph(); final OrientBaseGraph graph = getGraph();
if (rawElement != null) if (rawElement != null)
// ALREADY CONVERTED // ALREADY CONVERTED
return; return;
Expand Down
Expand Up @@ -144,10 +144,7 @@ public void run() {
} }
}; };


Orient Orient.instance().scheduleTask(purgeDeletedRecordsTask, OGlobalConfiguration.DISTRIBUTED_PURGE_RESPONSES_TIMER_DELAY.getValueAsLong(), OGlobalConfiguration.DISTRIBUTED_PURGE_RESPONSES_TIMER_DELAY.getValueAsLong());
.instance()
.scheduleTask(purgeDeletedRecordsTask, OGlobalConfiguration.DISTRIBUTED_PURGE_RESPONSES_TIMER_DELAY.getValueAsLong(),
OGlobalConfiguration.DISTRIBUTED_PURGE_RESPONSES_TIMER_DELAY.getValueAsLong());


asynchronousOperationsQueue = new ArrayBlockingQueue<OAsynchDistributedOperation>(10000); asynchronousOperationsQueue = new ArrayBlockingQueue<OAsynchDistributedOperation>(10000);
asynchWorker = new Thread() { asynchWorker = new Thread() {
Expand Down Expand Up @@ -800,8 +797,12 @@ public Object call() throws Exception {


switch (op.type) { switch (op.type) {
case ORecordOperation.CREATED: case ORecordOperation.CREATED:
task = new OCreateRecordTask(rid, record.toStream(), record.getRecordVersion(), ORecordInternal.getRecordType(record)); final byte[] stream = record.toStream();
break; if (!rid.isPersistent()) {
task = new OCreateRecordTask(rid, stream, record.getRecordVersion(), ORecordInternal.getRecordType(record));
break;
}
// ELSE TREAT IT AS UPDATE: GO DOWN


case ORecordOperation.UPDATED: case ORecordOperation.UPDATED:
// LOAD PREVIOUS CONTENT TO BE USED IN CASE OF UNDO // LOAD PREVIOUS CONTENT TO BE USED IN CASE OF UNDO
Expand Down

0 comments on commit ef7ae2d

Please sign in to comment.