DasClient { public <T> List<T> query(SqlBuilder builder) throws SQLException { final Hints hint = checkHints(builder.hints()); return internalExecute(hint, ()->{return delegate.query(builder);}); } DasClient(DasDelegate delegate); T queryByPk(T pk, Hints...hints); List<T> queryBySample(T sample, Hints...hints); List<T> queryBySample(T sample, PageRange range, Hints...hints); long countBySample(T sample, Hints...hints); int insert(T entity, Hints...hints); int insert(List<T> entities, Hints...hints); int[] batchInsert(List<T> entities, Hints...hints); int deleteByPk(T pk, Hints...hints); int deleteBySample(T sample, Hints...hints); int[] batchDelete(List<T> entities, Hints...hints); int update(T entity, Hints...hints); int[] batchUpdate(List<T> entities, Hints...hints); T queryObject(SqlBuilder builder); T queryObjectNullable(SqlBuilder builder); List<T> query(SqlBuilder builder); List<?> batchQuery(BatchQueryBuilder builder); int update(SqlBuilder builder); int[] batchUpdate(BatchUpdateBuilder builder); void call(CallBuilder builder); int[] batchCall(BatchCallBuilder builder); void execute(Transaction transaction, Hints...hints); T execute(CallableTransaction<T> transaction, Hints...hints);  }
@Test public void testQueryBetween() throws Exception { SqlBuilder builder = selectAll().from(p).where(p.PeopleID.between(1, 3)).orderBy(p.PeopleID.asc()).into(Person.class); List<Person> pl = dao.query(builder); assertEquals(3, pl.size()); assertEquals(1, pl.get(0).getPeopleID().intValue()); assertEquals(2, pl.get(1).getPeopleID().intValue()); assertEquals(3, pl.get(2).getPeopleID().intValue()); }
@Test public void testQuery() throws Exception { PersonDefinition p = Person.PERSON; List<Integer> pks = new ArrayList<>(); for (int k = 0; k < TABLE_MODE; k++) pks.add(k+1); SqlBuilder builder = selectAllFrom(p).where().allOf(p.PeopleID.in(pks)).orderBy(p.PeopleID.asc()).into(Person.class); Hints hints = builder.hints().diagnose(); List<Person> plist = dao.query(builder); if(this.dbCategory == SqlServer) { assertTrue(hints.getDiagnose().toString().contains(SegmentConstants.WITH_NO_LOCK.getText())); } assertEquals(4, plist.size()); for (int k = 0; k < TABLE_MODE; k++) { Person pk = plist.get(k); assertNotNull(p); assertEquals(k+1, pk.getPeopleID().intValue()); assertEquals("test", pk.getName()); } }
@Test public void testQueryWithLock() throws Exception { PersonDefinition p = Person.PERSON; SqlBuilder builder = selectAllFrom(p).withLock().into(Person.class); Hints hints = builder.hints().diagnose(); List<Person> plist = dao.query(builder); if(this.dbCategory == SqlServer) { assertFalse(hints.getDiagnose().toString().contains(SegmentConstants.WITH_NO_LOCK.getText())); } assertFalse(plist.isEmpty()); }
@Test public void testQueryIntoObjectID() throws Exception { PersonDefinition p = Person.PERSON; SqlBuilder builder = selectDistinct(p.PeopleID).from(p).orderBy(p.PeopleID.asc()).intoObject(); List plist = dao.query(builder); assertEquals(4, plist.size()); for(int i = 0; i < plist.size(); i++){ assertEquals(i + 1, ((Number)plist.get(i)).intValue()); } }
@Test public void testQueryTopObj() throws Exception { if(dbCategory == MySql) return; PersonDefinition p = Person.PERSON; SqlBuilder builder = selectTop(3, p.PeopleID).from(p).orderBy(p.PeopleID.asc()).intoObject(); List plist = dao.query(builder); assertEquals(3, plist.size()); for(int i = 0; i < plist.size(); i++){ assertEquals(i + 1, ((Number)plist.get(i)).intValue()); } }
@Test public void testQueryTopEntity() throws Exception { if(dbCategory == MySql) return; PersonDefinition p = Person.PERSON; SqlBuilder builder = selectTop(3, p.PeopleID, p.Name).from(p).orderBy(p.PeopleID.asc()).into(Person.class); List<Person> plist = null; plist = dao.query(builder); assertEquals(3, plist.size()); for(int i = 0; i < plist.size(); i++){ assertEquals("test", plist.get(i).getName()); } }
@Test public void testQueryIntoObjectString() throws Exception { PersonDefinition p = Person.PERSON; SqlBuilder builder = selectDistinct(p.Name).from(p).orderBy(p.Name.asc()).intoObject(); List plist = dao.query(builder); assertEquals(1, plist.size()); assertEquals("test", (String)plist.get(0)); }