package com.vci.client.omd.linktype.util;
|
|
import java.util.ArrayList;
|
|
import com.vci.corba.omd.atm.AttribItem;
|
/**
|
* 提供一些常用的功能
|
* @author Administrator
|
*
|
*/
|
public class Tool {
|
private static Tool tool = null;
|
private Tool(){
|
|
}
|
public static Tool getInstance(){
|
if(tool == null){
|
tool = new Tool();
|
}
|
return tool;
|
}
|
|
/**
|
* 获取属性字段的sql语句
|
* @param array
|
* @return
|
*/
|
public ArrayList<String> convertArrayToList(String[] array){
|
ArrayList<String> list = new ArrayList<String>();
|
for(int i = 0; i < array.length; i++){
|
list.add(array[i]);
|
}
|
return list;
|
}
|
|
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;
|
|
}
|
}
|