Skip to content

Commit e53f998

Browse files
committed
Upading the pull request after code cleanup.
1 parent 8a49637 commit e53f998

File tree

5 files changed

+47
-78
lines changed

5 files changed

+47
-78
lines changed

spring-all/src/main/java/org/baeldung/caching/config/myAppConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@Configuration
33
@EnableCaching
44

5-
public class myAppConfig {
5+
public class MyAppConfig {
66

77
// Your configuration code goes here.
88

Lines changed: 29 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,42 @@
1-
/**
2-
* The Class Customer.
3-
*/
1+
42
public class Customer {
53

6-
/** The id. */
7-
private int id;
84

9-
/** The name. */
10-
private String name;
5+
private int id;
6+
7+
8+
private String name;
9+
1110

12-
/** The address. */
13-
private String customerAddress;
11+
private String customerAddress;
1412

15-
Customer(String name, String address){
16-
this.name = name;
17-
this.address = address;
18-
}
13+
Customer(String name, String address){
14+
this.name = name;
15+
this.customerAddress = address;
16+
}
1917

2018

21-
/**
22-
* Gets the id.
23-
*
24-
* @return the id
25-
*/
26-
public int getId() {
27-
return id;
28-
}
19+
public int getId() {
20+
return id;
21+
}
2922

30-
/**
31-
* Sets the id.
32-
*
33-
* @param id the new id
34-
*/
35-
public void setId(int id) {
36-
this.id = id;
37-
}
23+
public void setId(int id) {
24+
this.id = id;
25+
}
3826

39-
/**
40-
* Gets the name.
41-
*
42-
* @return the name
43-
*/
44-
public String getName() {
45-
return name;
46-
}
27+
public String getName() {
28+
return name;
29+
}
4730

48-
/**
49-
* Gets the address.
50-
*
51-
* @return the address
52-
*/
53-
public String getCustomerAddress() {
54-
return this.customerAddress;
55-
}
31+
public String getCustomerAddress() {
32+
return this.customerAddress;
33+
}
5634

57-
/**
58-
* Sets the name.
59-
*
60-
* @param name the new name
61-
*/
62-
public void setName(String name) {
63-
this.name = name;
64-
}
35+
public void setName(String name) {
36+
this.name = name;
37+
}
6538

66-
/**
67-
* Sets the address.
68-
*
69-
* @param name the new address
70-
*/
71-
public void setCustomerAddress(String address) {
72-
this.customerAddress = this.name + "," + address;
73-
}
39+
public void setCustomerAddress(String address) {
40+
this.customerAddress = this.name + "," + address;
41+
}
7442
}

spring-all/src/main/java/org/baeldung/caching/example/CustomerDataService.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public class CustomerDataService {
1818
CacheManager cacheManager;
1919

2020
/**
21-
* Gets the address.
21+
* The method returns the customer's address,
22+
only it doesn't find it the cache- addresses and directory.
2223
*
2324
* @param customer the customer
2425
* @return the address
@@ -32,8 +33,9 @@ public String getAddress1(Customer customer) {
3233
}
3334

3435
/**
35-
* Gets the address.
36-
*
36+
* The method returns the customer's address,
37+
but refreshes all the entries in the cache to load new ones.
38+
*
3739
* @param customer the customer
3840
* @return the address
3941
*/
@@ -46,7 +48,8 @@ public String getAddress2(Customer customer) {
4648
}
4749

4850
/**
49-
* Gets the address.
51+
* The method returns the customer's address,
52+
but not before selectively evicting the cache as per specified paramters.
5053
*
5154
* @param customer the customer
5255
* @return the address
@@ -60,7 +63,7 @@ public String getAddress3(Customer customer) {
6063
}
6164

6265
/**
63-
* Gets the address.
66+
* The method uses the class level cache to look up for entries.
6467
*
6568
* @param customer the customer
6669
* @return the address
@@ -74,7 +77,7 @@ public String getAddress4(Customer customer) {
7477
}
7578

7679
/**
77-
* Gets the address.
80+
* The method selectively caches the results that meet the predefined criteria.
7881
*
7982
* @param customer the customer
8083
* @return the address

spring-all/src/main/java/org/baeldung/caching/test/SpringCachingBehaviorTest.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,23 @@
66
import org.springframework.context.ApplicationContext;
77
import org.springframework.context.support.ClassPathXmlApplicationContext;
88
import org.springframework.stereotype.Component;
9+
import static org.junit.Assert.*;
10+
import org.junit.Test;
911

1012

1113

12-
/**
13-
* The Class CustomerDataService.
14-
*/
1514
@Component
1615

1716
public class SpringCachingBehaviorTest {
18-
/**
19-
* The main method.
20-
*
21-
* @param args the arguments
22-
*/
23-
public static void main(String[] args) {
17+
18+
@Test
19+
public void testCaching() {
2420
@SuppressWarnings("resource")
2521
ApplicationContext context = new ClassPathXmlApplicationContext("config.xml");
2622
example = context.getBean(CustomerDataService.class);
2723
Customer cust = new Customer("Tom", "67-2, Downing Street, NY");
2824
example.getAddress(cust);
25+
fail("Unable to instantiate the CustomerDataService");
2926
}
3027

3128
}

spring-all/src/main/java/org/baeldung/multi-tenancy/java/com/baeldung/multitenancy/MTConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.sql.Connection;
88
import java.sql.SQLException;
99
import java.util.Map;
10+
import org.apache.log4j.Logger;
1011

1112

1213

@@ -32,7 +33,7 @@ public SessionFactoryBean sessionFactory(Map<String, DataSource> dataSourceMap,
3233
return sf;
3334

3435
} catch (Throwable ex) {
35-
System.err.println("Failed to load the SessionFactory: " + ex);
36+
logger.error("Failed to load the SessionFactory: " , ex);
3637
throw new ExceptionInInitializerError(ex);
3738
}
3839

0 commit comments

Comments
 (0)