817bb0fd77f8a652da3b077b1a4a73890fb4c643.svn-base 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. package com.persistence.service.assitant;
  2. import java.io.BufferedReader;
  3. import java.io.ByteArrayInputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.OutputStream;
  7. import java.io.Reader;
  8. import java.io.Writer;
  9. import java.sql.Connection;
  10. import java.util.ArrayList;
  11. import java.util.List;
  12. import java.util.Map;
  13. import javax.servlet.http.HttpServletRequest;
  14. import javax.xml.parsers.DocumentBuilderFactory;
  15. import javax.xml.parsers.ParserConfigurationException;
  16. import net.sf.json.JSONObject;
  17. import org.apache.log4j.Logger;
  18. import org.w3c.dom.Document;
  19. import org.xml.sax.SAXException;
  20. import com.sysmodel.Util;
  21. import com.sysmodel.XFormFactory;
  22. import com.sysmodel.collectmodel.xmlmodel.able.FormCollection;
  23. import com.sysmodel.collectmodel.xmlmodel.impl.HiddenFieldImpl;
  24. import com.sysmodel.collectmodel.xmlmodel.impl.ReportFieldImpl;
  25. import com.sysmodel.datamodel.xmlmodel.DataContent;
  26. import com.sysmodel.datamodel.xmlmodel.PropertyValue;
  27. import com.sysmodel.datamodel.xmlmodel.able.MdpAttribute;
  28. import com.sysmodel.datamodel.xmlmodel.able.MdpClass;
  29. import com.sysmodel.datamodel.xmlmodel.able.MdpConstant;
  30. import com.sysmodel.datamodel.xmlmodel.able.MdpDataSource;
  31. import com.sysmodel.datamodel.xmlmodel.able.Property;
  32. import com.sysmodel.datamodel.xmlmodel.able.Relation;
  33. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  34. import com.sysmodel.datamodel.xmlmodel.able.Template;
  35. import com.sysmodel.datamodel.xmlmodel.impl.MdpAttributeImpl;
  36. import com.sysmodel.datamodel.xmlmodel.impl.PropertyImpl;
  37. import com.sysmodel.datamodel.xmlmodel.impl.RelationImpl;
  38. import com.sysmodel.datamodel.xmlmodel.impl.TemplateImpl;
  39. import com.persistence.service.SysPersistence;
  40. import com.persistence.service.exception.PersistenceException;
  41. import com.persistence.service.exception.TransformTypeException;
  42. import com.persistence.service.logic.LogicFactory;
  43. import com.persistence.service.logic.LogicHelper;
  44. /**
  45. * sysmodel com.sysmodel.persistence create time 2006-5-18
  46. *
  47. * @author nbs
  48. */
  49. public class SysPersistenceImpl implements SysPersistence{
  50. private final static Logger log = Logger.getLogger(SysPersistenceImpl.class);
  51. private SysModel sysmodel = null;
  52. public SysPersistenceImpl(SysModel sysmodel) {
  53. this.sysmodel = sysmodel;
  54. }
  55. public String addObjectData(DataObject dataobject) throws TransformTypeException,
  56. PersistenceException {
  57. MdpClass mdpClass = sysmodel.getMdpClassByClassID(dataobject.getIntClassid());
  58. // 类型转换
  59. TypeTransformer.transformString(mdpClass, dataobject);
  60. // 子表类型转换
  61. List<DataObject> child = dataobject.getChildobject();
  62. for (int i = 0; i < child.size(); i++) {
  63. DataObject childObject = child.get(i);
  64. MdpClass childMdpClass = sysmodel.getMdpClassByClassID(childObject.getIntClassid());
  65. TypeTransformer.transformString(childMdpClass, childObject);
  66. }
  67. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  68. return DaoEngine.insertData(dataSource, dataobject);
  69. }
  70. public Connection getConnection() {
  71. return getConnection(99);
  72. }
  73. public Connection getConnection(int claasid) {
  74. MdpClass mdpClass = sysmodel.getMdpClassByClassID(claasid);
  75. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  76. LogicHelper helper = LogicFactory.getInstance(dataSource.getDataBase());
  77. return helper.getConnection(dataSource);
  78. }
  79. public String addChildData(DataObject dataobject, String parentid)
  80. throws TransformTypeException, PersistenceException {
  81. MdpClass mdpClass = sysmodel.getMdpClassByClassID(dataobject.getIntClassid());
  82. // 类型转换
  83. TypeTransformer.transformString(mdpClass, dataobject);
  84. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  85. return DaoEngine.insertChildData(dataSource, dataobject, parentid);
  86. }
  87. public boolean deleteChildData(int classid, String parentid) throws PersistenceException {
  88. // return this.deleteChildData(classid, parentid, false);
  89. // 为了当前系统可用,临时真删除
  90. return this.deleteChildData(classid, parentid, true);
  91. }
  92. public boolean deleteData(String objectID, int classid) throws PersistenceException {
  93. // 为了当前系统可用,临时真删除
  94. return this.deleteData(objectID, classid, true);
  95. // return this.deleteData(objectID, classid, false);
  96. }
  97. public boolean deleteChildData(int classid, String parentid, boolean isreal)
  98. throws PersistenceException {
  99. MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
  100. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  101. return DaoEngine.deleteChildData(dataSource, mdpClass.getName(), parentid, isreal);
  102. }
  103. public boolean deleteData(String objectID, int classid, boolean isreal)
  104. throws PersistenceException {
  105. MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
  106. DataObject object = new DataObject();
  107. object.setClassid(mdpClass.getClassid());
  108. object.setTablename(mdpClass.getName());
  109. object.setObjectID(objectID);
  110. List<RelationImpl> relationList = mdpClass.getRelations();
  111. for (int i = 0; i < relationList.size(); i++) {
  112. Relation relation = relationList.get(i);
  113. if (relation.getType() == Relation.REALTION_MASTER) {
  114. MdpClass childClass = sysmodel.getMdpClassByClassID(relation.getGuestClassid());
  115. DataObject childObject = new DataObject();
  116. childObject.setClassid(childClass.getClassid());
  117. childObject.setTablename(childClass.getName());
  118. object.addChildObject(childObject);
  119. }
  120. }
  121. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  122. return DaoEngine.deleteData(dataSource, object, isreal);
  123. }
  124. public String getDataBaseTime() throws PersistenceException {
  125. MdpClass mdpClass = sysmodel.getMdpClassByClassID(99);
  126. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  127. return DaoEngine.getDataBaseTime(dataSource);
  128. }
  129. public void readBlobToOutputStream(int classid, String objectID, String attributeName,
  130. OutputStream os) throws TransformTypeException, PersistenceException {
  131. MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
  132. MdpAttribute attribute = mdpClass.getMdpAttributeByName(attributeName);
  133. if (attribute == null)
  134. throw new TransformTypeException("not have " + attributeName + " in "
  135. + mdpClass.getName());
  136. DataObject object = new DataObject();
  137. object.setClassid(mdpClass.getClassid());
  138. object.setTablename(mdpClass.getName());
  139. object.setObjectID(objectID);
  140. Field field = new Field(attributeName, null);
  141. field.setDataType(attribute.getDataType());
  142. object.addAttribute(field);
  143. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  144. DaoEngine.readBlobToOutputStream(dataSource, object, os);
  145. }
  146. public void readClobToWriter(int classid, String objectID, String attributeName, Writer writer)
  147. throws TransformTypeException, PersistenceException {
  148. MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
  149. MdpAttribute attribute = mdpClass.getMdpAttributeByName(attributeName);
  150. if (attribute == null)
  151. throw new TransformTypeException("not have " + attributeName + " in "
  152. + mdpClass.getName());
  153. DataObject object = new DataObject();
  154. object.setClassid(mdpClass.getClassid());
  155. object.setTablename(mdpClass.getName());
  156. object.setObjectID(objectID);
  157. Field field = new Field(attributeName, null);
  158. field.setDataType(attribute.getDataType());
  159. object.addAttribute(field);
  160. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  161. DaoEngine.readClobToWriter(dataSource, object, writer);
  162. }
  163. public ArrayList<DataObject> searchAllData(int classid, List<Field> condition)
  164. throws TransformTypeException, PersistenceException {
  165. MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
  166. TypeTransformer.transformString(mdpClass, condition);
  167. DataObject dataobject = TypeTransformer.getSearchDataObject(mdpClass);
  168. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  169. return DaoEngine.searchAllData(dataSource, dataobject, condition);
  170. }
  171. public ArrayList<DataObject> searchAllData(int classid, String SQLcondition)
  172. throws TransformTypeException, PersistenceException {
  173. MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
  174. DataObject dataobject = TypeTransformer.getSearchDataObject(mdpClass);
  175. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  176. return DaoEngine.searchAllData(dataSource, dataobject, SQLcondition);
  177. }
  178. public ArrayList<DataObject> searchChildObjectData(String parentid, int classid)
  179. throws PersistenceException {
  180. MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
  181. DataObject dataobject = TypeTransformer.getSearchDataObject(mdpClass);
  182. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  183. return DaoEngine.searchChildData(dataSource, dataobject, parentid);
  184. }
  185. public DataObject searchObjectData(String objectID, int classid) throws PersistenceException {
  186. MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
  187. DataObject dataobject = TypeTransformer.getSearchDataObject(mdpClass);
  188. dataobject.setObjectID(objectID);
  189. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  190. return DaoEngine.searchData(dataSource, dataobject);
  191. }
  192. public DataObject searchObjectData(String objectID, int classid, String objectIDName)
  193. throws PersistenceException {
  194. MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
  195. DataObject dataobject = TypeTransformer.getSearchDataObject(mdpClass);
  196. dataobject.setObjectID(objectID);
  197. dataobject.setObjectIDName(objectIDName);
  198. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  199. return DaoEngine.searchData(dataSource, dataobject);
  200. }
  201. public void storeBlob(int classid, String objectID, String attributeName, InputStream is)
  202. throws TransformTypeException, PersistenceException {
  203. MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
  204. MdpAttribute attribute = mdpClass.getMdpAttributeByName(attributeName);
  205. if (attribute == null)
  206. throw new TransformTypeException("not have " + attributeName + " in "
  207. + mdpClass.getName());
  208. DataObject object = new DataObject();
  209. object.setClassid(mdpClass.getClassid());
  210. object.setTablename(mdpClass.getName());
  211. object.setObjectID(objectID);
  212. Field field = new Field(attributeName, null);
  213. field.setDataType(attribute.getDataType());
  214. object.addAttribute(field);
  215. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  216. DaoEngine.storeBlob(dataSource, object, is);
  217. }
  218. public void storeClob(int classid, String objectID, String attributeName, Reader reader)
  219. throws TransformTypeException, PersistenceException {
  220. MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
  221. MdpAttribute attribute = mdpClass.getMdpAttributeByName(attributeName);
  222. if (attribute == null)
  223. throw new TransformTypeException("not have " + attributeName + " in "
  224. + mdpClass.getName());
  225. DataObject object = new DataObject();
  226. object.setClassid(mdpClass.getClassid());
  227. object.setTablename(mdpClass.getName());
  228. object.setObjectID(objectID);
  229. Field field = new Field(attributeName, null);
  230. field.setDataType(attribute.getDataType());
  231. object.addAttribute(field);
  232. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  233. DaoEngine.storeClob(dataSource, object, reader);
  234. }
  235. public boolean updateObjectData(DataObject dataobject) throws TransformTypeException,
  236. PersistenceException {
  237. MdpClass mdpClass = sysmodel.getMdpClassByClassID(dataobject.getIntClassid());
  238. // 类型转换
  239. TypeTransformer.transformString(mdpClass, dataobject);
  240. // 子表类型转换
  241. List<DataObject> child = dataobject.getChildobject();
  242. for (int i = 0; i < child.size(); i++) {
  243. DataObject childObject = child.get(i);
  244. MdpClass childMdpClass = sysmodel.getMdpClassByClassID(childObject.getIntClassid());
  245. TypeTransformer.transformString(childMdpClass, childObject);
  246. }
  247. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  248. return DaoEngine.updateData(dataSource, dataobject);
  249. }
  250. public ArrayList<String[]> getSearchResult(int classid, String sql) throws PersistenceException {
  251. MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
  252. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  253. return DaoEngine.getSearchResult(dataSource, sql);
  254. }
  255. public int getFunctionNumber(int classid, String sql) throws PersistenceException {
  256. MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
  257. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  258. return DaoEngine.getFunctionNumber(dataSource, sql);
  259. }
  260. public int executeUpdateSQL(int classid, String sql) throws PersistenceException {
  261. MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
  262. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  263. return DaoEngine.executeUpdateSQL(dataSource, sql);
  264. }
  265. public int[] executeUpdateSQL(int classid, ArrayList<String> sql) throws PersistenceException {
  266. MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
  267. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  268. return DaoEngine.executeUpdateSQL(dataSource, sql);
  269. }
  270. public boolean deleteConstant(String codeName, String keyID) throws PersistenceException {
  271. // MdpConstant constant = sysmodel.getMdpConstantByName(codeName);
  272. // Property uniqueProperty = constant.getTemplate().getUniqueProperty();
  273. PropertyValue propertyValue = new PropertyValue();
  274. // propertyValue.setPropertyName(uniqueProperty.getName());
  275. // propertyValue.setDataType(uniqueProperty.getDataType());
  276. // propertyValue.setPropertyValue(TypeTransformer.transformConstantValue(uniqueProperty,keyID));
  277. // MdpDataSource dataSource =
  278. // sysmodel.getDataSourceByCode(constant.getDataSource());
  279. ArrayList<TemplateImpl> tempList = sysmodel.getTemplates();
  280. MdpDataSource dataSource = null;
  281. for (TemplateImpl template : tempList) {
  282. if (template.getTableName().equals(codeName)) {
  283. Property uniqueProperty = template.getUniqueProperty();
  284. propertyValue.setPropertyName(uniqueProperty.getName());
  285. propertyValue.setDataType(uniqueProperty.getDataType());
  286. propertyValue.setPropertyValue(TypeTransformer.transformConstantValue(
  287. uniqueProperty, keyID));
  288. dataSource = sysmodel.getDataSourceByCode(template.getDataSource());
  289. }
  290. }
  291. return DaoEngine.deleteConstant(dataSource, codeName, propertyValue);
  292. }
  293. public boolean insertConstant(String codeName, ArrayList<PropertyValue> listPropertyValue)
  294. throws TransformTypeException, PersistenceException {
  295. ArrayList<TemplateImpl> tempList = sysmodel.getTemplates();
  296. MdpDataSource dataSource = null;
  297. for (TemplateImpl imp : tempList) {
  298. log.info(imp.getTableName());
  299. if (imp.getTableName().equals(codeName)) {
  300. TypeTransformer.transformConstantValue(imp, listPropertyValue);
  301. dataSource = sysmodel.getDataSourceByCode(imp.getDataSource());
  302. }
  303. }
  304. return DaoEngine.insertConstant(dataSource, codeName, listPropertyValue);
  305. }
  306. public ArrayList<DataContent> searchDataContentByMdpConstant(MdpConstant constant)
  307. throws PersistenceException {
  308. ArrayList<PropertyValue> alPropertyValue = new ArrayList<PropertyValue>();
  309. Template template = constant.getTemplate();
  310. List<PropertyImpl> listProperty = template.getListproperty();
  311. for (int i = 0; i < listProperty.size(); i++) {
  312. Property property = listProperty.get(i);
  313. PropertyValue propertyValue = new PropertyValue();
  314. propertyValue.setPropertyName(property.getName());
  315. propertyValue.setDataType(property.getDataType());
  316. propertyValue.setUnique(property.isUnique());
  317. alPropertyValue.add(propertyValue);
  318. }
  319. MdpDataSource dataSource = sysmodel.getDataSourceByCode(constant.getDataSource());
  320. String codeName = constant.getCodeName();
  321. return DaoEngine.searchAllConstant(dataSource, template.getTableName(), alPropertyValue,
  322. codeName);
  323. }
  324. public ArrayList<DataContent> searchDataContentByTemplate(Template template)
  325. throws PersistenceException {
  326. ArrayList<PropertyValue> alPropertyValue = new ArrayList<PropertyValue>();
  327. List<PropertyImpl> listProperty = template.getListproperty();
  328. for (int i = 0; i < listProperty.size(); i++) {
  329. Property property = listProperty.get(i);
  330. PropertyValue propertyValue = new PropertyValue();
  331. propertyValue.setPropertyName(property.getName());
  332. propertyValue.setDataType(property.getDataType());
  333. propertyValue.setUnique(property.isUnique());
  334. alPropertyValue.add(propertyValue);
  335. }
  336. MdpDataSource dataSource = sysmodel.getDataSourceByCode(template.getDataSource());
  337. return DaoEngine.searchAllConstant(dataSource, template.getTableName(), alPropertyValue);
  338. }
  339. public ArrayList<PropertyValue> searchConstant(String codeName, String keyID)
  340. throws PersistenceException {
  341. ArrayList<PropertyValue> alPropertyValue = new ArrayList<PropertyValue>();
  342. ArrayList<TemplateImpl> tempList = sysmodel.getTemplates();
  343. MdpDataSource dataSource = null;
  344. for (TemplateImpl template : tempList) {
  345. if (template.getTableName().equals(codeName)) {
  346. List<PropertyImpl> listProperty = template.getListproperty();
  347. for (int i = 0; i < listProperty.size(); i++) {
  348. Property property = listProperty.get(i);
  349. PropertyValue propertyValue = new PropertyValue();
  350. propertyValue.setPropertyName(property.getName());
  351. if (property.isUnique()) {
  352. propertyValue.setPropertyValue(TypeTransformer.transformConstantValue(
  353. property, keyID));
  354. }
  355. propertyValue.setDataType(property.getDataType());
  356. propertyValue.setUnique(property.isUnique());
  357. alPropertyValue.add(propertyValue);
  358. }
  359. dataSource = sysmodel.getDataSourceByCode(template.getDataSource());
  360. }
  361. }
  362. return DaoEngine.searchConstant(dataSource, codeName, alPropertyValue);
  363. }
  364. public boolean updateConstant(String codeName, ArrayList<PropertyValue> listPropertyValue)
  365. throws TransformTypeException, PersistenceException {
  366. ArrayList<TemplateImpl> tempList = sysmodel.getTemplates();
  367. MdpDataSource dataSource = null;
  368. for (TemplateImpl imp : tempList) {
  369. // log.info(imp.getTableName());
  370. if (imp.getTableName().equals(codeName)) {
  371. TypeTransformer.transformConstantValue(imp, listPropertyValue);
  372. dataSource = sysmodel.getDataSourceByCode(imp.getDataSource());
  373. }
  374. }
  375. return DaoEngine.updateConstant(dataSource, codeName, listPropertyValue);
  376. }
  377. public ArrayList<String[]> searchPageResult(int classid, String sql, int intPageSize,
  378. int intCurrentPage) throws PersistenceException {
  379. MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
  380. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  381. return DaoEngine.searchPageResult(dataSource, sql, intPageSize, intCurrentPage);
  382. }
  383. // public DataObject generalDataObjectByUploader(int classid, Uploader
  384. // myUploader) {
  385. //
  386. // DataObject object = new DataObject();
  387. // MdpClass mdlclass = sysmodel.getMdpClassByClassID(classid);
  388. // if (mdlclass == null) return null;
  389. // object.setClassid(classid);
  390. // List list = mdlclass.getAllMdpAttributes();
  391. // for (int i = 0; i < list.size(); i++) {
  392. // MdpAttribute attribute = (MdpAttribute)list.get(i);
  393. // if (!attribute.isValidate())continue;
  394. // String value = myUploader.getParameter(attribute.getName());
  395. // if (value != null) {
  396. // Field field = new Field();
  397. // field.setFieldname(attribute.getName());
  398. // field.setFieldvalue(value);
  399. // object.addAttribute(field);
  400. // }
  401. // }
  402. // return object;
  403. // }
  404. public Document generalXmlDocument(HttpServletRequest request) {
  405. Document xmlDoc = null;
  406. /**
  407. * 接受AJAX从客户端传送过来的数据
  408. */
  409. StringBuffer sbxml = new StringBuffer();
  410. String line = null;
  411. try {
  412. BufferedReader reader = request.getReader();
  413. while ((line = reader.readLine()) != null) {
  414. sbxml.append(line);
  415. }
  416. } catch (Exception e) {
  417. log.error(e.toString());
  418. }
  419. String xml = sbxml.toString();
  420. try {
  421. xmlDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
  422. .parse(new ByteArrayInputStream(xml.getBytes()));
  423. } catch (ParserConfigurationException e) {
  424. log.error(e);
  425. } catch (SAXException e) {
  426. log.error(e);
  427. } catch (IOException e) {
  428. log.error(e);
  429. }
  430. return xmlDoc;
  431. }
  432. public DataObject generalDataObject(int classid, Document xmlDoc) {
  433. DataObject object = new DataObject();
  434. MdpClass mdlclass = sysmodel.getMdpClassByClassID(classid);
  435. if (mdlclass == null)
  436. return null;
  437. object.setClassid(classid);
  438. List<MdpAttributeImpl> list = mdlclass.getAllMdpAttributes();
  439. for (int i = 0; i < list.size(); i++) {
  440. MdpAttribute attribute = list.get(i);
  441. if (!attribute.isValidate())
  442. continue;
  443. // log.info("attribute.getName()" + attribute.getName());
  444. String value = null;
  445. if (xmlDoc.getElementsByTagName(attribute.getName()) != null
  446. && xmlDoc.getElementsByTagName(attribute.getName()).getLength() > 0) {
  447. // log.info("xmlDoc.getElementsByTagName(attribute.getName()).item(0) = "
  448. // + xmlDoc.getElementsByTagName(attribute.getName()).item(0));
  449. // log.info("xmlDoc.getElementsByTagName(attribute.getName()).item(0).getFirstChild() = "
  450. // +
  451. // xmlDoc.getElementsByTagName(attribute.getName()).item(0).getFirstChild());
  452. if (xmlDoc.getElementsByTagName(attribute.getName()).item(0).getFirstChild() == null)
  453. value = "";
  454. else
  455. value = xmlDoc.getElementsByTagName(attribute.getName()).item(0)
  456. .getFirstChild().getNodeValue();
  457. // log.info("value = " + value);
  458. }
  459. // log.info("value2 = " + value);
  460. if (value != null) {
  461. Field field = new Field();
  462. field.setFieldname(attribute.getName());
  463. field.setFieldvalue(value);
  464. object.addAttribute(field);
  465. }
  466. }
  467. return object;
  468. }
  469. public DataObject generalDataObjectJson(JSONObject JSONObject) {
  470. String pageid = (String) JSONObject.get("pageid");
  471. FormCollection FormCollection = XFormFactory.getXFormModel().getFormCollection(pageid);
  472. ArrayList<ReportFieldImpl> reportfields = FormCollection.getAllReportFields();
  473. ArrayList<HiddenFieldImpl> hiddenfields = FormCollection.getAlHiddenFields();
  474. DataObject object = new DataObject();
  475. object.setClassid(FormCollection.getClassid());
  476. for (int i = 0; i < reportfields.size(); i++) {
  477. ReportFieldImpl ReportFieldImpl = reportfields.get(i);
  478. String value = (String) JSONObject.get(ReportFieldImpl.getName()) == null ? ""
  479. : (String) JSONObject.get(ReportFieldImpl.getName());
  480. // log.info(ReportFieldImpl.getName()+" = "+value);
  481. Field field = new Field();
  482. field.setFieldname(ReportFieldImpl.getName());
  483. field.setFieldvalue(value);
  484. object.addAttribute(field);
  485. }
  486. for (int i = 0; i < hiddenfields.size(); i++) {
  487. HiddenFieldImpl HiddenFieldImpl = hiddenfields.get(i);
  488. String value = "";
  489. if (!HiddenFieldImpl.getValueMethod().equals("")
  490. || HiddenFieldImpl.getValueMethod() != null) {
  491. if (HiddenFieldImpl.getValueMethod().indexOf("session") != -1) {
  492. value = "123456";
  493. } else if (HiddenFieldImpl.getValueMethod().indexOf("idmake") != -1) {
  494. value = "";
  495. } else if (HiddenFieldImpl.getValueMethod().indexOf("systime") != -1) {
  496. value = "";
  497. }
  498. } else {
  499. value = (String) JSONObject.get(HiddenFieldImpl.getName());
  500. }
  501. Field field = new Field();
  502. field.setFieldname(HiddenFieldImpl.getName());
  503. field.setFieldvalue(JSONObject.get(value));
  504. object.addAttribute(field);
  505. }
  506. return object;
  507. }
  508. public DataObject generalDataObjectBySplit(int classid, HttpServletRequest request) {
  509. DataObject object = new DataObject();
  510. MdpClass mdlclass = sysmodel.getMdpClassByClassID(classid);
  511. if (mdlclass == null)
  512. return null;
  513. object.setClassid(classid);
  514. List<MdpAttributeImpl> list = mdlclass.getAllMdpAttributes();
  515. for (int i = 0; i < list.size(); i++) {
  516. MdpAttribute attribute = list.get(i);
  517. if (!attribute.isValidate())
  518. continue;
  519. // 这个地方只接受页面中DATAMODEL中名称+ “-” 表ID的采集科目
  520. String value = request.getParameter(attribute.getName() + "_" + classid);
  521. if (value != null) {
  522. Field field = new Field();
  523. field.setFieldname(attribute.getName());
  524. field.setFieldvalue(value);
  525. object.addAttribute(field);
  526. } else {
  527. if (attribute.getName().equalsIgnoreCase("UpdateDate")) {
  528. Field field = new Field();
  529. field.setFieldname(attribute.getName());
  530. field.setFieldvalue(Util.getDateTime());
  531. object.addAttribute(field);
  532. }
  533. }
  534. }
  535. return object;
  536. }
  537. public DataObject generalDataObject(int classid, HttpServletRequest request) {
  538. DataObject object = new DataObject();
  539. MdpClass mdlclass = sysmodel.getMdpClassByClassID(classid);
  540. if (mdlclass == null)
  541. return null;
  542. object.setClassid(classid);
  543. List<MdpAttributeImpl> list = mdlclass.getAllMdpAttributes();
  544. for (int i = 0; i < list.size(); i++) {
  545. MdpAttribute attribute = list.get(i);
  546. if (!attribute.isValidate())
  547. continue;
  548. String value = request.getParameter(attribute.getName());
  549. if (value != null) {
  550. Field field = new Field();
  551. field.setFieldname(attribute.getName());
  552. field.setFieldvalue(value);
  553. object.addAttribute(field);
  554. }
  555. }
  556. return object;
  557. }
  558. public ArrayList<Map<String, String>> getSearchResultToMap(int classid, String sql)
  559. throws PersistenceException {
  560. MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
  561. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  562. return DaoEngine.getSearchResultToMap(dataSource, sql);
  563. }
  564. public ArrayList<Map<String, String>> getPagingSearchResultToMap(int classid, String sql,
  565. String firstPageNum, String lastPageNum) throws PersistenceException {
  566. MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
  567. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  568. StringBuffer pagingSql = new StringBuffer();
  569. if (dataSource.getDataBase().equals("oracle")) {
  570. pagingSql.append("SELECT * FROM ( SELECT row_.*, rownum rownum_ FROM (");
  571. pagingSql.append(sql);
  572. pagingSql.append(") row_ WHERE rownum <= ").append(lastPageNum)
  573. .append(") WHERE rownum_ > ").append(firstPageNum);
  574. } else if (dataSource.getDataBase().equals("db2")) {
  575. pagingSql.append("SELECT * FROM ( ");
  576. pagingSql.append(sql);
  577. pagingSql.append(")as a where ROWNUM_ BETWEEN ").append(firstPageNum).append(" and ")
  578. .append(lastPageNum);
  579. } else if (dataSource.getDataBase().equals("sqlserver")) {
  580. pagingSql.append("SELECT * FROM (");
  581. pagingSql.append(sql);
  582. pagingSql.append(") as t where t.ROWNUM_ > " + firstPageNum + " and t.ROWNUM_ < "
  583. + lastPageNum);
  584. }
  585. log.info("列表查询调用SQL = " + pagingSql);
  586. return DaoEngine.getPagingSearchResultToMap(dataSource, pagingSql.toString());
  587. }
  588. /**
  589. * 根据sql条件、及分页条件进行查询,只查询该表数据 吴潇 2009-12-25
  590. *
  591. * @param SQLcondition
  592. * where 后面查询条件
  593. * @return 返回数据集合,每个对象为DataObject
  594. */
  595. public ArrayList<DataObject> getPagingSearchResultToDataObject(int classid,
  596. String SQLcondition, String firstPageNum, String lastPageNum)
  597. throws PersistenceException {
  598. MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
  599. DataObject dataobject = TypeTransformer.getSearchDataObject(mdpClass);
  600. MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
  601. return DaoEngine.getPagingSearchResultToDataObject(dataSource, dataobject, SQLcondition,
  602. firstPageNum, lastPageNum);
  603. }
  604. }