1 5 package org.h2.command.ddl; 6 7 import java.sql.SQLException ; 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 { 36 newIncrement = true; 37 if(increment == 0) { 38 throw Message.getSQLException(Message.INVALID_VALUE_2, new String []{"0", "INCREMENT"}, null); 39 } 40 this.increment = increment; 41 } 42 43 public int update() throws SQLException { 44 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 |