@Test public void testExecuteMulti() throws Exception { TypeToken<List<User>> pt = new TypeToken<List<User>>() { }; TypeToken<int[]> rt = TypeToken.of(int[].class); String srcSql = "update #table set name=:1.name where id=:1.id"; AbstractOperator operator = getOperator2(pt, rt, srcSql); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public int[] batchUpdate(DataSource ds, List<BoundSql> boundSqls) throws DataAccessException { if (boundSqls.size() == 3) { List<String> descSqls = Arrays.asList( "update user_30 set name=? where id=?", "update user_10 set name=? where id=?", "update user_20 set name=? where id=?"); List<String> sqls = new ArrayList<String>(); for (BoundSql boundSql : boundSqls) { sqls.add(boundSql.getSql()); } assertThat(sqls, equalTo(descSqls)); assertThat(boundSqls.size(), equalTo(3)); assertThat(boundSqls.get(0).getArgs().get(0), equalTo((Object) "ash")); assertThat(boundSqls.get(0).getArgs().get(1), equalTo((Object) 30)); assertThat(boundSqls.get(1).getArgs().get(0), equalTo((Object) "lily")); assertThat(boundSqls.get(1).getArgs().get(1), equalTo((Object) 10)); assertThat(boundSqls.get(2).getArgs().get(0), equalTo((Object) "gill")); assertThat(boundSqls.get(2).getArgs().get(1), equalTo((Object) 20)); return new int[] {3, 1, 2}; } else if (boundSqls.size() == 2) { List<String> descSqls = Arrays.asList( "update user_60 set name=? where id=?", "update user_55 set name=? where id=?"); List<String> sqls = new ArrayList<String>(); for (BoundSql boundSql : boundSqls) { sqls.add(boundSql.getSql()); } assertThat(sqls, equalTo(descSqls)); assertThat(boundSqls.size(), equalTo(2)); assertThat(boundSqls.get(0).getArgs().get(0), equalTo((Object) "lucy")); assertThat(boundSqls.get(0).getArgs().get(1), equalTo((Object) 60)); assertThat(boundSqls.get(1).getArgs().get(0), equalTo((Object) "liu")); assertThat(boundSqls.get(1).getArgs().get(1), equalTo((Object) 55)); return new int[] {6, 5}; } else { throw new IllegalStateException(); } } }); List<User> users = Arrays.asList( new User(30, "ash"), new User(60, "lucy"), new User(10, "lily"), new User(20, "gill"), new User(55, "liu")); int[] actualInts = (int[]) operator.execute(new Object[]{users}, InvocationStat.create()); assertThat(Arrays.toString(actualInts), equalTo(Arrays.toString(new int[]{3, 6, 1, 2, 5}))); }
@Override public Object execute(Object[] values, InvocationStat stat) { Iterables iterables = getIterables(values); if (iterables.isEmpty()) { return transformer.transform(new int[]{}); } Map<DataSource, Group> gorupMap = new HashMap<DataSource, Group>(); int t = 0; for (Object obj : iterables) { InvocationContext context = invocationContextFactory.newInvocationContext(new Object[]{obj}); group(context, gorupMap, t++); } int[] ints = executeDb(gorupMap, t, stat); return transformer.transform(ints); }
BatchUpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { Iterables iterables = getIterables(values); if (iterables.isEmpty()) { return transformer.transform(new int[]{}); } Map<DataSource, Group> gorupMap = new HashMap<DataSource, Group>(); int t = 0; for (Object obj : iterables) { InvocationContext context = invocationContextFactory.newInvocationContext(new Object[]{obj}); group(context, gorupMap, t++); } int[] ints = executeDb(gorupMap, t, stat); return transformer.transform(ints); } }
BatchUpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { Iterables iterables = getIterables(values); if (iterables.isEmpty()) { return transformer.transform(new int[]{}); } Map<DataSource, Group> gorupMap = new HashMap<DataSource, Group>(); int t = 0; for (Object obj : iterables) { InvocationContext context = invocationContextFactory.newInvocationContext(new Object[]{obj}); group(context, gorupMap, t++); } int[] ints = executeDb(gorupMap, t, stat); return transformer.transform(ints); } BatchUpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); }
BatchUpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { Iterables iterables = getIterables(values); if (iterables.isEmpty()) { return transformer.transform(new int[]{}); } Map<DataSource, Group> gorupMap = new HashMap<DataSource, Group>(); int t = 0; for (Object obj : iterables) { InvocationContext context = invocationContextFactory.newInvocationContext(new Object[]{obj}); group(context, gorupMap, t++); } int[] ints = executeDb(gorupMap, t, stat); return transformer.transform(ints); } BatchUpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat); }
BatchUpdateOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { Iterables iterables = getIterables(values); if (iterables.isEmpty()) { return transformer.transform(new int[]{}); } Map<DataSource, Group> gorupMap = new HashMap<DataSource, Group>(); int t = 0; for (Object obj : iterables) { InvocationContext context = invocationContextFactory.newInvocationContext(new Object[]{obj}); group(context, gorupMap, t++); } int[] ints = executeDb(gorupMap, t, stat); return transformer.transform(ints); } BatchUpdateOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object execute(Object[] values, InvocationStat stat);  }