use of com.orientechnologies.orient.core.collate.OCollate in project orientdb by orientechnologies.
the class OBinaryComparatorV0 method isEqual.
/**
* Compares if 2 field values are the same.
*
* @param iField1
* First value to compare
* @param iField2
* Second value to compare
* @return true if they match, otherwise false
*/
@Override
public boolean isEqual(final OBinaryField iField1, final OBinaryField iField2) {
final BytesContainer fieldValue1 = iField1.bytes;
final int offset1 = fieldValue1.offset;
final BytesContainer fieldValue2 = iField2.bytes;
final int offset2 = fieldValue2.offset;
try {
switch(iField1.type) {
case INTEGER:
{
final int value1 = OVarIntSerializer.readAsInteger(fieldValue1);
switch(iField2.type) {
case INTEGER:
{
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return value1 == value2;
}
case LONG:
case DATETIME:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return value1 == value2;
}
case DATE:
{
final long value2 = (OVarIntSerializer.readAsLong(fieldValue2) * ORecordSerializerBinaryV0.MILLISEC_PER_DAY);
return value1 == value2;
}
case SHORT:
{
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return value1 == value2;
}
case BYTE:
{
final byte value2 = ORecordSerializerBinaryV0.readByte(fieldValue2);
return value1 == value2;
}
case FLOAT:
{
final float value2 = Float.intBitsToFloat(ORecordSerializerBinaryV0.readInteger(fieldValue2));
return value1 == value2;
}
case DOUBLE:
{
final double value2 = Double.longBitsToDouble(ORecordSerializerBinaryV0.readLong(fieldValue2));
return value1 == value2;
}
case STRING:
{
return Integer.parseInt(ORecordSerializerBinaryV0.readString(fieldValue2)) == value1;
}
case DECIMAL:
{
final BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
return value1 == value2.intValue();
}
}
break;
}
case LONG:
{
final long value1 = OVarIntSerializer.readAsLong(fieldValue1);
switch(iField2.type) {
case INTEGER:
{
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return value1 == value2;
}
case LONG:
case DATETIME:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return value1 == value2;
}
case DATE:
{
final long value2 = (OVarIntSerializer.readAsLong(fieldValue2) * ORecordSerializerBinaryV0.MILLISEC_PER_DAY);
return value1 == value2;
}
case SHORT:
{
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return value1 == value2;
}
case BYTE:
{
final byte value2 = ORecordSerializerBinaryV0.readByte(fieldValue2);
return value1 == value2;
}
case FLOAT:
{
final float value2 = Float.intBitsToFloat(ORecordSerializerBinaryV0.readInteger(fieldValue2));
return value1 == value2;
}
case DOUBLE:
{
final double value2 = Double.longBitsToDouble(ORecordSerializerBinaryV0.readLong(fieldValue2));
return value1 == value2;
}
case STRING:
{
return Long.parseLong(ORecordSerializerBinaryV0.readString(fieldValue2)) == value1;
}
case DECIMAL:
{
final BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
return value1 == value2.longValue();
}
}
break;
}
case SHORT:
{
final short value1 = OVarIntSerializer.readAsShort(fieldValue1);
switch(iField2.type) {
case INTEGER:
{
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return value1 == value2;
}
case LONG:
case DATETIME:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return value1 == value2;
}
case DATE:
{
final long value2 = (OVarIntSerializer.readAsLong(fieldValue2) * ORecordSerializerBinaryV0.MILLISEC_PER_DAY);
return value1 == value2;
}
case SHORT:
{
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return value1 == value2;
}
case BYTE:
{
final byte value2 = ORecordSerializerBinaryV0.readByte(fieldValue2);
return value1 == value2;
}
case FLOAT:
{
final float value2 = Float.intBitsToFloat(ORecordSerializerBinaryV0.readInteger(fieldValue2));
return value1 == value2;
}
case DOUBLE:
{
final double value2 = Double.longBitsToDouble(ORecordSerializerBinaryV0.readLong(fieldValue2));
return value1 == value2;
}
case STRING:
{
return Short.parseShort(ORecordSerializerBinaryV0.readString(fieldValue2)) == value1;
}
case DECIMAL:
{
final BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
return value1 == value2.shortValue();
}
}
break;
}
case STRING:
{
switch(iField2.type) {
case INTEGER:
{
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return Integer.parseInt(ORecordSerializerBinaryV0.readString(fieldValue1)) == value2;
}
case LONG:
case DATETIME:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return Long.parseLong(ORecordSerializerBinaryV0.readString(fieldValue1)) == value2;
}
case DATE:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2) * ORecordSerializerBinaryV0.MILLISEC_PER_DAY;
return Long.parseLong(ORecordSerializerBinaryV0.readString(fieldValue1)) == value2;
}
case SHORT:
{
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return Short.parseShort(ORecordSerializerBinaryV0.readString(fieldValue1)) == value2;
}
case BYTE:
{
final byte value2 = ORecordSerializerBinaryV0.readByte(fieldValue2);
return Byte.parseByte(ORecordSerializerBinaryV0.readString(fieldValue1)) == value2;
}
case FLOAT:
{
final float value2 = Float.intBitsToFloat(ORecordSerializerBinaryV0.readInteger(fieldValue2));
return Float.parseFloat(ORecordSerializerBinaryV0.readString(fieldValue1)) == value2;
}
case DOUBLE:
{
final double value2 = Double.longBitsToDouble(ORecordSerializerBinaryV0.readLong(fieldValue2));
return Double.parseDouble(ORecordSerializerBinaryV0.readString(fieldValue1)) == value2;
}
case STRING:
{
final int len1 = OVarIntSerializer.readAsInteger(fieldValue1);
final int len2 = OVarIntSerializer.readAsInteger(fieldValue2);
if (len1 != len2)
return false;
final OCollate collate = (iField1.collate != null && !ODefaultCollate.NAME.equals(iField1.collate.getName())) ? iField1.collate : (iField2.collate != null && !ODefaultCollate.NAME.equals(iField2.collate.getName()) ? iField2.collate : null);
if (collate != null) {
final String str1 = (String) collate.transform(ORecordSerializerBinaryV0.stringFromBytes(fieldValue1.bytes, fieldValue1.offset, len1));
final String str2 = (String) collate.transform(ORecordSerializerBinaryV0.stringFromBytes(fieldValue2.bytes, fieldValue2.offset, len2));
return str1.equals(str2);
} else {
for (int i = 0; i < len1; ++i) {
if (fieldValue1.bytes[fieldValue1.offset + i] != fieldValue2.bytes[fieldValue2.offset + i])
return false;
}
}
return true;
}
case DECIMAL:
{
final BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
return new BigDecimal(ORecordSerializerBinaryV0.readString(fieldValue1)).equals(value2);
}
case BOOLEAN:
{
final boolean value2 = ORecordSerializerBinaryV0.readByte(fieldValue2) == 1;
return Boolean.parseBoolean(ORecordSerializerBinaryV0.readString(fieldValue1)) == value2;
}
}
break;
}
case DOUBLE:
{
final long value1AsLong = ORecordSerializerBinaryV0.readLong(fieldValue1);
switch(iField2.type) {
case INTEGER:
{
final double value1 = Double.longBitsToDouble(value1AsLong);
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return value1 == value2;
}
case LONG:
case DATETIME:
{
final double value1 = Double.longBitsToDouble(value1AsLong);
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return value1 == value2;
}
case SHORT:
{
final double value1 = Double.longBitsToDouble(value1AsLong);
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return value1 == value2;
}
case BYTE:
{
final double value1 = Double.longBitsToDouble(value1AsLong);
final byte value2 = ORecordSerializerBinaryV0.readByte(fieldValue2);
return value1 == value2;
}
case FLOAT:
{
final double value1 = Double.longBitsToDouble(value1AsLong);
final float value2 = Float.intBitsToFloat(ORecordSerializerBinaryV0.readInteger(fieldValue2));
return value1 == value2;
}
case DOUBLE:
{
final double value2AsLong = ORecordSerializerBinaryV0.readLong(fieldValue2);
return value1AsLong == value2AsLong;
}
case STRING:
{
final double value1 = Double.longBitsToDouble(value1AsLong);
return Double.parseDouble(ORecordSerializerBinaryV0.readString(fieldValue2)) == value1;
}
case DECIMAL:
{
final double value1 = Double.longBitsToDouble(value1AsLong);
final BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
return value1 == value2.doubleValue();
}
}
break;
}
case FLOAT:
{
final int value1AsInt = ORecordSerializerBinaryV0.readInteger(fieldValue1);
switch(iField2.type) {
case INTEGER:
{
final float value1 = Float.intBitsToFloat(value1AsInt);
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return value1 == value2;
}
case LONG:
case DATETIME:
{
final float value1 = Float.intBitsToFloat(value1AsInt);
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return value1 == value2;
}
case SHORT:
{
final float value1 = Float.intBitsToFloat(value1AsInt);
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return value1 == value2;
}
case BYTE:
{
final float value1 = Float.intBitsToFloat(value1AsInt);
final byte value2 = ORecordSerializerBinaryV0.readByte(fieldValue2);
return value1 == value2;
}
case FLOAT:
{
final float value2AsInt = ORecordSerializerBinaryV0.readInteger(fieldValue2);
return value1AsInt == value2AsInt;
}
case DOUBLE:
{
final float value1 = Float.intBitsToFloat(value1AsInt);
final double value2 = Double.longBitsToDouble(ORecordSerializerBinaryV0.readLong(fieldValue2));
return value1 == value2;
}
case STRING:
{
final float value1 = Float.intBitsToFloat(value1AsInt);
return Float.parseFloat(ORecordSerializerBinaryV0.readString(fieldValue2)) == value1;
}
case DECIMAL:
{
final float value1 = Float.intBitsToFloat(value1AsInt);
final BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
return value1 == value2.floatValue();
}
}
break;
}
case BYTE:
{
final byte value1 = ORecordSerializerBinaryV0.readByte(fieldValue1);
switch(iField2.type) {
case INTEGER:
{
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return value1 == value2;
}
case LONG:
case DATETIME:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return value1 == value2;
}
case SHORT:
{
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return value1 == value2;
}
case BYTE:
{
final byte value2 = ORecordSerializerBinaryV0.readByte(fieldValue2);
return value1 == value2;
}
case FLOAT:
{
final float value2 = Float.intBitsToFloat(ORecordSerializerBinaryV0.readInteger(fieldValue2));
return value1 == value2;
}
case DOUBLE:
{
final double value2 = Double.longBitsToDouble(ORecordSerializerBinaryV0.readLong(fieldValue2));
return value1 == value2;
}
case STRING:
{
final byte value2 = Byte.parseByte((ORecordSerializerBinaryV0.readString(fieldValue2)));
return value1 == value2;
}
case DECIMAL:
{
final BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
return value1 == value2.byteValue();
}
}
break;
}
case BOOLEAN:
{
final boolean value1 = ORecordSerializerBinaryV0.readByte(fieldValue1) == 1;
switch(iField2.type) {
case BOOLEAN:
{
final boolean value2 = ORecordSerializerBinaryV0.readByte(fieldValue2) == 1;
return value1 == value2;
}
case STRING:
{
final String str = ORecordSerializerBinaryV0.readString(fieldValue2);
return Boolean.parseBoolean(str) == value1;
}
}
break;
}
case DATE:
{
final long value1 = OVarIntSerializer.readAsLong(fieldValue1) * ORecordSerializerBinaryV0.MILLISEC_PER_DAY;
switch(iField2.type) {
case INTEGER:
{
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return value1 == value2;
}
case LONG:
case DATETIME:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return value1 == value2;
}
case DATE:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2) * ORecordSerializerBinaryV0.MILLISEC_PER_DAY;
return value1 == value2;
}
case SHORT:
{
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return value1 == value2;
}
case FLOAT:
{
final float value2 = Float.intBitsToFloat(ORecordSerializerBinaryV0.readInteger(fieldValue2));
return value1 == value2;
}
case DOUBLE:
{
final double value2 = Double.longBitsToDouble(ORecordSerializerBinaryV0.readLong(fieldValue2));
return value1 == value2;
}
case STRING:
{
final String value2AsString = ORecordSerializerBinaryV0.readString(fieldValue2);
if (OIOUtils.isLong(value2AsString)) {
final long value2 = Long.parseLong(value2AsString);
return value1 == value2;
}
final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
try {
final SimpleDateFormat dateFormat = db != null ? db.getStorage().getConfiguration().getDateFormatInstance() : new SimpleDateFormat(OStorageConfiguration.DEFAULT_DATETIME_FORMAT);
final Date value2AsDate = dateFormat.parse(value2AsString);
final long value2 = value2AsDate.getTime();
return value1 == value2;
} catch (ParseException e) {
try {
final SimpleDateFormat dateFormat = db != null ? db.getStorage().getConfiguration().getDateFormatInstance() : new SimpleDateFormat(OStorageConfiguration.DEFAULT_DATE_FORMAT);
final Date value2AsDate = dateFormat.parse(value2AsString);
final long value2 = value2AsDate.getTime();
return value1 == value2;
} catch (ParseException e1) {
return new Date(value1).toString().equals(value2AsString);
}
}
}
case DECIMAL:
{
final BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
return value1 == value2.longValue();
}
}
break;
}
case DATETIME:
{
final long value1 = OVarIntSerializer.readAsLong(fieldValue1);
switch(iField2.type) {
case INTEGER:
{
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return value1 == value2;
}
case LONG:
case DATETIME:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return value1 == value2;
}
case DATE:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2) * ORecordSerializerBinaryV0.MILLISEC_PER_DAY;
return value1 == value2;
}
case SHORT:
{
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return value1 == value2;
}
case FLOAT:
{
final float value2 = Float.intBitsToFloat(ORecordSerializerBinaryV0.readInteger(fieldValue2));
return value1 == value2;
}
case DOUBLE:
{
final double value2 = Double.longBitsToDouble(ORecordSerializerBinaryV0.readLong(fieldValue2));
return value1 == value2;
}
case STRING:
{
final String value2AsString = ORecordSerializerBinaryV0.readString(fieldValue2);
if (OIOUtils.isLong(value2AsString)) {
final long value2 = Long.parseLong(value2AsString);
return value1 == value2;
}
final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
try {
final SimpleDateFormat dateFormat = db != null ? db.getStorage().getConfiguration().getDateTimeFormatInstance() : new SimpleDateFormat(OStorageConfiguration.DEFAULT_DATETIME_FORMAT);
final Date value2AsDate = dateFormat.parse(value2AsString);
final long value2 = value2AsDate.getTime();
return value1 == value2;
} catch (ParseException e) {
try {
final SimpleDateFormat dateFormat = db != null ? db.getStorage().getConfiguration().getDateFormatInstance() : new SimpleDateFormat(OStorageConfiguration.DEFAULT_DATE_FORMAT);
final Date value2AsDate = dateFormat.parse(value2AsString);
final long value2 = value2AsDate.getTime();
return value1 == value2;
} catch (ParseException e1) {
return new Date(value1).toString().equals(value2AsString);
}
}
}
case DECIMAL:
{
final BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
return value1 == value2.longValue();
}
}
break;
}
case BINARY:
{
switch(iField2.type) {
case BINARY:
{
final int length1 = OVarIntSerializer.readAsInteger(fieldValue1);
final int length2 = OVarIntSerializer.readAsInteger(fieldValue2);
if (length1 != length2)
return false;
for (int i = 0; i < length1; ++i) {
if (fieldValue1.bytes[fieldValue1.offset + i] != fieldValue2.bytes[fieldValue2.offset + i])
return false;
}
return true;
}
}
break;
}
case LINK:
{
switch(iField2.type) {
case LINK:
{
final int clusterId1 = OVarIntSerializer.readAsInteger(fieldValue1);
final int clusterId2 = OVarIntSerializer.readAsInteger(fieldValue2);
if (clusterId1 != clusterId2)
return false;
final long clusterPos1 = OVarIntSerializer.readAsLong(fieldValue1);
final long clusterPos2 = OVarIntSerializer.readAsLong(fieldValue2);
if (clusterPos1 == clusterPos2)
return true;
}
case STRING:
{
return ORecordSerializerBinaryV0.readOptimizedLink(fieldValue1).toString().equals(ORecordSerializerBinaryV0.readString(fieldValue2));
}
}
break;
}
case DECIMAL:
{
BigDecimal value1 = ODecimalSerializer.INSTANCE.deserialize(fieldValue1.bytes, fieldValue1.offset);
switch(iField2.type) {
case INTEGER:
{
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return value1.equals(new BigDecimal(value2).setScale(value1.scale()));
}
case LONG:
case DATETIME:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return value1.equals(new BigDecimal(value2));
}
case SHORT:
{
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return value1.equals(new BigDecimal(value2));
}
case FLOAT:
{
final float value2 = Float.intBitsToFloat(ORecordSerializerBinaryV0.readInteger(fieldValue2));
return value1.equals(new BigDecimal(value2));
}
case DOUBLE:
{
final double value2 = Double.longBitsToDouble(ORecordSerializerBinaryV0.readLong(fieldValue2));
return value1.equals(new BigDecimal(value2));
}
case STRING:
{
return value1.toString().equals(ORecordSerializerBinaryV0.readString(fieldValue2));
}
case DECIMAL:
{
BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
int maxScale = Math.max(value1.scale(), value2.scale());
value1 = value1.setScale(maxScale, BigDecimal.ROUND_DOWN);
value2 = value2.setScale(maxScale, BigDecimal.ROUND_DOWN);
return value1.equals(value2);
}
}
break;
}
}
} finally {
fieldValue1.offset = offset1;
fieldValue2.offset = offset2;
}
return false;
}
use of com.orientechnologies.orient.core.collate.OCollate in project orientdb by orientechnologies.
the class OSimpleKeyIndexDefinition method serializeToStream.
@Override
protected void serializeToStream() {
super.serializeToStream();
final List<String> keyTypeNames = new ArrayList<String>(keyTypes.length);
for (final OType keyType : keyTypes) keyTypeNames.add(keyType.toString());
document.field("keyTypes", keyTypeNames, OType.EMBEDDEDLIST);
if (collate instanceof OCompositeCollate) {
List<String> collatesNames = new ArrayList<String>();
for (OCollate curCollate : ((OCompositeCollate) this.collate).getCollates()) collatesNames.add(curCollate.getName());
document.field("collates", collatesNames, OType.EMBEDDEDLIST);
} else
document.field("collate", collate.getName());
document.field("nullValuesIgnored", isNullValuesIgnored());
}
use of com.orientechnologies.orient.core.collate.OCollate in project orientdb by orientechnologies.
the class OCommandExecutorSQLCreateIndex method execute.
/**
* Execute the CREATE INDEX.
*/
@SuppressWarnings("rawtypes")
public Object execute(final Map<Object, Object> iArgs) {
if (indexName == null)
throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
final ODatabaseDocument database = getDatabase();
final OIndex<?> idx;
List<OCollate> collatesList = null;
if (collates != null) {
collatesList = new ArrayList<OCollate>();
for (String collate : collates) {
if (collate != null) {
final OCollate col = OSQLEngine.getCollate(collate);
collatesList.add(col);
} else
collatesList.add(null);
}
}
if (fields == null || fields.length == 0) {
OIndexFactory factory = OIndexes.getFactory(indexType.toString(), null);
if (keyTypes != null)
idx = database.getMetadata().getIndexManager().createIndex(indexName, indexType.toString(), new OSimpleKeyIndexDefinition(keyTypes, collatesList, factory.getLastVersion()), null, null, metadataDoc, engine);
else if (serializerKeyId != 0) {
idx = database.getMetadata().getIndexManager().createIndex(indexName, indexType.toString(), new ORuntimeKeyIndexDefinition(serializerKeyId, factory.getLastVersion()), null, null, metadataDoc, engine);
} else {
OLogManager.instance().warn(this, "Key type is not provided for '%s' index. Untyped indexes are deprecated and considered unstable." + " Please specify a key type.", indexName);
idx = database.getMetadata().getIndexManager().createIndex(indexName, indexType.toString(), null, null, null, metadataDoc, engine);
}
} else {
if ((keyTypes == null || keyTypes.length == 0) && collates == null) {
idx = oClass.createIndex(indexName, indexType.toString(), null, metadataDoc, engine, fields);
} else {
final List<OType> fieldTypeList;
if (keyTypes == null) {
for (final String fieldName : fields) {
if (!fieldName.equals("@rid") && !oClass.existsProperty(fieldName))
throw new OIndexException("Index with name : '" + indexName + "' cannot be created on class : '" + oClass.getName() + "' because field: '" + fieldName + "' is absent in class definition.");
}
fieldTypeList = ((OClassImpl) oClass).extractFieldTypes(fields);
} else
fieldTypeList = Arrays.asList(keyTypes);
final OIndexDefinition idxDef = OIndexDefinitionFactory.createIndexDefinition(oClass, Arrays.asList(fields), fieldTypeList, collatesList, indexType.toString(), null);
idx = database.getMetadata().getIndexManager().createIndex(indexName, indexType.name(), idxDef, oClass.getPolymorphicClusterIds(), null, metadataDoc, engine);
}
}
if (idx != null)
return idx.getSize();
return null;
}
use of com.orientechnologies.orient.core.collate.OCollate in project orientdb by orientechnologies.
the class OSQLEngine method getCollate.
public static OCollate getCollate(final String name) {
for (Iterator<OCollateFactory> iter = getCollateFactories(); iter.hasNext(); ) {
OCollateFactory f = iter.next();
final OCollate c = f.getCollate(name);
if (c != null)
return c;
}
return null;
}
use of com.orientechnologies.orient.core.collate.OCollate in project orientdb by orientechnologies.
the class OQueryOperatorEquality method evaluateRecord.
@Override
public Object evaluateRecord(final OIdentifiable iRecord, ODocument iCurrentResult, final OSQLFilterCondition iCondition, final Object iLeft, final Object iRight, OCommandContext iContext) {
if (iLeft instanceof OBinaryField && iRight instanceof OBinaryField)
// BINARY COMPARISON
return evaluate((OBinaryField) iLeft, (OBinaryField) iRight, iContext);
else if (iLeft instanceof OQueryRuntimeValueMulti) {
// LEFT = MULTI
final OQueryRuntimeValueMulti left = (OQueryRuntimeValueMulti) iLeft;
if (left.getValues().length == 0)
return false;
if (left.getDefinition().getRoot().startsWith(OSQLFilterItemFieldAll.NAME)) {
// ALL VALUES
for (int i = 0; i < left.getValues().length; ++i) {
Object v = left.getValues()[i];
Object r = iRight;
final OCollate collate = left.getCollate(i);
if (collate != null) {
v = collate.transform(v);
r = collate.transform(iRight);
}
if (v == null || !evaluateExpression(iRecord, iCondition, v, r, iContext))
return false;
}
return true;
} else {
// ANY VALUES
for (int i = 0; i < left.getValues().length; ++i) {
Object v = left.getValues()[i];
Object r = iRight;
final OCollate collate = left.getCollate(i);
if (collate != null) {
v = collate.transform(v);
r = collate.transform(iRight);
}
if (v != null && evaluateExpression(iRecord, iCondition, v, r, iContext))
return true;
}
return false;
}
} else if (iRight instanceof OQueryRuntimeValueMulti) {
// RIGHT = MULTI
final OQueryRuntimeValueMulti right = (OQueryRuntimeValueMulti) iRight;
if (right.getValues().length == 0)
return false;
if (right.getDefinition().getRoot().startsWith(OSQLFilterItemFieldAll.NAME)) {
// ALL VALUES
for (int i = 0; i < right.getValues().length; ++i) {
Object v = right.getValues()[i];
Object l = iLeft;
final OCollate collate = right.getCollate(i);
if (collate != null) {
v = collate.transform(v);
l = collate.transform(iLeft);
}
if (v == null || !evaluateExpression(iRecord, iCondition, l, v, iContext))
return false;
}
return true;
} else {
// ANY VALUES
for (int i = 0; i < right.getValues().length; ++i) {
Object v = right.getValues()[i];
Object l = iLeft;
final OCollate collate = right.getCollate(i);
if (collate != null) {
v = collate.transform(v);
l = collate.transform(iLeft);
}
if (v != null && evaluateExpression(iRecord, iCondition, l, v, iContext))
return true;
}
return false;
}
} else {
// SINGLE SIMPLE ITEM
return evaluateExpression(iRecord, iCondition, iLeft, iRight, iContext);
}
}
Aggregations