package com.vci.server.omd.linktype.delegate;
|
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import org.apache.commons.lang3.ArrayUtils;
|
import org.hibernate.Session;
|
|
import com.vci.corba.omd.atm.AttribItem;
|
import com.vci.corba.omd.ltm.LinkType;
|
import com.vci.omd.constants.LinkTypeConstants;
|
import com.vci.server.base.exception.ExceptionLocalHandler;
|
import com.vci.server.base.persistence.dao.HibernateSessionFactory;
|
import com.vci.server.base.utility.OmdHelper;
|
import com.vci.server.cache.OMCacheProvider;
|
import com.vci.server.omd.ddlTool.DDLHelper;
|
import com.vci.server.omd.linktype.cache.LinkTypeCacheUtil;
|
import com.vci.server.omd.linktype.service.LTService;
|
import com.vci.common.exception.VciExceptionTool;
|
import com.vci.common.log.ServerWithLog4j;
|
import com.vci.corba.common.VCIError;
|
|
public class LinkTypeServerDelegate {
|
|
// private final String otherFieldLt = "\n\tOID VARCHAR2(36) not null," +
|
// "\n\tCreator VARCHAR2(36),\n\tCreateTime TIMESTAMP,\n\tLastModifier VARCHAR2(36)," +
|
// "\n\tLastModifyTime TIMESTAMP,\n\tF_OID VARCHAR2(36) not null,\n\tF_REVISIONOID VARCHAR2(36)," +
|
// "\n\tF_NAMEOID VARCHAR2(36),\n\tF_BtwName VARCHAR2(36),\n\tT_OID VARCHAR2(36) not null,\n\tT_REVISIONOID VARCHAR2(36)," +
|
// "\n\tT_NAMEOID VARCHAR2(36),\n\tT_BtwName VARCHAR2(36),\n\tTS TIMESTAMP,\n\t";
|
|
|
private static LinkTypeServerDelegate instance;
|
|
private LinkTypeServerDelegate() {
|
|
}
|
|
public static LinkTypeServerDelegate getInstance() {
|
if (instance == null) {
|
instance = new LinkTypeServerDelegate();
|
}
|
|
return instance;
|
}
|
|
protected VCIError getLocalVciError(String key, Throwable e) {
|
VCIError error = new VCIError(key, new String[]{VciExceptionTool.getExceptionStr(e), VciExceptionTool.getExceptionDetail(e)});
|
VCIError rsError = ExceptionLocalHandler.getInstance().getLocalString(error, "PLMLINK");
|
return rsError;
|
}
|
|
public LinkType getLinkType(String name) throws VCIError {
|
return OMCacheProvider.getLinkType(name);
|
}
|
|
public LinkType[] getLinkTypes() throws VCIError {
|
return OMCacheProvider.getLinkTypes();
|
}
|
|
public String getLTData() throws VCIError {
|
return "";//LTServerCacheUtil.getInstance().getLTData();
|
}
|
|
public String[] getLTNamesByAPName(String apName) throws VCIError {
|
LinkType[] lts = OMCacheProvider.getLinkTypes();
|
|
List<String> lstLTName = new ArrayList<String>();
|
for (LinkType lt : lts) {
|
for (int i = 0; i < lt.attributes.length; i++) {
|
if (lt.attributes[i].equalsIgnoreCase(apName)) {
|
lstLTName.add(lt.name);
|
break;
|
}
|
}
|
}
|
|
return lstLTName.toArray(new String[0]);
|
}
|
|
|
public LinkType[] getLinkTypeByBtmName(String btmName, String direction) throws VCIError {
|
LinkType[] lts = OMCacheProvider.getLinkTypes();
|
|
List<LinkType> lstLT = new ArrayList<LinkType>();
|
for (LinkType lt : lts) {
|
if (LinkTypeConstants.Direction_From.equals(direction)) {
|
if (ArrayUtils.contains(lt.btmItemsFrom, btmName))
|
lstLT.add(lt);
|
} else {
|
if (ArrayUtils.contains(lt.btmItemsTo, btmName))
|
lstLT.add(lt);
|
}
|
}
|
|
return lstLT.toArray(new LinkType[0]);
|
}
|
|
public boolean addLinkType(LinkType lt) throws VCIError {
|
try{
|
boolean success = LTService.getInstance().addLinkType(lt);
|
|
if (success) {
|
createTable(lt.name);
|
}
|
|
if (success) {
|
LinkTypeCacheUtil.setLinkType(lt);
|
}
|
return success;
|
}catch(Throwable e){
|
ServerWithLog4j.logger.error("addLinkType", e);
|
throw getLocalVciError("P0010LINK-00001", e);
|
}
|
}
|
|
public boolean modifyLinkType(LinkType lt) throws VCIError {
|
try{
|
boolean success = LTService.getInstance().modifyLinkTypeTable(lt);
|
|
if (success) {
|
success = LTService.getInstance().modifyLinkType(lt);
|
}
|
if (success) {
|
LinkTypeCacheUtil.setLinkType(lt);
|
}
|
return success;
|
}catch(Throwable e){
|
ServerWithLog4j.logger.error("modifyLinkType", e);
|
throw getLocalVciError("P0010LINK-00002", e);
|
}
|
}
|
|
public boolean deleteLinkType(LinkType lt) throws VCIError {
|
try{
|
boolean success = LTService.getInstance().deleteLinkType(lt);
|
|
if (success) {
|
LinkTypeCacheUtil.delLinkType(lt.name);
|
}
|
return success;
|
}catch(Throwable e){
|
ServerWithLog4j.logger.error("deleteLinkType", e);
|
throw getLocalVciError("P0010LINK-00003", e);
|
}
|
}
|
|
/**
|
* 清空链接类型
|
*/
|
public boolean deleteLinkTypes(LinkType[] lts) throws VCIError {
|
try{
|
boolean success = LTService.getInstance().deleteLinkTypes(lts);
|
if (success) {
|
for (LinkType lt : lts)
|
LinkTypeCacheUtil.delLinkType(lt.name);
|
}
|
return success;
|
}catch(Throwable e){
|
ServerWithLog4j.logger.error("deleteLinkTypes", e);
|
throw getLocalVciError("P0010LINK-00003", e);
|
}
|
}
|
|
public String[] executeRepair(String[] sqlArray) throws VCIError {
|
try{
|
return LTService.getInstance().executeRepair(sqlArray);
|
}catch(Throwable e){
|
e.printStackTrace();
|
throw getLocalVciError("P0010LINK-00010", e);
|
}
|
}
|
|
public boolean createTable(String ltName) throws VCIError {
|
try {
|
return LTService.getInstance().createTable(ltName);
|
} catch (Throwable e) {
|
e.printStackTrace();
|
throw getLocalVciError("P0010LINK-00011", e);
|
}
|
}
|
|
public boolean createView() throws VCIError {
|
return LTService.getInstance().createView();
|
}
|
|
|
public boolean truncateTable(String ltName) throws VCIError {
|
try {
|
String tableName = OmdHelper.getLTTableName(ltName);
|
return DDLHelper.truncateTable(tableName);
|
} catch (Throwable e) {
|
e.printStackTrace();
|
throw getLocalVciError("P0010BTM-00018", e);
|
}
|
}
|
|
/**
|
* 清空链接表, 链接类型
|
*/
|
public boolean deleteLtsAndTables(LinkType[] lts) throws VCIError {
|
try{
|
boolean success = LTService.getInstance().deleteLtsAndTables(lts);
|
if (success) {
|
for (LinkType lt : lts)
|
LinkTypeCacheUtil.setLinkType(lt);
|
}
|
return success;
|
}catch(Throwable e){
|
ServerWithLog4j.logger.error("deleteLtsAndTables", e);
|
throw getLocalVciError("P0010LINK-00011", e);
|
}
|
}
|
|
|
public boolean xml2DB(String userName) throws VCIError {
|
return LTService.getInstance().xml2DB(userName);
|
}
|
|
// public boolean addLinkTypeNoCache(LinkType lt) throws VCIError {
|
// try{
|
// return LTService.getInstance().addLinkTypeNoCache(lt);
|
// }catch(Throwable e){
|
// e.printStackTrace();
|
// throw getLocalVciError("P0010LINK-00001", e);
|
// }
|
// }
|
|
// @Override
|
// public boolean deleteLinkTypeNoCache(LinkType lt) throws VCIError {
|
// try{
|
// return LTService.getInstance().deleteLinkTypeNoCache(lt);
|
// }catch(Throwable e){
|
// e.printStackTrace();
|
// throw getLocalVciError("P0010LINK-00003", e);
|
// }
|
// }
|
|
public String[] linkTypeConsistencyCheck() throws VCIError {
|
try{
|
return LTService.getInstance().linkTypeConsistencyCheck();
|
}catch(Throwable e){
|
ServerWithLog4j.logger.error("linkTypeConsistencyCheck", e);
|
throw getLocalVciError("P0010LINK-00009", e);
|
}
|
}
|
|
public boolean hasData(String ltName) throws VCIError {
|
boolean flag = false;
|
Session session = HibernateSessionFactory.getSession();
|
|
String table = OmdHelper.getLTTableName(ltName);
|
//判断表是否存在, 表不存在则该表无数据
|
String sql_ = "select count(1) from user_tables where TABLE_NAME = '" + table +"'";
|
List<?> list_ = session.createSQLQuery(sql_).list();
|
// 当list.get(i)中Object数量为1时, list.get(i)为Object
|
// 当list.get(i)中Object数量 > 1时, list.get(i)为Object
|
Object obj_ = list_.get(0);
|
int count_ = ((BigDecimal) obj_).intValue();
|
if (count_ < 1) {
|
return false;
|
}
|
String sql = "select count(*) from " + table;
|
List<?> list = session.createSQLQuery(sql).list();
|
//当list.get(i)中Object数量为1时, list.get(i)为Object
|
//当list.get(i)中Object数量 > 1时, list.get(i)为Object
|
Object obj = list.get(0);
|
int count = ((BigDecimal)obj).intValue();
|
if(count > 0){
|
flag = true;
|
}
|
return flag;
|
}
|
|
|
public boolean addIndex(String ltName, String[] indexAttrs) throws VCIError {
|
if (indexAttrs.length == 0)
|
return false;
|
|
String sql = "create unique INDEX "+ indexAttrs[0]+" on " + OmdHelper.getLTTableName(ltName) + "(" + indexAttrs[1] + ")\n";
|
|
try {
|
return DDLHelper.executeSql(sql);
|
} catch (Throwable e) {
|
throw getLocalVciError("dropIndex", e);
|
}
|
}
|
|
|
public boolean dropIndex(String btName, String[] indexAttrs) throws VCIError {
|
if (indexAttrs.length == 0)
|
return false;
|
|
String sql = "drop INDEX "+indexAttrs[0]+" \n";
|
|
try {
|
return DDLHelper.executeSql(sql);
|
} catch (Throwable e) {
|
throw getLocalVciError("dropIndex", e);
|
}
|
}
|
|
|
public boolean modifyLTAttribute(String ltName, String attrName) throws VCIError {
|
AttribItem ai = OMCacheProvider.getAttribute(attrName);
|
if (ai == null)
|
return false;
|
|
String abSql = DDLHelper.getAbSql(ai);
|
abSql = abSql.substring(0, abSql.lastIndexOf(","));
|
|
String sql = "alter table " + OmdHelper.getLTTableName(ltName) + " modify( " + abSql + " )";
|
|
try {
|
return DDLHelper.executeSql(sql);
|
} catch (Throwable e) {
|
throw getLocalVciError("modifyBTAttribute", e);
|
}
|
}
|
|
}
|