KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nilostep > xlsql > sql > xlSqlCreateTable


1 /*(Header: NiLOSTEP / xlSQL)
2
3     Copyright (C) 2004 NiLOSTEP Information Sciences, all
4     rights reserved.
5     
6     This program is licensed under the terms of the GNU
7     General Public License.You should have received a copy
8     of the GNU General Public License along with this
9     program;
10 */

11
12 package com.nilostep.xlsql.sql;
13
14 import com.nilostep.xlsql.database.xlDatabase;
15 import com.nilostep.xlsql.database.*;
16
17 import java.sql.*;
18
19 /**
20  * Adds a table to an xlDatabase.
21  *
22  * @author Jim Caprioli
23  */

24 public class xlSqlCreateTable implements xlSqlCommand {
25     //~ Instance variables ·····················································
26

27     protected com.nilostep.xlsql.database.xlDatabase db;
28     protected String JavaDoc _schema;
29     protected String JavaDoc _table;
30
31     /**
32      * Creates a new instance of type xlSqlCreateTable.
33      *
34      *
35      * @param database xlDatabase
36      * @param schema schema name
37      * @param table table name
38      */

39     public xlSqlCreateTable(com.nilostep.xlsql.database.xlDatabase database, String JavaDoc schema, String JavaDoc table) {
40         if (database == null) {
41             throw new NullPointerException JavaDoc("xlSQL: database null");
42         } else {
43             db = database;
44         }
45
46         if (schema == null) {
47             throw new NullPointerException JavaDoc("xlSQL: schema null");
48         } else {
49             _schema = schema;
50         }
51
52         if (table == null) {
53             throw new NullPointerException JavaDoc("xlSQL: table null");
54         } else {
55             _table = table;
56         }
57     }
58
59     /**
60      * Verifies if this command can be executed.
61      *
62      * @return true if allowed
63      *
64      * @throws SQLException
65      */

66     public boolean execAllowed() throws SQLException {
67         boolean ret = true;
68         if (db.tableExists(_schema, _table)) {
69                 ret = false;
70         }
71         return ret;
72     }
73
74     /**
75      * Executes the command.
76      *
77      * @throws SQLException if an unexpected error occurs.
78      */

79     public void execute() throws SQLException {
80         db.addSchema(_schema);
81         db.addTable(_schema, _table);
82     }
83 }
Popular Tags