@Override public SqlStatementCustomizer createForMethod(Annotation annotation, Class<?> sqlObjectType, Method method) { final int maxRows = ((MaxRows) annotation).value(); if (maxRows == DEFAULT_MAX_ROWS) { throw new IllegalArgumentException(String.format( "no value given for @%s on %s:%s", MaxRows.class.getSimpleName(), sqlObjectType.getName(), method.getName()) ); } if (maxRows <= 0) { throw new IllegalArgumentException(String.format( "@%s value given on %s:%s is %s, which is negative or 0. This makes no sense.", MaxRows.class.getSimpleName(), sqlObjectType.getName(), method.getName(), maxRows) ); } return stmt -> ((Query) stmt).setMaxRows(maxRows); }
((Query) stmt).setMaxRows(maxRows); };
@Test public void testStatementCustomizersPersistAfterMap() { h.execute("insert into something (id, name) values (?, ?)", 1, "hello"); h.execute("insert into something (id, name) values (?, ?)", 2, "world"); List<Something> rs = h.createQuery("select id, name from something") .setMaxRows(1) .mapToBean(Something.class) .list(); assertThat(rs).hasSize(1); }