/** 打开查询结果 */ public static String[] openQuery(Hashtable params) { JParamObject PO = new JParamObject(); for (Enumeration e = params.keys(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); String val = (String) params.get(key); PO.SetValueByParamName(key, val); } String[] queryResult = new String[2]; JResponseObject RO = (JResponseObject) JActiveDComDM.AbstractDataActiveFramework.InvokeObjectMethod( "DataReport", "OpenQuery", PO, ""); String XMLStr = (String) RO.ResponseObject; if (RO != null && RO.ResponseObject != null) { XMLStr = (String) RO.ResponseObject; JXMLBaseObject XMLObj = new JXMLBaseObject(XMLStr); Element queryElmt = XMLObj.GetElementByName("Query"); // 格式 queryResult[0] = queryElmt.getAttributeValue("QueryFormat"); // 数据 queryResult[0] = queryElmt.getAttributeValue("QueryData"); } return queryResult; }
/** * @param loginStub LoginStub * @return AccountStub * @throws Exception */ protected static AccountStub getAccountStub(JParamObject loginStub) throws Exception { java.util.List accountSetList = (List) ConfigManager.getDefault().getCfgData("AccountSet", null); if (accountSetList == null || accountSetList.size() == 0) return null; AccountStub accountStub = null; for (int i = 0; i < accountSetList.size(); i++) { accountStub = (AccountStub) accountSetList.get(i); if (accountStub.getDataStorageId().equals(loginStub.GetValueByEnvName("DataBaseName", null)) && accountStub.getAccountId().equals(loginStub.GetValueByEnvName("DBNO", null))) { return accountStub; } } return null; }
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; }
/** * 加载资源 * * @param reportName * @return */ public static String loadResource(String reportName) { String XMLStr = ""; JParamObject PO = JParamObject.Create(); JResponseObject RO = (JResponseObject) JActiveDComDM.AbstractDataActiveFramework.InvokeObjectMethod( "DataReport", "OpenReport", PO, reportName); if (RO != null && RO.ResponseObject != null) { XMLStr = (String) RO.ResponseObject; } return XMLStr; }
/** * @param paramObject JParamObject * @return JConnection * @throws Exception */ public JConnection getConnection( JParamObject paramObject, Object Data, Object CustomObject, Object AdditiveObject) throws Exception { JConnection conn = null; AccountStub accountStub = getAccountStub(paramObject); if (accountStub == null) return null; // 设置dbOwner paramObject.SetValueByEnvName("dbOwner", accountStub.getUserId()); DataStorageStub dataStorageStub = getDataStorageStub(accountStub); if (dataStorageStub == null) return null; JDataSourceStub dataSourceStub = (JDataSourceStub) getDataSourceStub(dataStorageStub); conn = createConnection(dataSourceStub); return initConnection(conn, paramObject, dataSourceStub, accountStub, dataStorageStub); }
/** * @param ParamObject Object * @param DataObject Object * @param CustomObject Object * @param AdditiveObject Object * @return Object * @throws Exception */ public Object CheckDBDataSource( Object ParamObject, Object DataObject, Object CustomObject, Object AdditiveObject) throws Exception { JParamObject PO; String DBType; JDataSourceStub DSS; JConnection jconn = null; boolean hasDataSource = false; PO = (JParamObject) ParamObject; DBType = PO.GetValueByEnvName("DataBaseType"); for (int i = 0; i < DBList.size(); i++) { DSS = (JDataSourceStub) DBList.get(i); if (DSS.DataBaseType.toLowerCase().equals(DBType.toLowerCase()) == true) { if (DSS.DBClass == null) { DSS.DBClass = Class.forName(DSS.classname); } if (DSS.NAClass == null) { DSS.NAClass = Class.forName(DSS.dbclass); } if (DSS.NAClass != null) { jconn = (JConnection) DSS.NAClass.newInstance(); try { hasDataSource = lookDataSource(jconn, PO); } catch (Exception e) { e.printStackTrace(); } if (hasDataSource) break; } } } if (!hasDataSource) { throw new Exception("ϵͳû���ṩ" + DBType + "������ݿ�������!"); } if (hasDataSource) return jconn; return null; }
/** * @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; }