package com.vci.client.omd.provider;
|
|
import java.io.BufferedReader;
|
import java.io.BufferedWriter;
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.FileNotFoundException;
|
import java.io.FileOutputStream;
|
import java.io.FileWriter;
|
import java.io.IOException;
|
import java.io.InputStreamReader;
|
import java.io.OutputStreamWriter;
|
import java.text.DateFormat;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.HashMap;
|
import java.util.HashSet;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Set;
|
import org.dom4j.Document;
|
import org.dom4j.DocumentException;
|
import org.dom4j.Element;
|
import org.dom4j.io.SAXReader;
|
|
import com.vci.corba.omd.atm.AttribItem;
|
import com.vci.corba.omd.btm.BtmItem;
|
import com.vci.corba.omd.ltm.LinkType;
|
import com.vci.corba.omd.ltm.LinkTypeServicePrx;
|
import com.vci.client.common.providers.ServiceProvider;
|
import com.vci.corba.common.VCIError;
|
|
|
/**
|
* 获取属性的数据类型, 属性: 系统属性, 属性池属性
|
*
|
*/
|
public class LinkTypeProvider {
|
private static LinkTypeProvider linkTypeProvider = null;
|
/**
|
* 链接类型table名的前缀
|
*/
|
private static LinkTypeServicePrx linkTypeService = null;
|
/**
|
* oracle中table名的最大长度
|
*/
|
// private static final int TABLEMAXLENTGH = 30;
|
|
public static DateFormat tsDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
public static DateFormat timeDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
// private String[] sysAttibutes = {"OID","Creator","CreateTime","LastModifier","LASTMODIFYTIME","F_OID","F_REVISIONOID","F_NAMEOID","F_BtwName",
|
// "T_OID","T_REVISIONOID","T_NAMEOID","T_BtwName","TS"};
|
// 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";
|
|
/**
|
* 缓存已经调用new LinkTypeProvider();
|
* 因此不能定义 私有的LinkTypeProvider();
|
* @return
|
*/
|
public static LinkTypeProvider getInstance(){
|
if(linkTypeProvider == null){
|
linkTypeProvider = new LinkTypeProvider();
|
}
|
return linkTypeProvider;
|
}
|
|
public String[] getSysAttributes() {
|
try {
|
return getService().getSysAttributes();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
return null;
|
}
|
|
|
public AttribItem[] getSysAttribItems() {
|
return getService().getSysAttribItems();
|
}
|
|
/**
|
* 获取属性的数据类型, 属性: 系统属性, 属性池属性
|
* @param abUpperName
|
* @return
|
*/
|
public String getAbItemDataType(String abName){
|
String dataType = null;
|
String abUpperName = abName.toUpperCase();
|
//系统属性
|
if(abUpperName.equals("OID") || abUpperName.equals("REVISIONOID") || abUpperName.equals("NAMEOID") || abUpperName.equals("BTMNAME")
|
|| abUpperName.equals("CREATOR") || abUpperName.equals("LASTMODIFIER") || abUpperName.equals("REVISIONRULE")
|
|| abUpperName.equals("VERSIONRULE") || abUpperName.equals("REVISIONVALUE") || abUpperName.equals("VERSIONVALUE")
|
|| abUpperName.equals("LCTID") || abUpperName.equals("LCSTATUS")
|
|| abUpperName.equals("ID") || abUpperName.equals("NAME") || abUpperName.equals("DESCRIPTION")
|
|| abUpperName.equals("OWNER") || abUpperName.equals("CHECKINBY")
|
|| abUpperName.equals("CHECKOUTBY") || abUpperName.equals("COPYFROMVERSION")
|
|| abUpperName.equals("ISLASTR") || abUpperName.equals("ISFIRSTR")
|
|| abUpperName.equals("ISLASTV") || abUpperName.equals("ISFIRSTV")
|
|| abUpperName.equals("F_OID") || abUpperName.equals("F_REVISIONOID")
|
|| abUpperName.equals("F_NAMEOID") || abUpperName.equals("F_BTWNAME")
|
|| abUpperName.equals("T_OID") || abUpperName.equals("T_REVISIONOID")
|
|| abUpperName.equals("T_NAMEOID") || abUpperName.equals("T_BTWNAME")){
|
dataType = "VTString";
|
}else if(abUpperName.equals("REVISIONSEQ") || abUpperName.equals("VERSIONSEQ")){
|
dataType = "VTInteger";
|
}else if(abUpperName.equals("CREATETIME") || abUpperName.equals("LASTMODIFYTIME")
|
|| abUpperName.equals("TS") || abUpperName.equals("CHECKINTIME") || abUpperName.equals("CHECKOUTTIME")){
|
dataType = "VTDateTime";
|
//属性池中属性
|
}else{
|
dataType = ApProvider.getAbItemDataType(abName);
|
}
|
return dataType;
|
}
|
|
/**
|
*
|
* @return
|
*/
|
public String getLTData(){
|
String content = "";
|
try {
|
content = getService().getLTData();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
return content;
|
}
|
|
/***
|
*
|
* 获取所有链接类型对象数组
|
*
|
*/
|
public LinkType [] getLinkTypes(){
|
LinkType[] linkTypes = null;
|
try {
|
linkTypes = getService().getLinkTypes();
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
return linkTypes;
|
}
|
/***
|
*
|
* 根据链接类型名称获取链接类型对象
|
*/
|
public LinkType getLinkTypeByName(String name){
|
LinkType[] linkTypes = null;
|
try {
|
linkTypes = getService().getLinkTypes();
|
for(LinkType lt:linkTypes){
|
if(lt.name.equals(name)){
|
return lt;
|
}
|
}
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
return null;
|
|
}
|
|
public LinkType[] getLinkTypeByBtmName(String btmName, String direction) {
|
LinkType[] linkTypes = null;
|
try {
|
linkTypes = getService().getLinkTypeByBtmName(btmName, direction);
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
return linkTypes;
|
}
|
|
public LinkTypeServicePrx getService(){
|
try {
|
return ServiceProvider.getOMDService().getLinkTypeService();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return linkTypeService;
|
}
|
|
|
/**
|
* 返回创建链接类型的sql
|
* @param linkType
|
* @return
|
*/
|
// public String getCreateLtSql(LinkType linkType){
|
// String tableName = OmdTools.getLTTableName(linkType.name);
|
// String sql = "create table " + tableName + "(" + otherFieldLt;
|
//
|
// String[] abInfo = linkType.attributes;
|
//
|
// for(int i = 0; i < abInfo.length; i++){
|
// com.vci.corba.omd.attribpool.AttribItem abItem = null;
|
// abItem = ApProvider.getAbItemByName(abInfo[i]);
|
//
|
// String abSql = getAbSql(abItem);
|
// sql += abSql;
|
// }
|
// sql = sql.substring(0, sql.lastIndexOf(","));
|
// sql += "\n)";
|
// return sql;
|
// }
|
|
/**
|
* 获取增加主键sql
|
* @param typeName
|
* @return
|
*/
|
// public String getAddPKSql(String typeName){
|
// return "alter table " + OmdTools.getLTTableName(typeName) + " add constraint PKLT_" + typeName + " primary key (OID)\n";
|
// }
|
|
// public String getAbSql(AttribItem abItem){
|
// String sql = "";
|
// if(abItem == null){
|
// return sql;
|
// }
|
// String abName = abItem.name;
|
// String vtType = abItem.vtDataType;
|
// String other = abItem.other;
|
// String defValue = abItem.defValue;
|
//
|
// if(vtType.equals("VTString")){
|
// int length = 50;
|
// String lengthStr = getOtherValueByType(other, "length");
|
// if(lengthStr != null && !lengthStr.equals("")){
|
// length = Integer.valueOf(lengthStr);
|
// }
|
// sql += abName.toUpperCase() + " VARCHAR2(" + length + ")";
|
// if(!defValue.equals("")){
|
// sql += " default '" + defValue + "'";
|
// }
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTInteger")){
|
// sql += abName.toUpperCase() + " NUMBER";
|
// if(!defValue.equals("")){
|
// sql += " default " + defValue;
|
// }
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTDouble")){
|
// int length = 20;
|
// String lengthStr = getOtherValueByType(other, "length");
|
// if(lengthStr != null && !lengthStr.equals("")){
|
// length = Integer.valueOf(lengthStr);
|
// }
|
//
|
// int accuracy = 2;
|
// String accuracyStr = getOtherValueByType(other, "accuracy");
|
// if(accuracyStr != null && !accuracyStr.equals("")){
|
// accuracy = Integer.valueOf(accuracyStr);
|
// }
|
// sql += abName.toUpperCase() + " NUMBER(" + length + ", " + accuracy +")";
|
// if(!defValue.equals("")){
|
// sql += " default " + defValue;
|
// }
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTBoolean")){
|
// sql += abName.toUpperCase() + " VARCHAR2(8)";
|
// if(!defValue.equals("")){
|
// sql += " default '" + defValue + "'";
|
// }
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTImage")){
|
// sql += abName.toUpperCase() + " VARCHAR2(255)";
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTDate")){
|
// sql += abName.toUpperCase() + " DATE";
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTTime")){
|
// sql += abName.toUpperCase() + " TIMESTAMP";
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTDateTime")){
|
// sql += abName.toUpperCase() + " TIMESTAMP";
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTNote")){
|
// sql += abName.toUpperCase() + " VARCHAR2(255)";
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTFilePath")){
|
// sql += abName.toUpperCase() + " VARCHAR2(255)";
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTClob")){
|
// sql += abName.toUpperCase() + " CLOB";
|
// sql += ",\n\t";
|
// }
|
//
|
// return sql;
|
// }
|
|
/**
|
* 获取属性other中type的值
|
* @param other
|
* @param type
|
* @return
|
*/
|
public String getOtherValueByType(String other, String type){
|
String[] otherArray = other.split(";");
|
for(int i = 0; i < otherArray.length; i++){
|
String otherValue = otherArray[i];
|
if(otherValue.contains(type)){
|
return otherValue.substring(otherValue.indexOf("=") + 2, otherValue.length());
|
}
|
}
|
return null;
|
|
}
|
|
/**
|
* Array-->List
|
* @param array
|
* @return
|
*/
|
public List<String> parseArrayToList(String[] array){
|
List<String> list = new ArrayList<String>();
|
for(int i = 0; i < array.length; i++){
|
list.add(array[i]);
|
}
|
return list;
|
}
|
|
/**
|
* 指定的链接类型是否使用了指定的业务类型
|
* @param link
|
* @param btmName
|
* @return
|
*/
|
public boolean containsBtm(LinkType link, String btmName){
|
String[] btms = link.btmItemsFrom;
|
for(int i = 0; i < btms.length; i++){
|
if(btmName.equalsIgnoreCase(btms[i])){
|
return true;
|
}
|
}
|
btms = link.btmItemsTo;
|
for(int i = 0; i < btms.length; i++){
|
if(btmName.equalsIgnoreCase(btms[i])){
|
return true;
|
}
|
}
|
return false;
|
}
|
|
/**
|
*
|
* 获取链接类型的全部属性(包括系统属性)数组
|
* @return
|
*/
|
public List<String> getAllAbNames(LinkType link){
|
List<String> abList = new ArrayList<String>();
|
for(String attr : getService().getSysAttributes()) {
|
abList.add(attr);
|
}
|
String[] abNames = getAbNames(link);
|
for(int i = 0; i < abNames.length; i++){
|
abList.add(abNames[i]);
|
}
|
|
return abList;
|
}
|
|
/**
|
* 获取链接类型的属性(不包括系统属性)数组
|
* @param btName
|
* @return
|
*/
|
public String[] getAbNames(LinkType link){
|
return link.attributes;
|
}
|
|
/**
|
* 获取链接类型对应的属性
|
* @param linkTypeName
|
* @return
|
*/
|
public AttribItem[] getLTAbItems(String linkTypeName) {
|
LinkType linkType = getLinkTypeByName(linkTypeName);
|
if (linkType.attributes == null || linkType.attributes.length == 0) {
|
return new AttribItem[0];
|
}
|
AttribItem[] abItems = ApProvider.getAttribItemsByNames(linkType.attributes);
|
|
return abItems;
|
}
|
|
public boolean expData(String dir, LinkType[] lts){
|
Set<String> attNameSet = new HashSet<String>();
|
Set<String> btNameSet = new HashSet<String>();
|
BufferedWriter bw = null;
|
FileOutputStream fos = null;
|
OutputStreamWriter osw =null;
|
try{
|
File file = new File(dir + "/lt.txt");
|
//将clob字段写到单独的文件中
|
new File(dir + "/lt").mkdir();
|
//add by caill start 2015.12.24 导出时将txt文件设置为“utf-8”格式
|
fos = new FileOutputStream(file);
|
osw = new OutputStreamWriter(fos, "utf-8");
|
bw = new BufferedWriter(osw);
|
//add by caill end
|
/*w = new FileWriter(file);
|
bw = new BufferedWriter(w);*/
|
for(LinkType lt : lts){
|
String[] apNames = lt.attributes;
|
if(apNames.length > 0){
|
attNameSet.addAll(Arrays.asList(apNames));
|
}
|
for(String btName : lt.btmItemsFrom){
|
btNameSet.add(btName);
|
}
|
for(String btName : lt.btmItemsTo){
|
btNameSet.add(btName);
|
}
|
//若str小于缓冲区大小, 将写到缓冲区;
|
//若str大于缓冲区大小, 将刷新缓冲区(将缓冲区内容写到底层流), 然后str直接写到底层流.
|
String text = getObjectText(lt);
|
bw.write(text);
|
bw.newLine();
|
BufferedWriter clobBW = null;
|
FileOutputStream fo = null;
|
OutputStreamWriter pw =null;
|
try{
|
File clobFile = new File(dir + "/lt/" + lt.oid + ".xml");
|
//add by caill start 2015.12.24 将xml内容和xml文件格式统一
|
fo = new FileOutputStream(clobFile);
|
pw = new OutputStreamWriter(fo, "utf-8");
|
clobBW = new BufferedWriter(pw);
|
clobBW.write( "<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
|
clobBW.write(getXmlText(lt));
|
clobBW.flush();
|
//add by caill end
|
/*clobW = new FileWriter(clobFile);
|
clobBW = new BufferedWriter(clobW);
|
clobBW.write( "<?xml version=\"1.0\" encoding=\"gb2312\" ?>");//gb2312
|
clobBW.write(getXmlText(lt));
|
clobBW.flush();*/
|
}catch(IOException e2){
|
e2.printStackTrace();
|
}finally{
|
try{
|
if(clobBW != null){
|
fo.close(); //add by caill 2015.12.24 将fo关闭
|
pw.close(); //add by caill 2015.12.24 将pw关闭
|
clobBW.close();
|
}
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
bw.flush();
|
//导出属性
|
AttribItem[] abs = ApProvider.getAttribItemsByNames(attNameSet.toArray(new String[0]));
|
boolean apFlag = ApProvider.expData(dir, abs);
|
|
//导出业务类型
|
List<BtmItem> bts = new ArrayList<BtmItem>();
|
for(String btName : btNameSet){
|
BtmItem bt = BtmProvider.getBtmItemByName(btName);
|
bts.add(bt);
|
}
|
boolean btFlag = BtmProvider.expData(dir, bts.toArray(new BtmItem[0]));
|
if(true & apFlag & btFlag){
|
System.out.println("**************链接类型导出成功************");
|
}else{
|
System.out.println("**************链接类型导出失败************");
|
}
|
return true & apFlag & btFlag;
|
}catch(IOException e){
|
e.printStackTrace();
|
}finally{
|
try {
|
if(bw != null){
|
fos.close(); //add by caill 2015.12.24 将fos关闭
|
osw.close(); //add by caill 2015.12.24 将osw关闭
|
bw.close();
|
}
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
return false;
|
}
|
|
private static final String OID = "oid";
|
private static final String NAME = "name";
|
private static final String LABEL = "label";
|
private static final String DESCRIPTION = "description";
|
private static final String TS = "ts";
|
private static final String CREATOR = "creator";
|
private static final String CREATETIME = "createTime";
|
private static final String MODIFIER = "modifier";
|
private static final String MODIFYTIME = "modifyTime";
|
|
/**
|
* 将对象转化成字符串
|
* {oid:qqq, name:q}
|
* @param lt
|
* @return
|
*/
|
public String getObjectText(LinkType lt) {
|
StringBuilder stb = new StringBuilder("{");
|
stb.append(OID + ":" + lt.oid + ",");
|
stb.append(NAME + ":" + lt.name + ",");
|
stb.append(LABEL + ":" + lt.tag + ",");
|
stb.append(DESCRIPTION + ":" + lt.description + ",");
|
stb.append(TS + ":" + lt.ts + ",");
|
stb.append(CREATOR + ":" + lt.creator + ",");
|
stb.append(CREATETIME + ":" + lt.createTime + ",");
|
stb.append(MODIFIER + ":" + lt.modifier + ",");
|
stb.append(MODIFYTIME + ":" + lt.modifyTime);
|
stb.append("}");
|
return stb.toString();
|
}
|
|
/**
|
* 将LinkType lt转化成xmltext
|
* @param bt
|
* @return
|
*/
|
public String getXmlText(LinkType lt){
|
StringBuilder stb = new StringBuilder("<linkType>");
|
stb.append("<name>" + lt.name + "</name>");
|
stb.append("<tag>" + lt.tag + "</tag>");
|
stb.append("<description>" + lt.description + "</description>");
|
for(String btmFrom : lt.btmItemsFrom){
|
stb.append("<btmFrom>" + btmFrom + "</btmFrom>");
|
}
|
for(String btmTo : lt.btmItemsTo){
|
stb.append("<btmTo>" + btmTo + "</btmTo>");
|
}
|
stb.append("<primitivesFrom>" + lt.primitivesFrom + "</primitivesFrom>");
|
stb.append("<primitivesTo>" + lt.primitivesTo + "</primitivesTo>");
|
stb.append("<relationFrom>" + lt.relationFrom + "</relationFrom>");
|
stb.append("<relationTo>" + lt.relationTo + "</relationTo>");
|
stb.append("<relation>" + lt.relation + "</relation>");
|
stb.append("<implClass>" + lt.implClass + "</implClass>");
|
stb.append("<shape>" + lt.shape + "</shape>");
|
for(String attibute : lt.attributes){
|
stb.append("<attibute>" + attibute + "</attibute>");
|
}
|
stb.append("</linkType>");
|
return stb.toString();
|
}
|
|
public List<LinkType> getLTFromFile(String dir) {
|
File file = new File(dir + "/lt.txt");
|
List<LinkType> list = new ArrayList<LinkType>();
|
BufferedReader br = null;
|
FileInputStream fo = null;
|
InputStreamReader isw =null;
|
try {
|
/*r = new FileReader(file);
|
br = new BufferedReader(r);*/
|
//add by caill start 2015.12.24 导入时将txt文件内容设置为“utf-8”格式
|
fo = new FileInputStream(file);
|
isw = new InputStreamReader(fo, "utf-8");
|
br = new BufferedReader(isw);
|
//add by caill end
|
String str = null;
|
while((str = br.readLine()) != null){
|
Map<String, String> map = getMapFormText(str);
|
String oid = map.get("oid");
|
if(oid != null && !oid.equals("")){
|
File contentFile = new File(dir + "/lt/" + oid + ".xml");
|
if(!contentFile.exists()){
|
System.out.println(dir + "/lt/" + oid + ".xml不存在");
|
break;
|
}
|
LinkType lt = new LinkType();
|
lt.oid = oid;
|
lt.name = map.get("name");
|
lt.tag = map.get("label");
|
lt.description = map.get("description");
|
lt.ts = Long.valueOf(map.get("ts"));
|
lt.creator = map.get("creator");
|
lt.createTime = Long.valueOf(map.get("createTime"));
|
lt.modifier = map.get("modifier");
|
lt.modifyTime = Long.valueOf(map.get("modifyTime"));
|
SAXReader sa = new SAXReader();
|
//add by caill 2015.12.24 导入时将saxReader对象设置为“utf-8”格式
|
sa.setEncoding("utf-8");
|
Document document = sa.read(contentFile);
|
setLTValueFormDoc(lt, document.getRootElement());
|
list.add(lt);
|
}else{
|
System.out.println(dir + "bt.txt中存在oid为空的错误记录");
|
break;
|
}
|
}
|
return list;
|
} catch (FileNotFoundException e) {
|
e.printStackTrace();
|
} catch (IOException e) {
|
e.printStackTrace();
|
} catch (DocumentException e) {
|
e.printStackTrace();
|
} finally{
|
if(br != null){
|
try {
|
fo.close(); //add by caill 2015.12.24 将fo关闭
|
isw.close(); //add by caill 2015.12.24 将isw关闭
|
br.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
return null;
|
}
|
/**
|
* 将文件中一条记录解析成key-value
|
* @param str
|
* @return
|
*/
|
public Map<String, String> getMapFormText(String str) {
|
str = str.trim();
|
if(!str.startsWith("{") || !str.endsWith("}")){
|
return null;
|
}
|
Map<String, String> map = new HashMap<String, String>();
|
str = str.substring(1, str.length() - 1);
|
String[] kvs = str.split(",");
|
for(String kv : kvs){
|
String[] kv_ = kv.split(":");
|
if(kv_.length == 1){
|
map.put(kv_[0].trim(), "");
|
}else{
|
map.put(kv_[0].trim(), kv_[1].trim());
|
}
|
}
|
return map;
|
}
|
|
/**
|
* 设置EnumItem存在
|
* @param att
|
* @param element
|
*/
|
public void setLTValueFormDoc(LinkType lt, Element element){
|
List<Element> fromElements = element.elements("btmFrom");
|
List<String> froms = new ArrayList<String>();
|
for(Element fromElement : fromElements){
|
froms.add(fromElement.getText());
|
}
|
lt.btmItemsFrom = froms.toArray(new String[0]);
|
List<Element> toElements = element.elements("btmTo");
|
List<String> tos = new ArrayList<String>();
|
for(Element toElement : toElements){
|
tos.add(toElement.getText());
|
}
|
lt.btmItemsTo = tos.toArray(new String[0]);
|
String value = element.elementText("primitivesFrom");
|
lt.primitivesFrom = (value == null ? "" : value);
|
value = element.elementText("primitivesTo");
|
lt.primitivesTo = (value == null ? "" : value);
|
value = element.elementText("relationFrom");
|
lt.relationFrom = (value == null ? "" : value);
|
value = element.elementText("relationTo");
|
lt.relationTo = (value == null ? "" : value);
|
value = element.elementText("relation");
|
lt.relation = (value == null ? "" : value);
|
value = element.elementText("implClass");
|
lt.implClass = (value == null ? "" : value);
|
value = element.elementText("shape");
|
lt.shape = (value == null ? "" : value);
|
List<Element> attElements = element.elements("attibute");
|
List<String> atts = new ArrayList<String>();
|
for(Element attElement : attElements){
|
atts.add(attElement.getText());
|
}
|
lt.attributes = atts.toArray(new String[0]);
|
}
|
|
public boolean impData(String dir, LinkType[] lts) {
|
try {
|
List<AttribItem> atts = ApProvider.getAttFromFile(dir);
|
boolean attFlag = ApProvider.impData(dir, atts.toArray(new AttribItem[0]));
|
if(!attFlag){
|
System.out.println("链接类型使用的属性导入失败。导入中止。");
|
return false;
|
}
|
|
List<BtmItem> bts = BtmProvider.getBTFromFile(dir);
|
boolean btFlag = BtmProvider.impData(dir, bts.toArray(new BtmItem[0]));
|
if(!btFlag){
|
System.out.println("链接类型使用的业务类型导入失败。导入中止。");
|
return false;
|
}
|
|
for(LinkType lt : lts){
|
LinkType lt_ = getService().getLinkType(lt.name);
|
//已经存在
|
if(!lt_.oid.equals("")){
|
getService().deleteLinkType(lt_);
|
getService().addLinkType(lt);
|
System.out.println(lt.name + "在数据库中已经存在, 覆盖。");
|
}else{
|
getService().addLinkType(lt);
|
}
|
}
|
return true;
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
return false;
|
}
|
/**将linktype导出为.sql文件
|
* add by caill 2015.12.22
|
*
|
* */
|
// public boolean expLinkSqlData(String dir, LinkType[] linkTypes) throws VCIError {
|
// new File(dir).mkdir();
|
// File file = new File(dir + "/platformLink.sql");
|
// FileWriter w = null;;
|
// BufferedWriter bw = null;
|
// try {
|
// w = new FileWriter(file);
|
// bw = new BufferedWriter(w);
|
// } catch (IOException e) {
|
// // TODO Auto-generated catch block
|
// e.printStackTrace();
|
// }
|
//
|
// for(int i = 0; i < linkTypes.length; i++){
|
// String sql = getLinkTableSqlByName(linkTypes[i]);
|
// try {
|
// bw.write(sql);
|
// bw.write("\r\n");
|
// } catch (IOException e) {
|
// // TODO Auto-generated catch block
|
// e.printStackTrace();
|
// }
|
// }
|
// try {
|
// bw.flush();
|
// bw.close();
|
// return true;
|
// } catch (IOException e) {
|
// // TODO Auto-generated catch block
|
// e.printStackTrace();
|
// }
|
//
|
//
|
// return false;
|
// }
|
/**
|
* 生成链接类型导出为.sql文件的sql语句 add by caill 2015.12.22
|
* @param linkType
|
* @return
|
*/
|
// public String getLinkTableSqlByName(LinkType linkType){
|
// String tableName = OmdTools.getLTTableName(linkType.name);
|
// String sql = "create table " + tableName +"(" + otherFieldLt;
|
// String[] abInfo = linkType.attributes;
|
// for(int i = 0; i < abInfo.length; i++){
|
// com.vci.corba.omd.attribpool.AttribItem abItem = null;
|
//
|
// abItem = ApProvider.getAbItemByName(abInfo[i]);
|
//
|
// String abSql = getAbSql(abItem);
|
// sql += abSql;
|
// }
|
// sql = sql.substring(0, sql.lastIndexOf(","));
|
// sql += "\n);";
|
// sql += "\r\ncomment on table "+tableName+" is '"+ linkType.tag+"';"; //添加表注释
|
// for(int i = 0; i < abInfo.length; i++){
|
// com.vci.corba.omd.attribpool.AttribItem abItem = null;
|
//
|
// abItem = ApProvider.getAbItemByName(abInfo[i]); //添加列注释
|
//
|
// sql += "\r\ncomment on column "+tableName+"."+abItem.name+" is '"+ abItem.label +"';";
|
// }
|
// return sql;
|
// }
|
|
}
|