当前位置: 首页>>代码示例>>Java>>正文


Java PersistenceHelper.isNew方法代码示例

本文整理汇总了Java中com.haulmont.cuba.core.global.PersistenceHelper.isNew方法的典型用法代码示例。如果您正苦于以下问题:Java PersistenceHelper.isNew方法的具体用法?Java PersistenceHelper.isNew怎么用?Java PersistenceHelper.isNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.haulmont.cuba.core.global.PersistenceHelper的用法示例。


在下文中一共展示了PersistenceHelper.isNew方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getOldValue

import com.haulmont.cuba.core.global.PersistenceHelper; //导入方法依赖的package包/类
/**
 * Returns an old value of an attribute changed in the current transaction. The entity must be in the Managed state.
 * @param entity    entity instance
 * @param attribute attribute name
 * @return  an old value stored in the database. For a new entity returns null.
 * @throws IllegalArgumentException if the entity is not persistent or not in the Managed state
 */
@Nullable
public Object getOldValue(Entity entity, String attribute) {
    Preconditions.checkNotNullArgument(entity, "entity is null");

    if (!(entity instanceof ChangeTracker) || !PersistenceHelper.isManaged(entity))
        throw new IllegalArgumentException("The entity " + entity + " is not a ChangeTracker");

    if (!PersistenceHelper.isManaged(entity))
        throw new IllegalArgumentException("The entity " + entity + " is not in the Managed state");

    if (PersistenceHelper.isNew(entity)) {
        return null;
    } else {
        ObjectChangeSet objectChanges =
                ((AttributeChangeListener)((ChangeTracker) entity)._persistence_getPropertyChangeListener()).getObjectChangeSet();
        if (objectChanges != null) { // can be null for example in AFTER_DELETE entity listener
            ChangeRecord changeRecord = objectChanges.getChangesForAttributeNamed(attribute);
            if (changeRecord != null)
                return changeRecord.getOldValue();
        }
    }
    return null;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:31,代码来源:PersistenceTools.java

示例2: getDirtyFields

import com.haulmont.cuba.core.global.PersistenceHelper; //导入方法依赖的package包/类
/**
 * Returns the set of dirty attributes (changed since the last load from the database).
 * <p> If the entity is new, returns all its attributes.
 * <p> If the entity is not persistent or not in the Managed state, returns empty set.
 *
 * @param entity    entity instance
 * @return          dirty attribute names
 * @see #isDirty(Entity, String...)
 */
public Set<String> getDirtyFields(Entity entity) {
    Preconditions.checkNotNullArgument(entity, "entity is null");

    if (!(entity instanceof ChangeTracker) || !PersistenceHelper.isManaged(entity))
        return Collections.emptySet();

    HashSet<String> result = new HashSet<>();
    if (PersistenceHelper.isNew(entity)) {
        for (MetaProperty property : metadata.getClassNN(entity.getClass()).getProperties()) {
            if (metadata.getTools().isPersistent(property))
                result.add(property.getName());
        }
    } else {
        PropertyChangeListener propertyChangeListener = ((ChangeTracker) entity)._persistence_getPropertyChangeListener();
        if (propertyChangeListener == null)
            throw new IllegalStateException("Entity '" + entity + "' is a ChangeTracker but has no PropertyChangeListener");
        ObjectChangeSet objectChanges = ((AttributeChangeListener) propertyChangeListener).getObjectChangeSet();
        if (objectChanges != null) // can be null for example in AFTER_DELETE entity listener
            result.addAll(objectChanges.getChangedAttributeNames());
    }
    return result;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:32,代码来源:PersistenceTools.java

示例3: hasTimeEntries

import com.haulmont.cuba.core.global.PersistenceHelper; //导入方法依赖的package包/类
public boolean hasTimeEntries() {
    for (DayOfWeek day : DayOfWeek.values()) {
        List<TimeEntry> timeEntries = getDayOfWeekTimeEntries(day);
        if (CollectionUtils.isNotEmpty(timeEntries)) {
            for (TimeEntry timeEntry : timeEntries) {
                if (PersistenceHelper.isNew(timeEntry)) {
                    return false;
                }
            }

            return true;
        }
    }
    return false;
}
 
开发者ID:cuba-platform,项目名称:sample-timesheets,代码行数:16,代码来源:WeeklyReportEntry.java

示例4: isDirty

import com.haulmont.cuba.core.global.PersistenceHelper; //导入方法依赖的package包/类
/**
 * Returns true if the given entity has dirty attributes (changed since the last load from the database).
 * <br> If the entity is new, returns true.
 * <br> If the entity is not persistent or not in the Managed state, returns false.
 *
 * @param entity    entity instance
 *
 * @see #getDirtyFields(Entity)
 * @see #isDirty(Entity, String...)
 */
public boolean isDirty(Entity entity) {
    Preconditions.checkNotNullArgument(entity, "entity is null");

    if (!(entity instanceof ChangeTracker) || !PersistenceHelper.isManaged(entity))
        return false;

    if (PersistenceHelper.isNew(entity))
        return true;

    AttributeChangeListener attributeChangeListener = (AttributeChangeListener) ((ChangeTracker) entity)._persistence_getPropertyChangeListener();
    return attributeChangeListener != null && attributeChangeListener.hasChanges();
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:23,代码来源:PersistenceTools.java

示例5: updateRejectionReasonField

import com.haulmont.cuba.core.global.PersistenceHelper; //导入方法依赖的package包/类
protected void updateRejectionReasonField() {
    rejectionReason.setEnabled(!userIsWorker());
    if (PersistenceHelper.isNew(getItem())
            || (userIsWorker() && getItem().getRejectionReason() == null)) {
        rejectionReason.setVisible(false);
    }
}
 
开发者ID:cuba-platform,项目名称:sample-timesheets,代码行数:8,代码来源:TimeEntryEdit.java

示例6: changeEntity

import com.haulmont.cuba.core.global.PersistenceHelper; //导入方法依赖的package包/类
private void changeEntity(Collection<Entity> managedEntities) {
    for (Object entity : managedEntities) {
        if (entity instanceof User && ((User) entity).getLogin().startsWith("TxLstnrTst-")) {
            User user = (User) entity;
            if (PersistenceHelper.isNew(user)) {
                assertEquals(user.getLogin().toLowerCase(), user.getLoginLowerCase()); // user listener has worked
                user.setName("set by tx listener");
            }
        }
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:12,代码来源:TestBeforeCommitTxListener.java

示例7: initMetaClass

import com.haulmont.cuba.core.global.PersistenceHelper; //导入方法依赖的package包/类
protected void initMetaClass(Entity entity) {
    if (!(entity instanceof BaseGenericIdEntity)) {
        throw new IllegalStateException("This datasource can contain only entity with subclass of BaseGenericIdEntity");
    }

    BaseGenericIdEntity baseGenericIdEntity = (BaseGenericIdEntity) entity;
    if (PersistenceHelper.isNew(baseGenericIdEntity) && baseGenericIdEntity.getDynamicAttributes() == null) {
        baseGenericIdEntity.setDynamicAttributes(new HashMap<>());
    }

    @SuppressWarnings("unchecked")
    Map<String, CategoryAttributeValue> dynamicAttributes = baseGenericIdEntity.getDynamicAttributes();
    Preconditions.checkNotNullArgument(dynamicAttributes, "Dynamic attributes should be loaded explicitly");

    if (baseGenericIdEntity instanceof Categorized) {
        category = ((Categorized) baseGenericIdEntity).getCategory();
    }
    if (!initializedBefore && category == null) {
        category = getDefaultCategory();
        if (baseGenericIdEntity.getMetaClass().getProperty("category") != null) {
            baseGenericIdEntity.setValue("category", category);
        }
    }

    item = new DynamicAttributesEntity(baseGenericIdEntity, attributes);
    if (PersistenceHelper.isNew(entity) || categoryChanged) {
        dynamicAttributesGuiTools.initDefaultAttributeValues(baseGenericIdEntity, resolveCategorizedEntityClass());
    }

    view = new View(DynamicAttributesEntity.class, false);
    Collection<MetaProperty> properties = metaClass.getProperties();
    for (MetaProperty property : properties) {
        view.addProperty(property.getName());
    }

    valid();
    initializedBefore = true;
    fireItemChanged(null);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:40,代码来源:RuntimePropsDatasourceImpl.java

示例8: modified

import com.haulmont.cuba.core.global.PersistenceHelper; //导入方法依赖的package包/类
@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;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:13,代码来源:AbstractDatasource.java

示例9: deleted

import com.haulmont.cuba.core.global.PersistenceHelper; //导入方法依赖的package包/类
@Override
public void deleted(T item) {
    if (PersistenceHelper.isNew(item)) {
        itemsToCreate.remove(item);
    } else {
        itemsToDelete.add(item);
    }
    modified = true;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:10,代码来源:AbstractDatasource.java

示例10: postInit

import com.haulmont.cuba.core.global.PersistenceHelper; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:10,代码来源:GroupEditor.java

示例11: postInit

import com.haulmont.cuba.core.global.PersistenceHelper; //导入方法依赖的package包/类
@Override
protected void postInit() {
    super.postInit();

    if (!PersistenceHelper.isNew(getItem())) {
        substUser.setEditable(false);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:9,代码来源:UserSubstitutionEditor.java

示例12: setItem

import com.haulmont.cuba.core.global.PersistenceHelper; //导入方法依赖的package包/类
@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.requestFocus();
    } else {
        uploadField.setVisible(false);
        nameField.requestFocus();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:16,代码来源:FileEditor.java

示例13: setItem

import com.haulmont.cuba.core.global.PersistenceHelper; //导入方法依赖的package包/类
/**
 * 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
 */
@Override
public void setItem(Entity item) {
    if (PersistenceHelper.isNew(item)) {
        DatasourceImplementation parentDs = (DatasourceImplementation) ((Editor) frame).getParentDs();
        if (parentDs == null || !parentDs.getItemsToCreate().contains(item)) {
            //noinspection unchecked
            initNewItem((T) item);
        }
    }
    ((Editor) frame).setItem(item);
    postInit();
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:20,代码来源:AbstractEditor.java

示例14: setUp

import com.haulmont.cuba.core.global.PersistenceHelper; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    addEntityPackage("com.haulmont.cuba");
    setViewConfig("/com/haulmont/cuba/gui/data/impl/testmodel1/test-views.xml");
    setupInfrastructure();

    metadataSession = metadata.getSession();
    dataService = new TestDataSupplier();

    dataService.commitCount = 0;

    new NonStrictExpectations() {
        {
            backgroundWorker.checkUIAccess(); result = null;
            AppBeans.get(BackgroundWorker.NAME); result = backgroundWorker;
            AppBeans.get(BackgroundWorker.class); result = backgroundWorker;
            AppBeans.get(BackgroundWorker.NAME, BackgroundWorker.class); result = backgroundWorker;

            configuration.getConfig(ClientConfig.class); result = clientConfig;

            clientConfig.getCollectionDatasourceDbSortEnabled(); result = true;

            persistenceManager.getMaxFetchUI(anyString); result = 10000;

            PersistenceHelper.isNew(any); result = false;
        }
    };
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:29,代码来源:DsContextApplyChangesTest.java

示例15: evictEntity

import com.haulmont.cuba.core.global.PersistenceHelper; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:8,代码来源:OrmCacheSupport.java


注:本文中的com.haulmont.cuba.core.global.PersistenceHelper.isNew方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。