📄 dbiofficefactory.java
字号:
}
catch( SQLException sqle ) {
System.err.println( "SQLException in DbIofficeFactory.java:" +
"getUserPermissionTypes(User user):reading groupperm table " + sqle );
result = new int[0];
}
finally {
try { pstmt.close(); }
catch (Exception e) { e.printStackTrace(); }
try { con.close(); }
catch (Exception e) { e.printStackTrace(); }
}
return result;
}
public int[] getGroupPermissionTypes(Group group)
{
ArrayList list=new ArrayList();
Connection con = null;
PreparedStatement pstmt = null;
int permtype;
int[] result=null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GROUP_PERMISSION);
pstmt.setInt(1, group.getID());
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
permtype = rs.getInt("IDMenue");
list.add( new Integer( permtype));
}
result = new int[ list.size() ];
for ( int i=0; i< list.size(); i++)
result[i]=((Integer)list.get(i)).intValue();
}
catch( SQLException sqle ) {
System.err.println( "SQLException in DbIofficeFactory.java:" +
"getGroupPermisssionTypes(Group group):reading groupperm table " + sqle );
result = new int[0];
}
finally {
try { pstmt.close(); }
catch (Exception e) { e.printStackTrace(); }
try { con.close(); }
catch (Exception e) { e.printStackTrace(); }
}
return result;
}
/**
* Return all user pairs, among each of which a
* superving relationship is specially defined.
* The result is an ArrayList of Integer Objects,
* the are order as sub1,obj1, sub2, obj2, ...
*/
/**
* Test if the unitToTest is the the predecendant unit of me
*/
public boolean isInCharge ( Unit me , Unit unitToTest )
{
String idtest = unitToTest.getID();
Unit tmpUnit = me.getParentUnit();
while ( tmpUnit != null )
{
if ( tmpUnit.getID().equalsIgnoreCase(idtest) ) return true;
tmpUnit = tmpUnit.getParentUnit();
}
return false ;
}
public void reportPulse(String ipAddr, String doingWhat )
{
//NO one will call this
}
public void reportPulse(int uid, String ipAddr, String doingWhat )
{
long thisPulse = new java.util.Date().getTime();
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(UPDATE_LOGIN);
pstmt.setString(1, ipAddr);
pstmt.setLong(2, thisPulse);
pstmt.setString(3, doingWhat);
pstmt.setInt(4, uid);
pstmt.execute();
}
catch( SQLException sqle ) {
System.err.println("Exception in DbAuthorizationFactory:" + sqle);
sqle.printStackTrace();
}
finally {
try { pstmt.close(); }
catch (Exception e) { e.printStackTrace(); }
try { con.close(); }
catch (Exception e) { e.printStackTrace(); }
}
}
public void deleteLoginRecord() {int i=0;}
public void deleteLoginRecord(int uid)
{
if ( uid<=0 ) return;
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
//delete user group link
pstmt = con.prepareStatement(DELETE_LOGIN_RECORD);
pstmt.setInt(1,uid);
pstmt.execute();
pstmt.close();
}
catch( SQLException sqle ) {
sqle.printStackTrace();
}
finally {
try { pstmt.close(); }
catch (Exception e) { e.printStackTrace(); }
try { con.close(); }
catch (Exception e) { e.printStackTrace(); }
}
}
public Iterator getLoginRecordIterator()
{
return new DbLoginRecordIterator( this );
}
/**
* Tells if a component is accessible to a certain authorization
*/
public boolean isAccessbile( Authorization authorization, IofficeComponent component)
{
if ( authorization.getUserID() == -1 )
return isAccessibleToAnonymousUsers(component); //when authorization is a anonymous user
String query = component.isDefaultAccessible()? FIND_USER_COMP_ACCESS2 :FIND_USER_COMP_ACCESS1;
Connection con = null;
PreparedStatement pstmt = null;
ArrayList list = new ArrayList();
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(query);
pstmt.setInt(1, authorization.getUserID() );
pstmt.setString( 2, component.getName());
ResultSet rs = pstmt.executeQuery();
if (!rs.next()) {
return false;
}
}
catch( SQLException sqle ) {
sqle.printStackTrace();
}
finally {
try { pstmt.close(); }
catch (Exception e) { e.printStackTrace(); }
try { con.close(); }
catch (Exception e) { e.printStackTrace(); }
}
return true;
}
public boolean isAccessibleToAnonymousUsers( IofficeComponent component)
{
int count = annmComp.size();
for (int i=0; i<count; i++)
{
if ( ((String)annmComp.get(i)).equals( component.getName()) ) return true;
}
return false;
}
/**
* Add accessiblity to a component or components for a group
* @param componentName the name of a specified component or 'ALL' OR 'DEFAULTS'
* @param group the object group
* @throws UnauthorizedException if the handle donnot have the right
*/
public void addAccess( String componentName, Group group ) throws UnauthorizedException
{
Connection con = null;
PreparedStatement pstmt = null;
ArrayList list = new ArrayList();
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(INSERT_GROUP_COMP_ACCESS);
pstmt.setString( 1, componentName);
pstmt.setInt(2, group.getID() );
pstmt.executeUpdate();
}
catch( SQLException sqle ) {
//we did not check where the <group, component > already exists or not
//so we have to catch this exception and do nothing for it
}
finally {
try { pstmt.close(); }
catch (Exception e) { e.printStackTrace(); }
try { con.close(); }
catch (Exception e) { e.printStackTrace(); }
}
}
/**
* Remove accessiblity to a component or components for a group
* @param componentName the name of a specified component or 'ALL' OR 'DEFAULTS'
* @param group the object group
* @throws UnauthorizedException if the handle donnot have the right
*/
public void removeAccess(String componentName, Group group ) throws UnauthorizedException
{
Connection con = null;
PreparedStatement pstmt = null;
ArrayList list = new ArrayList();
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(DELETE_GROUP_COMP_ACCESS);
pstmt.setString( 1, componentName);
pstmt.setInt(2, group.getID());
pstmt.executeUpdate();
}
catch( SQLException sqle ) {
sqle.printStackTrace();
}
finally {
try { pstmt.close(); }
catch (Exception e) { e.printStackTrace(); }
try { con.close(); }
catch (Exception e) { e.printStackTrace(); }
}
}
public boolean hasAccess( String componentName, Group group )
{
Connection con = null;
PreparedStatement pstmt = null;
ArrayList list = new ArrayList();
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(CHECK_GROUP_COMP_ACCESS);
pstmt.setString( 1, componentName);
pstmt.setInt(2, group.getID());
ResultSet rs=pstmt.executeQuery();
if ( rs.next()) return true;
}
catch( SQLException sqle ) {
sqle.printStackTrace();
}
finally {
try { pstmt.close(); }
catch (Exception e) { e.printStackTrace(); }
try { con.close(); }
catch (Exception e) { e.printStackTrace(); }
}
return false;
}
public synchronized void addAccessToAnonymousUsers(IofficeComponent component) throws UnauthorizedException
{
String INSERT_ANNM_ACCESS = "INSERT INTO iofficeAnnmCompAccess(componentName) VALUES(?)";
if ( isAccessibleToAnonymousUsers(component) ) return;
annmComp.add( component.getName());
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(INSERT_ANNM_ACCESS);
pstmt.setString( 1, component.getName());
pstmt.executeUpdate();
}
catch( SQLException sqle ) {
sqle.printStackTrace();
}
finally {
try { pstmt.close(); }
catch (Exception e) { e.printStackTrace(); }
try { con.close(); }
catch (Exception e) { e.printStackTrace(); }
}
}
public void removeAccessToAnonymousUsers(IofficeComponent component) throws UnauthorizedException
{
String DELETE_ANNM_ACCESS = "DELETE FROM iofficeannmcompaccess WHERE componentname = ?";
if ( isAccessibleToAnonymousUsers(component) ) return;
String cpName = component.getName();
for ( int i=0; i< annmComp.size(); i++)
{
if ( ((String)annmComp.get(i)).equals(cpName)) annmComp.remove(i);
}
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(DELETE_ANNM_ACCESS);
pstmt.setString( 1, component.getName());
pstmt.executeUpdate();
}
catch( SQLException sqle ) {
sqle.printStackTrace();
}
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 + -