KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * com.mckoi.database.interpret.Misc 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 com.mckoi.database.*;
28 import java.util.ArrayList JavaDoc;
29 import java.util.List JavaDoc;
30
31 /**
32  * Misc statements that I couldn't be bothered to roll a new Statement class
33  * for. These have to be exceptional statements that do not read or write
34  * to any tables and run in exclusive mode.
35  *
36  * @author Tobias Downer
37  */

38
39 public class Misc extends Statement {
40
41   /**
42    * Set to true if this statement is a shutdown statement.
43    */

44   boolean shutdown = false;
45
46
47
48   // ---------- Implemented from Statement ----------
49

50   public void prepare() throws DatabaseException {
51     Object JavaDoc command = cmd.getObject("command");
52     shutdown = command.equals("shutdown");
53   }
54
55   public Table evaluate() throws DatabaseException {
56
57     DatabaseQueryContext context = new DatabaseQueryContext(database);
58
59     // Is this a shutdown statement?
60
if (shutdown == true) {
61
62       // Check the user has privs to shutdown...
63
if (!database.getDatabase().canUserShutDown(context, user)) {
64         throw new UserAccessException(
65                  "User not permitted to shut down the database.");
66       }
67
68       // Shut down the database system.
69
database.getDatabase().startShutDownThread();
70
71       // Return 0 to indicate we going to be closing shop!
72
return FunctionTable.resultTable(context, 0);
73
74     }
75
76     return FunctionTable.resultTable(context, 0);
77   }
78
79
80 }
81
Popular Tags