📄 cmsdbaccess.java
字号:
// methods working with session-storage
/**
* This method creates a new session in the database. It is used
* for sessionfailover.
*
* @param sessionId the id of the session.
* @return data the sessionData.
*/
public void createSession(String sessionId, Hashtable data) throws CmsException {
//System.out.println("PL/SQL: createSession");
com.opencms.file.oracleplsql.CmsQueries cq = (com.opencms.file.oracleplsql.CmsQueries) m_cq;
byte[] value = null;
PreparedStatement statement = null;
PreparedStatement statement2 = null;
PreparedStatement nextStatement = null;
Connection con = null;
ResultSet res = null;
try {
// serialize the hashtable
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream oout = new ObjectOutputStream(bout);
oout.writeObject(data);
oout.close();
value = bout.toByteArray();
// write data to database
con = DriverManager.getConnection(m_poolName);
statement = con.prepareStatement(cq.get("C_PLSQL_SESSION_FORINSERT"));
statement.setString(1, sessionId);
statement.setTimestamp(2, new java.sql.Timestamp(System.currentTimeMillis()));
statement.executeUpdate();
statement.close();
statement2 = con.prepareStatement(cq.get("C_PLSQL_SESSION_FORUPDATE"));
statement2.setString(1, sessionId);
con.setAutoCommit(false);
res = statement2.executeQuery();
while (res.next()) {
oracle.sql.BLOB blob = ((OracleResultSet) res).getBLOB("SESSION_DATA");
ByteArrayInputStream instream = new ByteArrayInputStream(value);
OutputStream outstream = blob.getBinaryOutputStream();
byte[] chunk = new byte[blob.getChunkSize()];
int i = -1;
while ((i = instream.read(chunk)) != -1) {
outstream.write(chunk, 0, i);
}
instream.close();
outstream.close();
}
statement2.close();
res.close();
// for the oracle-driver commit or rollback must be executed manually
// because setAutoCommit = false
nextStatement = con.prepareStatement(cq.get("C_COMMIT"));
nextStatement.execute();
nextStatement.close();
con.setAutoCommit(true);
} catch (SQLException e) {
throw new CmsException("[" + this.getClass().getName() + "]" + e.getMessage(), CmsException.C_SQL_ERROR, e);
} catch (IOException e) {
throw new CmsException("[" + this.getClass().getName() + "]:" + CmsException.C_SERIALIZATION, e);
} finally {
if (res != null) {
try {
res.close();
} catch (SQLException se) {
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException exc) {
}
}
if (statement2 != null) {
try {
statement2.close();
} catch (SQLException exc) {
}
try {
nextStatement = con.prepareStatement(cq.get("C_ROLLBACK"));
nextStatement.execute();
} catch (SQLException se) {
}
}
if (nextStatement != null) {
try {
nextStatement.close();
} catch (SQLException exc) {
}
}
if (con != null) {
try {
con.setAutoCommit(true);
} catch (SQLException se) {
}
try {
con.close();
} catch (SQLException e) {
}
}
}
}
/**
* Returns all projects, which are owned by a user.
*
* @param user The requesting user.
*
* @return a Vector of projects.
*/
public Vector getAllAccessibleProjects(CmsUser user) throws CmsException {
//System.out.println("PL/SQL: getAllAccessibleProjects");
com.opencms.file.oracleplsql.CmsQueries cq = (com.opencms.file.oracleplsql.CmsQueries) m_cq;
CallableStatement statement = null;
Connection con = null;
Vector projects = new Vector();
ResultSet res = null;
try {
// create the statement
con = DriverManager.getConnection(m_poolName);
statement = con.prepareCall(cq.get("C_PLSQL_PROJECTS_GETALLACCESS"));
statement.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.CURSOR);
statement.setInt(2, user.getId());
statement.execute();
res = (ResultSet) statement.getObject(1);
while (res.next()) {
projects.addElement(new CmsProject(res.getInt(m_cq.get("C_PROJECTS_PROJECT_ID")),
res.getString(m_cq.get("C_PROJECTS_PROJECT_NAME")),
res.getString(m_cq.get("C_PROJECTS_PROJECT_DESCRIPTION")),
res.getInt(m_cq.get("C_PROJECTS_TASK_ID")),
res.getInt(m_cq.get("C_PROJECTS_USER_ID")),
res.getInt(m_cq.get("C_PROJECTS_GROUP_ID")),
res.getInt(m_cq.get("C_PROJECTS_MANAGERGROUP_ID")),
res.getInt(m_cq.get("C_PROJECTS_PROJECT_FLAGS")),
SqlHelper.getTimestamp(res, m_cq.get("C_PROJECTS_PROJECT_CREATEDATE")),
res.getInt(m_cq.get("C_PROJECTS_PROJECT_TYPE"))));
}
} catch (SQLException sqlexc) {
CmsException cmsException = getCmsException("[" + this.getClass().getName() + "] ", sqlexc);
throw cmsException;
} catch (Exception e) {
throw new CmsException("[" + this.getClass().getName() + "]", e);
} finally {
if (res != null) {
try {
res.close();
} catch (SQLException se) {
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException exc) {
}
}
if (con != null) {
try {
con.close();
} catch (SQLException e) {
}
}
}
return (projects);
}
/**
* Returns a list of groups of a user.<P/>
*
* @param name The name of the user.
* @return Vector of groups
* @exception CmsException Throws CmsException if operation was not succesful
*/
public Vector getAllGroupsOfUser(String username) throws CmsException {
//System.out.println("PL/SQL: getAllGroupsOfUser");
com.opencms.file.oracleplsql.CmsQueries cq = (com.opencms.file.oracleplsql.CmsQueries) m_cq;
CmsUser user = null;
try {
user = readUser(username, C_USER_TYPE_SYSTEMUSER);
} catch (CmsException exc){
user = readUser(username, C_USER_TYPE_WEBUSER);
}
CmsGroup group;
Vector groups = new Vector();
CallableStatement statement = null;
Connection con = null;
ResultSet res = null;
try {
// get all all groups of the user
con = DriverManager.getConnection(m_poolName);
statement = con.prepareCall(cq.get("C_PLSQL_GROUPS_GETGROUPSOFUSER"));
statement.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.CURSOR);
statement.setInt(2, user.getId());
statement.execute();
res = (ResultSet) statement.getObject(1);
while (res.next()) {
group = new CmsGroup(res.getInt(m_cq.get("C_GROUPS_GROUP_ID")),
res.getInt(m_cq.get("C_GROUPS_PARENT_GROUP_ID")),
res.getString(m_cq.get("C_GROUPS_GROUP_NAME")),
res.getString(m_cq.get("C_GROUPS_GROUP_DESCRIPTION")),
res.getInt(m_cq.get("C_GROUPS_GROUP_FLAGS")));
groups.addElement(group);
}
} catch (SQLException sqlexc) {
CmsException cmsException = getCmsException("[" + this.getClass().getName() + "] ", sqlexc);
throw cmsException;
} catch (Exception e) {
throw new CmsException("[" + this.getClass().getName() + "]", e);
} finally {
if (res != null) {
try {
res.close();
} catch (SQLException se) {
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException exc) {
}
}
if (con != null) {
try {
con.close();
} catch (SQLException e){
}
}
}
return groups;
}
/**
* Get the exeption.
*
* @return Exception.
*/
private CmsException getCmsException(String errorIn, Exception exc) {
CmsException cmsException = null;
String exceptionMessage = null;
int exceptionNumber = 0;
exceptionMessage = exc.getMessage();
try {
exceptionNumber = Integer.parseInt(exceptionMessage.substring(4, 9));
} catch(StringIndexOutOfBoundsException iobexc) {
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_DEBUG, "Error in getCmsException() " + exceptionMessage);
}
} catch(Exception otherExc) {
cmsException = new CmsException(errorIn + exceptionMessage, CmsException.C_UNKNOWN_EXCEPTION);
}
switch (exceptionNumber) {
case 20000 :
cmsException = new CmsException(errorIn, CmsException.C_UNKNOWN_EXCEPTION);
break;
case 20001 :
cmsException = new CmsException(errorIn, CmsException.C_NO_ACCESS);
break;
case 20002 :
cmsException = new CmsException(errorIn, CmsException.C_NOT_FOUND);
break;
case 20003 :
cmsException = new CmsException(errorIn, CmsException.C_BAD_NAME);
break;
case 20004 :
cmsException = new CmsException(errorIn + exc.getMessage(), CmsException.C_SQL_ERROR, exc);
break;
case 20005 :
cmsException = new CmsException(errorIn, CmsException.C_NOT_EMPTY);
break;
case 20006 :
cmsException = new CmsException(errorIn, CmsException.C_NOT_ADMIN);
break;
case 20007 :
cmsException = new CmsException(errorIn, CmsException.C_SERIALIZATION);
break;
case 20008 :
cmsException = new CmsException(errorIn, CmsException.C_NO_GROUP);
break;
case 20009 :
cmsException = new CmsException(errorIn, CmsException.C_GROUP_NOT_EMPTY);
break;
case 20010 :
cmsException = new CmsException(errorIn, CmsException.C_NO_USER);
break;
case 20011 :
cmsException = new CmsException(errorIn, CmsException.C_NO_DEFAULT_GROUP);
break;
case 20012 :
cmsException = new CmsException(errorIn, CmsException.C_FILE_EXISTS);
break;
case 20013 :
cmsException = new CmsException(errorIn, CmsException.C_LOCKED);
break;
case 20014 :
cmsException = new CmsException(errorIn, CmsException.C_FILESYSTEM_ERROR);
break;
case 20015 :
cmsException = new CmsException(errorIn, CmsException.C_INTERNAL_FILE);
break;
case 20016 :
// this exception is obselete and should not be used
cmsException = new CmsException(errorIn, 16);
break;
case 20017 :
cmsException = new CmsException(errorIn, CmsException.C_SERVICE_UNAVAILABLE);
break;
case 20028 :
cmsException = new CmsException(errorIn, CmsException.C_LAUNCH_ERROR);
break;
case 20029 :
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -