|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| package org.apache.xindice.tools.command; |
|
21 |
| |
|
22 |
| import org.apache.xindice.client.xmldb.services.DatabaseInstanceManager; |
|
23 |
| import org.apache.xindice.tools.XMLTools; |
|
24 |
| |
|
25 |
| import org.xmldb.api.DatabaseManager; |
|
26 |
| import org.xmldb.api.base.Collection; |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| public class Shutdown extends Command { |
|
35 |
| |
|
36 |
| |
|
37 |
0
| public boolean execute(XMLTools.Config table) throws Exception {
|
|
38 |
| |
|
39 |
0
| if (table.getString(XMLTools.COLLECTION) == null) {
|
|
40 |
0
| System.out.println("ERROR : Collection context required ");
|
|
41 |
0
| return false;
|
|
42 |
| } |
|
43 |
| |
|
44 |
0
| Collection col = null;
|
|
45 |
0
| try {
|
|
46 |
| |
|
47 |
0
| String context = table.getString(XMLTools.COLLECTION);
|
|
48 |
0
| String db = getDbName(context);
|
|
49 |
| |
|
50 |
| |
|
51 |
0
| String colstring = normalizeCollectionURI(db, table.getBoolean(XMLTools.LOCAL));
|
|
52 |
0
| col = DatabaseManager.getCollection(colstring);
|
|
53 |
| |
|
54 |
0
| if (col != null) {
|
|
55 |
0
| DatabaseInstanceManager man =
|
|
56 |
| (DatabaseInstanceManager) col.getService("DatabaseInstanceManager", XMLDBAPIVERSION); |
|
57 |
| |
|
58 |
| |
|
59 |
0
| man.shutdown();
|
|
60 |
| } |
|
61 |
| } finally { |
|
62 |
0
| if (col != null) {
|
|
63 |
0
| col.close();
|
|
64 |
| } |
|
65 |
| } |
|
66 |
| |
|
67 |
0
| return true;
|
|
68 |
| } |
|
69 |
| |
|
70 |
0
| private String getDbName(String context) {
|
|
71 |
0
| int i = context.indexOf("://");
|
|
72 |
0
| i = i < 0 ? 0 : i + 3;
|
|
73 |
| |
|
74 |
0
| int start = context.indexOf('/', i);
|
|
75 |
0
| int end = context.indexOf('/', start + 1);
|
|
76 |
0
| if (end == -1) {
|
|
77 |
0
| end = context.length();
|
|
78 |
| } |
|
79 |
| |
|
80 |
0
| return context.substring(0, end);
|
|
81 |
| } |
|
82 |
| |
|
83 |
0
| public void usage() {
|
|
84 |
0
| System.out.println("Format: xindice shutdown -c <context> [-l [-d <path>]] [-v]");
|
|
85 |
0
| System.out.println();
|
|
86 |
0
| System.out.println("Shuts down the database. Shutdown command only works with embedded driver");
|
|
87 |
0
| System.out.println();
|
|
88 |
| } |
|
89 |
| } |