KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > command > ddl > DropConstant


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.command.ddl;
6
7 import java.sql.SQLException JavaDoc;
8
9 import org.h2.engine.Database;
10 import org.h2.engine.Session;
11 import org.h2.message.Message;
12 import org.h2.schema.Constant;
13 import org.h2.schema.Schema;
14
15 public class DropConstant extends SchemaCommand {
16
17     private String JavaDoc constantName;
18     private boolean ifExists;
19     
20     public DropConstant(Session session, Schema schema) {
21         super(session, schema);
22     }
23
24     public void setIfExists(boolean b) {
25         ifExists = b;
26     }
27
28     public void setConstantName(String JavaDoc constantName) {
29         this.constantName = constantName;
30     }
31
32     public int update() throws SQLException JavaDoc {
33         session.getUser().checkAdmin();
34         session.commit();
35         Database db = session.getDatabase();
36         Constant constant = getSchema().findConstant(constantName);
37         if(constant == null) {
38             if(!ifExists) {
39                 throw Message.getSQLException(Message.CONSTANT_NOT_FOUND_1, constantName);
40             }
41         } else {
42             db.removeSchemaObject(session, constant);
43         }
44         return 0;
45     }
46
47 }
48
Popular Tags