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.table.TableLink; 14 15 16 19 20 public class CreateLinkedTable extends SchemaCommand { 21 22 private String tableName; 23 private String driver, url, user, password, originalTable; 24 private boolean ifNotExists; 25 private String comment; 26 27 public CreateLinkedTable(Session session, Schema schema) { 28 super(session, schema); 29 } 30 31 public void setTableName(String tableName) { 32 this.tableName = tableName; 33 } 34 35 public void setDriver(String driver) { 36 this.driver = driver; 37 } 38 39 public void setOriginalTable(String originalTable) { 40 this.originalTable = originalTable; 41 } 42 43 public void setPassword(String password) { 44 this.password = password; 45 } 46 47 public void setUrl(String url) { 48 this.url = url; 49 } 50 51 public void setUser(String user) { 52 this.user = user; 53 } 54 55 public void setIfNotExists(boolean ifNotExists) { 56 this.ifNotExists = ifNotExists; 57 } 58 59 public int update() throws SQLException { 60 session.commit(); 61 Database db = session.getDatabase(); 62 session.getUser().checkAdmin(); 63 if(getSchema().findTableOrView(session, tableName)!=null) { 64 if (ifNotExists) { 65 return 0; 66 } 67 throw Message.getSQLException(Message.TABLE_OR_VIEW_ALREADY_EXISTS_1, 68 tableName); 69 } 70 int id = getObjectId(false, true); 71 TableLink table = new TableLink(getSchema(), id, tableName, driver, url, user, password, originalTable); 72 table.setComment(comment); 73 db.addSchemaObject(session, table); 74 return 0; 75 } 76 77 public void setComment(String comment) { 78 this.comment = comment; 79 } 80 81 } 82 | Popular Tags |