KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > jdbc > typing > SQLStatementCustomizer


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  * Copyright (C) 2003 XQuark Group.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
19  * You can also get it at http://www.gnu.org/licenses/lgpl.html
20  *
21  * For more information on this software, see http://www.xquark.org.
22  */

23
24 package org.xquark.jdbc.typing;
25
26 /**
27  * This object perform simple SQL statement customization.
28  *
29  */

30 public class SQLStatementCustomizer
31 {
32     private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
33     private static final String JavaDoc RCSName = "$Name: $";
34
35     private String JavaDoc preparedStatement = null;
36
37     /**
38      * Constructor for SQLStatementCustomizer.
39      */

40     public SQLStatementCustomizer(String JavaDoc statement)
41     {
42         preparedStatement = statement;
43     }
44
45     public String JavaDoc getTableCreationStatement(
46         String JavaDoc tableName,
47         String JavaDoc columnSpecs)
48     {
49         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
50         int offset = preparedStatement.indexOf('?');
51         sb.append(preparedStatement.substring(0, offset));
52         sb.append(tableName);
53         int offset2 = preparedStatement.indexOf('?', offset + 1);
54         sb.append(preparedStatement.substring(offset + 1, offset2));
55         sb.append(columnSpecs);
56         sb.append(preparedStatement.substring(offset2 + 1));
57         return sb.toString();
58     }
59
60     public String JavaDoc getSelectStatement(
61         String JavaDoc columnList,
62         String JavaDoc tableName,
63         String JavaDoc filterClause)
64     {
65         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
66         int offset = preparedStatement.indexOf('?');
67         sb.append(preparedStatement.substring(0, offset));
68         sb.append(columnList);
69         int offset2 = preparedStatement.indexOf('?', offset + 1);
70         sb.append(preparedStatement.substring(offset + 1, offset2));
71         sb.append(tableName);
72         offset = offset2 + 1;
73         offset2 = preparedStatement.indexOf('?', offset);
74         sb.append(preparedStatement.substring(offset, offset2));
75         sb.append(filterClause);
76         sb.append(preparedStatement.substring(offset2 + 1));
77         return sb.toString();
78     }
79 }
80
Popular Tags