Skip to content

Commit

Permalink
Fixed issue #5081 by supporting binary query at storage level
Browse files Browse the repository at this point in the history
  • Loading branch information
lvca committed Oct 10, 2015
1 parent 1f5e71e commit d58b62d
Show file tree
Hide file tree
Showing 17 changed files with 448 additions and 148 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -23,3 +23,5 @@ out
.idea/ .idea/


tests/src/test/java/com/orientechnologies/orient/test/database/auto/_*.xml tests/src/test/java/com/orientechnologies/orient/test/database/auto/_*.xml

export/
@@ -1,3 +1,22 @@
/*
*
* * Copyright 2014 Orient Technologies LTD (info(at)orientechnologies.com)
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *
* * For more information: http://www.orientechnologies.com
*
*/
package com.orientechnologies.orient.core.metadata.schema; package com.orientechnologies.orient.core.metadata.schema;


import com.orientechnologies.common.listener.OProgressListener; import com.orientechnologies.common.listener.OProgressListener;
Expand Down
@@ -1,5 +1,32 @@
/*
*
* * Copyright 2014 Orient Technologies LTD (info(at)orientechnologies.com)
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *
* * For more information: http://www.orientechnologies.com
*
*/
package com.orientechnologies.orient.core.metadata.schema; package com.orientechnologies.orient.core.metadata.schema;


import com.orientechnologies.orient.core.collate.OCollate;
import com.orientechnologies.orient.core.index.OIndex;
import com.orientechnologies.orient.core.index.OIndexDefinition;
import com.orientechnologies.orient.core.metadata.schema.validation.ValidationBinaryComparable;
import com.orientechnologies.orient.core.metadata.schema.validation.ValidationCollectionComparable;
import com.orientechnologies.orient.core.metadata.schema.validation.ValidationMapComparable;
import com.orientechnologies.orient.core.metadata.schema.validation.ValidationStringComparable;

import java.util.Calendar; import java.util.Calendar;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
Expand All @@ -10,14 +37,6 @@
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;


import com.orientechnologies.orient.core.collate.OCollate;
import com.orientechnologies.orient.core.index.OIndex;
import com.orientechnologies.orient.core.index.OIndexDefinition;
import com.orientechnologies.orient.core.metadata.schema.validation.ValidationBinaryComparable;
import com.orientechnologies.orient.core.metadata.schema.validation.ValidationCollectionComparable;
import com.orientechnologies.orient.core.metadata.schema.validation.ValidationMapComparable;
import com.orientechnologies.orient.core.metadata.schema.validation.ValidationStringComparable;

/** /**
* @author Andrey Lomakin (a.lomakin-at-orientechnologies.com) * @author Andrey Lomakin (a.lomakin-at-orientechnologies.com)
* @since 10/21/14 * @since 10/21/14
Expand Down
@@ -1,3 +1,22 @@
/*
*
* * Copyright 2014 Orient Technologies LTD (info(at)orientechnologies.com)
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *
* * For more information: http://www.orientechnologies.com
*
*/
package com.orientechnologies.orient.core.metadata.schema; package com.orientechnologies.orient.core.metadata.schema;


import com.orientechnologies.common.util.OArrays; import com.orientechnologies.common.util.OArrays;
Expand Down
@@ -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.orientechnologies.orient.core.query; package com.orientechnologies.orient.core.query;


import com.orientechnologies.orient.core.command.OCommandRequestAbstract; import com.orientechnologies.orient.core.command.OCommandRequestAbstract;
Expand Down Expand Up @@ -59,7 +59,9 @@ public OQueryAbstract setFetchPlan(final String fetchPlan) {
public void reset() { public void reset() {
} }


@Override
public boolean isIdempotent() { public boolean isIdempotent() {
return true; return true;
} }

} }
Expand Up @@ -875,7 +875,7 @@ public static boolean hasSameContentItem(final Object iCurrent, ODatabaseDocumen
} }
} else if (!ODocumentHelper.hasSameContentOf(current, iMyDb, (ODocument) iOther, iOtherDb, ridMapper)) } else if (!ODocumentHelper.hasSameContentOf(current, iMyDb, (ODocument) iOther, iOtherDb, ridMapper))
return false; return false;
} else if (!compareScalarValues(iCurrent, iOther, ridMapper)) } else if (!compareScalarValues(iCurrent, iMyDb, iOther, iOtherDb, ridMapper))
return false; return false;
return true; return true;
} }
Expand Down Expand Up @@ -910,7 +910,7 @@ public static boolean hasSameContentOf(final ODocument iCurrent, final ODatabase
if (iOther == null) if (iOther == null)
return false; return false;


if (iCheckAlsoIdentity && !iCurrent.equals(iOther) && iCurrent.getIdentity().isValid()) if (iCheckAlsoIdentity && iCurrent.getIdentity().isValid() && !iCurrent.getIdentity().equals(iOther.getIdentity()))
return false; return false;


if (iMyDb != null) if (iMyDb != null)
Expand Down Expand Up @@ -988,7 +988,7 @@ public Object call() {
if (!hasSameContentOf((ODocument) myFieldValue, iMyDb, (ODocument) otherFieldValue, iOtherDb, ridMapper)) if (!hasSameContentOf((ODocument) myFieldValue, iMyDb, (ODocument) otherFieldValue, iOtherDb, ridMapper))
return false; return false;
} else { } else {
if (!compareScalarValues(myFieldValue, otherFieldValue, ridMapper)) if (!compareScalarValues(myFieldValue, iMyDb, otherFieldValue, iOtherDb, ridMapper))
return false; return false;
} }
} }
Expand Down Expand Up @@ -1073,7 +1073,7 @@ public Object call() {
} }
}); });


if (!compareScalarValues(myValue, otherValue, ridMapper)) if (!compareScalarValues(myValue, iMyDb, otherValue, iOtherDb, ridMapper))
return false; return false;
} }
} }
Expand Down Expand Up @@ -1330,7 +1330,8 @@ public Boolean call() {
} }
} }


private static boolean compareScalarValues(Object myValue, Object otherValue, RIDMapper ridMapper) { private static boolean compareScalarValues(Object myValue, ODatabaseDocumentInternal iMyDb, Object otherValue,
ODatabaseDocumentInternal iOtherDb, RIDMapper ridMapper) {
if (myValue == null && otherValue != null || myValue != null && otherValue == null) if (myValue == null && otherValue != null || myValue != null && otherValue == null)
return false; return false;


Expand All @@ -1351,7 +1352,12 @@ private static boolean compareScalarValues(Object myValue, Object otherValue, RI
for (int i = 0; i < myArraySize; i++) { for (int i = 0; i < myArraySize; i++) {
final Object first = Array.get(myValue, i); final Object first = Array.get(myValue, i);
final Object second = Array.get(otherValue, i); final Object second = Array.get(otherValue, i);
if (first == null && second != null || (first != null && !first.equals(second))) if (first == null && second != null)
return false;
if (first instanceof ODocument && second instanceof ODocument)
return hasSameContentOf((ODocument) first, iMyDb, (ODocument) second, iOtherDb, ridMapper);

if (first != null && !first.equals(second))
return false; return false;
} }


Expand Down
Expand Up @@ -20,6 +20,16 @@


package com.orientechnologies.orient.core.serialization.serializer.record.binary; package com.orientechnologies.orient.core.serialization.serializer.record.binary;


import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.orientechnologies.common.collection.OMultiValue; import com.orientechnologies.common.collection.OMultiValue;
import com.orientechnologies.common.exception.OException; import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.serialization.types.ODecimalSerializer; import com.orientechnologies.common.serialization.types.ODecimalSerializer;
Expand Down Expand Up @@ -56,16 +66,6 @@
import com.orientechnologies.orient.core.type.tree.OMVRBTreeRIDSet; import com.orientechnologies.orient.core.type.tree.OMVRBTreeRIDSet;
import com.orientechnologies.orient.core.util.ODateHelper; import com.orientechnologies.orient.core.util.ODateHelper;


import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class ORecordSerializerBinaryV0 implements ODocumentSerializer { public class ORecordSerializerBinaryV0 implements ODocumentSerializer {


private static final String CHARSET_UTF_8 = "UTF-8"; private static final String CHARSET_UTF_8 = "UTF-8";
Expand Down Expand Up @@ -106,7 +106,7 @@ public void deserializePartial(final ODocument document, final BytesContainer by
// CHECK BY FIELD NAME SIZE: THIS AVOID EVEN THE UNMARSHALLING OF FIELD NAME // CHECK BY FIELD NAME SIZE: THIS AVOID EVEN THE UNMARSHALLING OF FIELD NAME
boolean match = false; boolean match = false;
for (int i = 0; i < iFields.length; ++i) { for (int i = 0; i < iFields.length; ++i) {
if (iFields[i].length() == len) { if (iFields[i] != null && iFields[i].length() == len) {
boolean matchField = true; boolean matchField = true;
for (int j = 0; j < len; ++j) { for (int j = 0; j < len; ++j) {
if (bytes.bytes[bytes.offset + j] != fields[i][j]) { if (bytes.bytes[bytes.offset + j] != fields[i][j]) {
Expand Down
Expand Up @@ -19,7 +19,12 @@
*/ */
package com.orientechnologies.orient.core.sql; package com.orientechnologies.orient.core.sql;


import com.orientechnologies.orient.core.command.*; import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.command.OCommandDistributedReplicateRequest;
import com.orientechnologies.orient.core.command.OCommandExecutor;
import com.orientechnologies.orient.core.command.OCommandExecutorNotFoundException;
import com.orientechnologies.orient.core.command.OCommandRequest;
import com.orientechnologies.orient.core.command.OCommandRequestText;
import com.orientechnologies.orient.core.exception.OCommandExecutionException; import com.orientechnologies.orient.core.exception.OCommandExecutionException;


import java.util.Map; import java.util.Map;
Expand Down Expand Up @@ -86,6 +91,7 @@ public String getFetchPlan() {
return delegate.getFetchPlan(); return delegate.getFetchPlan();
} }


@Override
public boolean isIdempotent() { public boolean isIdempotent() {
return delegate.isIdempotent(); return delegate.isIdempotent();
} }
Expand Down
Expand Up @@ -30,7 +30,7 @@ public interface OCommandExecutorSQLFactory {
/** /**
* @return Set of supported command names of this factory * @return Set of supported command names of this factory
*/ */
public Set<String> getCommandNames(); Set<String> getCommandNames();


/** /**
* Create command for the given name. returned command may be a new instance each time or a constant. * Create command for the given name. returned command may be a new instance each time or a constant.
Expand All @@ -40,5 +40,5 @@ public interface OCommandExecutorSQLFactory {
* @throws OCommandExecutionException * @throws OCommandExecutionException
* : when command creation fail * : when command creation fail
*/ */
public OCommandExecutor createCommand(String name) throws OCommandExecutionException; OCommandExecutor createCommand(String name) throws OCommandExecutionException;
} }

0 comments on commit d58b62d

Please sign in to comment.