Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: javatools/db/DbExprFuncDef.java


1   /*
2       Javatools (modified version) - Some useful general classes.
3       Copyright (C) 2002-2003  Chris Bitmead (original) Antonio Petrelli (modified)
4   
5       This program is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published by
7       the Free Software Foundation; either version 2 of the License, or
8       (at your option) any later version.
9   
10      This program is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13      GNU General Public License for more details.
14  
15      You should have received a copy of the GNU General Public License
16      along with this program; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  
19      Contact me at: brenmcguire@users.sourceforge.net
20   */
21  package javatools.db;
22  import java.sql.*;
23  import java.util.*;
24  
25  /**
26   * An SQL expression of the form FUNCNAME(parameter....).
27   *
28   * @author Chris Bitmead
29   * @created October 18, 2001
30   * @version 0.7
31   * @commentedby Antonio Petrelli
32   */
33  public class DbExprFuncDef extends DbExpr {
34      /** The function name.
35       */    
36    String func;
37          /** The arguments for the function.
38           */        
39    Object args[];
40  
41  
42    /**
43           * Constructor for the DbExprFuncDef object
44           *
45           * @param db The database that will be used.
46           * @param func The function which will be used.
47           */
48    public DbExprFuncDef(DbDatabase db, String func) {
49      super(db);
50      this.func = func;
51    }
52  
53  
54    /**
55           * Constructor for the DbExprFuncDef object
56           *
57           * @param db The database that will be used.
58           * @param func The function that will be used.
59           * @param arg1 The first argument.
60           */
61    public DbExprFuncDef(DbDatabase db, String func, Object arg1) {
62      super(db);
63      this.func = func;
64      args = new Object[1];
65      args[0] = arg1;
66    }
67  
68  
69    /**
70           * Constructor for the DbExprFuncDef object
71           *
72           * @param db The database that will be used.
73           * @param func The function that will be used.
74           * @param arg1 The first argument.
75           * @param arg2 The second argument.
76           */
77    public DbExprFuncDef(DbDatabase db, String func, Object arg1, Object arg2) {
78      super(db);
79      this.func = func;
80      args = new Object[2];
81      args[0] = arg1;
82      args[1] = arg2;
83    }
84  
85  
86    /**
87           * Sets the sqlValues attribute of the DbExprFuncDef object
88           *
89           * @param ps The PreparedStatement.
90           * @param i                 The new sqlValues value
91           * @return Obscure...
92           * @exception DbException If something goes wrong.
93           * @exception SQLException If something goes wrong.
94           */
95    public int setSqlValues(PreparedStatement ps, int i) throws DbException, SQLException {
96      for (int c = 0; c < args.length; c++) {
97        i = setSqlValue(ps, i, args[c], null);
98      }
99      return i;
100   }
101 
102 
103   /**
104          * Gets the queryString attribute of the DbExprFuncDef object
105          *
106          * @return The queryString value
107          * @exception DbException If something goes wrong.
108          */
109   public String getQueryString() throws DbException {
110     String rtn = func + "(";
111     for (int c = 0; c < args.length; c++) {
112       if (c != 0) {
113         rtn += ", ";
114       }
115       rtn += getString(args[c]);
116     }
117     rtn += ")";
118     return rtn;
119   }
120 
121 
122   /**
123    *  Description of the Method
124    *
125    *@param  coll  Description of Parameter
126    */
127   public void usesTables(Set coll) {
128     for (int c = 0; c < args.length; c++) {
129       usesTables(coll, args[c]);
130     }
131   }
132 }