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


Java Persistable类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:hatunet,项目名称:spring-data-mybatis,代码行数:18,代码来源:AbstractCrudService.java

示例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);
    }
}
 
开发者ID:hatunet,项目名称:spring-data-mybatis,代码行数:18,代码来源:AbstractCrudService.java

示例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);
    }
}
 
开发者ID:hatunet,项目名称:spring-data-mybatis,代码行数:18,代码来源:AbstractCrudService.java

示例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);
    }
}
 
开发者ID:hatunet,项目名称:spring-data-mybatis,代码行数:18,代码来源:AbstractCrudService.java

示例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);
    }
}
 
开发者ID:hatunet,项目名称:spring-data-mybatis,代码行数:18,代码来源:AbstractCrudService.java

示例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);
        }
    }
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:29,代码来源:TransitionOperation.java

示例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);
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:18,代码来源:TransitionOperation.java

示例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;
    }
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:27,代码来源:DomainRepositoryImpl.java

示例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);
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:26,代码来源:TokenRepositoryImpl.java

示例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);
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:21,代码来源:MessagingProcessDriver.java

示例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);
  }
}
 
开发者ID:dgradecak,项目名称:alfresco-mvc,代码行数:20,代码来源:QueryTemplate.java

示例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);
}
 
开发者ID:rubasace,项目名称:spring-data-jdbc,代码行数:9,代码来源:BaseJdbcRepository.java

示例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());
	}
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:11,代码来源:ToIdSerializer.java

示例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);
}
 
开发者ID:hatunet,项目名称:spring-data-mybatis,代码行数:13,代码来源:MybatisEntityInformationSupport.java


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