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();
}
}
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;
}
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();
}
}
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();
}
}
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();
}
}
Aggregations