From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../Gerald Examples/src/examples/entity/intro/AccountClient.java | 1 + 1 file changed, 1 insertion(+) create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/AccountClient.java (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/AccountClient.java') diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/AccountClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/AccountClient.java new file mode 100644 index 0000000..ae85824 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/AccountClient.java @@ -0,0 +1 @@ +package examples.entity.intro; import java.util.Iterator; import java.util.List; import javax.naming.Context; import javax.naming.InitialContext; /** * Sample client code for an Account entity that is accessed through * a stateful session bean facade. */ public class AccountClient { public static void main(String[] args) { AccountInterface account = null; try { /* * Get a reference to the Account Session Object */ Context ctx = new InitialContext(System.getProperties()); account = (AccountInterface)ctx.lookup(AccountInterface.class.getName()); Bank bank = (Bank)ctx.lookup(Bank.class.getName()); /* * Let's find existing accounts in the bank... */ List accounts = bank.listAccounts(); /* * ... and print them to the screen */ System.out.println("--- Accounts in this bank ---"); for(Iterator iter = accounts.iterator(); iter.hasNext();) { System.out.println(iter.next()); } System.out.println("-----------------------------"); /* * Open the account */ account.open(4444); System.out.println("Initial Balance = " + account.getBalance()); /* * Deposit $100 into the account */ account.deposit(100); /* * Retrieve the resulting balance both from * the original and the local copy */ System.out.println("After depositing $100, the account balance is: $" + account.getBalance()); /* * Try to withdraw $150 */ System.out.println("Now trying to withdraw $150."); int withdrawn = account.withdraw(150); if(withdrawn != 150) System.out.println("No success..."); else System.out.println("Success, got the money!"); System.out.println("Finally, the account balance is: $" + account.getBalance()); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); } } } \ No newline at end of file -- cgit v1.2.3