01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.lucene.store.jdbc.handler;
18:
19: import java.io.IOException;
20: import java.sql.PreparedStatement;
21: import java.util.Iterator;
22: import java.util.List;
23:
24: import org.apache.lucene.store.jdbc.support.JdbcTemplate;
25:
26: /**
27: * Does not delete entries from the database, just marks them for deletion by updating the deleted
28: * column to <code>true</code>.
29: * <p/>
30: * To really delete file entries, use {@link org.apache.lucene.store.jdbc.JdbcDirectory#deleteMarkDeleted()}
31: * or {@link org.apache.lucene.store.jdbc.JdbcDirectory#deleteMarkDeleted(long)}.
32: *
33: * @author kimchy
34: */
35: public class MarkDeleteFileEntryHandler extends
36: AbstractFileEntryHandler {
37:
38: public void deleteFile(final String name) throws IOException {
39: jdbcTemplate.executeUpdate(table.sqlMarkDeleteByName(),
40: new JdbcTemplate.PrepateStatementAwareCallback() {
41: public void fillPrepareStatement(
42: PreparedStatement ps) throws Exception {
43: ps.setFetchSize(1);
44: ps.setBoolean(1, true);
45: ps.setString(2, name);
46: }
47: });
48: }
49:
50: public List deleteFiles(final List names) throws IOException {
51: jdbcTemplate.executeBatch(table.sqlMarkDeleteByName(),
52: new JdbcTemplate.PrepateStatementAwareCallback() {
53: public void fillPrepareStatement(
54: PreparedStatement ps) throws Exception {
55: ps.setFetchSize(1);
56: for (Iterator it = names.iterator(); it
57: .hasNext();) {
58: ps.setBoolean(1, true);
59: ps.setString(2, (String) it.next());
60: ps.addBatch();
61: }
62: }
63: });
64: return null;
65: }
66: }
|