Use AbstractQuery and anonymous inner classes