Fix sonar issues

This commit is contained in:
Victor Zalevskii 2021-08-27 13:27:50 +03:00
parent aff7ef8782
commit dabe4d2022
5 changed files with 17 additions and 15 deletions

View File

@ -85,13 +85,14 @@ public class App {
// installed and socket connection is open). // installed and socket connection is open).
App app = new App(isDbMongo(args)); App app = new App(isDbMongo(args));
app.useReadAndWriteThroughStrategy(); app.useReadAndWriteThroughStrategy();
System.out.println("=============================================="); String splitLine = "==============================================";
LOGGER.info(splitLine);
app.useReadThroughAndWriteAroundStrategy(); app.useReadThroughAndWriteAroundStrategy();
System.out.println("=============================================="); LOGGER.info(splitLine);
app.useReadThroughAndWriteBehindStrategy(); app.useReadThroughAndWriteBehindStrategy();
System.out.println("=============================================="); LOGGER.info(splitLine);
app.useCacheAsideStategy(); app.useCacheAsideStategy();
System.out.println("=============================================="); LOGGER.info(splitLine);
} }
/** /**

View File

@ -26,6 +26,7 @@ package com.iluwatar.caching;
import java.util.Optional; import java.util.Optional;
import com.iluwatar.caching.database.DbManager; import com.iluwatar.caching.database.DbManager;
import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
/** /**
@ -37,11 +38,12 @@ import lombok.extern.slf4j.Slf4j;
* appropriate function in the CacheStore class. * appropriate function in the CacheStore class.
*/ */
@Slf4j @Slf4j
@Data
public class AppManager { public class AppManager {
/** /**
* Caching Policy. * Caching Policy.
*/ */
private static CachingPolicy cachingPolicy; private CachingPolicy cachingPolicy;
/** /**
* Database Manager. * Database Manager.
*/ */

View File

@ -43,11 +43,11 @@ public class CacheStore {
/** /**
* Lru cache see {@link LruCache}. * Lru cache see {@link LruCache}.
*/ */
private static LruCache cache; private LruCache cache;
/** /**
* DbManager. * DbManager.
*/ */
private DbManager dbManager; private final DbManager dbManager;
/** /**
* Cache Store. * Cache Store.

View File

@ -45,7 +45,7 @@ public class MongoDb implements DbManager {
var iterable = db var iterable = db
.getCollection(CachingConstants.USER_ACCOUNT) .getCollection(CachingConstants.USER_ACCOUNT)
.find(new Document(USER_ID, userId)); .find(new Document(USER_ID, userId));
if (iterable == null) { if (iterable.first()==null) {
return null; return null;
} }
Document doc = iterable.first(); Document doc = iterable.first();

View File

@ -13,14 +13,14 @@ public class VirtualDb implements DbManager {
/** /**
* Virtual DataBase. * Virtual DataBase.
*/ */
private Map<String, UserAccount> virtualDB; private Map<String, UserAccount> db;
/** /**
* Creates new HashMap. * Creates new HashMap.
*/ */
@Override @Override
public void connect() { public void connect() {
virtualDB = new HashMap<>(); db = new HashMap<>();
} }
/** /**
@ -30,8 +30,8 @@ public class VirtualDb implements DbManager {
*/ */
@Override @Override
public UserAccount readFromDb(final String userId) { public UserAccount readFromDb(final String userId) {
if (virtualDB.containsKey(userId)) { if (db.containsKey(userId)) {
return virtualDB.get(userId); return db.get(userId);
} }
return null; return null;
} }
@ -43,7 +43,7 @@ public class VirtualDb implements DbManager {
*/ */
@Override @Override
public UserAccount writeToDb(final UserAccount userAccount) { public UserAccount writeToDb(final UserAccount userAccount) {
virtualDB.put(userAccount.getUserId(), userAccount); db.put(userAccount.getUserId(), userAccount);
return userAccount; return userAccount;
} }
@ -54,8 +54,7 @@ public class VirtualDb implements DbManager {
*/ */
@Override @Override
public UserAccount updateDb(final UserAccount userAccount) { public UserAccount updateDb(final UserAccount userAccount) {
virtualDB.put(userAccount.getUserId(), userAccount); return writeToDb(userAccount);
return userAccount;
} }
/** /**