本文整理了Java中com.haulmont.cuba.core.entity.Entity
类的一些代码示例,展示了Entity
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entity
类的具体详情如下:
包路径:com.haulmont.cuba.core.entity.Entity
类名称:Entity
[英]Interface to be implemented by domain model objects with identifiers.
[中]由具有标识符的域模型对象实现的接口。
代码示例来源:origin: com.haulmont.cuba/cuba-global
/**
* @param id id of an entity to be loaded
* @return this instance for chaining
*/
public LoadContext<E> setId(Object id) {
this.id = id instanceof Entity ? ((Entity) id).getId() : id; // for compatibility with legacy code relying on implicit conversions
return this;
}
代码示例来源:origin: com.haulmont.cuba/cuba-gui
@Override
protected Collection<EntitySnapshot> getEntities(Map<String, Object> params) {
if (entity != null) {
EntitySnapshotService snapshotService = AppBeans.get(EntitySnapshotService.NAME);
snapshots = snapshotService.getSnapshots(entity.getMetaClass(), entity.getId());
return snapshots;
}
return Collections.emptyList();
}
代码示例来源:origin: de.diedavids.cuba.entitysoftreference/entity-soft-reference-global
@Nonnull
@Override
public String format(@Nullable Object value) {
return ((Entity) value).getInstanceName();
}
代码示例来源:origin: com.haulmont.cuba/cuba-gui
protected void removeListeners(Entity entity) {
entity.removePropertyChangeListener(propertyChangeListener);
Map<String, EmbeddedPropertyChangeListener> listenerMap = embeddedPropertyListeners.get(entity);
if (listenerMap != null) {
for (Map.Entry<String, EmbeddedPropertyChangeListener> entry : listenerMap.entrySet()) {
Entity embedded = entity.getValue(entry.getKey());
if (embedded != null) {
embedded.removePropertyChangeListener(entry.getValue());
embedded.removePropertyChangeListener(propertyChangeListener);
}
}
embeddedPropertyListeners.remove(entity);
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
public static void setSecurityState(Entity entity, SecurityState securityState) {
Preconditions.checkNotNullArgument(entity, "Entity is null");
if (entity instanceof BaseGenericIdEntity) {
BaseGenericIdEntity baseGenericIdEntity = (BaseGenericIdEntity) entity;
baseGenericIdEntity.__securityState = securityState;
} else if (entity instanceof EmbeddableEntity) {
EmbeddableEntity embeddableEntity = (EmbeddableEntity) entity;
embeddableEntity.__securityState = securityState;
} else {
throw new IllegalArgumentException(String.format("Entity with type [%s] does not support security state", entity.getMetaClass().getName()));
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
protected Entity getReference(Entity entity, MetaProperty property) {
if (PersistenceHelper.isLoaded(entity, property.getName()))
return entity.getValue(property.getName());
else {
Query query = entityManager.createQuery(
"select e." + property.getName() + " from " + entity.getMetaClass().getName() + " e where e." + primaryKeyName + " = ?1");
query.setParameter(1, entity.getId());
Object refEntity = query.getFirstResult();
return (Entity) refEntity;
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-gui
/**
* Tries to initialize entity fields included in entity name pattern by default values
*
* @param entity instance
*/
protected void initNamePatternFields(Entity entity) {
Collection<MetaProperty> properties = metadata.getTools().getNamePatternProperties(entity.getMetaClass());
for (MetaProperty property : properties) {
if (entity.getValue(property.getName()) == null
&& property.getType() == MetaProperty.Type.DATATYPE) {
try {
entity.setValue(property.getName(), property.getJavaType().newInstance());
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException("Unable to set value of name pattern field", e);
}
}
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-gui
protected void setParentField(Entity item, String parentProperty, Entity parent) {
if (parentProperty != null && parent != null && item != null)
item.setValue(parentProperty, parent);
}
代码示例来源:origin: com.haulmont.cuba/cuba-gui
@Nullable
@Override
public E getParent(E item) {
Preconditions.checkNotNullArgument(item);
return item.getValue(hierarchyProperty);
}
}
代码示例来源:origin: de.diedavids.cuba.taggable/taggable-web
@Override
protected Collection<KeyValueEntity> getEntities(Map<String, Object> params) {
Tag tag = (Tag) params.get("tag");
Collection<Entity> entitiesWithTag = taggingService.getEntitiesWithTag(tag);
Collection<KeyValueEntity> result = new ArrayList<>();
for (Entity entity : entitiesWithTag) {
KeyValueEntity keyValueEntity = metadata.create(KeyValueEntity.class);
keyValueEntity.setMetaClass(entity.getMetaClass());
keyValueEntity.setValue("instanceName", entity.getInstanceName());
keyValueEntity.setValue("entity", entity);
result.add(keyValueEntity);
}
return result;
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-gui
@Override
public String apply(Object o) {
if (!(o instanceof Entity)) {
return "";
}
Entity entity = (Entity) o;
if (captionMode == CaptionMode.PROPERTY
&& captionProperty != null) {
if (entity.getMetaClass().getPropertyPath(captionProperty) == null) {
throw new IllegalArgumentException(String.format("Couldn't find property with name '%s'", captionProperty));
}
Object propertyValue = entity.getValueEx(captionProperty);
return propertyValue != null
? propertyValue.toString()
: " ";
}
return metadata.getTools().getInstanceName(entity);
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
protected void checkRequiredAttributes(Entity entity) {
SecurityState securityState = getSecurityState(entity);
if (securityState != null && !securityState.getRequiredAttributes().isEmpty()) {
for (MetaProperty metaProperty : entity.getMetaClass().getProperties()) {
String propertyName = metaProperty.getName();
if (BaseEntityInternalAccess.isRequired(securityState, propertyName) && entity.getValue(propertyName) == null) {
throw new RowLevelSecurityException(format("Attribute [%s] is required for entity %s", propertyName, entity),
entity.getMetaClass().getName());
}
}
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-web
@Override
public T apply(E entity) {
return propertyPath != null
? entity.getValueEx(propertyPath)
: null;
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
protected void importReference(Entity srcEntity,
Entity dstEntity,
EntityImportViewProperty importViewProperty,
View regularView,
CommitContext commitContext,
Collection<ReferenceInfo> referenceInfoList,
boolean optimisticLocking) {
Entity srcPropertyValue = srcEntity.getValue(importViewProperty.getName());
Entity dstPropertyValue = dstEntity.getValue(importViewProperty.getName());
if (importViewProperty.getView() == null) {
ReferenceInfo referenceInfo = new ReferenceInfo(dstEntity, null, importViewProperty, srcPropertyValue, dstPropertyValue);
referenceInfoList.add(referenceInfo);
} else {
dstPropertyValue = importEntity(srcPropertyValue, dstPropertyValue, importViewProperty.getView(), regularView, commitContext, referenceInfoList, optimisticLocking);
dstEntity.setValue(importViewProperty.getName(), dstPropertyValue);
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-gui
protected Object getValueByProperty(T item, MetaPropertyPath property) {
Preconditions.checkNotNullArgument(item);
if (property.getMetaProperties().length == 1) {
return item.getValue(property.getMetaProperty().getName());
} else {
return item.getValueEx(property);
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
protected void checkCompositePrimaryKey(Entity entity) {
if (metadata.getTools().hasCompositePrimaryKey(entity.getMetaClass()) && !(entity instanceof HasUuid)) {
throw new UnsupportedOperationException(format("Entity %s has no persistent UUID attribute", entity));
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-rest-api
protected void setField(Entity bean, String field, Object value)
throws IllegalAccessException, InvocationTargetException, IntrospectionException {
bean.setValue(field, value);
}
代码示例来源:origin: com.haulmont.cuba/cuba-gui
@Override
public boolean hasChildren(E item) {
return container.getItems().stream().anyMatch(it -> {
E parentItem = it.getValue(hierarchyProperty);
return parentItem != null && parentItem.equals(item);
});
}
代码示例来源:origin: com.haulmont.cuba/cuba-gui
@Override
public V getValue() {
E item = datasource.getItem();
if (item != null) {
return item.getValueEx(metaPropertyPath);
}
return null;
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
private void loadOne(EntityCrossDataStoreProperty entityCrossDataStoreProperty) {
Entity entity = entityCrossDataStoreProperty.entity;
CrossDataStoreProperty aProp = entityCrossDataStoreProperty.crossProp;
Object id = entity.getValue(aProp.relatedPropertyName);
LoadContext<Entity> loadContext = new LoadContext<>(aProp.property.getRange().asClass());
loadContext.setId(id);
if (aProp.viewProperty.getView() != null)
loadContext.setView(aProp.viewProperty.getView());
loadContext.setJoinTransaction(joinTransaction);
Entity relatedEntity = dataManager.load(loadContext);
entity.setValue(aProp.property.getName(), relatedEntity);
}
内容来源于网络,如有侵权,请联系作者删除!