Source code: org/jdbf/engine/sql/SQLStatement.java
1 /*
2 * 06/05/2002 - 23:35:27
3 *
4 * SQLStatement.java - JDBF Object Relational mapping system
5 * Copyright (C) 2002 Giovanni Martone
6 * giovannimartone@hotmail.com
7 * http://jdbf.sourceforge.net
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24
25 package org.jdbf.engine.sql;
26
27 import org.jdbf.engine.criteria.Criteria;
28 import org.jdbf.engine.repository.RepositoryView;
29
30 /**
31 * <code>SQLStatement</code> is an abstract class that represents the sql
32 * statement.
33 * SQLStatement handles the creation of sql statement with the informations
34 * specified in a RepositoryView object.
35 */
36 public abstract class SQLStatement{
37
38 /** class name */
39 protected String className = this.getClass().getName();
40 /** sql statement */
41 protected String statement;
42 /** Cirteria object */
43 protected Criteria criteria;
44 /** identifies WHERE clause */
45 protected final static String WHERE = SqlInterface.WHERE;
46 /** identifies ( */
47 protected static final String OPEN_BRACE = "( ";
48 /** identifies ) */
49 protected static final String CLOSE_BRACE = ") ";
50
51
52 public SQLStatement(){
53 criteria = null;
54 statement = "";
55 }
56
57
58 public SQLStatement(RepositoryView repository,String[] propertiesNames,
59 Criteria criteria){
60 this.criteria = criteria;
61 if(criteria != null){
62 statement = buildStatementForCriteria(repository,propertiesNames);
63 }
64 else
65 statement = buildStatement(repository,propertiesNames);
66 }
67
68
69 public abstract String buildStatement(RepositoryView repository,String[] propertiesNames);
70
71 public abstract String buildStatementForCriteria(RepositoryView repository,String[] propertiesNames);
72
73
74 public String toString(){
75 StringBuffer buff = new StringBuffer();
76 buff.append(className).append("[ ")
77 .append("statement= ").append(statement)
78 .append("]");
79 return buff.toString();
80 }
81 }