Fix issues in VALIDATE phase
This commit is contained in:
parent
dabe4d2022
commit
49039843e5
@ -23,9 +23,9 @@
|
||||
|
||||
package com.iluwatar.caching;
|
||||
|
||||
import com.iluwatar.caching.database.DbManager;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.iluwatar.caching.database.DbManager;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
@ -23,11 +23,11 @@
|
||||
|
||||
package com.iluwatar.caching;
|
||||
|
||||
import com.iluwatar.caching.database.DbManager;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.iluwatar.caching.database.DbManager;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
|
@ -29,6 +29,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
/**
|
||||
* Data structure/implementation of the application's cache. The data structure
|
||||
* consists of a hash table attached with a doubly linked-list. The linked-list
|
||||
@ -62,6 +63,7 @@ public class LruCache {
|
||||
|
||||
/**
|
||||
* Node definition.
|
||||
*
|
||||
* @param id String
|
||||
* @param account {@link UserAccount}
|
||||
*/
|
||||
@ -90,6 +92,7 @@ public class LruCache {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param cap Integer.
|
||||
*/
|
||||
public LruCache(final int cap) {
|
||||
@ -98,6 +101,7 @@ public class LruCache {
|
||||
|
||||
/**
|
||||
* Get user account.
|
||||
*
|
||||
* @param userId String
|
||||
* @return {@link UserAccount}
|
||||
*/
|
||||
@ -113,6 +117,7 @@ public class LruCache {
|
||||
|
||||
/**
|
||||
* Remove node from linked list.
|
||||
*
|
||||
* @param node {@link Node}
|
||||
*/
|
||||
public void remove(final Node node) {
|
||||
@ -130,6 +135,7 @@ public class LruCache {
|
||||
|
||||
/**
|
||||
* Move node to the front of the list.
|
||||
*
|
||||
* @param node {@link Node}
|
||||
*/
|
||||
public void setHead(final Node node) {
|
||||
@ -146,6 +152,7 @@ public class LruCache {
|
||||
|
||||
/**
|
||||
* Set user account.
|
||||
*
|
||||
* @param userAccount {@link UserAccount}
|
||||
* @param userId {@link String}
|
||||
*/
|
||||
@ -171,6 +178,7 @@ public class LruCache {
|
||||
|
||||
/**
|
||||
* Che if Cache cintains the userId.
|
||||
*
|
||||
* @param userId {@link String}
|
||||
* @return boolean
|
||||
*/
|
||||
@ -180,6 +188,7 @@ public class LruCache {
|
||||
|
||||
/**
|
||||
* Invalidate cache for user.
|
||||
*
|
||||
* @param userId {@link String}
|
||||
*/
|
||||
public void invalidate(final String userId) {
|
||||
@ -192,7 +201,7 @@ public class LruCache {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is cache full?
|
||||
* Check if the cache is full.
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isFull() {
|
||||
@ -201,6 +210,7 @@ public class LruCache {
|
||||
|
||||
/**
|
||||
* Get LRU data.
|
||||
*
|
||||
* @return {@link UserAccount}
|
||||
*/
|
||||
public UserAccount getLruData() {
|
||||
@ -218,6 +228,7 @@ public class LruCache {
|
||||
|
||||
/**
|
||||
* Returns cache data in list form.
|
||||
*
|
||||
* @return {@link List}
|
||||
*/
|
||||
public List<UserAccount> getCacheDataInListForm() {
|
||||
@ -232,6 +243,7 @@ public class LruCache {
|
||||
|
||||
/**
|
||||
* Set cache capacity.
|
||||
*
|
||||
* @param newCapacity int
|
||||
*/
|
||||
public void setCapacity(final int newCapacity) {
|
||||
|
@ -19,18 +19,21 @@ public interface DbManager {
|
||||
* @return {@link UserAccount}
|
||||
*/
|
||||
UserAccount readFromDb(String userId);
|
||||
|
||||
/**
|
||||
* Write to DB.
|
||||
* @param userAccount {@link UserAccount}
|
||||
* @return {@link UserAccount}
|
||||
*/
|
||||
UserAccount writeToDb(UserAccount userAccount);
|
||||
|
||||
/**
|
||||
* Update record.
|
||||
* @param userAccount {@link UserAccount}
|
||||
* @return {@link UserAccount}
|
||||
*/
|
||||
UserAccount updateDb(UserAccount userAccount);
|
||||
|
||||
/**
|
||||
* Update record or Insert if not exists.
|
||||
* @param userAccount {@link UserAccount}
|
||||
|
@ -1,5 +1,10 @@
|
||||
package com.iluwatar.caching.database;
|
||||
|
||||
import static com.iluwatar.caching.constants.CachingConstants.ADD_INFO;
|
||||
import static com.iluwatar.caching.constants.CachingConstants.USER_ACCOUNT;
|
||||
import static com.iluwatar.caching.constants.CachingConstants.USER_ID;
|
||||
import static com.iluwatar.caching.constants.CachingConstants.USER_NAME;
|
||||
|
||||
import com.iluwatar.caching.UserAccount;
|
||||
import com.iluwatar.caching.constants.CachingConstants;
|
||||
import com.mongodb.MongoClient;
|
||||
@ -7,11 +12,6 @@ import com.mongodb.client.MongoDatabase;
|
||||
import com.mongodb.client.model.UpdateOptions;
|
||||
import org.bson.Document;
|
||||
|
||||
import static com.iluwatar.caching.constants.CachingConstants.USER_NAME;
|
||||
import static com.iluwatar.caching.constants.CachingConstants.ADD_INFO;
|
||||
import static com.iluwatar.caching.constants.CachingConstants.USER_ID;
|
||||
import static com.iluwatar.caching.constants.CachingConstants.USER_ACCOUNT;
|
||||
|
||||
/**
|
||||
* Implementation of DatabaseManager.
|
||||
* implements base methods to work with MongoDb.
|
||||
@ -45,7 +45,7 @@ public class MongoDb implements DbManager {
|
||||
var iterable = db
|
||||
.getCollection(CachingConstants.USER_ACCOUNT)
|
||||
.find(new Document(USER_ID, userId));
|
||||
if (iterable.first()==null) {
|
||||
if (iterable.first() == null) {
|
||||
return null;
|
||||
}
|
||||
Document doc = iterable.first();
|
||||
|
@ -25,6 +25,7 @@ public class VirtualDb implements DbManager {
|
||||
|
||||
/**
|
||||
* Read from Db.
|
||||
*
|
||||
* @param userId {@link String}
|
||||
* @return {@link UserAccount}
|
||||
*/
|
||||
@ -38,6 +39,7 @@ public class VirtualDb implements DbManager {
|
||||
|
||||
/**
|
||||
* Write to DB.
|
||||
*
|
||||
* @param userAccount {@link UserAccount}
|
||||
* @return {@link UserAccount}
|
||||
*/
|
||||
@ -49,6 +51,7 @@ public class VirtualDb implements DbManager {
|
||||
|
||||
/**
|
||||
* Update reecord in DB.
|
||||
*
|
||||
* @param userAccount {@link UserAccount}
|
||||
* @return {@link UserAccount}
|
||||
*/
|
||||
@ -59,6 +62,7 @@ public class VirtualDb implements DbManager {
|
||||
|
||||
/**
|
||||
* Update.
|
||||
*
|
||||
* @param userAccount {@link UserAccount}
|
||||
* @return {@link UserAccount}
|
||||
*/
|
||||
|
@ -1,17 +1,14 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright © 2014-2021 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
Loading…
x
Reference in New Issue
Block a user