📄 datamanager.java
字号:
package kmd.gxml;
import kmd.Debug;
import kmd.commo.PageList;
import kmd.commo.SQLTools;
import kmd.commo.SequenceProducer;
import kmd.jdbc.DBConnection;
import java.util.ArrayList;
import java.sql.Connection;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.sql.ResultSetMetaData;
import java.sql.Types;
/**
* 对具体数据对象进行操作的类
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2007</p>
* <p>Company: 重庆科美达电脑有限公司</p>
* @author not attributable
* @version 1.0
*/
public class DataManager {
/**
* 默认构造符
*/
public DataManager() {}
/**
* 新增一个数据对象信息
* @param dataInfo DataInfo 数据对象信息
* @throws Exception
*/
public void addDataInfo(DataInfo dataInfo) throws Exception {
Connection cn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
cn = DBConnection.getConnection();
dataInfo.setOid(SequenceProducer.getId());
ps = cn.prepareStatement(
"INSERT INTO DataInfo(OId, TId, CName, EName, Operator, CreateTime, "
+ "LastModifyTime, Digest) VALUES(?,?,?,?,?,?,?,?)");
ps.setLong(1, dataInfo.getOid());
ps.setLong(2, dataInfo.getTid());
ps.setString(3, dataInfo.getCname());
ps.setString(4, dataInfo.getEname());
ps.setString(5, dataInfo.getOperator());
ps.setTimestamp(6, dataInfo.getCreateTime());
if (dataInfo.getLastModifyTime() == null) {
ps.setNull(7, Types.DATE);
} else {
ps.setTimestamp(7, dataInfo.getLastModifyTime());
}
if (dataInfo.getDigest() == null) {
ps.setNull(8, Types.VARCHAR);
} else {
ps.setString(8, dataInfo.getDigest());
}
if (ps.executeUpdate() <= 0) {
throw new Exception();
}
ArrayList attributeList = dataInfo.getAttributeList();
for (int i = 0; i < attributeList.size(); i++) {
AttributeInfo aInfo = (AttributeInfo) attributeList.get(i);
if (aInfo.getType().equals(AttributeInfo.TYPE_BOOLEAN)) {
ps = cn.prepareStatement(
"INSERT INTO BooleanAttribute(OId, AId, Content) VALUES(?,?,?)");
ps.setLong(1, dataInfo.getOid());
ps.setLong(2, aInfo.getAid());
ps.setBoolean(3, aInfo.getValue().equals("true") ? true : false);
ps.executeUpdate();
ps.close();
ps = null;
} else if (aInfo.getType().equals(AttributeInfo.TYPE_CHAR)) {
ps = cn.prepareStatement(
"INSERT INTO CharAttribute(OId, AId, Content) VALUES(?,?,?)");
ps.setLong(1, dataInfo.getOid());
ps.setLong(2, aInfo.getAid());
ps.setString(3, aInfo.getValue());
ps.executeUpdate();
ps.close();
ps = null;
} else if (aInfo.getType().equals(AttributeInfo.TYPE_DOUBLE)) {
ps = cn.prepareStatement(
"INSERT INTO DoubleAttribute(OId, AId, Content) VALUES(?,?,?)");
ps.setLong(1, dataInfo.getOid());
ps.setLong(2, aInfo.getAid());
ps.setDouble(3, Double.parseDouble(aInfo.getValue()));
ps.executeUpdate();
ps.close();
ps = null;
} else if (aInfo.getType().equals(AttributeInfo.TYPE_INT)) {
ps = cn.prepareStatement(
"INSERT INTO IntegerAttribute(OId, AId, Content) VALUES(?,?,?)");
ps.setLong(1, dataInfo.getOid());
ps.setLong(2, aInfo.getAid());
ps.setLong(3, Long.parseLong(aInfo.getValue()));
ps.executeUpdate();
ps.close();
ps = null;
} else if (aInfo.getType().equals(AttributeInfo.TYPE_TEXT)) {
ps = cn.prepareStatement(
"INSERT INTO ClobAttribute(OId, AId, Content) VALUES(?,?,?)");
ps.setLong(1, dataInfo.getOid());
ps.setLong(2, aInfo.getAid());
ps.setLong(3, Long.parseLong(aInfo.getValue()));
ps.executeUpdate();
ps.close();
ps = null;
}
}
} catch (Exception ex) {
if (Debug.isJavaBeanDebug) {
ex.printStackTrace();
}
throw ex;
} finally {
try {if (rs != null) {rs.close();
rs = null;
}
} catch (Exception ex) {}
try {if (ps != null) {ps.close();
ps = null;
}
} catch (Exception ex) {}
try {if (cn != null) {cn.close();
cn = null;
}
} catch (Exception ex) {}
}
}
/**
* 修改一个数据对象信息,包括他的基本信息以及属性信息
* @param dataInfo DataInfo 数据对象信息
* @throws Exception
*/
public void modifyDataInfo(DataInfo dataInfo) throws Exception {
Connection cn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
cn = DBConnection.getConnection();
cn.setAutoCommit(false);
ps = cn.prepareStatement(
"UPDATE DataInfo SET CName = ?, EName = ?, LastModifyTime = ?,"
+ " Digest = ? WHERE OId = ?");
ps.setString(1, dataInfo.getCname());
ps.setString(2, dataInfo.getEname());
ps.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
ps.executeUpdate();
ps.close();
ps = null;
ArrayList attributeList = dataInfo.getAttributeList();
for (int i = 0; i < attributeList.size(); i++) {
AttributeInfo aInfo = (AttributeInfo) attributeList.get(i);
if (aInfo.getType().equals(AttributeInfo.TYPE_BOOLEAN)) {
ps = cn.prepareStatement(
"UPDATE BooleanAttribute SET Content = ? WHERE OId = ? AND AId = ?");
ps.setBoolean(1, aInfo.getValue().equals("true") ? true : false);
ps.setLong(2, aInfo.getOid());
ps.setLong(3, aInfo.getAid());
ps.executeUpdate();
ps.close();
ps = null;
} else if (aInfo.getType().equals(AttributeInfo.TYPE_CHAR)) {
ps = cn.prepareStatement(
"UPDATE CharAttribute SET Content = ? WHERE OId = ? AND AId = ?");
ps.setString(1, aInfo.getValue());
ps.setLong(2, aInfo.getOid());
ps.setLong(3, aInfo.getAid());
ps.executeUpdate();
ps.close();
ps = null;
} else if (aInfo.getType().equals(AttributeInfo.TYPE_DOUBLE)) {
ps = cn.prepareStatement(
"UPDATE DoubleAttribute SET Content = ? WHERE OId = ? AND AId = ?");
ps.setDouble(1, Double.parseDouble(aInfo.getValue()));
ps.setLong(2, aInfo.getOid());
ps.setLong(3, aInfo.getAid());
ps.executeUpdate();
ps.close();
ps = null;
} else if (aInfo.getType().equals(AttributeInfo.TYPE_INT)) {
ps = cn.prepareStatement(
"UPDATE DoubleAttribute SET Content = ? WHERE OId = ? AND AId = ?");
ps.setLong(1, Long.parseLong(aInfo.getValue()));
ps.setLong(2, aInfo.getOid());
ps.setLong(3, aInfo.getAid());
ps.executeUpdate();
ps.close();
ps = null;
} else if (aInfo.getType().equals(AttributeInfo.TYPE_TEXT)) {
ps = cn.prepareStatement(
"UPDATE DoubleAttribute SET Content = ? WHERE OId = ? AND AId = ?");
ps.setString(1, aInfo.getValue());
ps.setLong(2, aInfo.getOid());
ps.setLong(3, aInfo.getAid());
ps.executeUpdate();
ps.close();
ps = null;
}
}
cn.commit();
cn.setAutoCommit(true);
} catch (Exception ex) {
if (Debug.isJavaBeanDebug) {
ex.printStackTrace();
}
try {
if (cn != null && !cn.getAutoCommit()) {
cn.rollback();
cn.setAutoCommit(true);
}
} catch (Exception e) {}
throw ex;
} finally {
try {if (rs != null) {rs.close();
rs = null;
}
} catch (Exception ex) {}
try {if (ps != null) {ps.close();
ps = null;
}
} catch (Exception ex) {}
try {if (cn != null) {cn.close();
cn = null;
}
} catch (Exception ex) {}
}
}
/**
* 删除一条数据对象信息
* @param oid long 数据对象编号
* @return int 被删除的数据对象信息的数量
* @throws Exception
*/
public int deleteDataInfo(long oid) throws Exception {
Connection cn = null;
PreparedStatement ps = null;
ResultSet rs = null;
int deleteNum = 0;
try {
cn = DBConnection.getConnection();
cn.setAutoCommit(false);
deleteNum = deleteDataInfo(oid, cn);
cn.commit();
cn.setAutoCommit(true);
} catch (Exception ex) {
if (Debug.isJavaBeanDebug) {
ex.printStackTrace();
}
if (cn != null && !cn.getAutoCommit()) {
cn.rollback();
cn.setAutoCommit(true);
}
} finally {
try {if (rs != null) {rs.close();
rs = null;
}
} catch (Exception ex) {}
try {if (ps != null) {ps.close();
ps = null;
}
} catch (Exception ex) {}
try {if (cn != null) {cn.close();
cn = null;
}
} catch (Exception ex) {}
}
return deleteNum;
}
/**
* 删除一部分数据对象信息
* @param oid long[] 将被删除的数据对象编号
* @return int 被删除的数据对象信息的数量
* @throws Exception
*/
public int deleteDataInfo(long[] oid) throws Exception {
Connection cn = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -