Search in sources :

Example 1 with MetaModel

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));
    }
}
Also used : MetaModel(com.haulmont.chile.core.model.MetaModel) Metadata(com.haulmont.cuba.core.global.Metadata) Session(com.haulmont.chile.core.model.Session) Test(org.junit.Test)

Example 2 with MetaModel

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();
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch) MetaModel(com.haulmont.chile.core.model.MetaModel) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Pair(com.haulmont.bali.datastruct.Pair)

Aggregations

MetaModel (com.haulmont.chile.core.model.MetaModel)2 Pair (com.haulmont.bali.datastruct.Pair)1 MetaClass (com.haulmont.chile.core.model.MetaClass)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 Session (com.haulmont.chile.core.model.Session)1 Metadata (com.haulmont.cuba.core.global.Metadata)1 Test (org.junit.Test)1 StopWatch (org.perf4j.StopWatch)1 Slf4JStopWatch (org.perf4j.slf4j.Slf4JStopWatch)1