@Override public void deleted(T item) { if (PersistenceHelper.isNew(item)) { itemsToCreate.remove(item); } else { itemsToDelete.add(item); } modified = true; }
@Override public void modified(T item) { if (PersistenceHelper.isNew(item)) { itemsToCreate.remove(item); itemsToCreate.add(item); } else { itemsToUpdate.remove(item); itemsToUpdate.add(item); } itemsToDelete.remove(item); modified = true; }
@Override @SuppressWarnings("unchecked") public <V> V getValue(String property) { if (DynamicAttributesUtils.isDynamicAttribute(property)) { if (PersistenceHelper.isNew(this) && dynamicAttributes == null) { dynamicAttributes = new HashMap<>(); } Preconditions.checkState(dynamicAttributes != null, "Dynamic attributes should be loaded explicitly"); CategoryAttributeValue categoryAttributeValue = dynamicAttributes.get(DynamicAttributesUtils.decodeAttributeCode(property)); if (categoryAttributeValue != null) { return (V) categoryAttributeValue.getValue(); } else { return null; } } else { return super.getValue(property); } }
@Override protected void postInit() { super.postInit(); if (!PersistenceHelper.isNew(getItem())) { substUser.setEditable(false); } }
@Override public boolean isGlobal(Presentation p) { p = getPresentation(p.getId()); return p != null && !PersistenceHelper.isNew(p) && p.getUser() == null; }
protected void initParentDsContextCommitListener() { getDsContext().addBeforeCommitListener(context -> { List<FileDescriptor> fileDescriptorsToCommit = new ArrayList<>(); Collection<Entity> commitInstances = context.getCommitInstances(); for (Entity commitInstance : commitInstances) { if (commitInstance instanceof ProcAttachment && PersistenceHelper.isNew(commitInstance)) { ProcAttachment procAttachment = (ProcAttachment) commitInstance; fileDescriptorsToCommit.add(procAttachment.getFile()); } } if (!fileDescriptorsToCommit.isEmpty()) { commitInstances.addAll(fileDescriptorsToCommit); context.setCommitInstances(commitInstances); } }); }
@Override public void add(Presentation p) { checkLoad(); presentations.put(p.getId(), p); if (PersistenceHelper.isNew(p)) { needToUpdate.add(p); if (BooleanUtils.isTrue(p.getDefault())) { def = p; } } firePresentationsSetChanged(); }
@Override protected boolean preCommit() { addCommitListeners(); if (PersistenceHelper.isNew(getItem())) { ((CollectionPropertyDatasourceImpl) treeDs).setModified(true); } return true; }
@Override public void remove(Presentation p) { checkLoad(); if (presentations.remove(p.getId()) != null) { if (PersistenceHelper.isNew(p)) { needToUpdate.remove(p); } else { needToUpdate.remove(p); needToRemove.add(p); } if (p.equals(def)) { def = null; } if (p.equals(current)) { current = null; } firePresentationsSetChanged(); } }
protected void __setItem(T item) { if (this.item != null) { detachListener(this.item); } if (item != null) { final MetaClass aClass = item.getMetaClass(); if (!aClass.equals(metaClass) && !metaClass.getDescendants().contains(aClass)) { throw new DevelopmentException(String.format("Invalid item metaClass '%s'", aClass), ParamsMap.of("datasource", getId(), "metaClass", aClass)); } attachListener(item); } this.item = item; this.modified = false; clearCommitLists(); if (item != null && PersistenceHelper.isNew(item)) { itemsToCreate.add(item); this.modified = true; } }
/** * Called by the framework to set an edited entity after creation of all components and datasources, and after * {@link #init(java.util.Map)}. * <p>Don't override this method in subclasses, use hooks {@link #initNewItem(com.haulmont.cuba.core.entity.Entity)} * and {@link #postInit()} instead.</p> * @param item entity instance */ @SuppressWarnings("unchecked") @Override public void setItem(Entity item) { if (PersistenceHelper.isNew(item)) { DatasourceImplementation parentDs = (DatasourceImplementation) getParentDs(); if (parentDs == null || !parentDs.getItemsToCreate().contains(item)) { initNewItem((T) item); } } setItemInternal(item); postInit(); }
private void evictEntity(Object entity) { if (entity != null && !PersistenceHelper.isNew(entity)) { EntityManagerFactory emf = persistence.getEntityManager().getDelegate().getEntityManagerFactory(); JpaCache cache = (JpaCache) emf.getCache(); cache.evict(entity, true); } } }
@Override protected boolean preCommit() { if (srcModel != null) { copyModel(); } else if (PersistenceHelper.isNew(getItem())) { String actModelId = modelService.createModel(getItem().getName()); getItem().setActModelId(actModelId); } return true; }
@Override protected void postInit() { if (!PersistenceHelper.isNew(getItem())) { parentField.setVisible(true); PickerField.LookupAction lookupAction = new PickerField.LookupAction(parentField); lookupAction.setLookupScreenParams(ParamsMap.of("exclude", getItem())); parentField.addAction(lookupAction); } } }
protected void subscribeCreateActionCloseHandler(CreateAction createAction) { createAction.setAfterWindowClosedHandler(((window, closeActionId) -> { if (!COMMIT_ACTION_ID.equals(closeActionId)) { Report newReport = (Report) ((Editor) window).getItem(); if (!PersistenceHelper.isNew(newReport)) { DataSupplier dataSupplier = getDsContext().getDataSupplier(); Report reloadedReport = dataSupplier.reload(newReport, reportDs.getView()); boolean modified = reportDs.isModified(); reportDs.addItem(reloadedReport); ((DatasourceImplementation) reportDs).setModified(modified); } } })); } }
@Override public <T extends Entity> T merge(T entity) { log.debug("merge {}", entity); if (PersistenceHelper.isManaged(entity)) return entity; String storeName = support.getStorageName(delegate.unwrap(UnitOfWork.class)); entityListenerMgr.fireListener(entity, EntityListenerType.BEFORE_ATTACH, storeName); if ((PersistenceHelper.isNew(entity) || !PersistenceHelper.isDetached(entity)) && entity.getId() != null) { // if a new instance is passed to merge(), we suppose it is persistent but "not detached" Entity destEntity = findOrCreate(entity.getClass(), entity.getId()); deepCopyIgnoringNulls(entity, destEntity, Sets.newIdentityHashSet()); //noinspection unchecked return (T) destEntity; } T merged = internalMerge(entity); support.registerInstance(merged, this); return merged; }
@Override public void setItem(Entity item) { super.setItem(item); boolean isNew = PersistenceHelper.isNew(fileDs.getItem()); if (isNew) { okBtn.setEnabled(false); uploadField.addFileUploadSucceedListener(new FileUploadListener()); uploadField.focus(); } else { uploadField.setVisible(false); nameField.focus(); } }
public void ready(SdbmtUserScreen<T> userScreen) { String tenantId = multiTenancyTools.getCurrentUserTenantId(); if (PersistenceHelper.isNew(userScreen.getUser())) { userScreen.getUser().setTenantId(tenantId); } if (tenantId != null) { userScreen.getTenantField().setVisible(false); return; //do not init tenant ID field if the current user is also a tenant } initTenantField(userScreen.getTenantField(), userScreen.getUser()); }
public PresentationEditor(Presentation presentation, HasPresentations component) { this.presentation = presentation; this.component = component; messages = AppBeans.get(Messages.NAME); sessionSource = AppBeans.get(UserSessionSource.NAME); isNew = PersistenceHelper.isNew(presentation); allowGlobalPresentations = sessionSource.getUserSession() .isSpecificPermitted("cuba.gui.presentations.global"); initLayout(); setWidthUndefined(); String titleMessageKey = isNew ? "PresentationsEditor.new" : "PresentationsEditor.edit"; setCaption(getMessage(titleMessageKey)); setModal(true); setResizable(false); }
@Override public void modifyItem(T item) { checkNotNullArgument(item, "item is null"); if (data.containsKey(item.getId())) { if (PersistenceHelper.isNew(item)) { Object existingItem = data.get(item.getId()); metadata.getTools().copy(item, (Instance) existingItem); modified((T) existingItem); } else { updateItem(item); modified(item); } } }