123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756 |
- /***************************************************
- * Copyright 2009-8-20, -sun,All rights reserved.
- * Create date : 2009-8-20
- * Author : sun
- * MYSQL 数据库表增删 DLL 操作处理类
- **************************************************/
- package com.persistence.DBdll.adapter;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.ResultSetMetaData;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Vector;
- import org.apache.log4j.Logger;
- import com.persistence.DBdll.adapter.assitant.ColumnInfo;
- import com.persistence.DBdll.adapter.assitant.ColumnInfoService;
- import com.persistence.DBdll.adapter.assitant.TableInfo;
- import com.persistence.DBdll.adapter.assitant.index.IndexInfo;
- import com.sysmodel.datamodel.Parameter.DataBaseType;
- import com.sysmodel.datamodel.Parameter.XmlManagerPara;
- import com.sysmodel.datamodel.xmlmodel.able.MdpDataSource;
- import com.sysmodel.datamodel.xmlmodel.able.Property;
- import com.sysmodel.datamodel.xmlmodel.able.Template;
- import com.sysmodel.datamodel.xmlmodel.impl.MdpAttributeImpl;
- import com.sysmodel.datamodel.xmlmodel.impl.MdpClassImpl;
- import com.sysmodel.datamodel.xmlmodel.impl.MdpDataSourceImpl;
- import com.sysmodel.datamodel.xmlmodel.impl.PropertyImpl;
- import com.sysmodel.datamodel.xmlmodel.impl.SysModelImpl;
- // TODO: Auto-generated Javadoc
- /**
- * The Class MysqlAdapter.
- */
- public class MysqlAdapter extends DatabaseAdapter{
- /** The Constant log. */
- private final static Logger log = Logger.getLogger(MysqlAdapter.class);
- /** The Adapter tool. */
- ColumnInfoService columnInfoService = new ColumnInfoService();
- /*
- * (non-Javadoc)
- *
- * @see
- * com.persistence.DBdll.adapter.DatabaseAdapter#createTable(com.sysmodel
- * .datamodel.xmlmodel.impl.MdpClassImpl)
- */
- public boolean createTable(MdpClassImpl table) {
- String sql = generalSQL(table);
- log.info(sql);
- MdpDataSource MdpDataSource = SysModelImpl.getInstance().getDataSourceByCode(
- table.getDataSource());
- return this.executeDDL(MdpDataSource, sql);
- }
- /*
- * (non-Javadoc)
- *
- * @see
- * com.persistence.DBdll.adapter.DatabaseAdapter#updateTable(com.sysmodel
- * .datamodel.xmlmodel.impl.MdpClassImpl)
- */
- public ArrayList<Vector<Object>> updateTable(MdpClassImpl table) {
- MdpDataSource MdpDataSource = SysModelImpl.getInstance().getDataSourceByCode(
- table.getDataSource());
- ArrayList<Vector<Object>> list = new ArrayList<Vector<Object>>();
- try {
- Vector<ColumnInfo> columninfos = getTableColumnInfo(table.getName(), MdpDataSource);
- if (columninfos.size() == 0) {
- return list;
- }
- Vector<Object> dllVec = new Vector<Object>();
- Vector<MdpAttributeImpl> add = columnInfoService.addDataBaseColumn(
- table.getAllMdpAttributes(), columninfos);
- for (int i = 0; i < add.size(); i++) {
- MdpAttributeImpl imp = add.elementAt(i);
- String sql = getTableModifyDllSQL(XmlManagerPara.add, imp, table.getName());
- boolean bresult = executeDDL(MdpDataSource, sql);
- dllVec = new Vector<Object>();
- dllVec.add("add");
- dllVec.add(imp);
- dllVec.add(bresult);
- dllVec.add(sql);
- list.add(dllVec);
- }
- Vector<ColumnInfo> delete = columnInfoService.deleteDataBaseColumn(
- table.getAllMdpAttributes(), columninfos);
- for (int i = 0; i < delete.size(); i++) {
- ColumnInfo imp = delete.elementAt(i);
- String sql = "alter table " + table.getName() + " drop column "
- + imp.getColumnName();
- boolean bresult = executeDDL(MdpDataSource, sql);
- dllVec = new Vector<Object>();
- dllVec.add("delete");
- dllVec.add(imp);
- dllVec.add(bresult);
- dllVec.add(sql);
- list.add(dllVec);
- }
- Vector<MdpAttributeImpl> update = columnInfoService.updateDataBaseColumn(
- table.getAllMdpAttributes(), columninfos);
- for (int i = 0; i < update.size(); i++) {
- MdpAttributeImpl imp = update.elementAt(i);
- String sql = getTableModifyDllSQL(XmlManagerPara.update, imp, table.getName());
- boolean bresult = executeDDL(MdpDataSource, sql);
- dllVec = new Vector<Object>();
- dllVec.add("update");
- dllVec.add(imp);
- dllVec.add(bresult);
- dllVec.add(sql);
- list.add(dllVec);
- }
- ColumnInfo info = columnInfoService
- .getColumnInfoByFieldName(columninfos, "fd_objectid");
- if (info == null) {
- String sql = "alter table " + table.getName() + " add fd_objectid VARCHAR("
- + XmlManagerPara.fd_objectidlength + ")";
- boolean bresult = executeDDL(MdpDataSource, sql);
- dllVec = new Vector<Object>();
- dllVec.add("addfd_objectid");
- dllVec.add("fd_objectid");
- dllVec.add(bresult);
- dllVec.add(sql);
- list.add(dllVec);
- } else {
- if (!info.getColumnTypeName().equalsIgnoreCase("VARCHAR")
- || info.getPrecision() != XmlManagerPara.fd_objectidlength) {
- String sql = "alter table " + table.getName() + " modify fd_objectid VARCHAR("
- + XmlManagerPara.fd_objectidlength + ")";
- boolean bresult = executeDDL(MdpDataSource, sql);
- dllVec = new Vector<Object>();
- dllVec.add("updatefd_objectid");
- dllVec.add("fd_objectid");
- dllVec.add(bresult);
- dllVec.add(sql);
- list.add(dllVec);
- }
- }
- } catch (Exception e) {
- log.error(e.toString());
- }
- return list;
- }
- /*
- * (non-Javadoc)
- *
- * @see
- * com.persistence.DBdll.adapter.DatabaseAdapter#renameTableName(com.sysmodel
- * .datamodel.xmlmodel.impl.MdpClassImpl, java.lang.String)
- */
- public boolean renameTableName(MdpClassImpl table, String newtablename) {
- MdpDataSource MdpDataSource = SysModelImpl.getInstance().getDataSourceByCode(
- table.getDataSource());
- return renameTableName(MdpDataSource, newtablename, table.getName());
- }
- /*
- * (non-Javadoc)
- *
- * @see
- * com.persistence.DBdll.adapter.DatabaseAdapter#updateTableAttribute(java
- * .lang.String, com.sysmodel.datamodel.xmlmodel.impl.MdpAttributeImpl,
- * com.sysmodel.datamodel.xmlmodel.impl.MdpClassImpl)
- */
- public boolean updateTableAttribute(String action, MdpAttributeImpl attribute,
- MdpClassImpl table) {
- MdpDataSource MdpDataSource = SysModelImpl.getInstance().getDataSourceByCode(
- table.getDataSource());
- String sql = getTableModifyDllSQL(action, attribute, table.getName());
- return executeDDL(MdpDataSource, sql);
- }
- /*
- * (non-Javadoc)
- *
- * @see
- * com.persistence.DBdll.adapter.DatabaseAdapter#createConstanTable(com.
- * sysmodel.datamodel.xmlmodel.impl.MdpConstantImpl)
- */
- @Override
- public boolean createConstanTable(Template template) {
- String sql = getCreateConstanTableDLL(template);
- log.info("createsql=" + sql);
- SysModelImpl sysmodel = SysModelImpl.getInstance();
- MdpDataSource MdpDataSource = sysmodel.getDataSourceByCode(template.getDataSource());
- return this.executeDDL(MdpDataSource, sql);
- }
- /*
- * (non-Javadoc)
- *
- * @see
- * com.persistence.DBdll.adapter.DatabaseAdapter#updateConstanTable(com.
- * sysmodel.datamodel.xmlmodel.impl.MdpConstantImpl)
- */
- @Override
- public ArrayList<Vector<Object>> updateConstanTable(Template template) {
- String tableName = template.getTableName();
- MdpDataSource MdpDataSource = SysModelImpl.getInstance().getDataSourceByCode(
- template.getDataSource());
- ArrayList<Vector<Object>> list = new ArrayList<Vector<Object>>();
- try {
- Vector<ColumnInfo> columninfos = getTableColumnInfo(tableName, MdpDataSource);
- if (columninfos.size() == 0) {
- return list;
- }
- List<PropertyImpl> Propertys = template.getListproperty();
- Vector<Object> dllVec = new Vector<Object>();
- // delete column
- Vector<ColumnInfo> delete = columnInfoService.deleteConstantDataBaseColumn(Propertys,
- columninfos);
- for (int i = 0; i < delete.size(); i++) {
- ColumnInfo imp = delete.elementAt(i);
- String sql = "alter table " + tableName + " drop column " + imp.getColumnName();
- boolean bresult = false;// executeDDL(MdpDataSource ,sql);
- dllVec = new Vector<Object>();
- dllVec.add("delete");
- dllVec.add(imp);
- dllVec.add(bresult);
- dllVec.add(sql);
- list.add(dllVec);
- }
- Vector<Property> add = columnInfoService.addConstantDataBaseColumn(Propertys,
- columninfos);
- for (int i = 0; i < add.size(); i++) {
- Property imp = (Property) add.elementAt(i);
- String sql = getCanstantModifyDllSQL(XmlManagerPara.add, imp, tableName);
- boolean bresult = false;// executeDDL(MdpDataSource ,sql);
- dllVec = new Vector<Object>();
- dllVec.add("add");
- dllVec.add(imp);
- dllVec.add(bresult);
- dllVec.add(sql);
- list.add(dllVec);
- }
- Vector<Property> update = columnInfoService.updateConstantDataBaseColumn(Propertys,
- columninfos);
- for (int i = 0; i < update.size(); i++) {
- Property imp = (Property) update.elementAt(i);
- String sql = getCanstantModifyDllSQL(XmlManagerPara.update, imp, tableName);
- boolean bresult = false;// executeDDL(MdpDataSource ,sql);
- dllVec = new Vector<Object>();
- dllVec.add("update");
- dllVec.add(imp);
- dllVec.add(bresult);
- dllVec.add(sql);
- list.add(dllVec);
- }
- } catch (Exception e) {
- log.error(e.toString());
- }
- return list;
- }
- @Override
- public boolean renameConstantTableName(Template template, String newtablename) {
- MdpDataSource MdpDataSource = SysModelImpl.getInstance().getDataSourceByCode(
- template.getDataSource());
- return renameTableName(MdpDataSource, newtablename, template.getTableName());
- }
- /**
- * Rename table name.
- *
- * @param MdpDataSource
- * the mdp data source
- * @param newtablename
- * the newtablename
- * @param oldtablename
- * the oldtablename
- *
- * @return true, if successful
- *
- * @author sun
- * @version 2009-8-20-10:28:52
- *
- * Rename table name.
- */
- private boolean renameTableName(MdpDataSource MdpDataSource, String newtablename,
- String oldtablename) {
- String sql = "sp_rename " + oldtablename + ", " + newtablename;
- log.info("sql = " + sql);
- return executeDDL(MdpDataSource, sql);
- }
- public String getCreateConstanTableDLL(Template template) {
- StringBuffer sql = new StringBuffer();
- sql.append("create table " + template.getTableName()).append("( ");
- ArrayList<PropertyImpl> propertys = (ArrayList<PropertyImpl>) template.getListproperty();
- for (int i = 0; i < propertys.size(); i++) {
- PropertyImpl PropertyImpl = (PropertyImpl) propertys.get(i);
- String fieldname = PropertyImpl.getName();
- String datatype = PropertyImpl.getDataType();
- if (datatype.equals(XmlManagerPara.date)) {
- sql.append(",").append(fieldname).append(" DATETIME");
- } else if (datatype.equals(XmlManagerPara.clob)) {
- sql.append(",").append(fieldname).append(" LONGTEXT");
- } else if (datatype.equals(XmlManagerPara.blob)) {
- sql.append(",").append(fieldname).append(" LONGBLOB");
- } else if (datatype.equals(XmlManagerPara.bool)) {
- sql.append(",").append(fieldname).append(" BIT");
- } else if (datatype.equals(XmlManagerPara.image)) {
- sql.append(",").append(fieldname).append(" VARCHAR(100)");
- } else if (datatype.equals(XmlManagerPara.number)) {
- String scale = PropertyImpl.getScale().equals("") ? "" : ","
- + PropertyImpl.getScale();
- if (scale.equals("")) {
- sql.append("," + fieldname + " float");
- } else {
- int length = PropertyImpl.getLength() == 0 ? 10 : PropertyImpl.getLength();
- sql.append("," + fieldname + " DECIMAL(" + length + scale + ")");
- }
- } else if (datatype.equals(XmlManagerPara.string)) {
- sql.append(",").append(fieldname);
- sql.append(" VARCHAR(").append(PropertyImpl.getLength()).append(")");
- }
- if (PropertyImpl.isUnique()) {
- sql.append(" NOT NULL primary key");
- }
- }
- sql.append(" ) ");
- sql.reverse();
- sql.deleteCharAt(sql.lastIndexOf(","));
- sql.reverse();
- return sql.toString();
- }
- /**
- * General sql.
- *
- * @param table
- * the table
- *
- * @return the string
- *
- * @author sun
- * @version 2009-8-20-10:28:52
- *
- * General sql.
- */
- private String generalSQL(MdpClassImpl table) {
- StringBuffer sql = new StringBuffer();
- sql.append("create table " + table.getName());
- sql.append("(FD_OBJECTID VARCHAR(" + XmlManagerPara.fd_objectidlength
- + ") NOT NULL primary key ");
- ArrayList<MdpAttributeImpl> list = (ArrayList<MdpAttributeImpl>) table
- .getAllMdpAttributes();
- for (int i = 0; i < list.size(); i++) {
- MdpAttributeImpl attribute = list.get(i);
- String fieldname = attribute.getName();
- String datatype = attribute.getDataType();
- if (datatype.equals(XmlManagerPara.date)) {
- sql.append("," + fieldname + " DATETIME");
- } else if (datatype.equals(XmlManagerPara.clob)) {
- sql.append("," + fieldname + " LONGTEXT");
- } else if (datatype.equals(XmlManagerPara.blob)) {
- sql.append("," + fieldname + " LONGBLOB");
- } else if (datatype.equals(XmlManagerPara.bool)) {
- sql.append("," + fieldname + " BIT(" + attribute.getPrecision() + ")");
- if (attribute.getDefaultValue() != null && !attribute.getDefaultValue().equals("")) {
- sql.append(" default " + attribute.getDefaultValue());
- }
- } else if (datatype.equals(XmlManagerPara.image)) {
- sql.append("," + fieldname + " VARCHAR(100)");
- } else if (datatype.equals(XmlManagerPara.number)) {
- int length = attribute.getPrecision() == 0 ? 10 : attribute.getPrecision();
- String scale = attribute.getScale().equals("") ? "" : "," + attribute.getScale();
- if (scale.equals("")) {
- sql.append("," + fieldname + " INTEGER(" + length + ")");
- } else {
- sql.append("," + fieldname + " DECIMAL(" + length + scale + ")");
- }
- if (attribute.getDefaultValue() != null && !attribute.getDefaultValue().equals("")) {
- sql.append(" default " + attribute.getDefaultValue());
- }
- } else if (datatype.equals(XmlManagerPara.string)) {
- sql.append("," + fieldname + " VARCHAR(" + attribute.getPrecision() + ")");
- if (attribute.getDefaultValue() != null && !attribute.getDefaultValue().equals("")) {
- sql.append(" default '" + attribute.getDefaultValue() + "'");
- }
- }
- }
- sql.append(" ) ");
- return sql.toString();
- }
- /**
- * 获得数据库中指定表中列的信息
- *
- * @param tablename
- * @param con
- * @return
- */
- public Vector<ColumnInfo> getTableColumnInfo(String tablename, MdpDataSource datasource) {
- Vector<ColumnInfo> vect = new Vector<ColumnInfo>();
- Connection connection = getConnection(datasource);
- if (connection == null)
- return vect;
- Statement st = null;
- ResultSet rs = null;
- DatabaseTableInfo TableInfo = new DatabaseTableInfo();
- try {
- HashMap<String, String> MapComments = TableInfo.getColComments(connection, tablename,
- DataBaseType.MYSQL);
- st = connection.createStatement();
- rs = st.executeQuery("select * from " + tablename + " where 1=0");
- ResultSetMetaData rm = rs.getMetaData();
- int colCount = rm.getColumnCount();// 取得列数
- ColumnInfo vo = null;
- for (int i = 1; i <= colCount; i++) {
- vo = new ColumnInfo();
- String ColumnName = rm.getColumnName(i);
- vo.setDataBaseType(DataBaseType.MYSQL);
- vo.setTableName(tablename);
- vo.setColumnName(rm.getColumnName(i));
- vo.setColumnType(rm.getColumnType(i));
- vo.setColumnTypeName(rm.getColumnTypeName(i));
- vo.setPrecision(rm.getPrecision(i));
- vo.setScale(rm.getScale(i));
- vo.setDescritpion(MapComments.get(ColumnName));
- vo.setAutoIncrement(rm.isAutoIncrement(i));
- vo.setIsNullable(rm.isNullable(i));
- vo.setReadOnly(rm.isReadOnly(i));
- vo.setSigned(rm.isSigned(i));
- vo.setSearchable(rm.isSearchable(i));
- vo.setColumnDisplaySize(rm.getColumnDisplaySize(i));
- vect.add(vo);
- }
- rs.close();
- st.close();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- if (rs != null)
- rs.close();
- if (st != null)
- st.close();
- if (connection != null)
- connection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return vect;
- }
- /**
- * 获得常量表需要修改的列的DLL sql语句 Gets the canstant modify dll sql.
- *
- * @param action
- * the action
- * @param imp
- * the imp
- * @param tablename
- * the tablename
- *
- * @return the canstant modify dll sql
- *
- * @author sun
- * @version 2009-8-20-10:28:52
- *
- * Gets the canstant modify dll sql.
- */
- private String getCanstantModifyDllSQL(String action, Property imp, String tablename) {
- String sql = "alter table " + tablename;
- if (action.equals(XmlManagerPara.add)) {
- sql = sql + " add ";
- } else if (action.equals(XmlManagerPara.delete)) {
- sql = sql + " drop column " + imp.getName();
- return sql;
- } else if (action.equals(XmlManagerPara.update)) {
- sql = "sp_rename " + tablename + "." + imp.getName() + ", ";
- }
- String fieldname = imp.getName();
- String datatype = imp.getDataType();
- if (datatype.equals(XmlManagerPara.date)) {
- sql = sql + fieldname + " DATETIME";
- } else if (datatype.equals(XmlManagerPara.bool)) {
- sql = sql + fieldname + " BIT(" + imp.getLength() + ")";
- sql = sql + " default null";
- }
- else if (datatype.equals(XmlManagerPara.number)) {
- int length = imp.getLength() == 0 ? 10 : imp.getLength();
- String scale = imp.getScale().equals("") ? "" : "," + imp.getScale();
- sql = sql + fieldname + " DECIMAL(" + length + scale + ")";
- sql = sql + " default null";
- } else if (datatype.equals(XmlManagerPara.string)) {
- sql = sql + fieldname + " varchar(" + imp.getLength() + ")";
- sql = sql + " default null";
- }
- log.info("sql = " + sql);
- return sql;
- }
- /**
- * Gets the table modify dll sql.
- *
- * @param action
- * the action
- * @param attribute
- * the attribute
- * @param tablename
- * the tablename
- *
- * @return the table modify dll sql
- *
- * @author sun
- * @version 2009-8-20-10:28:52
- *
- * Gets the table modify dll sql.
- */
- private String getTableModifyDllSQL(String action, MdpAttributeImpl attribute, String tablename) {
- String sql = "alter table " + tablename;
- if (action.equals(XmlManagerPara.add)) {
- sql = sql + " add ";
- } else if (action.equals(XmlManagerPara.update)) {
- sql = sql + " modify ";
- } else if (action.equals(XmlManagerPara.delete)) {
- sql = sql + " drop column " + attribute.getName();
- return sql;
- }
- String fieldname = attribute.getName();
- String datatype = attribute.getDataType();
- if (datatype.equals(XmlManagerPara.date)) {
- sql = sql + fieldname + " DATETIME";
- } else if (datatype.equals("blob")) {
- sql = sql + fieldname + " LONGBLOB";
- }
- else if (datatype.equals("clob")) {
- sql = sql + fieldname + " LONGTEXT ";
- }
- else if (datatype.equals(XmlManagerPara.bool)) {
- sql = sql + fieldname + " BIT(" + attribute.getPrecision() + ")";
- if (attribute.getDefaultValue() != null && !attribute.getDefaultValue().equals("")) {
- sql = sql + " default " + attribute.getDefaultValue();
- } else {
- sql = sql + " default null";
- }
- }
- else if (datatype.equals(XmlManagerPara.number)) {
- int length = attribute.getPrecision() == 0 ? 10 : attribute.getPrecision();
- String scale = attribute.getScale().equals("") ? "" : "," + attribute.getScale();
- sql = sql + fieldname + " DECIMAL(" + length + scale + ")";
- if (attribute.getDefaultValue() != null && !attribute.getDefaultValue().equals("")) {
- sql = sql + " default " + attribute.getDefaultValue();
- } else {
- sql = sql + " default null";
- }
- }
- else if (datatype.equals(XmlManagerPara.string)) {
- sql = sql + fieldname;
- if (attribute.getPrecision() < 50) {
- sql = sql + " VARCHAR(" + attribute.getPrecision() + ")";
- } else if (attribute.getPrecision() <= 2000 && attribute.getPrecision() >= 50) {
- sql = sql + " VARCHAR(" + attribute.getPrecision() + ")";
- } else {
- sql = sql + " VARCHAR(" + attribute.getPrecision() + ")";
- }
- if (attribute.getDefaultValue() != null && !attribute.getDefaultValue().equals("")) {
- sql = sql + " default '" + attribute.getDefaultValue() + "'";
- } else {
- sql = sql + " default null";
- }
- }
- log.info("sql = " + sql);
- return sql;
- }
- /*
- * (non-Javadoc)
- *
- * @see
- * com.persistence.DBdll.adapter.DatabaseAdapter#getXmlByTableName(java.
- * lang.String, com.sysmodel.datamodel.xmlmodel.able.MdpDataSource,
- * java.lang.String)
- */
- @Override
- public String getXmlByTableName(String tableName, MdpDataSource dataSource, String moduleId) {
- DatabaseTableInfo tableInfo = new DatabaseTableInfo();
- TableInfo tableVo = tableInfo.getTableInfo(tableName, dataSource, DataBaseType.MYSQL);
- Vector<ColumnInfo> ColumnInfoVec = this.getTableColumnInfo(tableName, dataSource);
- MdpDataSourceImpl dataSourceImpl = (MdpDataSourceImpl) dataSource;
- StringBuffer sb = new StringBuffer();
- sb.append(" \n <font color='#339900'>.......................................<br> \n");
- sb.append("<mdpClass classid=\"请替换成推荐号\" ");
- sb.append("name=\"" + tableName + "\" description=\"" + tableVo.getDescritpion()
- + "\" type=\"" + moduleId + "\" ");
- sb.append("primaryKey=\"" + tableVo.getPrimaryKey()
- + "\" exist=\"true\" catche=\"false\" validate=\"true\" ");
- sb.append("dataSource=\"" + dataSourceImpl.getDataSourceid() + "\" ");
- sb.append("><br> \n");
- int ColumnInfoVecSize = ColumnInfoVec.size();
- ColumnInfo ColumnInfo = new ColumnInfo();
- for (int i = 0; i < ColumnInfoVecSize; i++) {
- ColumnInfo = ColumnInfoVec.get(i);
- sb.append(" <mdpAttribute ");
- sb.append(" name=\"" + ColumnInfo.getColumnName() + "\" description=\""
- + ColumnInfo.getDescritpion() + "\"");
- sb.append(ColumnInfo.getColumTypeDetail());
- sb.append(" unit=\"\" logicPrimaryKey=\"false\" referenceType=\"0\" ");
- sb.append(" index=\"false\" indexType=\"\" defaultValue=\"\" notNull=\"false\" validate=\"true\" ");
- sb.append(" isAutoIncrement=\"false\" isReadOnly=\"false\" isSearchable=\"true\" isSigned=\"false\" ");
- sb.append(" columnDisplaySize=\"" + ColumnInfo.getColumnDisplaySize()
- + "\" fieldType=\"" + ColumnInfo.getColumnTypeName() + "("
- + ColumnInfo.getPrecision() + ")\" ");
- sb.append(" />");
- sb.append("<br> \n");
- }
- sb.append("</mdpClass><br>");
- sb.append("........................................<br></font>");
- ColumnInfoVec.clear();
- return sb.toString();
- }
- /*
- * (non-Javadoc)
- *
- * @see
- * com.persistence.DBdll.adapter.DatabaseAdapter#createConstanTableComment
- * (com.sysmodel.datamodel.xmlmodel.impl.MdpConstantImpl, java.lang.String)
- */
- @Override
- public StringBuffer createConstanTableComment(Template template, String type) {
- return null;
- }
- /*
- * (non-Javadoc)
- *
- * @see
- * com.persistence.DBdll.adapter.DatabaseAdapter#createOldTableComment(com
- * .sysmodel.datamodel.xmlmodel.impl.MdpClassImpl, java.lang.String)
- */
- @Override
- public StringBuffer createOldTableComment(MdpClassImpl table, String type) {
- // TODO Auto-generated method stub
- return null;
- }
- /*
- * (non-Javadoc)
- *
- * @see
- * com.persistence.DBdll.adapter.DatabaseAdapter#createTableComment(com.
- * sysmodel.datamodel.xmlmodel.impl.MdpClassImpl, java.lang.String)
- */
- @Override
- public StringBuffer createTableComment(MdpClassImpl table, String type) {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public ArrayList<String> getTableCreateKeyDll(int iDataSource) {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public ArrayList<IndexInfo> getTableIndexInfo() {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public ArrayList<String> getTableIndexCreateDll() {
- // TODO Auto-generated method stub
- return null;
- }
- }
- /*
- * //mysql : select TABLE_NAME from INFORMATION_SCHEMA.TABLES where
- * TABLE_SCHEMA='"+DbName+"'; //mysql : select TABLE_NAME from
- * INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='"+DbName+"';
- *//**
- * 获得Mysql数据库名称 Gets the mysql db name.
- *
- * @param dataSource
- * the data source
- *
- * @return the mysql db name
- */
- /*
- * private String getMysqlDbName(MdpDataSource dataSource){ String Url =
- * dataSource.getURL(); String str = Url.substring(0,Url.indexOf('?')); str =
- * str.substring(str.lastIndexOf('/') + 1); return str; }
- */
|