org.springframework.data.domain.Persistable Java Examples
The following examples show how to use
org.springframework.data.domain.Persistable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArangoTemplate.java From spring-data with Apache License 2.0 | 6 votes |
@Override public <T> void upsert(final T value, final UpsertStrategy strategy) throws DataAccessException { final Class<? extends Object> entityClass = value.getClass(); final ArangoPersistentEntity<?> entity = getConverter().getMappingContext().getPersistentEntity(entityClass); final Object id = getDocumentKey(entity, value); if (id != null && (!(value instanceof Persistable) || !Persistable.class.cast(value).isNew())) { switch (strategy) { case UPDATE: update(id.toString(), value); break; case REPLACE: default: replace(id.toString(), value); break; } return; } insert(value); }
Example #2
Source File: ArangoTemplate.java From spring-data with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public <T> void upsert(final Iterable<T> value, final UpsertStrategy strategy) throws DataAccessException { final Optional<T> first = StreamSupport.stream(value.spliterator(), false).findFirst(); if (!first.isPresent()) { return; } final Class<T> entityClass = (Class<T>) first.get().getClass(); final ArangoPersistentEntity<?> entity = getConverter().getMappingContext().getPersistentEntity(entityClass); final Collection<T> withId = new ArrayList<>(); final Collection<T> withoutId = new ArrayList<>(); for (final T e : value) { final Object id = getDocumentKey(entity, e); if (id != null && (!(e instanceof Persistable) || !Persistable.class.cast(e).isNew())) { withId.add(e); continue; } withoutId.add(e); } if (!withoutId.isEmpty()) { insert(withoutId, entityClass); } if (!withId.isEmpty()) { switch (strategy) { case UPDATE: update(withId, entityClass); break; case REPLACE: default: replace(withId, entityClass); break; } } }
Example #3
Source File: MybatisPersistableEntityInformation.java From spring-data-mybatis with Apache License 2.0 | 5 votes |
public MybatisPersistableEntityInformation(Class<T> domainClass) { super(domainClass); Class<?> idClass = ResolvableType.forClass(Persistable.class, domainClass) .resolveGeneric(0); if (null == idClass) { throw new IllegalArgumentException(String .format("Could not resolve identifier type for %s!", domainClass)); } this.idClass = (Class<ID>) idClass; }
Example #4
Source File: MybatisEntityInformationSupport.java From spring-data-mybatis with Apache License 2.0 | 5 votes |
public static <T> MybatisEntityInformation<T, ?> getEntityInformation( Class<T> domainClass) { Assert.notNull(domainClass, "Domain class must not be null!"); if (Persistable.class.isAssignableFrom(domainClass)) { return new MybatisPersistableEntityInformation(domainClass); } return new MybatisReflectionEntityInformation<>(domainClass); }
Example #5
Source File: EbeanRepositoryFactory.java From spring-data-ebean with Apache License 2.0 | 2 votes |
/** * Callback to create a {@link EbeanRepository} instance with the given {@link EbeanServer} * * @param <T> * @param <ID> * @param ebeanServer * @return */ protected <T extends Persistable, ID extends Serializable> SimpleEbeanRepository<T, ID> getTargetRepository( RepositoryInformation information, EbeanServer ebeanServer) { return getTargetRepositoryViaReflection(information, information.getDomainType(), ebeanServer); }