01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (http://h2database.com/html/license.html).
04: * Initial Developer: H2 Group
05: */
06: package org.h2.command.ddl;
07:
08: import java.sql.SQLException;
09:
10: import org.h2.constant.ErrorCode;
11: import org.h2.engine.Database;
12: import org.h2.engine.Session;
13: import org.h2.message.Message;
14: import org.h2.schema.Schema;
15: import org.h2.schema.Sequence;
16:
17: /**
18: * This class represents the statement
19: * DROP SEQUENCE
20: */
21: public class DropSequence extends SchemaCommand {
22:
23: private String sequenceName;
24: private boolean ifExists;
25:
26: public DropSequence(Session session, Schema schema) {
27: super (session, schema);
28: }
29:
30: public void setIfExists(boolean b) {
31: ifExists = b;
32: }
33:
34: public void setSequenceName(String sequenceName) {
35: this .sequenceName = sequenceName;
36: }
37:
38: public int update() throws SQLException {
39: // TODO rights: what are the rights required for a sequence?
40: session.getUser().checkAdmin();
41: session.commit(true);
42: Database db = session.getDatabase();
43: Sequence sequence = getSchema().findSequence(sequenceName);
44: if (sequence == null) {
45: if (!ifExists) {
46: throw Message.getSQLException(
47: ErrorCode.SEQUENCE_NOT_FOUND_1, sequenceName);
48: }
49: } else {
50: if (sequence.getBelongsToTable()) {
51: throw Message.getSQLException(
52: ErrorCode.SEQUENCE_BELONGS_TO_A_TABLE_1,
53: sequenceName);
54: }
55: db.removeSchemaObject(session, sequence);
56: }
57: return 0;
58: }
59:
60: }
|