package com.vci.server.omd.enumtype; import java.io.IOException; import java.sql.Clob; import java.sql.ResultSet; import java.sql.SQLException; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader; import com.vci.corba.omd.etm.EnumItem; import com.vci.omd.constants.OmdConstants; import com.vci.server.omd.enumtype.service.EnumService; public class EnumServiceImplHelper { private static class InstanceHolder{ private static EnumServiceImplHelper helper = new EnumServiceImplHelper(); } private EnumServiceImplHelper(){ } public static EnumServiceImplHelper getInstance(){ return InstanceHolder.helper; } /** * 将emItem转化成xmltext * @param emItem * @return */ public String getXmlText(EnumItem emItem) { return EnumService.getInstance().getXmlText(emItem); } /** * 将xmlText内容写入到临时的CLOB对象中 * @param xmlText * @param connection * @return * @throws SQLException * @throws IOException */ // public CLOB getXmlTypeContent(String xmlText, Connection connection) throws SQLException, IOException { // C3P0NativeJdbcExtractor c3p0NativeJdbcExtractor = new C3P0NativeJdbcExtractor(); // Connection nativeConnection = c3p0NativeJdbcExtractor.getNativeConnection(connection); // CLOB clob = CLOB.createTemporary(nativeConnection, false, CLOB.DURATION_SESSION); // clob.open(CLOB.MODE_READWRITE); // Writer writer = clob.setCharacterStream(1000); // writer.write(xmlText); // writer.flush(); // writer.close(); // clob.close(); // return clob; // } /** * 将一条数据库中的记录转化成enum * @param rs * @return * @throws SQLException * @throws DocumentException */ public EnumItem getEnum(ResultSet rs) throws SQLException, DocumentException { EnumItem em = new EnumItem(); String value = rs.getString("oid"); em.oid = (value == null ? "" : value); value = rs.getString("name"); em.name = (value == null ? "" : value); value = rs.getString("label"); em.label = (value == null ? "" : value); em.ts = OmdConstants.tsDF.format(rs.getTimestamp("ts")); value = rs.getString("creator"); em.creator = (value == null ? "" : value); em.createTime = rs.getTimestamp("createTime").getTime(); value = rs.getString("modifier"); em.modifier = (value == null ? "" : value); em.modifyTime = rs.getTimestamp("modifyTime").getTime(); Clob clob = rs.getClob("content"); Element enumDetails = getEnumDetails(clob); EnumService.getInstance().setEnumValueFormDoc(em, enumDetails); return em; } /** * 将查询的clob对象转换成xml的element, 便于解析 * @param clob * @return * @throws SQLException * @throws IOException * @throws DocumentException */ public Element getEnumDetails(Clob clob) throws DocumentException, SQLException{ SAXReader saxReader = new SAXReader(); //Document document = saxReader.read(clob.characterStreamValue()); Document document = saxReader.read(clob.getCharacterStream()); Element root = document.getRootElement(); return root; } }