1 5 package org.h2.command.ddl; 6 7 import java.sql.SQLException ; 8 9 import org.h2.engine.Constants; 10 import org.h2.engine.Database; 11 import org.h2.engine.Role; 12 import org.h2.engine.Session; 13 import org.h2.message.Message; 14 15 public class DropRole extends DefineCommand { 16 17 private String roleName; 18 private boolean ifExists; 19 20 public DropRole(Session session) { 21 super(session); 22 } 23 24 public void setRoleName(String roleName) { 25 this.roleName = roleName; 26 } 27 28 public int update() throws SQLException { 29 session.getUser().checkAdmin(); 30 session.commit(); 31 Database db = session.getDatabase(); 32 if(roleName.equals(Constants.PUBLIC_ROLE_NAME)) { 33 throw Message.getSQLException(Message.ROLE_CAN_NOT_BE_DROPPED_1, roleName); 34 } 35 Role role = db.findRole(roleName); 36 if(role == null) { 37 if(!ifExists) { 38 throw Message.getSQLException(Message.ROLE_NOT_FOUND_1, roleName); 39 } 40 } else { 41 db.removeDatabaseObject(session, role); 42 } 43 return 0; 44 } 45 46 public void setIfExists(boolean ifExists) { 47 this.ifExists = ifExists; 48 } 49 50 } 51 | Popular Tags |