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);
}
}
}
Aggregations