use of com.haulmont.chile.core.model.MetaModel in project cuba by cuba-platform.
the class MetadataTest method test.
@Test
public void test() {
Session session = AppBeans.get(Metadata.class).getSession();
assertNotNull(session);
Collection<MetaModel> models = session.getModels();
for (MetaModel model : models) {
System.out.println("Model: " + model.getName());
System.out.println(PrintUtils.printClassHierarchy(model));
}
}
use of com.haulmont.chile.core.model.MetaModel in project cuba by cuba-platform.
the class MetadataLoader method replaceExtendedMetaClasses.
protected void replaceExtendedMetaClasses() {
StopWatch sw = new Slf4JStopWatch("Metadata.replaceExtendedMetaClasses");
for (MetaModel model : session.getModels()) {
MetaModelImpl modelImpl = (MetaModelImpl) model;
List<Pair<MetaClass, MetaClass>> replaceMap = new ArrayList<>();
for (MetaClass metaClass : modelImpl.getClasses()) {
MetaClass effectiveMetaClass = session.getClass(extendedEntities.getEffectiveClass(metaClass));
if (effectiveMetaClass != metaClass) {
replaceMap.add(new Pair<>(metaClass, effectiveMetaClass));
}
for (MetaProperty metaProperty : metaClass.getOwnProperties()) {
MetaPropertyImpl propertyImpl = (MetaPropertyImpl) metaProperty;
// replace domain
Class effectiveDomainClass = extendedEntities.getEffectiveClass(metaProperty.getDomain());
MetaClass effectiveDomainMeta = session.getClass(effectiveDomainClass);
if (metaProperty.getDomain() != effectiveDomainMeta) {
propertyImpl.setDomain(effectiveDomainMeta);
}
if (metaProperty.getRange().isClass()) {
// replace range class
ClassRange range = (ClassRange) metaProperty.getRange();
Class effectiveRangeClass = extendedEntities.getEffectiveClass(range.asClass());
MetaClass effectiveRangeMeta = session.getClass(effectiveRangeClass);
if (effectiveRangeMeta != range.asClass()) {
ClassRange newRange = new ClassRange(effectiveRangeMeta);
newRange.setCardinality(range.getCardinality());
newRange.setOrdered(range.isOrdered());
((MetaPropertyImpl) metaProperty).setRange(newRange);
}
}
}
}
for (Pair<MetaClass, MetaClass> replace : replaceMap) {
MetaClass replacedMetaClass = replace.getFirst();
extendedEntities.registerReplacedMetaClass(replacedMetaClass);
MetaClassImpl effectiveMetaClass = (MetaClassImpl) replace.getSecond();
modelImpl.registerClass(replacedMetaClass.getName(), replacedMetaClass.getJavaClass(), effectiveMetaClass);
}
}
sw.stop();
}
Aggregations