1
|
package eu.dnetlib.xml.database;
|
2
|
|
3
|
import java.util.Iterator;
|
4
|
import java.util.List;
|
5
|
|
6
|
import org.exist.util.DatabaseConfigurationException;
|
7
|
import org.xmldb.api.base.XMLDBException;
|
8
|
|
9
|
/**
|
10
|
* xmldb API is ugly.
|
11
|
*
|
12
|
* This is a thin wrapper to the xmldb API with focus on the primary operations used by dnet
|
13
|
*
|
14
|
* @author marko
|
15
|
*
|
16
|
*/
|
17
|
public interface XMLDatabase { // NOPMD
|
18
|
|
19
|
/**
|
20
|
* creates a new resource or updates the resource if it already exists.
|
21
|
*
|
22
|
* @param name
|
23
|
* file name
|
24
|
* @param collection
|
25
|
* collection name
|
26
|
* @param content
|
27
|
* serialized xml string
|
28
|
* @throws XMLDBException
|
29
|
* happens
|
30
|
*/
|
31
|
void create(String name, String collection, String content) throws XMLDBException;
|
32
|
|
33
|
/**
|
34
|
* updates and already existing resource.
|
35
|
*
|
36
|
* @param name
|
37
|
* file name
|
38
|
* @param collection
|
39
|
* collection name
|
40
|
* @param content
|
41
|
* serialized xml string
|
42
|
* @throws XMLDBException
|
43
|
* fails if the resource doesn't exist
|
44
|
*/
|
45
|
void update(String name, String collection, String content) throws XMLDBException;
|
46
|
|
47
|
/**
|
48
|
* removes a resource.
|
49
|
*
|
50
|
* @param name
|
51
|
* file name
|
52
|
* @param collection
|
53
|
* collection name
|
54
|
* @return false if the resource doesn't exist
|
55
|
* @throws XMLDBException
|
56
|
* could happen
|
57
|
*/
|
58
|
boolean remove(String name, String collection) throws XMLDBException;
|
59
|
|
60
|
/**
|
61
|
* read a resource string xml.
|
62
|
*
|
63
|
* @param name
|
64
|
* file name
|
65
|
* @param collection
|
66
|
* collection name
|
67
|
* @return null if the resource doesn't exist, otherwise it returns the xml string serialization
|
68
|
* @throws XMLDBException
|
69
|
* happens
|
70
|
*/
|
71
|
String read(String name, String collection) throws XMLDBException;
|
72
|
|
73
|
/**
|
74
|
* Execute an xquery.
|
75
|
*
|
76
|
* @param xquery
|
77
|
* xquery source
|
78
|
* @return a xmldb resultset object
|
79
|
* @throws XMLDBException
|
80
|
* happens
|
81
|
*/
|
82
|
Iterator<String> xquery(String xquery) throws XMLDBException;
|
83
|
|
84
|
/**
|
85
|
* creates a new collection, non recursively.
|
86
|
*
|
87
|
* @param collection
|
88
|
* collection name
|
89
|
* @throws XMLDBException
|
90
|
* happens
|
91
|
*/
|
92
|
void createCollection(String collection) throws XMLDBException;
|
93
|
|
94
|
/**
|
95
|
* remove a collection.
|
96
|
*
|
97
|
* @param collection
|
98
|
* collection name
|
99
|
* @throws XMLDBException
|
100
|
* happens also when the collection doesn't eXist
|
101
|
*/
|
102
|
void removeCollection(String collection) throws XMLDBException;
|
103
|
|
104
|
void xupdate(String query) throws XMLDBException;
|
105
|
|
106
|
/**
|
107
|
* check whether a collection exists.
|
108
|
*
|
109
|
* @param collection
|
110
|
* collection name
|
111
|
* @return true if the collection exists
|
112
|
* @throws XMLDBException
|
113
|
* happens
|
114
|
*/
|
115
|
boolean collectionExists(String collection) throws XMLDBException;
|
116
|
|
117
|
/**
|
118
|
* lists child collections.
|
119
|
*
|
120
|
* @param collection
|
121
|
* parent collections
|
122
|
* @return list of collection names
|
123
|
* @throws XMLDBException
|
124
|
* happens
|
125
|
*/
|
126
|
List<String> listChildCollections(String collection) throws XMLDBException;
|
127
|
|
128
|
/**
|
129
|
* list the content of a collection.
|
130
|
*
|
131
|
* @param collection
|
132
|
* parent collection
|
133
|
* @return list of resource names
|
134
|
* @throws XMLDBException
|
135
|
* happens
|
136
|
*/
|
137
|
List<String> list(String collection) throws XMLDBException;
|
138
|
|
139
|
/**
|
140
|
* returns the name of the root collection.
|
141
|
*
|
142
|
* @return collection name
|
143
|
*/
|
144
|
String getRootCollection();
|
145
|
|
146
|
/**
|
147
|
* make a backup of entire database.
|
148
|
*
|
149
|
* @throws XMLDBException
|
150
|
* could happen
|
151
|
* @throws DatabaseConfigurationException
|
152
|
* could happen
|
153
|
* @return the path in which the Backup has been saved
|
154
|
*/
|
155
|
String backup() throws XMLDBException, DatabaseConfigurationException;
|
156
|
|
157
|
/**
|
158
|
* Return the dir that contains all backups.
|
159
|
*
|
160
|
* @return the path in which the Backup has been saved
|
161
|
*/
|
162
|
String getBackupDir();
|
163
|
|
164
|
}
|