You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(119) |
Oct
(111) |
Nov
(238) |
Dec
(395) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(239) |
Feb
(59) |
Mar
(354) |
Apr
(489) |
May
(23) |
Jun
(2) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
(4) |
May
(5) |
Jun
(2) |
Jul
|
Aug
|
Sep
(3) |
Oct
(14) |
Nov
(17) |
Dec
(9) |
| 2007 |
Jan
(4) |
Feb
(3) |
Mar
|
Apr
(1) |
May
(1) |
Jun
(2) |
Jul
|
Aug
|
Sep
(1) |
Oct
(2) |
Nov
(1) |
Dec
|
| 2008 |
Jan
|
Feb
|
Mar
(1) |
Apr
(7) |
May
(3) |
Jun
(6) |
Jul
(4) |
Aug
(3) |
Sep
(15) |
Oct
(13) |
Nov
(35) |
Dec
(40) |
| 2009 |
Jan
(19) |
Feb
(21) |
Mar
(16) |
Apr
(18) |
May
(36) |
Jun
(20) |
Jul
(32) |
Aug
(11) |
Sep
(3) |
Oct
(2) |
Nov
(2) |
Dec
(13) |
| 2010 |
Jan
(5) |
Feb
(5) |
Mar
(7) |
Apr
(1) |
May
(1) |
Jun
(3) |
Jul
(1) |
Aug
(1) |
Sep
(1) |
Oct
(1) |
Nov
|
Dec
|
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(2) |
Jul
(1) |
Aug
(1) |
Sep
(1) |
Oct
(4) |
Nov
|
Dec
(3) |
| 2012 |
Jan
(3) |
Feb
(3) |
Mar
(1) |
Apr
(4) |
May
(8) |
Jun
(4) |
Jul
(9) |
Aug
(2) |
Sep
(8) |
Oct
(3) |
Nov
(8) |
Dec
(4) |
| 2013 |
Jan
(2) |
Feb
(1) |
Mar
(5) |
Apr
(6) |
May
(10) |
Jun
(5) |
Jul
(6) |
Aug
(7) |
Sep
(5) |
Oct
(2) |
Nov
(4) |
Dec
(4) |
| 2014 |
Jan
(13) |
Feb
(4) |
Mar
(7) |
Apr
(9) |
May
(20) |
Jun
(13) |
Jul
(10) |
Aug
(3) |
Sep
(5) |
Oct
(2) |
Nov
(2) |
Dec
(2) |
| 2015 |
Jan
(3) |
Feb
(3) |
Mar
(5) |
Apr
(4) |
May
(3) |
Jun
(2) |
Jul
(4) |
Aug
(3) |
Sep
(1) |
Oct
|
Nov
(1) |
Dec
(3) |
| 2016 |
Jan
|
Feb
(1) |
Mar
(1) |
Apr
(1) |
May
(1) |
Jun
(2) |
Jul
(1) |
Aug
(4) |
Sep
(3) |
Oct
(3) |
Nov
(4) |
Dec
(2) |
| 2017 |
Jan
|
Feb
(2) |
Mar
|
Apr
(2) |
May
(1) |
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <pe...@us...> - 2003-12-31 00:39:33
|
Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/time In directory sc8-pr-cvs1:/tmp/cvs-serv2460/src/java/org/neuclear/commons/time Modified Files: TimeTools.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: TimeTools.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/time/TimeTools.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TimeTools.java 24 Dec 2003 00:25:41 -0000 1.6 --- TimeTools.java 31 Dec 2003 00:39:29 -0000 1.7 *************** *** 2,5 **** --- 2,9 ---- * $Id$ * $Log$ + * Revision 1.7 2003/12/31 00:39:29 pelle + * Added Drivers for handling different Database dialects in the entity model. + * Added Statement pattern to ledger, simplifying the statement writing process. + * * Revision 1.6 2003/12/24 00:25:41 pelle * Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code. *************** *** 129,132 **** --- 133,139 ---- return getDateFormatter().format(time); } + public static String formatTimeStampShort(final Date time) { + return DFS.format(time); + } private static SimpleDateFormat getDateFormatter() { *************** *** 148,151 **** --- 155,165 ---- DF.setTimeZone(TimeZone.getTimeZone("GMT")); } + // private static final String SHORT_DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss,SSSzzz"; + private static final SimpleDateFormat DFS = new SimpleDateFormat(); + + { + // DFS.setTimeZone(TimeZone.getTimeZone("GMT")); + } + /** |
|
From: <pe...@us...> - 2003-12-31 00:39:08
|
Update of /cvsroot/neuclear/neuclear-ledger/src/test/org/neuclear/ledger
In directory sc8-pr-cvs1:/tmp/cvs-serv2351/src/test/org/neuclear/ledger
Modified Files:
LedgerTest.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: LedgerTest.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-ledger/src/test/org/neuclear/ledger/LedgerTest.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** LedgerTest.java 26 Dec 2003 22:50:52 -0000 1.8
--- LedgerTest.java 31 Dec 2003 00:39:05 -0000 1.9
***************
*** 25,28 ****
--- 25,32 ----
* $Id$
* $Log$
+ * Revision 1.9 2003/12/31 00:39:05 pelle
+ * Added Drivers for handling different Database dialects in the entity model.
+ * Added Statement pattern to ledger, simplifying the statement writing process.
+ *
* Revision 1.8 2003/12/26 22:50:52 pelle
* Mainly fixes to SQLLedger to support the schema generated by the new EntityModel
***************
*** 121,131 ****
*/
public abstract class LedgerTest extends TestCase {
! protected final String account1 = "Bob";
! protected final String account2 = "Alice";
public LedgerTest(final String s) throws LowlevelLedgerException, UnknownLedgerException, SQLException, NamingException, IOException, NeuClearException {
super(s);
! ledger = new SQLLedger(new TestCaseXAConnectionSource(), "neu://superbux/reserve");
}
--- 125,135 ----
*/
public abstract class LedgerTest extends TestCase {
! protected final String account1 = "neu://test/bob";
! protected final String account2 = "nru://test/alice";
public LedgerTest(final String s) throws LowlevelLedgerException, UnknownLedgerException, SQLException, NamingException, IOException, NeuClearException {
super(s);
! ledger = new SQLLedger(new TestCaseXAConnectionSource(), "neu://test/bux");
}
|
|
From: <pe...@us...> - 2003-12-31 00:39:08
|
Update of /cvsroot/neuclear/neuclear-ledger
In directory sc8-pr-cvs1:/tmp/cvs-serv2351
Modified Files:
project.xml
Log Message:
Added Drivers for handling different Database dialects in the entity model.
Added Statement pattern to ledger, simplifying the statement writing process.
Index: project.xml
===================================================================
RCS file: /cvsroot/neuclear/neuclear-ledger/project.xml,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** project.xml 29 Dec 2003 22:40:16 -0000 1.11
--- project.xml 31 Dec 2003 00:39:05 -0000 1.12
***************
*** 87,98 ****
</dependency>
<dependency>
! <id>bouncycastle</id>
! <name>bouncycastle</name>
! <version>115</version>
! <jar>jce-jdk13-115.jar</jar>
! <properties>
! <war.bundle.jar>false</war.bundle.jar>
! </properties>
! </dependency>
<dependency>
<id>servletapi</id>
--- 87,106 ----
</dependency>
<dependency>
! <id>dom4j</id>
! <version>1.4</version>
! <jar>dom4j-1.4.jar</jar>
! <properties>
! <war.bundle>true</war.bundle>
! </properties>
! </dependency>
! <dependency>
! <id>bouncycastle</id>
! <name>bouncycastle</name>
! <version>120</version>
! <jar>bcprov-jdk14-120.jar</jar>
! <properties>
! <war.bundle>false</war.bundle>
! </properties>
! </dependency>
<dependency>
<id>servletapi</id>
|
|
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);
}
|
|
From: <pe...@us...> - 2003-12-31 00:39:08
|
Update of /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/servlets
In directory sc8-pr-cvs1:/tmp/cvs-serv2351/src/java/org/neuclear/ledger/servlets
Modified Files:
LedgerServlet.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: LedgerServlet.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/servlets/LedgerServlet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** LedgerServlet.java 29 Dec 2003 22:40:15 -0000 1.1
--- LedgerServlet.java 31 Dec 2003 00:39:04 -0000 1.2
***************
*** 8,11 ****
--- 8,15 ----
import org.neuclear.id.InvalidNamedObjectException;
import org.neuclear.ledger.implementations.SQLLedger;
+ import org.neuclear.ledger.browser.Statement;
+ import org.neuclear.ledger.browser.StatementEntry;
+ import org.neuclear.ledger.UnknownBookException;
+ import org.neuclear.ledger.LowlevelLedgerException;
import javax.servlet.http.HttpServlet;
***************
*** 46,49 ****
--- 50,57 ----
$Id$
$Log$
+ Revision 1.2 2003/12/31 00:39:04 pelle
+ Added Drivers for handling different Database dialects in the entity model.
+ Added Statement pattern to ledger, simplifying the statement writing process.
+
Revision 1.1 2003/12/29 22:40:15 pelle
Added LedgerServlet and friends
***************
*** 66,71 ****
serviceid
);
- ledger.createLedger(serviceid);
-
} catch (Exception e) {
throw new ServletException(e);
--- 74,77 ----
***************
*** 78,86 ****
PrintWriter out=response.getWriter();
ServletTools.printHeader(out,request,"Account Browser");
! String url=request.getServletPath();
try {
- Connection con=consrc.getConnection();
- PreparedStatement stmt=con.prepareStatement("select t.id,t.valuetime, r.bookid,t.comment,s.amount from entry s,entry r, transaction t where s.transactionid=t.id and r.transactionid=t.id and r.id<>s.id\n" +
- "and (s.bookid = ? ) and t.ledgerid=?");
Principal user=request.getUserPrincipal();
String book=request.getPathInfo();
--- 84,89 ----
PrintWriter out=response.getWriter();
ServletTools.printHeader(out,request,"Account Browser");
! String url=ServletTools.getAbsoluteURL(request,request.getServletPath());
try {
Principal user=request.getUserPrincipal();
String book=request.getPathInfo();
***************
*** 89,113 ****
else
book="neu:/"+book;
! stmt.setString(1,book);
! stmt.setString(2,book);
! stmt.setString(3,serviceid);
! ResultSet rs=stmt.executeQuery();
out.println("<table><tr><th>Transaction ID</th><th>Time</th><th>Counterparty</th><th>Comment</th><th>Amount</th></tr>");
! while(rs.next()){
! final BigDecimal amount = rs.getBigDecimal(5);
out.print("<tr");
if (amount.compareTo(ZERO)<0)
out.print(" class=\"negative\"");
! out.print("><td>");
! out.print(rs.getString(1));
out.print("</td><td>");
! out.print(TimeTools.formatTimeStamp(rs.getTimestamp(2)));
out.print("</td><td><a href=\"");
out.print(url);
! out.print(NSTools.name2path(rs.getString(3)));
out.println("\">");
! out.print(rs.getString(3));
out.print("</a></td><td>");
! out.print(rs.getString(4));
out.print("</td><td>");
out.print(amount);
--- 92,116 ----
else
book="neu:/"+book;
! Statement stmt=ledger.browse(ledger.getBook(book));
out.println("<table><tr><th>Transaction ID</th><th>Time</th><th>Counterparty</th><th>Comment</th><th>Amount</th></tr>");
! while(stmt.next()){
! final BigDecimal amount = stmt.getAmount();
out.print("<tr");
if (amount.compareTo(ZERO)<0)
out.print(" class=\"negative\"");
! out.print("><td style=\"size:small\">");
! out.print(stmt.getXid());
out.print("</td><td>");
! out.print(TimeTools.formatTimeStampShort(stmt.getValuetime()));
out.print("</td><td><a href=\"");
out.print(url);
! if (NSTools.isValidName(stmt.getCounterparty()))
! out.print(NSTools.name2path(stmt.getCounterparty()));
! else
! out.print("/"+stmt.getCounterparty());
out.println("\">");
! out.print(stmt.getCounterparty());
out.print("</a></td><td>");
! out.print(stmt.getComment());
out.print("</td><td>");
out.print(amount);
***************
*** 116,122 ****
}
out.println("</table>");
- } catch (SQLException e) {
- e.printStackTrace(out);
} catch (InvalidNamedObjectException e) {
e.printStackTrace();
}
--- 119,127 ----
}
out.println("</table>");
} catch (InvalidNamedObjectException e) {
+ e.printStackTrace();
+ } catch (UnknownBookException e) {
+ e.printStackTrace();
+ } catch (LowlevelLedgerException e) {
e.printStackTrace();
}
|
Update of /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/browser
In directory sc8-pr-cvs1:/tmp/cvs-serv2351/src/java/org/neuclear/ledger/browser
Added Files:
LedgerBrowser.java QueryStatement.java Statement.java
StatementEntry.java
Log Message:
Added Drivers for handling different Database dialects in the entity model.
Added Statement pattern to ledger, simplifying the statement writing process.
--- NEW FILE: LedgerBrowser.java ---
package org.neuclear.ledger.browser;
import org.neuclear.ledger.Book;
import org.neuclear.ledger.LowlevelLedgerException;
import java.util.Iterator;
import java.sql.Timestamp;
/*
NeuClear Distributed Transaction Clearing Platform
(C) 2003 Pelle Braendgaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: LedgerBrowser.java,v 1.1 2003/12/31 00:39:04 pelle Exp $
$Log: LedgerBrowser.java,v $
Revision 1.1 2003/12/31 00:39:04 pelle
Added Drivers for handling different Database dialects in the entity model.
Added Statement pattern to ledger, simplifying the statement writing process.
*/
/**
* User: pelleb
* Date: Dec 30, 2003
* Time: 4:09:59 PM
*/
public interface LedgerBrowser {
public Statement browse(Book book) throws LowlevelLedgerException;
public Statement browseFrom(Book book,Timestamp from) throws LowlevelLedgerException;
// public Statement browseUntil(Book book,Timestamp until);
public Statement browseRange(Book book,Timestamp from, Timestamp until) throws LowlevelLedgerException;
}
--- NEW FILE: QueryStatement.java ---
package org.neuclear.ledger.browser;
import org.neuclear.ledger.Book;
import org.neuclear.ledger.LowlevelLedgerException;
import org.neuclear.commons.Utility;
import java.sql.*;
import java.security.Principal;
/*
NeuClear Distributed Transaction Clearing Platform
(C) 2003 Pelle Braendgaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: QueryStatement.java,v 1.1 2003/12/31 00:39:04 pelle Exp $
$Log: QueryStatement.java,v $
Revision 1.1 2003/12/31 00:39:04 pelle
Added Drivers for handling different Database dialects in the entity model.
Added Statement pattern to ledger, simplifying the statement writing process.
*/
/**
* User: pelleb
* Date: Dec 30, 2003
* Time: 4:30:19 PM
*/
public class QueryStatement extends Statement {
public QueryStatement(Book book,Connection con) throws SQLException {
this(book,executeQuery(con,book));
}
public QueryStatement(Book book,Connection con,Timestamp from, Timestamp until) throws SQLException {
this(book,executeRangeQuery(con,book,from,until));
}
public QueryStatement(Book book,Connection con,Timestamp from) throws SQLException {
this(book,executeFromQuery(con,book,from));
}
private QueryStatement(Book book,ResultSet rs) throws SQLException {
super(book);
this.rs=rs;
next=rs.next();
}
private static ResultSet executeRangeQuery(Connection con,Book book,Timestamp from, Timestamp until) throws SQLException {
final PreparedStatement stmt = con.prepareStatement(RANGE_QUERY);
stmt.setTimestamp(3,from);
stmt.setTimestamp(4,until);
return executeQuery(stmt,book);
}
private static ResultSet executeFromQuery(Connection con,Book book,Timestamp from) throws SQLException {
final PreparedStatement stmt = con.prepareStatement(FROM_QUERY);
stmt.setTimestamp(3,from);
return executeQuery(stmt,book);
}
private static ResultSet executeUntilQuery(Connection con,Book book, Timestamp until) throws SQLException {
final PreparedStatement stmt = con.prepareStatement(UNTIL_QUERY);
stmt.setTimestamp(3,until);
return executeQuery(stmt,book);
}
private static ResultSet executeQuery(Connection con,Book book) throws SQLException {
return executeQuery(con.prepareStatement(FULL_QUERY),book);
}
private static ResultSet executeQuery(PreparedStatement stmt,Book book) throws SQLException {
stmt.setString(1,book.getBookID());
stmt.setString(2,book.getLedger().getId());
return stmt.executeQuery();
}
public boolean next() throws LowlevelLedgerException {
try {
if (!rs.next())
return false;
setRow(rs.getString(1),rs.getString(3),rs.getString(4),rs.getTimestamp(2),rs.getBigDecimal(5));
return true;
} catch (SQLException e) {
throw new LowlevelLedgerException(getBook().getLedger(),e);
}
}
private final ResultSet rs;
private boolean next;
private static final String BASE_QUERY = "select t.id,t.valuetime, r.bookid,t.comment,s.amount from entry s,entry r, transaction t where s.transactionid=t.id and r.transactionid=t.id and r.id<>s.id\nand s.bookid = ? and t.ledgerid=?";
private static final String UNTIL_CLAUSE = " AND t.valuetime<=?";
private static final String FROM_CLAUSE = " AND t.valuetime>?";
private static final String ORDERBY = " order by t.valuetime,t.id";
private static final String FULL_QUERY = BASE_QUERY+ORDERBY;
private static final String RANGE_QUERY = BASE_QUERY+FROM_CLAUSE+UNTIL_CLAUSE+ORDERBY;
private static final String FROM_QUERY = BASE_QUERY+FROM_CLAUSE+ORDERBY;
private static final String UNTIL_QUERY = BASE_QUERY+UNTIL_CLAUSE+ORDERBY;
}
--- NEW FILE: Statement.java ---
package org.neuclear.ledger.browser;
import org.neuclear.ledger.Book;
import org.neuclear.ledger.LowlevelLedgerException;
import java.util.Iterator;
import java.sql.Timestamp;
import java.math.BigDecimal;
/*
NeuClear Distributed Transaction Clearing Platform
(C) 2003 Pelle Braendgaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: Statement.java,v 1.1 2003/12/31 00:39:04 pelle Exp $
$Log: Statement.java,v $
Revision 1.1 2003/12/31 00:39:04 pelle
Added Drivers for handling different Database dialects in the entity model.
Added Statement pattern to ledger, simplifying the statement writing process.
*/
/**
* User: pelleb
* Date: Dec 30, 2003
* Time: 4:26:52 PM
*/
public abstract class Statement {
public Statement(Book book){
this.book=book;
}
public abstract boolean next() throws LowlevelLedgerException;
protected final void setRow(String xid,String counterparty,String comment,Timestamp valuetime, BigDecimal amount) {
this.xid=xid;
this.counterparty=counterparty;
this.comment=comment;
this.valuetime=valuetime;
this.amount=amount;
}
public Book getBook() {
return book;
}
public String getXid() {
return xid;
}
public String getCounterparty() {
return counterparty;
}
public String getComment() {
return comment;
}
public Timestamp getValuetime() {
return valuetime;
}
public BigDecimal getAmount() {
return amount;
}
private final Book book;
private String xid;
private String counterparty;
private String comment;
private Timestamp valuetime;
private BigDecimal amount;
}
--- NEW FILE: StatementEntry.java ---
package org.neuclear.ledger.browser;
import org.neuclear.ledger.Book;
import java.sql.Timestamp;
import java.math.BigDecimal;
/*
NeuClear Distributed Transaction Clearing Platform
(C) 2003 Pelle Braendgaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: StatementEntry.java,v 1.1 2003/12/31 00:39:04 pelle Exp $
$Log: StatementEntry.java,v $
Revision 1.1 2003/12/31 00:39:04 pelle
Added Drivers for handling different Database dialects in the entity model.
Added Statement pattern to ledger, simplifying the statement writing process.
*/
/**
* This class is used exclusively by the Browser to Generate rows in a ledger statement
*/
public final class StatementEntry {
StatementEntry(Book book) {
this.book = book;
}
void setRow(String xid,String counterparty,String comment,Timestamp valuetime, BigDecimal amount) {
this.xid=xid;
this.counterparty=counterparty;
this.comment=comment;
this.valuetime=valuetime;
this.amount=amount;
}
public Book getBook() {
return book;
}
public String getLedgerid() {
return book.getLedger().getId();
}
public String getXid() {
return xid;
}
public String getCounterparty() {
return counterparty;
}
public String getComment() {
return comment;
}
public Timestamp getValuetime() {
return valuetime;
}
public BigDecimal getAmount() {
return amount;
}
private final Book book;
private String xid;
private String counterparty;
private String comment;
private Timestamp valuetime;
private BigDecimal amount;
}
|
|
From: <pe...@us...> - 2003-12-30 21:08:36
|
Update of /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/browser In directory sc8-pr-cvs1:/tmp/cvs-serv24236/src/java/org/neuclear/ledger/browser Log Message: Directory /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/browser added to the repository |
|
From: <pe...@us...> - 2003-12-30 19:38:18
|
Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/sql/entities/drivers In directory sc8-pr-cvs1:/tmp/cvs-serv6221/src/java/org/neuclear/commons/sql/entities/drivers Log Message: Directory /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/sql/entities/drivers added to the repository |
|
From: <pe...@us...> - 2003-12-29 22:40:43
|
Update of /cvsroot/neuclear/neuclear-commons/src/test-cactus/org/neuclear/commons/crypto/passphraseagents In directory sc8-pr-cvs1:/tmp/cvs-serv30111/src/test-cactus/org/neuclear/commons/crypto/passphraseagents Modified Files: ServletPassPhraseAgentTest.java Log Message: Added LedgerServlet and friends Index: ServletPassPhraseAgentTest.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/test-cactus/org/neuclear/commons/crypto/passphraseagents/ServletPassPhraseAgentTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 |
|
From: <pe...@us...> - 2003-12-29 22:40:43
|
Update of /cvsroot/neuclear/neuclear-commons/src/test/org/neuclear/commons/sql/entities
In directory sc8-pr-cvs1:/tmp/cvs-serv30111/src/test/org/neuclear/commons/sql/entities
Modified Files:
TableDefinitionTest.java
Log Message:
Added LedgerServlet and friends
Index: TableDefinitionTest.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-commons/src/test/org/neuclear/commons/sql/entities/TableDefinitionTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TableDefinitionTest.java 26 Dec 2003 22:51:17 -0000 1.2
--- TableDefinitionTest.java 29 Dec 2003 22:40:38 -0000 1.3
***************
*** 34,37 ****
--- 34,40 ----
$Id$
$Log$
+ Revision 1.3 2003/12/29 22:40:38 pelle
+ Added LedgerServlet and friends
+
Revision 1.2 2003/12/26 22:51:17 pelle
Mainly fixes to SQLLedger to support the schema generated by the new EntityModel
***************
*** 125,129 ****
table.addComment();
table.create(con);
! Entity entity=table.insertEntity(con,new Object[] {
"created",TimeTools.now(),
"sender",new Object[]{
--- 128,132 ----
table.addComment();
table.create(con);
! /* Entity entity=table.insertEntity(con,new Object[] {
"created",TimeTools.now(),
"sender",new Object[]{
***************
*** 137,141 ****
});
assertNotNull(entity);
!
con.commit();
con.close();
--- 140,144 ----
});
assertNotNull(entity);
! */
con.commit();
con.close();
|
|
From: <pe...@us...> - 2003-12-29 22:40:20
|
Update of /cvsroot/neuclear/neuclear-ledger/src/webapp/WEB-INF In directory sc8-pr-cvs1:/tmp/cvs-serv30032/src/webapp/WEB-INF Added Files: web.xml Log Message: Added LedgerServlet and friends --- NEW FILE: web.xml --- <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <context-param> <param-name>serviceid</param-name> <param-value>neu://test/bux</param-value> <description>NeuClear id of Service</description> </context-param> <context-param> <param-name>title</param-name> <param-value>NeuClear Sample E-Currency Application</param-value> </context-param> <context-param> <param-name>datasource</param-name> <param-value>jdbc/AssetDS</param-value> </context-param> <servlet> <servlet-name>browser</servlet-name> <servlet-class>org.neuclear.ledger.servlets.LedgerServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>browser</servlet-name> <url-pattern>/browse/*</url-pattern> </servlet-mapping> </web-app> |
|
From: <pe...@us...> - 2003-12-29 22:40:20
|
Update of /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/servlets
In directory sc8-pr-cvs1:/tmp/cvs-serv30032/src/java/org/neuclear/ledger/servlets
Added Files:
LedgerServlet.java
Log Message:
Added LedgerServlet and friends
--- NEW FILE: LedgerServlet.java ---
package org.neuclear.ledger.servlets;
import org.neuclear.commons.servlets.ServletTools;
import org.neuclear.commons.time.TimeTools;
import org.neuclear.commons.Utility;
import org.neuclear.commons.sql.JNDIConnectionSource;
import org.neuclear.id.NSTools;
import org.neuclear.id.InvalidNamedObjectException;
import org.neuclear.ledger.implementations.SQLLedger;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.sql.DataSource;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.security.Principal;
import java.math.BigDecimal;
/*
NeuClear Distributed Transaction Clearing Platform
(C) 2003 Pelle Braendgaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: LedgerServlet.java,v 1.1 2003/12/29 22:40:15 pelle Exp $
$Log: LedgerServlet.java,v $
Revision 1.1 2003/12/29 22:40:15 pelle
Added LedgerServlet and friends
*/
/**
* User: pelleb
* Date: Dec 26, 2003
* Time: 5:54:05 PM
*/
public class LedgerServlet extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
datasource = ServletTools.getInitParam("datasource",config);
serviceid = ServletTools.getInitParam("serviceid",config);
try {
consrc = new JNDIConnectionSource(datasource);
ledger= new SQLLedger(
consrc,
serviceid
);
ledger.createLedger(serviceid);
} catch (Exception e) {
throw new ServletException(e);
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out=response.getWriter();
ServletTools.printHeader(out,request,"Account Browser");
String url=request.getServletPath();
try {
Connection con=consrc.getConnection();
PreparedStatement stmt=con.prepareStatement("select t.id,t.valuetime, r.bookid,t.comment,s.amount from entry s,entry r, transaction t where s.transactionid=t.id and r.transactionid=t.id and r.id<>s.id\n" +
"and (s.bookid = ? ) and t.ledgerid=?");
Principal user=request.getUserPrincipal();
String book=request.getPathInfo();
if (Utility.isEmpty(book))
book=serviceid;
else
book="neu:/"+book;
stmt.setString(1,book);
stmt.setString(2,book);
stmt.setString(3,serviceid);
ResultSet rs=stmt.executeQuery();
out.println("<table><tr><th>Transaction ID</th><th>Time</th><th>Counterparty</th><th>Comment</th><th>Amount</th></tr>");
while(rs.next()){
final BigDecimal amount = rs.getBigDecimal(5);
out.print("<tr");
if (amount.compareTo(ZERO)<0)
out.print(" class=\"negative\"");
out.print("><td>");
out.print(rs.getString(1));
out.print("</td><td>");
out.print(TimeTools.formatTimeStamp(rs.getTimestamp(2)));
out.print("</td><td><a href=\"");
out.print(url);
out.print(NSTools.name2path(rs.getString(3)));
out.println("\">");
out.print(rs.getString(3));
out.print("</a></td><td>");
out.print(rs.getString(4));
out.print("</td><td>");
out.print(amount);
out.print("</td></tr>");
}
out.println("</table>");
} catch (SQLException e) {
e.printStackTrace(out);
} catch (InvalidNamedObjectException e) {
e.printStackTrace();
}
}
private DataSource ds;
private String datasource;
private String serviceid;
private static final BigDecimal ZERO=new BigDecimal(0);
private SQLLedger ledger;
private JNDIConnectionSource consrc;
}
|
|
From: <pe...@us...> - 2003-12-29 22:40:20
|
Update of /cvsroot/neuclear/neuclear-ledger
In directory sc8-pr-cvs1:/tmp/cvs-serv30032
Modified Files:
project.properties project.xml
Log Message:
Added LedgerServlet and friends
Index: project.properties
===================================================================
RCS file: /cvsroot/neuclear/neuclear-ledger/project.properties,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** project.properties 26 Dec 2003 22:50:52 -0000 1.5
--- project.properties 29 Dec 2003 22:40:16 -0000 1.6
***************
*** 2,6 ****
# P R O J E C T P R O P E R T I E S
# -------------------------------------------------------------------
! #maven.test.skip=true
maven.compile.debug = on
--- 2,6 ----
# P R O J E C T P R O P E R T I E S
# -------------------------------------------------------------------
! maven.test.skip=true
maven.compile.debug = on
Index: project.xml
===================================================================
RCS file: /cvsroot/neuclear/neuclear-ledger/project.xml,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** project.xml 26 Dec 2003 22:50:52 -0000 1.10
--- project.xml 29 Dec 2003 22:40:16 -0000 1.11
***************
*** 65,80 ****
<id>hsqldb</id>
<version>1.7.1</version>
</dependency>
<dependency>
<id>picocontainer</id>
<version>1.0-beta-1</version>
</dependency>
<dependency>
- <id>nanocontainer</id>
- <version>1.0-alpha-PRESPLIT-1</version>
- </dependency>
- <dependency>
<id>neuclear-commons</id>
<version>0.6-SNAPSHOT</version>
</dependency>
<dependency>
--- 65,88 ----
<id>hsqldb</id>
<version>1.7.1</version>
+ <properties>
+ <war.bundle>true</war.bundle>
+ </properties>
</dependency>
<dependency>
+ <id>neuclear-id</id>
+ <version>0.8.1</version>
+ <properties>
+ <war.bundle>true</war.bundle>
+ </properties> </dependency>
+ <dependency>
<id>picocontainer</id>
<version>1.0-beta-1</version>
</dependency>
<dependency>
<id>neuclear-commons</id>
<version>0.6-SNAPSHOT</version>
+ <properties>
+ <war.bundle>true</war.bundle>
+ </properties>
</dependency>
<dependency>
***************
*** 87,90 ****
--- 95,102 ----
</properties>
</dependency>
+ <dependency>
+ <id>servletapi</id>
+ <version>2.3</version>
+ </dependency>
<dependency>
<id>junit</id>
***************
*** 95,110 ****
<id>carol</id>
<version>1.5.2</version>
</dependency>
<dependency>
! <id>jotm</id>
<version>1.4.3</version>
</dependency>
<dependency>
<id>xapool</id>
<version>1.3.1</version>
</dependency>
<dependency>
<id>jta-spec</id>
<version>1.0.1</version>
</dependency>
<dependency>
--- 107,143 ----
<id>carol</id>
<version>1.5.2</version>
+ <properties>
+ <war.bundle>true</war.bundle>
+ </properties>
</dependency>
<dependency>
! <groupId>jotm</groupId>
! <artifactId>jotm</artifactId>
<version>1.4.3</version>
+ <properties>
+ <war.bundle>true</war.bundle>
+ </properties>
+ </dependency>
+ <dependency>
+ <groupId>jotm</groupId>
+ <artifactId>jotm_jrmp_stubs</artifactId>
+ <version>1.4.3</version>
+ <properties>
+ <war.bundle>true</war.bundle>
+ </properties>
</dependency>
<dependency>
<id>xapool</id>
<version>1.3.1</version>
+ <properties>
+ <war.bundle>true</war.bundle>
+ </properties>
</dependency>
<dependency>
<id>jta-spec</id>
<version>1.0.1</version>
+ <properties>
+ <war.bundle>true</war.bundle>
+ </properties>
</dependency>
<dependency>
|
Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/sql/entities
In directory sc8-pr-cvs1:/tmp/cvs-serv2763/src/java/org/neuclear/commons/sql/entities
Modified Files:
DataColumnDefinition.java Entity.java EntityModel.java
Added Files:
Schema.java
Log Message:
Mainly fixes to SQLLedger to support the schema generated by the new EntityModel
--- NEW FILE: Schema.java ---
package org.neuclear.commons.sql.entities;
/*
NeuClear Distributed Transaction Clearing Platform
(C) 2003 Pelle Braendgaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: Schema.java,v 1.1 2003/12/26 22:51:17 pelle Exp $
$Log: Schema.java,v $
Revision 1.1 2003/12/26 22:51:17 pelle
Mainly fixes to SQLLedger to support the schema generated by the new EntityModel
*/
/**
* User: pelleb
* Date: Dec 26, 2003
* Time: 3:21:10 PM
*/
public class Schema {
}
Index: DataColumnDefinition.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/sql/entities/DataColumnDefinition.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DataColumnDefinition.java 24 Dec 2003 00:25:40 -0000 1.1
--- DataColumnDefinition.java 26 Dec 2003 22:51:17 -0000 1.2
***************
*** 21,24 ****
--- 21,27 ----
$Id$
$Log$
+ Revision 1.2 2003/12/26 22:51:17 pelle
+ Mainly fixes to SQLLedger to support the schema generated by the new EntityModel
+
Revision 1.1 2003/12/24 00:25:40 pelle
Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code.
***************
*** 54,58 ****
return "TIMESTAMP";
case FIELD_ID:
! return "BIGINT";
case FIELD_BOOLEAN:
return "TINYINT";
--- 57,61 ----
return "TIMESTAMP";
case FIELD_ID:
! return "IDENTITY";
case FIELD_BOOLEAN:
return "TINYINT";
Index: Entity.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/sql/entities/Entity.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Entity.java 24 Dec 2003 00:25:40 -0000 1.1
--- Entity.java 26 Dec 2003 22:51:17 -0000 1.2
***************
*** 21,24 ****
--- 21,27 ----
$Id$
$Log$
+ Revision 1.2 2003/12/26 22:51:17 pelle
+ Mainly fixes to SQLLedger to support the schema generated by the new EntityModel
+
Revision 1.1 2003/12/24 00:25:40 pelle
Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code.
***************
*** 36,40 ****
*/
public class Entity {
! public Entity(EntityModel model,String id,Object[] data) {
this.model = model;
this.data=data;
--- 39,43 ----
*/
public class Entity {
! Entity(EntityModel model,String id,Object[] data) {
this.model = model;
this.data=data;
Index: EntityModel.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/sql/entities/EntityModel.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** EntityModel.java 24 Dec 2003 00:25:40 -0000 1.1
--- EntityModel.java 26 Dec 2003 22:51:17 -0000 1.2
***************
*** 27,30 ****
--- 27,33 ----
$Id$
$Log$
+ Revision 1.2 2003/12/26 22:51:17 pelle
+ Mainly fixes to SQLLedger to support the schema generated by the new EntityModel
+
Revision 1.1 2003/12/24 00:25:40 pelle
Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code.
***************
*** 47,50 ****
--- 50,54 ----
foreign=new LinkedList();
this.name=name;
+ this.uri=uri;
id=new DataColumnDefinition(this,idname,uri?ColumnDefinition.FIELD_URI:ColumnDefinition.FIELD_ID);
addColumn(id);
***************
*** 53,57 ****
this(name,"id",uri);
}
! public final void create(Connection con){
//first lets build all the Dependencies
for (int i = 0; i < foreign.size(); i++) {
--- 57,61 ----
this(name,"id",uri);
}
! public synchronized final void create(Connection con){
//first lets build all the Dependencies
for (int i = 0; i < foreign.size(); i++) {
***************
*** 59,68 ****
definition.getRef().create(con);
}
- System.out.println("Attempting to create: "+getName());
try {
PreparedStatement stmt=con.prepareStatement(createDDL());
stmt.execute();
} catch (SQLException e) {
! System.out.println(e.getLocalizedMessage());
}
}
--- 63,73 ----
definition.getRef().create(con);
}
try {
PreparedStatement stmt=con.prepareStatement(createDDL());
stmt.execute();
+ System.out.println("Created: "+getName());
} catch (SQLException e) {
! if (e.getMessage().indexOf("exists")==-1)
! System.out.println(e.getLocalizedMessage());
}
}
***************
*** 72,84 ****
buf.append(" (\n");
Iterator iter=colseq.iterator();
while(iter.hasNext()) {
ColumnDefinition col=(ColumnDefinition)iter.next();
buf.append(col.createDDL());
- buf.append(",\n");
}
iter=foreign.iterator();
while(iter.hasNext()) {
ReferenceDefinition col=(ReferenceDefinition)iter.next();
! buf.append("FOREIGN KEY (");
buf.append(col.getName());
buf.append(") REFERENCES ");
--- 77,94 ----
buf.append(" (\n");
Iterator iter=colseq.iterator();
+ boolean first=true;
while(iter.hasNext()) {
+ if (first)
+ first=false;
+ else
+ buf.append(",\n");
+
ColumnDefinition col=(ColumnDefinition)iter.next();
buf.append(col.createDDL());
}
iter=foreign.iterator();
while(iter.hasNext()) {
ReferenceDefinition col=(ReferenceDefinition)iter.next();
! buf.append(",\nFOREIGN KEY (");
buf.append(col.getName());
buf.append(") REFERENCES ");
***************
*** 86,90 ****
buf.append("(");
buf.append(col.getRef().getId().getName());
! buf.append(") ON DELETE CASCADE,\n");
// buf.append("INDEX ");
// buf.append(col.getName());
--- 96,100 ----
buf.append("(");
buf.append(col.getRef().getId().getName());
! buf.append(") ON DELETE CASCADE");
// buf.append("INDEX ");
// buf.append(col.getName());
***************
*** 93,99 ****
// buf.append("),\n");
}
! buf.append("PRIMARY KEY(");
! buf.append(id.getName());
! buf.append(")\n)");
return buf.toString();
}
--- 103,112 ----
// buf.append("),\n");
}
! if (uri){
! buf.append(",\nPRIMARY KEY(");
! buf.append(id.getName());
! buf.append(")");
! }
! buf.append("\n)");
return buf.toString();
}
***************
*** 158,162 ****
return id;
}
! final Entity insertEntity(Connection con,Object data[]) throws SQLException {
if ((data.length%2==1))//&&(data.length/2<columns.size()))
throw new SQLException("Incorrect amount of parameters");
--- 171,175 ----
return id;
}
! public final Entity insertEntity(Connection con,Object data[]) throws SQLException {
if ((data.length%2==1))//&&(data.length/2<columns.size()))
throw new SQLException("Incorrect amount of parameters");
***************
*** 221,224 ****
--- 234,238 ----
private final List foreign;
private final String name;
+ private final boolean uri;
}
|
|
From: <pe...@us...> - 2003-12-26 22:51:21
|
Update of /cvsroot/neuclear/neuclear-commons
In directory sc8-pr-cvs1:/tmp/cvs-serv2763
Modified Files:
project.xml
Log Message:
Mainly fixes to SQLLedger to support the schema generated by the new EntityModel
Index: project.xml
===================================================================
RCS file: /cvsroot/neuclear/neuclear-commons/project.xml,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** project.xml 22 Dec 2003 22:14:37 -0000 1.18
--- project.xml 26 Dec 2003 22:51:17 -0000 1.19
***************
*** 4,8 ****
<name>NeuClear Commons</name>
<id>neuclear-commons</id>
! <currentVersion>0.5.1</currentVersion>
<inceptionYear>2003</inceptionYear>
<package>org.neuclear.commons</package>
--- 4,8 ----
<name>NeuClear Commons</name>
<id>neuclear-commons</id>
! <currentVersion>0.6-SNAPSHOT</currentVersion>
<inceptionYear>2003</inceptionYear>
<package>org.neuclear.commons</package>
***************
*** 74,77 ****
--- 74,81 ----
</dependency>
<dependency>
+ <id>hsqldb</id>
+ <version>1.7.1</version>
+ </dependency>
+ <dependency>
<id>picocontainer</id>
<version>1.0-beta-1</version>
***************
*** 120,124 ****
<version>1.0.1</version>
</dependency>
!
</dependencies>
--- 124,131 ----
<version>1.0.1</version>
</dependency>
! <dependency>
! <id>commons-logging</id>
! <version>1.0.3</version>
! </dependency>
</dependencies>
|
Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/sql
In directory sc8-pr-cvs1:/tmp/cvs-serv2763/src/java/org/neuclear/commons/sql
Modified Files:
SimpleConnectionSource.java XAConnectionSource.java
Added Files:
TestCaseConnectionSource.java TestCaseXAConnectionSource.java
Log Message:
Mainly fixes to SQLLedger to support the schema generated by the new EntityModel
--- NEW FILE: TestCaseConnectionSource.java ---
package org.neuclear.commons.sql;
import org.neuclear.commons.NeuClearException;
import javax.naming.NamingException;
import java.sql.Connection;
import java.sql.SQLException;
import java.io.IOException;
/*
NeuClear Distributed Transaction Clearing Platform
(C) 2003 Pelle Braendgaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: TestCaseConnectionSource.java,v 1.1 2003/12/26 22:51:17 pelle Exp $
$Log: TestCaseConnectionSource.java,v $
Revision 1.1 2003/12/26 22:51:17 pelle
Mainly fixes to SQLLedger to support the schema generated by the new EntityModel
*/
/**
* User: pelleb
* Date: Dec 26, 2003
* Time: 4:31:46 PM
*/
public class TestCaseConnectionSource extends SimpleConnectionSource{
public TestCaseConnectionSource() throws SQLException, NeuClearException, NamingException {
super( "org.hsqldb.jdbcDriver", "jdbc:hsqldb:target/testdata/db/ledger", "sa", "");
}
}
--- NEW FILE: TestCaseXAConnectionSource.java ---
package org.neuclear.commons.sql;
import org.neuclear.commons.NeuClearException;
import javax.naming.NamingException;
import java.sql.Connection;
import java.sql.SQLException;
import java.io.IOException;
/*
NeuClear Distributed Transaction Clearing Platform
(C) 2003 Pelle Braendgaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: TestCaseXAConnectionSource.java,v 1.1 2003/12/26 22:51:17 pelle Exp $
$Log: TestCaseXAConnectionSource.java,v $
Revision 1.1 2003/12/26 22:51:17 pelle
Mainly fixes to SQLLedger to support the schema generated by the new EntityModel
*/
/**
* User: pelleb
* Date: Dec 26, 2003
* Time: 4:31:46 PM
*/
public class TestCaseXAConnectionSource extends XAConnectionSource{
public TestCaseXAConnectionSource() throws SQLException, NeuClearException, NamingException {
super("jdbc/NeuClearTest", "org.hsqldb.jdbcDriver", "jdbc:hsqldb:target/testdata/db/ledger", "sa", "");
}
}
Index: SimpleConnectionSource.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/sql/SimpleConnectionSource.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** SimpleConnectionSource.java 24 Dec 2003 00:25:41 -0000 1.4
--- SimpleConnectionSource.java 26 Dec 2003 22:51:17 -0000 1.5
***************
*** 17,21 ****
* Time: 3:38:50 PM
*/
! public final class SimpleConnectionSource implements ConnectionSource {
public SimpleConnectionSource(final String driver, final String url, final String user, final String password) throws SQLException, NeuClearException, NamingException {
try {
--- 17,21 ----
* Time: 3:38:50 PM
*/
! public class SimpleConnectionSource implements ConnectionSource {
public SimpleConnectionSource(final String driver, final String url, final String user, final String password) throws SQLException, NeuClearException, NamingException {
try {
Index: XAConnectionSource.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/sql/XAConnectionSource.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** XAConnectionSource.java 3 Dec 2003 23:22:06 -0000 1.2
--- XAConnectionSource.java 26 Dec 2003 22:51:17 -0000 1.3
***************
*** 6,10 ****
--- 6,12 ----
import javax.naming.Context;
import javax.naming.NamingException;
+ import javax.naming.InitialContext;
import javax.sql.XADataSource;
+ import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Connection;
***************
*** 16,24 ****
* Time: 3:38:50 PM
*/
! public final class XAConnectionSource implements ConnectionSource {
public XAConnectionSource(final String name, final String driver, final String url, final String user, final String password) throws SQLException, NeuClearException, NamingException {
Context ctx = SQLTools.loadDefaultContext();
SQLTools.getTransactionManager();
try {
Class.forName(driver).newInstance();
} catch (InstantiationException e) {
--- 18,36 ----
* Time: 3:38:50 PM
*/
! public class XAConnectionSource implements ConnectionSource {
public XAConnectionSource(final String name, final String driver, final String url, final String user, final String password) throws SQLException, NeuClearException, NamingException {
+
Context ctx = SQLTools.loadDefaultContext();
SQLTools.getTransactionManager();
try {
+ DataSource ds = (DataSource) ctx.lookup("java:comp/env/" + name);
+ if (ds!=null){
+ xads=(XADataSource) ds;
+ return;
+ }
+ } catch (Exception e) {
+ ;//ignore and create new datasource
+ }
+ try {
Class.forName(driver).newInstance();
} catch (InstantiationException e) {
***************
*** 37,41 ****
! ctx.bind(name, xads);
}
--- 49,53 ----
! ctx.rebind(name, xads);
}
***************
*** 46,50 ****
}
! private final XADataSource xads;
// private XAConnection xaConnection;
--- 58,62 ----
}
! private XADataSource xads;
// private XAConnection xaConnection;
|
|
From: <pe...@us...> - 2003-12-26 22:51:21
|
Update of /cvsroot/neuclear/neuclear-commons/src/test/org/neuclear/commons/sql/entities In directory sc8-pr-cvs1:/tmp/cvs-serv2763/src/test/org/neuclear/commons/sql/entities Modified Files: TableDefinitionTest.java Log Message: Mainly fixes to SQLLedger to support the schema generated by the new EntityModel Index: TableDefinitionTest.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/test/org/neuclear/commons/sql/entities/TableDefinitionTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TableDefinitionTest.java 24 Dec 2003 00:25:41 -0000 1.1 --- TableDefinitionTest.java 26 Dec 2003 22:51:17 -0000 1.2 *************** *** 4,7 **** --- 4,8 ---- import org.neuclear.commons.sql.ConnectionSource; import org.neuclear.commons.sql.DefaultConnectionSource; + import org.neuclear.commons.sql.TestCaseConnectionSource; import org.neuclear.commons.NeuClearException; import org.neuclear.commons.time.TimeTools; *************** *** 33,36 **** --- 34,40 ---- $Id$ $Log$ + Revision 1.2 2003/12/26 22:51:17 pelle + Mainly fixes to SQLLedger to support the schema generated by the new EntityModel + Revision 1.1 2003/12/24 00:25:41 pelle Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code. *************** *** 68,78 **** table.addComment(); String correct="CREATE TABLE transaction (\n" + ! "id BIGINT,\n" + ! "valuetime TIMESTAMP,\n" + "from VARCHAR(50),\n" + "to VARCHAR(50),\n" + "amount DECIMAL,\n" + ! "comment VARCHAR(100),\n" + ! "PRIMARY KEY(id)\n)"; System.out.println(table.createDDL()); assertEquals(correct,table.createDDL()); --- 72,82 ---- table.addComment(); String correct="CREATE TABLE transaction (\n" + ! "id IDENTITY,\n" + ! "created TIMESTAMP,\n" + "from VARCHAR(50),\n" + "to VARCHAR(50),\n" + "amount DECIMAL,\n" + ! "comment VARCHAR(100)\n" + ! ")"; System.out.println(table.createDDL()); assertEquals(correct,table.createDDL()); *************** *** 87,92 **** table.addComment(); String correct="CREATE TABLE transaction (\n" + ! "id BIGINT,\n" + ! "valuetime TIMESTAMP,\n" + "sender VARCHAR(50),\n" + "to VARCHAR(50),\n" + --- 91,96 ---- table.addComment(); String correct="CREATE TABLE transaction (\n" + ! "id IDENTITY,\n" + ! "created TIMESTAMP,\n" + "sender VARCHAR(50),\n" + "to VARCHAR(50),\n" + *************** *** 95,101 **** "FOREIGN KEY (sender) REFERENCES accounts(id) ON DELETE CASCADE,\n" + // "INDEX fromidx (from),\n" + ! "FOREIGN KEY (to) REFERENCES accounts(id) ON DELETE CASCADE,\n" + // "INDEX toidx (to),\n" + ! "PRIMARY KEY(id)\n)"; System.out.println(table.createDDL()); assertEquals(correct,table.createDDL()); --- 99,105 ---- "FOREIGN KEY (sender) REFERENCES accounts(id) ON DELETE CASCADE,\n" + // "INDEX fromidx (from),\n" + ! "FOREIGN KEY (to) REFERENCES accounts(id) ON DELETE CASCADE\n" + // "INDEX toidx (to),\n" + ! ")"; System.out.println(table.createDDL()); assertEquals(correct,table.createDDL()); *************** *** 103,108 **** public void testCreateTableStructure() throws SQLException, IOException, NamingException, NeuClearException { ! EntityModel accounts=new EntityModel("accounts", true); ! EntityModel table=new EntityModel("transaction", false); table.addTimeStamp(); table.addReference("sender",accounts); --- 107,122 ---- public void testCreateTableStructure() throws SQLException, IOException, NamingException, NeuClearException { ! final Connection con = new TestCaseConnectionSource().getConnection(); ! try { ! PreparedStatement stmt=con.prepareStatement("drop testtransaction"); ! stmt.execute(); ! stmt=con.prepareStatement("drop testaccounts"); ! stmt.execute(); ! } catch (Exception e) { ! ; ! } ! ! EntityModel accounts=new EntityModel("testaccounts", true); ! EntityModel table=new EntityModel("testtransaction", false); table.addTimeStamp(); table.addReference("sender",accounts); *************** *** 110,118 **** table.addMoney(); table.addComment(); - final Connection con = new DefaultConnectionSource().getConnection(); table.create(con); Entity entity=table.insertEntity(con,new Object[] { ! "id",new Long(new Random().nextLong()), ! "valuetime",TimeTools.now(), "sender",new Object[]{ "id","neu://bob@test" --- 124,130 ---- table.addMoney(); table.addComment(); table.create(con); Entity entity=table.insertEntity(con,new Object[] { ! "created",TimeTools.now(), "sender",new Object[]{ "id","neu://bob@test" |
|
From: <pe...@us...> - 2003-12-26 22:50:56
|
Update of /cvsroot/neuclear/neuclear-ledger In directory sc8-pr-cvs1:/tmp/cvs-serv2665 Modified Files: project.properties project.xml Log Message: Mainly fixes to SQLLedger to support the schema generated by the new EntityModel Index: project.properties =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger/project.properties,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** project.properties 11 Nov 2003 03:10:16 -0000 1.4 --- project.properties 26 Dec 2003 22:50:52 -0000 1.5 *************** *** 2,5 **** --- 2,6 ---- # P R O J E C T P R O P E R T I E S # ------------------------------------------------------------------- + #maven.test.skip=true maven.compile.debug = on *************** *** 19,23 **** #maven.ui.property.file = ui.properties maven.repo.remote = http://www.ibiblio.org/maven/,http://dist.codehaus.org/,http://neuclear.org/maven/ - maven.test.skip=true maven.repo.central = neuclear.org maven.repo.central.directory = /home/sites/neuclear.org/public_html/maven --- 20,23 ---- Index: project.xml =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger/project.xml,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** project.xml 8 Dec 2003 18:57:28 -0000 1.9 --- project.xml 26 Dec 2003 22:50:52 -0000 1.10 *************** *** 4,8 **** <name>NeuClear Ledger</name> <id>neuclear-ledger</id> ! <currentVersion>0.3</currentVersion> <inceptionYear>2003</inceptionYear> <package>org.neuclear.ledger</package> --- 4,8 ---- <name>NeuClear Ledger</name> <id>neuclear-ledger</id> ! <currentVersion>0.4-SNAPSHOT</currentVersion> <inceptionYear>2003</inceptionYear> <package>org.neuclear.ledger</package> *************** *** 63,68 **** <dependencies> <dependency> ! <id>mysql</id> ! <jar>mysql-connector-java-3.0.8-stable-bin.jar</jar> </dependency> <dependency> --- 63,68 ---- <dependencies> <dependency> ! <id>hsqldb</id> ! <version>1.7.1</version> </dependency> <dependency> *************** *** 76,80 **** <dependency> <id>neuclear-commons</id> ! <version>0.4</version> </dependency> <dependency> --- 76,80 ---- <dependency> <id>neuclear-commons</id> ! <version>0.6-SNAPSHOT</version> </dependency> <dependency> *************** *** 108,111 **** --- 108,116 ---- <version>1.0.1</version> </dependency> + <dependency> + <id>commons-logging</id> + <version>1.0.3</version> + </dependency> + </dependencies> <build> |
|
From: <pe...@us...> - 2003-12-26 22:50:55
|
Update of /cvsroot/neuclear/neuclear-ledger/src/test/org/neuclear/ledger In directory sc8-pr-cvs1:/tmp/cvs-serv2665/src/test/org/neuclear/ledger Modified Files: LedgerTest.java SQLLedgerTest.java Log Message: Mainly fixes to SQLLedger to support the schema generated by the new EntityModel Index: LedgerTest.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger/src/test/org/neuclear/ledger/LedgerTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** LedgerTest.java 24 Dec 2003 00:24:33 -0000 1.7 --- LedgerTest.java 26 Dec 2003 22:50:52 -0000 1.8 *************** *** 5,8 **** --- 5,10 ---- import org.neuclear.commons.sql.DefaultConnectionSource; import org.neuclear.commons.sql.DefaultXAConnectionSource; + import org.neuclear.commons.sql.TestCaseConnectionSource; + import org.neuclear.commons.sql.TestCaseXAConnectionSource; import org.neuclear.ledger.implementations.SQLLedger; *************** *** 23,26 **** --- 25,31 ---- * $Id$ * $Log$ + * Revision 1.8 2003/12/26 22:50:52 pelle + * Mainly fixes to SQLLedger to support the schema generated by the new EntityModel + * * Revision 1.7 2003/12/24 00:24:33 pelle * Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code. *************** *** 122,126 **** public LedgerTest(final String s) throws LowlevelLedgerException, UnknownLedgerException, SQLException, NamingException, IOException, NeuClearException { super(s); ! ledger = new SQLLedger(new DefaultXAConnectionSource(), "neu://superbux/reserve"); } --- 127,131 ---- public LedgerTest(final String s) throws LowlevelLedgerException, UnknownLedgerException, SQLException, NamingException, IOException, NeuClearException { super(s); ! ledger = new SQLLedger(new TestCaseXAConnectionSource(), "neu://superbux/reserve"); } *************** *** 253,258 **** assertEquals(aliceBalance - amount, alice.getAvailableBalance(t2), 0); assertEquals(aliceBalance - amount, alice.getAvailableBalance(t3), 0); ! assertEquals(aliceBalance - amount, alice.getAvailableBalance(t4), 0); // Her available balance should be the same as her real balance here assertEquals(alice.getBalance(t5), alice.getAvailableBalance(t5), 0); assertEquals(alice.getBalance(t1), alice.getAvailableBalance(t1), 0); --- 258,264 ---- assertEquals(aliceBalance - amount, alice.getAvailableBalance(t2), 0); assertEquals(aliceBalance - amount, alice.getAvailableBalance(t3), 0); ! // Her available balance should be the same as her real balance here + assertEquals(alice.getBalance(t4), alice.getAvailableBalance(t4), 0); assertEquals(alice.getBalance(t5), alice.getAvailableBalance(t5), 0); assertEquals(alice.getBalance(t1), alice.getAvailableBalance(t1), 0); *************** *** 324,328 **** assertEquals(ignacio.getAvailableBalance(t2), balance - held, 0); assertEquals(ignacio.getAvailableBalance(t3), balance - held, 0); ! assertEquals(ignacio.getAvailableBalance(t4), balance - held, 0); assertEquals(ignacio.getAvailableBalance(t5), balance, 0); --- 330,334 ---- assertEquals(ignacio.getAvailableBalance(t2), balance - held, 0); assertEquals(ignacio.getAvailableBalance(t3), balance - held, 0); ! assertEquals(ignacio.getAvailableBalance(t4), balance , 0); assertEquals(ignacio.getAvailableBalance(t5), balance, 0); Index: SQLLedgerTest.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger/src/test/org/neuclear/ledger/SQLLedgerTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SQLLedgerTest.java 24 Dec 2003 00:24:33 -0000 1.4 --- SQLLedgerTest.java 26 Dec 2003 22:50:52 -0000 1.5 *************** *** 20,24 **** public SQLLedgerTest(final String s) throws LowlevelLedgerException, UnknownLedgerException, SQLException, NamingException, IOException, NeuClearException { super(s); ! SQLLedger.create(new DefaultConnectionSource()); } --- 20,24 ---- public SQLLedgerTest(final String s) throws LowlevelLedgerException, UnknownLedgerException, SQLException, NamingException, IOException, NeuClearException { super(s); ! //SQLLedger.create(new DefaultConnectionSource()); } |
|
From: <pe...@us...> - 2003-12-26 22:50:55
|
Update of /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/implementations
In directory sc8-pr-cvs1:/tmp/cvs-serv2665/src/java/org/neuclear/ledger/implementations
Modified Files:
SQLLedger.java
Log Message:
Mainly fixes to SQLLedger to support the schema generated by the new EntityModel
Index: SQLLedger.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/implementations/SQLLedger.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** SQLLedger.java 24 Dec 2003 00:24:32 -0000 1.6
--- SQLLedger.java 26 Dec 2003 22:50:52 -0000 1.7
***************
*** 13,18 ****
--- 13,22 ----
import org.neuclear.commons.sql.entities.EntityModel;
import org.neuclear.commons.NeuClearException;
+ import org.neuclear.commons.crypto.CryptoTools;
import org.neuclear.ledger.*;
import org.neuclear.ledger.InvalidTransactionException;
+ import org.neuclear.id.NSTools;
+ import org.bouncycastle.crypto.Digest;
+ import org.bouncycastle.crypto.digests.SHA1Digest;
import javax.transaction.*;
***************
*** 48,61 ****
// create(this.con);
createLedger(id);
-
}
public void createLedger(String name) throws LowlevelLedgerException {
try {
! final PreparedStatement stmt = prepQuery("insert into ledger (id,title,created) values (?,?,now())");
! stmt.setString(1, name);
! stmt.setString(2, name);
! stmt.execute();
} catch (SQLException e) {
rollbackUT();
--- 52,70 ----
// create(this.con);
+ create(con);
createLedger(id);
}
public void createLedger(String name) throws LowlevelLedgerException {
try {
! final PreparedStatement query=prepQuery("select * from ledger where id= ?");
! query.setString(1,name);
! ResultSet rs=query.executeQuery();
! if (!rs.next()) {
! final PreparedStatement stmt = prepQuery("insert into ledger (id,title,created) values (?,?,now())");
! stmt.setString(1, name);
! stmt.setString(2, name);
! stmt.execute();
! }
} catch (SQLException e) {
rollbackUT();
***************
*** 64,68 ****
}
! public static void create(ConnectionSource con) {
try {
Connection connection=con.getConnection();
--- 73,77 ----
}
! public static synchronized void create(ConnectionSource con) {
try {
Connection connection=con.getConnection();
***************
*** 163,172 ****
*/
public final PostedTransaction performTransaction(final UnPostedTransaction transaction) throws UnBalancedTransactionException, LowlevelLedgerException, InvalidTransactionException {
- final String newid;
if (!transaction.isBalanced()) {
throw new UnBalancedTransactionException(this, transaction);
}
try {
! final long xid = insertTransaction(transaction);
final Iterator items = transaction.getItems();
while (items.hasNext()) {
--- 172,180 ----
*/
public final PostedTransaction performTransaction(final UnPostedTransaction transaction) throws UnBalancedTransactionException, LowlevelLedgerException, InvalidTransactionException {
if (!transaction.isBalanced()) {
throw new UnBalancedTransactionException(this, transaction);
}
try {
! final String xid = insertTransaction(transaction);
final Iterator items = transaction.getItems();
while (items.hasNext()) {
***************
*** 174,183 ****
insertTransactionItem(xid, item);
}
! newid = Long.toString(xid);
} catch (SQLException e) {
rollbackUT();
throw new LowlevelLedgerException(this, e);
}
- return this.createTransaction(transaction, newid);
}
--- 182,190 ----
insertTransactionItem(xid, item);
}
! return this.createTransaction(transaction, xid);
} catch (SQLException e) {
rollbackUT();
throw new LowlevelLedgerException(this, e);
}
}
***************
*** 191,200 ****
*/
public final PostedHeldTransaction performHeldTransaction(final UnPostedHeldTransaction transaction) throws UnBalancedTransactionException, LowlevelLedgerException, InvalidTransactionException {
- final String newid;
if (!transaction.isBalanced()) {
throw new UnBalancedTransactionException(this, transaction);
}
try {
! final long xid = insertHeldTransaction(transaction);
final Iterator items = transaction.getItems();
while (items.hasNext()) {
--- 198,206 ----
*/
public final PostedHeldTransaction performHeldTransaction(final UnPostedHeldTransaction transaction) throws UnBalancedTransactionException, LowlevelLedgerException, InvalidTransactionException {
if (!transaction.isBalanced()) {
throw new UnBalancedTransactionException(this, transaction);
}
try {
! final String xid = insertHeldTransaction(transaction);
final Iterator items = transaction.getItems();
while (items.hasNext()) {
***************
*** 202,206 ****
insertHeldTransactionItem(xid, item);
}
! newid = Long.toString(xid);
} catch (SQLException e) {
rollbackUT();
--- 208,212 ----
insertHeldTransactionItem(xid, item);
}
! return this.createHeldTransaction(transaction, xid);
} catch (SQLException e) {
rollbackUT();
***************
*** 209,213 ****
throw new LowlevelLedgerException(this, e);
}
- return this.createHeldTransaction(transaction, newid);
}
--- 215,218 ----
***************
*** 274,314 ****
}
! private long insertTransaction(final UnPostedTransaction transaction) throws SQLException, LowlevelLedgerException {
! final PreparedStatement tranInsert = prepQuery("insert into transaction (valuetime,comment,ledgerid) values (?,?,?)");
! tranInsert.setTimestamp(1, SQLTools.toTimestamp(transaction.getTransactionTime()));
! tranInsert.setString(2, transaction.getComment());
! 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);
! else {
! rollbackUT();
! throw new LowlevelLedgerException(this, "We couldnt get the id of the transaction. Safer to Rollback.");
! }
}
! private long insertHeldTransaction(final UnPostedHeldTransaction transaction) throws SQLException, LowlevelLedgerException {
! final PreparedStatement tranInsert = prepQuery("insert into held_transaction (valuetime,comment,held_until,ledgerid) values (?,?,?,?)");
! tranInsert.setTimestamp(3, SQLTools.toTimestamp(transaction.getExpiryTime()));
! tranInsert.setTimestamp(1, SQLTools.toTimestamp(transaction.getTransactionTime()));
! tranInsert.setString(2, transaction.getComment());
! 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);
! else {
! rollbackUT();
! throw new LowlevelLedgerException(this, "We couldnt get the id of the transaction. Safer to Rollback.");
! }
}
! private void insertTransactionItem(final long xid, final TransactionItem item) throws SQLException, LowlevelLedgerException {
final PreparedStatement itemInsert = prepQuery("insert into entry (transactionid,bookid,amount) values (?,?,?)");
! itemInsert.setLong(1, xid);
itemInsert.setString(2, item.getBook().getBookID());
itemInsert.setDouble(3, item.getAmount());
--- 279,317 ----
}
! private String createTransactionID(){
! final Digest dig = new SHA1Digest();
! final StringBuffer buffy = new StringBuffer(getId());
! buffy.append('!');
! buffy.append(System.currentTimeMillis());
! buffy.append(CryptoTools.createRandomID());
! return buffy.toString();
! }
! private String insertTransaction(final UnPostedTransaction transaction) throws SQLException, LowlevelLedgerException {
! final PreparedStatement tranInsert = prepQuery("insert into transaction (id,valuetime,comment,ledgerid) values (?,?,?,?)");
! final String xid = createTransactionID();
! tranInsert.setString(1,xid);
! tranInsert.setTimestamp(2, SQLTools.toTimestamp(transaction.getTransactionTime()));
! tranInsert.setString(3, transaction.getComment());
! tranInsert.setString(4, getId());
tranInsert.execute();
! return xid;
}
! private String insertHeldTransaction(final UnPostedHeldTransaction transaction) throws SQLException, LowlevelLedgerException {
! final String xid = createTransactionID();
! final PreparedStatement tranInsert = prepQuery("insert into held_transaction (id,valuetime,comment,held_until,ledgerid,cancelled) values (?,?,?,?,?,0)");
! tranInsert.setString(1,xid);
! tranInsert.setTimestamp(2, SQLTools.toTimestamp(transaction.getTransactionTime()));
! tranInsert.setString(3, transaction.getComment());
! tranInsert.setTimestamp(4, SQLTools.toTimestamp(transaction.getExpiryTime()));
! tranInsert.setString(5, getId());
tranInsert.execute();
! return xid;
}
! private void insertTransactionItem(final String xid, final TransactionItem item) throws SQLException, LowlevelLedgerException {
final PreparedStatement itemInsert = prepQuery("insert into entry (transactionid,bookid,amount) values (?,?,?)");
! itemInsert.setString(1, xid);
itemInsert.setString(2, item.getBook().getBookID());
itemInsert.setDouble(3, item.getAmount());
***************
*** 316,322 ****
}
! private void insertHeldTransactionItem(final long xid, final TransactionItem item) throws SQLException, LowlevelLedgerException {
! final PreparedStatement itemInsert = prepQuery("insert into held_entry (held_transactionid,bookid,amount,ack) values (?,?,?,1)");
! itemInsert.setLong(1, xid);
itemInsert.setString(2, item.getBook().getBookID());
itemInsert.setDouble(3, item.getAmount());
--- 319,325 ----
}
! private void insertHeldTransactionItem(final String xid, final TransactionItem item) throws SQLException, LowlevelLedgerException {
! final PreparedStatement itemInsert = prepQuery("insert into held_entry (held_transactionid,bookid,amount) values (?,?,?)");
! itemInsert.setString(1, xid);
itemInsert.setString(2, item.getBook().getBookID());
itemInsert.setDouble(3, item.getAmount());
***************
*** 327,343 ****
* Searches for a Transaction based on its Transaction ID
*
! * @param idstring A valid ID
* @return The Transaction object
*/
! public final PostedTransaction findTransaction(final String idstring) throws LowlevelLedgerException, UnknownTransactionException {
! final long id = Long.parseLong(idstring);
try {
PreparedStatement stmt = prepQuery("select valuetime,comment from transaction where id=? and ledgerid=?");
! stmt.setLong(1, id);
stmt.setString(2, getId());
ResultSet rs = stmt.executeQuery();
if (!rs.next()) {
! throw new UnknownTransactionException(this, idstring);
}
final Date started = rs.getTimestamp(1);
--- 330,345 ----
* Searches for a Transaction based on its Transaction ID
*
! * @param xid A valid ID
* @return The Transaction object
*/
! public final PostedTransaction findTransaction(final String xid) throws LowlevelLedgerException, UnknownTransactionException {
try {
PreparedStatement stmt = prepQuery("select valuetime,comment from transaction where id=? and ledgerid=?");
! stmt.setString(1, xid);
stmt.setString(2, getId());
ResultSet rs = stmt.executeQuery();
if (!rs.next()) {
! throw new UnknownTransactionException(this, xid);
}
final Date started = rs.getTimestamp(1);
***************
*** 346,355 ****
final UnPostedTransaction transaction = new UnPostedTransaction(this, comment, started);
stmt = prepQuery("select bookid,amount from entry where transactionid=?");
! stmt.setLong(1, id);
rs = stmt.executeQuery();
while (rs.next())
transaction.addItem(getBook(rs.getString(1)), rs.getDouble(2));
! return this.createTransaction(transaction, idstring);
} catch (SQLException e) {
--- 348,357 ----
final UnPostedTransaction transaction = new UnPostedTransaction(this, comment, started);
stmt = prepQuery("select bookid,amount from entry where transactionid=?");
! stmt.setString(1, xid);
rs = stmt.executeQuery();
while (rs.next())
transaction.addItem(getBook(rs.getString(1)), rs.getDouble(2));
! return this.createTransaction(transaction, xid);
} catch (SQLException e) {
***************
*** 365,381 ****
* Searches for a Held Transaction based on its Transaction ID
*
! * @param idstring A valid ID
* @return The Transaction object
*/
! public final PostedHeldTransaction findHeldTransaction(final String idstring) throws LowlevelLedgerException, UnknownTransactionException {
! final long id = Long.parseLong(idstring);
try {
PreparedStatement stmt = prepQuery("select valuetime,held_until,comment from held_transaction where id=? and ledgerid=?");
! stmt.setLong(1, id);
stmt.setString(2, getId());
ResultSet rs = stmt.executeQuery();
if (!rs.next()) {
! throw new UnknownTransactionException(this, idstring);
}
final Date started = rs.getTimestamp(1);
--- 367,382 ----
* Searches for a Held Transaction based on its Transaction ID
*
! * @param xid A valid ID
* @return The Transaction object
*/
! public final PostedHeldTransaction findHeldTransaction(final String xid) throws LowlevelLedgerException, UnknownTransactionException {
try {
PreparedStatement stmt = prepQuery("select valuetime,held_until,comment from held_transaction where id=? and ledgerid=?");
! stmt.setString(1, xid);
stmt.setString(2, getId());
ResultSet rs = stmt.executeQuery();
if (!rs.next()) {
! throw new UnknownTransactionException(this, xid);
}
final Date started = rs.getTimestamp(1);
***************
*** 385,394 ****
final UnPostedHeldTransaction transaction = new UnPostedHeldTransaction(this, comment, started, ended);
stmt = prepQuery("select bookid,amount from held_entry where held_transactionid=?");
! stmt.setLong(1, id);
rs = stmt.executeQuery();
while (rs.next())
transaction.addItem(getBook(rs.getString(1)), rs.getDouble(2));
! return this.createHeldTransaction(transaction, idstring);
} catch (SQLException e) {
--- 386,395 ----
final UnPostedHeldTransaction transaction = new UnPostedHeldTransaction(this, comment, started, ended);
stmt = prepQuery("select bookid,amount from held_entry where held_transactionid=?");
! stmt.setString(1, xid);
rs = stmt.executeQuery();
while (rs.next())
transaction.addItem(getBook(rs.getString(1)), rs.getDouble(2));
! return this.createHeldTransaction(transaction, xid);
} catch (SQLException e) {
***************
*** 413,417 ****
stmt.setString(1, book.getBookID());
! stmt.setTimestamp(2, new Timestamp(time.getTime()));
stmt.setString(3, getId());
--- 414,418 ----
stmt.setString(1, book.getBookID());
! stmt.setTimestamp(2, new Timestamp(time.getTime()+1));
stmt.setString(3, getId());
***************
*** 446,450 ****
+ ") u "
);
! final Timestamp ts = SQLTools.toTimestamp(time);
stmt.setString(1, book.getBookID());
stmt.setTimestamp(2, ts);
--- 447,451 ----
+ ") u "
);
! final Timestamp ts = new Timestamp(time.getTime()+1);
stmt.setString(1, book.getBookID());
stmt.setTimestamp(2, ts);
***************
*** 493,497 ****
public final Book getBook(final String bookID) throws UnknownBookException, LowlevelLedgerException {
try {
! final PreparedStatement stmt = prepQuery("select comment from book where id=?");
stmt.setString(1, bookID);
final ResultSet rs = stmt.executeQuery();
--- 494,498 ----
public final Book getBook(final String bookID) throws UnknownBookException, LowlevelLedgerException {
try {
! final PreparedStatement stmt = prepQuery("select title from book where id=?");
stmt.setString(1, bookID);
final ResultSet rs = stmt.executeQuery();
|
|
From: <pe...@us...> - 2003-12-26 22:42:00
|
Update of /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/servlets In directory sc8-pr-cvs1:/tmp/cvs-serv1436/src/java/org/neuclear/ledger/servlets Log Message: Directory /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/servlets added to the repository |
Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/sql/entities In directory sc8-pr-cvs1:/tmp/cvs-serv23495/src/java/org/neuclear/commons/sql/entities Added Files: ColumnDefinition.java DataColumnDefinition.java Entity.java EntityModel.java ReferenceDefinition.java Log Message: Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code. Should mainly be used to create tables. Can also insert rows, but hasnt been thoroughly tested. At some point I will improve that part and add some kind of smart querying engine to it. Similar to EntityEngine. But I dont need that myself right now. SQLLedger now uses this to create its tables. It is not fully working yet, but will be shortly. --- NEW FILE: ColumnDefinition.java --- package org.neuclear.commons.sql.entities; /* NeuClear Distributed Transaction Clearing Platform (C) 2003 Pelle Braendgaard This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA $Id: ColumnDefinition.java,v 1.1 2003/12/24 00:25:40 pelle Exp $ $Log: ColumnDefinition.java,v $ Revision 1.1 2003/12/24 00:25:40 pelle Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code. Should mainly be used to create tables. Can also insert rows, but hasnt been thoroughly tested. At some point I will improve that part and add some kind of smart querying engine to it. Similar to EntityEngine. But I dont need that myself right now. SQLLedger now uses this to create its tables. It is not fully working yet, but will be shortly. */ /** * User: pelleb * Date: Dec 23, 2003 * Time: 2:15:18 PM */ public abstract class ColumnDefinition { protected ColumnDefinition(EntityModel table, String name) { this.model=table; this.name=name; } public abstract String createDDL(); public final EntityModel getModel(){ return model; } public String getName() { return name; } public int hashCode() { return (getClass().hashCode()+name.hashCode())/2; //To change body of overriden methods use Options | File Templates. } public boolean equals(Object object) { if (object==this) return true; if (!object.getClass().equals(this.getClass())) return false; final ColumnDefinition col2 = ((ColumnDefinition)object); return getModel().equals(col2.getModel())&&getName().equals(col2.getName()); } private final String name; private final EntityModel model; public static final int FIELD_URI=0; public static final int FIELD_COMMENT=1; public static final int FIELD_MONEY=2; public static final int FIELD_TIMESTAMP=3; public static final int FIELD_ID=4; public static final int FIELD_BOOLEAN=5; } --- NEW FILE: DataColumnDefinition.java --- package org.neuclear.commons.sql.entities; /* NeuClear Distributed Transaction Clearing Platform (C) 2003 Pelle Braendgaard This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA $Id: DataColumnDefinition.java,v 1.1 2003/12/24 00:25:40 pelle Exp $ $Log: DataColumnDefinition.java,v $ Revision 1.1 2003/12/24 00:25:40 pelle Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code. Should mainly be used to create tables. Can also insert rows, but hasnt been thoroughly tested. At some point I will improve that part and add some kind of smart querying engine to it. Similar to EntityEngine. But I dont need that myself right now. SQLLedger now uses this to create its tables. It is not fully working yet, but will be shortly. */ /** * User: pelleb * Date: Dec 23, 2003 * Time: 2:31:13 PM */ public class DataColumnDefinition extends ColumnDefinition{ public DataColumnDefinition(EntityModel table, String name, int type) { super(table,name); this.type = type; } public final String createDDL(){ return getName()+" "+getDefinition(); } protected String getDefinition() { switch(type){ case FIELD_COMMENT: return "VARCHAR(100)"; case FIELD_MONEY: return "DECIMAL"; case FIELD_TIMESTAMP: return "TIMESTAMP"; case FIELD_ID: return "BIGINT"; case FIELD_BOOLEAN: return "TINYINT"; } return "VARCHAR(50)"; } public int getType() { return type; } private final int type; } --- NEW FILE: Entity.java --- package org.neuclear.commons.sql.entities; /* NeuClear Distributed Transaction Clearing Platform (C) 2003 Pelle Braendgaard This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA $Id: Entity.java,v 1.1 2003/12/24 00:25:40 pelle Exp $ $Log: Entity.java,v $ Revision 1.1 2003/12/24 00:25:40 pelle Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code. Should mainly be used to create tables. Can also insert rows, but hasnt been thoroughly tested. At some point I will improve that part and add some kind of smart querying engine to it. Similar to EntityEngine. But I dont need that myself right now. SQLLedger now uses this to create its tables. It is not fully working yet, but will be shortly. */ /** * User: pelleb * Date: Dec 23, 2003 * Time: 4:38:23 PM */ public class Entity { public Entity(EntityModel model,String id,Object[] data) { this.model = model; this.data=data; this.id=id; } public String getID(){ return id; } public Object[] getData() { return data; } public EntityModel getModel() { return model; } private final EntityModel model; private final Object data[]; private final String id; } --- NEW FILE: EntityModel.java --- package org.neuclear.commons.sql.entities; import java.util.*; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Timestamp; /* NeuClear Distributed Transaction Clearing Platform (C) 2003 Pelle Braendgaard This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA $Id: EntityModel.java,v 1.1 2003/12/24 00:25:40 pelle Exp $ $Log: EntityModel.java,v $ Revision 1.1 2003/12/24 00:25:40 pelle Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code. Should mainly be used to create tables. Can also insert rows, but hasnt been thoroughly tested. At some point I will improve that part and add some kind of smart querying engine to it. Similar to EntityEngine. But I dont need that myself right now. SQLLedger now uses this to create its tables. It is not fully working yet, but will be shortly. */ /** * User: pelleb * Date: Dec 23, 2003 * Time: 2:13:21 PM */ public final class EntityModel { public EntityModel(final String name,String idname,boolean uri){ columns=new HashMap(); colseq=new LinkedList(); foreign=new LinkedList(); this.name=name; id=new DataColumnDefinition(this,idname,uri?ColumnDefinition.FIELD_URI:ColumnDefinition.FIELD_ID); addColumn(id); } public EntityModel(final String name,boolean uri){ this(name,"id",uri); } public final void create(Connection con){ //first lets build all the Dependencies for (int i = 0; i < foreign.size(); i++) { ReferenceDefinition definition = (ReferenceDefinition) foreign.get(i); definition.getRef().create(con); } System.out.println("Attempting to create: "+getName()); try { PreparedStatement stmt=con.prepareStatement(createDDL()); stmt.execute(); } catch (SQLException e) { System.out.println(e.getLocalizedMessage()); } } public final String createDDL(){ StringBuffer buf=new StringBuffer("CREATE TABLE "); buf.append(name); buf.append(" (\n"); Iterator iter=colseq.iterator(); while(iter.hasNext()) { ColumnDefinition col=(ColumnDefinition)iter.next(); buf.append(col.createDDL()); buf.append(",\n"); } iter=foreign.iterator(); while(iter.hasNext()) { ReferenceDefinition col=(ReferenceDefinition)iter.next(); buf.append("FOREIGN KEY ("); buf.append(col.getName()); buf.append(") REFERENCES "); buf.append(col.getRef().getName()); buf.append("("); buf.append(col.getRef().getId().getName()); buf.append(") ON DELETE CASCADE,\n"); // buf.append("INDEX "); // buf.append(col.getName()); // buf.append("idx ("); // buf.append(col.getName()); // buf.append("),\n"); } buf.append("PRIMARY KEY("); buf.append(id.getName()); buf.append(")\n)"); return buf.toString(); } public final String getName() { return name; } private final ColumnDefinition addColumn(ColumnDefinition col){ columns.put(col.getName(),col); colseq.add(col); return col; } public final DataColumnDefinition addURI(String name){ return (DataColumnDefinition) addColumn(new DataColumnDefinition(this,name,ColumnDefinition.FIELD_URI)); } public final DataColumnDefinition addURI(){ return addURI("name"); } public final DataColumnDefinition addMoney(String name){ return (DataColumnDefinition) addColumn(new DataColumnDefinition(this,name,ColumnDefinition.FIELD_MONEY)); } public final DataColumnDefinition addMoney(){ return addMoney("amount"); } public final DataColumnDefinition addTimeStamp(String name){ return (DataColumnDefinition) addColumn(new DataColumnDefinition(this,name,ColumnDefinition.FIELD_TIMESTAMP)); } public final DataColumnDefinition addTimeStamp(){ return addTimeStamp("created"); } public final DataColumnDefinition addValueTime(){ return addTimeStamp("valuetime"); } public final DataColumnDefinition addComment(String name){ return (DataColumnDefinition) addColumn(new DataColumnDefinition(this,name,ColumnDefinition.FIELD_COMMENT)); } public final DataColumnDefinition addComment(){ return addComment("comment"); } public final DataColumnDefinition addTitle(){ return addURI("title"); } public final DataColumnDefinition addBoolean(String name){ return (DataColumnDefinition) addColumn(new DataColumnDefinition(this,name,ColumnDefinition.FIELD_BOOLEAN)); } public final ReferenceDefinition addReference(EntityModel def) { ReferenceDefinition ref=new ReferenceDefinition(this,def); return addReference(ref); } private ReferenceDefinition addReference(ReferenceDefinition ref) { addColumn(ref); foreign.add(ref); return ref; } public final ReferenceDefinition addReference(String name,EntityModel def) { return addReference(new ReferenceDefinition(this,def,name)); } public final DataColumnDefinition getId() { return id; } final Entity insertEntity(Connection con,Object data[]) throws SQLException { if ((data.length%2==1))//&&(data.length/2<columns.size())) throw new SQLException("Incorrect amount of parameters"); StringBuffer buf=new StringBuffer(22+getName().length()+3*(data.length/2)); buf.append("INSERT INTO "); buf.append(getName()); buf.append(" ("); for (int i = 0; i<data.length; i+=2){ if (i>0) buf.append(", "); buf.append(data[i]); } buf.append(") VALUES ("); for (int i = 0; i<data.length; i+=2){ if (i>0) buf.append(", "); buf.append("?"); } buf.append(")"); PreparedStatement stmt=con.prepareStatement(buf.toString()); String id=null; for (int i = 0; i<(data.length/2); i++){ int j=i*2; ColumnDefinition definition = (ColumnDefinition) columns.get(data[j]); if (definition instanceof ReferenceDefinition) { ReferenceDefinition ref=(ReferenceDefinition) definition; if (data[2*i+1] instanceof Object[]) { Entity refentity=ref.getRef().insertEntity(con,(Object[]) data[j+1]); stmt.setString(i+1,refentity.getID()); } else { stmt.setString(i+1,data[j+1].toString()); } } else { switch (((DataColumnDefinition)definition).getType()) { case ColumnDefinition.FIELD_MONEY: stmt.setDouble(i+1,((Double)data[j+1]).doubleValue()); break; case ColumnDefinition.FIELD_TIMESTAMP: stmt.setTimestamp(i+1,((Timestamp)data[j+1])); break; case ColumnDefinition.FIELD_ID: stmt.setLong(i+1,((Long)data[j+1]).longValue()); break; case ColumnDefinition.FIELD_BOOLEAN: stmt.setBoolean(i+1,((Boolean)data[j+1]).booleanValue()); break; default: stmt.setString(i+1,data[j+1].toString()); } if (getId().getName().equals(data[j])) id=data[j+1].toString(); } } stmt.execute(); return new Entity(this,id,data); } private final DataColumnDefinition id; private final Map columns; private final List colseq; private final List foreign; private final String name; } --- NEW FILE: ReferenceDefinition.java --- package org.neuclear.commons.sql.entities; /* NeuClear Distributed Transaction Clearing Platform (C) 2003 Pelle Braendgaard This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA $Id: ReferenceDefinition.java,v 1.1 2003/12/24 00:25:40 pelle Exp $ $Log: ReferenceDefinition.java,v $ Revision 1.1 2003/12/24 00:25:40 pelle Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code. Should mainly be used to create tables. Can also insert rows, but hasnt been thoroughly tested. At some point I will improve that part and add some kind of smart querying engine to it. Similar to EntityEngine. But I dont need that myself right now. SQLLedger now uses this to create its tables. It is not fully working yet, but will be shortly. */ /** * User: pelleb * Date: Dec 23, 2003 * Time: 2:34:09 PM */ public class ReferenceDefinition extends ColumnDefinition{ public ReferenceDefinition(EntityModel table, EntityModel ref){ this(table,ref,ref.getName()+"id"); } public ReferenceDefinition(EntityModel table, EntityModel ref,String name) { super(table,name); this.ref = ref; } public final String createDDL() { return getName()+" "+getDefinition(); } private final String getDefinition(){ if (ref.getId().getType()==ColumnDefinition.FIELD_ID) return "INTEGER"; return "VARCHAR(50)"; } public final EntityModel getRef() { return ref; } private final EntityModel ref; } |
|
From: <pe...@us...> - 2003-12-24 00:25:44
|
Update of /cvsroot/neuclear/neuclear-commons/src/test/org/neuclear/commons/sql/entities In directory sc8-pr-cvs1:/tmp/cvs-serv23495/src/test/org/neuclear/commons/sql/entities Added Files: TableDefinitionTest.java Log Message: Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code. Should mainly be used to create tables. Can also insert rows, but hasnt been thoroughly tested. At some point I will improve that part and add some kind of smart querying engine to it. Similar to EntityEngine. But I dont need that myself right now. SQLLedger now uses this to create its tables. It is not fully working yet, but will be shortly. --- NEW FILE: TableDefinitionTest.java --- package org.neuclear.commons.sql.entities; import junit.framework.TestCase; import org.neuclear.commons.sql.ConnectionSource; import org.neuclear.commons.sql.DefaultConnectionSource; import org.neuclear.commons.NeuClearException; import org.neuclear.commons.time.TimeTools; import javax.naming.NamingException; import java.sql.*; import java.io.IOException; import java.util.Random; import java.math.BigDecimal; /* NeuClear Distributed Transaction Clearing Platform (C) 2003 Pelle Braendgaard This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA $Id: TableDefinitionTest.java,v 1.1 2003/12/24 00:25:41 pelle Exp $ $Log: TableDefinitionTest.java,v $ Revision 1.1 2003/12/24 00:25:41 pelle Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code. Should mainly be used to create tables. Can also insert rows, but hasnt been thoroughly tested. At some point I will improve that part and add some kind of smart querying engine to it. Similar to EntityEngine. But I dont need that myself right now. SQLLedger now uses this to create its tables. It is not fully working yet, but will be shortly. */ /** * User: pelleb * Date: Dec 23, 2003 * Time: 3:26:17 PM */ public class TableDefinitionTest extends TestCase{ public TableDefinitionTest(String string) throws SQLException, NamingException, IOException, NeuClearException { super(string); } public void testSimpleTable(){ EntityModel table=new EntityModel("accounts", true); String correct="CREATE TABLE accounts (\n" + "id VARCHAR(50),\n" + "PRIMARY KEY(id)\n)"; System.out.println(table.createDDL()); assertEquals(correct,table.createDDL()); } public void testComplexTable(){ EntityModel table=new EntityModel("transaction", false); table.addTimeStamp(); table.addURI("from"); table.addURI("to"); table.addMoney(); table.addComment(); String correct="CREATE TABLE transaction (\n" + "id BIGINT,\n" + "valuetime TIMESTAMP,\n" + "from VARCHAR(50),\n" + "to VARCHAR(50),\n" + "amount DECIMAL,\n" + "comment VARCHAR(100),\n" + "PRIMARY KEY(id)\n)"; System.out.println(table.createDDL()); assertEquals(correct,table.createDDL()); } public void testRelationalTable(){ EntityModel accounts=new EntityModel("accounts", true); EntityModel table=new EntityModel("transaction", false); table.addTimeStamp(); table.addReference("sender",accounts); table.addReference("to",accounts); table.addMoney(); table.addComment(); String correct="CREATE TABLE transaction (\n" + "id BIGINT,\n" + "valuetime TIMESTAMP,\n" + "sender VARCHAR(50),\n" + "to VARCHAR(50),\n" + "amount DECIMAL,\n" + "comment VARCHAR(100),\n" + "FOREIGN KEY (sender) REFERENCES accounts(id) ON DELETE CASCADE,\n" + // "INDEX fromidx (from),\n" + "FOREIGN KEY (to) REFERENCES accounts(id) ON DELETE CASCADE,\n" + // "INDEX toidx (to),\n" + "PRIMARY KEY(id)\n)"; System.out.println(table.createDDL()); assertEquals(correct,table.createDDL()); } public void testCreateTableStructure() throws SQLException, IOException, NamingException, NeuClearException { EntityModel accounts=new EntityModel("accounts", true); EntityModel table=new EntityModel("transaction", false); table.addTimeStamp(); table.addReference("sender",accounts); table.addReference("recipient",accounts); table.addMoney(); table.addComment(); final Connection con = new DefaultConnectionSource().getConnection(); table.create(con); Entity entity=table.insertEntity(con,new Object[] { "id",new Long(new Random().nextLong()), "valuetime",TimeTools.now(), "sender",new Object[]{ "id","neu://bob@test" }, "recipient",new Object[]{ "id","neu://alice@test" }, "amount",new Double(100), "comment","test comment" }); assertNotNull(entity); con.commit(); con.close(); } } |
Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/sql In directory sc8-pr-cvs1:/tmp/cvs-serv23495/src/java/org/neuclear/commons/sql Modified Files: DefaultConnectionSource.java Added Files: DefaultXAConnectionSource.java SimpleConnectionSource.java Log Message: Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code. Should mainly be used to create tables. Can also insert rows, but hasnt been thoroughly tested. At some point I will improve that part and add some kind of smart querying engine to it. Similar to EntityEngine. But I dont need that myself right now. SQLLedger now uses this to create its tables. It is not fully working yet, but will be shortly. --- NEW FILE: DefaultXAConnectionSource.java --- package org.neuclear.commons.sql; import org.neuclear.commons.NeuClearException; import javax.naming.NamingException; import java.io.IOException; import java.sql.Connection; import java.sql.SQLException; import java.util.Properties; /** * User: pelleb * Date: Aug 6, 2003 * Time: 3:38:50 PM */ public final class DefaultXAConnectionSource implements ConnectionSource { public DefaultXAConnectionSource() throws SQLException, NeuClearException, IOException, NamingException { final Properties props = SQLTools.loadProperties(); cs = new XAConnectionSource( props.getProperty("jndi.name"), props.getProperty("jdbc.class"), props.getProperty("jdbc.url"), props.getProperty("jdbc.username"), props.getProperty("jdbc.password") ); } public Connection getConnection() throws SQLException, IOException { return cs.getConnection(); } private final ConnectionSource cs; } Index: DefaultConnectionSource.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/sql/DefaultConnectionSource.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DefaultConnectionSource.java 3 Dec 2003 23:22:06 -0000 1.4 --- DefaultConnectionSource.java 24 Dec 2003 00:25:41 -0000 1.5 *************** *** 15,34 **** */ public final class DefaultConnectionSource implements ConnectionSource { - public DefaultConnectionSource() throws SQLException, NeuClearException, IOException, NamingException { - final Properties props = SQLTools.loadProperties(); - cs = new XAConnectionSource( - props.getProperty("jndi.name"), - props.getProperty("jdbc.class"), - props.getProperty("jdbc.url"), - props.getProperty("jdbc.username"), - props.getProperty("jdbc.password") - ); - } public Connection getConnection() throws SQLException, IOException { ! return cs.getConnection(); } - - private final ConnectionSource cs; } --- 15,22 ---- */ public final class DefaultConnectionSource implements ConnectionSource { public Connection getConnection() throws SQLException, IOException { ! return SQLTools.getConnection(); } } |
|
From: <pe...@us...> - 2003-12-24 00:25:44
|
Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/time In directory sc8-pr-cvs1:/tmp/cvs-serv23495/src/java/org/neuclear/commons/time Modified Files: TimeTools.java Log Message: Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code. Should mainly be used to create tables. Can also insert rows, but hasnt been thoroughly tested. At some point I will improve that part and add some kind of smart querying engine to it. Similar to EntityEngine. But I dont need that myself right now. SQLLedger now uses this to create its tables. It is not fully working yet, but will be shortly. Index: TimeTools.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/time/TimeTools.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TimeTools.java 19 Dec 2003 18:02:53 -0000 1.5 --- TimeTools.java 24 Dec 2003 00:25:41 -0000 1.6 *************** *** 2,5 **** --- 2,12 ---- * $Id$ * $Log$ + * Revision 1.6 2003/12/24 00:25:41 pelle + * Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code. + * Should mainly be used to create tables. Can also insert rows, but hasnt been thoroughly tested. + * At some point I will improve that part and add some kind of smart querying engine to it. Similar to EntityEngine. But I dont + * need that myself right now. + * SQLLedger now uses this to create its tables. It is not fully working yet, but will be shortly. + * * Revision 1.5 2003/12/19 18:02:53 pelle * Revamped a lot of exception handling throughout the framework, it has been simplified in most places: *************** *** 147,152 **** * @return */ ! public static Date now() { ! return new Date(); } } --- 154,159 ---- * @return */ ! public static Timestamp now() { ! return new Timestamp(System.currentTimeMillis()); } } |