Upading the pull request after code cleanup.

This commit is contained in:
Abhi Bavishi 2015-06-15 18:38:38 +05:30
parent 8a49637a14
commit e53f998d0d
5 changed files with 49 additions and 80 deletions

View File

@ -2,7 +2,7 @@
@Configuration @Configuration
@EnableCaching @EnableCaching
public class myAppConfig { public class MyAppConfig {
// Your configuration code goes here. // Your configuration code goes here.

View File

@ -1,74 +1,42 @@
/**
* The Class Customer.
*/
public class Customer { public class Customer {
/** The id. */
private int id;
/** The name. */ private int id;
private String name;
/** The address. */
private String customerAddress;
Customer(String name, String address){
this.name = name;
this.address = address;
}
/** private String name;
* Gets the id.
*
* @return the id
*/
public int getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(int id) {
this.id = id;
}
/** private String customerAddress;
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}
/** Customer(String name, String address){
* Gets the address. this.name = name;
* this.customerAddress = address;
* @return the address }
*/
public String getCustomerAddress() {
return this.customerAddress;
}
/**
* Sets the name.
*
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}
/** public int getId() {
* Sets the address. return id;
* }
* @param name the new address
*/ public void setId(int id) {
public void setCustomerAddress(String address) { this.id = id;
this.customerAddress = this.name + "," + address; }
}
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;
}
} }

View File

@ -18,7 +18,8 @@ public class CustomerDataService {
CacheManager cacheManager; 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 * @param customer the customer
* @return the address * @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 * @param customer the customer
* @return the address * @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 * @param customer the customer
* @return the address * @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 * @param customer the customer
* @return the address * @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 * @param customer the customer
* @return the address * @return the address

View File

@ -6,26 +6,23 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* The Class CustomerDataService.
*/
@Component @Component
public class SpringCachingBehaviorTest { public class SpringCachingBehaviorTest {
/**
* The main method. @Test
* public void testCaching() {
* @param args the arguments
*/
public static void main(String[] args) {
@SuppressWarnings("resource") @SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext("config.xml"); ApplicationContext context = new ClassPathXmlApplicationContext("config.xml");
example = context.getBean(CustomerDataService.class); example = context.getBean(CustomerDataService.class);
Customer cust = new Customer("Tom", "67-2, Downing Street, NY"); Customer cust = new Customer("Tom", "67-2, Downing Street, NY");
example.getAddress(cust); example.getAddress(cust);
fail("Unable to instantiate the CustomerDataService");
} }
} }

View File

@ -7,6 +7,7 @@ import java.io.IOException;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger;
@ -32,7 +33,7 @@ public class MTConfig {
return sf; return sf;
} catch (Throwable ex) { } catch (Throwable ex) {
System.err.println("Failed to load the SessionFactory: " + ex); logger.error("Failed to load the SessionFactory: " , ex);
throw new ExceptionInInitializerError(ex); throw new ExceptionInInitializerError(ex);
} }