File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\command\ddl\DropSequence.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.command.ddl;
8
9 import org.h2.command.CommandInterface;
10 import org.h2.constant.ErrorCode;
11 import org.h2.engine.Database;
12 import org.h2.engine.Session;
13 import org.h2.message.DbException;
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() {
39 session.getUser().checkAdmin();
40 session.commit(true);
41 Database db = session.getDatabase();
42 Sequence sequence = getSchema().findSequence(sequenceName);
43 if (sequence == null) {
44 if (!ifExists) {
45 throw DbException.get(ErrorCode.SEQUENCE_NOT_FOUND_1, sequenceName);
46 }
47 } else {
48 if (sequence.getBelongsToTable()) {
49 throw DbException.get(ErrorCode.SEQUENCE_BELONGS_TO_A_TABLE_1, sequenceName);
50 }
51 db.removeSchemaObject(session, sequence);
52 }
53 return 0;
54 }
55
56 public int getType() {
57 return CommandInterface.DROP_SEQUENCE;
58 }
59
60 }
61