Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4903984

Browse files
committed
Fix issues in VALIDATE phase
1 parentdabe4d2 commit4903984

File tree

9 files changed

+381
-365
lines changed

9 files changed

+381
-365
lines changed

‎caching/src/main/java/com/iluwatar/caching/App.java

Lines changed: 150 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -54,155 +54,155 @@
5454
*/
5555
@Slf4j
5656
publicclassApp {
57-
/**
58-
* Constant parameter name to use mongoDB.
59-
*/
60-
privatestaticfinalStringUSE_MONGO_DB ="--mongo";
61-
/**
62-
* Application manager.
63-
*/
64-
privatefinalAppManagerappManager;
65-
66-
/**
67-
* Constructor of current App.
68-
* @param isMongo boolean
69-
*/
70-
publicApp(finalbooleanisMongo) {
71-
DbManagerdbManager =DbManagerFactory.initDb(isMongo);
72-
appManager =newAppManager(dbManager);
73-
appManager.initDb();
74-
}
75-
76-
/**
77-
* Program entry point.
78-
*
79-
* @param args command line args
80-
*/
81-
publicstaticvoidmain(finalString[]args) {
82-
// VirtualDB (instead of MongoDB) was used in running the JUnit tests
83-
// and the App class to avoid Maven compilation errors. Set flag to
84-
// true to run the tests with MongoDB (provided that MongoDB is
85-
// installed and socket connection is open).
86-
Appapp =newApp(isDbMongo(args));
87-
app.useReadAndWriteThroughStrategy();
88-
StringsplitLine ="==============================================";
89-
LOGGER.info(splitLine);
90-
app.useReadThroughAndWriteAroundStrategy();
91-
LOGGER.info(splitLine);
92-
app.useReadThroughAndWriteBehindStrategy();
93-
LOGGER.info(splitLine);
94-
app.useCacheAsideStategy();
95-
LOGGER.info(splitLine);
96-
}
97-
98-
/**
99-
* Check the input parameters. if
100-
* @param args input params
101-
* @return true if there is "--mongo" parameter in arguments
102-
*/
103-
privatestaticbooleanisDbMongo(finalString[]args) {
104-
for (Stringarg :args) {
105-
if (arg.equals(USE_MONGO_DB)) {
106-
returntrue;
107-
}
108-
}
109-
returnfalse;
110-
}
111-
112-
/**
113-
* Read-through and write-through.
114-
*/
115-
publicvoiduseReadAndWriteThroughStrategy() {
116-
LOGGER.info("# CachingPolicy.THROUGH");
117-
appManager.initCachingPolicy(CachingPolicy.THROUGH);
118-
119-
varuserAccount1 =newUserAccount("001","John","He is a boy.");
120-
121-
appManager.save(userAccount1);
122-
LOGGER.info(appManager.printCacheContent());
123-
appManager.find("001");
124-
appManager.find("001");
125-
}
126-
127-
/**
128-
* Read-through and write-around.
129-
*/
130-
publicvoiduseReadThroughAndWriteAroundStrategy() {
131-
LOGGER.info("# CachingPolicy.AROUND");
132-
appManager.initCachingPolicy(CachingPolicy.AROUND);
133-
134-
varuserAccount2 =newUserAccount("002","Jane","She is a girl.");
135-
136-
appManager.save(userAccount2);
137-
LOGGER.info(appManager.printCacheContent());
138-
appManager.find("002");
139-
LOGGER.info(appManager.printCacheContent());
140-
userAccount2 =appManager.find("002");
141-
userAccount2.setUserName("Jane G.");
142-
appManager.save(userAccount2);
143-
LOGGER.info(appManager.printCacheContent());
144-
appManager.find("002");
145-
LOGGER.info(appManager.printCacheContent());
146-
appManager.find("002");
147-
}
148-
149-
/**
150-
* Read-through and write-behind.
151-
*/
152-
publicvoiduseReadThroughAndWriteBehindStrategy() {
153-
LOGGER.info("# CachingPolicy.BEHIND");
154-
appManager.initCachingPolicy(CachingPolicy.BEHIND);
155-
156-
varuserAccount3 =newUserAccount("003",
157-
"Adam",
158-
"He likes food.");
159-
varuserAccount4 =newUserAccount("004",
160-
"Rita",
161-
"She hates cats.");
162-
varuserAccount5 =newUserAccount("005",
163-
"Isaac",
164-
"He is allergic to mustard.");
165-
166-
appManager.save(userAccount3);
167-
appManager.save(userAccount4);
168-
appManager.save(userAccount5);
169-
LOGGER.info(appManager.printCacheContent());
170-
appManager.find("003");
171-
LOGGER.info(appManager.printCacheContent());
172-
UserAccountuserAccount6 =newUserAccount("006",
173-
"Yasha",
174-
"She is an only child.");
175-
appManager.save(userAccount6);
176-
LOGGER.info(appManager.printCacheContent());
177-
appManager.find("004");
178-
LOGGER.info(appManager.printCacheContent());
179-
}
180-
181-
/**
182-
* Cache-Aside.
183-
*/
184-
publicvoiduseCacheAsideStategy() {
185-
LOGGER.info("# CachingPolicy.ASIDE");
186-
appManager.initCachingPolicy(CachingPolicy.ASIDE);
187-
LOGGER.info(appManager.printCacheContent());
188-
189-
varuserAccount3 =newUserAccount("003",
190-
"Adam",
191-
"He likes food.");
192-
varuserAccount4 =newUserAccount("004",
193-
"Rita",
194-
"She hates cats.");
195-
varuserAccount5 =newUserAccount("005",
196-
"Isaac",
197-
"He is allergic to mustard.");
198-
appManager.save(userAccount3);
199-
appManager.save(userAccount4);
200-
appManager.save(userAccount5);
201-
202-
LOGGER.info(appManager.printCacheContent());
203-
appManager.find("003");
204-
LOGGER.info(appManager.printCacheContent());
205-
appManager.find("004");
206-
LOGGER.info(appManager.printCacheContent());
57+
/**
58+
* Constant parameter name to use mongoDB.
59+
*/
60+
privatestaticfinalStringUSE_MONGO_DB ="--mongo";
61+
/**
62+
* Application manager.
63+
*/
64+
privatefinalAppManagerappManager;
65+
66+
/**
67+
* Constructor of current App.
68+
* @param isMongo boolean
69+
*/
70+
publicApp(finalbooleanisMongo) {
71+
DbManagerdbManager =DbManagerFactory.initDb(isMongo);
72+
appManager =newAppManager(dbManager);
73+
appManager.initDb();
74+
}
75+
76+
/**
77+
* Program entry point.
78+
*
79+
* @param args command line args
80+
*/
81+
publicstaticvoidmain(finalString[]args) {
82+
// VirtualDB (instead of MongoDB) was used in running the JUnit tests
83+
// and the App class to avoid Maven compilation errors. Set flag to
84+
// true to run the tests with MongoDB (provided that MongoDB is
85+
// installed and socket connection is open).
86+
Appapp =newApp(isDbMongo(args));
87+
app.useReadAndWriteThroughStrategy();
88+
StringsplitLine ="==============================================";
89+
LOGGER.info(splitLine);
90+
app.useReadThroughAndWriteAroundStrategy();
91+
LOGGER.info(splitLine);
92+
app.useReadThroughAndWriteBehindStrategy();
93+
LOGGER.info(splitLine);
94+
app.useCacheAsideStategy();
95+
LOGGER.info(splitLine);
96+
}
97+
98+
/**
99+
* Check the input parameters. if
100+
* @param args input params
101+
* @return true if there is "--mongo" parameter in arguments
102+
*/
103+
privatestaticbooleanisDbMongo(finalString[]args) {
104+
for (Stringarg :args) {
105+
if (arg.equals(USE_MONGO_DB)) {
106+
returntrue;
107+
}
207108
}
109+
returnfalse;
110+
}
111+
112+
/**
113+
* Read-through and write-through.
114+
*/
115+
publicvoiduseReadAndWriteThroughStrategy() {
116+
LOGGER.info("# CachingPolicy.THROUGH");
117+
appManager.initCachingPolicy(CachingPolicy.THROUGH);
118+
119+
varuserAccount1 =newUserAccount("001","John","He is a boy.");
120+
121+
appManager.save(userAccount1);
122+
LOGGER.info(appManager.printCacheContent());
123+
appManager.find("001");
124+
appManager.find("001");
125+
}
126+
127+
/**
128+
* Read-through and write-around.
129+
*/
130+
publicvoiduseReadThroughAndWriteAroundStrategy() {
131+
LOGGER.info("# CachingPolicy.AROUND");
132+
appManager.initCachingPolicy(CachingPolicy.AROUND);
133+
134+
varuserAccount2 =newUserAccount("002","Jane","She is a girl.");
135+
136+
appManager.save(userAccount2);
137+
LOGGER.info(appManager.printCacheContent());
138+
appManager.find("002");
139+
LOGGER.info(appManager.printCacheContent());
140+
userAccount2 =appManager.find("002");
141+
userAccount2.setUserName("Jane G.");
142+
appManager.save(userAccount2);
143+
LOGGER.info(appManager.printCacheContent());
144+
appManager.find("002");
145+
LOGGER.info(appManager.printCacheContent());
146+
appManager.find("002");
147+
}
148+
149+
/**
150+
* Read-through and write-behind.
151+
*/
152+
publicvoiduseReadThroughAndWriteBehindStrategy() {
153+
LOGGER.info("# CachingPolicy.BEHIND");
154+
appManager.initCachingPolicy(CachingPolicy.BEHIND);
155+
156+
varuserAccount3 =newUserAccount("003",
157+
"Adam",
158+
"He likes food.");
159+
varuserAccount4 =newUserAccount("004",
160+
"Rita",
161+
"She hates cats.");
162+
varuserAccount5 =newUserAccount("005",
163+
"Isaac",
164+
"He is allergic to mustard.");
165+
166+
appManager.save(userAccount3);
167+
appManager.save(userAccount4);
168+
appManager.save(userAccount5);
169+
LOGGER.info(appManager.printCacheContent());
170+
appManager.find("003");
171+
LOGGER.info(appManager.printCacheContent());
172+
UserAccountuserAccount6 =newUserAccount("006",
173+
"Yasha",
174+
"She is an only child.");
175+
appManager.save(userAccount6);
176+
LOGGER.info(appManager.printCacheContent());
177+
appManager.find("004");
178+
LOGGER.info(appManager.printCacheContent());
179+
}
180+
181+
/**
182+
* Cache-Aside.
183+
*/
184+
publicvoiduseCacheAsideStategy() {
185+
LOGGER.info("# CachingPolicy.ASIDE");
186+
appManager.initCachingPolicy(CachingPolicy.ASIDE);
187+
LOGGER.info(appManager.printCacheContent());
188+
189+
varuserAccount3 =newUserAccount("003",
190+
"Adam",
191+
"He likes food.");
192+
varuserAccount4 =newUserAccount("004",
193+
"Rita",
194+
"She hates cats.");
195+
varuserAccount5 =newUserAccount("005",
196+
"Isaac",
197+
"He is allergic to mustard.");
198+
appManager.save(userAccount3);
199+
appManager.save(userAccount4);
200+
appManager.save(userAccount5);
201+
202+
LOGGER.info(appManager.printCacheContent());
203+
appManager.find("003");
204+
LOGGER.info(appManager.printCacheContent());
205+
appManager.find("004");
206+
LOGGER.info(appManager.printCacheContent());
207+
}
208208
}

‎caching/src/main/java/com/iluwatar/caching/AppManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424
packagecom.iluwatar.caching;
2525

26+
importcom.iluwatar.caching.database.DbManager;
2627
importjava.util.Optional;
2728

28-
importcom.iluwatar.caching.database.DbManager;
2929
importlombok.Data;
3030
importlombok.extern.slf4j.Slf4j;
3131

@@ -68,7 +68,7 @@ public AppManager(final DbManager newDbManager) {
6868
* to (temporarily) store the data/objects during runtime.
6969
*/
7070
publicvoidinitDb() {
71-
dbManager.connect();
71+
dbManager.connect();
7272
}
7373

7474
/**

‎caching/src/main/java/com/iluwatar/caching/CacheStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323

2424
packagecom.iluwatar.caching;
2525

26+
importcom.iluwatar.caching.database.DbManager;
2627
importjava.util.List;
2728
importjava.util.Optional;
2829
importjava.util.stream.Collectors;
2930

30-
importcom.iluwatar.caching.database.DbManager;
3131
importlombok.extern.slf4j.Slf4j;
3232

3333
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp