protected Collection<? extends Entity> reloadEntities(Collection<? extends Entity> entities, View view) { List<Object> ids = entities.stream() .map(Entity::getId) .collect(Collectors.toList()); MetaClass metaClass = metadata.getClassNN(view.getEntityClass()); LoadContext.Query query = LoadContext.createQuery("select e from " + metaClass.getName() + " e where e.id in :ids") .setParameter("ids", ids); LoadContext<? extends Entity> ctx = LoadContext.create(view.getEntityClass()) .setQuery(query) .setView(view); return dataManager.loadList(ctx); }
@Nullable protected Entity findEntity(String entityName, Object entityId) { Entity entity = null; if (entityId != null && !Strings.isNullOrEmpty(entityName)) { MetaClass metaClass = metadata.getClass(entityName); if (metaClass != null) { LoadContext ctx = new LoadContext(metaClass).setQuery( LoadContext.createQuery(String.format("select e from %s e where e.%s = :entityId", entityName, referenceToEntitySupport.getPrimaryKeyForLoadingEntity(metaClass))) .setParameter("entityId", entityId)) .setView(View.MINIMAL); entity = dataManager.load(ctx); } } return entity; }
protected List<com.haulmont.cuba.core.entity.Config> loadDbContent() { LoadContext<com.haulmont.cuba.core.entity.Config> loadContext = LoadContext.create(com.haulmont.cuba.core.entity.Config.class).setQuery( LoadContext.createQuery("select c from sys$Config c") ).setView("appProperties"); return dataManager.loadList(loadContext); }
protected void loadEntities(MetaClass metaClass) { LoadContext loadContext = LoadContext.create(metaClass.getJavaClass()) .setQuery(LoadContext.createQuery(format("select e from %s e", metaClass.getName()))); List entities = dataManager.loadList(loadContext); entitiesLookup.setOptionsList(entities); }
private List<Tenant> createOptionList() { return dataManager.loadList(LoadContext.create(Tenant.class) .setQuery(LoadContext.createQuery("select e from cubasdbmt$Tenant e")) .setView("tenant-with-group")); }
public EntitiesSearchResult loadEntitiesList(String entityName, @Nullable String viewName, @Nullable Integer limit, @Nullable Integer offset, @Nullable String sort, @Nullable Boolean returnNulls, @Nullable Boolean returnCount, @Nullable Boolean dynamicAttributes, @Nullable String modelVersion) { entityName = restControllerUtils.transformEntityNameIfRequired(entityName, modelVersion, JsonTransformationDirection.FROM_VERSION); MetaClass metaClass = restControllerUtils.getMetaClass(entityName); checkCanReadEntity(metaClass); String queryString = "select e from " + entityName + " e"; String json = _loadEntitiesList(queryString, viewName, limit, offset, sort, returnNulls, dynamicAttributes, modelVersion, metaClass, new HashMap<>()); json = restControllerUtils.transformJsonIfRequired(entityName, modelVersion, JsonTransformationDirection.TO_VERSION, json); Long count = null; if (BooleanUtils.isTrue(returnCount)) { LoadContext ctx = LoadContext.create(metaClass.getJavaClass()) .setQuery(LoadContext.createQuery(queryString)); count = dataManager.getCount(ctx); } return new EntitiesSearchResult(json, count); }
LoadContext<E> createLoadContext() { LoadContext<E> loadContext = LoadContext.create(loader.entityClass); loader.initCommonLoadContextParameters(loadContext); LoadContext.Query query = LoadContext.createQuery(queryString); for (Map.Entry<String, Object> entry : parameters.entrySet()) { if (noConversionParams.contains(entry.getKey())) query.setParameter(entry.getKey(), entry.getValue(), false); else query.setParameter(entry.getKey(), entry.getValue()); } loadContext.setQuery(query); loadContext.getQuery().setCondition(condition); loadContext.getQuery().setFirstResult(firstResult); loadContext.getQuery().setMaxResults(maxResults); loadContext.getQuery().setCacheable(cacheable); return loadContext; }
LoadContext<E> createLoadContext() { LoadContext<E> loadContext = LoadContext.create(entityClass); initCommonLoadContextParameters(loadContext); String entityName = AppBeans.get(Metadata.class).getClassNN(entityClass).getName(); String queryString = String.format("select e from %s e", entityName); loadContext.setQuery(LoadContext.createQuery(queryString)); return loadContext; }
/** * For entities with composite keys there will be a value of the 'uuid' property in the {@code entityId} parameter. */ protected Entity reloadEntity(MetaClass metaClass, Object entityId) { String ftsPrimaryKeyName = ftsService.getPrimaryKeyPropertyForFts(metaClass).getName(); String queryStr = String.format("select e from %s e where e.%s = :id", metaClass.getName(), ftsPrimaryKeyName); LoadContext lc = new LoadContext(metaClass) .setView(View.MINIMAL) .setQuery(LoadContext.createQuery(queryStr).setParameter("id", entityId)); List list = getDsContext().getDataSupplier().loadList(lc); return list.isEmpty() ? null : (Entity) list.get(0); } }
String queryString = String.format( "select e from %s e where e.%s in :idList", cdsrMetaClass, crossDataStoreProperty.primaryKeyName); loadContext.setQuery(LoadContext.createQuery(queryString).setParameter("idList", idList)); } else { sb.append(" and "); LoadContext.Query query = LoadContext.createQuery(sb.toString()); for (MetaProperty property : idMetaClass.getProperties()) { List<Object> propList = idList.stream()
loadContext.setView(view); loadContext.setQuery(LoadContext.createQuery(stringQuery).setParameter("searchString", searchString));
@Override public List<SessionLogEntry> getAllSessionLogRecords(UUID userSessionId) { return authentication.withSystemUser(() -> { LoadContext<SessionLogEntry> loadContext = LoadContext.create(SessionLogEntry.class) .setView(SessionLogEntry.DEFAULT_VIEW) .setQuery( createQuery("select e from sec$SessionLogEntry e where e.sessionId = :sid order by e.startedTs asc") .setParameter("sid", userSessionId) ); return dataManager.loadList(loadContext); }); }
@Override public SessionLogEntry getLastSessionLogRecord(UUID userSessionId) { return authentication.withSystemUser(() -> { LoadContext<SessionLogEntry> loadContext = LoadContext.create(SessionLogEntry.class) .setView(SessionLogEntry.DEFAULT_VIEW) .setQuery( createQuery("select e from sec$SessionLogEntry e where e.sessionId = :sid order by e.startedTs desc") .setParameter("sid", userSessionId) .setMaxResults(1) ); return dataManager.load(loadContext); }); }
/** * Set <code>finishedTs</code> to all sessions that were interrupted by server reboot */ protected void closeDeadSessionsOnStartup() { if (!globalConfig.getUserSessionLogEnabled()) { return; } if (clusterManager.isMaster()) { authentication.withSystemUser(() -> { LoadContext<SessionLogEntry> lc = LoadContext.create(SessionLogEntry.class).setView(SessionLogEntry.DEFAULT_VIEW) .setQuery(createQuery("select e from sec$SessionLogEntry e where e.finishedTs is null")); List<SessionLogEntry> sessionLogEntries = dataManager.loadList(lc); CommitContext cc = new CommitContext(); Set<UUID> activeSessionsIds = userSessionsAPI.getUserSessionsStream() .map(UserSession::getId) .collect(Collectors.toSet()); for (SessionLogEntry entry : sessionLogEntries) { if (activeSessionsIds.contains(entry.getSessionId())) { continue; // do not touch active session records } entry.setFinishedTs(timeSource.currentTimestamp()); entry.setLastAction(SessionAction.EXPIRATION); cc.addInstanceToCommit(entry); } dataManager.commit(cc); log.info("Dead session records have been closed"); return null; }); } }
protected Dashboard loadDashboardByCode(String code) { LoadContext<PersistentDashboard> loadContext = LoadContext.create(PersistentDashboard.class) .setQuery(LoadContext.createQuery("select d from dashboard$PersistentDashboard d where d.code = :code") .setParameter("code", code)) .setView("_local"); PersistentDashboard entity = dataManager.load(loadContext); if (entity == null || entity.getDashboardModel() == null) { return null; } return jsonConverter.dashboardFromJson(entity.getDashboardModel()); }
protected void checkGlobalDefaultAndCloseEditor() { List<FilterEntity> otherDefaultFilters = dataManager.loadList(LoadContext.create(FilterEntity.class) .setQuery(LoadContext.createQuery("select f from sec$Filter f where f.globalDefault = true and " + "f.componentId = :componentId and " + "f.id <> :currentId ") .setParameter("componentId", filterEntity.getComponentId()) .setParameter("currentId", filterEntity.getId()))); if (!otherDefaultFilters.isEmpty()) { String otherFilterNamesStr = otherDefaultFilters.stream() .map(FilterEntity::getName) .collect(Collectors.joining(", ")); showOptionDialog(getMessage("filter.editor.anotherGlobalDefaultFilterFound.dialogTitle"), formatMessage("filter.editor.anotherGlobalDefaultFilterFound.dialogMessage", otherFilterNamesStr), MessageType.WARNING, new Action[]{ new DialogAction(DialogAction.Type.YES, Action.Status.PRIMARY).withHandler(e -> { otherDefaultFilters.forEach(otherDefaultFilter -> otherDefaultFilter.setGlobalDefault(false)); modifiedGlobalDefaultFilters = dataManager.commit(new CommitContext(otherDefaultFilters)); close(COMMIT_ACTION_ID, true); }), new DialogAction(DialogAction.Type.NO, Action.Status.NORMAL).withHandler(e -> { filterEntity.setGlobalDefault(false); close(COMMIT_ACTION_ID, true); }), }); } else { close(COMMIT_ACTION_ID, true); } }
if (BooleanUtils.isTrue(returnCount)) { LoadContext ctx = LoadContext.create(metaClass.getJavaClass()) .setQuery(LoadContext.createQuery(queryString).setParameters(queryParameters)); count = dataManager.getCount(ctx);
@Override public EntitySnapshot getLastEntitySnapshot(Entity entity) { checkCompositePrimaryKey(entity); MetaClass metaClass = extendedEntities.getOriginalOrThisMetaClass(entity.getMetaClass()); View view = metadata.getViewRepository().getView(EntitySnapshot.class, "entitySnapshot.browse"); LoadContext<EntitySnapshot> lx = LoadContext.create(EntitySnapshot.class).setQuery(LoadContext .createQuery(format("select e from sys$EntitySnapshot e where e.entityMetaClass = :metaClass and" + " e.entity.%s = :entityId order by e.snapshotDate desc", referenceToEntitySupport.getReferenceIdPropertyName(metaClass))) .setParameter("metaClass", metaClass.getName()) .setParameter("entityId", referenceToEntitySupport.getReferenceId(entity)) .setMaxResults(1)) .setView(view); return dataManager.load(lx); }
LoadContext.createQuery(String.format("select e from %s e where e.%s = :entityId", metaClass.getName(), referenceToEntitySupport.getPrimaryKeyForLoadingEntity(metaClass)))
context.setQuery(LoadContext.createQuery(null));