KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > store > impl > rdbms > MySql41RDBMSAdapter


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/MySql41RDBMSAdapter.java,v 1.2 2004/07/28 09:34:17 ib Exp $
3  * $Revision: 1.2 $
4  * $Date: 2004/07/28 09:34:17 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2003 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23 package org.apache.slide.store.impl.rdbms;
24
25
26 import java.sql.Connection JavaDoc;
27 import java.sql.PreparedStatement JavaDoc;
28 import java.sql.SQLException JavaDoc;
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 /**
41  * Adapter for MySQL 4.1. DELETE semantics are somewhat deviant
42  * from MySQL 4.0. Table names should be referred to by their alias.
43  *
44  */

45 public class MySql41RDBMSAdapter extends MySqlRDBMSAdapter {
46
47   /**
48    * @param service
49    * @param logger
50    */

51   public MySql41RDBMSAdapter(Service service, Logger logger) {
52     super(service, logger);
53   }
54   
55   /*
56    * @see org.apache.slide.store.impl.rdbms.RDBMSAdapter#removeObject(
57    * java.sql.Connection, org.apache.slide.common.Uri,
58    * org.apache.slide.structure.ObjectNode)
59    */

60   public void removeObject(Connection JavaDoc connection, Uri uri, ObjectNode object)
61       throws ServiceAccessException, ObjectNotFoundException {
62     PreparedStatement JavaDoc statement = null;
63     try {
64       clearBinding(connection, uri);
65       
66       // delete links
67
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       // delete version history
77
// FIXME: Is this true??? Should the version history be removed if the object is removed???
78
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       // delete version
89
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       // delete the object itself
100
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       // finally delete the uri
111
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 JavaDoc e) {
121       throw createException(e, uri.toString());
122     }
123   }
124   
125   /*
126    * @see org.apache.slide.store.impl.rdbms.RDBMSAdapter#removeRevisionContent(
127    * java.sql.Connection, org.apache.slide.common.Uri,
128    * org.apache.slide.content.NodeRevisionDescriptor)
129    */

130   public void removeRevisionContent(Connection JavaDoc connection, Uri uri,
131       NodeRevisionDescriptor revisionDescriptor) throws ServiceAccessException {
132     try {
133       PreparedStatement JavaDoc 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 JavaDoc e) {
147       throw createException(e, uri.toString());
148     }
149   }
150   
151   /*
152    * @see org.apache.slide.store.impl.rdbms.RDBMSAdapter#removeRevisionDescriptor(
153    * java.sql.Connection, org.apache.slide.common.Uri,
154    * org.apache.slide.content.NodeRevisionNumber)
155    */

156   public void removeRevisionDescriptor(Connection JavaDoc connection, Uri uri,
157       NodeRevisionNumber revisionNumber) throws ServiceAccessException {
158     PreparedStatement JavaDoc 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 JavaDoc e) {
184       throw createException(e, uri.toString());
185     }
186   }
187   
188   /*
189    * @see org.apache.slide.store.impl.rdbms.RDBMSAdapter#removeRevisionDescriptors(
190    * java.sql.Connection, org.apache.slide.common.Uri)
191    */

192   public void removeRevisionDescriptors(Connection JavaDoc connection, Uri uri)
193       throws ServiceAccessException {
194     PreparedStatement JavaDoc 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 JavaDoc e) {
202       throw createException(e, uri.toString());
203     } finally {
204       close(statement);
205     }
206   }
207   
208   /*
209    * @see org.apache.slide.store.impl.rdbms.StandardRDBMSAdapter#clearBinding(java.sql.Connection, org.apache.slide.common.Uri)
210    */

211   protected void clearBinding(Connection JavaDoc connection, Uri uri)
212       throws ServiceAccessException, ObjectNotFoundException, SQLException JavaDoc {
213     PreparedStatement JavaDoc statement = null;
214     
215     // clear this uri from having bindings and being bound
216
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