Search in sources :

Example 1 with Position

use of com.google.apphosting.datastore.DatastoreV3Pb.CompiledCursor.Position in project appengine-java-standard by GoogleCloudPlatform.

the class CursorModernizer method modernizeCursor.

public static void modernizeCursor(CompiledCursor cursor, @Nullable DatastoreV3Pb.Query.Order.Direction firstSortDirection) throws InvalidConversionException {
    // First, convert any contents of the position field.
    if (cursor.hasPosition()) {
        InvalidConversionException.checkConversion(!cursor.hasPostfixPosition(), "A cursor cannot specify both position and postfix position.");
        InvalidConversionException.checkConversion(!cursor.hasAbsolutePosition(), "A cursor cannot specify both position and absolute position.");
        Position pos = cursor.getPosition();
        if (pos.hasStartKey()) {
            IndexPosition indexPos = cursor.getMutableAbsolutePosition();
            indexPos.setKeyAsBytes(pos.getStartKeyAsBytes());
            if (pos.hasStartInclusive()) {
                indexPos.setBefore(pos.isStartInclusive());
            }
            if (pos.hasBeforeAscending()) {
                indexPos.setBeforeAscending(pos.isBeforeAscending());
            }
        } else if (pos.hasKey() || pos.indexValueSize() > 0) {
            IndexPostfix postfixPos = cursor.getMutablePostfixPosition();
            for (PositionIndexValue value : pos.indexValues()) {
                IndexPostfix_IndexValue indexValue = postfixPos.addIndexValue().setPropertyName(value.getProperty());
                indexValue.getMutableValue().mergeFrom(value.getValue());
            }
            if (pos.hasKey()) {
                postfixPos.getMutableKey().mergeFrom(pos.getKey());
            }
            if (pos.hasStartInclusive()) {
                postfixPos.setBefore(pos.isStartInclusive());
            }
            if (pos.hasBeforeAscending()) {
                postfixPos.setBeforeAscending(pos.isBeforeAscending());
            }
        }
        cursor.clearPosition();
    }
    // Next, populate before_ascending or before.
    if (isEmpty(cursor)) {
        return;
    } else if (cursor.hasAbsolutePosition()) {
        IndexPosition indexPosition = cursor.getAbsolutePosition();
        if (indexPosition.hasBeforeAscending()) {
            setBefore(indexPosition, firstSortDirection);
        } else {
            setBeforeAscending(indexPosition, firstSortDirection);
        }
    } else if (cursor.hasPostfixPosition()) {
        IndexPostfix indexPostfix = cursor.getPostfixPosition();
        if (indexPostfix.hasBeforeAscending()) {
            setBefore(indexPostfix, firstSortDirection);
        } else {
            setBeforeAscending(indexPostfix, firstSortDirection);
        }
    }
}
Also used : IndexPostfix(com.google.storage.onestore.v3.OnestoreEntity.IndexPostfix) IndexPosition(com.google.storage.onestore.v3.OnestoreEntity.IndexPosition) Position(com.google.apphosting.datastore.DatastoreV3Pb.CompiledCursor.Position) PositionIndexValue(com.google.apphosting.datastore.DatastoreV3Pb.CompiledCursor.PositionIndexValue) IndexPosition(com.google.storage.onestore.v3.OnestoreEntity.IndexPosition) IndexPostfix_IndexValue(com.google.storage.onestore.v3.OnestoreEntity.IndexPostfix_IndexValue)

Aggregations

Position (com.google.apphosting.datastore.DatastoreV3Pb.CompiledCursor.Position)1 PositionIndexValue (com.google.apphosting.datastore.DatastoreV3Pb.CompiledCursor.PositionIndexValue)1 IndexPosition (com.google.storage.onestore.v3.OnestoreEntity.IndexPosition)1 IndexPostfix (com.google.storage.onestore.v3.OnestoreEntity.IndexPostfix)1 IndexPostfix_IndexValue (com.google.storage.onestore.v3.OnestoreEntity.IndexPostfix_IndexValue)1