|
From: <pe...@us...> - 2003-11-21 04:43:24
|
Update of /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/implementations
In directory sc8-pr-cvs1:/tmp/cvs-serv10452/src/java/org/neuclear/ledger/implementations
Modified Files:
EntityLedger.java SQLLedger.java SimpleLedger.java
Log Message:
EncryptedFileStore now works. It uses the PBECipher with DES3 afair.
Otherwise You will Finaliate.
Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final.
This should hopefully make everything more stable (and secure).
Index: EntityLedger.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/implementations/EntityLedger.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** EntityLedger.java 20 Nov 2003 23:41:12 -0000 1.1
--- EntityLedger.java 21 Nov 2003 04:43:20 -0000 1.2
***************
*** 1,5 ****
package org.neuclear.ledger.implementations;
! import org.ofbiz.core.entity.GenericDelegator;
/*
--- 1,5 ----
package org.neuclear.ledger.implementations;
! //import org.ofbiz.core.entity.GenericDelegator;
/*
***************
*** 23,26 ****
--- 23,32 ----
$Id$
$Log$
+ Revision 1.2 2003/11/21 04:43:20 pelle
+ EncryptedFileStore now works. It uses the PBECipher with DES3 afair.
+ Otherwise You will Finaliate.
+ Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final.
+ This should hopefully make everything more stable (and secure).
+
Revision 1.1 2003/11/20 23:41:12 pelle
Getting all the tests to work in id
***************
*** 36,44 ****
* Time: 2:16:21 PM
*/
! public class EntityLedger {
! public static void main(String args[]) {
System.out.println("Testing Entity Engine");
! GenericDelegator delegator = GenericDelegator.getGenericDelegator("default");
}
--- 42,50 ----
* Time: 2:16:21 PM
*/
! public final class EntityLedger {
! public static void main(final String[] args) {
System.out.println("Testing Entity Engine");
! // GenericDelegator delegator = GenericDelegator.getGenericDelegator("default");
}
Index: SQLLedger.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/implementations/SQLLedger.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** SQLLedger.java 28 Oct 2003 23:43:14 -0000 1.2
--- SQLLedger.java 21 Nov 2003 04:43:20 -0000 1.3
***************
*** 22,26 ****
* Window>Preferences>Java>Code Generation>Code and Comments
*/
! public class SQLLedger extends Ledger {
/**
--- 22,26 ----
* Window>Preferences>Java>Code Generation>Code and Comments
*/
! public final class SQLLedger extends Ledger {
/**
***************
*** 36,49 ****
}
*/
! public SQLLedger(ConnectionSource con, String id) throws LowlevelLedgerException, UnknownLedgerException {
super(id, getLedgerName(con, id));
this.con = con;
}
! private static String getLedgerName(ConnectionSource con, String id) throws UnknownLedgerException, LowlevelLedgerException {
try {
! PreparedStatement stmt = con.getConnection().prepareStatement("select title from ledger where id=?");
stmt.setString(1, id);
! ResultSet rs = stmt.executeQuery();
if (rs.next())
return rs.getString(1);
--- 36,49 ----
}
*/
! public SQLLedger(final ConnectionSource con, final String id) throws LowlevelLedgerException, UnknownLedgerException {
super(id, getLedgerName(con, id));
this.con = con;
}
! private static String getLedgerName(final ConnectionSource con, final String id) throws UnknownLedgerException, LowlevelLedgerException {
try {
! final PreparedStatement stmt = con.getConnection().prepareStatement("select title from ledger where id=?");
stmt.setString(1, id);
! final ResultSet rs = stmt.executeQuery();
if (rs.next())
return rs.getString(1);
***************
*** 62,74 ****
* @return
*/
! public boolean allowAutoBookCreation() {
return false;
}
! public boolean bookExists(String bookID) throws LowlevelLedgerException {
try {
! PreparedStatement stmt = prepQuery("select id from account where id=?");
stmt.setString(1, bookID);
! ResultSet rs = stmt.executeQuery();
return rs.next();
} catch (SQLException e) {
--- 62,74 ----
* @return
*/
! public final boolean allowAutoBookCreation() {
return false;
}
! public final boolean bookExists(final String bookID) throws LowlevelLedgerException {
try {
! final PreparedStatement stmt = prepQuery("select id from account where id=?");
stmt.setString(1, bookID);
! final ResultSet rs = stmt.executeQuery();
return rs.next();
} catch (SQLException e) {
***************
*** 77,86 ****
}
! public Book createNewBook(String bookID, String title) throws BookExistsException, LowlevelLedgerException {
if (bookExists(bookID))
throw new BookExistsException(this, bookID);
try {
getConnection().setAutoCommit(false);
! PreparedStatement stmt = prepQuery("insert into account values (?,?,3)");
stmt.setString(1, bookID);
stmt.setString(2, title);
--- 77,86 ----
}
! public final Book createNewBook(final String bookID, final String title) throws BookExistsException, LowlevelLedgerException {
if (bookExists(bookID))
throw new BookExistsException(this, bookID);
try {
getConnection().setAutoCommit(false);
! final PreparedStatement stmt = prepQuery("insert into account values (?,?,3)");
stmt.setString(1, bookID);
stmt.setString(2, title);
***************
*** 97,102 ****
* @see org.neuclear.ledger.Ledger#performTransaction(org.neuclear.ledger.UnPostedTransaction)
*/
! public PostedTransaction performTransaction(UnPostedTransaction transaction) throws UnBalancedTransactionException, LowlevelLedgerException, InvalidTransactionException {
! String newid;
if (!transaction.isBalanced()) {
throw new UnBalancedTransactionException(this, transaction);
--- 97,102 ----
* @see org.neuclear.ledger.Ledger#performTransaction(org.neuclear.ledger.UnPostedTransaction)
*/
! public final PostedTransaction performTransaction(final UnPostedTransaction transaction) throws UnBalancedTransactionException, LowlevelLedgerException, InvalidTransactionException {
! final String newid;
if (!transaction.isBalanced()) {
throw new UnBalancedTransactionException(this, transaction);
***************
*** 105,112 ****
getConnection().setAutoCommit(false);
! long xid = insertTransaction(transaction);
! Iterator items = transaction.getItems();
while (items.hasNext()) {
! TransactionItem item = (TransactionItem) items.next();
insertTransactionItem(xid, item);
}
--- 105,112 ----
getConnection().setAutoCommit(false);
! final long xid = insertTransaction(transaction);
! final Iterator items = transaction.getItems();
while (items.hasNext()) {
! final TransactionItem item = (TransactionItem) items.next();
insertTransactionItem(xid, item);
}
***************
*** 133,138 ****
* @return Unique ID
*/
! public PostedHeldTransaction performHeldTransaction(UnPostedHeldTransaction transaction) throws UnBalancedTransactionException, LowlevelLedgerException, InvalidTransactionException {
! String newid;
if (!transaction.isBalanced()) {
throw new UnBalancedTransactionException(this, transaction);
--- 133,138 ----
* @return Unique ID
*/
! public final PostedHeldTransaction performHeldTransaction(final UnPostedHeldTransaction transaction) throws UnBalancedTransactionException, LowlevelLedgerException, InvalidTransactionException {
! final String newid;
if (!transaction.isBalanced()) {
throw new UnBalancedTransactionException(this, transaction);
***************
*** 141,148 ****
getConnection().setAutoCommit(false);
! long xid = insertHeldTransaction(transaction);
! Iterator items = transaction.getItems();
while (items.hasNext()) {
! TransactionItem item = (TransactionItem) items.next();
insertHeldTransactionItem(xid, item);
}
--- 141,148 ----
getConnection().setAutoCommit(false);
! final long xid = insertHeldTransaction(transaction);
! final Iterator items = transaction.getItems();
while (items.hasNext()) {
! final TransactionItem item = (TransactionItem) items.next();
insertHeldTransactionItem(xid, item);
}
***************
*** 170,179 ****
* @throws UnknownTransactionException
*/
! public void performCancelHold(PostedHeldTransaction hold) throws LowlevelLedgerException, UnknownTransactionException {
try {
! PreparedStatement update = prepQuery("update held_transaction set cancelled=1 where id=? and ledgerid=?");
update.setString(1, hold.getXid());
update.setString(2, getId());
! int affected = update.executeUpdate();
if (affected == 0)
throw new UnknownTransactionException(this, hold.getXid());
--- 170,179 ----
* @throws UnknownTransactionException
*/
! public final void performCancelHold(final PostedHeldTransaction hold) throws LowlevelLedgerException, UnknownTransactionException {
try {
! final PreparedStatement update = prepQuery("update held_transaction set cancelled=1 where id=? and ledgerid=?");
update.setString(1, hold.getXid());
update.setString(2, getId());
! final int affected = update.executeUpdate();
if (affected == 0)
throw new UnknownTransactionException(this, hold.getXid());
***************
*** 188,206 ****
}
! public PostedTransaction performCompleteHold(PostedHeldTransaction hold, double amount, Date time, String comment) throws TransactionExpiredException, InvalidTransactionException, LowlevelLedgerException {
try {
! PreparedStatement query = prepQuery("select * from held_transaction where cancelled=0 and transactionid is null and id=? and ledgerid=?");
query.setString(1, hold.getXid());
query.setString(2, getId());
! ResultSet rs = query.executeQuery();
if (!rs.next())
throw new TransactionExpiredException(this, hold);
! PostedTransaction tran = createHeldComplete(hold, amount, time, comment);
! PreparedStatement update = prepQuery("update held_transaction set transactionid=? where id=? and ledgerid=?");
update.setString(1, tran.getXid());
update.setString(2, hold.getXid());
update.setString(3, getId());
! int affected = update.executeUpdate();
if (affected == 0)
throw new UnknownTransactionException(this, hold.getXid());
--- 188,206 ----
}
! public final PostedTransaction performCompleteHold(final PostedHeldTransaction hold, final double amount, final Date time, final String comment) throws TransactionExpiredException, InvalidTransactionException, LowlevelLedgerException {
try {
! final PreparedStatement query = prepQuery("select * from held_transaction where cancelled=0 and transactionid is null and id=? and ledgerid=?");
query.setString(1, hold.getXid());
query.setString(2, getId());
! final ResultSet rs = query.executeQuery();
if (!rs.next())
throw new TransactionExpiredException(this, hold);
! final PostedTransaction tran = createHeldComplete(hold, amount, time, comment);
! final PreparedStatement update = prepQuery("update held_transaction set transactionid=? where id=? and ledgerid=?");
update.setString(1, tran.getXid());
update.setString(2, hold.getXid());
update.setString(3, getId());
! final int affected = update.executeUpdate();
if (affected == 0)
throw new UnknownTransactionException(this, hold.getXid());
***************
*** 221,227 ****
}
! private long insertTransaction(UnPostedTransaction transaction) throws SQLException, LowlevelLedgerException {
! PreparedStatement tranInsert;
tranInsert = prepQuery("insert into transaction (value_date,comment,ledgerid) values (?,?,?)");
tranInsert.setTimestamp(1, SQLTools.toTimestamp(transaction.getTransactionTime()));
--- 221,227 ----
}
! private long insertTransaction(final UnPostedTransaction transaction) throws SQLException, LowlevelLedgerException {
! final PreparedStatement tranInsert;
tranInsert = prepQuery("insert into transaction (value_date,comment,ledgerid) values (?,?,?)");
tranInsert.setTimestamp(1, SQLTools.toTimestamp(transaction.getTransactionTime()));
***************
*** 229,234 ****
tranInsert.setString(3, getId());
tranInsert.execute();
! PreparedStatement tranID = prepQuery("select last_insert_id()");
! ResultSet rs = tranID.executeQuery();
if (rs.next())
return rs.getLong(1);
--- 229,234 ----
tranInsert.setString(3, getId());
tranInsert.execute();
! final PreparedStatement tranID = prepQuery("select last_insert_id()");
! final ResultSet rs = tranID.executeQuery();
if (rs.next())
return rs.getLong(1);
***************
*** 239,245 ****
}
! private long insertHeldTransaction(UnPostedHeldTransaction transaction) throws SQLException, LowlevelLedgerException {
! PreparedStatement tranInsert;
tranInsert = prepQuery("insert into held_transaction (value_date,comment,held_until,ledgerid) values (?,?,?,?)");
tranInsert.setTimestamp(3, SQLTools.toTimestamp(transaction.getExpiryTime()));
--- 239,245 ----
}
! private long insertHeldTransaction(final UnPostedHeldTransaction transaction) throws SQLException, LowlevelLedgerException {
! final PreparedStatement tranInsert;
tranInsert = prepQuery("insert into held_transaction (value_date,comment,held_until,ledgerid) values (?,?,?,?)");
tranInsert.setTimestamp(3, SQLTools.toTimestamp(transaction.getExpiryTime()));
***************
*** 249,254 ****
tranInsert.setString(4, getId());
tranInsert.execute();
! PreparedStatement tranID = prepQuery("select id from held_transaction where id=last_insert_id()");
! ResultSet rs = tranID.executeQuery();
if (rs.next())
return rs.getLong(1);
--- 249,254 ----
tranInsert.setString(4, getId());
tranInsert.execute();
! final PreparedStatement tranID = prepQuery("select id from held_transaction where id=last_insert_id()");
! final ResultSet rs = tranID.executeQuery();
if (rs.next())
return rs.getLong(1);
***************
*** 259,264 ****
}
! private void insertTransactionItem(long xid, TransactionItem item) throws SQLException, LowlevelLedgerException {
! PreparedStatement itemInsert = prepQuery("insert into entry (transactionid,accountid,amount,ack) values (?,?,?,1)");
itemInsert.setLong(1, xid);
itemInsert.setString(2, item.getBook().getBookID());
--- 259,264 ----
}
! private void insertTransactionItem(final long xid, final TransactionItem item) throws SQLException, LowlevelLedgerException {
! final PreparedStatement itemInsert = prepQuery("insert into entry (transactionid,accountid,amount,ack) values (?,?,?,1)");
itemInsert.setLong(1, xid);
itemInsert.setString(2, item.getBook().getBookID());
***************
*** 267,272 ****
}
! private void insertHeldTransactionItem(long xid, TransactionItem item) throws SQLException, LowlevelLedgerException {
! PreparedStatement itemInsert = prepQuery("insert into held_entry (held_transactionid,accountid,amount,ack) values (?,?,?,1)");
itemInsert.setLong(1, xid);
itemInsert.setString(2, item.getBook().getBookID());
--- 267,272 ----
}
! private void insertHeldTransactionItem(final long xid, final TransactionItem item) throws SQLException, LowlevelLedgerException {
! final PreparedStatement itemInsert = prepQuery("insert into held_entry (held_transactionid,accountid,amount,ack) values (?,?,?,1)");
itemInsert.setLong(1, xid);
itemInsert.setString(2, item.getBook().getBookID());
***************
*** 281,286 ****
* @return The Transaction object
*/
! public PostedTransaction findTransaction(String idstring) throws LowlevelLedgerException, UnknownTransactionException {
! long id = Long.parseLong(idstring);
try {
--- 281,286 ----
* @return The Transaction object
*/
! public final PostedTransaction findTransaction(final String idstring) throws LowlevelLedgerException, UnknownTransactionException {
! final long id = Long.parseLong(idstring);
try {
***************
*** 292,299 ****
throw new UnknownTransactionException(this, idstring);
}
! Date started = rs.getTimestamp(1);
! String comment = rs.getString(2);
! UnPostedTransaction transaction = new UnPostedTransaction(this, comment, started);
stmt = prepQuery("select accountid,amount from entry where transactionid=?");
stmt.setLong(1, id);
--- 292,299 ----
throw new UnknownTransactionException(this, idstring);
}
! final Date started = rs.getTimestamp(1);
! final String comment = rs.getString(2);
! final UnPostedTransaction transaction = new UnPostedTransaction(this, comment, started);
stmt = prepQuery("select accountid,amount from entry where transactionid=?");
stmt.setLong(1, id);
***************
*** 319,324 ****
* @return The Transaction object
*/
! public PostedHeldTransaction findHeldTransaction(String idstring) throws LowlevelLedgerException, UnknownTransactionException {
! long id = Long.parseLong(idstring);
try {
--- 319,324 ----
* @return The Transaction object
*/
! public final PostedHeldTransaction findHeldTransaction(final String idstring) throws LowlevelLedgerException, UnknownTransactionException {
! final long id = Long.parseLong(idstring);
try {
***************
*** 330,338 ****
throw new UnknownTransactionException(this, idstring);
}
! Date started = rs.getTimestamp(1);
! Date ended = rs.getTimestamp(2);
! String comment = rs.getString(3);
! UnPostedHeldTransaction transaction = new UnPostedHeldTransaction(this, comment, started, ended);
stmt = prepQuery("select accountid,amount from held_entry where held_transactionid=?");
stmt.setLong(1, id);
--- 330,338 ----
throw new UnknownTransactionException(this, idstring);
}
! final Date started = rs.getTimestamp(1);
! final Date ended = rs.getTimestamp(2);
! final String comment = rs.getString(3);
! final UnPostedHeldTransaction transaction = new UnPostedHeldTransaction(this, comment, started, ended);
stmt = prepQuery("select accountid,amount from held_entry where held_transactionid=?");
stmt.setLong(1, id);
***************
*** 352,356 ****
}
! private PreparedStatement prepQuery(String sql) throws SQLException, LowlevelLedgerException {
return getConnection().prepareStatement(sql);
}
--- 352,356 ----
}
! private PreparedStatement prepQuery(final String sql) throws SQLException, LowlevelLedgerException {
return getConnection().prepareStatement(sql);
}
***************
*** 359,365 ****
* @see org.neuclear.ledger.Ledger#getBalance(org.neuclear.ledger.Book, java.util.Date)
*/
! public double getBalance(Book book, Date time) throws LowlevelLedgerException {
try {
! PreparedStatement stmt = prepQuery("select sum(e.amount) from entry e,transaction t where e.transactionid=t.id and e.accountid=? and t.value_date<= ? and t.ledgerid=?");
stmt.setString(1, book.getBookID());
--- 359,365 ----
* @see org.neuclear.ledger.Ledger#getBalance(org.neuclear.ledger.Book, java.util.Date)
*/
! public final double getBalance(final Book book, final Date time) throws LowlevelLedgerException {
try {
! final PreparedStatement stmt = prepQuery("select sum(e.amount) from entry e,transaction t where e.transactionid=t.id and e.accountid=? and t.value_date<= ? and t.ledgerid=?");
stmt.setString(1, book.getBookID());
***************
*** 367,371 ****
stmt.setString(3, getId());
! ResultSet rs = stmt.executeQuery();
if (rs.next()) {
return rs.getDouble(1);
--- 367,371 ----
stmt.setString(3, getId());
! final ResultSet rs = stmt.executeQuery();
if (rs.next()) {
return rs.getDouble(1);
***************
*** 380,391 ****
* @see org.neuclear.ledger.Ledger#getBalance(org.neuclear.ledger.Book)
*/
! public double getBalance(Book book) throws LowlevelLedgerException {
return getBalance(book, new Date());
}
! public double getAvailableBalance(Book book, Date time) throws LowlevelLedgerException {
double balance = 0.0;
try {
! PreparedStatement stmt = prepQuery("select sum(u.amount) from (" +
"select sum( e.amount) as amount from entry e,transaction t " +
"where e.transactionid=t.id and e.accountid=? and t.value_date<= ? and t.ledgerid=?"
--- 380,391 ----
* @see org.neuclear.ledger.Ledger#getBalance(org.neuclear.ledger.Book)
*/
! public final double getBalance(final Book book) throws LowlevelLedgerException {
return getBalance(book, new Date());
}
! public final double getAvailableBalance(final Book book, final Date time) throws LowlevelLedgerException {
double balance = 0.0;
try {
! final PreparedStatement stmt = prepQuery("select sum(u.amount) from (" +
"select sum( e.amount) as amount from entry e,transaction t " +
"where e.transactionid=t.id and e.accountid=? and t.value_date<= ? and t.ledgerid=?"
***************
*** 397,401 ****
+ ") u "
);
! Timestamp ts = SQLTools.toTimestamp(time);
stmt.setString(1, book.getBookID());
stmt.setTimestamp(2, ts);
--- 397,401 ----
+ ") u "
);
! final Timestamp ts = SQLTools.toTimestamp(time);
stmt.setString(1, book.getBookID());
stmt.setTimestamp(2, ts);
***************
*** 406,410 ****
stmt.setString(7, getId());
! ResultSet rs = stmt.executeQuery();
// System.out.println("Avaliable Balance at: "+ts.toString());
while (rs.next()) {
--- 406,410 ----
stmt.setString(7, getId());
! final ResultSet rs = stmt.executeQuery();
// System.out.println("Avaliable Balance at: "+ts.toString());
while (rs.next()) {
***************
*** 422,426 ****
* @see org.neuclear.ledger.Ledger#getAvailableBalance(org.neuclear.ledger.Book)
*/
! public double getAvailableBalance(Book book) throws LowlevelLedgerException {
return getAvailableBalance(book, new Date());
}
--- 422,426 ----
* @see org.neuclear.ledger.Ledger#getAvailableBalance(org.neuclear.ledger.Book)
*/
! public final double getAvailableBalance(final Book book) throws LowlevelLedgerException {
return getAvailableBalance(book, new Date());
}
***************
*** 429,433 ****
* @see org.neuclear.ledger.Ledger#beginLinkedTransaction()
*/
! public void beginLinkedTransaction() {
// TODO Auto-generated method stub
--- 429,433 ----
* @see org.neuclear.ledger.Ledger#beginLinkedTransaction()
*/
! public final void beginLinkedTransaction() {
// TODO Auto-generated method stub
***************
*** 437,446 ****
* @see org.neuclear.ledger.Ledger#endLinkedTransactions()
*/
! public void endLinkedTransactions() {
// TODO Auto-generated method stub
}
! public String toString() {
return "SQL Ledger: " + getName();
}
--- 437,446 ----
* @see org.neuclear.ledger.Ledger#endLinkedTransactions()
*/
! public final void endLinkedTransactions() {
// TODO Auto-generated method stub
}
! public final String toString() {
return "SQL Ledger: " + getName();
}
***************
*** 456,466 ****
}
! private ConnectionSource con;
! public Book getBook(String bookID) throws UnknownBookException, LowlevelLedgerException {
try {
! PreparedStatement stmt = prepQuery("select screenname from account where id=?");
stmt.setString(1, bookID);
! ResultSet rs = stmt.executeQuery();
if (rs.next())
return createBookInstance(bookID, rs.getString(1));
--- 456,466 ----
}
! private final ConnectionSource con;
! public final Book getBook(final String bookID) throws UnknownBookException, LowlevelLedgerException {
try {
! final PreparedStatement stmt = prepQuery("select screenname from account where id=?");
stmt.setString(1, bookID);
! final ResultSet rs = stmt.executeQuery();
if (rs.next())
return createBookInstance(bookID, rs.getString(1));
Index: SimpleLedger.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/implementations/SimpleLedger.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** SimpleLedger.java 11 Nov 2003 21:17:31 -0000 1.2
--- SimpleLedger.java 21 Nov 2003 04:43:20 -0000 1.3
***************
*** 3,6 ****
--- 3,12 ----
* $Id$
* $Log$
+ * Revision 1.3 2003/11/21 04:43:20 pelle
+ * EncryptedFileStore now works. It uses the PBECipher with DES3 afair.
+ * Otherwise You will Finaliate.
+ * Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final.
+ * This should hopefully make everything more stable (and secure).
+ *
* Revision 1.2 2003/11/11 21:17:31 pelle
* Further vital reshuffling.
***************
*** 66,70 ****
public final class SimpleLedger extends Ledger {
! public SimpleLedger(String name) {
super(name,name);
ledger=new LinkedHashMap();
--- 72,76 ----
public final class SimpleLedger extends Ledger {
! public SimpleLedger(final String name) {
super(name,name);
ledger=new LinkedHashMap();
***************
*** 72,76 ****
}
! public boolean bookExists(String bookID) {
return books.containsKey(bookID); //Strictly speaking not true
}
--- 78,82 ----
}
! public boolean bookExists(final String bookID) {
return books.containsKey(bookID); //Strictly speaking not true
}
***************
*** 82,89 ****
* @return
*/
! public Book createNewBook(String bookID,String title) throws BookExistsException {
if (bookExists(bookID))
throw new BookExistsException(this,bookID);
! Book book=createBookInstance(bookID,title);
books.put(bookID,book);
return book;
--- 88,95 ----
* @return
*/
! public Book createNewBook(final String bookID,final String title) throws BookExistsException {
if (bookExists(bookID))
throw new BookExistsException(this,bookID);
! final Book book=createBookInstance(bookID,title);
books.put(bookID,book);
return book;
***************
*** 98,106 ****
* @return Unique ID
*/
! public PostedTransaction performTransaction(UnPostedTransaction trans) throws UnBalancedTransactionException, InvalidTransactionException {
if (!trans.isBalanced())
throw new UnBalancedTransactionException(this,trans);
! String id=getID();
! PostedTransaction posted=createTransaction(trans,id);
ledger.put(id,posted);
return posted;
--- 104,112 ----
* @return Unique ID
*/
! public PostedTransaction performTransaction(final UnPostedTransaction trans) throws UnBalancedTransactionException, InvalidTransactionException {
if (!trans.isBalanced())
throw new UnBalancedTransactionException(this,trans);
! final String id=getID();
! final PostedTransaction posted=createTransaction(trans,id);
ledger.put(id,posted);
return posted;
***************
*** 114,122 ****
* @return Unique ID
*/
! public PostedHeldTransaction performHeldTransaction(UnPostedHeldTransaction trans) throws UnBalancedTransactionException, LowlevelLedgerException, InvalidTransactionException {
if (!trans.isBalanced())
throw new UnBalancedTransactionException(this,trans);
! String id=getID();
! PostedHeldTransaction posted=createHeldTransaction(trans,id);
ledger.put(id,posted);
return posted;
--- 120,128 ----
* @return Unique ID
*/
! public PostedHeldTransaction performHeldTransaction(final UnPostedHeldTransaction trans) throws UnBalancedTransactionException, LowlevelLedgerException, InvalidTransactionException {
if (!trans.isBalanced())
throw new UnBalancedTransactionException(this,trans);
! final String id=getID();
! final PostedHeldTransaction posted=createHeldTransaction(trans,id);
ledger.put(id,posted);
return posted;
***************
*** 129,133 ****
* @ If it couldnt find the Transaction
*/
! public PostedTransaction findTransaction(String id) throws UnknownTransactionException {
if (!ledger.containsKey(id))
throw new UnknownTransactionException(this,id);
--- 135,139 ----
* @ If it couldnt find the Transaction
*/
! public PostedTransaction findTransaction(final String id) throws UnknownTransactionException {
if (!ledger.containsKey(id))
throw new UnknownTransactionException(this,id);
***************
*** 146,162 ****
* @return the balance as a double
*/
! public double getBalance(Book book, Date balancedate) {
double balance=0;
// Very silly slow and lazy implementation
! Iterator iter=ledger.keySet().iterator();
! boolean going=true;
while(iter.hasNext()&&going){
! Transaction tran=(Transaction)ledger.get((String)iter.next());
// The reason I'm doing !xx.after is because I need this to be <=
if (!tran.getTransactionTime().after(balancedate)) {
! Iterator items=tran.getItems();
! boolean isHold=(tran instanceof HeldTransaction);
while (items.hasNext()) {
! TransactionItem item = (TransactionItem) items.next();
if (item.getBook().equals(book)&&!isHold)
balance+=item.getAmount();
--- 152,168 ----
* @return the balance as a double
*/
! public double getBalance(final Book book, final Date balancedate) {
double balance=0;
// Very silly slow and lazy implementation
! final Iterator iter=ledger.keySet().iterator();
! final boolean going=true;
while(iter.hasNext()&&going){
! final Transaction tran=(Transaction)ledger.get((String)iter.next());
// The reason I'm doing !xx.after is because I need this to be <=
if (!tran.getTransactionTime().after(balancedate)) {
! final Iterator items=tran.getItems();
! final boolean isHold=(tran instanceof HeldTransaction);
while (items.hasNext()) {
! final TransactionItem item = (TransactionItem) items.next();
if (item.getBook().equals(book)&&!isHold)
balance+=item.getAmount();
***************
*** 169,173 ****
}
! public double getBalance(Book book) {
return getBalance(book,new Date());
}
--- 175,179 ----
}
! public double getBalance(final Book book) {
return getBalance(book,new Date());
}
***************
*** 186,205 ****
* @return the balance as a double
*/
! public double getAvailableBalance(Book book, Date balancedate) {
double balance=0;
// Very silly slow and lazy implementation
! Iterator iter=ledger.keySet().iterator();
! boolean going=true;
while(iter.hasNext()){
! Transaction tran=(Transaction)ledger.get((String)iter.next());
// The reason I'm doing !xx.after is because I need this to be <=
if (!tran.getTransactionTime().after(balancedate)) {
! Iterator items=tran.getItems();
! boolean isHold=(tran instanceof HeldTransaction);
! boolean isValidHold=isHold&&(!((HeldTransaction)tran).getExpiryTime().before(balancedate));
while (items.hasNext()) {
! TransactionItem item = (TransactionItem) items.next();
if (
item.getBook().equals(book)&&
--- 192,211 ----
* @return the balance as a double
*/
! public double getAvailableBalance(final Book book, final Date balancedate) {
double balance=0;
// Very silly slow and lazy implementation
! final Iterator iter=ledger.keySet().iterator();
! final boolean going=true;
while(iter.hasNext()){
! final Transaction tran=(Transaction)ledger.get((String)iter.next());
// The reason I'm doing !xx.after is because I need this to be <=
if (!tran.getTransactionTime().after(balancedate)) {
! final Iterator items=tran.getItems();
! final boolean isHold=(tran instanceof HeldTransaction);
! final boolean isValidHold=isHold&&(!((HeldTransaction)tran).getExpiryTime().before(balancedate));
while (items.hasNext()) {
! final TransactionItem item = (TransactionItem) items.next();
if (
item.getBook().equals(book)&&
***************
*** 222,226 ****
}
! public double getAvailableBalance(Book book) {
return getAvailableBalance(book,new Date());
}
--- 228,232 ----
}
! public double getAvailableBalance(final Book book) {
return getAvailableBalance(book,new Date());
}
***************
*** 251,255 ****
* @return The Transaction object
*/
! public PostedHeldTransaction findHeldTransaction(String idstring) throws LowlevelLedgerException, UnknownTransactionException {
return null; //To change body of implemented methods use Options | File Templates.
}
--- 257,261 ----
* @return The Transaction object
*/
! public PostedHeldTransaction findHeldTransaction(final String idstring) throws LowlevelLedgerException, UnknownTransactionException {
return null; //To change body of implemented methods use Options | File Templates.
}
***************
*** 261,269 ****
* @throws UnknownTransactionException
*/
! public void performCancelHold(PostedHeldTransaction hold) throws LowlevelLedgerException, UnknownTransactionException {
//To change body of implemented methods use Options | File Templates.
}
! public PostedTransaction performCompleteHold(PostedHeldTransaction hold, double amount, Date time, String comment) throws InvalidTransactionException, LowlevelLedgerException {
return null; //To change body of implemented methods use Options | File Templates.
}
--- 267,275 ----
* @throws UnknownTransactionException
*/
! public void performCancelHold(final PostedHeldTransaction hold) throws LowlevelLedgerException, UnknownTransactionException {
//To change body of implemented methods use Options | File Templates.
}
! public PostedTransaction performCompleteHold(final PostedHeldTransaction hold, final double amount, final Date time, final String comment) throws InvalidTransactionException, LowlevelLedgerException {
return null; //To change body of implemented methods use Options | File Templates.
}
***************
*** 273,280 ****
}
private long idSeq=0;
! private LinkedHashMap ledger;
! private HashMap books;
! public Book getBook(String bookID) throws UnknownBookException,LowlevelLedgerException {
if (bookExists(bookID))
return (Book)books.get(bookID);
--- 279,286 ----
}
private long idSeq=0;
! private final LinkedHashMap ledger;
! private final HashMap books;
! public Book getBook(final String bookID) throws UnknownBookException,LowlevelLedgerException {
if (bookExists(bookID))
return (Book)books.get(bookID);
|