signature:
public class OBinaryComparatorV0 { /** * Compares two values executing also conversion between types .
 * @ param iField1 First value to compare
 * @ param iField2 Second value to compare
 * @ return 0 if they matches , > 0 if first value is major than second , < 0 in case is minor */
@ Override public int compare ( final OBinaryField iField1 , final OBinaryField iField2 ) { } }

implementation:
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 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case LONG : case DATETIME : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case DATE : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) * MILLISEC_PER_DAY ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case SHORT : { final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case BYTE : { final byte value2 = readByte ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case FLOAT : { final float value2 = Float . intBitsToFloat ( readInteger ( fieldValue2 ) ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case DOUBLE : { final double value2 = Double . longBitsToDouble ( readLong ( fieldValue2 ) ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case STRING : { final String value2 = readString ( fieldValue2 ) ; return Integer . toString ( value1 ) . compareTo ( value2 ) ; } case DECIMAL : { final int value2 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue2 . bytes , fieldValue2 . offset ) . intValue ( ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } } break ; } case LONG : { final long value1 = OVarIntSerializer . readAsLong ( fieldValue1 ) ; switch ( iField2 . type ) { case INTEGER : { final int value2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case LONG : case DATETIME : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case DATE : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) * MILLISEC_PER_DAY ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case SHORT : { final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case BYTE : { final byte value2 = readByte ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case FLOAT : { final float value2 = Float . intBitsToFloat ( readInteger ( fieldValue2 ) ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case DOUBLE : { final double value2 = Double . longBitsToDouble ( readLong ( fieldValue2 ) ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case STRING : { final String value2 = readString ( fieldValue2 ) ; return Long . toString ( value1 ) . compareTo ( value2 ) ; } case DECIMAL : { final long value2 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue2 . bytes , fieldValue2 . offset ) . longValue ( ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } } break ; } case SHORT : { final short value1 = OVarIntSerializer . readAsShort ( fieldValue1 ) ; switch ( iField2 . type ) { case INTEGER : { final int value2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case LONG : case DATETIME : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case DATE : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) * MILLISEC_PER_DAY ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case SHORT : { final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case BYTE : { final byte value2 = readByte ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case FLOAT : { final float value2 = Float . intBitsToFloat ( readInteger ( fieldValue2 ) ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case DOUBLE : { final double value2 = Double . longBitsToDouble ( readLong ( fieldValue2 ) ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case STRING : { final String value2 = readString ( fieldValue2 ) ; return Short . toString ( value1 ) . compareTo ( value2 ) ; } case DECIMAL : { final short value2 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue2 . bytes , fieldValue2 . offset ) . shortValue ( ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } } break ; } case STRING : { final String value1 = readString ( fieldValue1 ) ; switch ( iField2 . type ) { case INTEGER : { final int value2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; return value1 . compareTo ( Integer . toString ( value2 ) ) ; } case LONG : case DATETIME : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; return value1 . compareTo ( Long . toString ( value2 ) ) ; } case DATE : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) * MILLISEC_PER_DAY ; return value1 . compareTo ( Long . toString ( value2 ) ) ; } case SHORT : { final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return value1 . compareTo ( Short . toString ( value2 ) ) ; } case BYTE : { final byte value2 = readByte ( fieldValue2 ) ; return value1 . compareTo ( Byte . toString ( value2 ) ) ; } case FLOAT : { final float value2 = Float . intBitsToFloat ( readInteger ( fieldValue2 ) ) ; return value1 . compareTo ( Float . toString ( value2 ) ) ; } case DOUBLE : { final double value2 = Double . longBitsToDouble ( readLong ( fieldValue2 ) ) ; return value1 . compareTo ( Double . toString ( value2 ) ) ; } case STRING : { final String value2 = readString ( fieldValue2 ) ; 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 ( value1 ) ; final String str2 = ( String ) collate . transform ( value2 ) ; return str1 . compareTo ( str2 ) ; } return value1 . compareTo ( value2 ) ; } case BOOLEAN : { final boolean value2 = readByte ( fieldValue2 ) == 1 ; return value1 . compareTo ( Boolean . toString ( value2 ) ) ; } case DECIMAL : { final BigDecimal value2 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue2 . bytes , fieldValue2 . offset ) ; return new BigDecimal ( value1 ) . compareTo ( value2 ) ; } } break ; } case DOUBLE : { final double value1 = Double . longBitsToDouble ( readLong ( fieldValue1 ) ) ; switch ( iField2 . type ) { case INTEGER : { final int value2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case LONG : case DATETIME : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case SHORT : { final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case BYTE : { final byte value2 = readByte ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case FLOAT : { final float value2 = Float . intBitsToFloat ( readInteger ( fieldValue2 ) ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case DOUBLE : { final double value2 = Double . longBitsToDouble ( readLong ( fieldValue2 ) ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case STRING : { final String value2 = readString ( fieldValue2 ) ; return Double . toString ( value1 ) . compareTo ( value2 ) ; } case DECIMAL : { final double value2 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue2 . bytes , fieldValue2 . offset ) . doubleValue ( ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } } break ; } case FLOAT : { final float value1 = Float . intBitsToFloat ( readInteger ( fieldValue1 ) ) ; switch ( iField2 . type ) { case INTEGER : { final int value2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case LONG : case DATETIME : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case SHORT : { final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case BYTE : { final byte value2 = readByte ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case FLOAT : { final float value2 = Float . intBitsToFloat ( readInteger ( fieldValue2 ) ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case DOUBLE : { final double value2 = Double . longBitsToDouble ( readLong ( fieldValue2 ) ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case STRING : { final String value2 = readString ( fieldValue2 ) ; return Float . toString ( value1 ) . compareTo ( value2 ) ; } case DECIMAL : { final String value2 = readString ( fieldValue2 ) ; return Float . toString ( value1 ) . compareTo ( value2 ) ; } } break ; } case BYTE : { final byte value1 = readByte ( fieldValue1 ) ; switch ( iField2 . type ) { case INTEGER : { final int value2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case LONG : case DATETIME : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case SHORT : { final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case BYTE : { final byte value2 = readByte ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case FLOAT : { final float value2 = Float . intBitsToFloat ( readInteger ( fieldValue2 ) ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case DOUBLE : { final double value2 = Double . longBitsToDouble ( readLong ( fieldValue2 ) ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case STRING : { final String value2 = readString ( fieldValue2 ) ; return Byte . toString ( value1 ) . compareTo ( value2 ) ; } case DECIMAL : { final byte value2 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue2 . bytes , fieldValue2 . offset ) . byteValue ( ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } } break ; } case BOOLEAN : { final boolean value1 = readByte ( fieldValue1 ) == 1 ; switch ( iField2 . type ) { case BOOLEAN : { final boolean value2 = readByte ( fieldValue2 ) == 1 ; return ( value1 == value2 ) ? 0 : value1 ? 1 : - 1 ; } case STRING : { final boolean value2 = Boolean . parseBoolean ( readString ( fieldValue2 ) ) ; return ( value1 == value2 ) ? 0 : value1 ? 1 : - 1 ; } } break ; } case DATETIME : { final long value1 = OVarIntSerializer . readAsLong ( fieldValue1 ) ; switch ( iField2 . type ) { case INTEGER : { final int value2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case LONG : case DATETIME : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case DATE : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) * MILLISEC_PER_DAY ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case SHORT : { final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case BYTE : { final byte value2 = readByte ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case FLOAT : { final float value2 = Float . intBitsToFloat ( readInteger ( fieldValue2 ) ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case DOUBLE : { final double value2 = Double . longBitsToDouble ( readLong ( fieldValue2 ) ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case STRING : { final String value2AsString = readString ( fieldValue2 ) ; if ( OIOUtils . isLong ( value2AsString ) ) { final long value2 = Long . parseLong ( value2AsString ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } 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 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } catch ( ParseException ignored ) { 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 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } catch ( ParseException ignore ) { return new Date ( value1 ) . toString ( ) . compareTo ( value2AsString ) ; } } } case DECIMAL : { final long value2 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue2 . bytes , fieldValue2 . offset ) . longValue ( ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } } break ; } case DATE : { final long value1 = OVarIntSerializer . readAsLong ( fieldValue1 ) * MILLISEC_PER_DAY ; switch ( iField2 . type ) { case INTEGER : { final int value2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case LONG : case DATETIME : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case DATE : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) * MILLISEC_PER_DAY ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case SHORT : { final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case FLOAT : { final float value2 = Float . intBitsToFloat ( readInteger ( fieldValue2 ) ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case DOUBLE : { final double value2 = Double . longBitsToDouble ( readLong ( fieldValue2 ) ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } case STRING : { final String value2AsString = readString ( fieldValue2 ) ; if ( OIOUtils . isLong ( value2AsString ) ) { final long value2 = Long . parseLong ( value2AsString ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal . instance ( ) . getIfDefined ( ) ; try { final SimpleDateFormat dateFormat = db != null ? db . getStorage ( ) . getConfiguration ( ) . getDateFormatInstance ( ) : new SimpleDateFormat ( OStorageConfiguration . DEFAULT_DATE_FORMAT ) ; final Date value2AsDate = dateFormat . parse ( value2AsString ) ; long value2 = value2AsDate . getTime ( ) ; value2 = convertDayToTimezone ( ODateHelper . getDatabaseTimeZone ( ) , TimeZone . getTimeZone ( "GMT" ) , value2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } catch ( ParseException ignore ) { try { final SimpleDateFormat dateFormat = db != null ? db . getStorage ( ) . getConfiguration ( ) . getDateFormatInstance ( ) : new SimpleDateFormat ( OStorageConfiguration . DEFAULT_DATETIME_FORMAT ) ; final Date value2AsDate = dateFormat . parse ( value2AsString ) ; long value2 = value2AsDate . getTime ( ) ; value2 = convertDayToTimezone ( ODateHelper . getDatabaseTimeZone ( ) , TimeZone . getTimeZone ( "GMT" ) , value2 ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } catch ( ParseException ignored ) { return new Date ( value1 ) . toString ( ) . compareTo ( value2AsString ) ; } } } case DECIMAL : { final long value2 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue2 . bytes , fieldValue2 . offset ) . longValue ( ) ; return ( value1 < value2 ) ? - 1 : ( ( value1 == value2 ) ? 0 : 1 ) ; } } break ; } case BINARY : { switch ( iField2 . type ) { case BINARY : { final int length1 = OVarIntSerializer . readAsInteger ( fieldValue1 ) ; final int length2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; final int max = Math . min ( length1 , length2 ) ; for ( int i = 0 ; i < max ; ++ i ) { final byte b1 = fieldValue1 . bytes [ fieldValue1 . offset + i ] ; final byte b2 = fieldValue2 . bytes [ fieldValue2 . offset + i ] ; if ( b1 > b2 ) return 1 ; else if ( b2 > b1 ) return - 1 ; } if ( length1 > length2 ) return 1 ; else if ( length2 > length1 ) return - 1 ; // EQUALS
return 0 ; } } break ; } case LINK : { switch ( iField2 . type ) { case LINK : { final int clusterId1 = OVarIntSerializer . readAsInteger ( fieldValue1 ) ; final int clusterId2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; if ( clusterId1 > clusterId2 ) return 1 ; else if ( clusterId1 < clusterId2 ) return - 1 ; else { final long clusterPos1 = OVarIntSerializer . readAsLong ( fieldValue1 ) ; final long clusterPos2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; if ( clusterPos1 > clusterPos2 ) return 1 ; else if ( clusterPos1 < clusterPos2 ) return - 1 ; return 0 ; } } case STRING : { return readOptimizedLink ( fieldValue1 , false ) . compareTo ( new ORecordId ( readString ( fieldValue2 ) ) ) ; } } break ; } case DECIMAL : { final BigDecimal value1 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue1 . bytes , fieldValue1 . offset ) ; switch ( iField2 . type ) { case INTEGER : { final int value2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; return value1 . compareTo ( new BigDecimal ( value2 ) ) ; } case LONG : case DATETIME : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; return value1 . compareTo ( new BigDecimal ( value2 ) ) ; } case SHORT : { final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return value1 . compareTo ( new BigDecimal ( value2 ) ) ; } case FLOAT : { final float value2 = Float . intBitsToFloat ( readInteger ( fieldValue2 ) ) ; return value1 . compareTo ( new BigDecimal ( value2 ) ) ; } case DOUBLE : { final double value2 = Double . longBitsToDouble ( readLong ( fieldValue2 ) ) ; return value1 . compareTo ( new BigDecimal ( value2 ) ) ; } case STRING : { final String value2 = readString ( fieldValue2 ) ; return value1 . toString ( ) . compareTo ( value2 ) ; } case DECIMAL : { final BigDecimal value2 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue2 . bytes , fieldValue2 . offset ) ; return value1 . compareTo ( value2 ) ; } case BYTE : { final byte value2 = readByte ( fieldValue2 ) ; return value1 . compareTo ( new BigDecimal ( value2 ) ) ; } } break ; } } } finally { fieldValue1 . offset = offset1 ; fieldValue2 . offset = offset2 ; } // NO COMPARE SUPPORTED , RETURN NON EQUALS
return 1 ;


signature:
public class OCompositeIndexDefinition { /** * Add new indexDefinition in current composite .
 * @ param indexDefinition Index to add . */
public void addIndex ( final OIndexDefinition indexDefinition ) { } }

implementation: indexDefinitions . add ( indexDefinition ) ; if ( indexDefinition instanceof OIndexDefinitionMultiValue ) { if ( multiValueDefinitionIndex == - 1 ) multiValueDefinitionIndex = indexDefinitions . size ( ) - 1 ; else throw new OIndexException ( "Composite key cannot contain more than one collection item" ) ; } collate . addCollate ( indexDefinition . getCollate ( ) ) ;


signature:
public class OCompositeIndexDefinition { /** * { @ inheritDoc } */
public List < String > getFields ( ) { } }

implementation: final List < String > fields = new LinkedList < String > ( ) ; for ( final OIndexDefinition indexDefinition : indexDefinitions ) { fields . addAll ( indexDefinition . getFields ( ) ) ; } return Collections . unmodifiableList ( fields ) ;


signature:
public class OCompositeIndexDefinition { /** * { @ inheritDoc } */
public Object getDocumentValueToIndex ( final ODocument iDocument ) { } }

implementation:
final List < OCompositeKey > compositeKeys = new ArrayList < OCompositeKey > ( 10 ) ; final OCompositeKey firstKey = new OCompositeKey ( ) ; boolean containsCollection = false ; compositeKeys . add ( firstKey ) ; for ( final OIndexDefinition indexDefinition : indexDefinitions ) { final Object result = indexDefinition . getDocumentValueToIndex ( iDocument ) ; if ( result == null && isNullValuesIgnored ( ) ) return null ; // for empty collections we add null key in index
if ( result instanceof Collection && ( ( Collection ) result ) . isEmpty ( ) && isNullValuesIgnored ( ) ) return null ; containsCollection = addKey ( firstKey , compositeKeys , containsCollection , result ) ; } if ( ! containsCollection ) return firstKey ; return compositeKeys ;


signature:
public class OCompositeIndexDefinition { /** * { @ inheritDoc } */
public Object createValue ( final Object ... params ) { } }

implementation: if ( params . length == 1 && params [ 0 ] instanceof Collection ) return params [ 0 ] ; return createValue ( Arrays . asList ( params ) ) ;


signature:
public class OCompositeIndexDefinition { /** * { @ inheritDoc } */
public OType [ ] getTypes ( ) { } }

implementation: final List < OType > types = new LinkedList < OType > ( ) ; for ( final OIndexDefinition indexDefinition : indexDefinitions ) Collections . addAll ( types , indexDefinition . getTypes ( ) ) ; return types . toArray ( new OType [ types . size ( ) ] ) ;


signature:
public class OCompositeIndexDefinition { /** * { @ inheritDoc } */
@ Override public ODocument toStream ( ) { } }

implementation: document . setInternalStatus ( ORecordElement . STATUS . UNMARSHALLING ) ; try { serializeToStream ( ) ; } finally { document . setInternalStatus ( ORecordElement . STATUS . LOADED ) ; } return document ;


signature:
public class OCompositeIndexDefinition { /** * { @ inheritDoc } */
public String toCreateIndexDDL ( final String indexName , final String indexType , String engine ) { } }

implementation: final StringBuilder ddl = new StringBuilder ( "create index " ) ; ddl . append ( indexName ) . append ( " on " ) . append ( className ) . append ( " ( " ) ; final Iterator < String > fieldIterator = getFieldsToIndex ( ) . iterator ( ) ; if ( fieldIterator . hasNext ( ) ) { ddl . append ( fieldIterator . next ( ) ) ; while ( fieldIterator . hasNext ( ) ) { ddl . append ( ", " ) . append ( fieldIterator . next ( ) ) ; } } ddl . append ( " ) " ) . append ( indexType ) . append ( ' ' ) ; if ( engine != null ) ddl . append ( OCommandExecutorSQLCreateIndex . KEYWORD_ENGINE + " " + engine ) . append ( ' ' ) ; if ( multiValueDefinitionIndex == - 1 ) { boolean first = true ; for ( OType oType : getTypes ( ) ) { if ( first ) first = false ; else ddl . append ( ", " ) ; ddl . append ( oType . name ( ) ) ; } } return ddl . toString ( ) ;


signature:
public class OCommandExecutorSQLTruncateRecord { /** * Execute the command . */
public Object execute ( final Map < Object , Object > iArgs ) { } }

implementation: if ( records . isEmpty ( ) ) throw new OCommandExecutionException ( "Cannot execute the command because it has not been parsed yet" ) ; int deleted = 0 ; final ODatabaseDocumentInternal database = getDatabase ( ) ; for ( String rec : records ) { try { final ORecordId rid = new ORecordId ( rec ) ; final OStorageOperationResult < Boolean > result = database . getStorage ( ) . deleteRecord ( rid , - 1 , 0 , null ) ; database . getLocalCache ( ) . deleteRecord ( rid ) ; if ( result . getResult ( ) ) deleted ++ ; } catch ( Exception e ) { throw OException . wrapException ( new OCommandExecutionException ( "Error on executing command" ) , e ) ; } } return deleted ;


signature:
public class OProjectionItem { /** * INTERNAL USE ONLY this has to be invoked ONLY if the item is aggregate ! ! !
 * @ param aggregateSplit */
public OProjectionItem splitForAggregation ( AggregateProjectionSplit aggregateSplit , OCommandContext ctx ) { } }

implementation: if ( isAggregate ( ) ) { OProjectionItem result = new OProjectionItem ( - 1 ) ; result . alias = getProjectionAlias ( ) ; result . expression = expression . splitForAggregation ( aggregateSplit , ctx ) ; result . nestedProjection = nestedProjection ; return result ; } else { return this ; }


signature:
public class OJson { /** * choosing return type is based on existence of @ class and @ type field in JSON
 * @ param source
 * @ param ctx
 * @ return */
public Object toObjectDetermineType ( OResult source , OCommandContext ctx ) { } }

implementation: String className = getClassNameForDocument ( ctx ) ; String type = getTypeForDocument ( ctx ) ; if ( className != null || ( type != null && "d" . equalsIgnoreCase ( type ) ) ) { return toDocument ( source , ctx , className ) ; } else { return toMap ( source , ctx ) ; }


signature:
public class OSQLFilterItemField { /** * Check whether or not this filter item is chain of fields ( e . g . " field1 . field2 . field3 " ) . Return true if filter item contains
 * only field projections operators , if field item contains any other projection operator the method returns false . When filter
 * item does not contains any chain operator , it is also field chain consist of one field .
 * @ return whether or not this filter item can be represented as chain of fields . */
public boolean isFieldChain ( ) { } }

implementation: if ( operationsChain == null ) { return true ; } for ( OPair < OSQLMethodRuntime , Object [ ] > pair : operationsChain ) { if ( ! pair . getKey ( ) . getMethod ( ) . getName ( ) . equals ( OSQLMethodField . NAME ) ) { return false ; } } return true ;


signature:
public class OSQLFilterItemField { /** * get the collate of this expression , based on the fully evaluated field chain starting from the passed object .
 * @ param doc the root element ( document ? ) of this field chain
 * @ return the collate , null if no collate is defined */
public OCollate getCollate ( Object doc ) { } }

implementation: if ( collate != null || operationsChain == null || ! isFieldChain ( ) ) { return collate ; } if ( ! ( doc instanceof OIdentifiable ) ) { return null ; } FieldChain chain = getFieldChain ( ) ; ODocument lastDoc = ( ( OIdentifiable ) doc ) . getRecord ( ) ; for ( int i = 0 ; i < chain . getItemCount ( ) - 1 ; i ++ ) { if ( lastDoc == null ) { return null ; } Object nextDoc = lastDoc . field ( chain . getItemName ( i ) ) ; if ( nextDoc == null || ! ( nextDoc instanceof OIdentifiable ) ) { return null ; } lastDoc = ( ( OIdentifiable ) nextDoc ) . getRecord ( ) ; } if ( lastDoc == null ) { return null ; } OClass schemaClass = lastDoc . getSchemaClass ( ) ; if ( schemaClass == null ) { return null ; } OProperty property = schemaClass . getProperty ( chain . getItemName ( chain . getItemCount ( ) - 1 ) ) ; if ( property == null ) { return null ; } return property . getCollate ( ) ;


signature:
public class OIdentifier { /** * returns the plain string representation of this identifier , with quoting removed from back - ticks
 * @ return */
public String getStringValue ( ) { } }

implementation: if ( value == null ) { return null ; } if ( value . contains ( "`" ) ) { return value . replaceAll ( "\\\\`" , "`" ) ; } return value ;


signature:
public class OIdentifier { /** * sets the value of the identifier . It can contain any values , this method can manage back - ticks ( internally quote them ) , so
 * back - ticks have not to be quoted when passed as a parameter
 * @ param s */
private void setStringValue ( String s ) { } }

implementation: if ( s == null ) { value = null ; } else if ( s . contains ( "`" ) ) { value = s . replaceAll ( "`" , "\\\\`" ) ; } else { value = s ; }


signature:
public class StripedBuffer { /** * Pseudo - randomly advances and records the given probe value for the given thread . */
private int advanceProbe ( int probe ) { } }

implementation:
probe ^= probe << 13 ; // xorshift
probe ^= probe >>> 17 ; probe ^= probe << 5 ; this . probe . get ( ) . set ( probe ) ; return probe ;


signature:
public class OTransactionOptimistic { /** * The transaction is reentrant . If { @ code begin ( ) } has been called several times , the actual commit happens only after the same
 * amount of { @ code commit ( ) } calls
 * @ param force commit transaction even */
@ Override public void commit ( final boolean force ) { } }

implementation: checkTransaction ( ) ; if ( txStartCounter < 0 ) throw new OStorageException ( "Invalid value of tx counter" ) ; if ( force ) txStartCounter = 0 ; else txStartCounter -- ; if ( txStartCounter == 0 ) { doCommit ( ) ; } else if ( txStartCounter > 0 ) OLogManager . instance ( ) . debug ( this , "Nested transaction was closed but transaction itself was not committed." ) ; else throw new OTransactionException ( "Transaction was committed more times than it is started." ) ;


signature:
public class OCommandExecutorSQLDropCluster { /** * Execute the DROP CLUSTER . */
public Object execute ( final Map < Object , Object > iArgs ) { } }

implementation:
if ( clusterName == null ) throw new OCommandExecutionException ( "Cannot execute the command because it has not been parsed yet" ) ; final ODatabaseDocumentInternal database = getDatabase ( ) ; // CHECK IF ANY CLASS IS USING IT
final int clusterId = database . getStorage ( ) . getClusterIdByName ( clusterName ) ; for ( OClass iClass : database . getMetadata ( ) . getSchema ( ) . getClasses ( ) ) { for ( int i : iClass . getClusterIds ( ) ) { if ( i == clusterId ) // IN USE
return false ; } } // REMOVE CACHE OF COMMAND RESULTS IF ACTIVE
database . getMetadata ( ) . getCommandCache ( ) . invalidateResultsOfCluster ( clusterName ) ; database . dropCluster ( clusterId , true ) ; return true ;


signature:
public class OFileManager { /** * It returns a ODocument starting from a json file .
 * @ param filePath
 * @ return ODocument ( null if the file does not exist or problem are encountered during the reading ) */
public static ODocument buildJsonFromFile ( String filePath ) throws IOException { } }

implementation: if ( filePath == null ) { return null ; } File jsonFile = new File ( filePath ) ; if ( ! jsonFile . exists ( ) ) { return null ; } FileInputStream is = new FileInputStream ( jsonFile ) ; BufferedReader rd = new BufferedReader ( new InputStreamReader ( is , Charset . forName ( "UTF-8" ) ) ) ; ODocument json = new ODocument ( ) ; String jsonText = OFileManager . readAllTextFile ( rd ) ; json . fromJSON ( jsonText , "noMap" ) ; return json ;


signature:
public class OCommandExecutorSQLDeleteVertex { /** * Execute the command and return the ODocument object created . */
public Object execute ( final Map < Object , Object > iArgs ) { } }

implementation:
if ( rid == null && query == null ) throw new OCommandExecutionException ( "Cannot execute the command because it has not been parsed yet" ) ; if ( ! returning . equalsIgnoreCase ( "COUNT" ) ) allDeletedRecords = new ArrayList < ORecord > ( ) ; txAlreadyBegun = getDatabase ( ) . getTransaction ( ) . isActive ( ) ; if ( rid != null ) { // REMOVE PUNCTUAL RID
OGraphCommandExecutorSQLFactory . runInConfiguredTxMode ( new OGraphCommandExecutorSQLFactory . GraphCallBack < Object > ( ) { @ Override public Object call ( OrientBaseGraph graph ) { final OrientVertex v = graph . getVertex ( rid ) ; if ( v != null ) { v . remove ( ) ; removed = 1 ; } return null ; } } ) ; // CLOSE PENDING TX
end ( ) ; } else if ( query != null ) { // TARGET IS A CLASS + OPTIONAL CONDITION
OGraphCommandExecutorSQLFactory . runInConfiguredTxMode ( new OGraphCommandExecutorSQLFactory . GraphCallBack < OrientGraph > ( ) { @ Override public OrientGraph call ( final OrientBaseGraph iGraph ) { // TARGET IS A CLASS + OPTIONAL CONDITION
currentGraph . set ( iGraph ) ; query . setContext ( getContext ( ) ) ; query . execute ( iArgs ) ; return null ; } } ) ; } else throw new OCommandExecutionException ( "Invalid target" ) ; if ( returning . equalsIgnoreCase ( "COUNT" ) ) // RETURNS ONLY THE COUNT
return removed ; else // RETURNS ALL THE DELETED RECORDS
return allDeletedRecords ;


signature:
public class OCommandExecutorSQLDeleteVertex { /** * Delete the current vertex . */
public boolean result ( final Object iRecord ) { } }

implementation: final OIdentifiable id = ( OIdentifiable ) iRecord ; if ( id . getIdentity ( ) . isValid ( ) ) { final ODocument record = id . getRecord ( ) ; final OrientBaseGraph g = currentGraph . get ( ) ; final OrientVertex v = g . getVertex ( record ) ; if ( v != null ) { v . remove ( ) ; if ( ! txAlreadyBegun && batch > 0 && removed % batch == 0 ) { if ( g instanceof OrientGraph ) { g . commit ( ) ; ( ( OrientGraph ) g ) . begin ( ) ; } } if ( returning . equalsIgnoreCase ( "BEFORE" ) ) allDeletedRecords . add ( record ) ; removed ++ ; } } return true ;


signature:
public class OCommandExecutorSQLDeleteVertex { /** * Parses the returning keyword if found . */
protected String parseReturn ( ) throws OCommandSQLParsingException { } }

implementation: final String returning = parserNextWord ( true ) ; if ( ! returning . equalsIgnoreCase ( "COUNT" ) && ! returning . equalsIgnoreCase ( "BEFORE" ) ) throwParsingException ( "Invalid " + KEYWORD_RETURN + " value set to '" + returning + "' but it should be COUNT (default), BEFORE. Example: " + KEYWORD_RETURN + " BEFORE" ) ; return returning ;


signature:
public class OSecurityManager { /** * Checks if an hash string matches a password , based on the algorithm found on hash string .
 * @ param iHash
 * Hash string . Can contain the algorithm as prefix in the format < code > { ALGORITHM } - HASH < / code > .
 * @ param iPassword
 * @ return */
public boolean checkPassword ( final String iPassword , final String iHash ) { } }

implementation:
if ( iHash . startsWith ( HASH_ALGORITHM_PREFIX ) ) { final String s = iHash . substring ( HASH_ALGORITHM_PREFIX . length ( ) ) ; return createSHA256 ( iPassword ) . equals ( s ) ; } else if ( iHash . startsWith ( PBKDF2_ALGORITHM_PREFIX ) ) { final String s = iHash . substring ( PBKDF2_ALGORITHM_PREFIX . length ( ) ) ; return checkPasswordWithSalt ( iPassword , s , PBKDF2_ALGORITHM ) ; } else if ( iHash . startsWith ( PBKDF2_SHA256_ALGORITHM_PREFIX ) ) { final String s = iHash . substring ( PBKDF2_SHA256_ALGORITHM_PREFIX . length ( ) ) ; return checkPasswordWithSalt ( iPassword , s , PBKDF2_SHA256_ALGORITHM ) ; } // Do not compare raw strings against each other , to avoid timing attacks .
// Instead , hash them both with a cryptographic hash function and
// compare their hashes with a constant - time comparison method .
return MessageDigest . isEqual ( digestSHA256 ( iPassword ) , digestSHA256 ( iHash ) ) ;


signature:
public class OSecurityManager { /** * Hashes the input string .
 * @ param iInput
 * String to hash
 * @ param iIncludeAlgorithm
 * Include the algorithm used or not
 * @ return */
public String createHash ( final String iInput , final String iAlgorithm , final boolean iIncludeAlgorithm ) { } }

implementation: if ( iInput == null ) throw new IllegalArgumentException ( "Input string is null" ) ; if ( iAlgorithm == null ) throw new IllegalArgumentException ( "Algorithm is null" ) ; final StringBuilder buffer = new StringBuilder ( 128 ) ; final String algorithm = validateAlgorithm ( iAlgorithm ) ; if ( iIncludeAlgorithm ) { buffer . append ( '{' ) ; buffer . append ( algorithm ) ; buffer . append ( '}' ) ; } final String transformed ; if ( HASH_ALGORITHM . equalsIgnoreCase ( algorithm ) ) { transformed = createSHA256 ( iInput ) ; } else if ( PBKDF2_ALGORITHM . equalsIgnoreCase ( algorithm ) ) { transformed = createHashWithSalt ( iInput , OGlobalConfiguration . SECURITY_USER_PASSWORD_SALT_ITERATIONS . getValueAsInteger ( ) , algorithm ) ; } else if ( PBKDF2_SHA256_ALGORITHM . equalsIgnoreCase ( algorithm ) ) { transformed = createHashWithSalt ( iInput , OGlobalConfiguration . SECURITY_USER_PASSWORD_SALT_ITERATIONS . getValueAsInteger ( ) , algorithm ) ; } else throw new IllegalArgumentException ( "Algorithm '" + algorithm + "' is not supported" ) ; buffer . append ( transformed ) ; return buffer . toString ( ) ;


signature:
public class OSecurityManager { /** * Returns true if the algorithm is supported by the current version of Java */
private static boolean isAlgorithmSupported ( final String algorithm ) { } }

implementation:
// Java 7 specific checks .
if ( Runtime . class . getPackage ( ) != null && Runtime . class . getPackage ( ) . getImplementationVersion ( ) != null ) { if ( Runtime . class . getPackage ( ) . getImplementationVersion ( ) . startsWith ( "1.7" ) ) { // Java 7 does not support the PBKDF2 _ SHA256 _ ALGORITHM .
if ( algorithm != null && algorithm . equals ( PBKDF2_SHA256_ALGORITHM ) ) { return false ; } } } return true ;


signature:
public class OIndexAbstract { /** * Creates the index .
 * @ param clusterIndexName Cluster name where to place the TreeMap */
public OIndexInternal < ? > create ( final OIndexDefinition indexDefinition , final String clusterIndexName , final Set < String > clustersToIndex , boolean rebuild , final OProgressListener progressListener , final OBinarySerializer valueSerializer ) { } }

implementation:
acquireExclusiveLock ( ) ; try { configuration = indexConfigurationInstance ( new ODocument ( ) . setTrackingChanges ( false ) ) ; this . indexDefinition = indexDefinition ; if ( clustersToIndex != null ) this . clustersToIndex = new HashSet < > ( clustersToIndex ) ; else this . clustersToIndex = new HashSet < > ( ) ; // do not remove this , it is needed to remove index garbage if such one exists
try { if ( apiVersion == 0 ) { removeValuesContainer ( ) ; } } catch ( Exception e ) { OLogManager . instance ( ) . error ( this , "Error during deletion of index '%s'" , e , name ) ; } indexId = storage . addIndexEngine ( name , algorithm , type , indexDefinition , valueSerializer , isAutomatic ( ) , true , version , 1 , this instanceof OIndexMultiValues , getEngineProperties ( ) , clustersToIndex , metadata ) ; apiVersion = OAbstractPaginatedStorage . extractEngineAPIVersion ( indexId ) ; assert indexId >= 0 ; assert apiVersion >= 0 ; onIndexEngineChange ( indexId ) ; if ( rebuild ) fillIndex ( progressListener , false ) ; updateConfiguration ( ) ; } catch ( Exception e ) { OLogManager . instance ( ) . error ( this , "Exception during index '%s' creation" , e , name ) ; while ( true ) try { if ( indexId >= 0 ) storage . deleteIndexEngine ( indexId ) ; break ; } catch ( OInvalidIndexEngineIdException ignore ) { doReloadIndexEngine ( ) ; } catch ( Exception ex ) { OLogManager . instance ( ) . error ( this , "Exception during index '%s' deletion" , ex , name ) ; } if ( e instanceof OIndexException ) throw ( OIndexException ) e ; throw OException . wrapException ( new OIndexException ( "Cannot create the index '" + name + "'" ) , e ) ; } finally { releaseExclusiveLock ( ) ; } return this ;


signature:
public class OIndexAbstract { /** * { @ inheritDoc } */
public long rebuild ( final OProgressListener iProgressListener ) { } }

implementation:
long documentIndexed ; final boolean intentInstalled = getDatabase ( ) . declareIntent ( new OIntentMassiveInsert ( ) ) ; acquireExclusiveLock ( ) ; try { // DO NOT REORDER 2 assignments bellow
// see # getRebuildVersion ( )
rebuilding = true ; rebuildVersion . incrementAndGet ( ) ; try { if ( indexId >= 0 ) { storage . deleteIndexEngine ( indexId ) ; } } catch ( Exception e ) { OLogManager . instance ( ) . error ( this , "Error during index '%s' delete" , e , name ) ; } removeValuesContainer ( ) ; indexId = storage . addIndexEngine ( name , algorithm , type , indexDefinition , determineValueSerializer ( ) , isAutomatic ( ) , true , version , 1 , this instanceof OIndexMultiValues , getEngineProperties ( ) , clustersToIndex , metadata ) ; apiVersion = OAbstractPaginatedStorage . extractEngineAPIVersion ( indexId ) ; onIndexEngineChange ( indexId ) ; } catch ( Exception e ) { try { if ( indexId >= 0 ) storage . clearIndex ( indexId ) ; } catch ( Exception e2 ) { OLogManager . instance ( ) . error ( this , "Error during index rebuild" , e2 ) ; // IGNORE EXCEPTION : IF THE REBUILD WAS LAUNCHED IN CASE OF RID INVALID CLEAR ALWAYS GOES IN ERROR
} rebuilding = false ; throw OException . wrapException ( new OIndexException ( "Error on rebuilding the index for clusters: " + clustersToIndex ) , e ) ; } finally { releaseExclusiveLock ( ) ; } acquireSharedLock ( ) ; try { documentIndexed = fillIndex ( iProgressListener , true ) ; } catch ( final Exception e ) { OLogManager . instance ( ) . error ( this , "Error during index rebuild" , e ) ; try { if ( indexId >= 0 ) storage . clearIndex ( indexId ) ; } catch ( Exception e2 ) { OLogManager . instance ( ) . error ( this , "Error during index rebuild" , e2 ) ; // IGNORE EXCEPTION : IF THE REBUILD WAS LAUNCHED IN CASE OF RID INVALID CLEAR ALWAYS GOES IN ERROR
} throw OException . wrapException ( new OIndexException ( "Error on rebuilding the index for clusters: " + clustersToIndex ) , e ) ; } finally { rebuilding = false ; if ( intentInstalled ) getDatabase ( ) . declareIntent ( null ) ; releaseSharedLock ( ) ; } return documentIndexed ;


signature:
public class OrientGraphQuery { /** * ( Blueprints Extension ) Sets the order of results by a field in ascending ( asc ) or descending ( desc ) order based on dir
 * parameter . This is translated on ORDER BY in the underlying SQL query .
 * @ param props Field to order by
 * @ param dir Direction . Use " asc " for ascending and " desc " for descending
 * @ return Current Query Object to allow calls in chain . */
public Query order ( final String props , final String dir ) { } }

implementation: this . orderBy = props ; this . orderByDir = dir ; return this ;


signature:
public class OrientGraphQuery { /** * Returns the result set of the query as iterable vertices . */
@ Override public Iterable < Vertex > vertices ( ) { } }

implementation:
if ( limit == 0 ) return Collections . emptyList ( ) ; OTransaction transaction = ( ( OrientBaseGraph ) graph ) . getRawGraph ( ) . getTransaction ( ) ; if ( transaction . isActive ( ) && transaction . getEntryCount ( ) > 0 || hasCustomPredicate ( ) ) { // INSIDE TRANSACTION QUERY DOESN ' T SEE IN MEMORY CHANGES , UNTIL
// SUPPORTED USED THE BASIC IMPL
String [ ] classes = allSubClassesLabels ( ) ; return new OrientGraphQueryIterable < Vertex > ( true , classes ) ; } final StringBuilder text = new StringBuilder ( 512 ) ; // GO DIRECTLY AGAINST E CLASS AND SUB - CLASSES
text . append ( QUERY_SELECT_FROM ) ; if ( ( ( OrientBaseGraph ) graph ) . isUseClassForVertexLabel ( ) && labels != null && labels . length > 0 ) { // FILTER PER CLASS SAVING CHECKING OF LABEL PROPERTY
if ( labels . length == 1 ) // USE THE CLASS NAME
text . append ( OrientBaseGraph . encodeClassName ( labels [ 0 ] ) ) ; else { // MULTIPLE CLASSES NOT SUPPORTED DIRECTLY : CREATE A SUB - QUERY
String [ ] classes = allSubClassesLabels ( ) ; return new OrientGraphQueryIterable < Vertex > ( true , classes ) ; } } else text . append ( OrientVertexType . CLASS_NAME ) ; final List < Object > queryParams = manageFilters ( text ) ; if ( ! ( ( OrientBaseGraph ) graph ) . isUseClassForVertexLabel ( ) ) manageLabels ( queryParams . size ( ) > 0 , text ) ; if ( orderBy . length ( ) > 1 ) { text . append ( ORDERBY ) ; text . append ( orderBy ) ; text . append ( " " ) . append ( orderByDir ) . append ( " " ) ; } if ( skip > 0 && skip < Integer . MAX_VALUE ) { text . append ( SKIP ) ; text . append ( skip ) ; } if ( limit > 0 && limit < Integer . MAX_VALUE ) { text . append ( LIMIT ) ; text . append ( limit ) ; } final OSQLSynchQuery < OIdentifiable > query = new OSQLSynchQuery < OIdentifiable > ( text . toString ( ) ) ; if ( fetchPlan != null ) query . setFetchPlan ( fetchPlan ) ; return new OrientElementIterable < Vertex > ( ( ( OrientBaseGraph ) graph ) , ( ( OrientBaseGraph ) graph ) . getRawGraph ( ) . query ( query , queryParams . toArray ( ) ) ) ;


signature:
public class OrientGraphQuery { /** * Returns the result set of the query as iterable edges . */
@ Override public Iterable < Edge > edges ( ) { } }

implementation:
if ( limit == 0 ) return Collections . emptyList ( ) ; if ( ( ( OrientBaseGraph ) graph ) . getRawGraph ( ) . getTransaction ( ) . isActive ( ) || hasCustomPredicate ( ) ) // INSIDE TRANSACTION QUERY DOESN ' T SEE IN MEMORY CHANGES , UNTIL
// SUPPORTED USED THE BASIC IMPL
return new OrientGraphQueryIterable < Edge > ( false , labels ) ; if ( ( ( OrientBaseGraph ) graph ) . isUseLightweightEdges ( ) ) return new OrientGraphQueryIterable < Edge > ( false , labels ) ; final StringBuilder text = new StringBuilder ( 512 ) ; // GO DIRECTLY AGAINST E CLASS AND SUB - CLASSES
text . append ( QUERY_SELECT_FROM ) ; if ( ( ( OrientBaseGraph ) graph ) . isUseClassForEdgeLabel ( ) && labels != null && labels . length > 0 ) { // FILTER PER CLASS SAVING CHECKING OF LABEL PROPERTY
if ( labels . length == 1 ) // USE THE CLASS NAME
text . append ( OrientBaseGraph . encodeClassName ( labels [ 0 ] ) ) ; else { // MULTIPLE CLASSES NOT SUPPORTED DIRECTLY : CREATE A SUB - QUERY
return new OrientGraphQueryIterable < Edge > ( false , labels ) ; } } else text . append ( OrientEdgeType . CLASS_NAME ) ; List < Object > queryParams = manageFilters ( text ) ; if ( ! ( ( OrientBaseGraph ) graph ) . isUseClassForEdgeLabel ( ) ) manageLabels ( queryParams . size ( ) > 0 , text ) ; final OSQLSynchQuery < OIdentifiable > query = new OSQLSynchQuery < OIdentifiable > ( text . toString ( ) ) ; if ( fetchPlan != null ) query . setFetchPlan ( fetchPlan ) ; if ( limit > 0 && limit < Integer . MAX_VALUE ) query . setLimit ( limit ) ; return new OrientElementIterable < Edge > ( ( ( OrientBaseGraph ) graph ) , ( ( OrientBaseGraph ) graph ) . getRawGraph ( ) . query ( query , queryParams . toArray ( ) ) ) ;


signature:
public class OAbstract2pcTask { /** * Return the partition keys of all the sub - tasks . */
@ Override public int [ ] getPartitionKey ( ) { } }

implementation:
if ( tasks . size ( ) == 1 ) // ONE TASK , USE THE INNER TASK ' S PARTITION KEY
return tasks . get ( 0 ) . getPartitionKey ( ) ; // MULTIPLE PARTITIONS
final int [ ] partitions = new int [ tasks . size ( ) ] ; for ( int i = 0 ; i < tasks . size ( ) ; ++ i ) { final OAbstractRecordReplicatedTask task = tasks . get ( i ) ; partitions [ i ] = task . getPartitionKey ( ) [ 0 ] ; } return partitions ;


signature:
public class OAbstract2pcTask { /** * Computes the timeout according to the transaction size .
 * @ return */
@ Override public long getDistributedTimeout ( ) { } }

implementation: final long to = OGlobalConfiguration . DISTRIBUTED_CRUD_TASK_SYNCH_TIMEOUT . getValueAsLong ( ) ; return to + ( ( to / 2 ) * tasks . size ( ) ) ;


signature:
public class OSimpleKeyIndexDefinition { /** * { @ inheritDoc }
 * @ param indexName
 * @ param indexType */
public String toCreateIndexDDL ( final String indexName , final String indexType , final String engine ) { } }

implementation: final StringBuilder ddl = new StringBuilder ( "create index `" ) ; ddl . append ( indexName ) . append ( "` " ) . append ( indexType ) . append ( ' ' ) ; if ( keyTypes != null && keyTypes . length > 0 ) { ddl . append ( keyTypes [ 0 ] . toString ( ) ) ; for ( int i = 1 ; i < keyTypes . length ; i ++ ) { ddl . append ( ", " ) . append ( keyTypes [ i ] . toString ( ) ) ; } } return ddl . toString ( ) ;


signature:
public class OClusterBasedStorageConfiguration { /** * Added version used for managed Network Versioning . */
public byte [ ] toStream ( final int iNetworkVersion , final Charset charset ) throws OSerializationException { } }

implementation:
lock . acquireReadLock ( ) ; try { final StringBuilder buffer = new StringBuilder ( 8192 ) ; write ( buffer , CURRENT_VERSION ) ; write ( buffer , null ) ; write ( buffer , getSchemaRecordId ( ) ) ; write ( buffer , "" ) ; write ( buffer , getIndexMgrRecordId ( ) ) ; write ( buffer , getLocaleLanguage ( ) ) ; write ( buffer , getLocaleCountry ( ) ) ; write ( buffer , getDateFormat ( ) ) ; write ( buffer , getDateFormat ( ) ) ; final TimeZone timeZone = getTimeZone ( ) ; assert timeZone != null ; write ( buffer , timeZone ) ; write ( buffer , charset ) ; if ( iNetworkVersion > 24 ) { write ( buffer , getConflictStrategy ( ) ) ; } phySegmentToStream ( buffer , new OStorageSegmentConfiguration ( ) ) ; final List < OStorageClusterConfiguration > clusters = getClusters ( ) ; write ( buffer , clusters . size ( ) ) ; for ( final OStorageClusterConfiguration c : clusters ) { if ( c == null ) { write ( buffer , - 1 ) ; continue ; } write ( buffer , c . getId ( ) ) ; write ( buffer , c . getName ( ) ) ; write ( buffer , c . getDataSegmentId ( ) ) ; if ( c instanceof OStoragePaginatedClusterConfiguration ) { write ( buffer , "d" ) ; final OStoragePaginatedClusterConfiguration paginatedClusterConfiguration = ( OStoragePaginatedClusterConfiguration ) c ; write ( buffer , paginatedClusterConfiguration . useWal ) ; write ( buffer , paginatedClusterConfiguration . recordOverflowGrowFactor ) ; write ( buffer , paginatedClusterConfiguration . recordGrowFactor ) ; write ( buffer , paginatedClusterConfiguration . compression ) ; if ( iNetworkVersion >= 31 ) { write ( buffer , paginatedClusterConfiguration . encryption ) ; } if ( iNetworkVersion > 24 ) { write ( buffer , paginatedClusterConfiguration . conflictStrategy ) ; } if ( iNetworkVersion > 25 ) { write ( buffer , paginatedClusterConfiguration . getStatus ( ) . name ( ) ) ; } if ( iNetworkVersion >= Integer . MAX_VALUE ) { write ( buffer , paginatedClusterConfiguration . getBinaryVersion ( ) ) ; } } } if ( iNetworkVersion <= 25 ) { // dataSegment array
write ( buffer , 0 ) ; // tx Segment File
write ( buffer , "" ) ; write ( buffer , "" ) ; write ( buffer , 0 ) ; // tx segment flags
write ( buffer , false ) ; write ( buffer , false ) ; } final List < OStorageEntryConfiguration > properties = getProperties ( ) ; write ( buffer , properties . size ( ) ) ; for ( final OStorageEntryConfiguration e : properties ) { entryToStream ( buffer , e ) ; } write ( buffer , getBinaryFormatVersion ( ) ) ; write ( buffer , getClusterSelection ( ) ) ; write ( buffer , getMinimumClusters ( ) ) ; if ( iNetworkVersion > 24 ) { write ( buffer , getRecordSerializer ( ) ) ; write ( buffer , getRecordSerializerVersion ( ) ) ; // WRITE CONFIGURATION
write ( buffer , configuration . getContextSize ( ) ) ; for ( final String k : configuration . getContextKeys ( ) ) { final OGlobalConfiguration cfg = OGlobalConfiguration . findByKey ( k ) ; write ( buffer , k ) ; if ( cfg != null ) { write ( buffer , cfg . isHidden ( ) ? null : configuration . getValueAsString ( cfg ) ) ; } else { write ( buffer , null ) ; OLogManager . instance ( ) . warn ( this , "Storing configuration for property:'" + k + "' not existing in current version" ) ; } } } final List < IndexEngineData > engines = loadIndexEngines ( ) ; write ( buffer , engines . size ( ) ) ; for ( final IndexEngineData engineData : engines ) { write ( buffer , engineData . getName ( ) ) ; write ( buffer , engineData . getAlgorithm ( ) ) ; write ( buffer , engineData . getIndexType ( ) == null ? "" : engineData . getIndexType ( ) ) ; write ( buffer , engineData . getValueSerializerId ( ) ) ; write ( buffer , engineData . getKeySerializedId ( ) ) ; write ( buffer , engineData . isAutomatic ( ) ) ; write ( buffer , engineData . getDurableInNonTxMode ( ) ) ; write ( buffer , engineData . getVersion ( ) ) ; write ( buffer , engineData . isNullValuesSupport ( ) ) ; write ( buffer , engineData . getKeySize ( ) ) ; write ( buffer , engineData . getEncryption ( ) ) ; write ( buffer , engineData . getEncryptionOptions ( ) ) ; if ( engineData . getKeyTypes ( ) != null ) { write ( buffer , engineData . getKeyTypes ( ) . length ) ; for ( final OType type : engineData . getKeyTypes ( ) ) { write ( buffer , type . name ( ) ) ; } } else { write ( buffer , 0 ) ; } if ( engineData . getEngineProperties ( ) == null ) { write ( buffer , 0 ) ; } else { write ( buffer , engineData . getEngineProperties ( ) . size ( ) ) ; for ( final Map . Entry < String , String > property : engineData . getEngineProperties ( ) . entrySet ( ) ) { write ( buffer , property . getKey ( ) ) ; write ( buffer , property . getValue ( ) ) ; } } write ( buffer , engineData . getApiVersion ( ) ) ; write ( buffer , engineData . isMultivalue ( ) ) ; } write ( buffer , getCreatedAtVersion ( ) ) ; write ( buffer , getPageSize ( ) ) ; write ( buffer , getFreeListBoundary ( ) ) ; write ( buffer , getMaxKeySize ( ) ) ; // PLAIN : ALLOCATE ENOUGH SPACE TO REUSE IT EVERY TIME
buffer . append ( "|" ) ; return buffer . toString ( ) . getBytes ( charset ) ; } finally { lock . releaseReadLock ( ) ; }


signature:
public class OrientGraph { /** * Returns the current Graph settings .
 * @ return Features object */
public Features getFeatures ( ) { } }

implementation:
makeActive ( ) ; if ( ! featuresInitialized ) { FEATURES . supportsDuplicateEdges = true ; FEATURES . supportsSelfLoops = true ; FEATURES . isPersistent = true ; FEATURES . supportsVertexIteration = true ; FEATURES . supportsVertexIndex = true ; FEATURES . ignoresSuppliedIds = true ; FEATURES . supportsTransactions = true ; FEATURES . supportsVertexKeyIndex = true ; FEATURES . supportsKeyIndices = true ; FEATURES . isWrapper = false ; FEATURES . supportsIndices = true ; FEATURES . supportsVertexProperties = true ; FEATURES . supportsEdgeProperties = true ; // For more information on supported types , please see :
// http : / / code . google . com / p / orient / wiki / Types
FEATURES . supportsSerializableObjectProperty = true ; FEATURES . supportsBooleanProperty = true ; FEATURES . supportsDoubleProperty = true ; FEATURES . supportsFloatProperty = true ; FEATURES . supportsIntegerProperty = true ; FEATURES . supportsPrimitiveArrayProperty = true ; FEATURES . supportsUniformListProperty = true ; FEATURES . supportsMixedListProperty = true ; FEATURES . supportsLongProperty = true ; FEATURES . supportsMapProperty = true ; FEATURES . supportsStringProperty = true ; FEATURES . supportsThreadedTransactions = false ; FEATURES . supportsThreadIsolatedTransactions = false ; // DYNAMIC FEATURES BASED ON CONFIGURATION
FEATURES . supportsEdgeIndex = ! isUseLightweightEdges ( ) ; FEATURES . supportsEdgeKeyIndex = ! isUseLightweightEdges ( ) ; FEATURES . supportsEdgeIteration = ! isUseLightweightEdges ( ) ; FEATURES . supportsEdgeRetrieval = ! isUseLightweightEdges ( ) ; featuresInitialized = true ; } return FEATURES ;


signature:
public class OrientGraph { /** * Removes the Edge from the Graph . Connected vertices aren ' t removed . */
public void removeEdgeInternal ( final OrientEdge edge ) { } }

implementation:
// OUT VERTEX
final OIdentifiable inVertexEdge = edge . vIn != null ? edge . vIn : edge . rawElement ; final String edgeClassName = OrientBaseGraph . encodeClassName ( edge . getLabel ( ) ) ; final boolean useVertexFieldsForEdgeLabels = settings . isUseVertexFieldsForEdgeLabels ( ) ; final OIdentifiable outVertex = edge . getOutVertex ( ) ; ODocument outVertexRecord = null ; boolean outVertexChanged = false ; if ( outVertex != null ) { outVertexRecord = outVertex . getRecord ( ) ; if ( outVertexRecord != null ) { final String outFieldName = OrientVertex . getConnectionFieldName ( Direction . OUT , edgeClassName , useVertexFieldsForEdgeLabels ) ; outVertexChanged = edge . dropEdgeFromVertex ( inVertexEdge , outVertexRecord , outFieldName , outVertexRecord . field ( outFieldName ) ) ; } } // IN VERTEX
final OIdentifiable outVertexEdge = edge . vOut != null ? edge . vOut : edge . rawElement ; final OIdentifiable inVertex = edge . getInVertex ( ) ; ODocument inVertexRecord = null ; boolean inVertexChanged = false ; if ( inVertex != null ) { inVertexRecord = inVertex . getRecord ( ) ; if ( inVertexRecord != null ) { final String inFieldName = OrientVertex . getConnectionFieldName ( Direction . IN , edgeClassName , useVertexFieldsForEdgeLabels ) ; inVertexChanged = edge . dropEdgeFromVertex ( outVertexEdge , inVertexRecord , inFieldName , inVertexRecord . field ( inFieldName ) ) ; } } if ( outVertexChanged ) outVertexRecord . save ( ) ; if ( inVertexChanged ) inVertexRecord . save ( ) ; if ( edge . rawElement != null ) // NON - LIGHTWEIGHT EDGE
edge . removeRecord ( ) ;


signature:
public class OCreateLinkStatement { /** * Execute the CREATE LINK . */
private Object execute ( OCommandContext ctx ) { } }

implementation:
if ( destField == null ) throw new OCommandExecutionException ( "Cannot execute the command because it has not been parsed yet" ) ; final ODatabaseDocumentInternal database = getDatabase ( ) ; if ( ! ( database . getDatabaseOwner ( ) instanceof ODatabaseDocument ) ) throw new OCommandSQLParsingException ( "This command supports only the database type ODatabaseDocumentTx and type '" + database . getClass ( ) + "' was found" ) ; final ODatabaseDocument db = ( ODatabaseDocument ) database . getDatabaseOwner ( ) ; final OClass sourceClass = database . getMetadata ( ) . getSchema ( ) . getClass ( getSourceClass ( ) . getStringValue ( ) ) ; if ( sourceClass == null ) throw new OCommandExecutionException ( "Source class '" + getSourceClass ( ) . getStringValue ( ) + "' not found" ) ; final OClass destClass = database . getMetadata ( ) . getSchema ( ) . getClass ( getDestClass ( ) . getStringValue ( ) ) ; if ( destClass == null ) throw new OCommandExecutionException ( "Destination class '" + getDestClass ( ) . getStringValue ( ) + "' not found" ) ; Object value ; String cmd = "select from " ; if ( ! ODocumentHelper . ATTRIBUTE_RID . equals ( destField ) ) { cmd = "select from " + getDestClass ( ) + " where " + destField + " = " ; } List < ODocument > result ; ODocument target ; Object oldValue ; long total = 0 ; String linkName = name == null ? sourceField . getStringValue ( ) : name . getStringValue ( ) ; boolean multipleRelationship ; OType linkType = OType . valueOf ( type . getStringValue ( ) . toUpperCase ( Locale . ENGLISH ) ) ; if ( linkType != null ) // DETERMINE BASED ON FORCED TYPE
multipleRelationship = linkType == OType . LINKSET || linkType == OType . LINKLIST ; else multipleRelationship = false ; long totRecords = db . countClass ( sourceClass . getName ( ) ) ; long currRecord = 0 ; database . declareIntent ( new OIntentMassiveInsert ( ) ) ; try { // BROWSE ALL THE RECORDS OF THE SOURCE CLASS
for ( ODocument doc : db . browseClass ( sourceClass . getName ( ) ) ) { if ( breakExec ) { break ; } value = doc . getProperty ( sourceField . getStringValue ( ) ) ; if ( value != null ) { if ( value instanceof ODocument || value instanceof ORID ) { // ALREADY CONVERTED
} else if ( value instanceof Collection < ? > ) { // TODO
} else { // SEARCH THE DESTINATION RECORD
target = null ; if ( ! ODocumentHelper . ATTRIBUTE_RID . equals ( destField ) && value instanceof String ) if ( ( ( String ) value ) . length ( ) == 0 ) value = null ; else value = "'" + value + "'" ; OResultSet rs = database . query ( cmd + value ) ; result = toList ( rs ) ; rs . close ( ) ; if ( result == null || result . size ( ) == 0 ) value = null ; else if ( result . size ( ) > 1 ) throw new OCommandExecutionException ( "Cannot create link because multiple records was found in class '" + destClass . getName ( ) + "' with value " + value + " in field '" + destField + "'" ) ; else { target = result . get ( 0 ) ; value = target ; } if ( target != null && inverse ) { // INVERSE RELATIONSHIP
oldValue = target . getProperty ( linkName ) ; if ( oldValue != null ) { if ( ! multipleRelationship ) multipleRelationship = true ; Collection < ODocument > coll ; if ( oldValue instanceof Collection ) { // ADD IT IN THE EXISTENT COLLECTION
coll = ( Collection < ODocument > ) oldValue ; target . setDirty ( ) ; } else { // CREATE A NEW COLLECTION FOR BOTH
coll = new ArrayList < ODocument > ( 2 ) ; target . setProperty ( linkName , coll ) ; coll . add ( ( ODocument ) oldValue ) ; } coll . add ( doc ) ; } else { if ( linkType != null ) if ( linkType == OType . LINKSET ) { value = new ORecordLazySet ( target ) ; ( ( Set < OIdentifiable > ) value ) . add ( doc ) ; } else if ( linkType == OType . LINKLIST ) { value = new ORecordLazyList ( target ) ; ( ( ORecordLazyList ) value ) . add ( doc ) ; } else // IGNORE THE TYPE , SET IT AS LINK
value = doc ; else value = doc ; target . setProperty ( linkName , value ) ; } target . save ( ) ; } else { // SET THE REFERENCE
doc . setProperty ( linkName , value ) ; doc . save ( ) ; } total ++ ; } } } if ( total > 0 ) { if ( inverse ) { // REMOVE THE OLD PROPERTY IF ANY
OProperty prop = destClass . getProperty ( linkName ) ; if ( prop != null ) destClass . dropProperty ( linkName ) ; if ( linkType == null ) linkType = multipleRelationship ? OType . LINKSET : OType . LINK ; // CREATE THE PROPERTY
destClass . createProperty ( linkName , linkType , sourceClass ) ; } else { // REMOVE THE OLD PROPERTY IF ANY
OProperty prop = sourceClass . getProperty ( linkName ) ; if ( prop != null ) sourceClass . dropProperty ( linkName ) ; // CREATE THE PROPERTY
sourceClass . createProperty ( linkName , OType . LINK , destClass ) ; } } } catch ( Exception e ) { throw OException . wrapException ( new OCommandExecutionException ( "Error on creation of links" ) , e ) ; } finally { database . declareIntent ( null ) ; } return total ;


signature:
public class OAtomicOperation { /** * This check if a file was trimmed or trunked in the current atomic operation .
 * @ param changesContainer changes container to check
 * @ param pageIndex limit to check against the changes
 * @ return true if there are no changes or pageIndex still fit , false if the pageIndex do not fit anymore */
private static boolean checkChangesFilledUpTo ( final FileChanges changesContainer , final long pageIndex ) { } }

implementation: if ( changesContainer == null ) { return true ; } else if ( changesContainer . isNew || changesContainer . maxNewPageIndex > - 2 ) { return pageIndex < changesContainer . maxNewPageIndex + 1 ; } else return ! changesContainer . truncate ;


signature:
public class OClassRemote { /** * { @ inheritDoc } */
@ Override public OClass truncateCluster ( String clusterName ) { } }

implementation: final ODatabaseDocumentInternal database = getDatabase ( ) ; database . checkSecurity ( ORule . ResourceGeneric . CLASS , ORole . PERMISSION_DELETE , name ) ; acquireSchemaReadLock ( ) ; try { final String cmd = String . format ( "truncate cluster %s" , clusterName ) ; database . command ( cmd ) . close ( ) ; } finally { releaseSchemaReadLock ( ) ; } return this ;


signature:
public class OCommandExecutorSQLAbstract { /** * Parses the timeout keyword if found . */
protected boolean parseTimeout ( final String w ) throws OCommandSQLParsingException { } }

implementation: if ( ! w . equals ( KEYWORD_TIMEOUT ) ) return false ; String word = parserNextWord ( true ) ; try { timeoutMs = Long . parseLong ( word ) ; } catch ( NumberFormatException ignore ) { throwParsingException ( "Invalid " + KEYWORD_TIMEOUT + " value set to '" + word + "' but it should be a valid long. Example: " + KEYWORD_TIMEOUT + " 3000" ) ; } if ( timeoutMs < 0 ) throwParsingException ( "Invalid " + KEYWORD_TIMEOUT + ": value set minor than ZERO. Example: " + KEYWORD_TIMEOUT + " 10000" ) ; word = parserNextWord ( true ) ; if ( word != null ) if ( word . equals ( TIMEOUT_STRATEGY . EXCEPTION . toString ( ) ) ) timeoutStrategy = TIMEOUT_STRATEGY . EXCEPTION ; else if ( word . equals ( TIMEOUT_STRATEGY . RETURN . toString ( ) ) ) timeoutStrategy = TIMEOUT_STRATEGY . RETURN ; else parserGoBack ( ) ; return true ;


signature:
public class OCommandExecutorSQLAbstract { /** * Parses the lock keyword if found . */
protected String parseLock ( ) throws OCommandSQLParsingException { } }

implementation: final String lockStrategy = parserNextWord ( true ) ; if ( ! lockStrategy . equalsIgnoreCase ( "DEFAULT" ) && ! lockStrategy . equalsIgnoreCase ( "NONE" ) && ! lockStrategy . equalsIgnoreCase ( "RECORD" ) ) throwParsingException ( "Invalid " + KEYWORD_LOCK + " value set to '" + lockStrategy + "' but it should be NONE (default) or RECORD. Example: " + KEYWORD_LOCK + " RECORD" ) ; return lockStrategy ;


signature:
public class SpatialQueryBuilderOverlap { /** * TODO check PGIS */
@ Override public OSpatialQueryContext build ( Map < String , Object > query ) throws Exception { } }

implementation: Shape shape = parseShape ( query ) ; SpatialStrategy strategy = manager . strategy ( ) ; SpatialArgs args = new SpatialArgs ( SpatialOperation . Intersects , shape . getBoundingBox ( ) ) ; Query filterQuery = strategy . makeQuery ( args ) ; BooleanQuery q = new BooleanQuery . Builder ( ) . add ( filterQuery , BooleanClause . Occur . MUST ) . add ( new MatchAllDocsQuery ( ) , BooleanClause . Occur . SHOULD ) . build ( ) ; return new OSpatialQueryContext ( null , manager . searcher ( ) , q ) ;


signature:
public class OCommandExecutorSQLOptimizeDatabase { /** * Execute the ALTER DATABASE . */
public Object execute ( final Map < Object , Object > iArgs ) { } }

implementation: final StringBuilder result = new StringBuilder ( ) ; if ( optimizeEdges ) result . append ( optimizeEdges ( ) ) ; return result . toString ( ) ;


signature:
public class OCommandExecutorSQLDeleteEdge { /** * Execute the command and return the ODocument object created . */
public Object execute ( final Map < Object , Object > iArgs ) { } }

implementation:
if ( fromExpr == null && toExpr == null && rids == null && query == null && compiledFilter == null ) throw new OCommandExecutionException ( "Cannot execute the command because it has not been parsed yet" ) ; txAlreadyBegun = getDatabase ( ) . getTransaction ( ) . isActive ( ) ; if ( rids != null ) { // REMOVE PUNCTUAL RID
OGraphCommandExecutorSQLFactory . runInConfiguredTxMode ( new OGraphCommandExecutorSQLFactory . GraphCallBack < Object > ( ) { @ Override public Object call ( OrientBaseGraph graph ) { for ( ORecordId rid : rids ) { final OrientEdge e = graph . getEdge ( rid ) ; if ( e != null ) { e . remove ( ) ; removed ++ ; } } return null ; } } ) ; // CLOSE PENDING TX
end ( ) ; } else { // MULTIPLE EDGES
final Set < OrientEdge > edges = new HashSet < OrientEdge > ( ) ; if ( query == null ) { OGraphCommandExecutorSQLFactory . runInConfiguredTxMode ( new OGraphCommandExecutorSQLFactory . GraphCallBack < Object > ( ) { @ Override public Object call ( OrientBaseGraph graph ) { Set < OIdentifiable > fromIds = null ; if ( fromExpr != null ) fromIds = OSQLEngine . getInstance ( ) . parseRIDTarget ( graph . getRawGraph ( ) , fromExpr , context , iArgs ) ; Set < OIdentifiable > toIds = null ; if ( toExpr != null ) toIds = OSQLEngine . getInstance ( ) . parseRIDTarget ( graph . getRawGraph ( ) , toExpr , context , iArgs ) ; if ( label == null ) label = OrientEdgeType . CLASS_NAME ; if ( fromIds != null && toIds != null ) { int fromCount = 0 ; int toCount = 0 ; for ( OIdentifiable fromId : fromIds ) { final OrientVertex v = graph . getVertex ( fromId ) ; if ( v != null ) fromCount += v . countEdges ( Direction . OUT , label ) ; } for ( OIdentifiable toId : toIds ) { final OrientVertex v = graph . getVertex ( toId ) ; if ( v != null ) toCount += v . countEdges ( Direction . IN , label ) ; } if ( fromCount <= toCount ) { // REMOVE ALL THE EDGES BETWEEN VERTICES
for ( OIdentifiable fromId : fromIds ) { final OrientVertex v = graph . getVertex ( fromId ) ; if ( v != null ) for ( Edge e : v . getEdges ( Direction . OUT , label ) ) { final OIdentifiable inV = ( ( OrientEdge ) e ) . getInVertex ( ) ; if ( inV != null && toIds . contains ( inV . getIdentity ( ) ) ) edges . add ( ( OrientEdge ) e ) ; } } } else { for ( OIdentifiable toId : toIds ) { final OrientVertex v = graph . getVertex ( toId ) ; if ( v != null ) for ( Edge e : v . getEdges ( Direction . IN , label ) ) { final OIdentifiable outV = ( ( OrientEdge ) e ) . getOutVertex ( ) ; if ( outV != null && fromIds . contains ( outV . getIdentity ( ) ) ) edges . add ( ( OrientEdge ) e ) ; } } } } else if ( fromIds != null ) { // REMOVE ALL THE EDGES THAT START FROM A VERTEXES
for ( OIdentifiable fromId : fromIds ) { final OrientVertex v = graph . getVertex ( fromId ) ; if ( v != null ) { for ( Edge e : v . getEdges ( Direction . OUT , label ) ) { edges . add ( ( OrientEdge ) e ) ; } } } } else if ( toIds != null ) { // REMOVE ALL THE EDGES THAT ARRIVE TO A VERTEXES
for ( OIdentifiable toId : toIds ) { final OrientVertex v = graph . getVertex ( toId ) ; if ( v != null ) { for ( Edge e : v . getEdges ( Direction . IN , label ) ) { edges . add ( ( OrientEdge ) e ) ; } } } } else throw new OCommandExecutionException ( "Invalid target: " + toIds ) ; if ( compiledFilter != null ) { // ADDITIONAL FILTERING
for ( Iterator < OrientEdge > it = edges . iterator ( ) ; it . hasNext ( ) ; ) { final OrientEdge edge = it . next ( ) ; if ( ! ( Boolean ) compiledFilter . evaluate ( edge . getRecord ( ) , null , context ) ) it . remove ( ) ; } } // DELETE THE FOUND EDGES
removed = edges . size ( ) ; for ( OrientEdge edge : edges ) edge . remove ( ) ; return null ; } } ) ; // CLOSE PENDING TX
end ( ) ; } else { OGraphCommandExecutorSQLFactory . runInConfiguredTxMode ( new OGraphCommandExecutorSQLFactory . GraphCallBack < OrientGraph > ( ) { @ Override public OrientGraph call ( final OrientBaseGraph iGraph ) { // TARGET IS A CLASS + OPTIONAL CONDITION
currentGraph . set ( iGraph ) ; query . setContext ( getContext ( ) ) ; query . execute ( iArgs ) ; return null ; } } ) ; } } return removed ;


signature:
public class OCommandExecutorSQLDeleteEdge { /** * Delete the current edge . */
public boolean result ( final Object iRecord ) { } }

implementation:
final OIdentifiable id = ( OIdentifiable ) iRecord ; if ( compiledFilter != null ) { // ADDITIONAL FILTERING
if ( ! ( Boolean ) compiledFilter . evaluate ( id . getRecord ( ) , null , context ) ) return true ; } if ( id . getIdentity ( ) . isValid ( ) ) { final OrientBaseGraph g = currentGraph . get ( ) ; final OrientEdge e = g . getEdge ( id ) ; if ( e != null ) { e . remove ( ) ; if ( ! txAlreadyBegun && batch > 0 && ( removed + 1 ) % batch == 0 ) { if ( g instanceof OrientGraph ) { g . commit ( ) ; ( ( OrientGraph ) g ) . begin ( ) ; } } removed ++ ; } } return true ;


signature:
public class OIndexSearchResult { /** * Combines two queries subset into one . This operation will be valid only if { @ link # canBeMerged ( OIndexSearchResult ) } method will
 * return < code > true < / code > for the same passed in parameter .
 * @ param searchResult
 * Query subset to merge .
 * @ return New instance that presents merged query . */
public OIndexSearchResult merge ( final OIndexSearchResult searchResult ) { } }

implementation:
// if ( searchResult . lastOperator instanceof OQueryOperatorEquals ) {
if ( searchResult . lastOperator instanceof OQueryOperatorEquals ) { return mergeFields ( this , searchResult ) ; } if ( lastOperator instanceof OQueryOperatorEquals ) { return mergeFields ( searchResult , this ) ; } if ( isIndexEqualityOperator ( searchResult . lastOperator ) ) { return mergeFields ( this , searchResult ) ; } return mergeFields ( searchResult , this ) ;


signature:
public class OCommandExecutorSQLTruncateClass { /** * Execute the command . */
public Object execute ( final Map < Object , Object > iArgs ) { } }

implementation:
if ( schemaClass == null ) throw new OCommandExecutionException ( "Cannot execute the command because it has not been parsed yet" ) ; final long recs = schemaClass . count ( deep ) ; if ( recs > 0 && ! unsafe ) { if ( schemaClass . isSubClassOf ( "V" ) ) { throw new OCommandExecutionException ( "'TRUNCATE CLASS' command cannot be used on not empty vertex classes. Apply the 'UNSAFE' keyword to force it (at your own risk)" ) ; } else if ( schemaClass . isSubClassOf ( "E" ) ) { throw new OCommandExecutionException ( "'TRUNCATE CLASS' command cannot be used on not empty edge classes. Apply the 'UNSAFE' keyword to force it (at your own risk)" ) ; } } Collection < OClass > subclasses = schemaClass . getAllSubclasses ( ) ; if ( deep && ! unsafe ) { // for multiple inheritance
for ( OClass subclass : subclasses ) { long subclassRecs = schemaClass . count ( ) ; if ( subclassRecs > 0 ) { if ( subclass . isSubClassOf ( "V" ) ) { throw new OCommandExecutionException ( "'TRUNCATE CLASS' command cannot be used on not empty vertex classes (" + subclass . getName ( ) + "). Apply the 'UNSAFE' keyword to force it (at your own risk)" ) ; } else if ( subclass . isSubClassOf ( "E" ) ) { throw new OCommandExecutionException ( "'TRUNCATE CLASS' command cannot be used on not empty edge classes (" + subclass . getName ( ) + "). Apply the 'UNSAFE' keyword to force it (at your own risk)" ) ; } } } } try { schemaClass . truncate ( ) ; invalidateCommandCache ( schemaClass ) ; if ( deep ) { for ( OClass subclass : subclasses ) { subclass . truncate ( ) ; invalidateCommandCache ( subclass ) ; } } } catch ( IOException e ) { throw OException . wrapException ( new OCommandExecutionException ( "Error on executing command" ) , e ) ; } return recs ;


signature:
public class Bucket { /** * Obtains the value stored under the given entry index in this bucket .
 * @ param entryIndex the value entry index .
 * @ return the obtained value . */
List < ORID > getValues ( final int entryIndex ) { } }

implementation:
assert isLeaf ; int entryPosition = getIntValue ( entryIndex * OIntegerSerializer . INT_SIZE + POSITIONS_ARRAY_OFFSET ) ; int nextItem = getIntValue ( entryPosition ) ; entryPosition += OIntegerSerializer . INT_SIZE ; // skip key
if ( encryption == null ) { entryPosition += getObjectSizeInDirectMemory ( keySerializer , entryPosition ) ; } else { final int encryptedSize = getIntValue ( entryPosition ) ; entryPosition += OIntegerSerializer . INT_SIZE + encryptedSize ; } int clusterId = getShortValue ( entryPosition ) ; long clusterPosition = getLongValue ( entryPosition + OShortSerializer . SHORT_SIZE ) ; final List < ORID > results = new ArrayList < > ( 8 ) ; results . add ( new ORecordId ( clusterId , clusterPosition ) ) ; while ( nextItem > 0 ) { final int nextNextItem = getIntValue ( nextItem ) ; final int nextItemSize = 0xFF & getByteValue ( nextItem + OIntegerSerializer . INT_SIZE ) ; for ( int i = 0 ; i < nextItemSize ; i ++ ) { clusterId = getShortValue ( nextItem + OIntegerSerializer . INT_SIZE + OByteSerializer . BYTE_SIZE + i * RID_SIZE ) ; clusterPosition = getLongValue ( nextItem + OIntegerSerializer . INT_SIZE + OShortSerializer . SHORT_SIZE + OByteSerializer . BYTE_SIZE + i * RID_SIZE ) ; results . add ( new ORecordId ( clusterId , clusterPosition ) ) ; } nextItem = nextNextItem ; } return results ;


signature:
public class OSystemDatabase { /** * Adds the specified cluster to the class , if it doesn ' t already exist . */
public void createCluster ( final String className , final String clusterName ) { } }

implementation: final ODatabaseDocumentInternal currentDB = ODatabaseRecordThreadLocal . instance ( ) . getIfDefined ( ) ; try { final ODatabaseDocumentInternal sysdb = openSystemDatabase ( ) ; try { if ( ! sysdb . existsCluster ( clusterName ) ) { OSchema schema = sysdb . getMetadata ( ) . getSchema ( ) ; OClass cls = schema . getClass ( className ) ; if ( cls != null ) { cls . addCluster ( clusterName ) ; } else { OLogManager . instance ( ) . error ( this , "createCluster() Class name %s does not exist" , null , className ) ; } } } finally { sysdb . close ( ) ; } } finally { if ( currentDB != null ) ODatabaseRecordThreadLocal . instance ( ) . set ( currentDB ) ; else ODatabaseRecordThreadLocal . instance ( ) . remove ( ) ; }


signature:
public class OAbstractRecordCache { /** * Remove all records belonging to specified cluster
 * @ param cid
 * identifier of cluster */
public void freeCluster ( final int cid ) { } }

implementation: final Set < ORID > toRemove = new HashSet < ORID > ( underlying . size ( ) / 2 ) ; final Set < ORID > keys = new HashSet < ORID > ( underlying . keys ( ) ) ; for ( final ORID id : keys ) if ( id . getClusterId ( ) == cid ) toRemove . add ( id ) ; for ( final ORID ridToRemove : toRemove ) underlying . remove ( ridToRemove ) ;


signature:
public class OAbstractRecordCache { /** * All operations running at cache initialization stage */
public void startup ( ) { } }

implementation: underlying . startup ( ) ; Orient . instance ( ) . getProfiler ( ) . registerHookValue ( profilerPrefix + "current" , "Number of entries in cache" , METRIC_TYPE . SIZE , new OProfilerHookValue ( ) { public Object getValue ( ) { return getSize ( ) ; } } , profilerMetadataPrefix + "current" ) ;


signature:
public class OAbstractRecordCache { /** * All operations running at cache destruction stage */
public void shutdown ( ) { } }

implementation: underlying . shutdown ( ) ; if ( Orient . instance ( ) . getProfiler ( ) != null ) { Orient . instance ( ) . getProfiler ( ) . unregisterHookValue ( profilerPrefix + "enabled" ) ; Orient . instance ( ) . getProfiler ( ) . unregisterHookValue ( profilerPrefix + "current" ) ; Orient . instance ( ) . getProfiler ( ) . unregisterHookValue ( profilerPrefix + "max" ) ; }


signature:
public class OScriptResultSets { /** * Result set with a single result ;
 * @ return */
public static OScriptResultSet singleton ( Object entity , OScriptTransformer transformer ) { } }

implementation: return new OScriptResultSet ( Collections . singletonList ( entity ) . iterator ( ) , transformer ) ;


signature:
public class ORole { /** * Grant a permission to the resource .
 * @ return */
public ORole grant ( final ORule . ResourceGeneric resourceGeneric , String resourceSpecific , final int iOperation ) { } }

implementation: ORule rule = rules . get ( resourceGeneric ) ; if ( rule == null ) { rule = new ORule ( resourceGeneric , null , null ) ; rules . put ( resourceGeneric , rule ) ; } rule . grantAccess ( resourceSpecific , iOperation ) ; rules . put ( resourceGeneric , rule ) ; updateRolesDocumentContent ( ) ; return this ;


signature:
public class ORole { /** * Revoke a permission to the resource . */
public ORole revoke ( final ORule . ResourceGeneric resourceGeneric , String resourceSpecific , final int iOperation ) { } }

implementation: if ( iOperation == PERMISSION_NONE ) return this ; ORule rule = rules . get ( resourceGeneric ) ; if ( rule == null ) { rule = new ORule ( resourceGeneric , null , null ) ; rules . put ( resourceGeneric , rule ) ; } rule . revokeAccess ( resourceSpecific , iOperation ) ; rules . put ( resourceGeneric , rule ) ; updateRolesDocumentContent ( ) ; return this ;


signature:
public class OFloatSerializer { /** * { @ inheritDoc } */
@ Override public void serializeInByteBufferObject ( Float object , ByteBuffer buffer , Object ... hints ) { } }

implementation: buffer . putInt ( Float . floatToIntBits ( object ) ) ;


signature:
public class OFloatSerializer { /** * { @ inheritDoc } */
@ Override public Float deserializeFromByteBufferObject ( ByteBuffer buffer , OWALChanges walChanges , int offset ) { } }

implementation: return Float . intBitsToFloat ( walChanges . getIntValue ( buffer , offset ) ) ;


signature:
public class OCommandExecutorSQLDelete { /** * Deletes the current record . */
public boolean result ( final Object iRecord ) { } }

implementation:
final ORecordAbstract record = ( ( OIdentifiable ) iRecord ) . getRecord ( ) ; if ( record instanceof ODocument && compiledFilter != null && ! Boolean . TRUE . equals ( this . compiledFilter . evaluate ( record , ( ODocument ) record , getContext ( ) ) ) ) { return true ; } try { if ( record . getIdentity ( ) . isValid ( ) ) { if ( returning . equalsIgnoreCase ( "BEFORE" ) ) allDeletedRecords . add ( record ) ; // RESET VERSION TO DISABLE MVCC AVOIDING THE CONCURRENT EXCEPTION IF LOCAL CACHE IS NOT UPDATED
// ORecordInternal . setVersion ( record , - 1 ) ;
if ( ! unsafe && record instanceof ODocument ) { // CHECK IF ARE VERTICES OR EDGES
final OClass cls = ( ( ODocument ) record ) . getSchemaClass ( ) ; if ( cls != null ) { if ( cls . isSubClassOf ( "V" ) ) // FOUND VERTEX
throw new OCommandExecutionException ( "'DELETE' command cannot delete vertices. Use 'DELETE VERTEX' command instead, or apply the 'UNSAFE' keyword to force it" ) ; else if ( cls . isSubClassOf ( "E" ) ) // FOUND EDGE
throw new OCommandExecutionException ( "'DELETE' command cannot delete edges. Use 'DELETE EDGE' command instead, or apply the 'UNSAFE' keyword to force it" ) ; } } record . delete ( ) ; recordCount ++ ; return true ; } return false ; } finally { if ( lockStrategy . equalsIgnoreCase ( "RECORD" ) ) ( ( OAbstractPaginatedStorage ) getDatabase ( ) . getStorage ( ) ) . releaseWriteLock ( record . getIdentity ( ) ) ; }


signature:
public class OMoveVertexExecutionPlanner { /** * add a step that transforms a normal OResult in a specific object that under setProperty ( ) updates the actual OIdentifiable
 * @ param plan the execution plan
 * @ param ctx the executino context */
private void convertToModifiableResult ( OUpdateExecutionPlan plan , OCommandContext ctx , boolean profilingEnabled ) { } }

implementation: plan . chain ( new ConvertToUpdatableResultStep ( ctx , profilingEnabled ) ) ;


signature:
public class OIntegerSerializer { /** * { @ inheritDoc } */
@ Override public void serializeInByteBufferObject ( Integer object , ByteBuffer buffer , Object ... hints ) { } }

implementation: buffer . putInt ( object ) ;


signature:
public class OIntegerSerializer { /** * { @ inheritDoc } */
@ Override public Integer deserializeFromByteBufferObject ( ByteBuffer buffer , OWALChanges walChanges , int offset ) { } }

implementation: return walChanges . getIntValue ( buffer , offset ) ;


signature:
public class OSQLPredicate { /** * Binds parameters . */
public void bindParameters ( final Map < Object , Object > iArgs ) { } }

implementation: if ( parameterItems == null || iArgs == null || iArgs . size ( ) == 0 ) return ; for ( int i = 0 ; i < parameterItems . size ( ) ; i ++ ) { OSQLFilterItemParameter value = parameterItems . get ( i ) ; if ( "?" . equals ( value . getName ( ) ) ) { value . setValue ( iArgs . get ( i ) ) ; } else { value . setValue ( iArgs . get ( value . getName ( ) ) ) ; } }


signature:
public class OObjectCustomSerializerList { /** * Convert the item requested .
 * @ param iIndex
 * Position of the item to convert */
private void convert ( final int iIndex ) { } }

implementation: if ( converted ) return ; Object o = list . get ( iIndex ) ; if ( o == null ) { o = serializedList . get ( iIndex ) ; list . set ( iIndex , OObjectEntitySerializer . deserializeFieldValue ( deserializeClass , o ) ) ; }


signature:
public class MatchEdgeTraverser { /** * TODO refactor this method to receive the item . */
protected Iterable < OResultInternal > traversePatternEdge ( OIdentifiable startingPoint , OCommandContext iCommandContext ) { } }

implementation: Iterable possibleResults = null ; if ( this . item . getFilter ( ) != null ) { String alias = getEndpointAlias ( ) ; Object matchedNodes = iCommandContext . getVariable ( MatchPrefetchStep . PREFETCHED_MATCH_ALIAS_PREFIX + alias ) ; if ( matchedNodes != null ) { if ( matchedNodes instanceof Iterable ) { possibleResults = ( Iterable ) matchedNodes ; } else { possibleResults = Collections . singleton ( matchedNodes ) ; } } } Object prevCurrent = iCommandContext . getVariable ( "$current" ) ; iCommandContext . setVariable ( "$current" , startingPoint ) ; Object qR ; try { qR = this . item . getMethod ( ) . execute ( startingPoint , possibleResults , iCommandContext ) ; } finally { iCommandContext . setVariable ( "$current" , prevCurrent ) ; } if ( qR == null ) { return Collections . EMPTY_LIST ; } if ( qR instanceof OIdentifiable ) { return Collections . singleton ( new OResultInternal ( ( OIdentifiable ) qR ) ) ; } if ( qR instanceof Iterable ) { final Iterator < Object > iter = ( ( Iterable ) qR ) . iterator ( ) ; Iterable < OResultInternal > result = ( ) -> new Iterator < OResultInternal > ( ) { private OResultInternal nextElement ; @ Override public boolean hasNext ( ) { if ( nextElement == null ) { fetchNext ( ) ; } return nextElement != null ; } @ Override public OResultInternal next ( ) { if ( nextElement == null ) { fetchNext ( ) ; } if ( nextElement == null ) { throw new IllegalStateException ( ) ; } OResultInternal res = nextElement ; nextElement = null ; return res ; } public void fetchNext ( ) { while ( iter . hasNext ( ) ) { Object o = iter . next ( ) ; if ( o instanceof OIdentifiable ) { nextElement = new OResultInternal ( ( OIdentifiable ) o ) ; break ; } else if ( o instanceof OResultInternal ) { nextElement = ( OResultInternal ) o ; break ; } else if ( o == null ) { continue ; } else { throw new UnsupportedOperationException ( ) ; } } } } ; return result ; } return Collections . EMPTY_LIST ;


signature:
public class OObjectEnumLazyList { /** * Convert the item requested .
 * @ param iIndex
 * Position of the item to convert */
private void convert ( final int iIndex ) { } }

implementation: if ( converted ) return ; Object o = list . get ( iIndex ) ; if ( o == null ) { o = serializedList . get ( iIndex ) ; if ( o instanceof Number ) o = enumClass . getEnumConstants ( ) [ ( ( Number ) o ) . intValue ( ) ] ; else o = Enum . valueOf ( enumClass , o . toString ( ) ) ; list . set ( iIndex , ( TYPE ) o ) ; }


signature:
public class ORecordSerializerStringAbstract { /** * Parses a string returning the closer type . Numbers by default are INTEGER if haven ' t decimal separator , otherwise FLOAT . To
 * treat all the number types numbers are postponed with a character that tells the type : b = byte , s = short , l = long , f = float ,
 * d = double , t = date .
 * @ param iValue
 * Value to parse
 * @ return The closest type recognized */
public static OType getType ( final String iValue ) { } }

implementation:
if ( iValue . length ( ) == 0 ) return null ; final char firstChar = iValue . charAt ( 0 ) ; if ( firstChar == ORID . PREFIX ) // RID
return OType . LINK ; else if ( firstChar == '\'' || firstChar == '"' ) return OType . STRING ; else if ( firstChar == OStringSerializerHelper . BINARY_BEGINEND ) return OType . BINARY ; else if ( firstChar == OStringSerializerHelper . EMBEDDED_BEGIN ) return OType . EMBEDDED ; else if ( firstChar == OStringSerializerHelper . LIST_BEGIN ) return OType . EMBEDDEDLIST ; else if ( firstChar == OStringSerializerHelper . SET_BEGIN ) return OType . EMBEDDEDSET ; else if ( firstChar == OStringSerializerHelper . MAP_BEGIN ) return OType . EMBEDDEDMAP ; else if ( firstChar == OStringSerializerHelper . CUSTOM_TYPE ) return OType . CUSTOM ; // BOOLEAN ?
if ( iValue . equalsIgnoreCase ( "true" ) || iValue . equalsIgnoreCase ( "false" ) ) return OType . BOOLEAN ; // NUMBER OR STRING ?
boolean integer = true ; for ( int index = 0 ; index < iValue . length ( ) ; ++ index ) { final char c = iValue . charAt ( index ) ; if ( c < '0' || c > '9' ) if ( ( index == 0 && ( c == '+' || c == '-' ) ) ) continue ; else if ( c == DECIMAL_SEPARATOR ) integer = false ; else { if ( index > 0 ) if ( ! integer && c == 'E' ) { // CHECK FOR SCIENTIFIC NOTATION
if ( index < iValue . length ( ) ) { if ( iValue . charAt ( index + 1 ) == '-' ) // JUMP THE DASH IF ANY ( NOT MANDATORY )
index ++ ; continue ; } } else if ( c == 'f' ) return index != ( iValue . length ( ) - 1 ) ? OType . STRING : OType . FLOAT ; else if ( c == 'c' ) return index != ( iValue . length ( ) - 1 ) ? OType . STRING : OType . DECIMAL ; else if ( c == 'l' ) return index != ( iValue . length ( ) - 1 ) ? OType . STRING : OType . LONG ; else if ( c == 'd' ) return index != ( iValue . length ( ) - 1 ) ? OType . STRING : OType . DOUBLE ; else if ( c == 'b' ) return index != ( iValue . length ( ) - 1 ) ? OType . STRING : OType . BYTE ; else if ( c == 'a' ) return index != ( iValue . length ( ) - 1 ) ? OType . STRING : OType . DATE ; else if ( c == 't' ) return index != ( iValue . length ( ) - 1 ) ? OType . STRING : OType . DATETIME ; else if ( c == 's' ) return index != ( iValue . length ( ) - 1 ) ? OType . STRING : OType . SHORT ; else if ( c == 'e' ) { // eg . 1e - 06
try { Double . parseDouble ( iValue ) ; return OType . DOUBLE ; } catch ( Exception ignore ) { return OType . STRING ; } } return OType . STRING ; } } if ( integer ) { // AUTO CONVERT TO LONG IF THE INTEGER IS TOO BIG
final int numberLength = iValue . length ( ) ; if ( numberLength > MAX_INTEGER_DIGITS || ( numberLength == MAX_INTEGER_DIGITS && iValue . compareTo ( MAX_INTEGER_AS_STRING ) > 0 ) ) return OType . LONG ; return OType . INTEGER ; } // CHECK IF THE DECIMAL NUMBER IS A FLOAT OR DOUBLE
final double dou = Double . parseDouble ( iValue ) ; if ( dou <= Float . MAX_VALUE && dou >= Float . MIN_VALUE && Double . toString ( dou ) . equals ( Float . toString ( ( float ) dou ) ) && new Double ( new Double ( dou ) . floatValue ( ) ) . doubleValue ( ) == dou ) { return OType . FLOAT ; } else if ( ! new Double ( dou ) . toString ( ) . equals ( iValue ) ) { return OType . DECIMAL ; } return OType . DOUBLE ;


signature:
public class ORecordSerializerStringAbstract { /** * Parses the field type char returning the closer type . Default is STRING . b = binary if iValue . length ( ) > = 4 b = byte if
 * iValue . length ( ) < = 3 s = short , l = long f = float d = double a = date t = datetime
 * @ param iValue
 * Value to parse
 * @ param iCharType
 * Char value indicating the type
 * @ return The closest type recognized */
public static OType getType ( final String iValue , final char iCharType ) { } }

implementation: if ( iCharType == 'f' ) return OType . FLOAT ; else if ( iCharType == 'c' ) return OType . DECIMAL ; else if ( iCharType == 'l' ) return OType . LONG ; else if ( iCharType == 'd' ) return OType . DOUBLE ; else if ( iCharType == 'b' ) { if ( iValue . length ( ) >= 1 && iValue . length ( ) <= 3 ) return OType . BYTE ; else return OType . BINARY ; } else if ( iCharType == 'a' ) return OType . DATE ; else if ( iCharType == 't' ) return OType . DATETIME ; else if ( iCharType == 's' ) return OType . SHORT ; else if ( iCharType == 'e' ) return OType . EMBEDDEDSET ; else if ( iCharType == 'g' ) return OType . LINKBAG ; else if ( iCharType == 'z' ) return OType . LINKLIST ; else if ( iCharType == 'm' ) return OType . LINKMAP ; else if ( iCharType == 'x' ) return OType . LINK ; else if ( iCharType == 'n' ) return OType . LINKSET ; else if ( iCharType == 'x' ) return OType . LINK ; else if ( iCharType == 'u' ) return OType . CUSTOM ; return OType . STRING ;


signature:
public class ORecordSerializerStringAbstract { /** * Parses a string returning the value with the closer type . Numbers by default are INTEGER if haven ' t decimal separator ,
 * otherwise FLOAT . To treat all the number types numbers are postponed with a character that tells the type : b = byte , s = short ,
 * l = long , f = float , d = double , t = date . If starts with # it ' s a RecordID . Most of the code is equals to getType ( ) but has been
 * copied to speed - up it .
 * @ param iValue
 * Value to parse
 * @ return The closest type recognized */
public static Object getTypeValue ( final String iValue ) { } }

implementation:
if ( iValue == null || iValue . equalsIgnoreCase ( "NULL" ) ) return null ; if ( iValue . length ( ) == 0 ) return "" ; if ( iValue . length ( ) > 1 ) if ( iValue . charAt ( 0 ) == '"' && iValue . charAt ( iValue . length ( ) - 1 ) == '"' ) // STRING
return OStringSerializerHelper . decode ( iValue . substring ( 1 , iValue . length ( ) - 1 ) ) ; else if ( iValue . charAt ( 0 ) == OStringSerializerHelper . BINARY_BEGINEND && iValue . charAt ( iValue . length ( ) - 1 ) == OStringSerializerHelper . BINARY_BEGINEND ) // STRING
return OStringSerializerHelper . getBinaryContent ( iValue ) ; else if ( iValue . charAt ( 0 ) == OStringSerializerHelper . LIST_BEGIN && iValue . charAt ( iValue . length ( ) - 1 ) == OStringSerializerHelper . LIST_END ) { // LIST
final ArrayList < String > coll = new ArrayList < String > ( ) ; OStringSerializerHelper . getCollection ( iValue , 0 , coll , OStringSerializerHelper . LIST_BEGIN , OStringSerializerHelper . LIST_END , OStringSerializerHelper . COLLECTION_SEPARATOR ) ; return coll ; } else if ( iValue . charAt ( 0 ) == OStringSerializerHelper . SET_BEGIN && iValue . charAt ( iValue . length ( ) - 1 ) == OStringSerializerHelper . SET_END ) { // SET
final Set < String > coll = new HashSet < String > ( ) ; OStringSerializerHelper . getCollection ( iValue , 0 , coll , OStringSerializerHelper . SET_BEGIN , OStringSerializerHelper . SET_END , OStringSerializerHelper . COLLECTION_SEPARATOR ) ; return coll ; } else if ( iValue . charAt ( 0 ) == OStringSerializerHelper . MAP_BEGIN && iValue . charAt ( iValue . length ( ) - 1 ) == OStringSerializerHelper . MAP_END ) { // MAP
return OStringSerializerHelper . getMap ( iValue ) ; } if ( iValue . charAt ( 0 ) == ORID . PREFIX ) // RID
return new ORecordId ( iValue ) ; boolean integer = true ; char c ; boolean stringStarBySign = false ; for ( int index = 0 ; index < iValue . length ( ) ; ++ index ) { c = iValue . charAt ( index ) ; if ( c < '0' || c > '9' ) { if ( ( index == 0 && ( c == '+' || c == '-' ) ) ) { stringStarBySign = true ; continue ; } else if ( c == DECIMAL_SEPARATOR ) integer = false ; else { if ( index > 0 ) { if ( ! integer && c == 'E' ) { // CHECK FOR SCIENTIFIC NOTATION
if ( index < iValue . length ( ) ) index ++ ; if ( iValue . charAt ( index ) == '-' ) continue ; } final String v = iValue . substring ( 0 , index ) ; if ( c == 'f' ) return new Float ( v ) ; else if ( c == 'c' ) return new BigDecimal ( v ) ; else if ( c == 'l' ) return new Long ( v ) ; else if ( c == 'd' ) return new Double ( v ) ; else if ( c == 'b' ) return new Byte ( v ) ; else if ( c == 'a' || c == 't' ) return new Date ( Long . parseLong ( v ) ) ; else if ( c == 's' ) return new Short ( v ) ; } return iValue ; } } else if ( stringStarBySign ) { stringStarBySign = false ; } } if ( stringStarBySign ) return iValue ; if ( integer ) { try { return new Integer ( iValue ) ; } catch ( NumberFormatException ignore ) { return new Long ( iValue ) ; } } else if ( "NaN" . equals ( iValue ) || "Infinity" . equals ( iValue ) ) // NaN and Infinity CANNOT BE MANAGED BY BIG - DECIMAL TYPE
return new Double ( iValue ) ; else return new BigDecimal ( iValue ) ;


signature:
public class FrequencySketch { /** * Increments the popularity of the element if it does not exceed the maximum ( 15 ) . The popularity
 * of all elements will be periodically down sampled when the observed events exceeds a threshold .
 * This process provides a frequency aging to allow expired long term entries to fade away .
 * @ param hash the hash code of element */
@ Override public void increment ( int hash ) { } }

implementation:
hash = spread ( hash ) ; final int start = ( hash & 3 ) << 2 ; // Loop unrolling improves throughput by 5m ops / s
final int index0 = indexOf ( hash , 0 ) ; final int index1 = indexOf ( hash , 1 ) ; final int index2 = indexOf ( hash , 2 ) ; final int index3 = indexOf ( hash , 3 ) ; boolean added = incrementAt ( index0 , start ) ; added |= incrementAt ( index1 , start + 1 ) ; added |= incrementAt ( index2 , start + 2 ) ; added |= incrementAt ( index3 , start + 3 ) ; if ( added && ( ++ size == sampleSize ) ) { reset ( ) ; }


signature:
public class FrequencySketch { /** * Increments the specified counter by 1 if it is not already at the maximum value ( 15 ) .
 * @ param i the table index ( 16 counters )
 * @ param j the counter to increment
 * @ return if incremented */
private boolean incrementAt ( final int i , final int j ) { } }

implementation: final int offset = j << 2 ; final long mask = ( 0xfL << offset ) ; if ( ( table [ i ] & mask ) != mask ) { table [ i ] += ( 1L << offset ) ; return true ; } return false ;


signature:
public class FrequencySketch { /** * Reduces every counter by half of its original value . */
private void reset ( ) { } }

implementation: int count = 0 ; for ( int i = 0 ; i < table . length ; i ++ ) { count += Long . bitCount ( table [ i ] & ONE_MASK ) ; table [ i ] = ( table [ i ] >>> 1 ) & RESET_MASK ; } size = ( size >>> 1 ) - ( count >>> 2 ) ;


signature:
public class FrequencySketch { /** * Returns the table index for the counter at the specified depth .
 * @ param item the element ' s hash
 * @ param i the counter depth
 * @ return the table index */
private int indexOf ( final int item , final int i ) { } }

implementation: long hash = SEED [ i ] * item ; hash += hash >> 32 ; return ( ( int ) hash ) & tableMask ;


signature:
public class FrequencySketch { /** * Applies a supplemental hash function to a given hashCode , which defends against poor quality
 * hash functions . */
private int spread ( int x ) { } }


signature:
public class OPropertyImpl { /** * Creates an index on this property . Indexes speed up queries but slow down insert and update operations . For massive inserts we
 * suggest to remove the index , make the massive insert and recreate it .
 * @ param iType
 * @ return
 * @ see { @ link OClass # createIndex ( String , OClass . INDEX _ TYPE , String . . . ) } instead . */
public OIndex < ? > createIndex ( final String iType ) { } }

implementation: acquireSchemaReadLock ( ) ; try { return owner . createIndex ( getFullName ( ) , iType , globalRef . getName ( ) ) ; } finally { releaseSchemaReadLock ( ) ; }