vgritsenko 2004/03/20 05:43:23
Modified: java/src/org/apache/xindice/core Collection.java
java/src/org/apache/xindice/core/meta MetaData.java
java/tests/src/org/apache/xindice/integration/client/resources
BinaryResourceTest.java
Log:
Support meta data for the binary resources. Go through exception messages one
more time.
Revision Changes Path
1.52 +28 -34
xml-xindice/java/src/org/apache/xindice/core/Collection.java
Index: Collection.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/Collection.java,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- Collection.java 15 Mar 2004 13:35:34 -0000 1.51
+++ Collection.java 20 Mar 2004 13:43:23 -0000 1.52
@@ -230,7 +230,7 @@
private void checkFiler(int faultCode) throws DBException {
if (filer == null) {
throw new DBException(faultCode,
- "This Collection '" + name + "' cannot
store Documents");
+ "Collection '" + name + "' cannot store
resources (no filer)");
}
}
@@ -336,7 +336,7 @@
public boolean drop() throws DBException {
if (this == getDatabase()) {
throw new DBException(FaultCodes.DBE_CANNOT_DROP,
- "You Cannot Drop The Database");
+ "You cannot drop the database");
}
DBObserver.getInstance().dropCollection(this);
@@ -389,7 +389,8 @@
checkFiler(FaultCodes.COL_NO_INDEXMANAGER);
if (index == null) {
- throw new DBException(FaultCodes.IDX_INDEX_NOT_FOUND, "Index
Value Null");
+ throw new DBException(FaultCodes.IDX_INDEX_NOT_FOUND,
+ "Index value is null");
}
boolean success = indexManager.drop(index.getName());
@@ -432,8 +433,8 @@
if (inlineMetaService == null) {
throw new DBException(FaultCodes.COL_DOCUMENT_NOT_FOUND,
- "There are no binary resources in
collection '"
- + getCanonicalName() + "': inline-metadata
is not enabled.");
+ "Collection '" + getCanonicalName() +
+ "' has no binary resources (inline
metadata is not enabled)");
}
Object entry = getEntry(key);
@@ -443,8 +444,8 @@
if (!(entry instanceof byte[])) {
throw new DBException(FaultCodes.COL_INVALID_RESULT,
- "The resource associated with key '" + key
+
- "' in collection '" + getCanonicalName() +
"'is not binary.");
+ "Resource '" + key + "' in collection '" +
+ getCanonicalName() + "' is not a binary
resource");
}
return (byte[]) entry;
@@ -564,8 +565,8 @@
if (!(entry instanceof Document)) {
throw new DBException(FaultCodes.COL_INVALID_RESULT,
- "The resource associated with key '" + key
+
- "' in collection '" + getCanonicalName() +
"' is not XML document");
+ "Resource '" + key + "' in collection '" +
+ getCanonicalName() + "' is not a
document");
}
return (Document) entry;
@@ -598,10 +599,9 @@
return null;
}
- if (null == getDocument(id)) {
+ if (null == getEntry(id)) {
throw new DBException(FaultCodes.COL_DOCUMENT_NOT_FOUND,
- "Document '" + id + "' does not exist " +
- "in collection '" + getCanonicalName() +
"'");
+ "Resource '" + id + "' does not exist in
'" + getCanonicalName() + "'");
}
MetaSystemCollection metacol = getMetaSystemCollection();
@@ -899,8 +899,8 @@
public Key insertBinary(Object docKey, byte[] bytes) throws DBException {
if (inlineMetaService == null) {
throw new DBException(FaultCodes.COL_CANNOT_STORE,
- "Cannot insert a binary resource in
collection " + name +
- ": inline-metadata is not enabled.");
+ "Cannot insert a binary resource in '" +
getCanonicalName() +
+ "' (inline-metadata is not enabled)");
}
Key key = createNewKey(docKey);
@@ -1050,29 +1050,24 @@
}
} catch (Exception e) {
throw new DBException(FaultCodes.COL_DOCUMENT_MALFORMED,
- "Unable to parse document " + key, e);
+ "Unable to parse document '" + key + "' in
'" + getCanonicalName() + "'", e);
}
return doc;
}
/*
- * Lowest-level method for saving a binary entry into the database.
+ * Lowest-level method for saving a binary entry into the database. At
this moment,
+ * presence of inline metadata is known.
* It now does update non-inline metadata if the user has configured it.
*/
private void putBinary(Key key, byte[] bytes, boolean create) throws
DBException {
- if (inlineMetaService == null) {
- throw new DBException(FaultCodes.COL_CANNOT_STORE,
- "Cannot store a binary resource in
collection " + getCanonicalName() +
- ": inline-metadata is not enabled");
- }
-
if (!create) {
byte[] storedBytes = getBinary(key);
if (storedBytes == null) {
// TODO: Do we need a COL_KEY_ALREADY_PRESENT fault so that
the caller can interpret this exception?
throw new DBException(FaultCodes.COL_CANNOT_STORE,
- "Error storing binary object with key
'" + key + "': the 'create' flag is false and" +
- " the key is not in the database");
+ "Error storing binary resource '" +
key + "' in '" + getCanonicalName() +
+ "': the 'create' flag is false and the
key is already in database");
}
}
@@ -1083,7 +1078,6 @@
// update the meta for this document
updateDocumentMeta(key.toString());
- // Not observable. DBObserver.getInstance().putDocument(this, key,
document, oldDoc == null);
}
/**
@@ -1274,7 +1268,7 @@
if (!filer.deleteRecord(objKey)) {
throw new DBException(FaultCodes.COL_DOCUMENT_NOT_FOUND,
- "Document Does Not Exist");
+ "Resource '" + objKey + "' does not exist
in '" + getCanonicalName() + "'");
}
// update the meta for this collection if necessary
@@ -1480,10 +1474,10 @@
return;
}
- Document doc = getDocument(id);
- if (null == doc) {
+ Object obj = getEntry(id);
+ if (null == obj) {
throw new DBException(FaultCodes.COL_DOCUMENT_NOT_FOUND,
- "Document " + id + " does not exist in
collection " + getCanonicalName());
+ "Resource '" + id + "' does not exist in
'" + getCanonicalName() + "'");
}
if (null != meta) {
@@ -1577,10 +1571,10 @@
return;
}
- Object doc = getEntry(id);
- if (null == doc) {
+ Object obj = getEntry(id);
+ if (null == obj) {
throw new DBException(FaultCodes.COL_DOCUMENT_NOT_FOUND,
- "Document " + id + " does not exist in " +
getCanonicalName());
+ "Resource '" + id + "' does not exist in
'" + getCanonicalName() + "'");
}
MetaSystemCollection metacol = getMetaSystemCollection();
1.15 +9 -9
xml-xindice/java/src/org/apache/xindice/core/meta/MetaData.java
Index: MetaData.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/meta/MetaData.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- MetaData.java 8 Feb 2004 02:50:37 -0000 1.14
+++ MetaData.java 20 Mar 2004 13:43:23 -0000 1.15
@@ -85,15 +85,15 @@
private static final Enumeration EMPTY =
(new Vector()).elements();
- private transient boolean dirty = false;
- private transient long created = 0;
- private transient long modified = 0;
- private transient String owner = null;
+ private transient boolean dirty;
+ private transient long created;
+ private transient long modified;
+ private transient String owner;
private short type = UNKNOWN;
- private String link = null;
- private Hashtable attrs = null;
- private Document custom = null;
+ private String link;
+ private Hashtable attrs;
+ private Document custom;
public MetaData() {
1.7 +32 -4
xml-xindice/java/tests/src/org/apache/xindice/integration/client/resources/BinaryResourceTest.java
Index: BinaryResourceTest.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/tests/src/org/apache/xindice/integration/client/resources/BinaryResourceTest.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- BinaryResourceTest.java 8 Feb 2004 03:57:02 -0000 1.6
+++ BinaryResourceTest.java 20 Mar 2004 13:43:23 -0000 1.7
@@ -21,6 +21,8 @@
import org.apache.xindice.integration.client.AbstractXmlDbClientTest;
import org.apache.xindice.integration.client.XmlDbClientSetup;
import org.apache.xindice.xml.dom.DOMParser;
+import org.apache.xindice.client.xmldb.services.MetaService;
+import org.apache.xindice.core.meta.MetaData;
import org.xmldb.api.base.Collection;
import org.xmldb.api.base.Resource;
@@ -41,7 +43,7 @@
name, DOMParser.toDocument(cfg));
}
- public void testRoundTrip() throws Exception {
+ public void testBinaryRoundTrip() throws Exception {
Collection collection =
client.getCollection(TEST_COLLECTION_PATH);
if (collection == null) {
throw new Exception("getCollection(" +
TEST_COLLECTION_PATH + ") returned null");
@@ -72,7 +74,7 @@
}
}
- public void testList() throws Exception {
+ public void testBinaryList() throws Exception {
Collection collection = client.getCollection(TEST_COLLECTION_PATH);
if (collection == null) {
throw new Exception("getCollection(" + TEST_COLLECTION_PATH + ")
returned null");
@@ -96,7 +98,7 @@
collection.removeResource(newResource);
}
- public void testRemove() throws Exception {
+ public void testBinaryRemove() throws Exception {
Collection collection =
client.getCollection(TEST_COLLECTION_PATH);
if (collection == null) {
throw new Exception("getCollection(" +
TEST_COLLECTION_PATH + ") returned null");
@@ -118,5 +120,31 @@
collection.removeResource(foundResource);
foundResource = collection.getResource(id);
assertNull("It should not be in there anymore", foundResource);
+ }
+
+ public void testBinaryMeta() throws Exception {
+ Collection collection =
client.getCollection(TEST_COLLECTION_PATH);
+ if (collection == null) {
+ throw new Exception("getCollection(" +
TEST_COLLECTION_PATH + ") returned null");
+ }
+
+ /*
+ * Create a binary resource, set / get meta data
+ */
+
+ Resource newResource = collection.createResource(null,
"BinaryResource");
+ newResource.setContent(new byte[] { 0x00, 0x10, 0x01, 0x11 });
+ collection.storeResource(newResource);
+ String id = newResource.getId();
+
+ MetaService service =
(MetaService)collection.getService("MetaService", "1.0");
+ MetaData meta = service.getMetaData(id);
+ assertNotNull("Meta should be in there", meta);
+
+ meta.setAttribute("test", "attribute");
+ service.setMetaData(id, meta);
+ meta = service.getMetaData(id);
+ assertNotNull("Meta should be in there", meta);
+ assertEquals("Attribute should not be in there", "attribute",
meta.getAttribute("test"));
}
}