kstaken 2002/07/20 15:44:36
Modified: java/src/org/apache/xindice/client/xmldb/embed
CollectionImpl.java
java/src/org/apache/xindice/client/xmldb/xmlrpc
CollectionImpl.java
Log:
Fixing the id usage to match the spec.
Revision Changes Path
1.2 +57 -54
xml-xindice/java/src/org/apache/xindice/client/xmldb/embed/CollectionImpl.java
Index: CollectionImpl.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/embed/CollectionImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CollectionImpl.java 12 Jul 2002 10:09:51 -0000 1.1
+++ CollectionImpl.java 20 Jul 2002 22:44:36 -0000 1.2
@@ -119,12 +119,12 @@
public Resource getResource(String resourceName) throws XMLDBException {
checkOpen();
- try {
-
+ try {
Document doc = col.getDocument(resourceName);
// This should probably just pass the document.
- return new XMLResourceImpl(resourceName, this, ((DocumentImpl)
doc).getSymbols(),
+ return new XMLResourceImpl(resourceName, resourceName, this,
+ ((DocumentImpl) doc).getSymbols(),
((DocumentImpl) doc).getDataBytes());
} catch (Exception e) {
return null;
@@ -156,42 +156,39 @@
* or if some other error condition arises.
*/
public void storeResource(Resource resource) throws XMLDBException {
-
- if (!(resource instanceof XMLResource)) {
- throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
- "Only XML resources supported");
- }
-
- if (resource.getContent() == null) {
- throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
- "no resource data");
- }
-
- checkOpen();
+
+ if (!(resource instanceof XMLResource)) {
+ throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
+ "Only XML resources supported");
+ }
+
+ if (resource.getContent() == null) {
+ throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
+ "no resource data");
+ }
- try {
- String name = "";
- Node content = ((XMLResourceImpl) resource).getContentAsDOM();
- if (content != null && content instanceof Document) {
- // TODO: make sure this is using the correct Id. May need to
be documentID.
- if (resource.getId() != null) {
- col.insertDocument(resource.getId(),
- (Document) content);
- }
- else {
- name = col.insertDocument((Document) content).toString();
- ((XMLResourceImpl) resource).setId(name);
- }
- }
- else {
- throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
- "A resource must be a document in
order to be stored.");
- }
-
+ checkOpen();
- } catch (Exception e) {
- throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR,
e.getMessage());
- }
+ try {
+ String name = "";
+ Node content = ((XMLResourceImpl) resource).getContentAsDOM();
+ if (content != null && content instanceof Document) {
+ if (resource.getId() != null) {
+ col.insertDocument(resource.getId(),
+ (Document) content);
+ }
+ else {
+ name = col.insertDocument((Document) content).toString();
+ ((XMLResourceImpl) resource).setId(name);
+ }
+ }
+ else {
+ throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
+ "A resource must be a document in
order to be stored.");
+ }
+ } catch (Exception e) {
+ throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, e.getMessage());
+ }
}
/**
@@ -256,6 +253,7 @@
*/
public void close() throws org.xmldb.api.base.XMLDBException {
col = null;
+ db.flushConfig();
}
/**
@@ -287,19 +285,24 @@
* in case of some other error
*/
public void removeResource(Resource resource) throws XMLDBException {
-
- if (!(resource instanceof XMLResource)) {
- throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
- "Only XML resources supported");
- }
-
- checkOpen();
- try {
- // TODO: Make sure this is the right ID.
- col.remove(resource.getId());
- } catch (Exception e) {
- throw new XMLDBException(ErrorCodes.NO_SUCH_RESOURCE,
e.getMessage());
- }
+
+ if (!(resource instanceof XMLResource)) {
+ throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
+ "Only XML resources supported");
+ }
+
+ if (resource.getId() == null) {
+ throw new XMLDBException(ErrorCodes.VENDOR_ERROR,
+ "This resource is a query result and can
" +
+ "not be removed from the database.");
+ }
+
+ checkOpen();
+ try {
+ col.remove(resource.getId());
+ } catch (Exception e) {
+ throw new XMLDBException(ErrorCodes.NO_SUCH_RESOURCE,
e.getMessage());
+ }
}
/**
@@ -393,8 +396,7 @@
String documentId = ((Element) n).getAttributeNS(QUERY_NS,
"key");
- // TODO: this is almost certainly using the wrong id.
- XMLResourceImpl resource = new XMLResourceImpl(documentId,
this,
+ XMLResourceImpl resource = new XMLResourceImpl(null,
documentId, this,
new TextWriter(n).toString());
rs.addResource(resource);
}
@@ -525,7 +527,8 @@
* @exception XMLDBException
*/
public void shutdown() throws XMLDBException {
- try {
+ try {
+ db.close();
}
catch (Exception e) {
throw FaultCodes.createXMLDBException(e);
1.8 +26 -20
xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java
Index: CollectionImpl.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- CollectionImpl.java 20 Jul 2002 20:26:32 -0000 1.7
+++ CollectionImpl.java 20 Jul 2002 22:44:36 -0000 1.8
@@ -185,7 +185,7 @@
if ( result instanceof Hashtable ) {
Hashtable compressed = (Hashtable) result;
SymbolDeserializer symbolDeserial = new SymbolDeserializer();
- return new XMLResourceImpl(resourceName, this,
+ return new XMLResourceImpl(resourceName, resourceName, this,
symbolDeserial.getSymbols(compressed),
(byte [])
compressed.get("document"));
}
@@ -359,23 +359,29 @@
* in case of some other error
*/
public void removeResource(Resource resource) throws XMLDBException {
-
- if (!(resource instanceof XMLResource)) {
-
- throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
- "Only XML resources supported");
- }
-
- checkOpen();
- try {
-
- Hashtable params = new Hashtable();
- params.put(RPCDefaultMessage.COLLECTION, collPath);
- params.put(RPCDefaultMessage.NAME, resource.getId());
- runRemoteCommand("RemoveDocument", params);
- } catch (Exception e) {
- throw new XMLDBException(ErrorCodes.NO_SUCH_RESOURCE,
e.getMessage());
- }
+
+ if (!(resource instanceof XMLResource)) {
+
+ throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
+ "Only XML resources supported");
+ }
+
+ if (resource.getId() == null) {
+ throw new XMLDBException(ErrorCodes.VENDOR_ERROR,
+ "This resource is a query result and can
" +
+ "not be removed from the database.");
+ }
+
+ checkOpen();
+ try {
+
+ Hashtable params = new Hashtable();
+ params.put(RPCDefaultMessage.COLLECTION, collPath);
+ params.put(RPCDefaultMessage.NAME, resource.getId());
+ runRemoteCommand("RemoveDocument", params);
+ } catch (Exception e) {
+ throw new XMLDBException(ErrorCodes.NO_SUCH_RESOURCE,
e.getMessage());
+ }
}
/**
@@ -486,7 +492,7 @@
String documentId = ((Element) n).getAttributeNS(
QUERY_NS, "key");
- XMLResourceImpl resource = new XMLResourceImpl(documentId,
+ XMLResourceImpl resource = new XMLResourceImpl(null,
documentId, this, TextWriter.toString(n));
rs.addResource(resource);
}