1 31 32 package org.opencms.db.oracle; 33 34 import org.opencms.db.CmsDbContext; 35 import org.opencms.db.CmsDbEntryNotFoundException; 36 import org.opencms.db.CmsDbIoException; 37 import org.opencms.db.CmsDbSqlException; 38 import org.opencms.db.generic.CmsSqlManager; 39 import org.opencms.db.generic.Messages; 40 import org.opencms.file.CmsDataAccessException; 41 import org.opencms.file.CmsProject; 42 import org.opencms.util.CmsUUID; 43 44 import java.io.IOException ; 45 import java.io.OutputStream ; 46 import java.sql.Connection ; 47 import java.sql.PreparedStatement ; 48 import java.sql.ResultSet ; 49 import java.sql.SQLException ; 50 51 import org.apache.commons.dbcp.DelegatingResultSet; 52 53 63 public class CmsVfsDriver extends org.opencms.db.generic.CmsVfsDriver { 64 65 68 public void createContent(CmsDbContext dbc, CmsProject project, CmsUUID resourceId, byte[] content, int versionId) 69 throws CmsDataAccessException { 70 71 PreparedStatement stmt = null; 72 Connection conn = null; 73 74 try { 75 conn = m_sqlManager.getConnection(dbc, project.getId()); 76 stmt = m_sqlManager.getPreparedStatement(conn, project, "C_ORACLE_CONTENTS_ADD"); 77 78 stmt.setString(1, new CmsUUID().toString()); 81 stmt.setString(2, resourceId.toString()); 82 83 stmt.executeUpdate(); 84 } catch (SQLException e) { 85 throw new CmsDbSqlException(org.opencms.db.generic.Messages.get().container( 86 org.opencms.db.generic.Messages.ERR_GENERIC_SQL_1, 87 CmsDbSqlException.getErrorQuery(stmt)), e); 88 } finally { 89 m_sqlManager.closeAll(dbc, conn, stmt, null); 90 } 91 92 writeContent(dbc, project, resourceId, content); 94 } 95 96 99 public org.opencms.db.generic.CmsSqlManager initSqlManager(String classname) { 100 101 return CmsSqlManager.getInstance(classname); 102 } 103 104 107 public void writeContent(CmsDbContext dbc, CmsProject project, CmsUUID resourceId, byte[] content) 108 throws CmsDataAccessException { 109 110 PreparedStatement stmt = null; 111 PreparedStatement commit = null; 112 PreparedStatement rollback = null; 113 Connection conn = null; 114 ResultSet res = null; 115 116 boolean wasInTransaction = false; 117 try { 118 conn = m_sqlManager.getConnection(dbc, project.getId()); 119 stmt = m_sqlManager.getPreparedStatement(conn, project, "C_ORACLE_CONTENTS_UPDATECONTENT"); 120 121 wasInTransaction = !conn.getAutoCommit(); 122 if (!wasInTransaction) { 123 conn.setAutoCommit(false); 124 } 125 126 stmt.setString(1, resourceId.toString()); 128 res = ((DelegatingResultSet)stmt.executeQuery()).getInnermostDelegate(); 129 if (!res.next()) { 130 throw new CmsDbEntryNotFoundException(Messages.get().container( 131 Messages.LOG_READING_RESOURCE_1, 132 resourceId)); 133 } 134 135 OutputStream output = CmsUserDriver.getOutputStreamFromBlob(res, "FILE_CONTENT"); 137 output.write(content); 138 output.close(); 139 140 if (!wasInTransaction) { 141 commit = m_sqlManager.getPreparedStatement(conn, "C_COMMIT"); 142 commit.execute(); 143 m_sqlManager.closeAll(dbc, null, commit, null); 144 } 145 146 m_sqlManager.closeAll(dbc, null, stmt, res); 147 148 commit = null; 149 stmt = null; 150 res = null; 151 152 if (!wasInTransaction) { 153 conn.setAutoCommit(true); 154 } 155 156 } catch (IOException e) { 157 throw new CmsDbIoException(Messages.get().container(Messages.ERR_WRITING_TO_OUTPUT_STREAM_1, resourceId), e); 158 } catch (SQLException e) { 159 throw new CmsDbSqlException(org.opencms.db.generic.Messages.get().container( 160 org.opencms.db.generic.Messages.ERR_GENERIC_SQL_1, 161 CmsDbSqlException.getErrorQuery(stmt)), e); 162 } finally { 163 164 if (res != null) { 165 try { 166 res.close(); 167 } catch (SQLException exc) { 168 } 170 } 171 172 if (commit != null) { 173 try { 174 commit.close(); 175 } catch (SQLException exc) { 176 } 178 } 179 180 if (!wasInTransaction) { 181 if (stmt != null) { 182 try { 183 rollback = m_sqlManager.getPreparedStatement(conn, "C_ROLLBACK"); 184 rollback.execute(); 185 rollback.close(); 186 } catch (SQLException se) { 187 } 189 try { 190 stmt.close(); 191 } catch (SQLException exc) { 192 } 194 } 195 if (conn != null) { 196 try { 197 conn.setAutoCommit(true); 198 conn.close(); 199 } catch (SQLException se) { 200 } 202 } 203 } 204 } 205 } 206 } 207 | Popular Tags |