1 23 package org.apache.slide.store.impl.rdbms; 24 25 26 import java.sql.Connection ; 27 import java.sql.PreparedStatement ; 28 import java.sql.SQLException ; 29 30 import org.apache.slide.common.Service; 31 import org.apache.slide.common.ServiceAccessException; 32 import org.apache.slide.common.Uri; 33 import org.apache.slide.content.NodeRevisionDescriptor; 34 import org.apache.slide.content.NodeRevisionNumber; 35 import org.apache.slide.store.impl.rdbms.MySqlRDBMSAdapter; 36 import org.apache.slide.structure.ObjectNode; 37 import org.apache.slide.structure.ObjectNotFoundException; 38 import org.apache.slide.util.logger.Logger; 39 40 45 public class MySql41RDBMSAdapter extends MySqlRDBMSAdapter { 46 47 51 public MySql41RDBMSAdapter(Service service, Logger logger) { 52 super(service, logger); 53 } 54 55 60 public void removeObject(Connection connection, Uri uri, ObjectNode object) 61 throws ServiceAccessException, ObjectNotFoundException { 62 PreparedStatement statement = null; 63 try { 64 clearBinding(connection, uri); 65 66 try { 68 statement = 69 connection.prepareStatement( 70 "delete l from LINKS l, URI u where l.URI_ID = u.URI_ID and u.URI_STRING = ?"); 71 statement.setString(1, uri.toString()); 72 statement.executeUpdate(); 73 } finally { 74 close(statement); 75 } 76 try { 79 statement = 80 connection.prepareStatement( 81 "delete vh from VERSION_HISTORY vh, URI u where vh.URI_ID = u.URI_ID and u.URI_STRING = ?"); 82 statement.setString(1, uri.toString()); 83 statement.executeUpdate(); 84 } 85 finally { 86 close(statement); 87 } 88 try { 90 statement = 91 connection.prepareStatement( 92 "delete v from VERSION v, URI u where v.URI_ID = u.URI_ID and u.URI_STRING = ?"); 93 statement.setString(1, uri.toString()); 94 statement.executeUpdate(); 95 } 96 finally { 97 close(statement); 98 } 99 try { 101 statement = 102 connection.prepareStatement( 103 "delete o from OBJECT o, URI u where o.URI_ID = u.URI_ID and u.URI_STRING = ?"); 104 statement.setString(1, uri.toString()); 105 statement.executeUpdate(); 106 } 107 finally { 108 close(statement); 109 } 110 try { 112 statement = connection.prepareStatement("delete from URI where URI_STRING = ?"); 113 statement.setString(1, uri.toString()); 114 statement.executeUpdate(); 115 } 116 finally { 117 close(statement); 118 } 119 } 120 catch (SQLException e) { 121 throw createException(e, uri.toString()); 122 } 123 } 124 125 130 public void removeRevisionContent(Connection connection, Uri uri, 131 NodeRevisionDescriptor revisionDescriptor) throws ServiceAccessException { 132 try { 133 PreparedStatement statement = null; 134 try { 135 statement = 136 connection.prepareStatement( 137 "delete vc from VERSION_CONTENT vc, VERSION_HISTORY vh, URI u where vc.VERSION_ID = vh.VERSION_ID and vh.REVISION_NO = ? and vh.URI_ID=u.URI_ID AND u.URI_STRING=?"); 138 statement.setString(1, revisionDescriptor.getRevisionNumber().toString()); 139 statement.setString(2, uri.toString()); 140 statement.executeUpdate(); 141 } 142 finally { 143 close(statement); 144 } 145 } 146 catch (SQLException e) { 147 throw createException(e, uri.toString()); 148 } 149 } 150 151 156 public void removeRevisionDescriptor(Connection connection, Uri uri, 157 NodeRevisionNumber revisionNumber) throws ServiceAccessException { 158 PreparedStatement statement = null; 159 try { 160 try { 161 statement = 162 connection.prepareStatement( 163 "delete vl from VERSION_LABELS vl, VERSION_HISTORY vh, URI u where vl.VERSION_ID = vh.VERSION_ID and vh.REVISION_NO = ? and vh.URI_ID = u.URI_ID AND u.URI_STRING = ?"); 164 statement.setString(1, revisionNumber.toString()); 165 statement.setString(2, uri.toString()); 166 statement.executeUpdate(); 167 } 168 finally { 169 close(statement); 170 } 171 try { 172 statement = 173 connection.prepareStatement( 174 "delete p from PROPERTIES p, VERSION_HISTORY vh, URI u where p.VERSION_ID = vh.VERSION_ID and vh.REVISION_NO = ? and vh.URI_ID = u.URI_ID AND u.URI_STRING = ?"); 175 statement.setString(1, revisionNumber.toString()); 176 statement.setString(2, uri.toString()); 177 statement.executeUpdate(); 178 } 179 finally { 180 close(statement); 181 } 182 } 183 catch (SQLException e) { 184 throw createException(e, uri.toString()); 185 } 186 } 187 188 192 public void removeRevisionDescriptors(Connection connection, Uri uri) 193 throws ServiceAccessException { 194 PreparedStatement statement = null; 195 try { 196 statement = 197 connection.prepareStatement( 198 "delete vp from VERSION_PREDS vp, VERSION_HISTORY vh, URI u where vp.VERSION_ID = vh.VERSION_ID and vh.URI_ID = u.URI_ID and u.URI_STRING = ?"); 199 statement.setString(1, uri.toString()); 200 statement.executeUpdate(); 201 } catch (SQLException e) { 202 throw createException(e, uri.toString()); 203 } finally { 204 close(statement); 205 } 206 } 207 208 211 protected void clearBinding(Connection connection, Uri uri) 212 throws ServiceAccessException, ObjectNotFoundException, SQLException { 213 PreparedStatement statement = null; 214 215 try { 217 statement = 218 connection.prepareStatement( 219 "delete c from BINDING c, URI u where c.URI_ID = u.URI_ID and u.URI_STRING = ?"); 220 statement.setString(1, uri.toString()); 221 statement.executeUpdate(); 222 } 223 finally { 224 close(statement); 225 } 226 227 try { 228 statement = 229 connection.prepareStatement( 230 "delete c from PARENT_BINDING c, URI u where c.URI_ID = u.URI_ID and u.URI_STRING = ?"); 231 statement.setString(1, uri.toString()); 232 statement.executeUpdate(); 233 } 234 finally { 235 close(statement); 236 } 237 } 238 } | Popular Tags |