Input: assigns default aliases to pattern nodes that do not have an explicit alias [CODESPLIT] private void assignDefaultAliases ( List < OMatchExpression > matchExpressions ) { int counter = 0 ; for ( OMatchExpression expression : matchExpressions ) { if ( expression . origin . getAlias ( ) == null ) { expression . origin . setAlias ( DEFAULT_ALIAS_PREFIX + ( counter ++ ) ) ; } for ( OMatchPathItem item : expression . items ) { if ( item . filter == null ) { item . filter = new OMatchFilter ( - 1 ) ; } if ( item . filter . getAlias ( ) == null ) { item . filter . setAlias ( DEFAULT_ALIAS_PREFIX + ( counter ++ ) ) ; } } } }


Input: this method works statefully using request and context variables from current Match statement . This method will be deprecated in next releases [CODESPLIT] @ Override public Object execute ( Map < Object , Object > iArgs ) { this . context . setInputParameters ( iArgs ) ; return execute ( this . request , this . context , this . progressListener ) ; }


Input: executes the match statement . This is the preferred execute () method and it has to be used as the default one in the future . This method works in stateless mode [CODESPLIT] public Object execute ( OSQLAsynchQuery < ODocument > request , OCommandContext context , OProgressListener progressListener ) { if ( orderBy != null ) { throw new OCommandExecutionException ( "ORDER BY is not supported in MATCH on the legacy API" ) ; } if ( groupBy != null ) { throw new OCommandExecutionException ( "GROUP BY is not supported in MATCH on the legacy API" ) ; } if ( unwind != null ) { throw new OCommandExecutionException ( "UNWIND is not supported in MATCH on the legacy API" ) ; } if ( skip != null ) { throw new OCommandExecutionException ( "SKIP is not supported in MATCH on the legacy API" ) ; } Map < Object , Object > iArgs = context . getInputParameters ( ) ; try { Map < String , Long > estimatedRootEntries = estimateRootEntries ( aliasClasses , aliasFilters , context ) ; if ( estimatedRootEntries . values ( ) . contains ( 0l ) ) { return new OBasicLegacyResultSet ( ) ; // some aliases do not match on any classes } List < EdgeTraversal > sortedEdges = getTopologicalSortedSchedule ( estimatedRootEntries , pattern ) ; MatchExecutionPlan executionPlan = new MatchExecutionPlan ( ) ; executionPlan . sortedEdges = sortedEdges ; calculateMatch ( pattern , estimatedRootEntries , new MatchContext ( ) , aliasClasses , aliasFilters , context , request , executionPlan ) ; return getResult ( request ) ; } finally { if ( request . getResultListener ( ) != null ) { request . getResultListener ( ) . end ( ) ; } } }


Input: Start a depth - first traversal from the starting node adding all viable unscheduled edges and vertices . [CODESPLIT] private void updateScheduleStartingAt ( PatternNode startNode , Set < PatternNode > visitedNodes , Set < PatternEdge > visitedEdges , Map < String , Set < String > > remainingDependencies , List < EdgeTraversal > resultingSchedule ) { // OrientDB requires the schedule to contain all edges present in the query, which is a stronger condition // than simply visiting all nodes in the query. Consider the following example query: //     MATCH { //         class: A, //         as: foo //     }.in() { //         as: bar //     }, { //         class: B, //         as: bar //     }.out() { //         as: foo //     } RETURN $matches // The schedule for the above query must have two edges, even though there are only two nodes and they can both // be visited with the traversal of a single edge. // // To satisfy it, we obey the following for each non-optional node: // - ignore edges to neighboring nodes which have unsatisfied dependencies; // - for visited neighboring nodes, add their edge if it wasn't already present in the schedule, but do not //   recurse into the neighboring node; // - for unvisited neighboring nodes with satisfied dependencies, add their edge and recurse into them. visitedNodes . add ( startNode ) ; for ( Set < String > dependencies : remainingDependencies . values ( ) ) { dependencies . remove ( startNode . alias ) ; } Map < PatternEdge , Boolean > edges = new LinkedHashMap < PatternEdge , Boolean > ( ) ; for ( PatternEdge outEdge : startNode . out ) { edges . put ( outEdge , true ) ; } for ( PatternEdge inEdge : startNode . in ) { edges . put ( inEdge , false ) ; } for ( Map . Entry < PatternEdge , Boolean > edgeData : edges . entrySet ( ) ) { PatternEdge edge = edgeData . getKey ( ) ; boolean isOutbound = edgeData . getValue ( ) ; PatternNode neighboringNode = isOutbound ? edge . in : edge . out ; if ( ! remainingDependencies . get ( neighboringNode . alias ) . isEmpty ( ) ) { // Unsatisfied dependencies, ignore this neighboring node. continue ; } if ( visitedNodes . contains ( neighboringNode ) ) { if ( ! visitedEdges . contains ( edge ) ) { // If we are executing in this block, we are in the following situation: // - the startNode has not been visited yet; // - it has a neighboringNode that has already been visited; // - the edge between the startNode and the neighboringNode has not been scheduled yet. // // The isOutbound value shows us whether the edge is outbound from the point of view of the startNode. // However, if there are edges to the startNode, we must visit the startNode from an already-visited // neighbor, to preserve the validity of the traversal. Therefore, we negate the value of isOutbound // to ensure that the edge is always scheduled in the direction from the already-visited neighbor // toward the startNode. Notably, this is also the case when evaluating "optional" nodes -- we always // visit the optional node from its non-optional and already-visited neighbor. // // The only exception to the above is when we have edges with "while" conditions. We are not allowed // to flip their directionality, so we leave them as-is. boolean traversalDirection ; if ( startNode . optional || edge . item . isBidirectional ( ) ) { traversalDirection = ! isOutbound ; } else { traversalDirection = isOutbound ; } visitedEdges . add ( edge ) ; resultingSchedule . add ( new EdgeTraversal ( edge , traversalDirection ) ) ; } } else if ( ! startNode . optional ) { // If the neighboring node wasn't visited, we don't expand the optional node into it, hence the above check. // Instead, we'll allow the neighboring node to add the edge we failed to visit, via the above block. if ( visitedEdges . contains ( edge ) ) { // Should never happen. throw new AssertionError ( "The edge was visited, but the neighboring vertex was not: " + edge + " " + neighboringNode ) ; } visitedEdges . add ( edge ) ; resultingSchedule . add ( new EdgeTraversal ( edge , isOutbound ) ) ; updateScheduleStartingAt ( neighboringNode , visitedNodes , visitedEdges , remainingDependencies , resultingSchedule ) ; } } }


Input: sort edges in the order they will be matched [CODESPLIT] private List < EdgeTraversal > getTopologicalSortedSchedule ( Map < String , Long > estimatedRootEntries , Pattern pattern ) { List < EdgeTraversal > resultingSchedule = new ArrayList < EdgeTraversal > ( ) ; Map < String , Set < String > > remainingDependencies = getDependencies ( pattern ) ; Set < PatternNode > visitedNodes = new HashSet < PatternNode > ( ) ; Set < PatternEdge > visitedEdges = new HashSet < PatternEdge > ( ) ; // Sort the possible root vertices in order of estimated size, since we want to start with a small vertex set. List < OPair < Long , String > > rootWeights = new ArrayList < OPair < Long , String > > ( ) ; for ( Map . Entry < String , Long > root : estimatedRootEntries . entrySet ( ) ) { rootWeights . add ( new OPair < Long , String > ( root . getValue ( ) , root . getKey ( ) ) ) ; } Collections . sort ( rootWeights ) ; // Add the starting vertices, in the correct order, to an ordered set. Set < String > remainingStarts = new LinkedHashSet < String > ( ) ; for ( OPair < Long , String > item : rootWeights ) { remainingStarts . add ( item . getValue ( ) ) ; } // Add all the remaining aliases after all the suggested start points. for ( String alias : pattern . aliasToNode . keySet ( ) ) { if ( ! remainingStarts . contains ( alias ) ) { remainingStarts . add ( alias ) ; } } while ( resultingSchedule . size ( ) < pattern . numOfEdges ) { // Start a new depth-first pass, adding all nodes with satisfied dependencies. // 1. Find a starting vertex for the depth-first pass. PatternNode startingNode = null ; List < String > startsToRemove = new ArrayList < String > ( ) ; for ( String currentAlias : remainingStarts ) { PatternNode currentNode = pattern . aliasToNode . get ( currentAlias ) ; if ( visitedNodes . contains ( currentNode ) ) { // If a previous traversal already visited this alias, remove it from further consideration. startsToRemove . add ( currentAlias ) ; } else if ( remainingDependencies . get ( currentAlias ) . isEmpty ( ) ) { // If it hasn't been visited, and has all dependencies satisfied, visit it. startsToRemove . add ( currentAlias ) ; startingNode = currentNode ; break ; } } remainingStarts . removeAll ( startsToRemove ) ; if ( startingNode == null ) { // We didn't manage to find a valid root, and yet we haven't constructed a complete schedule. // This means there must be a cycle in our dependency graph, or all dependency-free nodes are optional. // Therefore, the query is invalid. throw new OCommandExecutionException ( "This query contains MATCH conditions that cannot be evaluated, " + "like an undefined alias or a circular dependency on a $matched condition." ) ; } // 2. Having found a starting vertex, traverse its neighbors depth-first, //    adding any non-visited ones with satisfied dependencies to our schedule. updateScheduleStartingAt ( startingNode , visitedNodes , visitedEdges , remainingDependencies , resultingSchedule ) ; } if ( resultingSchedule . size ( ) != pattern . numOfEdges ) { throw new AssertionError ( "Incorrect number of edges: " + resultingSchedule . size ( ) + " vs " + pattern . numOfEdges ) ; } return resultingSchedule ; }


Input: @param request @param ctx @param record [CODESPLIT] private boolean addSingleResult ( OSQLAsynchQuery < ODocument > request , OBasicCommandContext ctx , ORecord record ) { if ( ( ( OBasicCommandContext ) context ) . addToUniqueResult ( record ) ) { request . getResultListener ( ) . result ( record ) ; long currentCount = ctx . getResultsProcessed ( ) . incrementAndGet ( ) ; long limitValue = limitFromProtocol ; if ( limit != null ) { limitValue = limit . num . getValue ( ) . longValue ( ) ; } if ( limitValue > - 1 && limitValue <= currentCount ) { return false ; } } return true ; }


Input: } [CODESPLIT] private OSelectStatement buildSelectStatement ( String className , OWhereClause oWhereClause ) { OSelectStatement stm = new OSelectStatement ( - 1 ) ; stm . whereClause = oWhereClause ; stm . target = new OFromClause ( - 1 ) ; stm . target . item = new OFromItem ( - 1 ) ; stm . target . item . identifier = new OIdentifier ( className ) ; return stm ; }


Input: Compares if 2 field values are the same . [CODESPLIT] @ Override public boolean isEqual ( final OBinaryField iField1 , final OBinaryField iField2 ) { final BytesContainer fieldValue1 = iField1 . bytes ; final int offset1 = fieldValue1 . offset ; final BytesContainer fieldValue2 = iField2 . bytes ; final int offset2 = fieldValue2 . offset ; try { switch ( iField1 . type ) { case INTEGER : { final int value1 = OVarIntSerializer . readAsInteger ( fieldValue1 ) ; switch ( iField2 . type ) { case INTEGER : { final int value2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; return value1 == value2 ; } case LONG : case DATETIME : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; return value1 == value2 ; } case DATE : { final long value2 = ( OVarIntSerializer . readAsLong ( fieldValue2 ) * MILLISEC_PER_DAY ) ; return value1 == value2 ; } case SHORT : { final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return value1 == value2 ; } case BYTE : { final byte value2 = readByte ( fieldValue2 ) ; return value1 == value2 ; } case FLOAT : { final float value2 = Float . intBitsToFloat ( readInteger ( fieldValue2 ) ) ; return value1 == value2 ; } case DOUBLE : { final double value2 = Double . longBitsToDouble ( readLong ( fieldValue2 ) ) ; return value1 == value2 ; } case STRING : { return Integer . parseInt ( readString ( fieldValue2 ) ) == value1 ; } case DECIMAL : { final BigDecimal value2 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue2 . bytes , fieldValue2 . offset ) ; return value1 == value2 . intValue ( ) ; } } break ; } case LONG : { final long value1 = OVarIntSerializer . readAsLong ( fieldValue1 ) ; switch ( iField2 . type ) { case INTEGER : { final int value2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; return value1 == value2 ; } case LONG : case DATETIME : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; return value1 == value2 ; } case DATE : { final long value2 = ( OVarIntSerializer . readAsLong ( fieldValue2 ) * MILLISEC_PER_DAY ) ; return value1 == value2 ; } case SHORT : { final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return value1 == value2 ; } case BYTE : { final byte value2 = readByte ( fieldValue2 ) ; return value1 == value2 ; } case FLOAT : { final float value2 = Float . intBitsToFloat ( readInteger ( fieldValue2 ) ) ; return value1 == value2 ; } case DOUBLE : { final double value2 = Double . longBitsToDouble ( readLong ( fieldValue2 ) ) ; return value1 == value2 ; } case STRING : { return Long . parseLong ( readString ( fieldValue2 ) ) == value1 ; } case DECIMAL : { final BigDecimal value2 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue2 . bytes , fieldValue2 . offset ) ; return value1 == value2 . longValue ( ) ; } } break ; } case SHORT : { final short value1 = OVarIntSerializer . readAsShort ( fieldValue1 ) ; switch ( iField2 . type ) { case INTEGER : { final int value2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; return value1 == value2 ; } case LONG : case DATETIME : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; return value1 == value2 ; } case DATE : { final long value2 = ( OVarIntSerializer . readAsLong ( fieldValue2 ) * MILLISEC_PER_DAY ) ; return value1 == value2 ; } case SHORT : { final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return value1 == value2 ; } case BYTE : { final byte value2 = readByte ( fieldValue2 ) ; return value1 == value2 ; } case FLOAT : { final float value2 = Float . intBitsToFloat ( readInteger ( fieldValue2 ) ) ; return value1 == value2 ; } case DOUBLE : { final double value2 = Double . longBitsToDouble ( readLong ( fieldValue2 ) ) ; return value1 == value2 ; } case STRING : { return Short . parseShort ( readString ( fieldValue2 ) ) == value1 ; } case DECIMAL : { final BigDecimal value2 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue2 . bytes , fieldValue2 . offset ) ; return value1 == value2 . shortValue ( ) ; } } break ; } case STRING : { switch ( iField2 . type ) { case INTEGER : { final int value2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; return Integer . parseInt ( readString ( fieldValue1 ) ) == value2 ; } case LONG : case DATETIME : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; return Long . parseLong ( readString ( fieldValue1 ) ) == value2 ; } case DATE : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) * MILLISEC_PER_DAY ; return Long . parseLong ( readString ( fieldValue1 ) ) == value2 ; } case SHORT : { final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return Short . parseShort ( readString ( fieldValue1 ) ) == value2 ; } case BYTE : { final byte value2 = readByte ( fieldValue2 ) ; return Byte . parseByte ( readString ( fieldValue1 ) ) == value2 ; } case FLOAT : { final float value2 = Float . intBitsToFloat ( readInteger ( fieldValue2 ) ) ; return Float . parseFloat ( readString ( fieldValue1 ) ) == value2 ; } case DOUBLE : { final double value2 = Double . longBitsToDouble ( readLong ( fieldValue2 ) ) ; return Double . parseDouble ( readString ( fieldValue1 ) ) == value2 ; } case STRING : { final int len1 = OVarIntSerializer . readAsInteger ( fieldValue1 ) ; final int len2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; if ( len1 != len2 ) return false ; final OCollate collate = ( iField1 . collate != null && ! ODefaultCollate . NAME . equals ( iField1 . collate . getName ( ) ) ) ? iField1 . collate : ( iField2 . collate != null && ! ODefaultCollate . NAME . equals ( iField2 . collate . getName ( ) ) ? iField2 . collate : null ) ; if ( collate != null ) { final String str1 = ( String ) collate . transform ( stringFromBytes ( fieldValue1 . bytes , fieldValue1 . offset , len1 ) ) ; final String str2 = ( String ) collate . transform ( stringFromBytes ( fieldValue2 . bytes , fieldValue2 . offset , len2 ) ) ; return str1 . equals ( str2 ) ; } else { for ( int i = 0 ; i < len1 ; ++ i ) { if ( fieldValue1 . bytes [ fieldValue1 . offset + i ] != fieldValue2 . bytes [ fieldValue2 . offset + i ] ) return false ; } } return true ; } case DECIMAL : { final BigDecimal value2 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue2 . bytes , fieldValue2 . offset ) ; return new BigDecimal ( readString ( fieldValue1 ) ) . equals ( value2 ) ; } case BOOLEAN : { final boolean value2 = readByte ( fieldValue2 ) == 1 ; return Boolean . parseBoolean ( readString ( fieldValue1 ) ) == value2 ; } } break ; } case DOUBLE : { final long value1AsLong = readLong ( fieldValue1 ) ; switch ( iField2 . type ) { case INTEGER : { final double value1 = Double . longBitsToDouble ( value1AsLong ) ; final int value2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; return value1 == value2 ; } case LONG : case DATETIME : { final double value1 = Double . longBitsToDouble ( value1AsLong ) ; final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; return value1 == value2 ; } case SHORT : { final double value1 = Double . longBitsToDouble ( value1AsLong ) ; final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return value1 == value2 ; } case BYTE : { final double value1 = Double . longBitsToDouble ( value1AsLong ) ; final byte value2 = readByte ( fieldValue2 ) ; return value1 == value2 ; } case FLOAT : { final double value1 = Double . longBitsToDouble ( value1AsLong ) ; final float value2 = Float . intBitsToFloat ( readInteger ( fieldValue2 ) ) ; return value1 == value2 ; } case DOUBLE : { final double value2AsLong = readLong ( fieldValue2 ) ; return value1AsLong == value2AsLong ; } case STRING : { final double value1 = Double . longBitsToDouble ( value1AsLong ) ; return Double . parseDouble ( readString ( fieldValue2 ) ) == value1 ; } case DECIMAL : { final double value1 = Double . longBitsToDouble ( value1AsLong ) ; final BigDecimal value2 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue2 . bytes , fieldValue2 . offset ) ; return value1 == value2 . doubleValue ( ) ; } } break ; } case FLOAT : { final int value1AsInt = readInteger ( fieldValue1 ) ; switch ( iField2 . type ) { case INTEGER : { final float value1 = Float . intBitsToFloat ( value1AsInt ) ; final int value2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; return value1 == value2 ; } case LONG : case DATETIME : { final float value1 = Float . intBitsToFloat ( value1AsInt ) ; final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; return value1 == value2 ; } case SHORT : { final float value1 = Float . intBitsToFloat ( value1AsInt ) ; final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return value1 == value2 ; } case BYTE : { final float value1 = Float . intBitsToFloat ( value1AsInt ) ; final byte value2 = readByte ( fieldValue2 ) ; return value1 == value2 ; } case FLOAT : { final float value2AsInt = readInteger ( fieldValue2 ) ; return value1AsInt == value2AsInt ; } case DOUBLE : { final float value1 = Float . intBitsToFloat ( value1AsInt ) ; final double value2 = Double . longBitsToDouble ( readLong ( fieldValue2 ) ) ; return value1 == value2 ; } case STRING : { final float value1 = Float . intBitsToFloat ( value1AsInt ) ; return Float . parseFloat ( readString ( fieldValue2 ) ) == value1 ; } case DECIMAL : { final float value1 = Float . intBitsToFloat ( value1AsInt ) ; final BigDecimal value2 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue2 . bytes , fieldValue2 . offset ) ; return value1 == value2 . floatValue ( ) ; } } break ; } case BYTE : { final byte value1 = readByte ( fieldValue1 ) ; switch ( iField2 . type ) { case INTEGER : { final int value2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; return value1 == value2 ; } case LONG : case DATETIME : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; return value1 == value2 ; } case SHORT : { final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return value1 == value2 ; } case BYTE : { final byte value2 = readByte ( fieldValue2 ) ; return value1 == value2 ; } case FLOAT : { final float value2 = Float . intBitsToFloat ( readInteger ( fieldValue2 ) ) ; return value1 == value2 ; } case DOUBLE : { final double value2 = Double . longBitsToDouble ( readLong ( fieldValue2 ) ) ; return value1 == value2 ; } case STRING : { final byte value2 = Byte . parseByte ( ( readString ( fieldValue2 ) ) ) ; return value1 == value2 ; } case DECIMAL : { final BigDecimal value2 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue2 . bytes , fieldValue2 . offset ) ; return value1 == value2 . byteValue ( ) ; } } break ; } case BOOLEAN : { final boolean value1 = readByte ( fieldValue1 ) == 1 ; switch ( iField2 . type ) { case BOOLEAN : { final boolean value2 = readByte ( fieldValue2 ) == 1 ; return value1 == value2 ; } case STRING : { final String str = readString ( fieldValue2 ) ; return Boolean . parseBoolean ( str ) == value1 ; } } 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 ; } case LONG : case DATETIME : { long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; value2 = convertDayToTimezone ( ODateHelper . getDatabaseTimeZone ( ) , TimeZone . getTimeZone ( "GMT" ) , value2 ) ; return value1 == value2 ; } case DATE : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) * MILLISEC_PER_DAY ; return value1 == value2 ; } case SHORT : { final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return value1 == value2 ; } case FLOAT : { final float value2 = Float . intBitsToFloat ( readInteger ( fieldValue2 ) ) ; return value1 == value2 ; } case DOUBLE : { final double value2 = Double . longBitsToDouble ( readLong ( fieldValue2 ) ) ; return value1 == value2 ; } case STRING : { } case DECIMAL : { final BigDecimal value2 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue2 . bytes , fieldValue2 . offset ) ; return value1 == value2 . longValue ( ) ; } } break ; } case DATETIME : { final long value1 = OVarIntSerializer . readAsLong ( fieldValue1 ) ; switch ( iField2 . type ) { case INTEGER : { final int value2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; return value1 == value2 ; } case LONG : case DATETIME : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; return value1 == value2 ; } case DATE : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) * MILLISEC_PER_DAY ; return value1 == value2 ; } case SHORT : { final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return value1 == value2 ; } case FLOAT : { final float value2 = Float . intBitsToFloat ( readInteger ( fieldValue2 ) ) ; return value1 == value2 ; } case DOUBLE : { final double value2 = Double . longBitsToDouble ( readLong ( fieldValue2 ) ) ; return value1 == value2 ; } case STRING : { final String value2AsString = readString ( fieldValue2 ) ; if ( OIOUtils . isLong ( value2AsString ) ) { final long value2 = Long . parseLong ( value2AsString ) ; return value1 == value2 ; } final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal . instance ( ) . getIfDefined ( ) ; try { final SimpleDateFormat dateFormat = db != null ? db . getStorage ( ) . getConfiguration ( ) . getDateTimeFormatInstance ( ) : new SimpleDateFormat ( OStorageConfiguration . DEFAULT_DATETIME_FORMAT ) ; final Date value2AsDate = dateFormat . parse ( value2AsString ) ; final long value2 = value2AsDate . getTime ( ) ; return value1 == value2 ; } catch ( ParseException ignore ) { try { final SimpleDateFormat dateFormat = db != null ? db . getStorage ( ) . getConfiguration ( ) . getDateFormatInstance ( ) : new SimpleDateFormat ( OStorageConfiguration . DEFAULT_DATE_FORMAT ) ; final Date value2AsDate = dateFormat . parse ( value2AsString ) ; final long value2 = value2AsDate . getTime ( ) ; return value1 == value2 ; } catch ( ParseException ignored ) { return new Date ( value1 ) . toString ( ) . equals ( value2AsString ) ; } } } case DECIMAL : { final BigDecimal value2 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue2 . bytes , fieldValue2 . offset ) ; return value1 == value2 . longValue ( ) ; } } break ; } case BINARY : { switch ( iField2 . type ) { case BINARY : { final int length1 = OVarIntSerializer . readAsInteger ( fieldValue1 ) ; final int length2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; if ( length1 != length2 ) return false ; for ( int i = 0 ; i < length1 ; ++ i ) { if ( fieldValue1 . bytes [ fieldValue1 . offset + i ] != fieldValue2 . bytes [ fieldValue2 . offset + i ] ) return false ; } return true ; } } break ; } case LINK : { switch ( iField2 . type ) { case LINK : { final int clusterId1 = OVarIntSerializer . readAsInteger ( fieldValue1 ) ; final int clusterId2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; if ( clusterId1 != clusterId2 ) return false ; final long clusterPos1 = OVarIntSerializer . readAsLong ( fieldValue1 ) ; final long clusterPos2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; if ( clusterPos1 == clusterPos2 ) return true ; break ; } case STRING : { return readOptimizedLink ( fieldValue1 , false ) . toString ( ) . equals ( 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 . equals ( new BigDecimal ( value2 ) ) ; } case LONG : case DATETIME : { final long value2 = OVarIntSerializer . readAsLong ( fieldValue2 ) ; return value1 . equals ( new BigDecimal ( value2 ) ) ; } case SHORT : { final short value2 = OVarIntSerializer . readAsShort ( fieldValue2 ) ; return value1 . equals ( new BigDecimal ( value2 ) ) ; } case FLOAT : { final float value2 = Float . intBitsToFloat ( readInteger ( fieldValue2 ) ) ; return value1 . equals ( new BigDecimal ( value2 ) ) ; } case DOUBLE : { final double value2 = Double . longBitsToDouble ( readLong ( fieldValue2 ) ) ; return value1 . equals ( new BigDecimal ( value2 ) ) ; } case STRING : { return value1 . toString ( ) . equals ( readString ( fieldValue2 ) ) ; } case DECIMAL : { final BigDecimal value2 = ODecimalSerializer . INSTANCE . deserialize ( fieldValue2 . bytes , fieldValue2 . offset ) ; return value1 . equals ( value2 ) ; } } break ; } } } finally { fieldValue1 . offset = offset1 ; fieldValue2 . offset = offset2 ; } return false ; }


Input: Compares two values executing also conversion between types . [CODESPLIT] @ Override public int compare ( final OBinaryField iField1 , final OBinaryField iField2 ) { final BytesContainer fieldValue1 = iField1 . bytes ; final int offset1 = fieldValue1 . offset ; final BytesContainer fieldValue2 = iField2 . bytes ; final int offset2 = fieldValue2 . offset ; try { switch ( iField1 . type ) { case INTEGER : { final int value1 = OVarIntSerializer . readAsInteger ( fieldValue1 ) ; switch ( iField2 . type ) { case INTEGER : { final int value2 = OVarIntSerializer . readAsInteger ( fieldValue2 ) ; return ( value1 < value2 ) ? - 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 ; }


Input: Add new indexDefinition in current composite . [CODESPLIT] public void addIndex ( final OIndexDefinition indexDefinition ) { 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 ( ) ) ; }


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


Input:
{ [CODESPLIT] public Object getDocumentValueToIndex ( final ODocument iDocument ) { 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 ; }


Input: { [CODESPLIT] public Object createValue ( final Object ... params ) { if ( params . length == 1 && params [ 0 ] instanceof Collection ) return params [ 0 ] ; return createValue ( Arrays . asList ( params ) ) ; }


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


Input: { [CODESPLIT] @ Override public ODocument toStream ( ) { document . setInternalStatus ( ORecordElement . STATUS . UNMARSHALLING ) ; try { serializeToStream ( ) ; } finally { document . setInternalStatus ( ORecordElement . STATUS . LOADED ) ; } return document ; }


Input: { [CODESPLIT] public String toCreateIndexDDL ( final String indexName , final String indexType , String engine ) { 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 ( ) ; }


Input: Execute the command . [CODESPLIT] public Object execute ( final Map < Object , Object > iArgs ) { 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 ; }


Input: INTERNAL USE ONLY this has to be invoked ONLY if the item is aggregate!!! [CODESPLIT] public OProjectionItem splitForAggregation ( AggregateProjectionSplit aggregateSplit , OCommandContext ctx ) { if ( isAggregate ( ) ) { OProjectionItem result = new OProjectionItem ( - 1 ) ; result . alias = getProjectionAlias ( ) ; result . expression = expression . splitForAggregation ( aggregateSplit , ctx ) ; result . nestedProjection = nestedProjection ; return result ; } else { return this ; } }


Input: choosing return type is based on existence of [CODESPLIT] public Object toObjectDetermineType ( OResult source , OCommandContext ctx ) { 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 ) ; } }


Input: 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 . [CODESPLIT] public boolean isFieldChain ( ) { if ( operationsChain == null ) { return true ; } for ( OPair < OSQLMethodRuntime , Object [ ] > pair : operationsChain ) { if ( ! pair . getKey ( ) . getMethod ( ) . getName ( ) . equals ( OSQLMethodField . NAME ) ) { return false ; } } return true ; }


Input: get the collate of this expression based on the fully evaluated field chain starting from the passed object . [CODESPLIT] public OCollate getCollate ( Object doc ) { 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 ( ) ; }


Input: returns the plain string representation of this identifier with quoting removed from back - ticks [CODESPLIT] public String getStringValue ( ) { if ( value == null ) { return null ; } if ( value . contains ( "`" ) ) { return value . replaceAll ( "\\\\`" , "`" ) ; } return value ; }


Input: 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 [CODESPLIT] private void setStringValue ( String s ) { if ( s == null ) { value = null ; } else if ( s . contains ( "`" ) ) { value = s . replaceAll ( "`" , "\\\\`" ) ; } else { value = s ; } }


Input: Pseudo - randomly advances and records the given probe value for the given thread . [CODESPLIT] private int advanceProbe ( int probe ) { probe ^= probe << 13 ; // xorshift probe ^= probe >>> 17 ; probe ^= probe << 5 ; this . probe . get ( ) . set ( probe ) ; return probe ; }


Input: 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 [CODESPLIT] @ Override public void commit ( final boolean force ) { 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." ) ; }


Input:
Execute the DROP CLUSTER . [CODESPLIT] public Object execute ( final Map < Object , Object > iArgs ) { 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 ; }


Input: It returns a ODocument starting from a json file . [CODESPLIT] public static ODocument buildJsonFromFile ( String filePath ) throws IOException { 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 ; }


Input:
Execute the command and return the ODocument object created . [CODESPLIT] public Object execute ( final Map < Object , Object > iArgs ) { 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 ; }


Input: Delete the current vertex . [CODESPLIT] public boolean result ( final Object iRecord ) { 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 ; }


Input: Parses the returning keyword if found . [CODESPLIT] protected String parseReturn ( ) throws OCommandSQLParsingException { 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 ; }


Input:
Checks if an hash string matches a password based on the algorithm found on hash string . [CODESPLIT] public boolean checkPassword ( final String iPassword , final String iHash ) { 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 ) ) ; }


Input: Hashes the input string . [CODESPLIT] public String createHash ( final String iInput , final String iAlgorithm , final boolean iIncludeAlgorithm ) { 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 ( ) ; }


Input:
Returns true if the algorithm is supported by the current version of Java [CODESPLIT] private static boolean isAlgorithmSupported ( final String algorithm ) { // 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 ; }


Input: Creates the index . [CODESPLIT] public OIndexInternal < ? > create ( final OIndexDefinition indexDefinition , final String clusterIndexName , final Set < String > clustersToIndex , boolean rebuild , final OProgressListener progressListener , final OBinarySerializer valueSerializer ) { 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 ; }


Input: { [CODESPLIT] public long rebuild ( final OProgressListener iProgressListener ) { 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 ; }


Input: ( 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 . [CODESPLIT] public Query order ( final String props , final String dir ) { this . orderBy = props ; this . orderByDir = dir ; return this ; }


Input: Returns the result set of the query as iterable vertices . [CODESPLIT] @ Override public Iterable < Vertex > vertices ( ) { 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 ( ) ) ) ; }


Input: Returns the result set of the query as iterable edges . [CODESPLIT] @ Override public Iterable < Edge > edges ( ) { 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 ( ) ) ) ; }


Input: Return the partition keys of all the sub - tasks . [CODESPLIT] @ Override public int [ ] getPartitionKey ( ) { 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 ; }


Input: Computes the timeout according to the transaction size . [CODESPLIT] @ Override public long getDistributedTimeout ( ) { final long to = OGlobalConfiguration . DISTRIBUTED_CRUD_TASK_SYNCH_TIMEOUT . getValueAsLong ( ) ; return to + ( ( to / 2 ) * tasks . size ( ) ) ; }


Input: { @inheritDoc } [CODESPLIT] public String toCreateIndexDDL ( final String indexName , final String indexType , final String engine ) { 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 ( ) ; }


Input: Added version used for managed Network Versioning . [CODESPLIT] public byte [ ] toStream ( final int iNetworkVersion , final Charset charset ) throws OSerializationException { 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 ( ) ; } }


Input: Returns the current Graph settings . [CODESPLIT] public Features getFeatures ( ) { 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 ; }


Input: Removes the Edge from the Graph . Connected vertices aren t removed . [CODESPLIT] public void removeEdgeInternal ( final OrientEdge edge ) { // 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 ( ) ; }


Input: Execute the CREATE LINK . [CODESPLIT] private Object execute ( OCommandContext ctx ) { 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 ; }


Input: This check if a file was trimmed or trunked in the current atomic operation . [CODESPLIT] private static boolean checkChangesFilledUpTo ( final FileChanges changesContainer , final long pageIndex ) { if ( changesContainer == null ) { return true ; } else if ( changesContainer . isNew || changesContainer . maxNewPageIndex > - 2 ) { return pageIndex < changesContainer . maxNewPageIndex + 1 ; } else return ! changesContainer . truncate ; }


Input: { [CODESPLIT] @ Override public OClass truncateCluster ( String clusterName ) { 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 ; }


Input: Parses the timeout keyword if found . [CODESPLIT] protected boolean parseTimeout ( final String w ) throws OCommandSQLParsingException { 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 ; }


Input: Parses the lock keyword if found . [CODESPLIT] protected String parseLock ( ) throws OCommandSQLParsingException { 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 ; }


Input: TODO check PGIS [CODESPLIT] @ Override public OSpatialQueryContext build ( Map < String , Object > query ) throws Exception { 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 ) ; }


Input: Execute the ALTER DATABASE . [CODESPLIT] public Object execute ( final Map < Object , Object > iArgs ) { final StringBuilder result = new StringBuilder ( ) ; if ( optimizeEdges ) result . append ( optimizeEdges ( ) ) ; return result . toString ( ) ; }


Input:
Execute the command and return the ODocument object created . [CODESPLIT] public Object execute ( final Map < Object , Object > iArgs ) { 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 ; }


Input:
Delete the current edge . [CODESPLIT] public boolean result ( final Object iRecord ) { 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 ; }


Input:
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 . [CODESPLIT] public OIndexSearchResult merge ( final OIndexSearchResult searchResult ) { // 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 ) ; }


Input:
Execute the command . [CODESPLIT] public Object execute ( final Map < Object , Object > iArgs ) { 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 ; }


Input: Obtains the value stored under the given entry index in this bucket . [CODESPLIT] List < ORID > getValues ( final int entryIndex ) { 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 ; }