public void loadForm(JParamObject PO, EFFormDataModel formDataModel) {

    JConnection conn = null;
    JStatement stmt = null;
    Object object = null;
    try {
      conn = JConnection.getInstance(jdbcTemplate.getDataSource().getConnection());

      stmt = conn.createStatement();

      object =
          formServiceUtil.loadFormService(request, PO.GetValueByParamName(SYS_MODEL.SERVICE_ID));

      EMPComposeFormInfo formInfo = (EMPComposeFormInfo) object;
      pluginsMap = (HashMap) formInfo.getDataContainerStub().getRefCompStubMap();

      prepareSaveForm(PO, stmt, formDataModel);

      saveBillData(PO, stmt, formDataModel);

      finishSaveForm(PO, stmt, formDataModel);
    } catch (Exception ce) {
      ce.printStackTrace();
      formDataModel.setFormSaveMessage(ce.getCause().getMessage());
    } finally {
      closeAllResources(null, stmt, conn);
    }
  }
 /**
  * @param dataSourceStub JDataSourceStub
  * @return JConnection
  * @throws Exception
  */
 protected static JConnection createConnection(JDataSourceStub dataSourceStub) throws Exception {
   JConnection jconn = null;
   if (dataSourceStub.DBClass == null) {
     dataSourceStub.DBClass = Class.forName(dataSourceStub.classname);
   }
   if (dataSourceStub.NAClass == null) {
     dataSourceStub.NAClass = Class.forName(dataSourceStub.dbclass);
   }
   if (dataSourceStub.NAClass != null) {
     jconn = (JConnection) dataSourceStub.NAClass.newInstance();
   }
   if (jconn != null) jconn.setDataBaseType(dataSourceStub.DataBaseType);
   return jconn;
 }
  /**
   * 获取自列表的列与掩码的Map
   *
   * @param conn
   * @param PO
   * @param dictMetadata
   * @param DOMeta
   * @throws Exception
   */
  protected static java.util.Map getSelfEnumColViewMap(
      JConnection conn, JParamObject PO, DictMetadata dictMetadata) throws Exception {
    if (dictMetadata == null) {
      return null;
    }
    TableMetadata tableMetadata = dictMetadata.getTableMetadata();
    if (tableMetadata == null) {
      return null;
    }
    java.util.List colList = tableMetadata.getColList();
    if (colList == null) return null;

    // 获取各列的掩码
    java.util.Map map = new java.util.HashMap();
    String objid = tableMetadata.getString("OBJ_ID", "");
    Statement st = null;
    ResultSet rs = null;
    String sql = " select * from SYS_SELFENUM" + " where OBJ_ID='" + objid + "' order by COL_DISP";
    try {
      st = conn.createStatement();
      rs = st.executeQuery(sql);
      while (rs.next()) {
        String colid = rs.getString("COL_ID");
        String colval = rs.getString("COL_VAL");
        String colnote = rs.getString("F_NOTE");
        if (colval == null || colval.length() == 0) {
          colval = " ";
        }
        if (colnote == null || colnote.length() == 0) {
          colnote = colval;
        }
        String view = (String) map.get(colid);
        if (view == null) {
          map.put(colid, colval + ":" + colnote);
        } else {
          if (view.endsWith(";")) {
            view = view.substring(0, view.length() - 1);
          }
          map.put(colid, view + ";" + colval + ":" + colnote);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      conn.BackStatement(st, rs);
    }
    return map;
  }
 boolean lookDataSource(JConnection jconn, JParamObject PO) throws Exception {
   boolean hasDataSource = false;
   if (jconn != null) {
     String dataSource = PO.GetValueByEnvName("DataSource");
     if (dataSource != null && !"".equals(dataSource)) {
       DataSource ds = null;
       //        try {
       //          ds = (DataSource) jconn.getDBContext().lookup("jdbc/" +
       //              dataSource);
       //        }
       //        catch (Exception e) {
       //          Context context = new InitialContext();
       //          Context envContext = (Context) context.lookup(
       //              "java:/comp/env");
       //          ds = (DataSource) envContext.lookup("jdbc/" + dataSource);
       //
       //        }
       if (ds != null) {
         jconn.getInstance(ds.getConnection());
         hasDataSource = true;
       }
     }
   }
   return hasDataSource;
 }
 /** 使用新式的元数据兼容旧的元数据 */
 protected static DictMetadata getMetaDataNew(JConnection conn, JParamObject PO, String dctid)
     throws Exception {
   DictMetadata dictMetadata = DictMetadata.getInstance();
   dictMetadata.setID(dctid);
   Statement st = null;
   DCTMetaData DICTMeta = null;
   DOMetaData DOMeta = null;
   try {
     st = JConnection.getInstance(conn).createStatement();
     //
     ESPServerContext ctx = ESPServerContext.getInstance(PO, JConnection.getInstance(conn));
     ctx.setStatement(st);
     DICTMeta =
         (DCTMetaData)
             MetaDataManager.getInstance(MetaDataManager._DCTObject_ + "_DAL")
                 .getMetaData(ctx, dctid);
     if (DICTMeta != null) {
       DOMeta = DICTMeta.getDoMetaData();
       dictMetadata.setStubTable(new Hashtable());
       dictMetadata.getStubTable().putAll(DICTMeta.getDataMap());
       //                DICTMeta.getSYS_DCT_CST();
     } else {
       DOMeta =
           (DOMetaData)
               MetaDataManager.getInstance(MetaDataManager._DataObject_ + "_DAL")
                   .getMetaData(ctx, dctid);
     }
     // 对象信息
     TableMetadata tableMetadata = TableMetadata.getInstance();
     tableMetadata.setID(dctid);
     tableMetadata.setStubTable(new Hashtable());
     if (tableMetadata.colList == null) tableMetadata.colList = new ArrayList();
     dictMetadata.tableMetadata = tableMetadata;
     // 复制对象信息
     if (DOMeta != null) tableMetadata.getStubTable().putAll(DOMeta.getDataMap());
     // 复制列信息
     getColMetadata(conn, PO, dictMetadata, DOMeta);
     // 复制数据字典的扩展属性
     getSYS_DCT_CST(conn, PO, dictMetadata, DICTMeta);
   } catch (Exception ex) {
     ex.printStackTrace();
   } finally {
     conn.BackStatement(st, null);
   }
   return dictMetadata;
 }
 /** 取数据字典的自定义属性列表STUBOBJECT */
 private static List getDictCST(JConnection conn, JParamObject PO, String dctid) {
   java.util.List maps = new ArrayList();
   Statement stmt = null;
   try {
     stmt = conn.createStatement();
     HashMap map = new HashMap();
     map.put("TABLE", "SYS_DCT_CST");
     map.put("WHERE", "DCT_ID = '" + dctid + "'");
     map.put("ORDER", "UNIT_ID,DCT_KEY");
     maps.add(map);
     return DBUtils.SimpleQuery(conn, PO, maps, stmt);
   } catch (Exception ex) {
     ex.printStackTrace();
   } finally {
     conn.BackStatement(stmt, null);
   }
   return null;
 }
  /**
   * @param conn Connection
   * @param PO JParamObject
   * @param dctid String
   * @return DictMetadata
   * @throws Exception
   */
  public static DictMetadata getMetaData(Connection conn, JParamObject PO, String dctid)
      throws Exception {

    return getMetaDataNew(JConnection.getInstance(conn), PO, dctid);

    //        MetaContextObject     mco = MetaContextObject.getInstance(PO,
    // JConnection.getInstance(conn), null, "IndexModel");
    //        DictMetadata dictMetadata =
    // DBMetadataManager.getDefault("IndexModel").getDictMetadata(mco, dctid);
    //        //增加对数据字典的自定义属性SYS_DCT_CST
    //        java.util.List     dctcst = getDictCST(JConnection.getInstance(conn), PO, dctid);
    //        dictMetadata.setObject("SYS_DCT_CST", dctcst);
    //        return dictMetadata;
  }
 /**
  * @param conn JConnection
  * @param PO JParamObject
  * @param DSS JDataSourceStub
  * @param custObj Object
  * @return JConnection
  * @throws Exception
  */
 protected static JConnection initConnection(
     JConnection conn,
     JParamObject PO,
     JDataSourceStub dataSourceStub,
     AccountStub accountStub,
     DataStorageStub dataStorageStub)
     throws Exception {
   if (conn.InitConnection(PO, dataSourceStub, accountStub, dataStorageStub) == null) return null;
   //    if (PO.isAutoConnection()) {
   //      PO.addConn(conn);
   //    }
   // 写入日志
   writeLoginfo(conn, PO);
   // add by fsz
   List sqlList = (List) PO.getValue("$$SQL_VIEWLIST", null);
   if (sqlList != null) {
     //      conn.setSqlLogList(sqlList);
   }
   return conn;
 }
  public static void closeAllResources(ResultSet rs, JStatement stmt, JConnection conn) {
    try {
      if (rs != null) {
        rs.close();
      }
    } catch (Exception ce) {
      ce.printStackTrace();
    }

    try {
      if (stmt != null) stmt.close();
    } catch (Exception ce) {
      ce.printStackTrace();
    }

    try {
      if (conn != null) conn.close();
    } catch (Exception ce) {
      ce.printStackTrace();
    }
  }