|
From: Pelle B. <pe...@us...> - 2004-03-24 12:43:49
|
Update of /cvsroot/neuclear/neuclear-ledger-hibernate/src/java/org/neuclear/ledger/hibernate In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15235/src/java/org/neuclear/ledger/hibernate Modified Files: HTransaction.hbm.xml HTransaction.java HTransactionItem.hbm.xml HibernateLedger.java Log Message: Actually kind of works now, for checking balance and creating normal transactions and transaction items. Index: HTransaction.hbm.xml =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger-hibernate/src/java/org/neuclear/ledger/hibernate/HTransaction.hbm.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** HTransaction.hbm.xml 23 Mar 2004 21:57:48 -0000 1.1 --- HTransaction.hbm.xml 24 Mar 2004 12:33:10 -0000 1.2 *************** *** 14,30 **** <generator class="assigned"/> </id> ! <property name="requestId"> <column name="reqid" sql-type="char(32)" not-null="true"/> </property> ! <property name="transactionTime"> ! <column name="transactiontime" sql-type="double" not-null="true"/> </property> ! <property name="comment"> <column name="comment" sql-type="varchar(256)" not-null="true"/> </property> ! <set name="items" table="transaction_items" inverse="true" cascade="all"> <key column="transaction_id"/> <one-to-many class="org.neuclear.ledger.hibernate.HTransactionItem"/> --- 14,30 ---- <generator class="assigned"/> </id> ! <property name="requestId" type="string"> <column name="reqid" sql-type="char(32)" not-null="true"/> </property> ! <property name="transactionTime" type="timestamp"> ! <column name="transactiontime" not-null="true"/> </property> ! <property name="comment" type="string"> <column name="comment" sql-type="varchar(256)" not-null="true"/> </property> ! <set name="items" table="transaction_items" cascade="all"> <key column="transaction_id"/> <one-to-many class="org.neuclear.ledger.hibernate.HTransactionItem"/> Index: HTransactionItem.hbm.xml =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger-hibernate/src/java/org/neuclear/ledger/hibernate/HTransactionItem.hbm.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** HTransactionItem.hbm.xml 23 Mar 2004 21:57:48 -0000 1.1 --- HTransactionItem.hbm.xml 24 Mar 2004 12:33:10 -0000 1.2 *************** *** 14,23 **** <generator class="uuid.hex"/> </id> ! <property name="book"> <column name="book" sql-type="char(32)" not-null="true"/> </property> ! <property name="amount"> ! <column name="amount" sql-type="double" not-null="true"/> </property> --- 14,23 ---- <generator class="uuid.hex"/> </id> ! <property name="book" type="string"> <column name="book" sql-type="char(32)" not-null="true"/> </property> ! <property name="amount" type="double"> ! <column name="amount" not-null="true"/> </property> Index: HibernateLedger.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger-hibernate/src/java/org/neuclear/ledger/hibernate/HibernateLedger.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** HibernateLedger.java 23 Mar 2004 21:57:48 -0000 1.3 --- HibernateLedger.java 24 Mar 2004 12:33:10 -0000 1.4 *************** *** 8,11 **** --- 8,12 ---- import net.sf.hibernate.HibernateException; + import net.sf.hibernate.Query; import net.sf.hibernate.Session; import net.sf.hibernate.SessionFactory; *************** *** 17,20 **** --- 18,22 ---- import java.sql.Timestamp; import java.util.Date; + import java.util.Iterator; /** *************** *** 26,30 **** public final class HibernateLedger extends Ledger implements LedgerBrowser { ! public HibernateLedger(final String id) throws LowlevelLedgerException, UnknownLedgerException { super(id); --- 28,36 ---- public final class HibernateLedger extends Ledger implements LedgerBrowser { ! public HibernateLedger(final String id) throws UnknownLedgerException, LowlevelLedgerException { ! this(id, false); ! } ! ! public HibernateLedger(final String id, final boolean create) throws LowlevelLedgerException, UnknownLedgerException { super(id); *************** *** 32,39 **** Configuration cfg = new Configuration() .addClass(HTransaction.class) ! .addClass(HTransactionItem.class) ! .addClass(HHeld.class) ! .addClass(HHeldItem.class); ! // new net.sf.hibernate.tool.hbm2ddl.SchemaExport(cfg).create(true, true); factory = cfg.buildSessionFactory(); } catch (HibernateException e) { --- 38,45 ---- Configuration cfg = new Configuration() .addClass(HTransaction.class) ! .addClass(HTransactionItem.class); ! // .addClass(HHeld.class) ! // .addClass(HHeldItem.class); ! // new net.sf.hibernate.tool.hbm2ddl.SchemaExport(cfg).create(create,create); factory = cfg.buildSessionFactory(); } catch (HibernateException e) { *************** *** 54,61 **** try { Session ses = factory.openSession(); ! net.sf.hibernate.Transaction t = ses.beginTransaction(); HTransaction posted = new HTransaction(trans, new Date()); ! ses.saveOrUpdate(posted); ! t.commit(); ses.close(); return posted.createPosted(); --- 60,68 ---- try { Session ses = factory.openSession(); ! // net.sf.hibernate.Transaction t = ses.beginTransaction(); HTransaction posted = new HTransaction(trans, new Date()); ! ses.save(posted); ! ses.flush(); ! // t.commit(); ses.close(); return posted.createPosted(); *************** *** 99,106 **** try { Session ses = factory.openSession(); ! net.sf.hibernate.Transaction t = ses.beginTransaction(); HHeld posted = new HHeld(trans, new Date()); ses.saveOrUpdate(posted); ! t.commit(); ses.close(); return posted.createPosted(); --- 106,114 ---- try { Session ses = factory.openSession(); ! // net.sf.hibernate.Transaction t = ses.beginTransaction(); HHeld posted = new HHeld(trans, new Date()); ses.saveOrUpdate(posted); ! // t.commit(); ! ses.flush(); ses.close(); return posted.createPosted(); *************** *** 174,178 **** public double getBalance(String book) throws LowlevelLedgerException { ! return 0; } --- 182,201 ---- public double getBalance(String book) throws LowlevelLedgerException { ! try { ! Session sess = factory.openSession(); ! Query q = sess.createQuery("select sum(item.amount) from HTransactionItem item where item.book = ?"); ! q.setString(0, book); ! Iterator cats = q.iterate(); ! if (cats.hasNext()) { ! final Object o = cats.next(); ! if (o != null) ! return ((Double) o).doubleValue(); ! // throw new LowlevelLedgerException(this,"Query returned more or less than one column"); ! } ! // throw new LowlevelLedgerException(this,"Query didnt return a row"); ! return 0; ! } catch (HibernateException e) { ! throw new LowlevelLedgerException(e); ! } } |