package com.vci.server.bof.utils;
|
|
import java.io.BufferedReader;
|
import java.io.IOException;
|
import java.io.Reader;
|
import java.math.BigDecimal;
|
import java.sql.Clob;
|
import java.sql.ResultSet;
|
import java.sql.SQLException;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
import com.vci.corba.omd.atm.AttribItem;
|
import com.vci.corba.omd.data.AttributeValue;
|
import com.vci.corba.omd.data.BusinessObject;
|
|
public class ServerObjectUtil {
|
|
private static ServerObjectUtil instance = null;
|
|
private ServerObjectUtil() {
|
|
}
|
|
public static synchronized ServerObjectUtil getInstance() {
|
if (instance == null) {
|
instance = new ServerObjectUtil();
|
}
|
|
return instance;
|
}
|
|
|
public static BusinessObject createBOByRS(AttribItem[] attrItems, ResultSet rs) throws SQLException {
|
BusinessObject bo = new BusinessObject();
|
|
int index = 1;
|
|
bo.oid = rs.getString(index++);
|
bo.revisionid = rs.getString(index++);
|
bo.nameoid = rs.getString(index++);
|
bo.btName = rs.getString(index++);
|
bo.isLastR = rs.getInt(index++) != 0;
|
bo.isFirstR = rs.getInt(index++) != 0;
|
bo.isLastV = rs.getInt(index++) != 0;
|
bo.isFirstV = rs.getInt(index++) != 0;
|
bo.creator = rs.getString(index++);
|
bo.createTime = rs.getTimestamp(index++).getTime();
|
bo.modifier = rs.getString(index++);
|
bo.modifyTime = rs.getTimestamp(index++).getTime();
|
bo.revisionRule = rs.getString(index++);
|
bo.versionRule = rs.getString(index++);
|
bo.revisionSeq = rs.getShort(index++);
|
bo.revisionValue = rs.getString(index++);
|
bo.versionSeq = rs.getShort(index++);
|
bo.versionValue = rs.getString(index++);
|
bo.lctId = rs.getString(index++);
|
bo.lcStatus = rs.getString(index++);
|
bo.ts = rs.getTimestamp(index++).getTime();
|
bo.id = rs.getString(index++);
|
bo.name = rs.getString(index++);
|
bo.description = rs.getString(index++);
|
bo.owner = rs.getString(index++);
|
bo.fromVersion = rs.getString(index++);
|
|
ArrayList<AttributeValue> list = new ArrayList<AttributeValue>();
|
for (int i = 0; i < attrItems.length; i++) {
|
AttributeValue attrVal = new AttributeValue();
|
attrVal.attrName = attrItems[i].name;
|
attrVal.attrVal = rs.getString(index++);
|
list.add(attrVal);
|
}
|
bo.newAttrValList = new AttributeValue[0];
|
bo.hisAttrValList = list.toArray(new AttributeValue[list.size()]);
|
|
return bo;
|
}
|
|
|
|
public String tansferSystemDBDateToString(Map<String, String> attrType, String attributeName, Object value) {
|
if (value == null) {
|
return "";
|
}
|
String rsValue = "";
|
String dType = attrType.get(attributeName);
|
try {
|
if (dType.equals("VTString")){
|
rsValue = value.toString();
|
} else if (dType.equals("VTInteger")){
|
rsValue = ((BigDecimal)value).toString();
|
} else if (dType.equals("VTLong")){
|
rsValue = ((BigDecimal)value).toString();
|
} else if (dType.equals("VTDouble")){
|
rsValue = ((BigDecimal)value).toString();
|
} else if (dType.equals("VTBoolean")){
|
rsValue = (String)value;
|
} else if (dType.equals("VTImage")){
|
rsValue = (String)value;
|
} else if (dType.equals("VTDate")){
|
// rsValue = String.valueOf(((java.sql.Timestamp)value).getTime());
|
if (value instanceof java.sql.Date) {
|
long time = ((java.sql.Date)value).getTime();
|
rsValue = ((Long)time).toString();
|
} else if (value instanceof java.sql.Timestamp){
|
long time = ((java.sql.Timestamp)value).getTime();
|
rsValue = ((Long)time).toString();
|
}
|
} else if (dType.equals("VTTime")){
|
// rsValue = String.valueOf(((java.sql.Timestamp)value).getTime());
|
rsValue = ((java.sql.Timestamp)value).toString();
|
} else if (dType.equals("VTDateTime")) {
|
// rsValue = String.valueOf(((java.sql.Timestamp)value).getTime());
|
if (value instanceof java.sql.Date) {
|
long time = ((java.sql.Date)value).getTime();
|
rsValue = ((Long)time).toString();
|
} else if (value instanceof java.sql.Timestamp){
|
long time = ((java.sql.Timestamp)value).getTime();
|
rsValue = ((Long)time).toString();
|
}
|
} else if (dType.equals("VTNote")){
|
rsValue = (String)value;
|
} else if (dType.equals("VTFilePath")) {
|
rsValue = (String)value;
|
} else if (dType.equals("VTClob")) {
|
rsValue = clobToString((java.sql.Clob)value);
|
} else {
|
rsValue = (String)value;
|
}
|
} catch (Exception e) {
|
rsValue = "";
|
e.printStackTrace();
|
}
|
|
return rsValue;
|
}
|
|
public String tansferTypeDBDateToString(String attrType, Object value) {
|
if (value == null) {
|
return "";
|
} else if (value.equals("")) {
|
return "";
|
}
|
String rsValue = "";
|
|
if (attrType.equals("VTString")){
|
rsValue = String.valueOf(value);
|
} else if (attrType.equals("VTInteger")){
|
rsValue = ((BigDecimal)value).toString();
|
} else if (attrType.equals("VTLong")){
|
rsValue = ((BigDecimal)value).toString();
|
} else if (attrType.equals("VTDouble")){
|
rsValue = ((BigDecimal)value).toString();
|
} else if (attrType.equals("VTBoolean")){
|
rsValue = (String)value;
|
} else if (attrType.equals("VTImage")){
|
rsValue = (String)value;
|
} else if (attrType.equals("VTDate")){
|
if (value instanceof java.sql.Date) {
|
rsValue = ((java.sql.Date)value).toString();
|
} else if (value instanceof java.sql.Timestamp){
|
rsValue = ((java.sql.Timestamp)value).toString();
|
}
|
} else if (attrType.equals("VTTime")){
|
rsValue = ((java.sql.Timestamp)value).toString();
|
} else if (attrType.equals("VTDateTime")) {
|
if (value instanceof java.sql.Date) {
|
rsValue = ((java.sql.Date)value).toString();
|
} else if (value instanceof java.sql.Timestamp){
|
rsValue = ((java.sql.Timestamp)value).toString();
|
}
|
} else if (attrType.equals("VTNote")){
|
rsValue = (String)value;
|
} else if (attrType.equals("VTFilePath")) {
|
rsValue = (String)value;
|
} else if (attrType.equals("VTClob")) {
|
rsValue = clobToString((java.sql.Clob)value);
|
} else {
|
rsValue = (String)value;
|
}
|
return rsValue;
|
}
|
|
/**
|
* clob转String
|
* @param value
|
* @return
|
*/
|
private String clobToString(Clob value) {
|
// TODO Auto-generated method stub
|
String clobValue = "";
|
try {
|
Reader is = value.getCharacterStream();
|
BufferedReader br = new BufferedReader(is);
|
String s = br.readLine();
|
StringBuffer sb = new StringBuffer();
|
while(s!=null){
|
sb.append(s);
|
s=br.readLine();
|
}
|
clobValue = sb.toString();
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} catch (IOException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
|
return clobValue;
|
}
|
|
public String tansferTypeDBDateToString(
|
HashMap<String, String> bO_CONSTANTS, String attrType,
|
Object attributeValue) {
|
// TODO Auto-generated method stub
|
return null;
|
}
|
}
|