guzz批量更新程序

private void updateGroup() {
		String sql = "update um_group set pid=:pid where group_id=:id";
		CompiledSQL cs = tm.getCompiledSQLBuilder().buildCompiledSQL(
				User.class, sql);
		cs.addParamType("pid", "int");
		cs.addParamType("id", "int");

		WriteTranSession session = tm.openRWTran(false);
		try {
			SQLBatcher batcher = session.createCompiledSQLBatcher(cs);
			batcher.setBatchSize(80);

			for (int i = 0; i < groups.size(); i++) {
				Map g = groups.get(i);
				HashMap params = new HashMap();
				params.put("pid", Util.o2l(g.get("pid")));
				params.put("id", Util.o2l(g.get("id")));
				batcher.addNewBatchParams(params);
			}

			batcher.executeBatch();
			session.commit();
		} finally {
			session.close();
		}
	}

你可能感兴趣的:(guzz)