Commit 546efae9 by Harish Butani

fix minor issues in Walker, Stores: get MemRepo:create to work

parent 2810310f
...@@ -42,7 +42,7 @@ public class Id implements ITypedReferenceableInstance { ...@@ -42,7 +42,7 @@ public class Id implements ITypedReferenceableInstance {
} }
public Id(String className) { public Id(String className) {
this(-System.currentTimeMillis(), 0, className); this(-System.nanoTime(), 0, className);
} }
public boolean isUnassigned() { public boolean isUnassigned() {
......
...@@ -56,7 +56,7 @@ public class MapIds implements ObjectGraphWalker.NodeProcessor { ...@@ -56,7 +56,7 @@ public class MapIds implements ObjectGraphWalker.NodeProcessor {
} else if ( nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS ) { } else if ( nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS ) {
if ( nd.value != null && nd.value instanceof IReferenceableInstance ) { if ( nd.value != null && nd.value instanceof IReferenceableInstance ) {
Id oldId = ((IReferenceableInstance)nd.value).getId(); Id oldId = ((IReferenceableInstance)nd.value).getId();
Id newId = idToNewIdMap.get(ref.getId()); Id newId = idToNewIdMap.get(oldId);
/* /*
* Replace Instances with Ids, irrespective of whether they map to newIds or not. * Replace Instances with Ids, irrespective of whether they map to newIds or not.
*/ */
......
...@@ -59,23 +59,23 @@ public class AttributeStores { ...@@ -59,23 +59,23 @@ public class AttributeStores {
} else if ( i.dataType() == DataTypes.SHORT_TYPE ) { } else if ( i.dataType() == DataTypes.SHORT_TYPE ) {
new ShortAttributeStore(i); new ShortAttributeStore(i);
} else if ( i.dataType() == DataTypes.INT_TYPE ) { } else if ( i.dataType() == DataTypes.INT_TYPE ) {
new IntAttributeStore(i); return new IntAttributeStore(i);
} else if ( i.dataType() == DataTypes.LONG_TYPE ) { } else if ( i.dataType() == DataTypes.LONG_TYPE ) {
new LongAttributeStore(i); return new LongAttributeStore(i);
} else if ( i.dataType() == DataTypes.FLOAT_TYPE ) { } else if ( i.dataType() == DataTypes.FLOAT_TYPE ) {
new FloatAttributeStore(i); return new FloatAttributeStore(i);
} else if ( i.dataType() == DataTypes.DOUBLE_TYPE ) { } else if ( i.dataType() == DataTypes.DOUBLE_TYPE ) {
new DoubleAttributeStore(i); return new DoubleAttributeStore(i);
} else if ( i.dataType() == DataTypes.BIGINTEGER_TYPE ) { } else if ( i.dataType() == DataTypes.BIGINTEGER_TYPE ) {
new BigIntStore(i); return new BigIntStore(i);
} else if ( i.dataType() == DataTypes.BIGDECIMAL_TYPE ) { } else if ( i.dataType() == DataTypes.BIGDECIMAL_TYPE ) {
new BigDecimalStore(i); return new BigDecimalStore(i);
} else if ( i.dataType() == DataTypes.DATE_TYPE ) { } else if ( i.dataType() == DataTypes.DATE_TYPE ) {
new DateStore(i); return new DateStore(i);
} else if ( i.dataType() == DataTypes.STRING_TYPE ) { } else if ( i.dataType() == DataTypes.STRING_TYPE ) {
new StringStore(i); return new StringStore(i);
} else if ( i.dataType() == DataTypes.STRING_TYPE ) { } else if ( i.dataType() == DataTypes.STRING_TYPE ) {
new StringStore(i); return new StringStore(i);
} else { } else {
throw new RepositoryException(String.format("Unknown datatype %s", i.dataType())); throw new RepositoryException(String.format("Unknown datatype %s", i.dataType()));
} }
...@@ -237,8 +237,8 @@ public class AttributeStores { ...@@ -237,8 +237,8 @@ public class AttributeStores {
@Override @Override
public void ensureCapacity(int pos) throws RepositoryException { public void ensureCapacity(int pos) throws RepositoryException {
list.ensureCapacity(pos); list.size(pos+1);
nullList.ensureCapacity(pos); nullList.size(pos+1);
} }
} }
...@@ -269,8 +269,8 @@ public class AttributeStores { ...@@ -269,8 +269,8 @@ public class AttributeStores {
@Override @Override
public void ensureCapacity(int pos) throws RepositoryException { public void ensureCapacity(int pos) throws RepositoryException {
list.ensureCapacity(pos); list.size(pos+1);
nullList.ensureCapacity(pos); nullList.size(pos+1);
} }
} }
...@@ -301,8 +301,8 @@ public class AttributeStores { ...@@ -301,8 +301,8 @@ public class AttributeStores {
@Override @Override
public void ensureCapacity(int pos) throws RepositoryException { public void ensureCapacity(int pos) throws RepositoryException {
list.ensureCapacity(pos); list.size(pos+1);
nullList.ensureCapacity(pos); nullList.size(pos+1);
} }
} }
...@@ -333,8 +333,8 @@ public class AttributeStores { ...@@ -333,8 +333,8 @@ public class AttributeStores {
@Override @Override
public void ensureCapacity(int pos) throws RepositoryException { public void ensureCapacity(int pos) throws RepositoryException {
list.ensureCapacity(pos); list.size(pos+1);
nullList.ensureCapacity(pos); nullList.size(pos+1);
} }
} }
...@@ -365,8 +365,8 @@ public class AttributeStores { ...@@ -365,8 +365,8 @@ public class AttributeStores {
@Override @Override
public void ensureCapacity(int pos) throws RepositoryException { public void ensureCapacity(int pos) throws RepositoryException {
list.ensureCapacity(pos); list.size(pos+1);
nullList.ensureCapacity(pos); nullList.size(pos+1);
} }
} }
...@@ -397,8 +397,8 @@ public class AttributeStores { ...@@ -397,8 +397,8 @@ public class AttributeStores {
@Override @Override
public void ensureCapacity(int pos) throws RepositoryException { public void ensureCapacity(int pos) throws RepositoryException {
list.ensureCapacity(pos); list.size(pos+1);
nullList.ensureCapacity(pos); nullList.size(pos+1);
} }
} }
...@@ -429,8 +429,8 @@ public class AttributeStores { ...@@ -429,8 +429,8 @@ public class AttributeStores {
@Override @Override
public void ensureCapacity(int pos) throws RepositoryException { public void ensureCapacity(int pos) throws RepositoryException {
list.ensureCapacity(pos); list.size(pos+1);
nullList.ensureCapacity(pos); nullList.size(pos+1);
} }
} }
...@@ -445,8 +445,10 @@ public class AttributeStores { ...@@ -445,8 +445,10 @@ public class AttributeStores {
@Override @Override
public void ensureCapacity(int pos) throws RepositoryException { public void ensureCapacity(int pos) throws RepositoryException {
list.ensureCapacity(pos); while (list.size() < pos + 1) {
nullList.ensureCapacity(pos); list.add((T)null);
}
nullList.size(pos+1);
} }
} }
......
...@@ -31,10 +31,7 @@ import org.apache.hadoop.metadata.types.AttributeInfo; ...@@ -31,10 +31,7 @@ import org.apache.hadoop.metadata.types.AttributeInfo;
import org.apache.hadoop.metadata.types.HierarchicalType; import org.apache.hadoop.metadata.types.HierarchicalType;
import org.apache.hadoop.metadata.types.IConstructableType; import org.apache.hadoop.metadata.types.IConstructableType;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
public class HierarchicalTypeStore { public class HierarchicalTypeStore {
...@@ -80,6 +77,10 @@ public class HierarchicalTypeStore { ...@@ -80,6 +77,10 @@ public class HierarchicalTypeStore {
superTypeStores = b1.build(); superTypeStores = b1.build();
nextPos = 0; nextPos = 0;
idPosMap = new HashMap<Id, Integer>();
freePositions = new ArrayList<Integer>();
lock = new ReentrantReadWriteLock();
} }
/** /**
...@@ -141,7 +142,7 @@ public class HierarchicalTypeStore { ...@@ -141,7 +142,7 @@ public class HierarchicalTypeStore {
} }
void releaseWriteLock() { void releaseWriteLock() {
lock.readLock().unlock(); lock.writeLock().unlock();
} }
/** /**
...@@ -183,7 +184,9 @@ public class HierarchicalTypeStore { ...@@ -183,7 +184,9 @@ public class HierarchicalTypeStore {
} }
public void ensureCapacity(int pos) throws RepositoryException { public void ensureCapacity(int pos) throws RepositoryException {
typeNameList.ensureCapacity(pos); while (typeNameList.size() < pos + 1) {
typeNameList.add(null);
}
for(Map.Entry<AttributeInfo, IAttributeStore> e : attrStores.entrySet()) { for(Map.Entry<AttributeInfo, IAttributeStore> e : attrStores.entrySet()) {
IAttributeStore attributeStore = e.getValue(); IAttributeStore attributeStore = e.getValue();
attributeStore.ensureCapacity(pos); attributeStore.ensureCapacity(pos);
......
...@@ -176,11 +176,19 @@ public class MemRepository implements IRepository { ...@@ -176,11 +176,19 @@ public class MemRepository implements IRepository {
for (ITypedReferenceableInstance instance : newInstances) { for (ITypedReferenceableInstance instance : newInstances) {
HierarchicalTypeStore st = typeStores.get(instance.getTypeName()); HierarchicalTypeStore st = typeStores.get(instance.getTypeName());
st.assignPosition(instance.getId()); st.assignPosition(instance.getId());
for(String traitName : instance.getTraits()) {
HierarchicalTypeStore tt = typeStores.get(traitName);
tt.assignPosition(instance.getId());
}
} }
for (ITypedReferenceableInstance instance : newInstances) { for (ITypedReferenceableInstance instance : newInstances) {
HierarchicalTypeStore st = typeStores.get(instance.getTypeName()); HierarchicalTypeStore st = typeStores.get(instance.getTypeName());
st.store((ReferenceableInstance)instance); st.store((ReferenceableInstance)instance);
for(String traitName : instance.getTraits()) {
HierarchicalTypeStore tt = typeStores.get(traitName);
// ??
}
} }
} catch(RepositoryException re) { } catch(RepositoryException re) {
for (ITypedReferenceableInstance instance : newInstances) { for (ITypedReferenceableInstance instance : newInstances) {
......
...@@ -32,7 +32,7 @@ public class ObjectGraphWalker { ...@@ -32,7 +32,7 @@ public class ObjectGraphWalker {
this.nodeProcessor = nodeProcessor; this.nodeProcessor = nodeProcessor;
queue = new LinkedList<IReferenceableInstance>(); queue = new LinkedList<IReferenceableInstance>();
processedIds = new HashSet<Id>(); processedIds = new HashSet<Id>();
queue.add(start); visitReferenceableInstance(start);
} }
public ObjectGraphWalker(TypeSystem typeSystem, NodeProcessor nodeProcessor, public ObjectGraphWalker(TypeSystem typeSystem, NodeProcessor nodeProcessor,
...@@ -42,7 +42,9 @@ public class ObjectGraphWalker { ...@@ -42,7 +42,9 @@ public class ObjectGraphWalker {
this.nodeProcessor = nodeProcessor; this.nodeProcessor = nodeProcessor;
queue = new LinkedList<IReferenceableInstance>(); queue = new LinkedList<IReferenceableInstance>();
processedIds = new HashSet<Id>(); processedIds = new HashSet<Id>();
queue.addAll(roots); for(IReferenceableInstance r : roots) {
visitReferenceableInstance(r);
}
} }
public void walk() throws MetadataException { public void walk() throws MetadataException {
...@@ -145,7 +147,10 @@ public class ObjectGraphWalker { ...@@ -145,7 +147,10 @@ public class ObjectGraphWalker {
IReferenceableInstance ref = (IReferenceableInstance) val; IReferenceableInstance ref = (IReferenceableInstance) val;
if (!processedIds.contains(ref.getId())) { if (!processedIds.contains(ref.getId())) {
queue.add(ref); processedIds.add(ref.getId());
if ( !(ref instanceof Id) ) {
queue.add(ref);
}
} }
} }
......
...@@ -21,7 +21,9 @@ public class StorageTest extends BaseTest { ...@@ -21,7 +21,9 @@ public class StorageTest extends BaseTest {
Referenceable hrDept = createDeptEg1(ts); Referenceable hrDept = createDeptEg1(ts);
//ITypedReferenceableInstance hrDept2 = ms.getRepository().create(hrDept); ITypedReferenceableInstance hrDept2 = ms.getRepository().create(hrDept);
//System.out.println(hrDept2);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment