diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..abb822c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+*/target
+*/.settings
+*/.classpath
+*/.project
+/nb-configuration.xml
+
+/target/*
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..01441d2
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,112 @@
+
+ 4.0.0
+
+ com.dariawan
+ BankOfJakarta
+ 1.0.0
+ jar
+
+ BankOfJakarta
+ http://maven.apache.org
+
+
+ 1.8
+ 1.8
+ 1.8
+ UTF-8
+ 1.2
+ 1.7.25
+ 1.2.3
+ 2.10.1
+ 2.5.0
+ 42.2.5
+ 4.3.21.RELEASE
+
+
+
+
+ commons-logging
+ commons-logging
+ ${commons-logging.version}
+ provided
+
+
+
+ org.slf4j
+ slf4j-api
+ ${org.slf4j.version}
+
+
+ org.slf4j
+ jcl-over-slf4j
+ ${org.slf4j.version}
+ runtime
+
+
+
+ org.slf4j
+ log4j-over-slf4j
+ ${org.slf4j.version}
+ runtime
+
+
+
+ ch.qos.logback
+ logback-classic
+ ${ch.qos.logback.version}
+ runtime
+
+
+ junit
+ junit
+ 4.10
+ test
+
+
+
+ joda-time
+ joda-time
+ ${joda-time.version}
+
+
+
+ org.postgresql
+ postgresql
+ ${postgresql.version}
+ runtime
+
+
+
+ org.apache.commons
+ commons-dbcp2
+ ${commons-dbcp2.version}
+
+
+
+ org.springframework
+ spring-context
+ ${org.springframework.version}
+
+
+
+ org.springframework
+ spring-jdbc
+ ${org.springframework.version}
+
+
+
+ org.springframework
+ spring-test
+ ${org.springframework.version}
+ test
+
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+
diff --git a/sql/create-table.sql b/sql/create-table.sql
new file mode 100644
index 0000000..9dd17fd
--- /dev/null
+++ b/sql/create-table.sql
@@ -0,0 +1,311 @@
+-- Create tables for Bank of Jakarta, the tutorial's online banking application.
+-- Also seed the NEXT_ID table with initial values.
+
+CREATE TABLE ACCOUNT (
+ account_id VARCHAR(8) CONSTRAINT pk_account PRIMARY KEY,
+ type VARCHAR(24),
+ description VARCHAR(30),
+ balance NUMERIC(10,2),
+ credit_line NUMERIC(10,2),
+ begin_balance NUMERIC(10,2),
+ begin_balance_time_stamp TIMESTAMP);
+
+CREATE TABLE CUSTOMER (
+ customer_id VARCHAR(8) CONSTRAINT pk_customer PRIMARY KEY,
+ last_name VARCHAR(30),
+ first_name VARCHAR(30),
+ middle_initial VARCHAR(1),
+ street VARCHAR(40),
+ city VARCHAR(40),
+ state VARCHAR(2),
+ zip VARCHAR(5),
+ phone VARCHAR(16),
+ email VARCHAR(30));
+
+CREATE TABLE TX (
+ tx_id VARCHAR(8) CONSTRAINT pk_tx PRIMARY KEY,
+ account_id VARCHAR(8),
+ time_stamp TIMESTAMP,
+ amount NUMERIC(10,2),
+ balance NUMERIC(10,2),
+ description VARCHAR(30),
+ CONSTRAINT fk_tx_account_id FOREIGN KEY (account_id) REFERENCES account(account_id));
+
+CREATE TABLE CUSTOMER_ACCOUNT_XREF (
+ customer_id VARCHAR(8),
+ account_id VARCHAR(8),
+ CONSTRAINT fk_customer_id FOREIGN KEY (customer_id) REFERENCES customer(customer_id),
+ CONSTRAINT fk_account_id FOREIGN KEY (account_id) REFERENCES account(account_id));
+
+CREATE TABLE NEXT_ID (
+ beanName VARCHAR(30) CONSTRAINT pk_next_id PRIMARY KEY,
+ id NUMERIC);
+
+INSERT INTO NEXT_ID
+ VALUES ('customer', 202);
+
+INSERT INTO NEXT_ID
+ VALUES ('account', 5050);
+
+INSERT INTO NEXT_ID
+ VALUES ('tx', 100);
+
+INSERT INTO ACCOUNT VALUES
+('5005', 'Money Market', 'Hi Balance', 4000.00, 0.00, 3500.00, '2003-07-28 23:03:20');
+
+INSERT INTO ACCOUNT VALUES
+('5006', 'Checking', 'Checking', 85.00, 0.00, 66.54, '2003-07-21 03:12:00');
+
+INSERT INTO ACCOUNT VALUES
+('5007', 'Credit', 'Visa', 599.18, 5000.00, 166.08, '2003-07-23 10:13:54');
+
+INSERT INTO ACCOUNT VALUES
+('5008', 'Savings', 'Super Interest Account', 55601.35, 0.00, 5433.89, '2003-07-15 12:55:33');
+
+INSERT INTO CUSTOMER VALUES
+('200', 'Jones', 'Richard', 'K',
+ '88 Poplar Ave.', 'Cupertino', 'CA', '95014',
+ '408-123-4567', 'rhill@j2ee.com');
+
+INSERT INTO CUSTOMER VALUES
+('201', 'Jones', 'Mary', 'R',
+ '88 Poplar Ave.', 'Cupertino', 'CA', '95014',
+ '408-123-4567', 'mhill@j2ee.com');
+
+INSERT INTO CUSTOMER_ACCOUNT_XREF VALUES
+('200', '5005');
+
+INSERT INTO CUSTOMER_ACCOUNT_XREF VALUES
+('201', '5005');
+
+INSERT INTO CUSTOMER_ACCOUNT_XREF VALUES
+('200', '5006');
+
+INSERT INTO CUSTOMER_ACCOUNT_XREF VALUES
+('200', '5007');
+
+INSERT INTO CUSTOMER_ACCOUNT_XREF VALUES
+('201', '5006');
+
+INSERT INTO CUSTOMER_ACCOUNT_XREF VALUES
+('201', '5007');
+
+INSERT INTO CUSTOMER_ACCOUNT_XREF VALUES
+('200', '5008');
+
+INSERT INTO CUSTOMER_ACCOUNT_XREF VALUES
+('201', '5008');
+
+INSERT INTO TX VALUES
+('1', '5005', '2003-9-01 12:55:33', 200.00, 4200.00, 'Refund');
+UPDATE ACCOUNT SET balance = 4200.00 WHERE account_id = '5005';
+INSERT INTO TX VALUES
+('3', '5008', '2003-9-03 12:56:33', -1000.00, 54601.35, 'Transfer Out');
+UPDATE ACCOUNT SET balance = 54604.35 WHERE account_id = '5008';
+INSERT INTO TX VALUES
+('4', '5006', '2003-9-03 12:57:33', 1000.00, 1085.00, 'Transfer In');
+UPDATE ACCOUNT SET balance = 1085.00 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('5', '5007', '2003-9-05 12:58:33', 33.00, 199.08, 'Clothing');
+UPDATE ACCOUNT SET balance = 199.08 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('6', '5006', '2003-9-06 12:59:33', 2000.00, 3085.00, 'Paycheck Deposit');
+UPDATE ACCOUNT SET balance = 3085.00 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('7', '5005', '2003-9-07 13:00:33', -200.00, 4000.00, 'ATM Withdrawal');
+UPDATE ACCOUNT SET balance = 3085.00 WHERE account_id = '5005';
+INSERT INTO TX VALUES
+('8', '5006', '2003-9-08 13:01:33', -200.00, 2885.00, 'Car Insurance');
+UPDATE ACCOUNT SET balance = 2885.00 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('9', '5007', '2003-9-09 13:02:33', 186.00, 385.08, 'Car Repair');
+UPDATE ACCOUNT SET balance = 385.08 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('10', '5008', '2003-9-10 12:55:33', 1000.00, 55601.35, 'Deposit');
+UPDATE ACCOUNT SET balance = 55601.35 WHERE account_id = '5008';
+INSERT INTO TX VALUES
+('11', '5007', '2003-9-11 12:55:33', 585.00, 970.08, 'Airplane Tickets');
+UPDATE ACCOUNT SET balance = 970.08 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('12', '5006', '2003-9-12 12:55:33', -675.00, 2210.00, 'Mortgage Payment');
+UPDATE ACCOUNT SET balance = 2210.00 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('13', '5005', '2003-9-13 12:55:33', -100.00, 3900.00, 'ATM Withdrawal');
+UPDATE ACCOUNT SET balance = 3900.00 WHERE account_id = '5005';
+INSERT INTO TX VALUES
+('14', '5006', '2003-9-14 12:55:33', -385.08, 1824.92, 'Visa Payment');
+UPDATE ACCOUNT SET balance = 1824.92 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('15', '5007', '2003-9-15 12:55:33', -385.08, 585.00, 'Payment');
+UPDATE ACCOUNT SET balance = 585.00 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('17', '5007', '2003-9-17 12:55:33', 26.95, 611.95, 'Movies');
+UPDATE ACCOUNT SET balance = 611.95 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('18', '5006', '2003-9-18 12:55:33', -31.00, 1793.92, 'Groceries');
+UPDATE ACCOUNT SET balance = 1793.92 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('19', '5005', '2003-9-19 12:55:33', -150.00, 3750.00, 'ATM Withdrawal');
+UPDATE ACCOUNT SET balance = 3750.00 WHERE account_id = '5005';
+INSERT INTO TX VALUES
+('20', '5006', '2003-9-20 12:55:33', 2000.00, 3173.92, 'Paycheck Deposit');
+UPDATE ACCOUNT SET balance = 3173.92 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('21', '5007', '2003-9-21 12:55:33', 124.00, 735.95, 'Furnishings');
+UPDATE ACCOUNT SET balance = 735.95 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('23', '5007', '2003-9-23 12:55:33', 33.12, 769.07, 'Hardware');
+UPDATE ACCOUNT SET balance = 769.07 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('24', '5006', '2003-9-24 12:55:33', -175.33, 2998.59, 'Utility Bill');
+UPDATE ACCOUNT SET balance = 2998.59 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('25', '5006', '2003-9-25 12:55:33', -123.00, 2875.59, 'Groceries');
+UPDATE ACCOUNT SET balance = 2875.59 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('26', '5006', '2003-9-26 12:55:33', -675.00, 2200.59, 'Mortgage Payment');
+UPDATE ACCOUNT SET balance = 2200.59 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('27', '5007', '2003-9-27 12:55:33', 24.72, 793.79, 'Cafe');
+UPDATE ACCOUNT SET balance = 793.79 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('28', '5008', '2003-9-28 12:55:33', 1000.00, 56601.35, 'Deposit');
+UPDATE ACCOUNT SET balance = 56601.35 WHERE account_id = '5008';
+INSERT INTO TX VALUES
+('29', '5007', '2003-9-29 12:55:33', 35.00, 828.79, 'Hair Salon');
+UPDATE ACCOUNT SET balance = 828.79 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('30', '5006', '2003-9-30 12:55:33', -20.00, 2180.59, 'Gasoline');
+UPDATE ACCOUNT SET balance = 2180.59 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('31', '5005', '2003-10-01 12:55:33', -100.00, 3650.00, 'ATM Withdrawal');
+UPDATE ACCOUNT SET balance = 3650.00 WHERE account_id = '5005';
+INSERT INTO TX VALUES
+('32', '5006', '2003-10-02 12:55:33', -56.87, 2123.72, 'Phone Bill');
+UPDATE ACCOUNT SET balance = 2123.72 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('33', '5007', '2003-10-03 12:55:33', 67.99, 896.78, 'Acme Shoes');
+UPDATE ACCOUNT SET balance = 896.78 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('35', '5007', '2003-10-05 12:55:33', 24.00, 920.78, 'Movies');
+UPDATE ACCOUNT SET balance = 920.78 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('36', '5006', '2003-10-06 12:55:33', 2000.00, 4123.72, 'Paycheck Deposit');
+UPDATE ACCOUNT SET balance = 4123.72 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('38', '5006', '2003-10-08 12:55:33', -100.00, 4023.72, 'Groceries');
+UPDATE ACCOUNT SET balance = 4023.72 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('39', '5007', '2003-10-09 12:55:33', 26.95, 947.73, 'Pizza');
+UPDATE ACCOUNT SET balance = 947.73 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('41', '5007', '2003-10-11 12:55:33', 125.00, 1072.73, 'Dentist');
+UPDATE ACCOUNT SET balance = 1072.73 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('42', '5006', '2003-10-12 12:55:33', -675.00, 3348.72, 'Mortgage Payment');
+UPDATE ACCOUNT SET balance = 3348.72 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('43', '5005', '2003-10-13 12:55:33', -150.00, 3500.00, 'ATM Withdrawal');
+UPDATE ACCOUNT SET balance = 3500.00 WHERE account_id = '5005';
+INSERT INTO TX VALUES
+('44', '5006', '2003-10-14 12:55:33', -947.73, 2400.99, 'Visa Payment');
+UPDATE ACCOUNT SET balance = 2400.99 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('45', '5007', '2003-10-15 12:55:33', -947.73, 125.00, 'Payment');
+UPDATE ACCOUNT SET balance = 125.00 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('47', '5007', '2003-10-17 12:55:33', 49.90, 100.85, 'Bookstore');
+UPDATE ACCOUNT SET balance = 100.85 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('48', '5006', '2003-10-18 12:55:33', -100.00, 2300.99, 'Groceries');
+UPDATE ACCOUNT SET balance = 2300.99 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('50', '5006', '2003-10-20 12:55:33', 2000.00, 4300.99, 'Paycheck Deposit');
+UPDATE ACCOUNT SET balance = 4300.99 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('51', '5007', '2003-10-21 12:55:33', 80.32, 181.17, 'Restaurant');
+UPDATE ACCOUNT SET balance = 181.17 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('53', '5007', '2003-10-23 12:55:33', 11.78, 192.95, 'Electronics');
+UPDATE ACCOUNT SET balance = 192.95 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('54', '5006', '2003-10-24 12:55:33', -150.45, 4150.54, 'Utility Bill');
+UPDATE ACCOUNT SET balance = 4150.54 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('55', '5005', '2003-10-25 12:55:33', -100.00, 3400.00, 'ATM Withdrawal');
+UPDATE ACCOUNT SET balance = 3400.00 WHERE account_id = '5005';
+INSERT INTO TX VALUES
+('56', '5006', '2003-10-26 12:55:33', -675.00, 3475.54, 'Mortgage Payment');
+UPDATE ACCOUNT SET balance = 3475.54 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('57', '5007', '2003-10-27 12:55:33', 24.00, 216.95, 'Ice Skating');
+UPDATE ACCOUNT SET balance = 216.95 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('58', '5006', '2003-10-28 12:55:33', -1000.00, 2475.54, 'Transfer Out');
+UPDATE ACCOUNT SET balance = 2475.54 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('59', '5008', '2003-10-28 12:55:33', 1000.00, 57601.35, 'Transfer In');
+UPDATE ACCOUNT SET balance = 57601.35 WHERE account_id = '5008';
+INSERT INTO TX VALUES
+('60', '5006', '2003-11-02 12:55:33', -99.22, 3376.32, 'Phone Bill');
+UPDATE ACCOUNT SET balance = 3376.32 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('61', '5007', '2003-11-03 12:55:33', 29.97, 246.92, 'Toy Store');
+UPDATE ACCOUNT SET balance = 246.92 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('62', '5006', '2003-11-04 12:55:33', -2000.00, 376.32, 'Transfer Out');
+UPDATE ACCOUNT SET balance = 376.32 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('63', '5008', '2003-11-05 12:55:33', 2000.00, 59601.35, 'Transfer In');
+UPDATE ACCOUNT SET balance = 59601.35 WHERE account_id = '5008';
+INSERT INTO TX VALUES
+('64', '5006', '2003-11-06 12:55:33', 2000.00, 2376.32, 'Paycheck Deposit');
+UPDATE ACCOUNT SET balance = 59601.35 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('65', '5007', '2003-11-07 12:55:33', 14.69, 261.61, 'Cafe');
+UPDATE ACCOUNT SET balance = 261.61 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('66', '5006', '2003-11-08 12:55:33', -108.99, 2267.33, 'Groceries');
+UPDATE ACCOUNT SET balance = 2267.33 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('67', '5006', '2003-11-09 12:55:33', -30.12, 2237.21, 'Gasoline');
+UPDATE ACCOUNT SET balance = 2237.21 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('69', '5007', '2003-11-11 12:55:33', 125.00, 386.61, 'Dentist');
+UPDATE ACCOUNT SET balance = 2237.21 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('70', '5006', '2003-11-12 12:55:33', -675.00, 1562.21, 'Mortgage Payment');
+UPDATE ACCOUNT SET balance = 1562.21 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('72', '5006', '2003-11-13 12:55:33', -261.61, 1300.60, 'Visa Payment');
+UPDATE ACCOUNT SET balance = 1300.60 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('73', '5007', '2003-11-14 12:55:33', -261.61, 125.00, 'Payment');
+UPDATE ACCOUNT SET balance = 125.00 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('75', '5007', '2003-11-15 12:55:33', 24.00, 149.00, 'Drug Store');
+UPDATE ACCOUNT SET balance = 149.00 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('76', '5006', '2003-11-16 12:55:33', -67.98, 1232.62, 'Groceries');
+UPDATE ACCOUNT SET balance = 1232.62 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('78', '5006', '2003-11-17 12:55:33', 2000.00, 3232.62, 'Paycheck Deposit');
+UPDATE ACCOUNT SET balance = 3232.62 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('79', '5007', '2003-11-18 12:55:33', 32.95, 181.95, 'CDs');
+UPDATE ACCOUNT SET balance = 181.95 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('81', '5007', '2003-11-20 12:55:33', 14.10, 196.05, 'Sports Store');
+UPDATE ACCOUNT SET balance = 196.05 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('82', '5006', '2003-11-21 12:55:33', -99.30, 3133.32, 'Utility Bill');
+UPDATE ACCOUNT SET balance = 3133.32 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('84', '5006', '2003-11-21 12:55:33', -675.00, 2458.32, 'Mortgage Payment');
+UPDATE ACCOUNT SET balance = 2458.32 WHERE account_id = '5006';
+INSERT INTO TX VALUES
+('85', '5007', '2003-11-22 12:55:33', 23.98, 220.03, 'Garden Supply');
+UPDATE ACCOUNT SET balance = 220.03 WHERE account_id = '5007';
+INSERT INTO TX VALUES
+('86', '5005', '2003-11-23 12:55:33', -100.00, 3300.00, 'ATM Withdrawal');
+UPDATE ACCOUNT SET balance = 3300.00 WHERE account_id = '5005';
diff --git a/sql/delete.sql b/sql/delete.sql
new file mode 100644
index 0000000..7b23849
--- /dev/null
+++ b/sql/delete.sql
@@ -0,0 +1,15 @@
+-- Drop tables for the Bank of Jakarta online banking sample application.
+
+ALTER TABLE TX DROP CONSTRAINT fk_tx_account_id;
+ALTER TABLE CUSTOMER_ACCOUNT_XREF DROP CONSTRAINT fk_customer_id;
+ALTER TABLE CUSTOMER_ACCOUNT_XREF DROP CONSTRAINT fk_account_id;
+ALTER TABLE ACCOUNT DROP CONSTRAINT pk_account;
+ALTER TABLE CUSTOMER DROP CONSTRAINT pk_customer;
+ALTER TABLE TX DROP CONSTRAINT pk_tx;
+ALTER TABLE NEXT_ID DROP CONSTRAINT pk_next_id;
+
+DROP TABLE TX;
+DROP TABLE CUSTOMER_ACCOUNT_XREF;
+DROP TABLE ACCOUNT;
+DROP TABLE CUSTOMER;
+DROP TABLE NEXT_ID;
diff --git a/src/main/java/com/dariawan/bankofjakarta/App.java b/src/main/java/com/dariawan/bankofjakarta/App.java
new file mode 100644
index 0000000..e98b99b
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/App.java
@@ -0,0 +1,13 @@
+package com.dariawan.bankofjakarta;
+
+/**
+ * Hello world!
+ *
+ */
+public class App
+{
+ public static void main( String[] args )
+ {
+ System.out.println( "Hello World!" );
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/dao/AccountDao.java b/src/main/java/com/dariawan/bankofjakarta/dao/AccountDao.java
new file mode 100644
index 0000000..c7ae357
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/dao/AccountDao.java
@@ -0,0 +1,21 @@
+package com.dariawan.bankofjakarta.dao;
+
+import com.dariawan.bankofjakarta.domain.Account;
+import com.dariawan.bankofjakarta.exception.db.CreateException;
+import com.dariawan.bankofjakarta.exception.db.FinderException;
+import java.util.List;
+
+public interface AccountDao {
+
+ // Account create(String accountId, String type,
+ // String description, BigDecimal balance, BigDecimal creditLine,
+ // BigDecimal beginBalance, Date beginBalanceTimeStamp)
+ // throws CreateException;
+ Account create(Account account) throws CreateException;
+
+ Account findByPrimaryKey(String accountId) throws FinderException;
+
+ List findByCustomerId(String customerId) throws FinderException;
+
+ void remove(Account account);
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/dao/CustomerAccountDao.java b/src/main/java/com/dariawan/bankofjakarta/dao/CustomerAccountDao.java
new file mode 100644
index 0000000..f085a6d
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/dao/CustomerAccountDao.java
@@ -0,0 +1,15 @@
+package com.dariawan.bankofjakarta.dao;
+
+import com.dariawan.bankofjakarta.domain.Account;
+import com.dariawan.bankofjakarta.domain.Customer;
+import java.util.ArrayList;
+import java.util.List;
+
+public interface CustomerAccountDao {
+
+ void add(Customer customer, Account account);
+
+ void removeByAccount(Account account);
+
+ void removeCustomerFromAccount(Customer customer, Account account);
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/dao/CustomerDao.java b/src/main/java/com/dariawan/bankofjakarta/dao/CustomerDao.java
new file mode 100644
index 0000000..01f6615
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/dao/CustomerDao.java
@@ -0,0 +1,23 @@
+package com.dariawan.bankofjakarta.dao;
+
+import com.dariawan.bankofjakarta.domain.Customer;
+import com.dariawan.bankofjakarta.exception.db.CreateException;
+import com.dariawan.bankofjakarta.exception.db.FinderException;
+import java.util.List;
+
+public interface CustomerDao {
+
+ // Customer create(String customerId, String lastName,
+ // String firstName, String middleInitial, String street, String city,
+ // String state, String zip, String phone, String email)
+ // throws CreateException;
+ Customer create(Customer customer) throws CreateException;
+
+ Customer findByPrimaryKey(String customerId) throws FinderException;
+
+ List findByAccountId(String accountId) throws FinderException;
+
+ List findByLastName(String lastName) throws FinderException;
+
+ void remove(Customer customer);
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/dao/NextIdDao.java b/src/main/java/com/dariawan/bankofjakarta/dao/NextIdDao.java
new file mode 100644
index 0000000..2647dbc
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/dao/NextIdDao.java
@@ -0,0 +1,9 @@
+package com.dariawan.bankofjakarta.dao;
+
+import com.dariawan.bankofjakarta.domain.NextId;
+import com.dariawan.bankofjakarta.exception.db.FinderException;
+
+public interface NextIdDao {
+
+ NextId findByPrimaryKey(String beanName) throws FinderException;
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/dao/TxDao.java b/src/main/java/com/dariawan/bankofjakarta/dao/TxDao.java
new file mode 100644
index 0000000..99dd981
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/dao/TxDao.java
@@ -0,0 +1,20 @@
+package com.dariawan.bankofjakarta.dao;
+
+import com.dariawan.bankofjakarta.domain.Tx;
+import com.dariawan.bankofjakarta.exception.db.CreateException;
+import com.dariawan.bankofjakarta.exception.db.FinderException;
+import java.util.Date;
+import java.util.List;
+
+public interface TxDao {
+
+ // Tx create(String txId, Account account, Date timeStamp,
+ // BigDecimal amount, BigDecimal balance, String description)
+ // throws CreateException;
+ Tx create(Tx tx) throws CreateException;
+
+ Tx findByPrimaryKey(String txId) throws FinderException;
+
+ List findByAccountId(Date startDate, Date endDate, String accountId)
+ throws FinderException;
+} // TxDao
diff --git a/src/main/java/com/dariawan/bankofjakarta/dao/impl/AccountDaoImpl.java b/src/main/java/com/dariawan/bankofjakarta/dao/impl/AccountDaoImpl.java
new file mode 100644
index 0000000..510df26
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/dao/impl/AccountDaoImpl.java
@@ -0,0 +1,96 @@
+package com.dariawan.bankofjakarta.dao.impl;
+
+import com.dariawan.bankofjakarta.dao.AccountDao;
+import com.dariawan.bankofjakarta.domain.Account;
+import com.dariawan.bankofjakarta.exception.db.CreateException;
+import com.dariawan.bankofjakarta.exception.db.FinderException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+import javax.sql.DataSource;
+import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.PreparedStatementCreator;
+import org.springframework.jdbc.core.RowMapper;
+
+public class AccountDaoImpl implements AccountDao {
+
+ private static final String SQL_INSERT = "insert into ACCOUNT ("
+ + "account_id, type, description, balance, credit_line, "
+ + "begin_balance, begin_balance_time_stamp) "
+ + "values (?, ?, ?, ?, ?, ?, ?)";
+
+ private static final String SQL_FIND_BY_ACCOUNT_ID = "select * from ACCOUNT where account_id = ?";
+
+ private static final String SQL_FIND_BY_CUSTOMER_ID = "select acc.* "
+ + "from CUSTOMER_ACCOUNT_XREF cax "
+ + "inner join ACCOUNT acc on acc.account_id = cax.account_id "
+ + "where cax.customer_id = ?";
+
+ private static final String SQL_DELETE = "delete from ACCOUNT where account_id = ?";
+
+
+ private JdbcTemplate jdbcTemplate;
+
+ public void setDataSource(DataSource dataSource) {
+ this.jdbcTemplate = new JdbcTemplate(dataSource);
+ }
+
+ // public Account create(String accountId, String type, String description,
+ // BigDecimal balance, BigDecimal creditLine,
+ // BigDecimal beginBalance, Date beginBalanceTimeStamp)
+ public Account create(Account account) throws CreateException {
+ jdbcTemplate.update(new PreparedStatementCreator() {
+
+ @Override
+ public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
+ PreparedStatement ps = conn.prepareStatement(SQL_INSERT);
+ ps.setString(1, account.getAccountId());
+ ps.setString(2, account.getType());
+ ps.setString(3, account.getDescription());
+ ps.setBigDecimal(4, account.getBalance());
+ ps.setBigDecimal(5, account.getCreditLine());
+ ps.setBigDecimal(6, account.getBeginBalance());
+ ps.setDate(7, new java.sql.Date(account.getBeginBalanceTimeStamp().getTime()));
+ return ps;
+ }
+ });
+ return account;
+ }
+
+ public Account findByPrimaryKey(String accountId) throws FinderException {
+ try {
+ Account account = jdbcTemplate.queryForObject(SQL_FIND_BY_ACCOUNT_ID, new ResultSetAccount(), accountId);
+ return account;
+ } catch (EmptyResultDataAccessException err) {
+ return null;
+ }
+ }
+
+ public List findByCustomerId(String customerId) throws FinderException {
+ List result = jdbcTemplate.query(SQL_FIND_BY_CUSTOMER_ID, new ResultSetAccount(), customerId);
+ return result;
+ }
+
+ public void remove(Account account) {
+ jdbcTemplate.update(SQL_DELETE, account.getAccountId());
+ }
+
+ private class ResultSetAccount implements RowMapper {
+
+ @Override
+ public Account mapRow(ResultSet rs, int i) throws SQLException {
+ Account account = new Account();
+ account.setAccountId(rs.getString("account_id"));
+ account.setType(rs.getString("type"));
+ account.setDescription(rs.getString("description"));
+ account.setBalance(rs.getBigDecimal("balance"));
+ account.setCreditLine(rs.getBigDecimal("credit_line"));
+ account.setBeginBalance(rs.getBigDecimal("begin_balance"));
+ account.setBeginBalanceTimeStamp(rs.getDate("begin_balance_time_stamp"));
+ return account;
+ }
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/dao/impl/CustomerAccountDaoImpl.java b/src/main/java/com/dariawan/bankofjakarta/dao/impl/CustomerAccountDaoImpl.java
new file mode 100644
index 0000000..de437c8
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/dao/impl/CustomerAccountDaoImpl.java
@@ -0,0 +1,49 @@
+package com.dariawan.bankofjakarta.dao.impl;
+
+import com.dariawan.bankofjakarta.dao.CustomerAccountDao;
+import com.dariawan.bankofjakarta.domain.Account;
+import com.dariawan.bankofjakarta.domain.Customer;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.List;
+import javax.sql.DataSource;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.PreparedStatementCreator;
+
+public class CustomerAccountDaoImpl implements CustomerAccountDao {
+
+ private static final String SQL_INSERT = "insert into CUSTOMER_ACCOUNT_XREF ("
+ + "customer_id, account_id) values (?, ?)";
+
+ private static final String SQL_DELETE_BY_ACCOUNT_ID = "delete from CUSTOMER_ACCOUNT_XREF where account_id = ?";
+
+ private static final String SQL_DELETE_BY_CUSOMER_N_ACCOUNT_ID = "delete from CUSTOMER_ACCOUNT_XREF where customer_id = ? and account_id = ?";
+
+ private JdbcTemplate jdbcTemplate;
+
+ public void setDataSource(DataSource dataSource) {
+ this.jdbcTemplate = new JdbcTemplate(dataSource);
+ }
+
+ public void add(Customer customer, Account account) {
+ jdbcTemplate.update(new PreparedStatementCreator() {
+
+ @Override
+ public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
+ PreparedStatement ps = conn.prepareStatement(SQL_INSERT);
+ ps.setString(1, customer.getCustomerId());
+ ps.setString(2, account.getAccountId());
+ return ps;
+ }
+ });
+ }
+
+ public void removeByAccount(Account account) {
+ jdbcTemplate.update(SQL_DELETE_BY_ACCOUNT_ID, account.getAccountId());
+ }
+
+ public void removeCustomerFromAccount(Customer customer, Account account) {
+ jdbcTemplate.update(SQL_DELETE_BY_ACCOUNT_ID, customer.getCustomerId(), account.getAccountId());
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/dao/impl/CustomerDaoImpl.java b/src/main/java/com/dariawan/bankofjakarta/dao/impl/CustomerDaoImpl.java
new file mode 100644
index 0000000..5c421e2
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/dao/impl/CustomerDaoImpl.java
@@ -0,0 +1,109 @@
+package com.dariawan.bankofjakarta.dao.impl;
+
+import com.dariawan.bankofjakarta.dao.CustomerDao;
+import com.dariawan.bankofjakarta.domain.Customer;
+import com.dariawan.bankofjakarta.exception.db.CreateException;
+import com.dariawan.bankofjakarta.exception.db.FinderException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+import javax.sql.DataSource;
+import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.PreparedStatementCreator;
+import org.springframework.jdbc.core.RowMapper;
+
+public class CustomerDaoImpl implements CustomerDao {
+
+ private static final String SQL_INSERT = "insert into CUSTOMER ("
+ + "customer_id, last_name, first_name, middle_initial, "
+ + "street, city, state, zip, phone, email) "
+ + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+
+ private static final String SQL_FIND_BY_CUSTOMER_ID = "select * from CUSTOMER where customer_id = ?";
+
+ private static final String SQL_FIND_BY_ACCOUNT_ID = "select cus.* "
+ + "from CUSTOMER_ACCOUNT_XREF cax "
+ + "inner join CUSTOMER cus on cus.customer_id = cax.customer_id "
+ + "where cax.account_id = ?";
+
+ private static final String SQL_FIND_BY_LAST_NAME = "select * "
+ + "from CUSTOMER where last_name = ?";
+
+ private static final String SQL_DELETE = "delete from CUSTOMER where customer_id = ?";
+
+ private JdbcTemplate jdbcTemplate;
+
+ public void setDataSource(DataSource dataSource) {
+ this.jdbcTemplate = new JdbcTemplate(dataSource);
+ }
+
+ // public Customer create(String customerId, String lastName, String firstName,
+ // String middleInitial, String street, String city, String state,
+ // String zip, String phone, String email) throws CreateException {
+ public Customer create(Customer customer) throws CreateException {
+ jdbcTemplate.update(new PreparedStatementCreator() {
+
+ @Override
+ public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
+ PreparedStatement ps = conn.prepareStatement(SQL_INSERT);
+ ps.setString(1, customer.getCustomerId());
+ ps.setString(2, customer.getLastName());
+ ps.setString(3, customer.getFirstName());
+ ps.setString(4, customer.getMiddleInitial());
+ ps.setString(5, customer.getStreet());
+ ps.setString(6, customer.getCity());
+ ps.setString(7, customer.getState());
+ ps.setString(8, customer.getZip());
+ ps.setString(9, customer.getPhone());
+ ps.setString(10, customer.getEmail());
+ return ps;
+ }
+ });
+ return customer;
+ }
+
+ public Customer findByPrimaryKey(String customerId) throws FinderException {
+ try {
+ Customer customer = jdbcTemplate.queryForObject(SQL_FIND_BY_CUSTOMER_ID, new ResultSetCustomer(), customerId);
+ return customer;
+ } catch (EmptyResultDataAccessException err) {
+ return null;
+ }
+ }
+
+ public List findByAccountId(String accountId) throws FinderException {
+ List result = jdbcTemplate.query(SQL_FIND_BY_ACCOUNT_ID, new ResultSetCustomer(), accountId);
+ return result;
+ }
+
+ public List findByLastName(String lastName) throws FinderException {
+ List result = jdbcTemplate.query(SQL_FIND_BY_LAST_NAME, new ResultSetCustomer(), lastName);
+ return result;
+ }
+
+ public void remove(Customer customer) {
+ jdbcTemplate.update(SQL_DELETE, customer.getCustomerId());
+ }
+
+ private class ResultSetCustomer implements RowMapper {
+
+ @Override
+ public Customer mapRow(ResultSet rs, int i) throws SQLException {
+ Customer customer = new Customer();
+ customer.setCustomerId(rs.getString("customer_id"));
+ customer.setLastName(rs.getString("last_name"));
+ customer.setFirstName(rs.getString("first_name"));
+ customer.setMiddleInitial(rs.getString("middle_initial"));
+ customer.setStreet(rs.getString("street"));
+ customer.setCity(rs.getString("city"));
+ customer.setState(rs.getString("state"));
+ customer.setZip(rs.getString("zip"));
+ customer.setPhone(rs.getString("phone"));
+ customer.setEmail(rs.getString("email"));
+ return customer;
+ }
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/dao/impl/NextIdDaoImpl.java b/src/main/java/com/dariawan/bankofjakarta/dao/impl/NextIdDaoImpl.java
new file mode 100644
index 0000000..38abb9d
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/dao/impl/NextIdDaoImpl.java
@@ -0,0 +1,60 @@
+package com.dariawan.bankofjakarta.dao.impl;
+
+import com.dariawan.bankofjakarta.dao.NextIdDao;
+import com.dariawan.bankofjakarta.domain.NextId;
+import com.dariawan.bankofjakarta.exception.db.FinderException;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import javax.sql.DataSource;
+import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
+import org.springframework.jdbc.core.namedparam.SqlParameterSource;
+
+public class NextIdDaoImpl implements NextIdDao {
+
+ private static final String SQL_FIND_BY_BEAN_NAME = "select * from NEXT_ID where beanName = ?";
+ private static final String SQL_UPDATE_NEXT_ID = "update NEXT_ID set id = :id where beanName = :beanName";
+
+
+ private JdbcTemplate jdbcTemplate;
+ private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
+
+ public void setDataSource(DataSource dataSource) {
+ this.jdbcTemplate = new JdbcTemplate(dataSource);
+ this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
+ }
+
+ public NextId findByPrimaryKey(String beanName) throws FinderException {
+ try {
+ NextId nextId = jdbcTemplate.queryForObject(SQL_FIND_BY_BEAN_NAME, new ResultSetNextId(), beanName);
+
+ int i = nextId.getId();
+ i++;
+ nextId.setId(i);
+
+ SqlParameterSource nextIdParameter = new MapSqlParameterSource()
+ .addValue("id", nextId.getId())
+ .addValue("beanName", nextId.getBeanName());
+ namedParameterJdbcTemplate.update(SQL_UPDATE_NEXT_ID, nextIdParameter);
+
+ return nextId;
+ } catch (EmptyResultDataAccessException err) {
+ return null;
+ }
+ }
+
+ private class ResultSetNextId implements RowMapper {
+
+ @Override
+ public NextId mapRow(ResultSet rs, int i) throws SQLException {
+ NextId nextId = new NextId();
+ nextId.setBeanName(rs.getString("beanName"));
+ nextId.setId(rs.getInt("id"));
+ return nextId;
+ }
+ }
+
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/dao/impl/TxDaoImpl.java b/src/main/java/com/dariawan/bankofjakarta/dao/impl/TxDaoImpl.java
new file mode 100644
index 0000000..f57ba2d
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/dao/impl/TxDaoImpl.java
@@ -0,0 +1,92 @@
+package com.dariawan.bankofjakarta.dao.impl;
+
+import com.dariawan.bankofjakarta.dao.TxDao;
+import com.dariawan.bankofjakarta.domain.Account;
+import com.dariawan.bankofjakarta.domain.Tx;
+import com.dariawan.bankofjakarta.exception.db.CreateException;
+import com.dariawan.bankofjakarta.exception.db.FinderException;
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import javax.sql.DataSource;
+import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.PreparedStatementCreator;
+import org.springframework.jdbc.core.RowMapper;
+
+public class TxDaoImpl implements TxDao {
+
+ private static final String SQL_INSERT = "insert into TX ("
+ + "tx_id, account_id, time_stamp, amount, balance, description) "
+ + "values (?, ?, ?, ?, ?, ?)";
+
+ private static final String SQL_FIND_BY_TX_ID = "select * from TX where tx_id = ?";
+
+ private static final String SQL_FIND_BY_ACCOUNT_ID = "select * from TX "
+ + "where account_id = ? "
+ + "and timestamp between ? and ?";
+
+ private JdbcTemplate jdbcTemplate;
+
+ public void setDataSource(DataSource dataSource) {
+ this.jdbcTemplate = new JdbcTemplate(dataSource);
+ }
+
+ // Tx create(String txId, Account tx, Date timeStamp,
+ // BigDecimal amount, BigDecimal balance, String description)
+ // throws CreateException;
+ public Tx create(Tx tx) throws CreateException {
+ jdbcTemplate.update(new PreparedStatementCreator() {
+
+ @Override
+ public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
+ PreparedStatement ps = conn.prepareStatement(SQL_INSERT);
+ ps.setString(1, tx.getTxId());
+ ps.setString(2, tx.getAccountId());
+ ps.setDate(3, new java.sql.Date(tx.getTimeStamp().getTime()));
+ ps.setBigDecimal(4, tx.getAmount());
+ ps.setBigDecimal(5, tx.getBalance());
+ ps.setString(6, tx.getDescription());
+ return ps;
+ }
+ });
+ return tx;
+ }
+
+ @Override
+ public Tx findByPrimaryKey(String txId) throws FinderException {
+ try {
+ Tx tx = jdbcTemplate.queryForObject(SQL_FIND_BY_TX_ID, new ResultSetTx(), txId);
+ return tx;
+ } catch (EmptyResultDataAccessException err) {
+ return null;
+ }
+ }
+
+ @Override
+ public List findByAccountId(Date startDate, Date endDate, String accountId) throws FinderException {
+ List result = jdbcTemplate.query(SQL_FIND_BY_ACCOUNT_ID, new ResultSetTx(), accountId, startDate, endDate);
+ return result;
+ }
+
+ private class ResultSetTx implements RowMapper {
+
+ @Override
+ public Tx mapRow(ResultSet rs, int i) throws SQLException {
+ String txId = rs.getString("tx_id");
+ String accountId = rs.getString("account_id");
+ Date timeStamp = rs.getDate("time_stamp");
+ BigDecimal amount = rs.getBigDecimal("amount");
+ BigDecimal balance = rs.getBigDecimal("balance");
+ String description = rs.getString("begin_balance");
+
+ Tx tx = new Tx(txId, accountId, timeStamp, amount, balance, description);
+ return tx;
+ }
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/domain/Account.java b/src/main/java/com/dariawan/bankofjakarta/domain/Account.java
new file mode 100644
index 0000000..b15f327
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/domain/Account.java
@@ -0,0 +1,109 @@
+package com.dariawan.bankofjakarta.domain;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * This class holds the details of a bank account entity. It contains getters
+ * and setters for each variable.
+ */
+public class Account implements Serializable {
+
+ private String accountId;
+ private String type;
+ private String description;
+ private BigDecimal balance;
+ private BigDecimal creditLine;
+ private BigDecimal beginBalance;
+ private Date beginBalanceTimeStamp;
+
+ public Account() {
+ }
+
+ public Account(String accountId, String type, String description,
+ BigDecimal balance, BigDecimal creditLine, BigDecimal beginBalance,
+ Date beginBalanceTimeStamp) {
+ this.accountId = accountId;
+ this.type = type;
+ this.description = description;
+ this.balance = balance;
+ this.creditLine = creditLine;
+ this.beginBalance = beginBalance;
+ this.beginBalanceTimeStamp = beginBalanceTimeStamp;
+ }
+
+ public Account(String type, String description, BigDecimal balance,
+ BigDecimal creditLine, BigDecimal beginBalance,
+ Date beginBalanceTimeStamp) {
+ // this.accountId = accountId;
+ this.type = type;
+ this.description = description;
+ this.balance = balance;
+ this.creditLine = creditLine;
+ this.beginBalance = beginBalance;
+ this.beginBalanceTimeStamp = beginBalanceTimeStamp;
+ }
+
+ // getters
+ public String getAccountId() {
+ return accountId;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public BigDecimal getBalance() {
+ return balance;
+ }
+
+ public BigDecimal getCreditLine() {
+ return creditLine;
+ }
+
+ public BigDecimal getBeginBalance() {
+ return beginBalance;
+ }
+
+ public Date getBeginBalanceTimeStamp() {
+ return beginBalanceTimeStamp;
+ }
+
+ public BigDecimal getRemainingCredit() {
+ return creditLine.subtract(balance);
+ }
+
+ // setters
+ public void setAccountId(String accountId) {
+ this.accountId = accountId;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public void setBalance(BigDecimal balance) {
+ this.balance = balance;
+ }
+
+ public void setCreditLine(BigDecimal creditLine) {
+ this.creditLine = creditLine;
+ }
+
+ public void setBeginBalance(BigDecimal beginBalance) {
+ this.beginBalance = beginBalance;
+ }
+
+ public void setBeginBalanceTimeStamp(Date beginBalanceTimeStamp) {
+ this.beginBalanceTimeStamp = beginBalanceTimeStamp;
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/domain/Customer.java b/src/main/java/com/dariawan/bankofjakarta/domain/Customer.java
new file mode 100644
index 0000000..38e796d
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/domain/Customer.java
@@ -0,0 +1,135 @@
+package com.dariawan.bankofjakarta.domain;
+
+import java.io.Serializable;
+
+/**
+ * This class holds the details of a customer entity. It contains getters and
+ * setters for each variable.
+ */
+public class Customer implements Serializable {
+
+ private String customerId;
+ private String lastName;
+ private String firstName;
+ private String middleInitial;
+ private String street;
+ private String city;
+ private String state;
+ private String zip;
+ private String phone;
+ private String email;
+
+ public Customer () {
+ }
+
+ public Customer(String lastName, String firstName,
+ String middleInitial, String street, String city, String state,
+ String zip, String phone, String email) {
+ this.lastName = lastName;
+ this.firstName = firstName;
+ this.middleInitial = middleInitial;
+ this.street = street;
+ this.city = city;
+ this.state = state;
+ this.zip = zip;
+ this.phone = phone;
+ this.email = email;
+ }
+
+ public Customer(String customerId, String lastName,
+ String firstName, String middleInitial, String street, String city,
+ String state, String zip, String phone, String email) {
+ this.customerId = customerId;
+ this.lastName = lastName;
+ this.firstName = firstName;
+ this.middleInitial = middleInitial;
+ this.street = street;
+ this.city = city;
+ this.state = state;
+ this.zip = zip;
+ this.phone = phone;
+ this.email = email;
+ }
+
+ // getters
+ public String getCustomerId() {
+ return customerId;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public String getMiddleInitial() {
+ return middleInitial;
+ }
+
+ public String getStreet() {
+ return street;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public String getZip() {
+ return zip;
+ }
+
+ public String getPhone() {
+ return phone;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ // setters
+ public void setCustomerId(String customerId) {
+ this.customerId = customerId;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public void setMiddleInitial(String middleInitial) {
+ this.middleInitial = middleInitial;
+ }
+
+ public void setStreet(String street) {
+ this.street = street;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ public void setZip(String zip) {
+ this.zip = zip;
+ }
+
+ public void setPhone(String phone) {
+ this.phone = phone;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+} // Customer
diff --git a/src/main/java/com/dariawan/bankofjakarta/domain/NextId.java b/src/main/java/com/dariawan/bankofjakarta/domain/NextId.java
new file mode 100644
index 0000000..ff3a11c
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/domain/NextId.java
@@ -0,0 +1,23 @@
+package com.dariawan.bankofjakarta.domain;
+
+public class NextId {
+
+ private String beanName;
+ private int id;
+
+ public String getBeanName() {
+ return beanName;
+ }
+
+ public void setBeanName(String beanName) {
+ this.beanName = beanName;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/domain/Tx.java b/src/main/java/com/dariawan/bankofjakarta/domain/Tx.java
new file mode 100644
index 0000000..3513107
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/domain/Tx.java
@@ -0,0 +1,50 @@
+package com.dariawan.bankofjakarta.domain;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+public class Tx implements Serializable {
+
+ private final String txId;
+ private final String accountId;
+ private final Date timeStamp;
+ private final BigDecimal amount;
+ private final BigDecimal balance;
+ private final String description;
+
+ public Tx(String txId, String accountId, Date timeStamp, BigDecimal amount,
+ BigDecimal balance, String description) {
+ this.txId = txId;
+ this.accountId = accountId;
+ this.timeStamp = timeStamp;
+ this.amount = amount;
+ this.balance = balance;
+ this.description = description;
+ }
+
+ // getters
+ public String getTxId() {
+ return txId;
+ }
+
+ public String getAccountId() {
+ return accountId;
+ }
+
+ public Date getTimeStamp() {
+ return timeStamp;
+ }
+
+ public BigDecimal getAmount() {
+ return amount;
+ }
+
+ public BigDecimal getBalance() {
+ return balance;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+} // Tx
diff --git a/src/main/java/com/dariawan/bankofjakarta/exception/AccountNotFoundException.java b/src/main/java/com/dariawan/bankofjakarta/exception/AccountNotFoundException.java
new file mode 100644
index 0000000..8ae3638
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/exception/AccountNotFoundException.java
@@ -0,0 +1,15 @@
+package com.dariawan.bankofjakarta.exception;
+
+/**
+ * This application exception indicates that an Account entity has not been
+ * found.
+ */
+public class AccountNotFoundException extends Exception {
+
+ public AccountNotFoundException() {
+ }
+
+ public AccountNotFoundException(String msg) {
+ super(msg);
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/exception/CustomerInAccountException.java b/src/main/java/com/dariawan/bankofjakarta/exception/CustomerInAccountException.java
new file mode 100644
index 0000000..5fef184
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/exception/CustomerInAccountException.java
@@ -0,0 +1,16 @@
+package com.dariawan.bankofjakarta.exception;
+
+/**
+ * This application exception indicates that a customer-account relationship
+ * already exists. In other words, the customer has already been assigned to the
+ * account.
+ */
+public class CustomerInAccountException extends Exception {
+
+ public CustomerInAccountException() {
+ }
+
+ public CustomerInAccountException(String msg) {
+ super(msg);
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/exception/CustomerNotFoundException.java b/src/main/java/com/dariawan/bankofjakarta/exception/CustomerNotFoundException.java
new file mode 100644
index 0000000..ea46511
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/exception/CustomerNotFoundException.java
@@ -0,0 +1,15 @@
+package com.dariawan.bankofjakarta.exception;
+
+/**
+ * This class application exception indicates that a Customer entity has not
+ * been found.
+ */
+public class CustomerNotFoundException extends Exception {
+
+ public CustomerNotFoundException() {
+ }
+
+ public CustomerNotFoundException(String msg) {
+ super(msg);
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/exception/CustomerNotInAccountException.java b/src/main/java/com/dariawan/bankofjakarta/exception/CustomerNotInAccountException.java
new file mode 100644
index 0000000..799e292
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/exception/CustomerNotInAccountException.java
@@ -0,0 +1,15 @@
+package com.dariawan.bankofjakarta.exception;
+
+/**
+ * This class application exception indicates that a a customer who was expected
+ * to be in an account was not found there.
+ */
+public class CustomerNotInAccountException extends Exception {
+
+ public CustomerNotInAccountException() {
+ }
+
+ public CustomerNotInAccountException(String msg) {
+ super(msg);
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/exception/CustomerRequiredException.java b/src/main/java/com/dariawan/bankofjakarta/exception/CustomerRequiredException.java
new file mode 100644
index 0000000..a334d48
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/exception/CustomerRequiredException.java
@@ -0,0 +1,15 @@
+package com.dariawan.bankofjakarta.exception;
+
+/**
+ * This application exception indicates that at least one customer is required
+ * for an account.
+ */
+public class CustomerRequiredException extends Exception {
+
+ public CustomerRequiredException() {
+ }
+
+ public CustomerRequiredException(String msg) {
+ super(msg);
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/exception/IllegalAccountTypeException.java b/src/main/java/com/dariawan/bankofjakarta/exception/IllegalAccountTypeException.java
new file mode 100644
index 0000000..65765bc
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/exception/IllegalAccountTypeException.java
@@ -0,0 +1,15 @@
+package com.dariawan.bankofjakarta.exception;
+
+/**
+ * This an application exception is thrown when an illegal account type is
+ * detected.
+ */
+public class IllegalAccountTypeException extends Exception {
+
+ public IllegalAccountTypeException() {
+ }
+
+ public IllegalAccountTypeException(String msg) {
+ super(msg);
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/exception/IllegalStateException.java b/src/main/java/com/dariawan/bankofjakarta/exception/IllegalStateException.java
new file mode 100644
index 0000000..bc270ab
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/exception/IllegalStateException.java
@@ -0,0 +1,15 @@
+package com.dariawan.bankofjakarta.exception;
+
+/**
+ * This an application exception is thrown when an illegal state is
+ * detected.
+ */
+public class IllegalStateException extends Exception {
+
+ public IllegalStateException() {
+ }
+
+ public IllegalStateException(String msg) {
+ super(msg);
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/exception/InsufficientCreditException.java b/src/main/java/com/dariawan/bankofjakarta/exception/InsufficientCreditException.java
new file mode 100644
index 0000000..684e11a
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/exception/InsufficientCreditException.java
@@ -0,0 +1,15 @@
+package com.dariawan.bankofjakarta.exception;
+
+/**
+ * This application exception indicates that the credit line of an account is
+ * not large enough to perform an operation.
+ */
+public class InsufficientCreditException extends Exception {
+
+ public InsufficientCreditException() {
+ }
+
+ public InsufficientCreditException(String msg) {
+ super(msg);
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/exception/InsufficientFundsException.java b/src/main/java/com/dariawan/bankofjakarta/exception/InsufficientFundsException.java
new file mode 100644
index 0000000..ebf20da
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/exception/InsufficientFundsException.java
@@ -0,0 +1,15 @@
+package com.dariawan.bankofjakarta.exception;
+
+/**
+ * This application exception indicates that an account has insufficient funds
+ * to perform an operation.
+ */
+public class InsufficientFundsException extends Exception {
+
+ public InsufficientFundsException() {
+ }
+
+ public InsufficientFundsException(String msg) {
+ super(msg);
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/exception/InvalidParameterException.java b/src/main/java/com/dariawan/bankofjakarta/exception/InvalidParameterException.java
new file mode 100644
index 0000000..f5d0ef4
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/exception/InvalidParameterException.java
@@ -0,0 +1,15 @@
+package com.dariawan.bankofjakarta.exception;
+
+/**
+ * This an application exception is thrown when an illegal parameter is
+ * detected.
+ */
+public class InvalidParameterException extends Exception {
+
+ public InvalidParameterException() {
+ }
+
+ public InvalidParameterException(String msg) {
+ super(msg);
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/exception/TxNotFoundException.java b/src/main/java/com/dariawan/bankofjakarta/exception/TxNotFoundException.java
new file mode 100644
index 0000000..c3c1eac
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/exception/TxNotFoundException.java
@@ -0,0 +1,15 @@
+package com.dariawan.bankofjakarta.exception;
+
+/**
+ * This class application exception indicates that a Tx entity has not been
+ * found.
+ */
+public class TxNotFoundException extends Exception {
+
+ public TxNotFoundException() {
+ }
+
+ public TxNotFoundException(String msg) {
+ super(msg);
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/exception/db/CreateException.java b/src/main/java/com/dariawan/bankofjakarta/exception/db/CreateException.java
new file mode 100644
index 0000000..6c6f035
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/exception/db/CreateException.java
@@ -0,0 +1,15 @@
+package com.dariawan.bankofjakarta.exception.db;
+
+
+/**
+ * This db exception indicates that an create/insert failed.
+ */
+public class CreateException extends Exception {
+
+ public CreateException() {
+ }
+
+ public CreateException(String msg) {
+ super(msg);
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/exception/db/FinderException.java b/src/main/java/com/dariawan/bankofjakarta/exception/db/FinderException.java
new file mode 100644
index 0000000..7b2a8f2
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/exception/db/FinderException.java
@@ -0,0 +1,15 @@
+package com.dariawan.bankofjakarta.exception.db;
+
+
+/**
+ * This db exception indicates that an find a record is failed.
+ */
+public class FinderException extends Exception {
+
+ public FinderException() {
+ }
+
+ public FinderException(String msg) {
+ super(msg);
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/service/AccountService.java b/src/main/java/com/dariawan/bankofjakarta/service/AccountService.java
new file mode 100644
index 0000000..841b0b0
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/service/AccountService.java
@@ -0,0 +1,51 @@
+package com.dariawan.bankofjakarta.service;
+
+import com.dariawan.bankofjakarta.domain.Account;
+import com.dariawan.bankofjakarta.exception.AccountNotFoundException;
+import com.dariawan.bankofjakarta.exception.CustomerNotFoundException;
+import com.dariawan.bankofjakarta.exception.IllegalAccountTypeException;
+import com.dariawan.bankofjakarta.exception.InvalidParameterException;
+import java.util.ArrayList;
+import java.util.List;
+
+public interface AccountService {
+
+ // account creation and removal methods
+ public String createAccount(Account account, String customerId)
+ throws IllegalAccountTypeException,
+ CustomerNotFoundException, InvalidParameterException;
+
+ // makes a new account and enters it into db,
+ // customer for customerId must exist 1st
+ public void removeAccount(String accountId)
+ throws InvalidParameterException,
+ AccountNotFoundException;
+
+ // removes account from db
+ // customer-account relationship methods
+ public void addCustomerToAccount(String customerId, String accountId)
+ throws InvalidParameterException,
+ CustomerNotFoundException, AccountNotFoundException;
+
+ // adds another customer to the account
+ public void removeCustomerFromAccount(String customerId, String accountId)
+ throws InvalidParameterException,
+ CustomerNotFoundException, AccountNotFoundException;
+
+ // removes a customer from the account, but
+ // the customer is not removed from the db
+ public List getAccountsOfCustomer(String customerId)
+ throws InvalidParameterException,
+ CustomerNotFoundException;
+
+ // returns an ArrayList of Account objects
+ // that correspond to the accounts for the specified
+ // customer
+ public ArrayList getCustomerIds(String accountId)
+ throws InvalidParameterException,
+ AccountNotFoundException;
+
+ public Account getDetails(String accountId)
+ throws InvalidParameterException,
+ AccountNotFoundException;
+} // AccountService
diff --git a/src/main/java/com/dariawan/bankofjakarta/service/CustomerService.java b/src/main/java/com/dariawan/bankofjakarta/service/CustomerService.java
new file mode 100644
index 0000000..7e9c880
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/service/CustomerService.java
@@ -0,0 +1,45 @@
+package com.dariawan.bankofjakarta.service;
+
+import com.dariawan.bankofjakarta.domain.Customer;
+import com.dariawan.bankofjakarta.exception.CustomerNotFoundException;
+import com.dariawan.bankofjakarta.exception.InvalidParameterException;
+import java.util.ArrayList;
+import java.util.List;
+
+public interface CustomerService {
+ // customer creation and removal methods
+
+ // makes a new customer and enters it into db,
+ // returns customerId
+ String createCustomer(Customer customer) throws InvalidParameterException;
+
+ // removes customer from db
+ void removeCustomer(String customerId)
+ throws CustomerNotFoundException, InvalidParameterException;
+
+ // getters
+ // returns the details of a customer
+ Customer getDetails(String customerId)
+ throws CustomerNotFoundException, InvalidParameterException;
+
+ // returns a List of Customer objects
+ // that correspond to the customers for the specified
+ // account
+ List getCustomersOfAccount(String accountId)
+ throws CustomerNotFoundException, InvalidParameterException;
+
+ // returns a List of Customer objects
+ // that correspond to the customers for the specified
+ // last name; if now customers are found the ArrayList
+ // is empty
+ List getCustomersOfLastName(String lastName) throws InvalidParameterException;
+
+ // setters
+ void setName(String lastName, String firstName,
+ String middleInitial, String customerId)
+ throws CustomerNotFoundException, InvalidParameterException;
+
+ void setAddress(String street, String city, String state,
+ String zip, String phone, String email, String customerId)
+ throws CustomerNotFoundException, InvalidParameterException;
+} // CustomerService
diff --git a/src/main/java/com/dariawan/bankofjakarta/service/TxService.java b/src/main/java/com/dariawan/bankofjakarta/service/TxService.java
new file mode 100644
index 0000000..47a373f
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/service/TxService.java
@@ -0,0 +1,56 @@
+package com.dariawan.bankofjakarta.service;
+
+import com.dariawan.bankofjakarta.domain.Tx;
+import com.dariawan.bankofjakarta.exception.AccountNotFoundException;
+import com.dariawan.bankofjakarta.exception.IllegalAccountTypeException;
+import com.dariawan.bankofjakarta.exception.InsufficientCreditException;
+import com.dariawan.bankofjakarta.exception.InsufficientFundsException;
+import com.dariawan.bankofjakarta.exception.InvalidParameterException;
+import com.dariawan.bankofjakarta.exception.TxNotFoundException;
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
+public interface TxService {
+
+ // getters
+ List getTxsOfAccount(Date startDate, Date endDate, String accountId)
+ throws InvalidParameterException;
+
+ // returns an ArrayList of Tx objects
+ // that correspond to the txs for the specified
+ // account
+ Tx getDetails(String txId)
+ throws TxNotFoundException, InvalidParameterException;
+
+ // returns the Tx for the specified tx
+ // business transaction methods
+ void withdraw(BigDecimal amount, String description, String accountId)
+ throws InvalidParameterException,
+ AccountNotFoundException, IllegalAccountTypeException,
+ InsufficientFundsException;
+
+ // withdraws funds from a non-credit account
+ void deposit(BigDecimal amount, String description, String accountId)
+ throws InvalidParameterException,
+ AccountNotFoundException, IllegalAccountTypeException;
+
+ // deposits funds to a non-credit account
+ void transferFunds(BigDecimal amount, String description,
+ String fromAccountId, String toAccountId)
+ throws InvalidParameterException,
+ AccountNotFoundException, InsufficientFundsException,
+ InsufficientCreditException;
+
+ // transfers funds from one account to another
+ void makeCharge(BigDecimal amount, String description, String accountId)
+ throws InvalidParameterException, AccountNotFoundException,
+ IllegalAccountTypeException, InsufficientCreditException;
+
+ // makes a charge to a credit account
+ void makePayment(BigDecimal amount, String description, String accountId)
+ throws InvalidParameterException, AccountNotFoundException,
+ IllegalAccountTypeException;
+
+ // makes a payment to a credit account
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/service/impl/AccountServiceImpl.java b/src/main/java/com/dariawan/bankofjakarta/service/impl/AccountServiceImpl.java
new file mode 100644
index 0000000..2bac018
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/service/impl/AccountServiceImpl.java
@@ -0,0 +1,296 @@
+package com.dariawan.bankofjakarta.service.impl;
+
+import com.dariawan.bankofjakarta.dao.AccountDao;
+import com.dariawan.bankofjakarta.dao.CustomerAccountDao;
+import com.dariawan.bankofjakarta.dao.CustomerDao;
+import com.dariawan.bankofjakarta.dao.NextIdDao;
+import com.dariawan.bankofjakarta.domain.Account;
+import com.dariawan.bankofjakarta.domain.Customer;
+import com.dariawan.bankofjakarta.domain.NextId;
+import com.dariawan.bankofjakarta.exception.AccountNotFoundException;
+import com.dariawan.bankofjakarta.exception.CustomerNotFoundException;
+import com.dariawan.bankofjakarta.exception.IllegalAccountTypeException;
+import com.dariawan.bankofjakarta.exception.InvalidParameterException;
+import com.dariawan.bankofjakarta.exception.db.FinderException;
+import com.dariawan.bankofjakarta.service.AccountService;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+public class AccountServiceImpl implements AccountService {
+
+ private AccountDao accountDao;
+ private CustomerDao customerDao;
+ private NextIdDao nextIdDao;
+ private CustomerAccountDao customerAccountDao;
+
+ public void setAccountDao(AccountDao accountDao) {
+ this.accountDao = accountDao;
+ }
+
+ public void setCustomerDao(CustomerDao customerDao) {
+ this.customerDao = customerDao;
+ }
+
+ public void setNextIdDao(NextIdDao nextIdDao) {
+ this.nextIdDao = nextIdDao;
+ }
+
+ public void setCustomerAccountDao(CustomerAccountDao customerAccountDao) {
+ this.customerAccountDao = customerAccountDao;
+ }
+
+ // account creation and removal methods
+ public String createAccount(Account account, String customerId)
+ throws IllegalAccountTypeException, CustomerNotFoundException,
+ InvalidParameterException {
+ // makes a new account and enters it into db,
+ Customer customer = null;
+
+ // System.out.println("AccountServiceImpl createAccount");
+ if (account.getType() == null) {
+ throw new InvalidParameterException("null type");
+ } else if (account.getDescription() == null) {
+ throw new InvalidParameterException("null description");
+ } else if (account.getBeginBalanceTimeStamp() == null) {
+ throw new InvalidParameterException("null beginBalanceTimeStamp");
+ } else if (customerId == null) {
+ throw new InvalidParameterException("null customerId");
+ }
+
+ try {
+ customer = customerDao.findByPrimaryKey(customerId);
+ } catch (FinderException ex) {
+ throw new CustomerNotFoundException();
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex.getMessage());
+ }
+
+ try {
+ NextId nextId = nextIdDao.findByPrimaryKey("account");
+ // account = accountDao.create(nextId.getNextId(), details.getType(),
+ // details.getDescription(), details.getBalance(),
+ // details.getCreditLine(), details.getBeginBalance(),
+ // details.getBeginBalanceTimeStamp());
+
+ account.setAccountId(String.valueOf(nextId.getId()));
+ account = accountDao.create(account);
+ customerAccountDao.add(customer, account);
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex.getMessage());
+ }
+
+ return account.getAccountId();
+ }
+
+ public void removeAccount(String accountId)
+ throws InvalidParameterException, AccountNotFoundException {
+ // removes account
+ Account account = null;
+
+ // System.out.println("AccountServiceImpl removeAccount");
+ if (accountId == null) {
+ throw new InvalidParameterException("null accountId");
+ }
+
+ try {
+ account = accountDao.findByPrimaryKey(accountId);
+
+ customerAccountDao.removeByAccount(account);
+ accountDao.remove(account);
+ // account.remove();
+ } catch (FinderException ex) {
+ throw new AccountNotFoundException();
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex.getMessage());
+ }
+ }
+
+ // customer-account relationship methods
+ public void addCustomerToAccount(String customerId, String accountId)
+ throws InvalidParameterException, CustomerNotFoundException,
+ AccountNotFoundException {
+ // adds another customer to the account
+ Customer customer = null;
+ Account account = null;
+
+ // System.out.println("AccountServiceImpl addCustomerToAccount");
+ if (customerId == null) {
+ throw new InvalidParameterException("null customerId");
+ } else if (accountId == null) {
+ throw new InvalidParameterException("null accountId");
+ }
+
+ try {
+ // System.out.println("AccountServiceImpl Getting the account: "
+ // + accountId);
+ account = accountDao.findByPrimaryKey(accountId);
+ } catch (FinderException ex) {
+ throw new AccountNotFoundException();
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex.getMessage());
+ }
+
+ try {
+ // System.out.println("AccountServiceImpl Getting the customer: "
+ // + customerId);
+ customer = customerDao.findByPrimaryKey(customerId);
+
+ // System.out.println(
+ // "AccountServiceImpl Adding the customer to the account.");
+ // account.addCustomer(customer);
+ customerAccountDao.add(customer, account);
+ } catch (FinderException ex) {
+ throw new CustomerNotFoundException();
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex.getMessage());
+ }
+ }
+
+ public void removeCustomerFromAccount(String customerId, String accountId)
+ throws InvalidParameterException, CustomerNotFoundException,
+ AccountNotFoundException {
+ // removes a customer from this account, but
+ // the customer is not removed from the db
+ Account account = null;
+ Customer customer = null;
+
+ if (customerId == null) {
+ throw new InvalidParameterException("null customerId");
+ } else if (accountId == null) {
+ throw new InvalidParameterException("null accountId");
+ }
+
+ // System.out.println("AccountServiceImpl removeCustomerFromAccount");
+
+ try {
+ account = accountDao.findByPrimaryKey(accountId);
+ } catch (FinderException ex) {
+ throw new AccountNotFoundException();
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex.getMessage());
+ }
+
+ try {
+ customer = customerDao.findByPrimaryKey(customerId);
+ // account.removeCustomer(customer);
+ customerAccountDao.removeCustomerFromAccount(customer, account);
+ } catch (FinderException ex) {
+ throw new CustomerNotFoundException();
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex.getMessage());
+ }
+ }
+
+ // getters
+ public List getAccountsOfCustomer(String customerId)
+ throws InvalidParameterException, CustomerNotFoundException {
+ // returns an ArrayList of Account
+ // that correspond to the accounts for the specified
+ // customer
+ // System.out.println("AccountServiceImpl getAccountsOfCustomer");
+
+ List accounts = null;
+ Customer customer = null;
+
+ if (customerId == null) {
+ throw new InvalidParameterException("null customerId");
+ }
+
+ try {
+ customer = customerDao.findByPrimaryKey(customerId);
+ // accounts = customer.getAccounts();
+ accounts = accountDao.findByCustomerId(customer.getCustomerId());
+ } catch (FinderException ex) {
+ throw new CustomerNotFoundException();
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex.getMessage());
+ }
+
+ // return copyAccountsToDetails(accounts);
+ return accounts;
+ }
+
+ public ArrayList getCustomerIds(String accountId)
+ throws InvalidParameterException, AccountNotFoundException {
+ // System.out.println("AccountServiceImpl getCustomerIds");
+
+ List customers = null;
+ Account account = null;
+
+ if (accountId == null) {
+ throw new InvalidParameterException("null accountId");
+ }
+
+ try {
+ account = accountDao.findByPrimaryKey(accountId);
+ // customers = account.getCustomers();
+ customers = customerDao.findByAccountId(account.getAccountId());
+ } catch (FinderException ex) {
+ throw new AccountNotFoundException();
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex.getMessage());
+ }
+
+ return copyCustomerIdsToArrayList(customers);
+ }
+
+ public Account getDetails(String accountId)
+ throws InvalidParameterException, AccountNotFoundException {
+ // System.out.println("AccountServiceImpl getDetails");
+
+ Account details = null;
+ Account account = null;
+
+ if (accountId == null) {
+ throw new InvalidParameterException("null accountId");
+ }
+
+ try {
+ account = accountDao.findByPrimaryKey(accountId);
+ details = new Account(accountId, account.getType(),
+ account.getDescription(), account.getBalance(),
+ account.getCreditLine(), account.getBeginBalance(),
+ account.getBeginBalanceTimeStamp());
+ } catch (FinderException ex) {
+ throw new AccountNotFoundException();
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex.getMessage());
+ }
+
+ return details;
+ }
+
+ // private methods
+ /*
+ private ArrayList copyAccountsToDetails(Collection accounts) {
+ ArrayList detailsList = new ArrayList();
+ Iterator i = accounts.iterator();
+
+ while (i.hasNext()) {
+ Account account = (Account) i.next();
+ Account details
+ = new Account(account.getAccountId(), account.getType(),
+ account.getDescription(), account.getBalance(),
+ account.getCreditLine(), account.getBeginBalance(),
+ account.getBeginBalanceTimeStamp());
+ detailsList.add(details);
+ }
+
+ return detailsList;
+ }
+ */
+
+ private ArrayList copyCustomerIdsToArrayList(Collection customers) {
+ ArrayList customerIdList = new ArrayList();
+ Iterator i = customers.iterator();
+
+ while (i.hasNext()) {
+ Customer customer = (Customer) i.next();
+ customerIdList.add(customer.getCustomerId());
+ }
+
+ return customerIdList;
+ }
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/service/impl/CustomerServiceImpl.java b/src/main/java/com/dariawan/bankofjakarta/service/impl/CustomerServiceImpl.java
new file mode 100644
index 0000000..05b7ae4
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/service/impl/CustomerServiceImpl.java
@@ -0,0 +1,261 @@
+package com.dariawan.bankofjakarta.service.impl;
+
+import com.dariawan.bankofjakarta.dao.AccountDao;
+import com.dariawan.bankofjakarta.dao.CustomerAccountDao;
+import com.dariawan.bankofjakarta.dao.CustomerDao;
+import com.dariawan.bankofjakarta.dao.NextIdDao;
+import com.dariawan.bankofjakarta.domain.Account;
+import com.dariawan.bankofjakarta.domain.Customer;
+import com.dariawan.bankofjakarta.domain.NextId;
+import com.dariawan.bankofjakarta.exception.CustomerNotFoundException;
+import com.dariawan.bankofjakarta.exception.InvalidParameterException;
+import com.dariawan.bankofjakarta.exception.db.FinderException;
+import com.dariawan.bankofjakarta.service.CustomerService;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+public class CustomerServiceImpl implements CustomerService {
+
+ private CustomerDao customerDao;
+ private AccountDao accountDao;
+ private NextIdDao nextIdDao;
+
+ // customer creation and removal methods
+ public String createCustomer(Customer customer)
+ throws InvalidParameterException {
+ // makes a new customer and enters it into db
+
+ // System.out.println("CustomerServiceImpl createCustomer");
+
+ if (customer.getLastName() == null) {
+ throw new InvalidParameterException("null lastName");
+ }
+
+ if (customer.getFirstName() == null) {
+ throw new InvalidParameterException("null firstName");
+ }
+
+ try {
+ // System.out.println("CustomerServiceImpl creating nextId bean");
+ NextId nextId = nextIdDao.findByPrimaryKey("customer");
+ // System.out.println("Creating LocalCustomer with customerDao.create");
+
+ // customer = customerDao.create(nextId.getNextId(),
+ // details.getLastName(), details.getFirstName(),
+ // details.getMiddleInitial(), details.getStreet(),
+ // details.getCity(), details.getState(), details.getZip(),
+ // details.getPhone(), details.getEmail());
+ customer.setCustomerId(String.valueOf(nextId.getId()));
+ customer = customerDao.create(customer);
+ } catch (Exception ex) {
+ throw new IllegalStateException("createCustomer: " + ex.getMessage());
+ }
+
+ return customer.getCustomerId();
+ }
+
+ public void removeCustomer(String customerId)
+ throws CustomerNotFoundException, InvalidParameterException {
+ // removes customer from db
+ // System.out.println("CustomerServiceImpl removeCustomer");
+
+ if (customerId == null) {
+ throw new InvalidParameterException("null customerId");
+ }
+
+ try {
+ Customer customer = customerDao.findByPrimaryKey(customerId);
+ // customer.remove();
+ customerDao.remove(customer);
+ } catch (Exception ex) {
+ throw new IllegalStateException("removeCustomer: " + ex.getMessage());
+ }
+ }
+
+ // getters
+ public Customer getDetails(String customerId)
+ throws CustomerNotFoundException, InvalidParameterException {
+ // returns the Customer for the specified customer
+ // System.out.println("CustomerServiceImpl getDetails");
+
+ Customer result;
+
+ if (customerId == null) {
+ throw new InvalidParameterException("null customerId");
+ }
+
+ try {
+ result = customerDao.findByPrimaryKey(customerId);
+ // result = new Customer(customer.getLastName(),
+ // customer.getFirstName(), customer.getMiddleInitial(),
+ // customer.getStreet(), customer.getCity(),
+ // customer.getState(), customer.getZip(),
+ // customer.getPhone(), customer.getEmail());
+ } catch (FinderException ex) {
+ throw new CustomerNotFoundException();
+ } catch (Exception ex) {
+ throw new IllegalStateException("getDetails: " + ex.getMessage());
+ }
+
+ return result;
+ }
+
+ public List getCustomersOfAccount(String accountId)
+ throws InvalidParameterException {
+ // returns an ArrayList of Customer
+ // that correspond to the accountId specified
+ // System.out.println("CustomerServiceImpl getCustomersOfAccount");
+
+ List customers = null;
+
+ if (accountId == null) {
+ throw new InvalidParameterException("null accountId");
+ }
+
+ try {
+ Account account = accountDao.findByPrimaryKey(accountId);
+ // customers = account.getCustomers();
+ customers = customerDao.findByAccountId(account.getAccountId());
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex.getMessage());
+ }
+
+ // return copyCustomersToDetails(customers);
+ return customers;
+ }
+
+ public List getCustomersOfLastName(String lastName)
+ throws InvalidParameterException {
+ // returns an ArrayList of Customer
+ // that correspond to the the lastName specified
+ // returns null if no customers are found
+ // System.out.println("CustomerServiceImpl getCustomersOfLastName");
+
+ List customers = null;
+
+ if (lastName == null) {
+ throw new InvalidParameterException("null lastName");
+ }
+
+ try {
+ customers = customerDao.findByLastName(lastName);
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex.getMessage());
+ }
+
+ // return copyCustomersToDetails(customers);
+ return customers;
+ }
+
+ // setters
+ public void setName(String lastName, String firstName,
+ String middleInitial, String customerId)
+ throws CustomerNotFoundException, InvalidParameterException {
+ // System.out.println("CustomerServiceImpl setName");
+
+ if (lastName == null) {
+ throw new InvalidParameterException("null lastName");
+ }
+
+ if (firstName == null) {
+ throw new InvalidParameterException("null firstName");
+ }
+
+ if (customerId == null) {
+ throw new InvalidParameterException("null customerId");
+ }
+
+ if (customerExists(customerId) == false) {
+ throw new CustomerNotFoundException(customerId);
+ }
+
+ try {
+ Customer customer = customerDao.findByPrimaryKey(customerId);
+ customer.setLastName(lastName);
+ customer.setFirstName(firstName);
+ customer.setMiddleInitial(middleInitial);
+ } catch (Exception ex) {
+ throw new IllegalStateException("setName: " + ex.getMessage());
+ }
+ }
+
+ public void setAddress(String street, String city, String state,
+ String zip, String phone, String email, String customerId)
+ throws CustomerNotFoundException, InvalidParameterException {
+ // System.out.println("CustomerServiceImpl setAddress");
+
+ if (street == null) {
+ throw new InvalidParameterException("null street");
+ }
+
+ if (city == null) {
+ throw new InvalidParameterException("null city");
+ }
+
+ if (state == null) {
+ throw new InvalidParameterException("null state");
+ }
+
+ if (customerId == null) {
+ throw new InvalidParameterException("null customerId");
+ }
+
+ try {
+ Customer customer = customerDao.findByPrimaryKey(customerId);
+ customer.setStreet(street);
+ customer.setCity(city);
+ customer.setState(state);
+ customer.setZip(zip);
+ customer.setPhone(phone);
+ customer.setEmail(email);
+ } catch (Exception ex) {
+ throw new IllegalStateException("setAddress: " + ex.getMessage());
+ }
+ }
+
+ // private methods
+ private boolean customerExists(String customerId) {
+ // If a business method has been invoked with
+ // a different customerId, then update the
+ // customerId and customer variables.
+ // Return null if the customer is not found.
+ Customer customer;
+
+ // System.out.println("CustomerServiceImpl customerExists");
+
+ try {
+ customer = customerDao.findByPrimaryKey(customerId);
+ } catch (Exception ex) {
+ return false;
+ }
+
+ return customer==null;
+ }
+
+ /*
+ private ArrayList copyCustomersToDetails(Collection customers) {
+ ArrayList detailsList = new ArrayList();
+ Iterator i = customers.iterator();
+
+ try {
+ while (i.hasNext()) {
+ Customer customer = (Customer) i.next();
+ Customer details =
+ new Customer(customer.getCustomerId(),
+ customer.getLastName(), customer.getFirstName(),
+ customer.getMiddleInitial(), customer.getStreet(),
+ customer.getCity(), customer.getState(),
+ customer.getZip(), customer.getPhone(),
+ customer.getEmail());
+ detailsList.add(details);
+ }
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex.getMessage());
+ }
+
+ return detailsList;
+ }
+ */
+} // CustomerServiceImpl
diff --git a/src/main/java/com/dariawan/bankofjakarta/service/impl/TxServiceImpl.java b/src/main/java/com/dariawan/bankofjakarta/service/impl/TxServiceImpl.java
new file mode 100644
index 0000000..8f11d46
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/service/impl/TxServiceImpl.java
@@ -0,0 +1,270 @@
+package com.dariawan.bankofjakarta.service.impl;
+
+import com.dariawan.bankofjakarta.dao.AccountDao;
+import com.dariawan.bankofjakarta.dao.NextIdDao;
+import com.dariawan.bankofjakarta.dao.TxDao;
+import com.dariawan.bankofjakarta.domain.Account;
+import com.dariawan.bankofjakarta.domain.NextId;
+import com.dariawan.bankofjakarta.domain.Tx;
+import com.dariawan.bankofjakarta.exception.AccountNotFoundException;
+import com.dariawan.bankofjakarta.exception.IllegalAccountTypeException;
+import com.dariawan.bankofjakarta.exception.InsufficientCreditException;
+import com.dariawan.bankofjakarta.exception.InsufficientFundsException;
+import com.dariawan.bankofjakarta.exception.InvalidParameterException;
+import com.dariawan.bankofjakarta.exception.TxNotFoundException;
+import com.dariawan.bankofjakarta.service.TxService;
+import com.dariawan.bankofjakarta.util.DomainUtil;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+public class TxServiceImpl implements TxService {
+
+ private TxDao txDao;
+ private AccountDao accountDao;
+ private NextIdDao nextIdDao;
+ private BigDecimal bigZero = new BigDecimal("0.00");
+
+ public List getTxsOfAccount(Date startDate, Date endDate, String accountId)
+ throws InvalidParameterException {
+ // System.out.println("TxControllerBean getTxsOfAccount");
+
+ List txList = new ArrayList<>();
+
+ if (startDate == null) {
+ throw new InvalidParameterException("null startDate");
+ }
+
+ if (endDate == null) {
+ throw new InvalidParameterException("null endDate");
+ }
+
+ if (accountId == null) {
+ throw new InvalidParameterException("null accountId");
+ }
+
+ try {
+ txList = txDao.findByAccountId(startDate, endDate, accountId);
+ } catch (Exception ex) {
+ return txList;
+ }
+
+ // return copyTxsToDetails(txIds);
+ return txList;
+ } // getTxsOfAccount
+
+ public Tx getDetails(String txId)
+ throws TxNotFoundException, InvalidParameterException {
+ // System.out.println("TxControllerBean getDetails");
+
+ Tx tx;
+
+ if (txId == null) {
+ throw new InvalidParameterException("null txId");
+ }
+
+ try {
+ tx = txDao.findByPrimaryKey(txId);
+ // tx = new Tx(tx.getTxId(), tx.getTimeStamp(),
+ // tx.getAmount(), tx.getBalance(), tx.getDescription());
+ } catch (Exception ex) {
+ throw new TxNotFoundException(txId);
+ }
+
+ return tx;
+ } // getDetails
+
+ public void withdraw(BigDecimal amount, String description, String accountId)
+ throws InvalidParameterException, AccountNotFoundException,
+ IllegalAccountTypeException, InsufficientFundsException {
+ // System.out.println("TxControllerBean withdraw");
+
+ Account account = checkAccountArgs(amount, description, accountId);
+
+ String type = account.getType();
+
+ if (DomainUtil.isCreditAccount(type)) {
+ throw new IllegalAccountTypeException(type);
+ }
+
+ BigDecimal newBalance = account.getBalance()
+ .subtract(amount);
+
+ if (newBalance.compareTo(bigZero) == -1) {
+ throw new InsufficientFundsException();
+ }
+
+ executeTx(amount.negate(), description, newBalance, account);
+ }
+
+ public void deposit(BigDecimal amount, String description, String accountId)
+ throws InvalidParameterException, AccountNotFoundException,
+ IllegalAccountTypeException {
+ // System.out.println("TxControllerBean deposit");
+
+ Account account = checkAccountArgs(amount, description, accountId);
+
+ String type = account.getType();
+
+ if (DomainUtil.isCreditAccount(type)) {
+ throw new IllegalAccountTypeException(type);
+ }
+
+ BigDecimal newBalance = account.getBalance()
+ .add(amount);
+ executeTx(amount, description, newBalance, account);
+ }
+
+ public void makeCharge(BigDecimal amount, String description,
+ String accountId)
+ throws InvalidParameterException, AccountNotFoundException,
+ IllegalAccountTypeException, InsufficientCreditException {
+ // System.out.println("TxControllerBean charge");
+
+ Account account = checkAccountArgs(amount, description, accountId);
+
+ String type = account.getType();
+
+ if (DomainUtil.isCreditAccount(type) == false) {
+ throw new IllegalAccountTypeException(type);
+ }
+
+ BigDecimal newBalance = account.getBalance()
+ .add(amount);
+
+ if (newBalance.compareTo(account.getCreditLine()) == 1) {
+ throw new InsufficientCreditException();
+ }
+
+ executeTx(amount, description, newBalance, account);
+ }
+
+ public void makePayment(BigDecimal amount, String description,
+ String accountId)
+ throws InvalidParameterException, AccountNotFoundException,
+ IllegalAccountTypeException {
+ // System.out.println("TxControllerBean makePayment");
+
+ Account account = checkAccountArgs(amount, description, accountId);
+
+ String type = account.getType();
+
+ if (DomainUtil.isCreditAccount(type) == false) {
+ throw new IllegalAccountTypeException(type);
+ }
+
+ BigDecimal newBalance = account.getBalance()
+ .subtract(amount);
+ executeTx(amount, description, newBalance, account);
+ }
+
+ public void transferFunds(BigDecimal amount, String description,
+ String fromAccountId, String toAccountId)
+ throws InvalidParameterException, AccountNotFoundException,
+ InsufficientFundsException, InsufficientCreditException {
+ Account fromAccount = checkAccountArgs(amount, description, fromAccountId);
+ Account toAccount = checkAccountArgs(amount, description, toAccountId);
+
+ String fromType = fromAccount.getType();
+ BigDecimal fromBalance = fromAccount.getBalance();
+
+ if (DomainUtil.isCreditAccount(fromType)) {
+ BigDecimal fromNewBalance = fromBalance.add(amount);
+
+ if (fromNewBalance.compareTo(fromAccount.getCreditLine()) == 1) {
+ throw new InsufficientCreditException();
+ }
+
+ executeTx(amount, description, fromNewBalance, fromAccount);
+ } else {
+ BigDecimal fromNewBalance = fromBalance.subtract(amount);
+
+ if (fromNewBalance.compareTo(bigZero) == -1) {
+ throw new InsufficientFundsException();
+ }
+
+ executeTx(amount.negate(), description, fromNewBalance, fromAccount);
+ }
+
+ String toType = toAccount.getType();
+ BigDecimal toBalance = toAccount.getBalance();
+
+ if (DomainUtil.isCreditAccount(toType)) {
+ BigDecimal toNewBalance = toBalance.subtract(amount);
+ executeTx(amount.negate(), description, toNewBalance, toAccount);
+ } else {
+ BigDecimal toNewBalance = toBalance.add(amount);
+ executeTx(amount, description, toNewBalance, toAccount);
+ }
+ } // transferFunds
+
+ // private methods
+ private void executeTx(BigDecimal amount, String description,
+ BigDecimal newBalance, Account account) {
+ // System.out.println("TxControllerBean executeTx");
+
+ Tx tx = null;
+ NextId nextId = null;
+
+ // Set the new balance and create a new transaction
+ try {
+ account.setBalance(newBalance);
+ nextId = nextIdDao.findByPrimaryKey("tx");
+ // tx = txDao.create(nextId.getId(), account,
+ // new java.util.Date(), amount, newBalance, description);
+ tx = new Tx(String.valueOf(nextId.getId()), account.getAccountId(), new Date(),
+ amount, newBalance, description);
+ txDao.create(tx);
+ } catch (Exception ex) {
+ throw new IllegalStateException("executeTx: " + ex.getMessage());
+ }
+ }
+
+ private Account checkAccountArgs(BigDecimal amount,
+ String description, String accountId)
+ throws InvalidParameterException, AccountNotFoundException {
+ Account account = null;
+
+ if (description == null) {
+ throw new InvalidParameterException("null description");
+ }
+
+ if (accountId == null) {
+ throw new InvalidParameterException("null accountId");
+ }
+
+ if (amount.compareTo(bigZero) != 1) {
+ throw new InvalidParameterException("amount <= 0");
+ }
+
+ try {
+ account = accountDao.findByPrimaryKey(accountId);
+ } catch (Exception ex) {
+ throw new AccountNotFoundException(accountId);
+ }
+
+ return account;
+ } // checkAccountArgs
+
+ /*
+ private ArrayList copyTxsToDetails(Collection txs) {
+ ArrayList detailsList = new ArrayList();
+ Iterator i = txs.iterator();
+
+ try {
+ while (i.hasNext()) {
+ Tx tx = (Tx) i.next();
+ Tx Tx
+ = new Tx(tx.getTxId(), tx.getTimeStamp(),
+ tx.getAmount(), tx.getBalance(), tx.getDescription());
+ detailsList.add(Tx);
+ }
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex.getMessage());
+ }
+
+ return detailsList;
+ }
+ */
+}
diff --git a/src/main/java/com/dariawan/bankofjakarta/util/DomainUtil.java b/src/main/java/com/dariawan/bankofjakarta/util/DomainUtil.java
new file mode 100644
index 0000000..1572628
--- /dev/null
+++ b/src/main/java/com/dariawan/bankofjakarta/util/DomainUtil.java
@@ -0,0 +1,37 @@
+package com.dariawan.bankofjakarta.util;
+
+import com.dariawan.bankofjakarta.exception.IllegalAccountTypeException;
+
+public class DomainUtil {
+
+ // The accountTypes array stores the valid account types.
+ private static String[] accountTypes
+ = {"Checking", "Savings", "Credit", "Money Market"};
+
+ public static String[] getAccountTypes() {
+ return accountTypes;
+ }
+
+ public static void checkAccountType(String type)
+ throws IllegalAccountTypeException {
+ boolean foundIt = false;
+
+ for (int i = 0; i < accountTypes.length; i++) {
+ if (accountTypes[i].equals(type)) {
+ foundIt = true;
+ }
+ }
+
+ if (foundIt == false) {
+ throw new IllegalAccountTypeException(type);
+ }
+ }
+
+ public static boolean isCreditAccount(String type) {
+ if (type.equals("Credit")) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+} // DomainUtil
diff --git a/src/test/java/com/dariawan/bankofjakarta/AppTest.java b/src/test/java/com/dariawan/bankofjakarta/AppTest.java
new file mode 100644
index 0000000..a07ad7c
--- /dev/null
+++ b/src/test/java/com/dariawan/bankofjakarta/AppTest.java
@@ -0,0 +1,38 @@
+package com.dariawan.bankofjakarta;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}