-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e70c81
commit 09cd5e9
Showing
85 changed files
with
516 additions
and
104 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 103 additions & 1 deletion
104
src/main/java/com/robb/banking/daos/Account_infoDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,106 @@ | ||
package com.robb.banking.daos; | ||
|
||
public class Account_infoDao { | ||
import com.robb.banking.exceptions.ResourcePersistanceException; | ||
import com.robb.banking.models.Account_info; | ||
import com.robb.banking.util.ConnectionFactory; | ||
import com.robb.banking.util.collections.LinkedList; | ||
import com.robb.banking.util.logging.Logger; | ||
import java.io.IOException; | ||
import java.sql.*; | ||
import java.util.List; | ||
|
||
public class Account_infoDao implements Crudable<Account_info> { | ||
|
||
private Logger logger = Logger.getLogger(); | ||
|
||
@Override | ||
public Account_info create(Account_info newAccount_info) { | ||
try (Connection conn = ConnectionFactory.getInstance().getConnection();) { | ||
String sql = "insert into account info values (default, ?, ?, ?, ?, ?"; | ||
|
||
PreparedStatement ps = conn.prepareStatement(sql); | ||
|
||
ps.setString(1, newAccount_info.getAccount_number()); | ||
ps.setInt(2, newAccount_info.getAccount_balance()); | ||
ps.setString(3, newAccount_info.getAccount_type()); | ||
ps.setString(4, newAccount_info.getUser_email()); | ||
ps.setString(5, newAccount_info.getMemo()); | ||
|
||
int checkInsert = ps.executeUpdate(); | ||
|
||
if (checkInsert == 0) { | ||
throw new ResourcePersistanceException("Account info was not entered into our database due to some issues."); | ||
} | ||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
return newAccount_info; | ||
} | ||
|
||
@Override | ||
public List<Account_info> findAll() throws IOException { | ||
List<Account_info> account_infos = new LinkedList<>(); | ||
|
||
try (Connection conn = ConnectionFactory.getInstance().getConnection();) { | ||
|
||
String sql = "select * from Account info"; | ||
Statement s = conn.createStatement(); | ||
|
||
ResultSet rs = s.executeQuery(sql); | ||
|
||
while (rs.next()) { | ||
Account_info account_info = new Account_info(); | ||
|
||
account_info.setAccount_number(rs.getString("Account_number")); | ||
account_info.setAccount_balance(rs.getInt("Account_balance")); | ||
account_info.setAccount_type(rs.getString("Account_type")); | ||
account_info.setUser_email(rs.getString("User_email")); | ||
account_info.setMemo(rs.getString("Memo")); | ||
|
||
account_infos.add(account_info); | ||
} | ||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
|
||
return account_infos; | ||
} | ||
|
||
@Override | ||
public Account_info findById(String id) { | ||
try (Connection conn = ConnectionFactory.getInstance().getConnection();) { | ||
|
||
String sql = "select * from account_info where id = ?"; | ||
PreparedStatement ps = conn.prepareStatement(sql); | ||
|
||
ps.setInt(1, Integer.parseInt(id)); | ||
|
||
ResultSet rs = ps.executeQuery(); | ||
|
||
if(!rs.next()){ | ||
throw new ResourcePersistanceException("Account_info was not found in the database. Please check ID entered was correct."); | ||
} | ||
|
||
Account_info account_info = new Account_info(); | ||
|
||
account_info.setAccount_number(rs.getString("Account_number")); | ||
account_info.setAccount_balance(rs.getInt("Account_balance")); | ||
account_info.setAccount_type(rs.getString("Account_type")); | ||
account_info.setUser_email(rs.getString("User_email")); | ||
account_info.setMemo(rs.getString("Memo")); | ||
|
||
return account_info; | ||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean update(Account_info updatedAccount_info) { return false; } | ||
|
||
@Override | ||
public boolean delete(String id) { return false; } | ||
} |
47 changes: 46 additions & 1 deletion
47
src/main/java/com/robb/banking/util/collections/ArrayList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,49 @@ | ||
package com.robb.banking.util.collections; | ||
|
||
public class ArrayList { | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import java.util.Arrays; | ||
|
||
@JsonSerialize(using = ArrayListSerializer.class) | ||
public class ArrayList<T> implements List<T> { | ||
|
||
protected int size; | ||
protected Object[] elements; | ||
public ArrayList() { elements = new Object[16]; } | ||
|
||
public ArrayList(int initialCapacity) { elements = new Object[initialCapacity]; } | ||
|
||
@Override | ||
public boolean add(T element) { | ||
resizeBackingArrayIfNeeded(); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean contains(T element) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { return size == 0; } | ||
|
||
@Override | ||
public boolean remove(T element) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public int size() { return size; } | ||
|
||
@Override | ||
public T get(int index) { | ||
return null; | ||
} | ||
|
||
protected void resizeBackingArrayIfNeeded() { | ||
|
||
} | ||
|
||
@Override | ||
public String toString() { return Arrays.toString(elements); } | ||
} |
28 changes: 27 additions & 1 deletion
28
src/main/java/com/robb/banking/util/collections/ArrayListSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,30 @@ | ||
package com.robb.banking.util.collections; | ||
|
||
public class ArrayListSerializer { | ||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.ser.std.StdSerializer; | ||
import com.robb.banking.models.Customer_info; | ||
|
||
import java.io.IOException; | ||
|
||
public class ArrayListSerializer extends StdSerializer<ArrayList> { | ||
|
||
public ArrayListSerializer() { this(null); } | ||
|
||
public ArrayListSerializer(Class<ArrayList> t) { super(t); } | ||
|
||
@Override | ||
public void serialize(ArrayList arrayList, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { | ||
|
||
for (int i = 0; i < arrayList.size(); i++) { | ||
Customer_info customer_info = (Customer_info) arrayList.get(i); | ||
jsonGenerator.writeStartObject(); | ||
jsonGenerator.writeStringField("first_name", customer_info.getFirst_name()); | ||
jsonGenerator.writeStringField("last_name", customer_info.getLast_name()); | ||
jsonGenerator.writeStringField("email_address", customer_info.getEmail_address()); | ||
jsonGenerator.writeStringField("user_password", customer_info.getUserpassword()); | ||
jsonGenerator.writeStringField("date_of_birth", customer_info.getDate_of_birth()); | ||
jsonGenerator.writeEndObject(); | ||
} | ||
} | ||
} |
123 changes: 122 additions & 1 deletion
123
src/main/java/com/robb/banking/util/collections/LinkedList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,125 @@ | ||
package com.robb.banking.util.collections; | ||
|
||
public class LinkedList { | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.robb.banking.util.collections.serializers.LinkedListSerializerCustomer_info; | ||
import com.robb.banking.util.collections.serializers.LinkedListSerializerAccount_info; | ||
|
||
import javax.xml.soap.Node; | ||
|
||
@JsonSerialize(using = LinkedListSerializerCustomer_info.class) | ||
public class LinkedList<T> implements List<T> { | ||
|
||
private int size; | ||
private Node<T> head; | ||
private Node<T> tail; | ||
|
||
@Override | ||
public boolean add(T element) { | ||
|
||
if (element == null) return false; | ||
|
||
Node<T> newNode = new Node<>(element); | ||
|
||
if (head == null) { | ||
tail = head = newNode; | ||
} else { | ||
tail.nextNode = newNode; | ||
tail = newNode; | ||
} | ||
|
||
size++; | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public boolean contains(T element) { | ||
|
||
Node<T> runner = head; | ||
|
||
while (runner != null) { | ||
if (runner.data.equals(element)) { | ||
return true; | ||
} | ||
|
||
runner = runner.nextNode; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return size == 0; | ||
} | ||
|
||
@Override | ||
public boolean remove(T element) { | ||
|
||
if (element == null || size == 0) { | ||
return false; | ||
} | ||
|
||
Node<T> prevNode = null; | ||
Node<T> currentNode = head; | ||
|
||
for ( | ||
int i = 0; | ||
i < size; i++) { | ||
if (currentNode.data != null && currentNode.data.equals(element)) { | ||
if (currentNode == head) { | ||
head = currentNode.nextNode; | ||
} else { | ||
prevNode.nextNode = currentNode.nextNode; | ||
} | ||
|
||
size--; | ||
return true; | ||
} | ||
prevNode = currentNode; | ||
currentNode = currentNode.nextNode; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return size; | ||
} | ||
|
||
@Override | ||
public T get(int index) { | ||
|
||
if (index < 0 || index >= size) { | ||
throw new IndexOutOfBoundsException(); | ||
} | ||
|
||
Node<T> currentNode = head; | ||
|
||
for (int i = 0; i <= index; i++) { | ||
if (i == index) { | ||
return currentNode.data; | ||
} | ||
|
||
currentNode = currentNode.nextNode; | ||
} | ||
|
||
return null; | ||
|
||
} | ||
|
||
@Override | ||
public String toString() { | ||
return super.toString(); | ||
} | ||
|
||
private static class Node<T> { | ||
T data; | ||
Node<T> nextNode; | ||
|
||
public Node(T data) { | ||
this.data = data; | ||
} | ||
} | ||
} |
Oops, something went wrong.