/** * Creates a {@link SpringDataMongodbQuery}. * * @return */ private SpringDataMongodbQuery<T> createQuery() { return new SpringDataMongodbQuery<>(mongoOperations, typeInformation().getJavaType()); }
/** * @param entity */ private <S extends T> void doSave(S entity) { EntityInformation<Object, S> entityInformation = getEntityInformation(entity); if (entityInformation.isNew(entity)) { entityManager.persist(entity); } else { entityManager.merge(entity); } }
@Override public <S extends T> S save(S entity) { Assert.notNull(entity, "Entity must not be null!"); if (entityInformation.isNew(entity)) { return operations.insert(entity); } return operations.update(entityInformation.getRequiredId(entity), entity); }
@Override public <U extends T> U save(U entity) { ID id = this.entityInformation.getRequiredId(entity); this.template.put(id, entity); return entity; }
/** * Looks up the id of the given entity using one of the {@link org.synyx.hades.dao.orm.GenericDaoSupport.IdAware} * implementations of Hades. * * @param entity * @return */ private ID getId(T entity) { return information.getId(entity); }
@Override public Class<ID> getIdType() { return delegate.getIdType(); } }
@Override public <S extends T> S save(S entity) { Assert.notNull(entity, "Entity must not be null!"); if (entityInformation.isNew(entity)) { return operations.insert(entity); } return operations.update(entityInformation.getRequiredId(entity), entity); }
@Override public <U extends T> Iterable<U> saveAll(Iterable<U> entities) { Map<ID, U> entitiesToSave = new HashMap<>(); entities.forEach(entity -> entitiesToSave.put(this.entityInformation.getRequiredId(entity), entity)); this.template.putAll(entitiesToSave); return entitiesToSave.values(); }
@Override protected ID getId(S source) { return entityInformation.getId(source); }
public Class<ID> getIdType() { return delegate.getIdType(); } }
@Override public <S extends T> Optional<S> findOne(Example<S> example) { RedisOperationChain operationChain = createQuery(example); KeyValueQuery<RedisOperationChain> query = new KeyValueQuery<>(operationChain); Iterator<T> iterator = keyValueTemplate.find(query.limit(2), entityInformation.getJavaType()).iterator(); Optional result = Optional.empty(); if (iterator.hasNext()) { result = Optional.of((S) iterator.next()); if (iterator.hasNext()) { throw new IncorrectResultSizeDataAccessException(1); } } return result; }
@Override public <S extends T> S save(S entity) { Assert.notNull(entity, "Entity must not be null!"); if (entityInformation.isNew(entity)) { return operations.insert(entity); } return operations.update(entityInformation.getRequiredId(entity), entity); }
@Override public boolean isNew(T entity) { return delegate.isNew(entity); }
@Override public <U extends T> U save(U entity) { ID id = this.entityInformation.getRequiredId(entity); this.template.put(id, entity); return entity; }
public ID getId(T entity) { return delegate.getId(entity); }
/** * Returns the actual typed id. Looks up an available customly registered {@link PropertyEditor} from the * {@link PropertyEditorRegistry} before falling back on a {@link SimpleTypeConverter} to translate the {@link String} * id into the type one. * * @param idAsString * @return */ @SuppressWarnings("unchecked") private ID getId(String idAsString) { Class<ID> idClass = information.getIdType(); PropertyEditor idEditor = registry.findCustomEditor(idClass, null); if (idEditor != null) { idEditor.setAsText(idAsString); return (ID) idEditor.getValue(); } return new SimpleTypeConverter().convertIfNecessary(idAsString, idClass); }
@Override public <S extends T> Iterable<S> findAll(Example<S> example) { RedisOperationChain operationChain = createQuery(example); return (Iterable<S>) keyValueTemplate.find(new KeyValueQuery<>(operationChain), entityInformation.getJavaType()); }
public boolean isNew(T entity) { return delegate.isNew(entity); }
@Override public <U extends T> Iterable<U> saveAll(Iterable<U> entities) { Map<ID, U> entitiesToSave = new HashMap<>(); entities.forEach(entity -> entitiesToSave.put(this.entityInformation.getRequiredId(entity), entity)); this.template.putAll(entitiesToSave); return entitiesToSave.values(); }
@Nullable @Override public ID getId(T entity) { return delegate.getId(entity); }