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.engine.User; 12 import org.h2.message.Message; 13 14 public class DropUser extends DefineCommand { 15 16 private boolean ifExists; 17 private String userName; 18 19 public DropUser(Session session) { 20 super(session); 21 } 22 23 public void setIfExists(boolean b) { 24 ifExists = b; 25 } 26 27 public void setUserName(String userName) { 28 this.userName = userName; 29 } 30 31 public int update() throws SQLException { 32 session.getUser().checkAdmin(); 33 session.commit(); 34 Database db = session.getDatabase(); 35 User user = db.findUser(userName); 36 if(user == null) { 37 if(!ifExists) { 38 throw Message.getSQLException(Message.USER_NOT_FOUND_1, userName); 39 } 40 } else { 41 if(user == session.getUser()) { 42 throw Message.getSQLException(Message.CANT_DROP_CURRENT_USER); 43 } 44 db.removeDatabaseObject(session, user); 45 } 46 return 0; 47 } 48 49 public boolean isTransactional() { 50 return false; 51 } 52 53 } 54 | Popular Tags |