KickJava   Java API By Example, From Geeks To Geeks.

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


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.Schema;
13 import org.h2.schema.Sequence;
14
15 public class DropSequence extends SchemaCommand {
16
17     private String JavaDoc sequenceName;
18     private boolean ifExists;
19     
20     public DropSequence(Session session, Schema schema) {
21         super(session, schema);
22     }
23
24     public void setIfExists(boolean b) {
25         ifExists = b;
26     }
27
28     public void setSequenceName(String JavaDoc sequenceName) {
29         this.sequenceName = sequenceName;
30     }
31
32     public int update() throws SQLException JavaDoc {
33         // TODO rights: what are the rights required for a sequence?
34
session.getUser().checkAdmin();
35         session.commit();
36         Database db = session.getDatabase();
37         Sequence sequence = getSchema().findSequence(sequenceName);
38         if(sequence == null) {
39             if(!ifExists) {
40                 throw Message.getSQLException(Message.SEQUENCE_NOT_FOUND_1, sequenceName);
41             }
42         } else {
43             if(sequence.getBelongsToTable()) {
44                 throw Message.getSQLException(Message.SEQUENCE_BELONGS_TO_A_TABLE_1, sequenceName);
45             }
46             db.removeSchemaObject(session, sequence);
47         }
48         return 0;
49     }
50
51 }
52
Popular Tags