本文整理汇总了Java中com.haulmont.cuba.core.global.PersistenceHelper类的典型用法代码示例。如果您正苦于以下问题:Java PersistenceHelper类的具体用法?Java PersistenceHelper怎么用?Java PersistenceHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PersistenceHelper类属于com.haulmont.cuba.core.global包,在下文中一共展示了PersistenceHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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 "";
}
示例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 "";
}
示例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);
}
示例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();
}
示例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;
}
}
示例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);
}
}
}
}
}
示例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;
}
示例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;
}
示例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"));
}
}
示例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"));
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}