From 4afcff940551079617e8f4116e52bb0ef9df7fcc Mon Sep 17 00:00:00 2001 From: Kamal Wickramanayake Date: Sat, 25 Apr 2026 21:53:33 +0530 Subject: Added Spring Framework sample code --- .../java/com/example/fp/FinancialPlannerApp.java | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 spring-framework/07-user-jdbc-ds-transaction/src/main/java/com/example/fp/FinancialPlannerApp.java (limited to 'spring-framework/07-user-jdbc-ds-transaction/src/main/java/com/example/fp/FinancialPlannerApp.java') 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 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(); + } + +} -- cgit v1.2.3