前台和后台执行Action的统一调用入口,可用于NC6 Client端调用DAO执行增删改等操作

package com.ufida.zior.console;

import nc.bs.framework.common.NCLocator;
import nc.bs.framework.common.RuntimeEnv;
import nc.bs.framework.comn.NetStreamConstants;

import com.ufida.iufo.pub.tools.AppDebug;
import com.ufida.iufo.pub.tools.DateUtil;
import com.ufida.zior.exception.MessageException;
import com.ufida.zior.perfwatch.PerfWatch;

/**
 * 前台和后台执行Action的统一调用入口
 * 
 */
public class ActionHandler {

	private final static boolean ON_SERVER = RuntimeEnv.getInstance()
			.isRunningInServer();

	public static Object exec(String action, String method) {
		return exec(action, method, null);
	}

	public static Object exec(String action, String method, Object paramter) {
		return exec(action, method, paramter, false);
	}

	public static Object execWithZip(String action, String method,
			Object paramter) {
		return exec(action, method, paramter, true);
	}

	public static Object exec(String action, String method, Object paramter,
			boolean needCompress) {

		if (action == null || method == null) {
			throw new IllegalArgumentException("action or method is null.");
		}

		String tag = " ActionInvoke: " + action + "." + method + "()";
		AppDebug.debug(DateUtil.getCurTimeWithMillisecond()	+ tag);
		// pw.appendMessage("paramter: ").appendMessage(paramter);
		// 参数可能为大对象CellsModel,不得输出
		final boolean STREAM_NEED_COMPRESS = NetStreamConstants.STREAM_NEED_COMPRESS;
		PerfWatch pw = null;
		try {
			// server端不得使用PerfWatch
			if (ON_SERVER) {
				return ActionExecutor.exec(action, method, paramter);
			} else {
				pw = new PerfWatch(tag);
				NetStreamConstants.STREAM_NEED_COMPRESS = needCompress;
				IActionInvokeService env = (IActionInvokeService) NCLocator
						.getInstance().lookup(
								IActionInvokeService.class.getName());

				return env.exec(action, method, paramter);
			}

		} catch (Exception e) {
			if (pw != null){
				pw.appendMessage(e);
			}
			throw MessageException.handle(e);

		} finally {
			NetStreamConstants.STREAM_NEED_COMPRESS = STREAM_NEED_COMPRESS;
			if (pw != null){
				pw.stop();
			}
		}

	}

	// /**
	// * 请求发送到后台进行处理
	// * @param action
	// * @param method
	// * @param paramter
	// * @return
	// */
	// private static Object req2srv(String action, String method, Object
	// paramter)
	// throws Exception {
	//
	// final String SERVER_URL = ServiceConfig.getBaseHttpURL()
	// //ClientAssistant.getServerURL()//
	// + "/service/~uap/com.ufida.zior.console.ActionHandlerServlet";
	//
	// java.net.URLConnection urlc = null;
	// java.io.ObjectOutputStream oos = null;
	// java.util.zip.GZIPOutputStream gzo = null;
	// try{
	// URL urlAddress = new java.net.URL(SERVER_URL);
	// urlc = urlAddress.openConnection();
	// urlc.setDoOutput(true);
	// gzo = new java.util.zip.GZIPOutputStream(
	// urlc.getOutputStream());
	// oos = new java.io.ObjectOutputStream(gzo);
	// oos.writeObject(action);
	// oos.writeObject(method);
	// oos.writeObject(paramter);
	// oos.writeObject(MultiLangUtil.getLanguage());//当前语种
	// oos.writeObject(Logger.getModule()); // 日志模块
	//
	// } catch(Exception e){
	// String msg = "SERVER_URL: " + SERVER_URL;
	// AppDebug.debug(msg);
	// AppDebug.debug(e);
	// throw new RuntimeException(msg + " -->" + e.getMessage() , e);
	// } finally {
	// if(oos != null){
	// oos.flush();
	// oos.close();
	// }
	// if(gzo != null){
	// gzo.finish();
	// gzo.flush();
	// }
	// }
	//
	// java.io.ObjectInputStream in = new java.io.ObjectInputStream(urlc
	// .getInputStream());
	// boolean success = (Boolean) in.readObject();
	// Object result = in.readObject();
	//
	// in.close();
	//
	// if (!success) {
	// AppDebug.debug(result);
	// throw new RuntimeException((String) result);
	// }
	// return result;
	// }

}

如使用 NC Client端调用DAO执行update:
5版中是没有的,通过查看6版本代码 可以通过以下实现

public  Object execUpdate(String sql, SQLParameter parameter) {
     return ActionHandler.exec("nc.bs.dao.BaseDAO", "executeUpdate", new Object[] { sql, parameter });
}

返回参数为executeUpdate方法的返回值。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值