Move the position of the record.
@param iRelPosition The positions to move.
@return The record at this position.
@see moveTableQuery.
@exception DBException File exception.
492599
public FieldList move(int iRelPosition) throws DBException
    {
        Record record = ((QueryRecord)m_record).moveTableQuery(iRelPosition);
        if (record != null)
            return (QueryRecord)m_record;
        else
            return null;
    }
694727
public int doMove(int iRelPosition) throws DBException
    {
        this.checkCacheMode(Boolean.TRUE);      // Make sure the cache is set up correctly for this type of query (typically needed)
        int iErrorCode = DBConstants.NORMAL_RETURN;
        try   {
            Object objData = null;
            synchronized (this.getSyncObject())
            {   // In case this is called from another task
                objData = m_tableRemote.doMove(iRelPosition, 1);
            }
            if (objData instanceof Vector)
            {
                Vector<Object> data = (Vector)objData;  //m_tableRemote.dataToFields();
                Record recordBase = this.getRecord();
                int iFieldTypes = BaseBuffer.PHYSICAL_FIELDS;
                if (!recordBase.isAllSelected())
                    iFieldTypes = BaseBuffer.DATA_FIELDS; // SELECTED_FIELDS; (selected and physical)
                BaseBuffer buffer = new VectorBuffer(data, iFieldTypes);
                if (DBParams.RECORD.equals(buffer.getHeader()))
                { // Warning: The target record was a multitable and This is the record name!
                    String strTableNames = buffer.getHeader().toString();
                    Utility.getLogger().warning("ClientTable.doMove() - Warning: Multitable needs to be specified: " + strTableNames);
                }
                else
                    buffer.resetPosition();
                m_dataSource = buffer;
                iErrorCode = DBConstants.NORMAL_RETURN;
            }
            else if (objData instanceof Number)
                iErrorCode = ((Number)objData).intValue();
            else
                iErrorCode = DBConstants.ERROR_RETURN;  // Never
            return iErrorCode;
        } catch (Exception ex) {
            ex.printStackTrace();
            throw DatabaseException.toDatabaseException(ex);
        }
    }
1087045
public void savePosition() {
		RecordId rid1 = s1.getRecordId();
		RecordId rid2 = (s2 == null) ? null : s2.getRecordId();
		savedPosition = Arrays.asList(rid1, rid2);
	}
102060
public void addPhysicalPosition(final OPhysicalPosition iPPosition) throws IOException {
    final long[] pos;
    final boolean recycled;
    long offset;

    acquireExclusiveLock();
    try {

      offset = holeSegment.popLastEntryPosition();
      if (offset > -1) {
        // REUSE THE HOLE
        pos = fileSegment.getRelativePosition(offset);
        recycled = true;
      } else {
        // NO HOLES FOUND: ALLOCATE MORE SPACE
        pos = allocateRecord();
        offset = fileSegment.getAbsolutePosition(pos);
        recycled = false;
      }

      final OFile file = fileSegment.files[(int) pos[0]];
      long p = pos[1];

      file.writeShort(p, (short) iPPosition.dataSegmentId);
      file.writeLong(p += OBinaryProtocol.SIZE_SHORT, iPPosition.dataSegmentPos);
      file.writeByte(p += OBinaryProtocol.SIZE_LONG, iPPosition.recordType);

      if (recycled)
        // GET LAST VERSION
        iPPosition.recordVersion = file.readInt(p + OBinaryProtocol.SIZE_BYTE) * -1;
      else
        iPPosition.recordVersion = 0;

      file.writeInt(p + OBinaryProtocol.SIZE_BYTE, iPPosition.recordVersion);

      iPPosition.clusterPosition = offset / RECORD_SIZE;

      updateBoundsAfterInsertion(iPPosition.clusterPosition);

    } finally {
      releaseExclusiveLock();
    }
  }
1104913
public Object elementAt(int iTargetPosition)
    {
        Record record = null;
        Object bookmark = null;
        if (m_iEndOfFileIndex != UNKNOWN_POSITION) if (iTargetPosition >= m_iEndOfFileIndex)
            return null;    // Past/At EOF
        if (!m_gridBuffer.inBufferList(iTargetPosition))
        {
            bookmark = m_gridList.elementAt(iTargetPosition);
            if (bookmark != null)
                return bookmark;    // In grid list, return it!
            // Find the next lower item in the list
            int iLowestNonNullIndex = this.lowestNonNullIndex(iTargetPosition);
            if (iLowestNonNullIndex != -1)
            {
                bookmark = m_gridList.elementAt(iLowestNonNullIndex);
                if (bookmark == null)
                    bookmark = m_gridBuffer.elementAt(iLowestNonNullIndex);
            }
            
            boolean bFindTargetUsingCurrentQuery = false;
            if (bookmark == null)
                bFindTargetUsingCurrentQuery = true;
            else
            {
                if (iTargetPosition == m_iPhysicalFilePosition + 1)
                    if (m_bIsSequentialQueryValid)
                        bFindTargetUsingCurrentQuery = true;
            }

            if (!bFindTargetUsingCurrentQuery)
            { // This record is not in the grid list, because the granularity is too great
                // Read the record before it, and move forward.
                // Move to > bookmark, and move next until you hit this target.
                this.getNextTable().setDataRecord((DataRecord)bookmark);
                record = this.getRecord();
                if (m_behCompare != null)
                    record.removeListener(m_behCompare, true);
                m_behCompare = new SubCurrentFilter(true, false);
                m_behCompare.setMasterSlaveFlag(RecordOwner.MASTER | RecordOwner.SLAVE);    // Should run in either space
                record.addListener(m_behCompare);
                this.getNextTable().close();
                this.getRecord().setOpenMode(this.getRecord().getOpenMode() | DBConstants.OPEN_SUPPRESS_MESSAGES);   // Don't send an "AFTER_REQUERY_TYPE" message
                try   {
                    m_iPhysicalFilePosition = iLowestNonNullIndex - 1;
                    m_bIsSequentialQueryValid = true;
                    record = (Record)this.move(+1);
                    m_iPhysicalFilePosition = iLowestNonNullIndex;
                } catch (DBException e)   {
                    record = null;
                } finally {
                    this.getRecord().setOpenMode(this.getRecord().getOpenMode() & ~DBConstants.OPEN_SUPPRESS_MESSAGES);
                }
                if (record == null) if (m_behCompare != null)
                {
                    this.getRecord().removeListener(m_behCompare, true);
                    m_behCompare = null;
                }
            }

            try   {
                int iCurrentPosition = m_iPhysicalFilePosition;
                if (iCurrentPosition == -1)
                {
                    for (iCurrentPosition = 0; ; iCurrentPosition++)
                    {       // Find the first non-deleted record
                        if ((!m_gridBuffer.inBufferList(iCurrentPosition))
                            || (m_gridBuffer.elementAt(iCurrentPosition) != null))
                                break;
                    }
                    record = (Record)this.move(DBConstants.FIRST_RECORD);
                    if (record != null)
                    {
                        if (iCurrentPosition != 0)
                        {
                            bookmark = m_gridList.elementAt(0);
                            if (bookmark == null)
                                bookmark = m_gridBuffer.elementAt(0);
                            m_gridBuffer.addElement(0, null, m_gridList);   // Set this as deleted again
                            m_gridBuffer.addElement(iCurrentPosition, bookmark, m_gridList);   // Set this in the right logical position
                            m_iPhysicalFilePosition = iCurrentPosition;
                        }
                    }
                    else
                    {
                        iTargetPosition = 0;    // Make sure current position = 0!
                        m_iEndOfFileIndex = 0;  // EOF + 1
                    }
                }
                int iMoveRelative = iTargetPosition - iCurrentPosition;
                if (iMoveRelative < 0)
                    record = (Record)this.move(iMoveRelative);
                else
                {
                    while (iMoveRelative > 0)
                    {
                        if ((m_gridBuffer.inBufferList(m_iPhysicalFilePosition + 1))
                            && (m_gridBuffer.elementAt(m_iPhysicalFilePosition + 1) == null))
                        {
                            m_iPhysicalFilePosition++;  // This record shows deleted, don't fill with a record.
                        }
                        else
                        {
                            record = (Record)this.move(+1);
                            if (record == null)
                                break;
                        }
                        iMoveRelative--;
                    }
                }
                m_bIsSequentialQueryValid = true; // The query is in force, you may use move(+1) next time (instead of starting a new query)
            } catch (DBException ex)    {
                ex.printStackTrace();
                record = null;
            }
            m_iPhysicalFilePosition = iTargetPosition;
            if (m_behCompare != null)
            {
                this.getRecord().removeListener(m_behCompare, true);
                m_behCompare = null;
            }
            if (record == null)
                return null;
        }
        if (m_gridBuffer.inBufferList(iTargetPosition))
            bookmark = m_gridBuffer.elementAt(iTargetPosition);
        else
            bookmark = m_gridList.elementAt(iTargetPosition);
        return bookmark;
    }
1244754
public Record moveRecordToBase(Record record)
    {
        SharedBaseRecordTable sharedTable = this.getSharedTable();
        sharedTable.setCurrentRecord(record);
        boolean bCopyEditMode = false;
        boolean bOnlyModifiedFields = false;
        Record recBase = sharedTable.getBaseRecord();
        sharedTable.copyRecordInfo(recBase, record, bCopyEditMode, bOnlyModifiedFields);
        return recBase;
    }
763223
public boolean removeEntryWithPosition(final long iPosition) throws IOException {
    // BROWSE IN ASCENDING ORDER UNTIL THE REQUESTED POSITION IS FOUND
    boolean canShrink = true;
    for (int pos = getHoles() - 1; pos >= 0; --pos) {
      final long recycledPosition = file.readLong(pos * RECORD_SIZE);

      if (recycledPosition == iPosition) {
        if (OLogManager.instance().isDebugEnabled())
          OLogManager.instance().debug(this, "Removing hole #%d containing the position #%d:%d", pos, owner.getId(),
              recycledPosition);

        file.writeLong(pos * RECORD_SIZE, -1);
        if (canShrink)
          // SHRINK THE FILE
          file.removeTail((getHoles() - pos) * RECORD_SIZE);

        return true;

      } else if (iPosition != -1)
        // NO NULL ENTRY: CAN'T SHRINK WITHOUT LOST OF ENTRIES
        canShrink = false;
    }
    return false;
  }
1339472
public boolean moveFields(Record recSource, ResourceBundle resource, boolean bDisplayOption, int iMoveMode, boolean bAllowFieldChange, boolean bOnlyModifiedFields, boolean bMoveModifiedState, boolean syncSelection)
    {
        boolean bFieldsMoved = false;
        for (int iFieldSeq = 0; iFieldSeq < this.getFieldCount(); iFieldSeq++)
        {
            BaseField fldDest = this.getField(iFieldSeq);
            BaseField fldSource = null;
            try   {
                if (resource == Record.MOVE_BY_NAME)
                {
                    String strSourceField = fldDest.getFieldName();
                    fldSource = recSource.getField(strSourceField);
                }
                else if (resource != null)
                {
                    String strSourceField = resource.getString(fldDest.getFieldName());    // Lookup source field name from dest
                    if ((strSourceField != null) && (strSourceField.length() > 0))
                        fldSource = recSource.getField(strSourceField);
                }
                else // if (resource == null)
                {
                    fldSource = recSource.getField(iFieldSeq);
                }
            } catch (MissingResourceException ex) {
                fldSource = null;
            }
            if (fldSource != null)
            {
                if ((!bOnlyModifiedFields) || (fldSource.isModified()))
                {
                    boolean[] rgbEnabled = null;
                    if (bAllowFieldChange == false)    // Don't enable a disabled field listener
                        rgbEnabled = fldDest.setEnableListeners(bAllowFieldChange);                  // Don't call the HandleFieldChanged beh until ALL inited!
                    
                    FieldDataScratchHandler listenerScratchData = null;
                    if ((bAllowFieldChange == false) && (bMoveModifiedState))
                    	if (iMoveMode == DBConstants.READ_MOVE)	// Very obscure - Make sure this fake read move does not change the scratch area
                    		if (fldDest.getNextValidListener(iMoveMode) instanceof FieldDataScratchHandler)	// Always enable would have to be true since listeners have been disabled
                    			(listenerScratchData = ((FieldDataScratchHandler)fldDest.getNextValidListener(iMoveMode))).setAlwaysEnabled(false);

                    fldDest.moveFieldToThis(fldSource, bDisplayOption, iMoveMode);
                    
                    if (listenerScratchData != null)
                    	listenerScratchData.setAlwaysEnabled(true);
                    
                    if (rgbEnabled != null)
                        fldDest.setEnableListeners(rgbEnabled);
                    if (bAllowFieldChange == false)
                        fldDest.setModified(false); // At this point, no changes have been done
                    bFieldsMoved = true;
                }
                if ((bAllowFieldChange) || (bMoveModifiedState))
                    fldDest.setModified(fldSource.isModified()); // If you allow field change set if source is modified.
                if (syncSelection)
                    fldDest.setSelected(fldSource.isSelected());
            }
        }
        return bFieldsMoved;
    }
366952
public int readNextToTarget(int iTargetPosition, int iRelPosition) throws DBException
    {
        int iRecordStatus = DBConstants.RECORD_NORMAL;
        boolean bMore = true;
        ResultSet resultSet = (ResultSet)this.getResultSet();
        while (m_iRow < iTargetPosition)
        {   // Spin until you get to the row or hit EOF
            try   {
                bMore = resultSet.next();
                if (!bMore)
                {
                    m_iEOFRow = m_iRow;   // Last physical row = this row - 1.
                    break;  // Hit EOF
                }
                m_iRow++; // Current row
            } catch (SQLException e)    {
                DBException dbEx = this.getDatabase().convertError(e);
                int iErrorCode = dbEx.getErrorCode();
                if ((iRelPosition == DBConstants.FIRST_RECORD) || ((iRelPosition == DBConstants.LAST_RECORD)))
                    if (iErrorCode == DBConstants.INVALID_RECORD)
                        return (DBConstants.RECORD_INVALID | DBConstants.RECORD_AT_BOF | DBConstants.RECORD_AT_EOF);    // Move first - no records
                throw dbEx;
            }
        }
        if ((m_iRow == -1) || (iTargetPosition == -1))
            iRecordStatus |= DBConstants.RECORD_INVALID | DBConstants.RECORD_AT_BOF;
        if (!bMore)
        {
            iRecordStatus |= DBConstants.RECORD_AT_EOF;
            int iEOFRow = m_iEOFRow;   // Save for a sec
            this.setResultSet(null, DBConstants.SQL_SELECT_TYPE);  // Can't use anymore
            m_iEOFRow = iEOFRow;       // I do know the EOF
        }
        return iRecordStatus;
    }
311406
public FieldList move(int iRelPosition) throws DBException
    {
        Record record = (Record)super.move(iRelPosition);
        Iterator<BaseTable> iterator = this.getTables();
        while (iterator.hasNext())
        {
            BaseTable table = iterator.next();
            if ((table != null) && (table != this.getNextTable()))
                this.syncTables(table, record);
        }
        return record;
    }
1018355
public ODatabaseRecord delete(final ORID iRecord) {
    executeDeleteRecord(iRecord, -1, true, true, OPERATION_MODE.SYNCHRONOUS);
    return this;
  }
1350266
@Override
    protected boolean moveCursor() throws SQLException, OntopConnectionException {
        boolean foundFreshRow;
        List<Object> currentKey;
        do{
           foundFreshRow = rs.next();
           // Cannot use this in the while condition: limit case where the last row was a duplicate
           if(!foundFreshRow) {
               break;
           }
           currentKey = computeRowKey(rs);
        } while(!rowKeys.add(currentKey));

        return foundFreshRow;
    }
1226817
public void moveSQLToField(ResultSet resultset, int iColumn) throws SQLException
    {
        int sResult = resultset.getInt(iColumn);
        if (resultset.wasNull())
            this.setString(Constants.BLANK, false, DBConstants.READ_MOVE);  // Null value
        else
        {
            if ((!this.isNullable()) && (sResult == NAN))
                this.setString(Constants.BLANK, false, DBConstants.READ_MOVE);  // Null value
            else
                this.setValue(sResult, false, DBConstants.READ_MOVE);
        }
    }
739799
public boolean doHasNext() throws DBException
    {
        if ((m_iRecordStatus & DBConstants.RECORD_AT_EOF) != 0)
            return false; // Already at EOF, can't be one after
        if ((m_iRecordStatus & DBConstants.RECORD_NEXT_PENDING) != 0)
            return true;    // Already one waiting
        boolean bAtEOF = true;
        if (!this.isOpen())
            this.open();    // Make sure any listeners are called before disabling.
        Object[] rgobjEnabledFields = this.getRecord().setEnableNonFilter(null, false, false, false, false, true);
        FieldList record = null;
        try {
            record = this.move(DBConstants.NEXT_RECORD);
            if (record == null)
                bAtEOF = true;
            else if ((m_iRecordStatus & DBConstants.RECORD_AT_EOF) != 0)
                bAtEOF = true;
            else if (this.isTable())
                bAtEOF = this.isEOF();
            else
                bAtEOF = false;     // Valid record!
        } catch (DBException ex) {
            throw ex;
        } finally {
            this.getRecord().setEnableNonFilter(rgobjEnabledFields, false, false, false, bAtEOF, true);
        }
        if (bAtEOF)
            return false; // Does not have a next record
        m_iRecordStatus |= DBConstants.RECORD_NEXT_PENDING;     // If next call is a moveNext(), return unchanged!
        return true;        // Yes, a next record exists.
    }
1027195
public int dataToFields(Rec record) throws DBException
    {
        m_iColumn = 1;
        int iErrorCode = super.dataToFields(record);

        KeyArea keyArea = this.getRecord().getKeyArea(0); // Primary index
        keyArea.setupKeyBuffer(null, DBConstants.TEMP_KEY_AREA);        // Save keys for possible update/delete
        if (this.getResultSetType() != DBConstants.SQL_SELECT_TYPE)
            if (CLEANUP_STATEMENTS)
                this.setResultSet(null, this.getResultSetType());  // Close this statement

        return iErrorCode;
    }
1135086
def move_to_position(
        cls,
        resource_id,
        to_position,
        new_parent_id=noop,
        db_session=None,
        *args,
        **kwargs
    ):
        
        db_session = get_db_session(db_session)
        # lets lock rows to prevent bad tree states
        resource = ResourceService.lock_resource_for_update(
            resource_id=resource_id, db_session=db_session
        )
        ResourceService.lock_resource_for_update(
            resource_id=resource.parent_id, db_session=db_session
        )
        same_branch = False

        # reset if parent is same as old
        if new_parent_id == resource.parent_id:
            new_parent_id = noop

        if new_parent_id is not noop:
            cls.check_node_parent(resource_id, new_parent_id, db_session=db_session)
        else:
            same_branch = True

        if new_parent_id is noop:
            # it is not guaranteed that parent exists
            parent_id = resource.parent_id if resource else None
        else:
            parent_id = new_parent_id

        cls.check_node_position(
            parent_id, to_position, on_same_branch=same_branch, db_session=db_session
        )
        # move on same branch
        if new_parent_id is noop:
            order_range = list(sorted((resource.ordering, to_position)))
            move_down = resource.ordering > to_position

            query = db_session.query(cls.model)
            query = query.filter(cls.model.parent_id == parent_id)
            query = query.filter(cls.model.ordering.between(*order_range))
            if move_down:
                query.update(
                    {cls.model.ordering: cls.model.ordering + 1},
                    synchronize_session=False,
                )
            else:
                query.update(
                    {cls.model.ordering: cls.model.ordering - 1},
                    synchronize_session=False,
                )
            db_session.flush()
            db_session.expire(resource)
            resource.ordering = to_position
        # move between branches
        else:
            cls.shift_ordering_down(
                resource.parent_id, resource.ordering, db_session=db_session
            )
            cls.shift_ordering_up(new_parent_id, to_position, db_session=db_session)
            db_session.expire(resource)
            resource.parent_id = new_parent_id
            resource.ordering = to_position
            db_session.flush()
        return True
640058
public long getNearestPosition(long recordNumber) {
        if (recordNumber < startingRecordNumber || recordNumber > lastRecordNumber)
            throw new IndexOutOfBoundsException();
        return index.get((int) ((recordNumber - startingRecordNumber) / step));
    }