2 * Copyright (C) 2005 The Mir-coders group
\r
4 * This file is part of Mir.
\r
6 * Mir is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 2 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Mir is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with Mir; if not, write to the Free Software
\r
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 * In addition, as a special exception, The Mir-coders gives permission to link
\r
21 * the code of this program with any library licensed under the Apache Software License,
\r
22 * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
\r
23 * (or with modified versions of the above that use the same license as the above),
\r
24 * and distribute linked combinations including the two. You must obey the
\r
25 * GNU General Public License in all respects for all of the code used other than
\r
26 * the above mentioned libraries. If you modify this file, you may extend this
\r
27 * exception to your version of the file, but you are not obligated to do so.
\r
28 * If you do not wish to do so, delete this exception statement from your version.
\r
30 package mir.storage;
\r
32 import java.sql.Connection;
\r
33 import java.sql.ResultSet;
\r
37 * Class to generate update statements
\r
39 public class RecordRetriever extends StatementGenerator {
\r
40 public RecordRetriever(String aTableName, String aPrefix) {
\r
41 tableName = aTableName;
\r
43 if (prefix == null || "".equals(prefix)) {
\r
46 extraTables = new ArrayList();
\r
47 whereClause = new StringBuffer();
\r
48 orderByClause = new StringBuffer();
\r
50 appendQuery("SELECT ");
\r
53 public void addExtraTable(String aTableSpecification) {
\r
54 extraTables.add(aTableSpecification);
\r
57 public void addField(String aField) {
\r
65 appendQuery(prefix);
\r
69 appendQuery(aField);
\r
72 public void appendStringParameter(String aValue) {
\r
73 appendParameter(aValue);
\r
76 public void appendWhereClause(String aPart) {
\r
77 whereClause.append(aPart);
\r
80 public void appendOrderByClause(String aPart) {
\r
81 orderByClause.append(aPart);
\r
84 public void setLimit(int aLimit) {
\r
88 public void setOffset(int anOffset) {
\r
93 * Executes the statement. Returns then number of records
\r
96 public ResultSet execute(Connection aConnection) throws DatabaseFailure {
\r
98 appendQuery("FROM ");
\r
99 appendQuery(tableName);
\r
100 if (prefix!=null) {
\r
102 appendQuery(prefix);
\r
105 Iterator i = extraTables.iterator();
\r
106 while (i.hasNext()) {
\r
108 appendQuery((String) i.next());
\r
111 if (whereClause.toString().trim().length()>0) {
\r
113 appendQuery("WHERE ");
\r
114 appendQuery(whereClause.toString());
\r
117 if (orderByClause.toString().trim().length()>0) {
\r
119 appendQuery("ORDER BY ");
\r
120 appendQuery(orderByClause.toString());
\r
125 appendQuery("LIMIT ");
\r
126 appendQuery(Integer.toString(limit));
\r
131 appendQuery("OFFSET ");
\r
132 appendQuery(Integer.toString(offset));
\r
135 return executeWithResultSet(aConnection);
\r
138 private String tableName;
\r
139 private String prefix;
\r
140 private List extraTables;
\r
141 private boolean firstField = true;
\r
142 private StringBuffer whereClause;
\r
143 private StringBuffer orderByClause;
\r
144 private int limit = -1;
\r
145 private int offset = -1;
\r
147 private static final String CRLF = "\n\r";
\r