📄 cmsdbaccess.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/file/oracleplsql/CmsDbAccess.java,v $
* Date : $Date: 2002/04/30 09:29:57 $
* Version: $Revision: 1.48 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001 The OpenCms Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about OpenCms, please see the
* OpenCms Website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.opencms.file.oracleplsql;
import oracle.jdbc.driver.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
import java.security.*;
import java.io.*;
import source.org.apache.java.io.*;
import source.org.apache.java.util.*;
import com.opencms.core.*;
import com.opencms.file.*;
import com.opencms.file.utils.*;
import com.opencms.util.*;
/**
* This is the generic access module to load and store resources from and into
* the database.
*
* @author Andreas Schouten
* @author Michael Emmerich
* @author Hanjo Riege
* @author Anders Fugmann
* @version $Revision: 1.48 $ $Date: 2002/04/30 09:29:57 $ *
*/
public class CmsDbAccess extends com.opencms.file.genericSql.CmsDbAccess implements I_CmsConstants, I_CmsLogChannels {
/**
* Instanciates the access-module and sets up all required modules and connections.
* @param config The OpenCms configuration.
* @exception CmsException Throws CmsException if something goes wrong.
*/
public CmsDbAccess(Configurations config)
throws CmsException {
super(config);
}
/**
* Checks, if the user may create this resource.
*
* @param currentUser The user who requested this method.
* @param currentProject The current project of the user.
* @param resource The resource to check.
* @return wether the user has access, or not.
*/
public boolean accessCreate(CmsUser currentUser, CmsProject currentProject, CmsResource resource) throws CmsException {
//System.out.println("PL/SQL: accessCreate");
com.opencms.file.oracleplsql.CmsQueries cq = (com.opencms.file.oracleplsql.CmsQueries) m_cq;
CallableStatement statement = null;
Connection con = null;
try {
// create the statement
con = DriverManager.getConnection(m_poolName);
statement = con.prepareCall(cq.get("C_PLSQL_ACCESS_ACCESSCREATE"));
statement.registerOutParameter(1, Types.INTEGER);
statement.setInt(2, currentUser.getId());
statement.setInt(3, currentProject.getId());
statement.setInt(4, resource.getResourceId());
statement.execute();
if (statement.getInt(1) == 1) {
return true;
} else {
return false;
}
} catch (SQLException sqlexc) {
CmsException cmsException = getCmsException("[" + this.getClass().getName() + "] ", sqlexc);
throw cmsException;
} catch (Exception e) {
throw new CmsException("[" + this.getClass().getName() + "]", e);
} finally {
if (statement != null) {
try {
statement.close();
} catch (SQLException exc){
// nothing to do here
}
}
if (con != null) {
try {
con.close();
} catch (SQLException exc){
// nothing to do here
}
}
}
}
/**
* Checks, if the user may lock this resource.
*
* @param currentUser The user who requested this method.
* @param currentProject The current project of the user.
* @param resource The resource to check.
* @return wether the user has access, or not.
*/
public boolean accessLock(CmsUser currentUser, CmsProject currentProject, CmsResource resource) throws CmsException {
//System.out.println("PL/SQL: accessLock");
com.opencms.file.oracleplsql.CmsQueries cq = (com.opencms.file.oracleplsql.CmsQueries) m_cq;
CallableStatement statement = null;
Connection con = null;
try {
// create the statement
con = DriverManager.getConnection(m_poolName);
statement = con.prepareCall(cq.get("C_PLSQL_ACCESS_ACCESSLOCK"));
statement.registerOutParameter(1, Types.INTEGER);
statement.setInt(2, currentUser.getId());
statement.setInt(3, currentProject.getId());
statement.setInt(4, resource.getResourceId());
statement.execute();
if (statement.getInt(1) == 1) {
return true;
} else {
return false;
}
} catch (SQLException sqlexc) {
CmsException cmsException = getCmsException("[" + this.getClass().getName() + "] ", sqlexc);
throw cmsException;
} catch (Exception e) {
throw new CmsException("[" + this.getClass().getName() + "]", e);
} finally {
if (statement != null) {
try {
statement.close();
} catch (SQLException exc){
// nothing to do here
}
}
if (con != null) {
try {
con.close();
} catch (SQLException exc){
// nothing to do here
}
}
}
}
/**
* Checks, if the user may read this resource.
*
* @param currentUser The user who requested this method.
* @param currentProject The current project of the user.
* @param resource The resource to check.
* @return wether the user has access, or not
*/
public boolean accessProject(CmsUser currentUser, int projectId) throws CmsException {
//System.out.println("PL/SQL: accessProject");
com.opencms.file.oracleplsql.CmsQueries cq = (com.opencms.file.oracleplsql.CmsQueries) m_cq;
CallableStatement statement = null;
Connection con = null;
try {
// create the statement
con = DriverManager.getConnection(m_poolName);
statement = con.prepareCall(cq.get("C_PLSQL_ACCESS_ACCESSPROJECT"));
statement.registerOutParameter(1, Types.INTEGER);
statement.setInt(2, currentUser.getId());
statement.setInt(3, projectId);
statement.execute();
if (statement.getInt(1) == 1) {
return true;
} else {
return false;
}
} catch (SQLException sqlexc) {
CmsException cmsException = getCmsException("[" + this.getClass().getName() + "] ", sqlexc);
throw cmsException;
} catch (Exception e) {
throw new CmsException("[" + this.getClass().getName() + "]", e);
} finally {
if (statement != null) {
try {
statement.close();
} catch (SQLException exc){
// nothing to do here
}
}
if (con != null) {
try {
con.close();
} catch (SQLException exc){
// nothing to do here
}
}
}
}
/**
* Checks, if the user may read this resource.
*
* @param currentUser The user who requested this method.
* @param currentProject The current project of the user.
* @param resource The resource to check.
* @return wether the user has access, or not.
*/
public boolean accessRead(CmsUser currentUser, CmsProject currentProject, CmsResource resource) throws CmsException {
//System.out.println("PL/SQL: accessRead");
com.opencms.file.oracleplsql.CmsQueries cq = (com.opencms.file.oracleplsql.CmsQueries) m_cq;
CallableStatement statement = null;
Connection con = null;
try {
// create the statement
con = DriverManager.getConnection(m_poolName);
statement = con.prepareCall(cq.get("C_PLSQL_ACCESS_ACCESSREAD"));
statement.registerOutParameter(1, Types.INTEGER);
statement.setInt(2, currentUser.getId());
statement.setInt(3, currentProject.getId());
statement.setString(4, resource.getResourceName());
statement.execute();
if (statement.getInt(1) == 1) {
return true;
} else {
return false;
}
} catch (SQLException sqlexc) {
CmsException cmsException = getCmsException("[" + this.getClass().getName() + "] ", sqlexc);
throw cmsException;
} catch (Exception e) {
throw new CmsException("[" + this.getClass().getName() + "]", e);
} finally {
if (statement != null) {
try {
statement.close();
} catch (SQLException exc){
// nothing to do here
}
}
if (con != null) {
try {
con.close();
} catch (SQLException exc){
// nothing to do here
}
}
}
}
/**
* Checks, if the user may write this resource.
*
* @param currentUser The user who requested this method.
* @param currentProject The current project of the user.
* @param resource The resource to check.
* @return wether the user has access, or not.
*/
public boolean accessWrite(CmsUser currentUser, CmsProject currentProject, CmsResource resource) throws CmsException {
//System.out.println("PL/SQL: accessWrite");
com.opencms.file.oracleplsql.CmsQueries cq = (com.opencms.file.oracleplsql.CmsQueries) m_cq;
CallableStatement statement = null;
Connection con = null;
try {
// create the statement
con = DriverManager.getConnection(m_poolName);
statement = con.prepareCall(cq.get("C_PLSQL_ACCESS_ACCESSWRITE"));
statement.registerOutParameter(1, Types.INTEGER);
statement.setInt(2, currentUser.getId());
statement.setInt(3, currentProject.getId());
statement.setInt(4, resource.getResourceId());
statement.execute();
if (statement.getInt(1) == 1) {
return true;
} else {
return false;
}
} catch (SQLException sqlexc) {
CmsException cmsException = getCmsException("[" + this.getClass().getName() + "] ", sqlexc);
throw cmsException;
} catch (Exception e) {
throw new CmsException("[" + this.getClass().getName() + "]", e);
} finally {
if (statement != null) {
try {
statement.close();
} catch (SQLException exc){
// nothing to do here
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -