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.Schema; 13 import org.h2.schema.Sequence; 14 15 public class DropSequence extends SchemaCommand { 16 17 private String 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 sequenceName) { 29 this.sequenceName = sequenceName; 30 } 31 32 public int update() throws SQLException { 33 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 |