Hi Mark,

Yes, the logic is a little bit confusing, but I've finally figured it out.

Here's what's going on (sorry for the tons of detail, but writing this 
out actually helped me figure out *why* this works):

(1) When Item class is loaded, "this.dublinCore" is initialized as a 
"new MetadataCache()" (and MetadataCache is a subclass). This becomes 
very important later on.
https://github.com/DSpace/DSpace/blob/master/dspace-api/src/main/java/org/dspace/content/Item.java#L86

(2) A call to that specific "addMetadata" method begins with first 
calling "getMetadata()":
https://github.com/DSpace/DSpace/blob/master/dspace-api/src/main/java/org/dspace/content/Item.java#L709

(3) The call to "getMetadata()" calls "this.dublinCore.get()", which is 
MetadataCache.get():
https://github.com/DSpace/DSpace/blob/master/dspace-api/src/main/java/org/dspace/content/Item.java#L2744

(4) The call to "this.dublinCore.get()" loads all the existing metadata 
fields/values into a GLOBALLY SAVED List<DCValue> 
(MetadataCache.metadata), and returns a reference to it. The IMPORTANT 
part is that this List<DCValue> is getting saved globally as part of 
"this.dublinCore" right here:
https://github.com/DSpace/DSpace/blob/master/dspace-api/src/main/java/org/dspace/content/Item.java#L2768

(5) Back in "addMetadata", that referenced List<DCValue> is 
(confusingly) saved to a locally scoped variable also named "dublinCore":
https://github.com/DSpace/DSpace/blob/master/dspace-api/src/main/java/org/dspace/content/Item.java#L709

(6) The rest of the "addMetadata" method updates that local variable 
"dublinCore" (by adding metadata to the existing global List<DCValue>):
https://github.com/DSpace/DSpace/blob/master/dspace-api/src/main/java/org/dspace/content/Item.java#L771

(7) If new metadata values were added, then the global 
"this.dublinCoreChanged" flag is set to true at the end of "addMetadata()".

(8) AS SOON AS "item.update()" is called, the globally saved 
List<DCValue> is reloaded (via another call to "getMetadata()) and 
actually saved to the database:
https://github.com/DSpace/DSpace/blob/master/dspace-api/src/main/java/org/dspace/content/Item.java#L1591


To summarize: the role of "item.addMetadata()" is to update/change a 
global MetadataCache (stored in "this.dublinCore"). By itself, all it 
does is update that global cache (nothing actually changes).  But, once 
you call "item.update()" any changes are then written to the database.

- Tim

On 1/22/2014 12:31 PM, Mark H. Wood wrote:
> I must be missing something.  The addMetadata() methods all converge
> on:
>
>       public void addMetadata(String schema,
>              String element,
>              String qualifier,
>              String lang,
>              String[] values,
>              String authorities[],
>              int confidences[])
>
> which carefully checks authority and confidence, grooms metadata value
> strings, adds metadata entries to a *local* list whose name shadows
> the instance metadata cache, sets dublinCoreChanged if something
> changed, accumulates event details, and then exits, returning no value
> and apparently changing no instance or global state except
> dublinCoreChanged.
>
> So what's it for?  What did I miss?
>
> This is used in Item, ItemTest, and MetadataImport.
>
> It worries me that this code sets dublinCoreChanged, as if it had
> modified the content of the *field* "MetadataCache dublinCore = new
> MetadataCache()", but it looks to me as though it's only adding to the
> local variable "List<DCValue> dublinCore".
>
>
>
> ------------------------------------------------------------------------------
> CenturyLink Cloud: The Leader in Enterprise Cloud Services.
> Learn Why More Businesses Are Choosing CenturyLink Cloud For
> Critical Workloads, Development Environments & Everything In Between.
> Get a Quote or Start a Free Trial Today.
> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
>
>
>
> _______________________________________________
> Dspace-devel mailing list
> Dspace-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/dspace-devel
>

------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Dspace-devel mailing list
Dspace-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dspace-devel

Reply via email to