On Thu, Jan 23, 2014 at 11:42:09AM -0600, Tim Donohue wrote: > 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
What I had missed is here. MetadataCache.get() returns a reference to the managed cache content. Wow, is that ever broken. I am adding Javadoc to make this a little clearer. > (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. Thanks! It is more than a little confusing. I think the whole addMetadata(String, String, String, String, String[], String[], String[]) method belongs in MetadataCache, instead of handing out references to internal data structures in MetadataCache.get(). -- Mark H. Wood, Lead System Programmer mw...@iupui.edu Machines should not be friendly. Machines should be obedient.
signature.asc
Description: Digital signature
------------------------------------------------------------------------------ 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