@Override public void deleted(T item) { if (PersistenceHelper.isNew(item)) { itemsToCreate.remove(item); } else { itemsToDelete.add(item); } modified = true; }
protected Object getValueExIgnoreUnfetched(Instance instance, String[] properties) { Object currentValue = null; Instance currentInstance = instance; for (String property : properties) { if (currentInstance == null) { break; } if (!PersistenceHelper.isLoaded(currentInstance, property)) { LoggerFactory.getLogger(WebAbstractTable.class) .warn("Ignored unfetched attribute {} of instance {} in Table cell", property, currentInstance); return null; } currentValue = currentInstance.getValue(property); if (currentValue == null) { break; } currentInstance = currentValue instanceof Instance ? (Instance) currentValue : null; } return currentValue; }
@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; }
if (commitInstance instanceof BaseGenericIdEntity && !isNewInstance(newInstanceIds, commitInstance) && !PersistenceHelper.isDetached(commitInstance)) { PersistenceHelper.makePatch((BaseGenericIdEntity) commitInstance); && !property.getRange().getCardinality().isMany() && !property.isReadOnly() && PersistenceHelper.isLoaded(entity, property.getName())) { refEntity = metadata.create(refEntity.getMetaClass()); ((BaseGenericIdEntity) refEntity).setId(refEntityId); PersistenceHelper.makeDetached((BaseGenericIdEntity) refEntity); ((AbstractInstance) entity).setValue(property.getName(), refEntity, false);
if (existingTemplate != null) { loadedTemplate.setVersion(existingTemplate.getVersion()); if (PersistenceHelper.isNew(loadedTemplate)) { PersistenceHelper.makeDetached(loadedTemplate);
if (!PersistenceHelper.isManaged(parent) && !PersistenceHelper.isDetached(parent)) throw new IllegalStateException("Unable to create GroupHierarchy. Commit parent group first."); if (PersistenceHelper.isDetached(parent)) parent = em.find(Group.class, parent.getId()); // refresh parent in case of detached
@Override public void remove(Entity entity) { log.debug("remove {}", entity); if (PersistenceHelper.isDetached(entity)) { entity = internalMerge(entity); } if (entity instanceof SoftDelete && softDeletion) { ((SoftDelete) entity).setDeleteTs(timeSource.currentTimestamp()); ((SoftDelete) entity).setDeletedBy(auditInfoProvider.getCurrentUserLogin()); } else { delegate.remove(entity); if (entity instanceof BaseGenericIdEntity) { BaseEntityInternalAccess.setRemoved((BaseGenericIdEntity) entity, true); } } }
if (!metaProperty.isReadOnly() && PersistenceHelper.isDetached(value) && !(value instanceof EmbeddableEntity)) { if (!optimizeForDetached || needReloading(e, propertyView)) { if (log.isTraceEnabled()) {
@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 public String toString() { MoreObjects.ToStringHelper builder = MoreObjects.toStringHelper("ScheduledTask") .omitNullValues() .addValue(id); String[] fields = new String[]{"beanName", "methodName", "className", "scriptName", "singleton", "period", "cron", "startDate"}; for (String field : fields) { if (PersistenceHelper.isLoaded(this, field)) { Object value = getValue(field); if (value instanceof Date) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); value = df.format(value); } builder.add(field, value); } } return builder.toString(); }
@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); } }
@MetaProperty public String getLocName() { if (PersistenceHelper.isLoaded(this, "procDefinition") && procDefinition != null && PersistenceHelper.isLoaded(procDefinition, "actId") && !Strings.isNullOrEmpty(procDefinition.getActId())) { ProcessMessagesService processMessagesService = AppBeans.get(ProcessMessagesService.class); String locName = processMessagesService.findMessage(procDefinition.getActId(), code); if (locName != null) return locName; } return name; } }
@Override public boolean isGlobal(Presentation p) { p = getPresentation(p.getId()); return p != null && !PersistenceHelper.isNew(p) && p.getUser() == null; }
protected void addSpecificSuggestions(SourceCodeEditor sender, String text, int cursorPosition, List<Suggestion> suggestions) { if (cursorPosition <= 0) return; int colonIdx = text.substring(0, cursorPosition).lastIndexOf(":"); if (colonIdx < 0) return; List<String> strings = new ArrayList<>(); strings.add(SESSION_PREFIX + "userGroupId"); strings.add(SESSION_PREFIX + "userId"); strings.add(SESSION_PREFIX + "userLogin"); if (PersistenceHelper.isLoaded(getItem(), "group") && getItem().getGroup() != null) { List<String> attributeNames = userManagementService.getSessionAttributeNames(getItem().getGroup().getId()); for (String name : attributeNames) { strings.add(SESSION_PREFIX + name); } } Collections.sort(strings); String entered = text.substring(colonIdx + 1, cursorPosition); for (String string : strings) { if (string.startsWith(entered)) { suggestions.add(new Suggestion(sender.getAutoCompleteSupport(), string, string.substring(entered.length()), "", cursorPosition, cursorPosition)); } } }
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); } }); }
protected void storeIndexFields(Report report) { if (PersistenceHelper.isLoaded(report, "xml")) { StringBuilder entityTypes = new StringBuilder(IDX_SEPARATOR); if (report.getInputParameters() != null) { for (ReportInputParameter parameter : report.getInputParameters()) { if (isNotBlank(parameter.getEntityMetaClass())) { entityTypes.append(parameter.getEntityMetaClass()) .append(IDX_SEPARATOR); } } } report.setInputEntityTypesIdx(entityTypes.length() > 1 ? entityTypes.toString() : null); StringBuilder screens = new StringBuilder(IDX_SEPARATOR); if (report.getReportScreens() != null) { for (ReportScreen reportScreen : report.getReportScreens()) { screens.append(reportScreen.getScreenId()) .append(IDX_SEPARATOR); } } report.setScreensIdx(screens.length() > 1 ? screens.toString() : null); StringBuilder roles = new StringBuilder(IDX_SEPARATOR); if (report.getRoles() != null) { for (Role role : report.getRoles()) { roles.append(role.getId().toString()) .append(IDX_SEPARATOR); } } report.setRolesIdx(roles.length() > 1 ? roles.toString() : null); } }
@Override protected void postInit() { super.postInit(); if (!PersistenceHelper.isNew(getItem())) { substUser.setEditable(false); } }
protected boolean propertyWritingAllowed(MetaProperty metaProperty, Entity entity) { return !"id".equals(metaProperty.getName()) && (DynamicAttributesUtils.isDynamicAttribute(metaProperty) || (entity instanceof AbstractNotPersistentEntity) || !metadataTools.isPersistent(metaProperty) || (metadataTools.isPersistent(metaProperty) && PersistenceHelper.isLoaded(entity, metaProperty.getName()))); }
@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(); } }