/** * @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 boolean isNew(T entity) { return delegate.isNew(entity); }
public boolean isNew(T entity) { return delegate.isNew(entity); }
@Transactional @Override public <T> T save(Class<T> clazz, T entity) { EntityInformation<T, ?> entityInformation = getEntityInformation(clazz); if (entityInformation.isNew(entity)) { entityManager.persist(entity); return entity; } else { return 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 <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 <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); }
@Transactional public <S extends T> S save(S entity) { if (entityInformation == null) { this.entityInformation = this.entityInfo.getEntityInformation(entity.getClass(), em); } if (entityInformation.isNew(entity)) { BeanUtils.setFieldWithAnnotation(entity, VersionNumber.class, "1.0"); em.persist(entity); return entity; } Object id = getId(entity); if (id == null) return null; Authentication authentication = auth.getAuthentication(); Principal lockOwner = lockingService.lockOwner(id); if ((authentication == null || (authentication.isAuthenticated() == false) && lockOwner == null)) { return em.merge(entity); } else if (authentication != null && authentication.isAuthenticated() && (lockOwner == null || authentication.getName().equals(lockOwner.getName()))) { return em.merge(entity); } else { throw new LockOwnerException(format("entity not locked by you")); } }