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方法的返回值。