Refering to the Python workaround for "GQL kinda like" queries, the Java implementation with the low level datastore API should look like this :
// From user input
String usernamePrefix = "XX";
Filter usernameGreaterThanPrefixFilter =
new FilterPredicate("username",
FilterOperator.GREATER_THAN_OR_EQUAL,
usernamePrefix);
Filter usernameLessThanLargestPossibleFilter =
new FilterPredicate("username",
FilterOperator.LESS_THAN,
usernamePrefix + "\ufffd");
Filter usernameKindaLikeFilter =
CompositeFilterOperator.and(usernameGreaterThanPrefixFilter, usernameLessThanLargestPossibleFilter);
Query q = new Query("User").setFilter(usernameKindaLikeFilter);
I have never tested this though, if it works I would have learned something thanks to you.
If it does not work, you can always store a fixed length "userPrefix" property on each entity, which would be a substring of the username. You could then query the userPrefix property with a FilterOperator.EQUAL
equality filter.