|
From: <pe...@us...> - 2003-12-31 00:39:08
|
Update of /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/implementations
In directory sc8-pr-cvs1:/tmp/cvs-serv2351/src/java/org/neuclear/ledger/implementations
Modified Files:
SQLLedger.java
Log Message:
Added Drivers for handling different Database dialects in the entity model.
Added Statement pattern to ledger, simplifying the statement writing process.
Index: SQLLedger.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/implementations/SQLLedger.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** SQLLedger.java 26 Dec 2003 22:50:52 -0000 1.7
--- SQLLedger.java 31 Dec 2003 00:39:04 -0000 1.8
***************
*** 12,19 ****
--- 12,23 ----
import org.neuclear.commons.sql.DefaultConnectionSource;
import org.neuclear.commons.sql.entities.EntityModel;
+ import org.neuclear.commons.sql.entities.Schema;
import org.neuclear.commons.NeuClearException;
import org.neuclear.commons.crypto.CryptoTools;
import org.neuclear.ledger.*;
import org.neuclear.ledger.InvalidTransactionException;
+ import org.neuclear.ledger.browser.LedgerBrowser;
+ import org.neuclear.ledger.browser.Statement;
+ import org.neuclear.ledger.browser.QueryStatement;
import org.neuclear.id.NSTools;
import org.bouncycastle.crypto.Digest;
***************
*** 33,37 ****
* Window>Preferences>Java>Code Generation>Code and Comments
*/
! public final class SQLLedger extends Ledger {
/**
--- 37,41 ----
* Window>Preferences>Java>Code Generation>Code and Comments
*/
! public final class SQLLedger extends Ledger implements LedgerBrowser {
/**
***************
*** 50,56 ****
super(id, "sql ledger");
this.con = new SQLContext(con);
! // create(this.con);
!
! create(con);
createLedger(id);
}
--- 54,64 ----
super(id, "sql ledger");
this.con = new SQLContext(con);
! try {
! create(con.getConnection());
! } catch (SQLException e) {
! throw new LowlevelLedgerException(this,e);
! } catch (IOException e) {
! throw new LowlevelLedgerException(this,e);
! }
createLedger(id);
}
***************
*** 73,109 ****
}
! public static synchronized void create(ConnectionSource con) {
! try {
! Connection connection=con.getConnection();
! EntityModel ledgerModel=new EntityModel("ledger",true);
! ledgerModel.addTitle();
// ledgerModel.addComment();
! ledgerModel.addTimeStamp();
! EntityModel bookModel=new EntityModel("book",true);
! bookModel.addTitle();
! bookModel.addTimeStamp();
! EntityModel xactModel=new EntityModel("transaction",true);
! xactModel.addComment();
! xactModel.addValueTime();
! xactModel.addReference(ledgerModel);
! EntityModel entryModel=new EntityModel("entry",false);
! entryModel.addMoney();
! entryModel.addReference(bookModel);
! entryModel.addReference(xactModel);
! EntityModel hxactModel=new EntityModel("held_transaction",true);
! hxactModel.addComment();
! hxactModel.addValueTime();
! hxactModel.addTimeStamp("held_until");
! hxactModel.addReference(ledgerModel);
! hxactModel.addReference(xactModel);
! hxactModel.addBoolean("cancelled");
! EntityModel hentryModel=new EntityModel("held_entry",false);
! hentryModel.addMoney();
! hentryModel.addReference(bookModel);
! hentryModel.addReference(hxactModel);
! entryModel.create(connection);
! hentryModel.create(connection);
! connection.close();
} catch (SQLException e) {
e.printStackTrace();
--- 81,122 ----
}
! public static synchronized void create(Connection con){
! createSchema().create(con);
! }
! public static Schema createSchema() {
! Schema schema=new Schema("mysql");
!
! EntityModel ledgerModel=schema.addEntityModel("ledger");
! ledgerModel.addTitle();
// ledgerModel.addComment();
! ledgerModel.addTimeStamp();
! EntityModel bookModel=schema.addEntityModel("book");
! bookModel.addTitle();
! bookModel.addTimeStamp();
! EntityModel xactModel=schema.addEntityModel("transaction");
! xactModel.addComment();
! xactModel.addValueTime();
! xactModel.addReference(ledgerModel);
! EntityModel entryModel=schema.addEntityModel("entry",false);
! entryModel.addMoney();
! entryModel.addReference(bookModel);
! entryModel.addReference(xactModel);
! EntityModel hxactModel=schema.addEntityModel("held_transaction");
! hxactModel.addComment();
! hxactModel.addValueTime();
! hxactModel.addTimeStamp("held_until");
! hxactModel.addReference(ledgerModel);
! hxactModel.addReference(xactModel);
! hxactModel.addBoolean("cancelled");
! EntityModel hentryModel=schema.addEntityModel("held_entry",false);
! hentryModel.addMoney();
! hentryModel.addReference(bookModel);
! hentryModel.addReference(hxactModel);
! return schema;
! }
! public static void main(String args[]){
! try {
! create(new DefaultConnectionSource().getConnection());
} catch (SQLException e) {
e.printStackTrace();
***************
*** 111,118 ****
e.printStackTrace();
}
-
- }
- public static void main(String args[]){
- create(new DefaultConnectionSource());
}
private static String getLedgerName(final ConnectionSource con, final String id) throws UnknownLedgerException, LowlevelLedgerException {
--- 124,127 ----
***************
*** 517,520 ****
--- 526,553 ----
throw new LowlevelLedgerException(this,e);
} catch (IOException e) {
+ throw new LowlevelLedgerException(this,e);
+ }
+ }
+
+ public Statement browse(Book book) throws LowlevelLedgerException {
+ try {
+ return new QueryStatement(book,getConnection());
+ } catch (SQLException e) {
+ throw new LowlevelLedgerException(this,e);
+ }
+ }
+
+ public Statement browseFrom(Book book, Timestamp from) throws LowlevelLedgerException {
+ try {
+ return new QueryStatement(book,getConnection(),from);
+ } catch (SQLException e) {
+ throw new LowlevelLedgerException(this,e);
+ }
+ }
+
+ public Statement browseRange(Book book, Timestamp from, Timestamp until) throws LowlevelLedgerException {
+ try {
+ return new QueryStatement(book,getConnection(),from,until);
+ } catch (SQLException e) {
throw new LowlevelLedgerException(this,e);
}
|