📄 dbunit.java
字号:
/*
* DbUnit.java
*
* Created on 2001年7月4日, 上午10:37
*/
package com.gs.db.dbimp;
import com.gs.db.*;
import com.gs.util.Cacheable;
import com.gs.util.CacheSizes;
import java.sql.*;
import java.util.Iterator;
import java.util.ArrayList;
import java.lang.*;
import java.util.*;
/**
*
* @author administrator
* @version
*/
public class DbUnit
implements Unit, Cacheable {
private static final String LOAD_UNIT_BY_ID =
"SELECT * FROM u_djjg WHERE djjg=? order by djjg";
private static final String UPDATE_UNIT =
"UPDATE u_djjg SET djjgmc=?,lxr=?,lxdh=?,sjjg=?,inside=? WHERE djjg=?";
private static final String GET_PRIORITY_COUNT =
"SELECT groupid FROM gsGroup WHERE djjg=?";
private static final String UNIT_GROUPS =
"SELECT groupid from gsGroup WHERE djjg=? ORDER BY priority ASC ";
private static final String SUB_UNITS =
"SELECT djjg from u_djjg WHERE sjjg=? order by djjg";
private static final String INSIDE_SUB_UNITS =
"SELECT djjg from u_djjg WHERE sjjg=? and inside='1' order by djjg";
private static final String NONINSIDE_SUB_UNITS =
"SELECT djjg from u_djjg WHERE sjjg=? and inside='0' order by djjg";
private static final String UNIT_MEMBERS =
"SELECT DISTINCT gsGroupUser.userid from gsGroup, gsGroupUser"
+ "WHERE gsGroup.djjg=? AND gsGroupUser.groupid=gsGroup.groupid";
private String id = "-1";
private String parentid = null;
private String name = null;
private String lxdh = "";
private String lxr = "";
private String inside = "0";
private ProfileManager profileManager;
private DbIofficeFactory factory;
// get DbUnit from DB, ROOT unit is not created by any functions, but by Setup program
//just get a existing Unit, not any constructors to create a UNIT
protected DbUnit(String unitid, DbIofficeFactory factory) throws
UnitNotFoundException {
this.id = unitid;
this.factory = factory;
this.profileManager = factory.getProfileManager();
loadFromDb();
}
public Iterator getAssociateGroupsIterator() {
return new DbGroupIterator(this, profileManager);
}
public int[] getAssociateGroups() {
//We don't know how many results will be returned, so store them
//in an ArrayList.
int[] mygroups = null;
ArrayList tempGroups = new ArrayList();
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(UNIT_GROUPS);
pstmt.setString(1, this.id);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
tempGroups.add(new Integer(rs.getInt("groupid")));
}
}
catch (SQLException sqle) {
System.err.println("Error in DbUnit: getMyGroups()-" + sqle);
}
finally {
try {
pstmt.close();
}
catch (Exception e) {
e.printStackTrace();
}
try {
con.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
mygroups = new int[tempGroups.size()];
for (int i = 0; i < mygroups.length; i++) {
mygroups[i] = ( (Integer) tempGroups.get(i)).intValue();
}
return mygroups;
}
public String getPhone() {
return lxdh;
}
public String getLxr() {
return lxr;
}
public String getInside() {
return inside;
}
public void setInside(String insd) {
inside = insd;
}
public boolean isInside() {
return inside.equals("1") ? true : false;
}
public String getID() {
return id;
}
public Unit getParentUnit() {
if (id.equals("0"))return null; // this is a root unit
try {
return profileManager.getUnit(parentid);
}
catch (UnitNotFoundException e) {
return null;
}
}
public Unit getInsideTopUnit(){
if(!isInside())
return this;
Unit parent = getParentUnit();
if(parent==null)
return null;
boolean bInside = parent.isInside();
while(bInside){
parent = getParentUnit();
bInside = parent.isInside();
}
return parent;
}
public String getPathName() {
if (this.parentid == null) {
return name;
}
return getParentUnit().getPathName() + "|" + this.name;
}
public Iterator getSubUnitsIterator() {
return new DbUnitIterator( (Unit)this, profileManager);
}
public Iterator getInsideSubUnitsIterator() {
return new DbUnitIterator( (Unit)this, profileManager,1);
}
public Iterator getExtSubUnitsIterator() {
return new DbUnitIterator( (Unit)this, profileManager,2);
}
public String[] getSubUnits() {
//We don't know how many results will be returned, so store them
//in an ArrayList.
String[] units;
ArrayList tempUnits = new ArrayList();
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(SUB_UNITS);
pstmt.setString(1, this.id);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
tempUnits.add(rs.getString("djjg"));
}
}
catch (SQLException sqle) {
System.err.println("Error in DbUnitIterator:constructor()-" + sqle);
}
finally {
try {
pstmt.close();
}
catch (Exception e) {
e.printStackTrace();
}
try {
con.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
//Now copy into an array.
units = new String[tempUnits.size()];
for (int i = 0; i < units.length; i++) {
units[i] = (String) tempUnits.get(i);
}
return units;
}
public String[] getInsideSubUnits() {
//We don't know how many results will be returned, so store them
//in an ArrayList.
String[] units;
ArrayList tempUnits = new ArrayList();
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(INSIDE_SUB_UNITS);
pstmt.setString(1, this.id);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
tempUnits.add(rs.getString("djjg"));
}
}
catch (SQLException sqle) {
System.err.println("Error in DbUnitIterator:constructor()-" + sqle);
}
finally {
try {
pstmt.close();
}
catch (Exception e) {
e.printStackTrace();
}
try {
con.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
//Now copy into an array.
units = new String[tempUnits.size()];
for (int i = 0; i < units.length; i++) {
units[i] = (String) tempUnits.get(i);
}
return units;
}
public String[] getExtSubUnits() {
//We don't know how many results will be returned, so store them
//in an ArrayList.
String[] units;
ArrayList tempUnits = new ArrayList();
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(NONINSIDE_SUB_UNITS);
pstmt.setString(1, this.id);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
tempUnits.add(rs.getString("djjg"));
}
}
catch (SQLException sqle) {
System.err.println("Error in DbUnitIterator:constructor()-" + sqle);
}
finally {
try {
pstmt.close();
}
catch (Exception e) {
e.printStackTrace();
}
try {
con.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -