From e53f998d0d14b04792e7fae56f2097349a70b409 Mon Sep 17 00:00:00 2001 From: Abhi Bavishi Date: Mon, 15 Jun 2015 18:38:38 +0530 Subject: [PATCH] Upading the pull request after code cleanup. --- .../baeldung/caching/config/myAppConfig.java | 2 +- .../baeldung/caching/example/Customer.java | 94 ++++++------------- .../caching/example/CustomerDataService.java | 15 +-- .../test/SpringCachingBehaviorTest.java | 15 ++- .../com/baeldung/multitenancy/MTConfig.java | 3 +- 5 files changed, 49 insertions(+), 80 deletions(-) diff --git a/spring-all/src/main/java/org/baeldung/caching/config/myAppConfig.java b/spring-all/src/main/java/org/baeldung/caching/config/myAppConfig.java index b5313c6eea..042e57bc35 100644 --- a/spring-all/src/main/java/org/baeldung/caching/config/myAppConfig.java +++ b/spring-all/src/main/java/org/baeldung/caching/config/myAppConfig.java @@ -2,7 +2,7 @@ @Configuration @EnableCaching -public class myAppConfig { +public class MyAppConfig { // Your configuration code goes here. diff --git a/spring-all/src/main/java/org/baeldung/caching/example/Customer.java b/spring-all/src/main/java/org/baeldung/caching/example/Customer.java index ee8c736141..c796cc9c60 100644 --- a/spring-all/src/main/java/org/baeldung/caching/example/Customer.java +++ b/spring-all/src/main/java/org/baeldung/caching/example/Customer.java @@ -1,74 +1,42 @@ -/** - * The Class Customer. - */ + public class Customer { - /** The id. */ - private int id; - /** The name. */ - private String name; - - /** The address. */ - private String customerAddress; - - Customer(String name, String address){ - this.name = name; - this.address = address; - } + private int id; - /** - * Gets the id. - * - * @return the id - */ - public int getId() { - return id; - } + private String name; - /** - * Sets the id. - * - * @param id the new id - */ - public void setId(int id) { - this.id = id; - } - /** - * Gets the name. - * - * @return the name - */ - public String getName() { - return name; - } + private String customerAddress; - /** - * Gets the address. - * - * @return the address - */ - public String getCustomerAddress() { - return this.customerAddress; - } + Customer(String name, String address){ + this.name = name; + this.customerAddress = address; + } - /** - * Sets the name. - * - * @param name the new name - */ - public void setName(String name) { - this.name = name; - } - /** - * Sets the address. - * - * @param name the new address - */ - public void setCustomerAddress(String address) { - this.customerAddress = this.name + "," + address; - } + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public String getCustomerAddress() { + return this.customerAddress; + } + + public void setName(String name) { + this.name = name; + } + + public void setCustomerAddress(String address) { + this.customerAddress = this.name + "," + address; + } } diff --git a/spring-all/src/main/java/org/baeldung/caching/example/CustomerDataService.java b/spring-all/src/main/java/org/baeldung/caching/example/CustomerDataService.java index e773cddec6..4c72d83245 100644 --- a/spring-all/src/main/java/org/baeldung/caching/example/CustomerDataService.java +++ b/spring-all/src/main/java/org/baeldung/caching/example/CustomerDataService.java @@ -18,7 +18,8 @@ public class CustomerDataService { CacheManager cacheManager; /** - * Gets the address. + * The method returns the customer's address, + only it doesn't find it the cache- addresses and directory. * * @param customer the customer * @return the address @@ -32,8 +33,9 @@ public class CustomerDataService { } /** - * Gets the address. - * + * The method returns the customer's address, + but refreshes all the entries in the cache to load new ones. + * * @param customer the customer * @return the address */ @@ -46,7 +48,8 @@ public class CustomerDataService { } /** - * Gets the address. + * The method returns the customer's address, + but not before selectively evicting the cache as per specified paramters. * * @param customer the customer * @return the address @@ -60,7 +63,7 @@ public class CustomerDataService { } /** - * Gets the address. + * The method uses the class level cache to look up for entries. * * @param customer the customer * @return the address @@ -74,7 +77,7 @@ public class CustomerDataService { } /** - * Gets the address. + * The method selectively caches the results that meet the predefined criteria. * * @param customer the customer * @return the address diff --git a/spring-all/src/main/java/org/baeldung/caching/test/SpringCachingBehaviorTest.java b/spring-all/src/main/java/org/baeldung/caching/test/SpringCachingBehaviorTest.java index 5097177803..259f7719eb 100644 --- a/spring-all/src/main/java/org/baeldung/caching/test/SpringCachingBehaviorTest.java +++ b/spring-all/src/main/java/org/baeldung/caching/test/SpringCachingBehaviorTest.java @@ -6,26 +6,23 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.stereotype.Component; +import static org.junit.Assert.*; +import org.junit.Test; -/** - * The Class CustomerDataService. - */ @Component public class SpringCachingBehaviorTest { -/** - * The main method. - * - * @param args the arguments - */ - public static void main(String[] args) { + + @Test + public void testCaching() { @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext("config.xml"); example = context.getBean(CustomerDataService.class); Customer cust = new Customer("Tom", "67-2, Downing Street, NY"); example.getAddress(cust); + fail("Unable to instantiate the CustomerDataService"); } } diff --git a/spring-all/src/main/java/org/baeldung/multi-tenancy/java/com/baeldung/multitenancy/MTConfig.java b/spring-all/src/main/java/org/baeldung/multi-tenancy/java/com/baeldung/multitenancy/MTConfig.java index 0d966acc4d..223d35bf5a 100644 --- a/spring-all/src/main/java/org/baeldung/multi-tenancy/java/com/baeldung/multitenancy/MTConfig.java +++ b/spring-all/src/main/java/org/baeldung/multi-tenancy/java/com/baeldung/multitenancy/MTConfig.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.sql.Connection; import java.sql.SQLException; import java.util.Map; +import org.apache.log4j.Logger; @@ -32,7 +33,7 @@ public class MTConfig { return sf; } catch (Throwable ex) { - System.err.println("Failed to load the SessionFactory: " + ex); + logger.error("Failed to load the SessionFactory: " , ex); throw new ExceptionInInitializerError(ex); }