本文整理汇总了Java中org.springframework.data.domain.Persistable类的典型用法代码示例。如果您正苦于以下问题:Java Persistable类的具体用法?Java Persistable怎么用?Java Persistable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Persistable类属于org.springframework.data.domain包,在下文中一共展示了Persistable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: save
import org.springframework.data.domain.Persistable; //导入依赖的package包/类
@Override
@Transactional
public void save(T entity) {
Assert.notNull(entity, "Entity can not be null. [" + entity.getClass() + "]");
if (useCache()) {
if (entity instanceof Persistable && (null != ((Persistable) entity).getId())) {
evictCache(getBasic((ID) ((Persistable) entity).getId()));
} else {
evictCache(entity);
}
}
repository.save(entity);
if (useCache()) {
evictCache(entity);
}
}
示例2: saveIgnoreNull
import org.springframework.data.domain.Persistable; //导入依赖的package包/类
@Override
@Transactional
public void saveIgnoreNull(T entity) {
Assert.notNull(entity, "Entity can not be null. [" + entity.getClass() + "]");
if (useCache()) {
if (entity instanceof Persistable && (null != ((Persistable) entity).getId())) {
evictCache(getBasic((ID) ((Persistable) entity).getId()));
} else {
evictCache(entity);
}
}
repository.saveIgnoreNull(entity);
if (useCache()) {
evictCache(entity);
}
}
示例3: insert
import org.springframework.data.domain.Persistable; //导入依赖的package包/类
@Override
@Transactional
public void insert(T entity) {
Assert.notNull(entity, "Entity can not be null. [" + entity.getClass() + "]");
if (useCache()) {
if (entity instanceof Persistable && (null != ((Persistable) entity).getId())) {
evictCache(getBasic((ID) ((Persistable) entity).getId()));
} else {
evictCache(entity);
}
}
repository.insert(entity);
if (useCache()) {
evictCache(entity);
}
}
示例4: update
import org.springframework.data.domain.Persistable; //导入依赖的package包/类
@Override
@Transactional
public void update(T entity) {
Assert.notNull(entity, "Entity can not be null. [" + entity.getClass() + "]");
if (useCache()) {
if (entity instanceof Persistable && (null != ((Persistable) entity).getId())) {
evictCache(getBasic((ID) ((Persistable) entity).getId()));
} else {
evictCache(entity);
}
}
repository.update(entity);
if (useCache()) {
evictCache(entity);
}
}
示例5: updateIgnore
import org.springframework.data.domain.Persistable; //导入依赖的package包/类
@Override
@Transactional
public void updateIgnore(T entity) {
Assert.notNull(entity, "Entity can not be null. [" + entity.getClass() + "]");
if (useCache()) {
if (entity instanceof Persistable && (null != ((Persistable) entity).getId())) {
evictCache(getBasic((ID) ((Persistable) entity).getId()));
} else {
evictCache(entity);
}
}
repository.updateIgnoreNull(entity);
if (useCache()) {
evictCache(entity);
}
}
示例6: assertRelationIdNotChanged
import org.springframework.data.domain.Persistable; //导入依赖的package包/类
public static <T extends Persistable<? extends Serializable>, U extends Persistable<ID>, ID extends Serializable> void assertRelationIdNotChanged(
@Nonnull final T entity,
@Nonnull final Function<? super T, U> relationFunction,
@Nonnull final ID relationId) {
Objects.requireNonNull(entity, "entity is null");
Objects.requireNonNull(relationFunction, "relationAttribute is null");
Objects.requireNonNull(relationId, "relationId is null");
if (!entity.isNew()) {
final U relatedObject = relationFunction.apply(entity);
if (!Objects.equals(relationId, relatedObject.getId())) {
throw new CannotChangeAssociatedEntityException(String.format(
"%s: cannot change ID of related %s: %d -> %d",
entity.getClass().getSimpleName(), relatedObject.getClass().getSimpleName(),
relatedObject.getId(), relationId));
}
}
}
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:21,代码来源:CannotChangeAssociatedEntityException.java
示例7: execute
import org.springframework.data.domain.Persistable; //导入依赖的package包/类
/**
* Execute workflow transition for domains.
*
* @param executionContext ExecutionContext.
*/
@SuppressWarnings("unchecked")
@Override
public void execute(ExecutionContext executionContext) {
Assert.notNull(transitionIdExpression, "transitionIdExpression not set");
Assert.notNull(domainExpression, "domainExpression not set");
Object domain = executionContext.getExpressionExecutor()
.evaluate(executionContext, domainExpression);
String transitionId = executionContext.getExpressionExecutor()
.evaluate(executionContext, transitionIdExpression);
if (domain != null) {
if (domain instanceof Collection) {
Collection<Persistable<Long>> domains = (Collection<Persistable<Long>>) domain;
for (Persistable<Long> object : domains) {
transition(object, transitionId, executionContext);
}
} else {
transition((Persistable<Long>) domain, transitionId, executionContext);
}
}
}
示例8: transition
import org.springframework.data.domain.Persistable; //导入依赖的package包/类
private void transition(Persistable<Long> domain, String transitionId,
ExecutionContext executionContext) {
Assert.notNull(transitionId,
"transitionIdExpression has not evaluated to a valid transitionId");
ProcessToken token = tokenRepository.findByDomain(domain);
Assert.isTrue(domain == token.getDomainObject(),
"Loaded token should have same instance of domain as returned in expression 'domainExpression'.");
//Create a new parameters map to prevent contamination and initialise from executionContext parameters.
HashMap<String, Object> parameters = new HashMap<String, Object>(executionContext.getParameters());
workflowEnvironment.getService().executeTransition(token, transitionId, parameters);
tokenRepository.save(token);
}
示例9: load
import org.springframework.data.domain.Persistable; //导入依赖的package包/类
/**
* JAVADOC Method Level Comments
*
* @param type JAVADOC.
* @param id JAVADOC.
*
* @return JAVADOC.
*/
@SuppressWarnings("unchecked")
@Override
public Persistable<?extends Serializable> load(String type, Serializable id) {
Class<?> clazz = instanceFactory.getClassType(type);
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<?> cq = cb.createQuery(clazz);
Root<?> token = cq.from(clazz);
cq.where(cb.equal(token.get("id"), id));
try {
return (Persistable<?extends Serializable>) entityManager.createQuery(cq).getSingleResult();
} catch (Exception e) {
LOG.info("Oops", e);
return null;
}
}
示例10: create
import org.springframework.data.domain.Persistable; //导入依赖的package包/类
private void create(ProcessToken token) {
Assert.notNull(token, "token cannot be null");
Assert.isNull(token.getId(), "This must be a new token");
Assert.notNull(token.getDomainObject(), "token must have a domainObject");
if (token.getDomainObject().getId() == null) {
Persistable<?extends Serializable> domain = token.getDomainObject();
entityManager.persist(domain);
Assert.notNull(domain.getId(), "id must now be set on domainObject");
token.setDomainObject(domain);
} else {
entityManager.merge(token.getDomainObject());
}
// Now set id and type of domainObject on Token
token.setDomainObjectId(token.getDomainObject().getId());
BeanWrapper beanWrapper = new BeanWrapperImpl(token.getDomainObject());
token.setDomainObjectType((String) beanWrapper.getPropertyValue("applicationType"));
entityManager.persist(token);
}
示例11: process
import org.springframework.data.domain.Persistable; //导入依赖的package包/类
private Object process(AbstractElementDescriptor descriptor, ExecutionContext context) {
String application = (String) descriptor.get("application");
BeanWrapper beanWrapper = new BeanWrapperImpl(context.getToken().getDomainObject());
descriptor.put("domainType", beanWrapper.getPropertyValue("applicationType"));
Persistable<?> po = context.getToken().getDomainObject();
descriptor.put("domainId",
(po instanceof EntityDescriptor) ? ((EntityDescriptor) po).getRemoteId() : po.getId());
if (StringUtils.isEmpty(application)) {
throw new IllegalArgumentException("application is not specified");
// return testLocal(ced, executionContext);
}
return sendAndReceive(conversionService.convert(descriptor, ProcessElementDto.class),
context);
}
示例12: queryForObject
import org.springframework.data.domain.Persistable; //导入依赖的package包/类
public <T extends Persistable<NodeRef>> T queryForObject(final String query, final NodePropertiesMapper<T> mapper, final String language) throws IncorrectResultSizeException {
Assert.notNull(mapper);
Assert.hasText(query);
List<T> list = queryForList(query.toString(), mapper, 2, 0, 1, StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, language).getContent();
int size = list.size();
switch (size) {
case 0:
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("No result found. Returning null.");
}
return null;
case 1:
return list.get(0);
default:
LOGGER.error(IncorrectResultSizeException.DEFAULT_MESSAGE_ID, size);
throw new IncorrectResultSizeException(size);
}
}
示例13: createEntityInformation
import org.springframework.data.domain.Persistable; //导入依赖的package包/类
@SuppressWarnings({"rawtypes", "unchecked"})
protected static EntityInformation createEntityInformation(Class<?> entityType) {
if (Persistable.class.isAssignableFrom(entityType)) {
return new PersistableEntityInformation(entityType);
}
return new ReflectionEntityInformation(entityType);
}
示例14: serialize
import org.springframework.data.domain.Persistable; //导入依赖的package包/类
@Override
public void serialize(final Persistable<?> bean, final JsonGenerator generator, final SerializerProvider provider) throws IOException {
if (bean.getId() instanceof Number) {
// Numeric, but no decimal accepted
generator.writeNumber(((Number) bean.getId()).longValue());
} else {
// Consider ID as a String (not failsafe)
generator.writeString((String) bean.getId());
}
}
示例15: getEntityInformation
import org.springframework.data.domain.Persistable; //导入依赖的package包/类
public static <T, ID extends Serializable> MybatisEntityInformation<T, ID> getEntityInformation(MybatisMappingContext mappingContext,
AuditorAware<?> auditorAware,
AuditDateAware<?> auditDateAware,
Class<T> domainClass) {
Assert.notNull(domainClass);
PersistentEntity<T, ?> persistentEntity = (PersistentEntity<T, ?>) mappingContext.getPersistentEntity(domainClass);
if (Persistable.class.isAssignableFrom(domainClass)) {
return new MybatisPersistableEntityInformation(persistentEntity, auditorAware, auditDateAware, domainClass);
}
return new MybatisMetamodelEntityInformation<T, ID>(persistentEntity, auditorAware, auditDateAware, domainClass);
}