KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > database > interpret > Compact


1 /**
2  * com.mckoi.database.interpret.Compact 14 Sep 2001
3  *
4  * Mckoi SQL Database ( http://www.mckoi.com/database )
5  * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * Version 2 as published by the Free Software Foundation.
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
14  * GNU General Public License Version 2 for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * Version 2 along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * Change Log:
21  *
22  *
23  */

24
25 package com.mckoi.database.interpret;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
29 import com.mckoi.database.*;
30
31 /**
32  * Statement that handles COMPACT sql command.
33  *
34  * @author Tobias Downer
35  */

36
37 public class Compact extends Statement {
38
39   /**
40    * The name the table that we are to update.
41    */

42   String JavaDoc table_name;
43
44   // ---------- Implemented from Statement ----------
45

46   public void prepare() throws DatabaseException {
47     table_name = (String JavaDoc) cmd.getObject("table_name");
48   }
49
50   public Table evaluate() throws DatabaseException {
51
52     DatabaseQueryContext context = new DatabaseQueryContext(database);
53
54 // TableName tname =
55
// TableName.resolve(database.getCurrentSchema(), table_name);
56
TableName tname = resolveTableName(table_name, database);
57     // Does the table exist?
58
if (!database.tableExists(tname)) {
59       throw new DatabaseException("Table '" + tname + "' does not exist.");
60     }
61
62     // Does the user have privs to compact this tables?
63
if (!database.getDatabase().canUserCompactTableObject(context,
64                                                           user, tname)) {
65       throw new UserAccessException(
66          "User not permitted to compact table: " + table_name);
67     }
68
69     // Compact the table,
70
database.compactTable(tname);
71
72     // Return '0' if success.
73
return FunctionTable.resultTable(context, 0);
74
75   }
76
77
78 }
79
Popular Tags