List listHiddenKeys = Arrays.asList(key_hiddens);
DOBO bo = DOBO.getDOBOByName("do_bo");
DOBO selected = DOBO.getDOBOByID(bo.getCorrInstance().getUid());
DODataSource dss = null;
///多租户情况`
if ("true".equals(DOGlobals.getValue("multi.tenancy"))) {
dss = DOGlobals.getInstance().getSessoinContext()
.getTenancyValues().getDataDDS();
} else {//单租户情况
dss = selected.getDataBase();
}
Transaction t = dss.getTransaction();
t.begin();
// /先确定删除的
List list = selected.retrieveProperties();
List propCols = new ArrayList();
for (Iterator it = list.iterator(); it.hasNext();) {
DOBOProperty dop = (DOBOProperty) it.next();
if (dop.getIsPersistence() == null
|| dop.getIsPersistence().intValue() == DOBOProperty.PERSISTENCE_YES) {
propCols.add(dop.getObjUid());
}
}
List removeCols = new ArrayList(propCols);
System.out.println("AllCols::" + removeCols);
removeCols.removeAll(listHiddenKeys);
// //需要删除的字段propCols
System.out.println("RemoveCols::" + removeCols);
for (int i = 0; i < removeCols.size(); i++) {
String colObjuid = (String) removeCols.get(i);
DOBOProperty dop = DOBOProperty.getDOBOPropertyByID(colObjuid);
StringBuffer sb = new StringBuffer("alter table ");
sb.append(selected.getSqlStr()).append(" drop column ").append(
dop.getColName());
listSql.add(sb.toString());
pm.removeProperty(selected, dop);
}
// 先确定新增的
for (int len = 0; len < key_hiddens.length; len++) {
String keyHidden = key_hiddens[len];
if (keyHidden == null || keyHidden.equals("")) {
if (colNames[len] != null && !colNames[len].equals("")) {
DOBOProperty dopExists = DOBOProperty.getDOBOPropertyByName(selected.getName(),
colNames[len]);
if (dopExists==null || dopExists.getColName()==null) {
StringBuffer sb = new StringBuffer("alter table ");
sb.append(selected.getSqlStr()).append(" add ")
.append(colNames[len]).append(" ").append(
dbtypes[len]);
int iDBSize = 255;
if (dbsizes[len] != null && !dbsizes[len].equals("")) {
iDBSize = Integer
.parseInt(dbsizes[len]);
sb.append(" (").append(dbsizes[len]).append(")");
}
listSql.add(sb.toString());
int iType = 12;
try {
iType = Integer.parseInt(map.get(dbtypes[len]
.toLowerCase()));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("ColName:" + colNames[len]
+ " DBSize:" + dbsizes[len]);
pm.addProperty(selected, colNames[len], iType, iDBSize);
}else{
System.out.println("已经存在ColName::" + DOBOProperty.getDOBOPropertyByName(selected.getName(),
colNames[len]));
}
}
}
}
// //确定修改的
Connection con = null;
try {
con = dss.getConnection();
Statement stmt = con.createStatement();
for (Iterator<String> it = listSql.iterator(); it.hasNext();) {
String aSql = it.next();
stmt.execute(aSql);