You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by Terry Rosenbaum <Te...@amicas.com> on 2002/09/09 17:48:39 UTC

Collection.createResource(null, "XMLResource") does not assign ID (patch included)

Xincide (latest embedded version from CVS) does not
fulfill the contract of Collection.createResource(String id, String 
type) which states:

"If id is null or its value is empty then an id is generated by calling 
createId()."

In XindiceCollection.createResource(String name, String type), we have:

    public Resource createResource(String name, String type) throws 
XMLDBException {
        if (name == null) {

            name = "";
        }
...

The ID is left empty, createId() is not called,
and, nowhere later is an ID created for an empty ID.
The "auto-id" feature of xindice 1.0 is gone.

As a result, all XMLResources stored to a Collection
via storeResource with a null ID go into the Collection
under the same (empty) key and thus overwrite
the previous contents of the resource with the empty ID.
e.g. if you store 10 documents into the collection supplying
a null ID each time to storeResource, only the 10th document
appears to be in the collection afterward.

Automatic id creation used to be done in CollectionImpl.storeResource by:

         String id = resource.getId();
         if ( ( id == null ) || ( id.length() == 0 ) ) {
            id = createId();
         }

but that apparently went away with the switch to the "embedded" 
CollectionImpl.

So, Xindice embedded version does not create resource IDs automatically
whereas version 1.0 did.

Here is a proposed patch to fix that issue. Could someone with commit 
power please
review this and, if acceptable, check it in? (Code search showed that 
createResource(String id, String type)
is called in only one place in all of Xindice code, and that place 
(don't recall where now) supplies
an id string, so there should be no side effects on Xindice from this 
change).

---------------------------------------------------- 
8< ----------------------------------------------------
diff -aur 
xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java 
patched-xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java
--- 
xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java    
Fri Jul 12 06:09:51 2002
+++ 
patched-xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java    
Sun Sep  8 14:49:30 2002
@@ -248,9 +248,10 @@
      * @exception XMLDBException thrown in case of an invalid resource 
type or name
      */
     public Resource createResource(String name, String type) throws 
XMLDBException {
-        if (name == null) {
-
-            name = "";
+        if (name == null || name.length() == 0) {
+            // fulfill contract stating
+            // "If id is null or its value is empty then an id is 
generated by calling createId()."
+            name = createId();
         }
        
         if (name.indexOf('/') != -1) {
---------------------------------------------------- 
8< ----------------------------------------------------

Thanks.

-Terry


RE: Collection.createResource(null, "XMLResource") does not assign ID (patch included)

Posted by Matt Liotta <ml...@r337.com>.
If you want an auto-generated ID I think you are supposed to use
Collection.createResource(String type).

Matt Liotta
President & CEO
Montara Software, Inc.
http://www.montarasoftware.com/
888-408-0900 x901

> -----Original Message-----
> From: Terry Rosenbaum [mailto:Terry@amicas.com]
> Sent: Monday, September 09, 2002 8:49 AM
> To: xindice-dev
> Subject: Collection.createResource(null, "XMLResource") does not
assign ID
> (patch included)
> 
> Xincide (latest embedded version from CVS) does not
> fulfill the contract of Collection.createResource(String id, String
> type) which states:
> 
> "If id is null or its value is empty then an id is generated by
calling
> createId()."
> 
> In XindiceCollection.createResource(String name, String type), we
have:
> 
>     public Resource createResource(String name, String type) throws
> XMLDBException {
>         if (name == null) {
> 
>             name = "";
>         }
> ...
> 
> The ID is left empty, createId() is not called,
> and, nowhere later is an ID created for an empty ID.
> The "auto-id" feature of xindice 1.0 is gone.
> 
> As a result, all XMLResources stored to a Collection
> via storeResource with a null ID go into the Collection
> under the same (empty) key and thus overwrite
> the previous contents of the resource with the empty ID.
> e.g. if you store 10 documents into the collection supplying
> a null ID each time to storeResource, only the 10th document
> appears to be in the collection afterward.
> 
> Automatic id creation used to be done in CollectionImpl.storeResource
by:
> 
>          String id = resource.getId();
>          if ( ( id == null ) || ( id.length() == 0 ) ) {
>             id = createId();
>          }
> 
> but that apparently went away with the switch to the "embedded"
> CollectionImpl.
> 
> So, Xindice embedded version does not create resource IDs
automatically
> whereas version 1.0 did.
> 
> Here is a proposed patch to fix that issue. Could someone with commit
> power please
> review this and, if acceptable, check it in? (Code search showed that
> createResource(String id, String type)
> is called in only one place in all of Xindice code, and that place
> (don't recall where now) supplies
> an id string, so there should be no side effects on Xindice from this
> change).
> 
> ----------------------------------------------------
> 8< ----------------------------------------------------
> diff -aur
> xml-
>
xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java
> patched-xml-
>
xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java
> ---
> xml-
>
xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java
> Fri Jul 12 06:09:51 2002
> +++
> patched-xml-
>
xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java
> Sun Sep  8 14:49:30 2002
> @@ -248,9 +248,10 @@
>       * @exception XMLDBException thrown in case of an invalid
resource
> type or name
>       */
>      public Resource createResource(String name, String type) throws
> XMLDBException {
> -        if (name == null) {
> -
> -            name = "";
> +        if (name == null || name.length() == 0) {
> +            // fulfill contract stating
> +            // "If id is null or its value is empty then an id is
> generated by calling createId()."
> +            name = createId();
>          }
> 
>          if (name.indexOf('/') != -1) {
> ----------------------------------------------------
> 8< ----------------------------------------------------
> 
> Thanks.
> 
> -Terry


Re: Collection.createResource(null, "XMLResource") does not assign ID (patch included)

Posted by Terry Rosenbaum <Te...@amicas.com>.
Thanks Fernando!

BTW, there is no createResource(String type) (suggested by Matt Liotta) 
available in the
Collection interface of xmldb. And, the Collection contract was 
previously fulfilled (at least
wrt what happened when you stored the resource) under
Xindice 1.0, so this was a regression.

-Terry

Fernando Padilla wrote:

>I agree.  The documentation I'm looking at is: 
>http://xmldb.org/xapi/api/org/xmldb/api/base/Collection.html
>
>I wonder if that is the latest version, but either way, I believe this 
>should be the correct behavior.  The change has been checked in.
>
>Terry, I made a few more modifications on that function, so expect a 
>conflict.  You might want to remove the java file, then cvs up again.
>
>
>
>On Mon, 9 Sep 2002, Terry Rosenbaum wrote:
>
>  
>
>>Xincide (latest embedded version from CVS) does not
>>fulfill the contract of Collection.createResource(String id, String 
>>type) which states:
>>
>>"If id is null or its value is empty then an id is generated by calling 
>>createId()."
>>
>>In XindiceCollection.createResource(String name, String type), we have:
>>
>>    public Resource createResource(String name, String type) throws 
>>XMLDBException {
>>        if (name == null) {
>>
>>            name = "";
>>        }
>>...
>>
>>The ID is left empty, createId() is not called,
>>and, nowhere later is an ID created for an empty ID.
>>The "auto-id" feature of xindice 1.0 is gone.
>>
>>As a result, all XMLResources stored to a Collection
>>via storeResource with a null ID go into the Collection
>>under the same (empty) key and thus overwrite
>>the previous contents of the resource with the empty ID.
>>e.g. if you store 10 documents into the collection supplying
>>a null ID each time to storeResource, only the 10th document
>>appears to be in the collection afterward.
>>
>>Automatic id creation used to be done in CollectionImpl.storeResource by:
>>
>>         String id = resource.getId();
>>         if ( ( id == null ) || ( id.length() == 0 ) ) {
>>            id = createId();
>>         }
>>
>>but that apparently went away with the switch to the "embedded" 
>>CollectionImpl.
>>
>>So, Xindice embedded version does not create resource IDs automatically
>>whereas version 1.0 did.
>>
>>Here is a proposed patch to fix that issue. Could someone with commit 
>>power please
>>review this and, if acceptable, check it in? (Code search showed that 
>>createResource(String id, String type)
>>is called in only one place in all of Xindice code, and that place 
>>(don't recall where now) supplies
>>an id string, so there should be no side effects on Xindice from this 
>>change).
>>
>>---------------------------------------------------- 
>>8< ----------------------------------------------------
>>diff -aur 
>>xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java 
>>patched-xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java
>>--- 
>>xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java    
>>Fri Jul 12 06:09:51 2002
>>+++ 
>>patched-xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java    
>>Sun Sep  8 14:49:30 2002
>>@@ -248,9 +248,10 @@
>>      * @exception XMLDBException thrown in case of an invalid resource 
>>type or name
>>      */
>>     public Resource createResource(String name, String type) throws 
>>XMLDBException {
>>-        if (name == null) {
>>-
>>-            name = "";
>>+        if (name == null || name.length() == 0) {
>>+            // fulfill contract stating
>>+            // "If id is null or its value is empty then an id is 
>>generated by calling createId()."
>>+            name = createId();
>>         }
>>        
>>         if (name.indexOf('/') != -1) {
>>---------------------------------------------------- 
>>8< ----------------------------------------------------
>>
>>Thanks.
>>
>>-Terry
>>
>>
>>    
>>
>
>
>  
>



Re: Collection.createResource(null, "XMLResource") does not assign ID (patch included)

Posted by Fernando Padilla <fe...@interdimensions.com>.
I agree.  The documentation I'm looking at is: 
http://xmldb.org/xapi/api/org/xmldb/api/base/Collection.html

I wonder if that is the latest version, but either way, I believe this 
should be the correct behavior.  The change has been checked in.

Terry, I made a few more modifications on that function, so expect a 
conflict.  You might want to remove the java file, then cvs up again.



On Mon, 9 Sep 2002, Terry Rosenbaum wrote:

> Xincide (latest embedded version from CVS) does not
> fulfill the contract of Collection.createResource(String id, String 
> type) which states:
> 
> "If id is null or its value is empty then an id is generated by calling 
> createId()."
> 
> In XindiceCollection.createResource(String name, String type), we have:
> 
>     public Resource createResource(String name, String type) throws 
> XMLDBException {
>         if (name == null) {
> 
>             name = "";
>         }
> ...
> 
> The ID is left empty, createId() is not called,
> and, nowhere later is an ID created for an empty ID.
> The "auto-id" feature of xindice 1.0 is gone.
> 
> As a result, all XMLResources stored to a Collection
> via storeResource with a null ID go into the Collection
> under the same (empty) key and thus overwrite
> the previous contents of the resource with the empty ID.
> e.g. if you store 10 documents into the collection supplying
> a null ID each time to storeResource, only the 10th document
> appears to be in the collection afterward.
> 
> Automatic id creation used to be done in CollectionImpl.storeResource by:
> 
>          String id = resource.getId();
>          if ( ( id == null ) || ( id.length() == 0 ) ) {
>             id = createId();
>          }
> 
> but that apparently went away with the switch to the "embedded" 
> CollectionImpl.
> 
> So, Xindice embedded version does not create resource IDs automatically
> whereas version 1.0 did.
> 
> Here is a proposed patch to fix that issue. Could someone with commit 
> power please
> review this and, if acceptable, check it in? (Code search showed that 
> createResource(String id, String type)
> is called in only one place in all of Xindice code, and that place 
> (don't recall where now) supplies
> an id string, so there should be no side effects on Xindice from this 
> change).
> 
> ---------------------------------------------------- 
> 8< ----------------------------------------------------
> diff -aur 
> xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java 
> patched-xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java
> --- 
> xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java    
> Fri Jul 12 06:09:51 2002
> +++ 
> patched-xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java    
> Sun Sep  8 14:49:30 2002
> @@ -248,9 +248,10 @@
>       * @exception XMLDBException thrown in case of an invalid resource 
> type or name
>       */
>      public Resource createResource(String name, String type) throws 
> XMLDBException {
> -        if (name == null) {
> -
> -            name = "";
> +        if (name == null || name.length() == 0) {
> +            // fulfill contract stating
> +            // "If id is null or its value is empty then an id is 
> generated by calling createId()."
> +            name = createId();
>          }
>         
>          if (name.indexOf('/') != -1) {
> ---------------------------------------------------- 
> 8< ----------------------------------------------------
> 
> Thanks.
> 
> -Terry
> 
>