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 {
}
public Id(String className) {
this(-System.currentTimeMillis(), 0, className);
this(-System.nanoTime(), 0, className);
}
public boolean isUnassigned() {
......
......@@ -56,7 +56,7 @@ public class MapIds implements ObjectGraphWalker.NodeProcessor {
} else if ( nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS ) {
if ( nd.value != null && nd.value instanceof IReferenceableInstance ) {
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.
*/
......
......@@ -59,23 +59,23 @@ public class AttributeStores {
} else if ( i.dataType() == DataTypes.SHORT_TYPE ) {
new ShortAttributeStore(i);
} else if ( i.dataType() == DataTypes.INT_TYPE ) {
new IntAttributeStore(i);
return new IntAttributeStore(i);
} else if ( i.dataType() == DataTypes.LONG_TYPE ) {
new LongAttributeStore(i);
return new LongAttributeStore(i);
} else if ( i.dataType() == DataTypes.FLOAT_TYPE ) {
new FloatAttributeStore(i);
return new FloatAttributeStore(i);
} else if ( i.dataType() == DataTypes.DOUBLE_TYPE ) {
new DoubleAttributeStore(i);
return new DoubleAttributeStore(i);
} else if ( i.dataType() == DataTypes.BIGINTEGER_TYPE ) {
new BigIntStore(i);
return new BigIntStore(i);
} else if ( i.dataType() == DataTypes.BIGDECIMAL_TYPE ) {
new BigDecimalStore(i);
return new BigDecimalStore(i);
} else if ( i.dataType() == DataTypes.DATE_TYPE ) {
new DateStore(i);
return new DateStore(i);
} else if ( i.dataType() == DataTypes.STRING_TYPE ) {
new StringStore(i);
return new StringStore(i);
} else if ( i.dataType() == DataTypes.STRING_TYPE ) {
new StringStore(i);
return new StringStore(i);
} else {
throw new RepositoryException(String.format("Unknown datatype %s", i.dataType()));
}
......@@ -237,8 +237,8 @@ public class AttributeStores {
@Override
public void ensureCapacity(int pos) throws RepositoryException {
list.ensureCapacity(pos);
nullList.ensureCapacity(pos);
list.size(pos+1);
nullList.size(pos+1);
}
}
......@@ -269,8 +269,8 @@ public class AttributeStores {
@Override
public void ensureCapacity(int pos) throws RepositoryException {
list.ensureCapacity(pos);
nullList.ensureCapacity(pos);
list.size(pos+1);
nullList.size(pos+1);
}
}
......@@ -301,8 +301,8 @@ public class AttributeStores {
@Override
public void ensureCapacity(int pos) throws RepositoryException {
list.ensureCapacity(pos);
nullList.ensureCapacity(pos);
list.size(pos+1);
nullList.size(pos+1);
}
}
......@@ -333,8 +333,8 @@ public class AttributeStores {
@Override
public void ensureCapacity(int pos) throws RepositoryException {
list.ensureCapacity(pos);
nullList.ensureCapacity(pos);
list.size(pos+1);
nullList.size(pos+1);
}
}
......@@ -365,8 +365,8 @@ public class AttributeStores {
@Override
public void ensureCapacity(int pos) throws RepositoryException {
list.ensureCapacity(pos);
nullList.ensureCapacity(pos);
list.size(pos+1);
nullList.size(pos+1);
}
}
......@@ -397,8 +397,8 @@ public class AttributeStores {
@Override
public void ensureCapacity(int pos) throws RepositoryException {
list.ensureCapacity(pos);
nullList.ensureCapacity(pos);
list.size(pos+1);
nullList.size(pos+1);
}
}
......@@ -429,8 +429,8 @@ public class AttributeStores {
@Override
public void ensureCapacity(int pos) throws RepositoryException {
list.ensureCapacity(pos);
nullList.ensureCapacity(pos);
list.size(pos+1);
nullList.size(pos+1);
}
}
......@@ -445,8 +445,10 @@ public class AttributeStores {
@Override
public void ensureCapacity(int pos) throws RepositoryException {
list.ensureCapacity(pos);
nullList.ensureCapacity(pos);
while (list.size() < pos + 1) {
list.add((T)null);
}
nullList.size(pos+1);
}
}
......
......@@ -31,10 +31,7 @@ import org.apache.hadoop.metadata.types.AttributeInfo;
import org.apache.hadoop.metadata.types.HierarchicalType;
import org.apache.hadoop.metadata.types.IConstructableType;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public class HierarchicalTypeStore {
......@@ -80,6 +77,10 @@ public class HierarchicalTypeStore {
superTypeStores = b1.build();
nextPos = 0;
idPosMap = new HashMap<Id, Integer>();
freePositions = new ArrayList<Integer>();
lock = new ReentrantReadWriteLock();
}
/**
......@@ -141,7 +142,7 @@ public class HierarchicalTypeStore {
}
void releaseWriteLock() {
lock.readLock().unlock();
lock.writeLock().unlock();
}
/**
......@@ -183,7 +184,9 @@ public class HierarchicalTypeStore {
}
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()) {
IAttributeStore attributeStore = e.getValue();
attributeStore.ensureCapacity(pos);
......
......@@ -176,11 +176,19 @@ public class MemRepository implements IRepository {
for (ITypedReferenceableInstance instance : newInstances) {
HierarchicalTypeStore st = typeStores.get(instance.getTypeName());
st.assignPosition(instance.getId());
for(String traitName : instance.getTraits()) {
HierarchicalTypeStore tt = typeStores.get(traitName);
tt.assignPosition(instance.getId());
}
}
for (ITypedReferenceableInstance instance : newInstances) {
HierarchicalTypeStore st = typeStores.get(instance.getTypeName());
st.store((ReferenceableInstance)instance);
for(String traitName : instance.getTraits()) {
HierarchicalTypeStore tt = typeStores.get(traitName);
// ??
}
}
} catch(RepositoryException re) {
for (ITypedReferenceableInstance instance : newInstances) {
......
......@@ -32,7 +32,7 @@ public class ObjectGraphWalker {
this.nodeProcessor = nodeProcessor;
queue = new LinkedList<IReferenceableInstance>();
processedIds = new HashSet<Id>();
queue.add(start);
visitReferenceableInstance(start);
}
public ObjectGraphWalker(TypeSystem typeSystem, NodeProcessor nodeProcessor,
......@@ -42,7 +42,9 @@ public class ObjectGraphWalker {
this.nodeProcessor = nodeProcessor;
queue = new LinkedList<IReferenceableInstance>();
processedIds = new HashSet<Id>();
queue.addAll(roots);
for(IReferenceableInstance r : roots) {
visitReferenceableInstance(r);
}
}
public void walk() throws MetadataException {
......@@ -145,7 +147,10 @@ public class ObjectGraphWalker {
IReferenceableInstance ref = (IReferenceableInstance) val;
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 {
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