diff options
Diffstat (limited to 'spring-framework/07-user-jdbc-ds-transaction/src/main/java/com/example/fp/FinancialPlannerApp.java')
| -rw-r--r-- | spring-framework/07-user-jdbc-ds-transaction/src/main/java/com/example/fp/FinancialPlannerApp.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/spring-framework/07-user-jdbc-ds-transaction/src/main/java/com/example/fp/FinancialPlannerApp.java b/spring-framework/07-user-jdbc-ds-transaction/src/main/java/com/example/fp/FinancialPlannerApp.java new file mode 100644 index 0000000..24b4675 --- /dev/null +++ b/spring-framework/07-user-jdbc-ds-transaction/src/main/java/com/example/fp/FinancialPlannerApp.java @@ -0,0 +1,45 @@ +package com.example.fp; + +import java.util.List; + +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class FinancialPlannerApp { + + /** + * @param args + */ + public static void main(String[] args) { + + AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {"classpath:META-INF/spring/applicationContext.xml"}); + + // Register a shutdown hook with the JVM runtime, closing this context on JVM shutdown unless it has already been closed at that time. + // Delegates to doClose() for the actual closing procedure. + // This will trigger the destroy-method of the DataSource in our application (for example, in case of unexpected JVM shutdown). + ctx.registerShutdownHook(); + + UserManager userManager = ctx.getBean("userManager", UserManager.class); + + // Create an account + System.out.println("Creating users..."); + + userManager.create(new User("Kamal", "Kamal Wickramanayake", "abc123", true)); + userManager.create(new User("Rajith", "Rajith Virajana", "abc123", true)); + userManager.create(new User("Uththama", "Uththama Yapa", "abc123", true)); + + List<User> users = userManager.findAll(); + + for (User user : users) { + System.out.println(user); + } + + User newUser = new User("Kamal2", "Kamal Wickramanayake", "abc123", true); + System.out.println(newUser); + userManager.create(newUser); + System.out.println(newUser); + + ctx.close(); + } + +} |
