summaryrefslogtreecommitdiff
path: root/spring-framework/07-user-jdbc-ds-transaction/src/main/java/com/example/fp/FinancialPlannerApp.java
diff options
context:
space:
mode:
authorKamal Wickramanayake <kamal@inbox.lk>2026-04-25 21:53:33 +0530
committerKamal Wickramanayake <kamal@inbox.lk>2026-04-25 21:53:33 +0530
commit4afcff940551079617e8f4116e52bb0ef9df7fcc (patch)
treecbaed6a2a53c7d032bfafaa38b94e4fc607f3e76 /spring-framework/07-user-jdbc-ds-transaction/src/main/java/com/example/fp/FinancialPlannerApp.java
parent7b08f1155e1cb8bf263c3570eeb119970407a037 (diff)
Added Spring Framework sample code
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.java45
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();
+ }
+
+}