@Test void update() { AccountEntity accountEntity = createNotExists(); accountEntity.setPassword("passWordUpdate"); iStorage.update(accountEntity); iStorage.remove(accountEntity.getId()); Assertions.assertEquals("passWordUpdate",iStorage.get(accountEntity.getAccount()).getPassword()); }
@Override @Transactional(rollbackFor = Exception.class) public void update(E entity) { PK id = entity.getId(); Preconditions.checkNotNull(id,"id不能为null"); CacheGetResult<E> cacheGetResult = cache.GET(id); if (cacheGetResult.isSuccess()){ E entityFromCache = cacheGetResult.getValue(); if (entityFromCache == null) { throw new EntityNotFoundException("数据库中不存在该实体，先create一下？"); } else { executeUpdate(entity); } }else { if (exists(entity.getId())){ executeUpdate(entity); }else { throw new EntityNotFoundException("数据库中不存在该实体，先create一下？"); } } }
StorageJetCache extends SimpleJpaRepository<E,PK> implements IStorage<PK,E> { @Override @Transactional(rollbackFor = Exception.class) public void update(E entity) { PK id = entity.getId(); Preconditions.checkNotNull(id,"id不能为null"); CacheGetResult<E> cacheGetResult = cache.GET(id); if (cacheGetResult.isSuccess()){ E entityFromCache = cacheGetResult.getValue(); if (entityFromCache == null) { throw new EntityNotFoundException("数据库中不存在该实体，先create一下？"); } else { executeUpdate(entity); } }else { if (exists(entity.getId())){ executeUpdate(entity); }else { throw new EntityNotFoundException("数据库中不存在该实体，先create一下？"); } } } }
StorageJetCache extends SimpleJpaRepository<E,PK> implements IStorage<PK,E> { @Override @Transactional(rollbackFor = Exception.class) public void update(E entity) { PK id = entity.getId(); Preconditions.checkNotNull(id,"id不能为null"); CacheGetResult<E> cacheGetResult = cache.GET(id); if (cacheGetResult.isSuccess()){ E entityFromCache = cacheGetResult.getValue(); if (entityFromCache == null) { throw new EntityNotFoundException("数据库中不存在该实体，先create一下？"); } else { executeUpdate(entity); } }else { if (exists(entity.getId())){ executeUpdate(entity); }else { throw new EntityNotFoundException("数据库中不存在该实体，先create一下？"); } } } StorageJetCache(JpaEntityInformation<E, ?> entityInformation, EntityManager entityManager); }
StorageJetCache extends SimpleJpaRepository<E,PK> implements IStorage<PK,E> { @Override @Transactional(rollbackFor = Exception.class) public void update(E entity) { PK id = entity.getId(); Preconditions.checkNotNull(id,"id不能为null"); CacheGetResult<E> cacheGetResult = cache.GET(id); if (cacheGetResult.isSuccess()){ E entityFromCache = cacheGetResult.getValue(); if (entityFromCache == null) { throw new EntityNotFoundException("数据库中不存在该实体，先create一下？"); } else { executeUpdate(entity); } }else { if (exists(entity.getId())){ executeUpdate(entity); }else { throw new EntityNotFoundException("数据库中不存在该实体，先create一下？"); } } } StorageJetCache(JpaEntityInformation<E, ?> entityInformation, EntityManager entityManager); @Override @Transactional(rollbackFor = Exception.class) E create(E entity); @Override @Transactional(rollbackFor = Exception.class) void update(E entity); @Override void mergeUpdate(E entity); @Override E get(PK id); @Override @Transactional(rollbackFor = Exception.class) E getOrCreate(PK id, EntityCreator<PK, E> entityCreator); @Override @Transactional(rollbackFor = Exception.class) E remove(PK id); void setDelay(int delay); void setProxy(IStorage<PK, E> proxy); void setCache(Cache<PK, E> cache); }
StorageJetCache extends SimpleJpaRepository<E,PK> implements IStorage<PK,E> { @Override @Transactional(rollbackFor = Exception.class) public void update(E entity) { PK id = entity.getId(); Preconditions.checkNotNull(id,"id不能为null"); CacheGetResult<E> cacheGetResult = cache.GET(id); if (cacheGetResult.isSuccess()){ E entityFromCache = cacheGetResult.getValue(); if (entityFromCache == null) { throw new EntityNotFoundException("数据库中不存在该实体，先create一下？"); } else { executeUpdate(entity); } }else { if (exists(entity.getId())){ executeUpdate(entity); }else { throw new EntityNotFoundException("数据库中不存在该实体，先create一下？"); } } } StorageJetCache(JpaEntityInformation<E, ?> entityInformation, EntityManager entityManager); @Override @Transactional(rollbackFor = Exception.class) E create(E entity); @Override @Transactional(rollbackFor = Exception.class) void update(E entity); @Override void mergeUpdate(E entity); @Override E get(PK id); @Override @Transactional(rollbackFor = Exception.class) E getOrCreate(PK id, EntityCreator<PK, E> entityCreator); @Override @Transactional(rollbackFor = Exception.class) E remove(PK id); void setDelay(int delay); void setProxy(IStorage<PK, E> proxy); void setCache(Cache<PK, E> cache);  }