Commit 82209db0 by Harish Butani

introduce ClassStore + TraitStore

parent 546efae9
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.metadata.storage.memory;
import com.google.common.collect.ImmutableList;
import org.apache.hadoop.metadata.storage.ReferenceableInstance;
import org.apache.hadoop.metadata.storage.RepositoryException;
import org.apache.hadoop.metadata.types.ClassType;
import org.apache.hadoop.metadata.types.HierarchicalType;
import java.util.ArrayList;
public class ClassStore extends HierarchicalTypeStore {
final ArrayList<ImmutableList<String>> traitNamesStore;
public ClassStore(MemRepository repository, ClassType hierarchicalType) throws RepositoryException {
super(repository, hierarchicalType);
traitNamesStore = new ArrayList<ImmutableList<String>>();
}
void store(ReferenceableInstance i) throws RepositoryException {
super.store(i);
int pos = idPosMap.get(i.getId());
traitNamesStore.set(pos, i.getTraits());
}
public void ensureCapacity(int pos) throws RepositoryException {
super.ensureCapacity(pos);
while (traitNamesStore.size() < pos + 1) {
traitNamesStore.add(null);
}
}
}
...@@ -22,11 +22,9 @@ import com.google.common.collect.ImmutableBiMap; ...@@ -22,11 +22,9 @@ import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.apache.hadoop.metadata.storage.Id; import org.apache.hadoop.metadata.storage.*;
import org.apache.hadoop.metadata.ITypedReferenceableInstance; import org.apache.hadoop.metadata.ITypedReferenceableInstance;
import org.apache.hadoop.metadata.storage.Id; import org.apache.hadoop.metadata.storage.Id;
import org.apache.hadoop.metadata.storage.ReferenceableInstance;
import org.apache.hadoop.metadata.storage.RepositoryException;
import org.apache.hadoop.metadata.types.AttributeInfo; 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;
...@@ -34,7 +32,7 @@ import org.apache.hadoop.metadata.types.IConstructableType; ...@@ -34,7 +32,7 @@ import org.apache.hadoop.metadata.types.IConstructableType;
import java.util.*; import java.util.*;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
public class HierarchicalTypeStore { public abstract class HierarchicalTypeStore {
final MemRepository repository; final MemRepository repository;
final IConstructableType hierarchicalType; final IConstructableType hierarchicalType;
...@@ -145,6 +143,13 @@ public class HierarchicalTypeStore { ...@@ -145,6 +143,13 @@ public class HierarchicalTypeStore {
lock.writeLock().unlock(); lock.writeLock().unlock();
} }
protected void storeFields(int pos, StructInstance s) throws RepositoryException {
for(Map.Entry<AttributeInfo, IAttributeStore> e : attrStores.entrySet()) {
IAttributeStore attributeStore = e.getValue();
attributeStore.store(pos, hierarchicalType, s);
}
}
/** /**
* - store the typeName * - store the typeName
* - store the immediate attributes in the respective IAttributeStore * - store the immediate attributes in the respective IAttributeStore
...@@ -155,10 +160,7 @@ public class HierarchicalTypeStore { ...@@ -155,10 +160,7 @@ public class HierarchicalTypeStore {
void store(ReferenceableInstance i) throws RepositoryException { void store(ReferenceableInstance i) throws RepositoryException {
int pos = idPosMap.get(i.getId()); int pos = idPosMap.get(i.getId());
typeNameList.set(pos, i.getTypeName()); typeNameList.set(pos, i.getTypeName());
for(Map.Entry<AttributeInfo, IAttributeStore> e : attrStores.entrySet()) { storeFields(pos, i);
IAttributeStore attributeStore = e.getValue();
attributeStore.store(pos, hierarchicalType, i);
}
for(HierarchicalTypeStore s : superTypeStores) { for(HierarchicalTypeStore s : superTypeStores) {
s.store(i); s.store(i);
......
...@@ -187,7 +187,7 @@ public class MemRepository implements IRepository { ...@@ -187,7 +187,7 @@ public class MemRepository implements IRepository {
st.store((ReferenceableInstance)instance); st.store((ReferenceableInstance)instance);
for(String traitName : instance.getTraits()) { for(String traitName : instance.getTraits()) {
HierarchicalTypeStore tt = typeStores.get(traitName); HierarchicalTypeStore tt = typeStores.get(traitName);
// ?? tt.store((ReferenceableInstance)instance);
} }
} }
} catch(RepositoryException re) { } catch(RepositoryException re) {
...@@ -228,12 +228,12 @@ public class MemRepository implements IRepository { ...@@ -228,12 +228,12 @@ public class MemRepository implements IRepository {
} }
public void defineClass(ClassType type) throws RepositoryException { public void defineClass(ClassType type) throws RepositoryException {
HierarchicalTypeStore s = new HierarchicalTypeStore(this, type); HierarchicalTypeStore s = new ClassStore(this, type);
typeStores.put(type.getName(), s); typeStores.put(type.getName(), s);
} }
public void defineTrait(TraitType type) throws RepositoryException { public void defineTrait(TraitType type) throws RepositoryException {
HierarchicalTypeStore s = new HierarchicalTypeStore(this, type); HierarchicalTypeStore s = new TraitStore(this, type);
typeStores.put(type.getName(), s); typeStores.put(type.getName(), s);
} }
......
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.metadata.storage.memory;
import org.apache.hadoop.metadata.storage.ReferenceableInstance;
import org.apache.hadoop.metadata.storage.RepositoryException;
import org.apache.hadoop.metadata.storage.StructInstance;
import org.apache.hadoop.metadata.types.TraitType;
import java.util.ArrayList;
public class TraitStore extends HierarchicalTypeStore {
final ArrayList<String> classNameStore;
public TraitStore(MemRepository repository, TraitType hierarchicalType) throws RepositoryException {
super(repository, hierarchicalType);
classNameStore = new ArrayList<String>();
}
void store(ReferenceableInstance i) throws RepositoryException {
int pos = idPosMap.get(i.getId());
StructInstance s = (StructInstance) i.getTrait(hierarchicalType.getName());
super.storeFields(pos, s);
classNameStore.set(pos, i.getTypeName());
}
public void ensureCapacity(int pos) throws RepositoryException {
super.ensureCapacity(pos);
while (classNameStore.size() < pos + 1) {
classNameStore.add(null);
}
}
}
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