Search in sources :

Example 6 with StopWatch

use of org.perf4j.StopWatch in project cuba by cuba-platform.

the class FoldersServiceBean method loadSearchFolders.

@Override
public List<SearchFolder> loadSearchFolders() {
    log.debug("Loading SearchFolders");
    StopWatch stopWatch = new Slf4JStopWatch("SearchFolders");
    stopWatch.start();
    Transaction tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        MetaClass effectiveMetaClass = metadata.getExtendedEntities().getEffectiveMetaClass(SearchFolder.class);
        TypedQuery<SearchFolder> q = em.createQuery("select f from " + effectiveMetaClass.getName() + " f " + "left join fetch f.user u on u.id = ?1 " + "left join fetch f.presentation " + "where (u.id = ?1 or u is null) " + "order by f.sortOrder, f.name", SearchFolder.class);
        q.setParameter(1, userSessionSource.currentOrSubstitutedUserId());
        List<SearchFolder> list = q.getResultList();
        // fetch parents
        for (SearchFolder folder : list) {
            folder.getParent();
        }
        tx.commit();
        return list;
    } finally {
        tx.end();
        stopWatch.stop();
    }
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) MetaClass(com.haulmont.chile.core.model.MetaClass) SearchFolder(com.haulmont.cuba.security.entity.SearchFolder) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch)

Example 7 with StopWatch

use of org.perf4j.StopWatch in project cuba by cuba-platform.

the class FoldersServiceBean method loadAppFolders.

@Override
public List<AppFolder> loadAppFolders() {
    log.debug("Loading AppFolders");
    StopWatch stopWatch = new Slf4JStopWatch("AppFolders");
    stopWatch.start();
    List<AppFolder> resultList;
    try (Transaction tx = persistence.createTransaction()) {
        String metaClassName = metadata.getExtendedEntities().getEffectiveMetaClass(AppFolder.class).getName();
        TypedQuery<AppFolder> q = persistence.getEntityManager().createQuery("select f from " + metaClassName + " f order by f.sortOrder, f.name", AppFolder.class);
        resultList = q.getResultList();
        // fetch parent folder
        resultList.forEach(Folder::getParent);
        tx.commit();
    } finally {
        stopWatch.stop();
    }
    if (CollectionUtils.isNotEmpty(resultList)) {
        Binding binding = new Binding();
        binding.setVariable("persistence", persistence);
        binding.setVariable("metadata", metadata);
        binding.setVariable("userSession", userSessionSource.getUserSession());
        Iterator<AppFolder> iterator = resultList.iterator();
        while (iterator.hasNext()) {
            AppFolder folder = iterator.next();
            try (Transaction tx = persistence.createTransaction()) {
                boolean evaluatedVisibilityScript = true;
                try {
                    if (!StringUtils.isBlank(folder.getVisibilityScript())) {
                        binding.setVariable("folder", folder);
                        Boolean visible = runScript(folder.getVisibilityScript(), binding);
                        if (BooleanUtils.isFalse(visible)) {
                            iterator.remove();
                            continue;
                        }
                    }
                } catch (Exception e) {
                    log.warn("Unable to evaluate AppFolder visibility script for folder: id: {}  name: {}", folder.getId(), folder.getName(), e);
                    // because EclipseLink Query marks transaction as rollback-only on JPQL syntax errors
                    evaluatedVisibilityScript = false;
                }
                boolean evaluatedQuantityScript = loadFolderQuantity(binding, folder);
                if (evaluatedVisibilityScript && evaluatedQuantityScript) {
                    tx.commit();
                }
            }
        }
    }
    return resultList;
}
Also used : Binding(groovy.lang.Binding) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) AppFolder(com.haulmont.cuba.core.entity.AppFolder) SearchFolder(com.haulmont.cuba.security.entity.SearchFolder) Folder(com.haulmont.cuba.core.entity.Folder) IOException(java.io.IOException) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch) AppFolder(com.haulmont.cuba.core.entity.AppFolder) Transaction(com.haulmont.cuba.core.Transaction)

Example 8 with StopWatch

use of org.perf4j.StopWatch in project cuba by cuba-platform.

the class FoldersServiceBean method reloadAppFolders.

@Override
public List<AppFolder> reloadAppFolders(List<AppFolder> folders) {
    log.debug("Reloading AppFolders {}", folders);
    StopWatch stopWatch = new Slf4JStopWatch("AppFolders");
    stopWatch.start();
    try {
        if (!folders.isEmpty()) {
            Binding binding = new Binding();
            binding.setVariable("persistence", persistence);
            binding.setVariable("metadata", metadata);
            binding.setProperty("userSession", userSessionSource.getUserSession());
            for (AppFolder folder : folders) {
                Transaction tx = persistence.createTransaction();
                try {
                    if (loadFolderQuantity(binding, folder)) {
                        tx.commit();
                    }
                } finally {
                    tx.end();
                }
            }
        }
        return folders;
    } finally {
        stopWatch.stop();
    }
}
Also used : Binding(groovy.lang.Binding) AppFolder(com.haulmont.cuba.core.entity.AppFolder) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) Transaction(com.haulmont.cuba.core.Transaction) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch)

Example 9 with StopWatch

use of org.perf4j.StopWatch in project cuba by cuba-platform.

the class WindowManager method afterShowWindow.

protected void afterShowWindow(Window window) {
    if (!WindowParams.DISABLE_APPLY_SETTINGS.getBool(window.getContext())) {
        window.applySettings(getSettingsImpl(window.getId()));
    }
    if (!WindowParams.DISABLE_RESUME_SUSPENDED.getBool(window.getContext())) {
        ((DsContextImplementation) window.getDsContext()).resumeSuspended();
    }
    if (window instanceof AbstractWindow) {
        AbstractWindow abstractWindow = (AbstractWindow) window;
        if (abstractWindow.isAttributeAccessControlEnabled()) {
            AttributeAccessSupport attributeAccessSupport = AppBeans.get(AttributeAccessSupport.NAME);
            attributeAccessSupport.applyAttributeAccess(abstractWindow, false);
        }
        StopWatch readyStopWatch = new Slf4JStopWatch(window.getId() + "#" + LifeCycle.READY, LoggerFactory.getLogger(UIPerformanceLogger.class));
        abstractWindow.ready();
        readyStopWatch.stop();
    }
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation) UIPerformanceLogger(com.haulmont.cuba.gui.logging.UIPerformanceLogger) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch)

Example 10 with StopWatch

use of org.perf4j.StopWatch in project cuba by cuba-platform.

the class WindowManager method init.

protected void init(Window window, Map<String, Object> params) {
    if (window instanceof AbstractWindow) {
        StopWatch initStopWatch = new Slf4JStopWatch(window.getId() + "#" + LifeCycle.INIT, LoggerFactory.getLogger(UIPerformanceLogger.class));
        ((AbstractWindow) window).init(params);
        initStopWatch.stop();
    }
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) UIPerformanceLogger(com.haulmont.cuba.gui.logging.UIPerformanceLogger) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch)

Aggregations

StopWatch (org.perf4j.StopWatch)41 Slf4JStopWatch (org.perf4j.slf4j.Slf4JStopWatch)41 UIPerformanceLogger (com.haulmont.cuba.gui.logging.UIPerformanceLogger)17 Element (org.dom4j.Element)4 Transaction (com.haulmont.cuba.core.Transaction)3 Test (org.testng.annotations.Test)3 Node (com.haulmont.bali.datastruct.Node)2 MetaClass (com.haulmont.chile.core.model.MetaClass)2 AppFolder (com.haulmont.cuba.core.entity.AppFolder)2 ComponentLoader (com.haulmont.cuba.gui.xml.layout.ComponentLoader)2 ComponentLoaderContext (com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext)2 SearchFolder (com.haulmont.cuba.security.entity.SearchFolder)2 Binding (groovy.lang.Binding)2 IOException (java.io.IOException)2 KryoException (com.esotericsoftware.kryo.KryoException)1 Pair (com.haulmont.bali.datastruct.Pair)1 Tree (com.haulmont.bali.datastruct.Tree)1 MetaModel (com.haulmont.chile.core.model.MetaModel)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 EntityManager (com.haulmont.cuba.core.EntityManager)1