Convert to java, and add a junit test for creating select query