| 26 | } |
| 27 | |
| 28 | @Override |
| 29 | protected boolean run() { |
| 30 | // close existing database |
| 31 | Close.close(context); |
| 32 | |
| 33 | // input (can be path or XML string) |
| 34 | final String input = args[0].trim(); |
| 35 | if(input.isEmpty()) return true; |
| 36 | |
| 37 | // get path and database name, overwrite database name with generated name |
| 38 | final IO io = IO.get(input); |
| 39 | final String dbName = io.dbName(); |
| 40 | |
| 41 | // choose OPEN if user has no create permissions, or if database exists |
| 42 | final Command cmd = open(io, dbName) ? new Open(dbName) : |
| 43 | new CreateDB(dbName, io.exists() ? input : null); |
| 44 | |
| 45 | // execute command |
| 46 | try { |
| 47 | final boolean ok = pushJob(cmd).run(context); |
| 48 | final String msg = cmd.info().trim(); |
| 49 | return ok ? info(msg) : error(msg); |
| 50 | } finally { |
| 51 | popJob(); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Checks if the addressed database can be opened, or needs to be (re)built. |