📄 datatypemanager.java
字号:
+
"SELECT b.* FROM CharAttribute b WHERE a.AId = b.AId AND a.Oid IN("
+
"SELECT c.Oid FROM DataInfo c WHERE c.TId = ?))");
ps.setLong(1, tid);
ps.executeUpdate();
ps.close();
ps = null;
ps = cn.prepareStatement("DELETE FROM ClobAttribute a WHERE EXISTS ("
+
"SELECT b.* FROM CharAttribute b WHERE a.AId = b.AId AND a.Oid IN("
+
"SELECT c.Oid FROM DataInfo c WHERE c.TId = ?))");
ps.setLong(1, tid);
ps.executeUpdate();
ps.close();
ps = null;
ps = cn.prepareStatement("DELETE FROM DataInfo WHERE TId = ?");
ps.setLong(1, tid);
ps.executeUpdate();
ps.close();
ps = null;
ps = cn.prepareStatement("DELETE FROM DataType WHERE Tid = ?");
ps.setLong(1, tid);
ps.executeUpdate();
ps.close();
ps = null;
deleteNum++;
if (isChild) {
for (int i = 0; i < childIds.size(); i++) {
deleteNum = deleteNum +
deleteDataType(Long.parseLong((String) childIds.get(i)),
isChild, cn);
}
} else {
DataTypeInfo parentInfo = getParent(tid);
for (int i = 0; i < childIds.size(); i++) {
modifyParent(Long.parseLong((String) childIds.get(i)),
parentInfo.getTid(), cn);
}
}
} catch (Exception ex) {
if (Debug.isJavaBeanDebug) {
ex.printStackTrace();
}
} finally {
if (ps != null) {try {ps.close();
ps = null;
} catch (Exception e) {}
}
}
return deleteNum;
}
/**
* 得到单个对象类型信息,根据传递的编号获得
* @param tid long 对象类型编号
* @return DataTypeInfo 对象类型信息,如果在获得数据过程中出现错误或未找到数据则返回空对象
*/
public DataTypeInfo getTypeInfo(long tid) {
Connection cn = null;
PreparedStatement ps = null;
ResultSet rs = null;
DataTypeInfo info = null;
try {
cn = DBConnection.getConnection();
ps = cn.prepareStatement("SELECT * FROM DataType WHERE Tid = ?");
ps.setLong(1, tid);
rs = ps.executeQuery();
if(rs.next()) {
info = getInfo(rs);
}
} catch (Exception ex) {
if (Debug.isJavaBeanDebug) {
ex.printStackTrace();
}
info = null;
} finally {
if (rs != null) {try {rs.close();
rs = null;
} catch (Exception e) {}
}
if (ps != null) {try {ps.close();
ps = null;
} catch (Exception e) {}
}
if (cn != null) {try {cn.close();
cn = null;
} catch (Exception e) {}
}
}
return info;
}
/**
* 根据条件获得对象类型列表,条件有对象类型的名称,对象类型的父编号
* @param name String 查找包括指定关键字的对象类型信息,对象类型的名称中必须包含此字符串,如要忽略此条件则传""
* @param pid long 对象类型的父编号,必填项,如要查找顶级对象类型,则传递0
* @param pageNo int 页码
* @param pageSize int 每页显示的记录数
* @return PageList 信息列表,当出现错误或未找到信息时返回一个长度为0的PageList
*/
public PageList getTypeList(String name, long pid, int pageNo, int pageSize) {
PageList infoList = new PageList();
if(pageNo<1||pageSize<1) return infoList;
int sumrecords = 0;
int beginrecord = (pageNo-1)*pageSize + 1;
int endrecord = beginrecord+pageSize - 1;
Connection cn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
StringBuffer whereStr = new StringBuffer();
ArrayList parList = new ArrayList();
whereStr.append(" WHERE Pid = ?");
parList.add(new Long(pid));
if(name != null && !name.trim().equals("")) {
whereStr.append(" AND Name LIKE ?");
parList.add("%" + name.trim() + "%");
}
cn = DBConnection.getConnection();
ps = cn.prepareStatement("SELECT COUNT(Tid) AS num FROM DataType " + whereStr.toString());
SQLTools.prepared(parList, ps);
rs = ps.executeQuery();
if(rs.next())
{
sumrecords = rs.getInt("num");
}
rs.close();
ps.close();
if(sumrecords>=beginrecord)
{
int readernum = pageNo * pageSize;
ps = cn.prepareStatement("SELECT * FROM DataType " + whereStr.toString()
+" ORDER BY Tid DESC LIMIT ? OFFSET ?");
parList.add(new Integer(endrecord));
parList.add(new Integer(beginrecord));
SQLTools.prepared(parList, ps);
rs = ps.executeQuery();
while(rs.next()) {
infoList.add(getInfo(rs));
}
}
}
catch(Exception ex) {
if(Debug.isJavaBeanExceptionDebug) ex.printStackTrace();
}
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) {}
}
infoList.pageno=pageNo;
infoList.pagesize=pageSize;
infoList.pagesum=sumrecords;
if(sumrecords>0){
if(sumrecords%pageSize==0)
infoList.pagenum=sumrecords/pageSize;
else
infoList.pagenum=sumrecords/pageSize+1;
}else
infoList.pagenum=0;
return infoList;
}
/**
* 得到指定对象类型的父类型
* @param tid long
* @return ArrayList
*/
public DataTypeInfo getParent(long tid) {
Connection cn = null;
PreparedStatement ps = null;
ResultSet rs = null;
DataTypeInfo info = null;
try {
} catch (Exception ex) {
if (Debug.isJavaBeanDebug) {
ex.printStackTrace();
}
} finally {
if (rs != null) {try {rs.close();
rs = null;
} catch (Exception e) {}
}
if (ps != null) {try {ps.close();
ps = null;
} catch (Exception e) {}
}
if (cn != null) {try {cn.close();
cn = null;
} catch (Exception e) {}
}
}
return info;
}
/**
* 根据结果集得到对象信息
* @param rs ResultSet
* @return DataTypeInfo
*/
private DataTypeInfo getInfo(ResultSet rs) {
DataTypeInfo info = null;
ResultSetMetaData rsmd = null;
try {
rsmd = rs.getMetaData();
info = new DataTypeInfo();
for (int i = 0; i < rsmd.getColumnCount(); i++) {
String column = rsmd.getColumnName(i + 1).toLowerCase();
if (column.equals("tid")) {
info.setTid(rs.getLong("Tid"));
break;
} else if(column.equals("pid")) {
info.setPid(rs.getLong("Pid"));
break;
} else if (column.equals("name")) {
info.setName(rs.getString("Name"));
break;
} else if (column.equals("digest")) {
info.setDigest(rs.getString("Digest"));
break;
} else {
break;
}
}
} catch (Exception ex) {
info = null;
}
return info;
}
/**
* 得到指定对象类型的所有子类型编号
* @param tid long
* @return ArrayList
*/
private ArrayList getChileId(long tid) {
Connection cn = null;
PreparedStatement ps = null;
ResultSet rs = null;
ArrayList tids = new ArrayList();
try {
cn = DBConnection.getConnection();
ps = cn.prepareStatement("SELECT Tid FROM DataType WHERE PId = ?");
ps.setLong(1, tid);
rs = ps.executeQuery();
while (rs.next()) {
tids.add(rs.getString("Tid"));
}
} catch (Exception ex) {
if (Debug.isJavaBeanDebug) {
ex.printStackTrace();
}
tids.clear();
} finally {
if (rs != null) {try {rs.close();
rs = null;
} catch (Exception e) {}
}
if (ps != null) {try {ps.close();
ps = null;
} catch (Exception e) {}
}
if (cn != null) {try {cn.close();
cn = null;
} catch (Exception e) {}
}
}
return tids;
}
/**
* 改变指定对象类型的父类型
* @param tid long
* @param newPid long
*/
private void modifyParent(long tid, long newPid, Connection conn) throws
Exception {
Connection cn = null;
PreparedStatement ps = null;
try {
//cn = DBConnection.getConnection();
cn = conn;
ps = cn.prepareStatement("UPDATE DataType SET PId = ? WHERE TId = ?");
ps.setLong(1, newPid);
ps.setLong(2, tid);
if (ps.executeUpdate() <= 0) {
throw new Exception();
}
} catch (Exception ex) {
if (Debug.isJavaBeanDebug) {
ex.printStackTrace();
}
} finally {
if (ps != null) {try {ps.close();
ps = null;
} catch (Exception e) {}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -