From da731d2bb81666b9c697d9099da632e7dfcdc0f7 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 9 Sep 2014 12:13:21 +0200 Subject: Replaced int sysKey Item identifier with UUID, which is now portable. ItemPath objects are now used to identify Items throughout the kernel, replacing ints and Integers. --- .../com/c2kernel/collection/AggregationMember.java | 70 ++++++++++++---------- 1 file changed, 38 insertions(+), 32 deletions(-) (limited to 'src/main/java/com/c2kernel/collection/AggregationMember.java') diff --git a/src/main/java/com/c2kernel/collection/AggregationMember.java b/src/main/java/com/c2kernel/collection/AggregationMember.java index 67e92ad..cb8c355 100644 --- a/src/main/java/com/c2kernel/collection/AggregationMember.java +++ b/src/main/java/com/c2kernel/collection/AggregationMember.java @@ -1,12 +1,12 @@ package com.c2kernel.collection; import java.util.StringTokenizer; +import java.util.UUID; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.proxy.ItemProxy; import com.c2kernel.graph.model.GraphableVertex; import com.c2kernel.lookup.ItemPath; -import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.persistency.ClusterStorage; import com.c2kernel.process.Gateway; import com.c2kernel.property.Property; @@ -24,11 +24,11 @@ import com.c2kernel.utils.Logger; public class AggregationMember extends GraphableVertex implements CollectionMember { - private int mSystemKey = -1; - private ItemProxy mItem = null; - private Aggregation mCollection = null; + private ItemPath mItemPath = null; + private ItemProxy mItem = null; + private Aggregation mCollection = null; private String mClassProps = null; - String ItemName; + private String mItemName = null; /************************************************************************** @@ -37,14 +37,12 @@ public class AggregationMember extends GraphableVertex implements CollectionMemb public AggregationMember() { super(); - mSystemKey = -1; - mCollection = null; } @Override - public void setSystemKey(int sysKey) { - mSystemKey = sysKey; - ItemName = null; + public void setItemPath(ItemPath itemPath) { + mItemPath = itemPath; + mItemName = null; } public void setCollection(Aggregation aggregation) @@ -59,9 +57,9 @@ public class AggregationMember extends GraphableVertex implements CollectionMemb } @Override - public int getSystemKey() + public ItemPath getItemPath() { - return mSystemKey; + return mItemPath; } public Aggregation getCollection() @@ -76,9 +74,9 @@ public class AggregationMember extends GraphableVertex implements CollectionMemb } @Override - public void assignItem(int sysKey) throws MembershipException + public void assignItem(ItemPath itemPath) throws MembershipException { - if (sysKey > -1) { + if (itemPath != null) { if (mClassProps == null || getProperties() == null) throw new MembershipException("ClassProps not yet set. Cannot check membership validity."); @@ -89,9 +87,9 @@ public class AggregationMember extends GraphableVertex implements CollectionMemb String aClassProp = sub.nextToken(); try { String memberValue = (String)getProperties().get(aClassProp); - Property ItemProperty = (Property)Gateway.getStorage().get(sysKey, ClusterStorage.PROPERTY+"/"+aClassProp, null); + Property ItemProperty = (Property)Gateway.getStorage().get(itemPath, ClusterStorage.PROPERTY+"/"+aClassProp, null); if (ItemProperty == null) - throw new MembershipException("Property "+aClassProp+ " does not exist for sysKey=" + sysKey ); + throw new MembershipException("Property "+aClassProp+ " does not exist for item " + itemPath ); if (ItemProperty.getValue() == null || !ItemProperty.getValue().equalsIgnoreCase(memberValue)) throw new MembershipException("Value of mandatory prop "+aClassProp+" does not match: " + ItemProperty.getValue()+"!="+memberValue); } @@ -106,46 +104,54 @@ public class AggregationMember extends GraphableVertex implements CollectionMemb } } - mSystemKey = sysKey; + mItemPath = itemPath; mItem = null; - ItemName = null; + mItemName = null; } @Override public void clearItem() { - mSystemKey = -1; + mItemPath = null; mItem = null; + mItemName = null; } @Override public ItemProxy resolveItem() throws ObjectNotFoundException { - if (mItem == null) { - try { - ItemPath path = new ItemPath(mSystemKey); - mItem = Gateway.getProxyManager().getProxy(path); - } catch (InvalidItemPathException ex) { - throw new ObjectNotFoundException("No member defined", ""); - } + if (mItem == null && mItemPath != null) { + mItem = Gateway.getProxyManager().getProxy(mItemPath); } return mItem; } public String getItemName() { - if (ItemName == null) { - if (mSystemKey > -1) { + if (mItemName == null) { + if (mItemPath != null) { try { - ItemName = resolveItem().getName(); + mItemName = resolveItem().getName(); } catch (ObjectNotFoundException ex) { Logger.error(ex); - ItemName = "Error ("+mSystemKey+")"; + mItemName = "Error ("+mItemPath+")"; } } else - ItemName = "Empty"; + mItemName = "Empty"; } - return ItemName; + return mItemName; } + @Override + public void setChildUUID(String uuid) throws MembershipException { + setItemPath(new ItemPath(UUID.fromString(uuid))); + } + + + @Override + public String getChildUUID() { + if (getItemPath() == null) return null; + return getItemPath().getUUID().toString(); + } + } -- cgit v1.2.3