Change method name from getNullableById to getByIdOfNullable in CrudService

pull/98/head
johnniang 2019-02-20 18:01:15 +08:00
parent 99914cdeca
commit b66637a6c8
4 changed files with 16 additions and 25 deletions

View File

@ -96,7 +96,7 @@ public abstract class AbstractCrudService<DOMAIN, ID> implements CrudService<DOM
} }
@Override @Override
public DOMAIN getNullableById(ID id) { public DOMAIN getByIdOfNullable(ID id) {
return fetchById(id).orElse(null); return fetchById(id).orElse(null);
} }

View File

@ -1,5 +1,6 @@
package cc.ryanc.halo.service.base; package cc.ryanc.halo.service.base;
import cc.ryanc.halo.exception.NotFoundException;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
@ -15,7 +16,6 @@ import java.util.Optional;
* *
* @param <DOMAIN> domain type * @param <DOMAIN> domain type
* @param <ID> id type * @param <ID> id type
*
* @author johnniang * @author johnniang
*/ */
public interface CrudService<DOMAIN, ID> { public interface CrudService<DOMAIN, ID> {
@ -33,7 +33,6 @@ public interface CrudService<DOMAIN, ID> {
* List all by sort * List all by sort
* *
* @param sort sort * @param sort sort
*
* @return List * @return List
*/ */
@NonNull @NonNull
@ -43,7 +42,6 @@ public interface CrudService<DOMAIN, ID> {
* List all by pageable * List all by pageable
* *
* @param pageable pageable * @param pageable pageable
*
* @return Page * @return Page
*/ */
@NonNull @NonNull
@ -53,7 +51,6 @@ public interface CrudService<DOMAIN, ID> {
* List all by ids * List all by ids
* *
* @param ids ids * @param ids ids
*
* @return List * @return List
*/ */
@NonNull @NonNull
@ -64,7 +61,6 @@ public interface CrudService<DOMAIN, ID> {
* *
* @param ids ids * @param ids ids
* @param sort sort * @param sort sort
*
* @return List * @return List
*/ */
@NonNull @NonNull
@ -74,7 +70,6 @@ public interface CrudService<DOMAIN, ID> {
* Fetch by id * Fetch by id
* *
* @param id id * @param id id
*
* @return Optional * @return Optional
*/ */
@NonNull @NonNull
@ -84,33 +79,34 @@ public interface CrudService<DOMAIN, ID> {
* Get by id * Get by id
* *
* @param id id * @param id id
*
* @return DOMAIN * @return DOMAIN
* @throws NotFoundException If the specified id does not exist
*/ */
@NonNull @NonNull
DOMAIN getById(@NonNull ID id); DOMAIN getById(@NonNull ID id);
/** /**
* Get nullable by id * Gets domain of nullable by id.
* *
* @param id id * @param id id
*
* @return DOMAIN * @return DOMAIN
*/ */
@Nullable @Nullable
DOMAIN getNullableById(@NonNull ID id); DOMAIN getByIdOfNullable(@NonNull ID id);
/** /**
* @param id id * Exists by id.
* *
* @param id id
* @return boolean * @return boolean
*/ */
boolean existsById(@NonNull ID id); boolean existsById(@NonNull ID id);
/** /**
* exist by id * Must exist by id, or throw NotFoundException.
* *
* @param id id * @param id id
* @throws NotFoundException If the specified id does not exist
*/ */
void mustExistById(@NonNull ID id); void mustExistById(@NonNull ID id);
@ -125,7 +121,6 @@ public interface CrudService<DOMAIN, ID> {
* save by domain * save by domain
* *
* @param domain domain * @param domain domain
*
* @return DOMAIN * @return DOMAIN
*/ */
@NonNull @NonNull
@ -135,47 +130,43 @@ public interface CrudService<DOMAIN, ID> {
* save by domains * save by domains
* *
* @param domains domains * @param domains domains
*
* @return List * @return List
*/ */
@NonNull @NonNull
List<DOMAIN> createInBatch(@NonNull Collection<DOMAIN> domains); List<DOMAIN> createInBatch(@NonNull Collection<DOMAIN> domains);
/** /**
* Update by domain * Updates by domain
* *
* @param domain domain * @param domain domain
*
* @return DOMAIN * @return DOMAIN
*/ */
@NonNull @NonNull
DOMAIN update(@NonNull DOMAIN domain); DOMAIN update(@NonNull DOMAIN domain);
/** /**
* Update by domains * Updates by domains
* *
* @param domains domains * @param domains domains
*
* @return List * @return List
*/ */
@NonNull @NonNull
List<DOMAIN> updateInBatch(@NonNull Collection<DOMAIN> domains); List<DOMAIN> updateInBatch(@NonNull Collection<DOMAIN> domains);
/** /**
* Remove by id * Removes by id
* *
* @param id id * @param id id
*
* @return DOMAIN * @return DOMAIN
* @throws NotFoundException If the specified id does not exist
*/ */
@NonNull @NonNull
DOMAIN removeById(@NonNull ID id); DOMAIN removeById(@NonNull ID id);
/** /**
* Remove by id * Removes by id if present.
* *
* @param id id * @param id id
*
* @return DOMAIN * @return DOMAIN
*/ */
@Nullable @Nullable

View File

@ -117,7 +117,7 @@ public class OptionsServiceImpl extends AbstractCrudService<Options, String> imp
*/ */
@Override @Override
public String findOneOption(String key) { public String findOneOption(String key) {
// final Options options = getNullableById(key); // final Options options = getByIdOfNullable(key);
// if (null != options) { // if (null != options) {
// return options.getOptionValue(); // return options.getOptionValue();
// } // }

View File

@ -21,7 +21,7 @@ public class PostSyncTask {
final PostService postService = SpringUtil.getBean(PostService.class); final PostService postService = SpringUtil.getBean(PostService.class);
int count = 0; int count = 0;
for (Long key : POSTS_VIEWS.keySet()) { for (Long key : POSTS_VIEWS.keySet()) {
Post post = postService.getNullableById(key); Post post = postService.getByIdOfNullable(key);
if (null != post) { if (null != post) {
post.setPostViews(post.getPostViews() + POSTS_VIEWS.get(key)); post.setPostViews(post.getPostViews() + POSTS_VIEWS.get(key));
postService.create(post); postService.create(post);