fda9206690a67f0339918fa1089c70f8424a50e7.svn-base 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package xin.glue.scheduling;
  2. import java.util.Collections;
  3. import java.util.Comparator;
  4. import java.util.List;
  5. import java.util.Map;
  6. import com.posdata.glue.biz.activity.PosActivity;
  7. import com.posdata.glue.biz.constants.PosBizControlConstants;
  8. import com.posdata.glue.biz.control.PosBizProvider;
  9. import com.posdata.glue.component.layout.PosXmlMessageLayout;
  10. import com.posdata.glue.context.PosContext;
  11. import com.posdata.glue.dao.PosGenericDao;
  12. import com.posdata.glue.dao.manager.PosQueryDefinition;
  13. import com.posdata.glue.dao.manager.PosQueryManager;
  14. import com.posdata.glue.dao.vo.PosParameter;
  15. import com.posdata.glue.msg.PosMESMessageImpl;
  16. import com.posdata.glue.msg.PosMessage;
  17. import com.posdata.glue.msg.util.PosMessageUtil;
  18. public abstract class XinHandleDataL2 extends PosActivity {
  19. private static byte[] lock = new byte[0]; // ÌØÊâµÄinstance±äÁ¿
  20. protected PosGenericDao getDao() {
  21. String testdao = getProperty("dao");
  22. if (testdao == null)
  23. testdao = "mesdao";
  24. else
  25. testdao = testdao.trim();
  26. return getDao(testdao);
  27. }
  28. protected boolean UpdateRec(String sqlKey, Object[] args) {
  29. try {
  30. PosParameter param = new PosParameter();
  31. for (int i = 0; i < args.length; i++)
  32. param.setWhereClauseParameter(i, args[i]);
  33. if (getDao().update(sqlKey, param) == 1)
  34. return true;
  35. else {
  36. StringBuffer sb = new StringBuffer("Record update failure!!\n");
  37. sb.append("SqlKey: ").append(sqlKey).append("\n");
  38. PosQueryManager queryManager = (PosQueryManager)PosContext.getBeanFactory().getBeanObject("queryManager");
  39. PosQueryDefinition queryDefinition = queryManager.getQueryDefinition(sqlKey);
  40. if (queryDefinition != null) {
  41. String sql = queryDefinition.getQueryStatement();
  42. for (int i = 0; i < args.length; i++)
  43. sql.replaceFirst("?", args[i].toString());
  44. sb.append(sql);
  45. }
  46. logger.logError(sb.toString());
  47. }
  48. } catch (Exception e) {
  49. logger.logError(e);
  50. }
  51. return false;
  52. }
  53. protected void TC_SEND(String sMsg, String TcId) {
  54. PosContext context = new PosContext();
  55. PosMessage message = new PosMESMessageImpl();
  56. context.setMessage(message);
  57. message.setTC(sMsg);
  58. message.setTCID(TcId);
  59. context.put(PosBizControlConstants.SERVICE_NAME, TcId + "-service");
  60. synchronized(lock) {
  61. PosBizProvider.getController().doSubController(context, false);
  62. }
  63. }
  64. private String setLength(int len) {
  65. if (len < 10) return "000" + len;
  66. else if (len < 100) return "00" + len;
  67. else if (len < 1000) return "0" + len;
  68. return "" + len;
  69. }
  70. private String setLength(String sMsg, int len) {
  71. for (int i = sMsg.length(); i < len; i++)
  72. sMsg += ' ';
  73. return sMsg.substring(0, len);
  74. }
  75. protected String getMessage(String sMsg, String TcId) {
  76. StringBuffer msg = new StringBuffer();
  77. try {
  78. List attributes = new PosXmlMessageLayout().getAttributes(TcId).getAttributes();
  79. Collections.sort(attributes, new Comparator() {
  80. public int compare(Object o1, Object o2) {
  81. return (Integer.parseInt(PosMessageUtil.getSource(o1, "seq").toString()) -
  82. Integer.parseInt(PosMessageUtil.getSource(o2, "seq").toString()));
  83. }});
  84. int mLen = sMsg.length();
  85. int iLen = 0;
  86. for (int i = 0, size = attributes.size(); i < size; i++) {
  87. Map attribute = (Map) attributes.get(i);
  88. String key = (String) attribute.get("id");
  89. msg.append(setLength(key, 20)).append('[').append(setLength(iLen)).append(" ");
  90. int len = Integer.parseInt(attribute.get("length").toString());
  91. msg.append(setLength(len)).append("] ");
  92. if (iLen + len <= mLen)
  93. msg.append(sMsg.substring(iLen, iLen + len));
  94. else if (iLen < mLen)
  95. msg.append(sMsg.substring(iLen, mLen - iLen));
  96. else
  97. msg.append('*');
  98. msg.append('\n');
  99. iLen += len;
  100. }
  101. msg.insert(0, "[Message Length: " + sMsg.length() + "]\t[Request Length: " + iLen + "]\n");
  102. msg.insert(0, sMsg + '\n');
  103. } catch (Exception e) {
  104. return TcId + ": " + sMsg;
  105. }
  106. return msg.toString();
  107. }
  108. }