• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java PersistenceHelper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



PersistenceHelper类属于com.haulmont.cuba.core.global包,在下文中一共展示了PersistenceHelper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getCurrentPrice

import com.haulmont.cuba.core.global.PersistenceHelper; //导入依赖的package包/类
/**
 * Calculates the currentPrice value for the {@link Product} instance, considering {@link Product#rebates}
 * @return {@link BigDecimal} value representing the product price after rebates
 */
@MetaProperty
public BigDecimal getCurrentPrice() {
    if (msrp == null)
        return null;

    if (rebates != null && PersistenceHelper.isLoaded(this, "rebates")) {
        final Date now = new Date();
        BigDecimal totalRebate = rebates.stream()
                .filter(e ->
                        (e.rebateStart == null || now.after(e.rebateStart))
                        && (e.rebateEnd == null || now.before(e.rebateEnd))
                        && e.rebate != null
                )
                .map(ProductRebate::getRebate)
                .reduce(BigDecimal.ZERO, BigDecimal::add);
        return msrp.subtract(totalRebate);
    }
    return null;
}
 
开发者ID:aleksey-stukalov,项目名称:cuba-vision-clinic,代码行数:24,代码来源:Product.java


示例2: getDefaultTagsList

import com.haulmont.cuba.core.global.PersistenceHelper; //导入依赖的package包/类
@MetaProperty(related = {"defaultTags"})
public String getDefaultTagsList() {
    if (!PersistenceHelper.isLoaded(this, "defaultTags")) {
        return null;
    }

    if (defaultTags != null) {
        StringBuilder stringBuilder = new StringBuilder();
        for (Tag defaultTag : defaultTags) {
            stringBuilder.append(defaultTag.getInstanceName()).append(",");
        }
        return StringUtils.chop(stringBuilder.toString());
    }

    return "";
}
 
开发者ID:cuba-platform,项目名称:sample-timesheets,代码行数:17,代码来源:Task.java


示例3: getRequiredTagTypesList

import com.haulmont.cuba.core.global.PersistenceHelper; //导入依赖的package包/类
@MetaProperty(related = {"requiredTagTypes"})
public String getRequiredTagTypesList() {
    if (!PersistenceHelper.isLoaded(this, "requiredTagTypes")) {
        return null;
    }

    if (requiredTagTypes != null) {
        StringBuilder stringBuilder = new StringBuilder();
        for (TagType requiredTagType : requiredTagTypes) {
            stringBuilder.append(requiredTagType.getInstanceName()).append(",");
        }
        return StringUtils.chop(stringBuilder.toString());
    }

    return "";
}
 
开发者ID:cuba-platform,项目名称:sample-timesheets,代码行数:17,代码来源:Task.java


示例4: PresentationEditor

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


示例5: toString

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


示例6: isValid

import com.haulmont.cuba.core.global.PersistenceHelper; //导入依赖的package包/类
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
    try {
        if (value instanceof Entity) {
            PersistenceHelper.checkLoadedWithView((Entity) value, view);
        } else if (value instanceof Collection) {
            @SuppressWarnings("unchecked")
            Collection<Entity> entities = (Collection<Entity>) value;
            for (Entity entity : entities) {
                PersistenceHelper.checkLoadedWithView(entity, view);
            }
        }

        return true;
    } catch (IllegalArgumentException e) {
        LoggerFactory.getLogger(RequiredViewValidator.class)
                .debug("Failed validation of instance with required view: {}", e.getMessage());

        return false;
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:22,代码来源:RequiredViewValidator.java


示例7: clearPermissionsOnUser

import com.haulmont.cuba.core.global.PersistenceHelper; //导入依赖的package包/类
/**
 * INTERNAL
 */
public void clearPermissionsOnUser(UserSession session) {
    List<User> users = new ArrayList<>();
    users.add(session.getUser());
    if (session.getSubstitutedUser() != null) {
        users.add(session.getSubstitutedUser());
    }
    for (User user : users) {
        if (PersistenceHelper.isDetached(user) && user.getUserRoles() != null) {
            for (UserRole userRole : user.getUserRoles()) {
                Role role = userRole.getRole();
                if (userRole.getRole() != null && PersistenceHelper.isLoaded(role, "permissions")) {
                    userRole.getRole().setPermissions(null);
                }
            }
        }
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:21,代码来源:UserSessionManager.java


示例8: 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


示例9: 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


示例10: testCheckLoaded

import com.haulmont.cuba.core.global.PersistenceHelper; //导入依赖的package包/类
@Test
public void testCheckLoaded() {
    Server server = new Server();

    cont.persistence().runInTransaction((em) -> {
        em.persist(server);
    });

    View view = new View(Server.class).addProperty("name").addProperty("data")
            .setLoadPartialEntities(true);
    Server reloadedServer = cont.persistence().callInTransaction((em) -> {
        return em.find(Server.class, server.getId(), view);
    });

    PersistenceHelper.checkLoaded(reloadedServer, "name"); // fine

    try {
        PersistenceHelper.checkLoaded(reloadedServer, "data", "running");
        Assert.fail("Must throw exception");
    } catch (IllegalArgumentException e) {
        Assert.assertTrue(e.getMessage().contains("Server.running"));
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:24,代码来源:PersistenceHelperTest.java


示例11: testReloadSameTx

import com.haulmont.cuba.core.global.PersistenceHelper; //导入依赖的package包/类
@Test
public void testReloadSameTx() throws Exception {
    User originalUser, reloadedUser;

    View view = new View(User.class, false)
            .addProperty("name");

    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();

        originalUser = em.find(User.class, userId, view);
        assertNotNull(originalUser);
        reloadedUser = em.reload(originalUser, "user.edit");

        tx.commit();
    } finally {
        tx.end();
    }
    assertTrue(originalUser == reloadedUser);
    reloadedUser = reserialize(reloadedUser);
    assertNotNull(reloadedUser);
    assertNotNull(reloadedUser.getLogin());
    assertTrue(PersistenceHelper.isLoaded(reloadedUser, "userRoles"));
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:26,代码来源:EntityManagerTest.java


示例12: getSubTotal

import com.haulmont.cuba.core.global.PersistenceHelper; //导入依赖的package包/类
/**
 * Aggregates {@link InvoiceDetails#getSubTotal()} values for all invoice lines included in the invoice
 * @return {@link BigDecimal} value representing the invoice subtotal
 */
@MetaProperty
public BigDecimal getSubTotal() {
    if (details != null && PersistenceHelper.isLoaded(this, "details")) {
        return details.stream()
                .map(InvoiceDetails::getSubTotal)
                .filter(e -> e != null)
                .reduce(BigDecimal.ZERO, BigDecimal::add);
    }
    return null;
}
 
开发者ID:aleksey-stukalov,项目名称:cuba-vision-clinic,代码行数:15,代码来源:Invoices.java


示例13: 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


示例14: getOvertime

import com.haulmont.cuba.core.global.PersistenceHelper; //导入依赖的package包/类
@MetaProperty(related = {"user", "date"})
public Overtime getOvertime() {
    if (!PersistenceHelper.isLoaded(this, "user")
            || !PersistenceHelper.isLoaded(this, "date")) {
        return null;
    }

    return new Overtime(getUser(), getDate(), overtimeInHours);
}
 
开发者ID:cuba-platform,项目名称:sample-timesheets,代码行数:10,代码来源:TimeEntry.java


示例15: 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


示例16: 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


示例17: 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


示例18: 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


示例19: postInit

import com.haulmont.cuba.core.global.PersistenceHelper; //导入依赖的package包/类
@Override
protected void postInit() {
    setCaption(PersistenceHelper.isNew(getItem()) ?
            getMessage("createCaption") : formatMessage("editCaption", getItem().getName()));

    screensTabFrame.loadPermissions();
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:8,代码来源:RoleEditor.java


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EntityProviderReadProperties类代码示例发布时间:2022-05-22
下一篇:
Java XSSAPI类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap