123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685 |
- package com.persistence.service.assitant;
- import java.io.BufferedReader;
- import java.io.ByteArrayInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.io.Reader;
- import java.io.Writer;
- import java.sql.Connection;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import javax.servlet.http.HttpServletRequest;
- import javax.xml.parsers.DocumentBuilderFactory;
- import javax.xml.parsers.ParserConfigurationException;
- import net.sf.json.JSONObject;
- import org.apache.log4j.Logger;
- import org.w3c.dom.Document;
- import org.xml.sax.SAXException;
- import com.sysmodel.Util;
- import com.sysmodel.XFormFactory;
- import com.sysmodel.collectmodel.xmlmodel.able.FormCollection;
- import com.sysmodel.collectmodel.xmlmodel.impl.HiddenFieldImpl;
- import com.sysmodel.collectmodel.xmlmodel.impl.ReportFieldImpl;
- import com.sysmodel.datamodel.xmlmodel.DataContent;
- import com.sysmodel.datamodel.xmlmodel.PropertyValue;
- import com.sysmodel.datamodel.xmlmodel.able.MdpAttribute;
- import com.sysmodel.datamodel.xmlmodel.able.MdpClass;
- import com.sysmodel.datamodel.xmlmodel.able.MdpConstant;
- import com.sysmodel.datamodel.xmlmodel.able.MdpDataSource;
- import com.sysmodel.datamodel.xmlmodel.able.Property;
- import com.sysmodel.datamodel.xmlmodel.able.Relation;
- import com.sysmodel.datamodel.xmlmodel.able.SysModel;
- import com.sysmodel.datamodel.xmlmodel.able.Template;
- import com.sysmodel.datamodel.xmlmodel.impl.MdpAttributeImpl;
- import com.sysmodel.datamodel.xmlmodel.impl.PropertyImpl;
- import com.sysmodel.datamodel.xmlmodel.impl.RelationImpl;
- import com.sysmodel.datamodel.xmlmodel.impl.TemplateImpl;
- import com.persistence.service.SysPersistence;
- import com.persistence.service.exception.PersistenceException;
- import com.persistence.service.exception.TransformTypeException;
- import com.persistence.service.logic.LogicFactory;
- import com.persistence.service.logic.LogicHelper;
- /**
- * sysmodel com.sysmodel.persistence create time 2006-5-18
- *
- * @author nbs
- */
- public class SysPersistenceImpl implements SysPersistence{
- private final static Logger log = Logger.getLogger(SysPersistenceImpl.class);
- private SysModel sysmodel = null;
- public SysPersistenceImpl(SysModel sysmodel) {
- this.sysmodel = sysmodel;
- }
- public String addObjectData(DataObject dataobject) throws TransformTypeException,
- PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(dataobject.getIntClassid());
- // 类型转换
- TypeTransformer.transformString(mdpClass, dataobject);
- // 子表类型转换
- List<DataObject> child = dataobject.getChildobject();
- for (int i = 0; i < child.size(); i++) {
- DataObject childObject = child.get(i);
- MdpClass childMdpClass = sysmodel.getMdpClassByClassID(childObject.getIntClassid());
- TypeTransformer.transformString(childMdpClass, childObject);
- }
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- return DaoEngine.insertData(dataSource, dataobject);
- }
- public Connection getConnection() {
- return getConnection(99);
- }
- public Connection getConnection(int claasid) {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(claasid);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- LogicHelper helper = LogicFactory.getInstance(dataSource.getDataBase());
- return helper.getConnection(dataSource);
- }
- public String addChildData(DataObject dataobject, String parentid)
- throws TransformTypeException, PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(dataobject.getIntClassid());
- // 类型转换
- TypeTransformer.transformString(mdpClass, dataobject);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- return DaoEngine.insertChildData(dataSource, dataobject, parentid);
- }
- public boolean deleteChildData(int classid, String parentid) throws PersistenceException {
- // return this.deleteChildData(classid, parentid, false);
- // 为了当前系统可用,临时真删除
- return this.deleteChildData(classid, parentid, true);
- }
- public boolean deleteData(String objectID, int classid) throws PersistenceException {
- // 为了当前系统可用,临时真删除
- return this.deleteData(objectID, classid, true);
- // return this.deleteData(objectID, classid, false);
- }
- public boolean deleteChildData(int classid, String parentid, boolean isreal)
- throws PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- return DaoEngine.deleteChildData(dataSource, mdpClass.getName(), parentid, isreal);
- }
- public boolean deleteData(String objectID, int classid, boolean isreal)
- throws PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- DataObject object = new DataObject();
- object.setClassid(mdpClass.getClassid());
- object.setTablename(mdpClass.getName());
- object.setObjectID(objectID);
- List<RelationImpl> relationList = mdpClass.getRelations();
- for (int i = 0; i < relationList.size(); i++) {
- Relation relation = relationList.get(i);
- if (relation.getType() == Relation.REALTION_MASTER) {
- MdpClass childClass = sysmodel.getMdpClassByClassID(relation.getGuestClassid());
- DataObject childObject = new DataObject();
- childObject.setClassid(childClass.getClassid());
- childObject.setTablename(childClass.getName());
- object.addChildObject(childObject);
- }
- }
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- return DaoEngine.deleteData(dataSource, object, isreal);
- }
- public String getDataBaseTime() throws PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(99);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- return DaoEngine.getDataBaseTime(dataSource);
- }
- public void readBlobToOutputStream(int classid, String objectID, String attributeName,
- OutputStream os) throws TransformTypeException, PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- MdpAttribute attribute = mdpClass.getMdpAttributeByName(attributeName);
- if (attribute == null)
- throw new TransformTypeException("not have " + attributeName + " in "
- + mdpClass.getName());
- DataObject object = new DataObject();
- object.setClassid(mdpClass.getClassid());
- object.setTablename(mdpClass.getName());
- object.setObjectID(objectID);
- Field field = new Field(attributeName, null);
- field.setDataType(attribute.getDataType());
- object.addAttribute(field);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- DaoEngine.readBlobToOutputStream(dataSource, object, os);
- }
- public void readClobToWriter(int classid, String objectID, String attributeName, Writer writer)
- throws TransformTypeException, PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- MdpAttribute attribute = mdpClass.getMdpAttributeByName(attributeName);
- if (attribute == null)
- throw new TransformTypeException("not have " + attributeName + " in "
- + mdpClass.getName());
- DataObject object = new DataObject();
- object.setClassid(mdpClass.getClassid());
- object.setTablename(mdpClass.getName());
- object.setObjectID(objectID);
- Field field = new Field(attributeName, null);
- field.setDataType(attribute.getDataType());
- object.addAttribute(field);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- DaoEngine.readClobToWriter(dataSource, object, writer);
- }
- public ArrayList<DataObject> searchAllData(int classid, List<Field> condition)
- throws TransformTypeException, PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- TypeTransformer.transformString(mdpClass, condition);
- DataObject dataobject = TypeTransformer.getSearchDataObject(mdpClass);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- return DaoEngine.searchAllData(dataSource, dataobject, condition);
- }
- public ArrayList<DataObject> searchAllData(int classid, String SQLcondition)
- throws TransformTypeException, PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- DataObject dataobject = TypeTransformer.getSearchDataObject(mdpClass);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- return DaoEngine.searchAllData(dataSource, dataobject, SQLcondition);
- }
- public ArrayList<DataObject> searchChildObjectData(String parentid, int classid)
- throws PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- DataObject dataobject = TypeTransformer.getSearchDataObject(mdpClass);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- return DaoEngine.searchChildData(dataSource, dataobject, parentid);
- }
- public DataObject searchObjectData(String objectID, int classid) throws PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- DataObject dataobject = TypeTransformer.getSearchDataObject(mdpClass);
- dataobject.setObjectID(objectID);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- return DaoEngine.searchData(dataSource, dataobject);
- }
- public DataObject searchObjectData(String objectID, int classid, String objectIDName)
- throws PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- DataObject dataobject = TypeTransformer.getSearchDataObject(mdpClass);
- dataobject.setObjectID(objectID);
- dataobject.setObjectIDName(objectIDName);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- return DaoEngine.searchData(dataSource, dataobject);
- }
- public void storeBlob(int classid, String objectID, String attributeName, InputStream is)
- throws TransformTypeException, PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- MdpAttribute attribute = mdpClass.getMdpAttributeByName(attributeName);
- if (attribute == null)
- throw new TransformTypeException("not have " + attributeName + " in "
- + mdpClass.getName());
- DataObject object = new DataObject();
- object.setClassid(mdpClass.getClassid());
- object.setTablename(mdpClass.getName());
- object.setObjectID(objectID);
- Field field = new Field(attributeName, null);
- field.setDataType(attribute.getDataType());
- object.addAttribute(field);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- DaoEngine.storeBlob(dataSource, object, is);
- }
- public void storeClob(int classid, String objectID, String attributeName, Reader reader)
- throws TransformTypeException, PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- MdpAttribute attribute = mdpClass.getMdpAttributeByName(attributeName);
- if (attribute == null)
- throw new TransformTypeException("not have " + attributeName + " in "
- + mdpClass.getName());
- DataObject object = new DataObject();
- object.setClassid(mdpClass.getClassid());
- object.setTablename(mdpClass.getName());
- object.setObjectID(objectID);
- Field field = new Field(attributeName, null);
- field.setDataType(attribute.getDataType());
- object.addAttribute(field);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- DaoEngine.storeClob(dataSource, object, reader);
- }
- public boolean updateObjectData(DataObject dataobject) throws TransformTypeException,
- PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(dataobject.getIntClassid());
- // 类型转换
- TypeTransformer.transformString(mdpClass, dataobject);
- // 子表类型转换
- List<DataObject> child = dataobject.getChildobject();
- for (int i = 0; i < child.size(); i++) {
- DataObject childObject = child.get(i);
- MdpClass childMdpClass = sysmodel.getMdpClassByClassID(childObject.getIntClassid());
- TypeTransformer.transformString(childMdpClass, childObject);
- }
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- return DaoEngine.updateData(dataSource, dataobject);
- }
- public ArrayList<String[]> getSearchResult(int classid, String sql) throws PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- return DaoEngine.getSearchResult(dataSource, sql);
- }
- public int getFunctionNumber(int classid, String sql) throws PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- return DaoEngine.getFunctionNumber(dataSource, sql);
- }
- public int executeUpdateSQL(int classid, String sql) throws PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- return DaoEngine.executeUpdateSQL(dataSource, sql);
- }
- public int[] executeUpdateSQL(int classid, ArrayList<String> sql) throws PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- return DaoEngine.executeUpdateSQL(dataSource, sql);
- }
- public boolean deleteConstant(String codeName, String keyID) throws PersistenceException {
- // MdpConstant constant = sysmodel.getMdpConstantByName(codeName);
- // Property uniqueProperty = constant.getTemplate().getUniqueProperty();
- PropertyValue propertyValue = new PropertyValue();
- // propertyValue.setPropertyName(uniqueProperty.getName());
- // propertyValue.setDataType(uniqueProperty.getDataType());
- // propertyValue.setPropertyValue(TypeTransformer.transformConstantValue(uniqueProperty,keyID));
- // MdpDataSource dataSource =
- // sysmodel.getDataSourceByCode(constant.getDataSource());
- ArrayList<TemplateImpl> tempList = sysmodel.getTemplates();
- MdpDataSource dataSource = null;
- for (TemplateImpl template : tempList) {
- if (template.getTableName().equals(codeName)) {
- Property uniqueProperty = template.getUniqueProperty();
- propertyValue.setPropertyName(uniqueProperty.getName());
- propertyValue.setDataType(uniqueProperty.getDataType());
- propertyValue.setPropertyValue(TypeTransformer.transformConstantValue(
- uniqueProperty, keyID));
- dataSource = sysmodel.getDataSourceByCode(template.getDataSource());
- }
- }
- return DaoEngine.deleteConstant(dataSource, codeName, propertyValue);
- }
- public boolean insertConstant(String codeName, ArrayList<PropertyValue> listPropertyValue)
- throws TransformTypeException, PersistenceException {
- ArrayList<TemplateImpl> tempList = sysmodel.getTemplates();
- MdpDataSource dataSource = null;
- for (TemplateImpl imp : tempList) {
- log.info(imp.getTableName());
- if (imp.getTableName().equals(codeName)) {
- TypeTransformer.transformConstantValue(imp, listPropertyValue);
- dataSource = sysmodel.getDataSourceByCode(imp.getDataSource());
- }
- }
- return DaoEngine.insertConstant(dataSource, codeName, listPropertyValue);
- }
- public ArrayList<DataContent> searchDataContentByMdpConstant(MdpConstant constant)
- throws PersistenceException {
- ArrayList<PropertyValue> alPropertyValue = new ArrayList<PropertyValue>();
- Template template = constant.getTemplate();
- List<PropertyImpl> listProperty = template.getListproperty();
- for (int i = 0; i < listProperty.size(); i++) {
- Property property = listProperty.get(i);
- PropertyValue propertyValue = new PropertyValue();
- propertyValue.setPropertyName(property.getName());
- propertyValue.setDataType(property.getDataType());
- propertyValue.setUnique(property.isUnique());
- alPropertyValue.add(propertyValue);
- }
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(constant.getDataSource());
- String codeName = constant.getCodeName();
- return DaoEngine.searchAllConstant(dataSource, template.getTableName(), alPropertyValue,
- codeName);
- }
- public ArrayList<DataContent> searchDataContentByTemplate(Template template)
- throws PersistenceException {
- ArrayList<PropertyValue> alPropertyValue = new ArrayList<PropertyValue>();
- List<PropertyImpl> listProperty = template.getListproperty();
- for (int i = 0; i < listProperty.size(); i++) {
- Property property = listProperty.get(i);
- PropertyValue propertyValue = new PropertyValue();
- propertyValue.setPropertyName(property.getName());
- propertyValue.setDataType(property.getDataType());
- propertyValue.setUnique(property.isUnique());
- alPropertyValue.add(propertyValue);
- }
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(template.getDataSource());
- return DaoEngine.searchAllConstant(dataSource, template.getTableName(), alPropertyValue);
- }
- public ArrayList<PropertyValue> searchConstant(String codeName, String keyID)
- throws PersistenceException {
- ArrayList<PropertyValue> alPropertyValue = new ArrayList<PropertyValue>();
- ArrayList<TemplateImpl> tempList = sysmodel.getTemplates();
- MdpDataSource dataSource = null;
- for (TemplateImpl template : tempList) {
- if (template.getTableName().equals(codeName)) {
- List<PropertyImpl> listProperty = template.getListproperty();
- for (int i = 0; i < listProperty.size(); i++) {
- Property property = listProperty.get(i);
- PropertyValue propertyValue = new PropertyValue();
- propertyValue.setPropertyName(property.getName());
- if (property.isUnique()) {
- propertyValue.setPropertyValue(TypeTransformer.transformConstantValue(
- property, keyID));
- }
- propertyValue.setDataType(property.getDataType());
- propertyValue.setUnique(property.isUnique());
- alPropertyValue.add(propertyValue);
- }
- dataSource = sysmodel.getDataSourceByCode(template.getDataSource());
- }
- }
- return DaoEngine.searchConstant(dataSource, codeName, alPropertyValue);
- }
- public boolean updateConstant(String codeName, ArrayList<PropertyValue> listPropertyValue)
- throws TransformTypeException, PersistenceException {
- ArrayList<TemplateImpl> tempList = sysmodel.getTemplates();
- MdpDataSource dataSource = null;
- for (TemplateImpl imp : tempList) {
- // log.info(imp.getTableName());
- if (imp.getTableName().equals(codeName)) {
- TypeTransformer.transformConstantValue(imp, listPropertyValue);
- dataSource = sysmodel.getDataSourceByCode(imp.getDataSource());
- }
- }
- return DaoEngine.updateConstant(dataSource, codeName, listPropertyValue);
- }
- public ArrayList<String[]> searchPageResult(int classid, String sql, int intPageSize,
- int intCurrentPage) throws PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- return DaoEngine.searchPageResult(dataSource, sql, intPageSize, intCurrentPage);
- }
- // public DataObject generalDataObjectByUploader(int classid, Uploader
- // myUploader) {
- //
- // DataObject object = new DataObject();
- // MdpClass mdlclass = sysmodel.getMdpClassByClassID(classid);
- // if (mdlclass == null) return null;
- // object.setClassid(classid);
- // List list = mdlclass.getAllMdpAttributes();
- // for (int i = 0; i < list.size(); i++) {
- // MdpAttribute attribute = (MdpAttribute)list.get(i);
- // if (!attribute.isValidate())continue;
- // String value = myUploader.getParameter(attribute.getName());
- // if (value != null) {
- // Field field = new Field();
- // field.setFieldname(attribute.getName());
- // field.setFieldvalue(value);
- // object.addAttribute(field);
- // }
- // }
- // return object;
- // }
- public Document generalXmlDocument(HttpServletRequest request) {
- Document xmlDoc = null;
- /**
- * 接受AJAX从客户端传送过来的数据
- */
- StringBuffer sbxml = new StringBuffer();
- String line = null;
- try {
- BufferedReader reader = request.getReader();
- while ((line = reader.readLine()) != null) {
- sbxml.append(line);
- }
- } catch (Exception e) {
- log.error(e.toString());
- }
- String xml = sbxml.toString();
- try {
- xmlDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
- .parse(new ByteArrayInputStream(xml.getBytes()));
- } catch (ParserConfigurationException e) {
- log.error(e);
- } catch (SAXException e) {
- log.error(e);
- } catch (IOException e) {
- log.error(e);
- }
- return xmlDoc;
- }
- public DataObject generalDataObject(int classid, Document xmlDoc) {
- DataObject object = new DataObject();
- MdpClass mdlclass = sysmodel.getMdpClassByClassID(classid);
- if (mdlclass == null)
- return null;
- object.setClassid(classid);
- List<MdpAttributeImpl> list = mdlclass.getAllMdpAttributes();
- for (int i = 0; i < list.size(); i++) {
- MdpAttribute attribute = list.get(i);
- if (!attribute.isValidate())
- continue;
- // log.info("attribute.getName()" + attribute.getName());
- String value = null;
- if (xmlDoc.getElementsByTagName(attribute.getName()) != null
- && xmlDoc.getElementsByTagName(attribute.getName()).getLength() > 0) {
- // log.info("xmlDoc.getElementsByTagName(attribute.getName()).item(0) = "
- // + xmlDoc.getElementsByTagName(attribute.getName()).item(0));
- // log.info("xmlDoc.getElementsByTagName(attribute.getName()).item(0).getFirstChild() = "
- // +
- // xmlDoc.getElementsByTagName(attribute.getName()).item(0).getFirstChild());
- if (xmlDoc.getElementsByTagName(attribute.getName()).item(0).getFirstChild() == null)
- value = "";
- else
- value = xmlDoc.getElementsByTagName(attribute.getName()).item(0)
- .getFirstChild().getNodeValue();
- // log.info("value = " + value);
- }
- // log.info("value2 = " + value);
- if (value != null) {
- Field field = new Field();
- field.setFieldname(attribute.getName());
- field.setFieldvalue(value);
- object.addAttribute(field);
- }
- }
- return object;
- }
- public DataObject generalDataObjectJson(JSONObject JSONObject) {
- String pageid = (String) JSONObject.get("pageid");
- FormCollection FormCollection = XFormFactory.getXFormModel().getFormCollection(pageid);
- ArrayList<ReportFieldImpl> reportfields = FormCollection.getAllReportFields();
- ArrayList<HiddenFieldImpl> hiddenfields = FormCollection.getAlHiddenFields();
- DataObject object = new DataObject();
- object.setClassid(FormCollection.getClassid());
- for (int i = 0; i < reportfields.size(); i++) {
- ReportFieldImpl ReportFieldImpl = reportfields.get(i);
- String value = (String) JSONObject.get(ReportFieldImpl.getName()) == null ? ""
- : (String) JSONObject.get(ReportFieldImpl.getName());
- // log.info(ReportFieldImpl.getName()+" = "+value);
- Field field = new Field();
- field.setFieldname(ReportFieldImpl.getName());
- field.setFieldvalue(value);
- object.addAttribute(field);
- }
- for (int i = 0; i < hiddenfields.size(); i++) {
- HiddenFieldImpl HiddenFieldImpl = hiddenfields.get(i);
- String value = "";
- if (!HiddenFieldImpl.getValueMethod().equals("")
- || HiddenFieldImpl.getValueMethod() != null) {
- if (HiddenFieldImpl.getValueMethod().indexOf("session") != -1) {
- value = "123456";
- } else if (HiddenFieldImpl.getValueMethod().indexOf("idmake") != -1) {
- value = "";
- } else if (HiddenFieldImpl.getValueMethod().indexOf("systime") != -1) {
- value = "";
- }
- } else {
- value = (String) JSONObject.get(HiddenFieldImpl.getName());
- }
- Field field = new Field();
- field.setFieldname(HiddenFieldImpl.getName());
- field.setFieldvalue(JSONObject.get(value));
- object.addAttribute(field);
- }
- return object;
- }
- public DataObject generalDataObjectBySplit(int classid, HttpServletRequest request) {
- DataObject object = new DataObject();
- MdpClass mdlclass = sysmodel.getMdpClassByClassID(classid);
- if (mdlclass == null)
- return null;
- object.setClassid(classid);
- List<MdpAttributeImpl> list = mdlclass.getAllMdpAttributes();
- for (int i = 0; i < list.size(); i++) {
- MdpAttribute attribute = list.get(i);
- if (!attribute.isValidate())
- continue;
- // 这个地方只接受页面中DATAMODEL中名称+ “-” 表ID的采集科目
- String value = request.getParameter(attribute.getName() + "_" + classid);
- if (value != null) {
- Field field = new Field();
- field.setFieldname(attribute.getName());
- field.setFieldvalue(value);
- object.addAttribute(field);
- } else {
- if (attribute.getName().equalsIgnoreCase("UpdateDate")) {
- Field field = new Field();
- field.setFieldname(attribute.getName());
- field.setFieldvalue(Util.getDateTime());
- object.addAttribute(field);
- }
- }
- }
- return object;
- }
- public DataObject generalDataObject(int classid, HttpServletRequest request) {
- DataObject object = new DataObject();
- MdpClass mdlclass = sysmodel.getMdpClassByClassID(classid);
- if (mdlclass == null)
- return null;
- object.setClassid(classid);
- List<MdpAttributeImpl> list = mdlclass.getAllMdpAttributes();
- for (int i = 0; i < list.size(); i++) {
- MdpAttribute attribute = list.get(i);
- if (!attribute.isValidate())
- continue;
- String value = request.getParameter(attribute.getName());
- if (value != null) {
- Field field = new Field();
- field.setFieldname(attribute.getName());
- field.setFieldvalue(value);
- object.addAttribute(field);
- }
- }
- return object;
- }
- public ArrayList<Map<String, String>> getSearchResultToMap(int classid, String sql)
- throws PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- return DaoEngine.getSearchResultToMap(dataSource, sql);
- }
- public ArrayList<Map<String, String>> getPagingSearchResultToMap(int classid, String sql,
- String firstPageNum, String lastPageNum) throws PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- StringBuffer pagingSql = new StringBuffer();
- if (dataSource.getDataBase().equals("oracle")) {
- pagingSql.append("SELECT * FROM ( SELECT row_.*, rownum rownum_ FROM (");
- pagingSql.append(sql);
- pagingSql.append(") row_ WHERE rownum <= ").append(lastPageNum)
- .append(") WHERE rownum_ > ").append(firstPageNum);
- } else if (dataSource.getDataBase().equals("db2")) {
- pagingSql.append("SELECT * FROM ( ");
- pagingSql.append(sql);
- pagingSql.append(")as a where ROWNUM_ BETWEEN ").append(firstPageNum).append(" and ")
- .append(lastPageNum);
- } else if (dataSource.getDataBase().equals("sqlserver")) {
- pagingSql.append("SELECT * FROM (");
- pagingSql.append(sql);
- pagingSql.append(") as t where t.ROWNUM_ > " + firstPageNum + " and t.ROWNUM_ < "
- + lastPageNum);
- }
- log.info("列表查询调用SQL = " + pagingSql);
- return DaoEngine.getPagingSearchResultToMap(dataSource, pagingSql.toString());
- }
- /**
- * 根据sql条件、及分页条件进行查询,只查询该表数据 吴潇 2009-12-25
- *
- * @param SQLcondition
- * where 后面查询条件
- * @return 返回数据集合,每个对象为DataObject
- */
- public ArrayList<DataObject> getPagingSearchResultToDataObject(int classid,
- String SQLcondition, String firstPageNum, String lastPageNum)
- throws PersistenceException {
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(classid);
- DataObject dataobject = TypeTransformer.getSearchDataObject(mdpClass);
- MdpDataSource dataSource = sysmodel.getDataSourceByCode(mdpClass.getDataSource());
- return DaoEngine.getPagingSearchResultToDataObject(dataSource, dataobject, SQLcondition,
- firstPageNum, lastPageNum);
- }
- }
|