📄 cmsdbaccess.java
字号:
// nothing to do here
}
}
if(con != null) {
try {
con.close();
} catch(SQLException exc) {
// nothing to do here
}
}
}
return(projects);
}
/**
* retrieve the correct instance of the queries holder.
* This method should be overloaded if other query strings should be used.
*/
protected com.opencms.file.genericSql.CmsQueries getQueries()
{
return new com.opencms.file.oraclesql.CmsQueries();
}
/**
* Private helper method to read the fileContent for publishProject(export).
*
* @param fileId the fileId.
*
* @throws CmsException Throws CmsException if operation was not succesful.
*/
protected byte[] readFileContent(int projectId, int fileId)
throws CmsException {
//System.out.println("PL/SQL: readFileContent");
PreparedStatement statement = null;
Connection con = null;
ResultSet res = null;
byte[] returnValue = null;
int onlineProject = I_CmsConstants.C_PROJECT_ONLINE_ID;
String usedPool;
String usedStatement;
if (projectId == onlineProject){
usedPool = m_poolNameOnline;
usedStatement = "_ONLINE";
} else {
usedPool = m_poolName;
usedStatement = "";
}
try {
// read fileContent from database
con = DriverManager.getConnection(usedPool);
statement = con.prepareStatement(m_cq.get("C_FILE_READ"+usedStatement));
statement.setInt(1,fileId);
res = statement.executeQuery();
if (res.next()) {
returnValue = getBytesFromResultset(res, m_cq.get("C_RESOURCES_FILE_CONTENT"));
} else {
throw new CmsException("["+this.getClass().getName()+"]"+fileId,CmsException.C_NOT_FOUND);
}
} catch (SQLException e){
throw new CmsException("["+this.getClass().getName()+"] "+e.getMessage(),CmsException.C_SQL_ERROR, 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 se) {
}
}
}
return returnValue;
}
/**
* This method updates a session in the database. It is used
* for sessionfailover.
*
* @param sessionId the id of the session.
* @return data the sessionData.
*/
public int updateSession(String sessionId, Hashtable data) throws CmsException {
byte[] value = null;
PreparedStatement statement = null;
PreparedStatement statement2 = null;
PreparedStatement nextStatement = null;
PreparedStatement trimStatement = null;
Connection con = null;
int retValue;
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 in two steps because of using Oracle BLOB
// first update the session_time
con = DriverManager.getConnection(m_poolName);
statement = con.prepareStatement(m_cq.get("C_ORACLE_SESSION_UPDATE"));
statement.setTimestamp(1, new java.sql.Timestamp(System.currentTimeMillis()));
statement.setString(2, sessionId);
retValue = statement.executeUpdate();
statement.close();
// now update the session_data
statement2 = con.prepareStatement(m_cq.get("C_ORACLE_SESSION_FORUPDATE"));
statement2.setString(1, sessionId);
con.setAutoCommit(false);
res = statement2.executeQuery();
while (res.next()) {
oracle.sql.BLOB blob = ((OracleResultSet) res).getBLOB("SESSION_DATA");
// first trim the blob to 0 bytes, otherwise there could be left some bytes
// of the old content
trimStatement = con.prepareStatement(m_cq.get("C_TRIMBLOB"));
trimStatement.setBlob(1, blob);
trimStatement.setInt(2, 0);
trimStatement.execute();
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 in CmsDbPool.CmsDbPool
nextStatement = con.prepareStatement(m_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(m_cq.get("C_ROLLBACK"));
nextStatement.execute();
} catch (SQLException se) {
}
}
if (nextStatement != null) {
try {
nextStatement.close();
} catch (SQLException exc) {
}
}
if (trimStatement != null) {
try {
trimStatement.close();
} catch (SQLException exc) {
}
}
if (con != null) {
try {
con.setAutoCommit(true);
} catch (SQLException se) {
}
try {
con.close();
} catch (SQLException se) {
}
}
}
return retValue;
}
/**
* Writes a serializable object to the systemproperties.
*
* @param name The name of the property.
* @param object The property-object.
*
* @return object The property-object.
*
* @throws CmsException Throws CmsException if something goes wrong.
*/
public Serializable writeSystemProperty(String name, Serializable object) throws CmsException {
PreparedStatement statement = null;
PreparedStatement nextStatement = null;
PreparedStatement trimStatement = null;
ResultSet res = null;
Connection con = null;
byte[] value = null;
try {
// serialize the object
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream oout = new ObjectOutputStream(bout);
oout.writeObject(object);
oout.close();
value = bout.toByteArray();
con = DriverManager.getConnection(m_poolName);
statement = con.prepareStatement(m_cq.get("C_ORACLE_SYSTEMPROPERTIES_NAMEFORUPDATE"));
statement.setString(1, name);
con.setAutoCommit(false);
res = statement.executeQuery();
while (res.next()) {
oracle.sql.BLOB blob = ((OracleResultSet) res).getBLOB("SYSTEMPROPERTY_VALUE");
// first trim the blob to 0 bytes, otherwise ther could be left some bytes
// of the old content
trimStatement = con.prepareStatement(m_cq.get("C_TRIMBLOB"));
trimStatement.setBlob(1, blob);
trimStatement.setInt(2, 0);
trimStatement.execute();
trimStatement.close();
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();
}
statement.close();
res.close();
// for the oracle-driver commit or rollback must be executed manually
// because setAutoCommit = false in CmsDbPool.CmsDbPool
nextStatement = con.prepareStatement(m_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 se) {
}
try {
nextStatement = con.prepareStatement(m_cq.get("C_ROLLBACK"));
nextStatement.execute();
} catch (SQLException exc){
}
}
if (nextStatement != null) {
try {
nextStatement.close();
} catch (SQLException exc) {
}
}
if (trimStatement != null) {
try {
trimStatement.close();
} catch (SQLException exc) {
}
}
if (con != null) {
try {
con.setAutoCommit(true);
} catch (SQLException se) {
}
try {
con.close();
} catch (SQLException se) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -