KickJava   Java API By Example, From Geeks To Geeks.

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


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.Sequence;
13
14 public class AlterSequence extends DefineCommand {
15
16     private Sequence sequence;
17     private boolean newStart;
18     private long start;
19     private boolean newIncrement;
20     private long increment;
21
22     public AlterSequence(Session session) {
23         super(session);
24     }
25
26     public void setSequence(Sequence sequence) {
27         this.sequence = sequence;
28     }
29     
30     public void setStartWith(long start) {
31         newStart = true;
32         this.start = start;
33     }
34
35     public void setIncrement(long increment) throws SQLException JavaDoc {
36         newIncrement = true;
37         if(increment == 0) {
38             throw Message.getSQLException(Message.INVALID_VALUE_2, new String JavaDoc[]{"0", "INCREMENT"}, null);
39         }
40         this.increment = increment;
41     }
42
43     public int update() throws SQLException JavaDoc {
44         // TODO rights: what are the rights required for a sequence?
45
session.commit();
46         Database db = session.getDatabase();
47         if(newStart) {
48             sequence.setStartValue(start);
49         }
50         if(newIncrement) {
51             sequence.setIncrement(increment);
52         }
53         db.update(session, sequence);
54         return 0;
55     }
56
57 }
58
Popular Tags