package com.orientechnologies.orient.core.command;

import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.record.impl.ODocumentHelper;

/**
 * This class is designed to compare documents based on deep equality (to be used in Sets)
 */
public class ODocumentEqualityWrapper {
  private final ODocument internal;

  ODocumentEqualityWrapper(ODocument internal) {

    this.internal = internal;
  }

  public boolean equals(Object obj) {
    if(obj instanceof ODocumentEqualityWrapper) {
      return ODocumentHelper.hasSameContentOf(internal, null, ((ODocumentEqualityWrapper)obj).internal, null, null);
    }
    return false;
  }

  @Override
  public int hashCode() {
    int result = 0;
    for (String fieldName : internal.fieldNames()) {
      result += fieldName.hashCode();
      Object value = internal.field(fieldName);
      if (value != null) {
        result += value.hashCode();
      }
    }
    return result;
  }
}

@@ -45,16 +45,159 @@
 mmand;%0A%0A
+import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;%0Aimport com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;%0A
 import c
@@ -668,24 +668,113 @@
 yWrapper) %7B%0A
+      ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();%0A
       return
@@ -817,20 +817,18 @@
 ternal, 
-null
+db
 , ((ODoc
@@ -863,20 +863,18 @@
 ternal, 
-null
+db
 , null);

Fix NPE on EXPLAIN MATCH