|
From: Pelle B. <pe...@us...> - 2004-03-23 22:08:19
|
Update of /cvsroot/neuclear/neuclear-ledger-hibernate/src/java/org/neuclear/ledger/hibernate In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13266/src/java/org/neuclear/ledger/hibernate Modified Files: HibernateLedger.java Added Files: HHeld.hbm.xml HHeld.java HHeldItem.hbm.xml HHeldItem.java HTransaction.hbm.xml HTransaction.java HTransactionItem.hbm.xml HTransactionItem.java Log Message: Added much to the Hibernate implementation: - Added Hibernate business objects that mirror the internal Ledger objects for Transactions and Items. - Added mapping documents - Added hibernate.properties for using local hsqldb - Implemented various of the processTransaction methods in HibernateLedger Schema gets generated fine, but there are still issues in inserting the objects. --- NEW FILE: HHeldItem.java --- package org.neuclear.ledger.hibernate; /** * Created by IntelliJ IDEA. * User: pelleb * Date: Mar 23, 2004 * Time: 10:33:27 AM * To change this template use File | Settings | File Templates. */ public class HHeldItem { public HHeldItem(HHeld held, String book, double amount) { this.book = book; this.amount = amount; this.held = held; // this.heldId=held.getId(); } public HHeldItem() { } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getBook() { return book; } public void setBook(String book) { this.book = book; } public double getAmount() { return amount; } public void setAmount(double amount) { this.amount = amount; } // public String getHeldId() { // return heldId; // } // // public void setHeldId(String heldId) { // this.heldId = heldId; // } public HHeld getHeld() { return held; } public void setHeld(HHeld held) { this.held = held; } private String id; // private String heldId; private HHeld held; private String book; private double amount; } --- NEW FILE: HTransactionItem.hbm.xml --- <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping> <class name="org.neuclear.ledger.hibernate.HTransactionItem" table="transaction_items"> <id name="id" type="string" unsaved-value="null"> <column name="id" sql-type="char(32)" not-null="true"/> <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> <many-to-one name="transaction" class="org.neuclear.ledger.hibernate.HTransaction" column="transaction_id" update="false" insert="false" /> </class> </hibernate-mapping> Index: HibernateLedger.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger-hibernate/src/java/org/neuclear/ledger/hibernate/HibernateLedger.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** HibernateLedger.java 22 Mar 2004 23:21:12 -0000 1.2 --- HibernateLedger.java 23 Mar 2004 21:57:48 -0000 1.3 *************** *** 31,36 **** try { Configuration cfg = new Configuration() ! .addClass(PostedTransaction.class) ! .addClass(PostedHeldTransaction.class); factory = cfg.buildSessionFactory(); } catch (HibernateException e) { --- 31,39 ---- try { 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) { *************** *** 52,60 **** Session ses = factory.openSession(); net.sf.hibernate.Transaction t = ses.beginTransaction(); ! PostedTransaction posted = new PostedTransaction(trans, new Date()); ses.saveOrUpdate(posted); t.commit(); ses.close(); ! return posted; } catch (HibernateException e) { throw new LowlevelLedgerException(e); --- 55,63 ---- 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(); } catch (HibernateException e) { throw new LowlevelLedgerException(e); *************** *** 69,73 **** */ public PostedTransaction performVerifiedTransfer(UnPostedTransaction trans) throws UnBalancedTransactionException, LowlevelLedgerException, InvalidTransactionException { ! return null; } --- 72,88 ---- */ public PostedTransaction performVerifiedTransfer(UnPostedTransaction trans) throws UnBalancedTransactionException, LowlevelLedgerException, InvalidTransactionException { ! if (!trans.isBalanced()) ! throw new UnBalancedTransactionException(this, trans); ! 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(); ! } catch (HibernateException e) { ! throw new LowlevelLedgerException(e); ! } } *************** *** 80,84 **** */ public PostedHeldTransaction performHeldTransfer(UnPostedHeldTransaction trans) throws UnBalancedTransactionException, LowlevelLedgerException, InvalidTransactionException { ! return null; } --- 95,111 ---- */ public PostedHeldTransaction performHeldTransfer(UnPostedHeldTransaction trans) throws UnBalancedTransactionException, LowlevelLedgerException, InvalidTransactionException { ! if (!trans.isBalanced()) ! throw new UnBalancedTransactionException(this, trans); ! 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(); ! } catch (HibernateException e) { ! throw new LowlevelLedgerException(e); ! } } *************** *** 184,189 **** } ! public void close() { ! } --- 211,220 ---- } ! public void close() throws LowlevelLedgerException { ! try { ! factory.close(); ! } catch (HibernateException e) { ! throw new LowlevelLedgerException(e); ! } } --- NEW FILE: HTransaction.hbm.xml --- <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping> <class name="org.neuclear.ledger.hibernate.HTransaction" table="transactions"> <id name="id" type="string" unsaved-value="null"> <column name="id" sql-type="char(32)" not-null="true"/> <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"/> </set> </class> </hibernate-mapping> --- NEW FILE: HHeld.hbm.xml --- <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping> <class name="org.neuclear.ledger.hibernate.HHeld" table="heldtransactions"> <id name="id" type="string" unsaved-value="null"> <column name="id" sql-type="char(32)" not-null="true"/> <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="expiryTime"> <column name="expirytime" 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="held_items" inverse="true" cascade="all"> <key column="held_id"/> <one-to-many class="org.neuclear.ledger.hibernate.HHeldItem"/> </set> </class> </hibernate-mapping> --- NEW FILE: HHeld.java --- package org.neuclear.ledger.hibernate; import org.neuclear.ledger.InvalidTransactionException; import org.neuclear.ledger.PostedHeldTransaction; import org.neuclear.ledger.TransactionItem; import org.neuclear.ledger.UnPostedHeldTransaction; import java.util.*; /** * Created by IntelliJ IDEA. * User: pelleb * Date: Mar 23, 2004 * Time: 10:29:34 AM * To change this template use File | Settings | File Templates. */ public class HHeld { public HHeld() { } public HHeld(UnPostedHeldTransaction tran, Date transactionTime) { this.id = tran.getId(); this.requestId = tran.getRequestId(); this.transactionTime = transactionTime; this.expiryTime = tran.getExpiryTime(); this.comment = tran.getComment(); final List ol = tran.getItemList(); this.items = new HashSet(ol.size()); for (int i = 0; i < ol.size(); i++) { TransactionItem item = (TransactionItem) ol.get(i); items.add(new HHeldItem(this, item.getBook(), item.getAmount())); } } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getRequestId() { return requestId; } public void setRequestId(String requestId) { this.requestId = requestId; } public Date getTransactionTime() { return transactionTime; } public void setTransactionTime(Date transactionTime) { this.transactionTime = transactionTime; } public Date getExpiryTime() { return expiryTime; } public void setExpiryTime(Date expiryTime) { this.expiryTime = expiryTime; } public String getComment() { return comment; } public void setComment(String comment) { this.comment = comment; } public Set getItems() { return items; } public void setItems(Set items) { this.items = items; } public PostedHeldTransaction createPosted() throws InvalidTransactionException { UnPostedHeldTransaction unp = new UnPostedHeldTransaction(id, requestId, comment, expiryTime); Iterator iter = items.iterator(); while (iter.hasNext()) { HHeldItem item = (HHeldItem) iter.next(); unp.addItem(item.getBook(), item.getAmount()); } return new PostedHeldTransaction(unp, transactionTime); } private String id; private String requestId; private Date transactionTime; private Date expiryTime; private String comment; private Set items; } --- NEW FILE: HTransactionItem.java --- package org.neuclear.ledger.hibernate; /** * Created by IntelliJ IDEA. * User: pelleb * Date: Mar 23, 2004 * Time: 10:33:27 AM * To change this template use File | Settings | File Templates. */ public class HTransactionItem { public HTransactionItem(HTransaction tran, String book, double amount) { this.book = book; this.amount = amount; this.transaction = tran; // this.transactionId=tran.getId(); } public HTransactionItem() { } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getBook() { return book; } public void setBook(String book) { this.book = book; } public double getAmount() { return amount; } public void setAmount(double amount) { this.amount = amount; } /* public String getTransactionId() { return transactionId; } public void setTransactionId(String transactionId) { this.transactionId = transactionId; } */ public HTransaction getTransaction() { return transaction; } public void setTransaction(HTransaction transaction) { this.transaction = transaction; } private String id; // private String transactionId; private HTransaction transaction; private String book; private double amount; } --- NEW FILE: HHeldItem.hbm.xml --- <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping> <class name="org.neuclear.ledger.hibernate.HHeldItem" table="held_items"> <id name="id" type="string" unsaved-value="null"> <column name="id" sql-type="char(32)" not-null="true"/> <generator class="uuid.hex"/> </id> <!-- <property name="heldId" update="false" insert="false">--> <!-- <column name="held_id" sql-type="char(32)"--> <!-- not-null="true"/>--> <!-- </property>--> <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> <many-to-one name="held" class="org.neuclear.ledger.hibernate.HHeld" column="held_id" update="false" insert="false" /> </class> </hibernate-mapping> --- NEW FILE: HTransaction.java --- package org.neuclear.ledger.hibernate; import org.neuclear.ledger.InvalidTransactionException; import org.neuclear.ledger.PostedTransaction; import org.neuclear.ledger.TransactionItem; import org.neuclear.ledger.UnPostedTransaction; import java.util.*; /** * Created by IntelliJ IDEA. * User: pelleb * Date: Mar 23, 2004 * Time: 10:29:34 AM * To change this template use File | Settings | File Templates. */ public class HTransaction { public HTransaction() { } public HTransaction(UnPostedTransaction unp, Date transactionTime) { this.id = unp.getId(); this.requestId = unp.getRequestId(); this.transactionTime = transactionTime; this.comment = unp.getComment(); final List ol = unp.getItemList(); this.items = new HashSet(ol.size()); for (int i = 0; i < ol.size(); i++) { TransactionItem item = (TransactionItem) ol.get(i); items.add(new HTransactionItem(this, item.getBook(), item.getAmount())); } } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getRequestId() { return requestId; } public void setRequestId(String requestId) { this.requestId = requestId; } public Date getTransactionTime() { return transactionTime; } public void setTransactionTime(Date transactionTime) { this.transactionTime = transactionTime; } public String getComment() { return comment; } public void setComment(String comment) { this.comment = comment; } public Set getItems() { return items; } public void setItems(Set items) { this.items = items; } public PostedTransaction createPosted() throws InvalidTransactionException { UnPostedTransaction unp = new UnPostedTransaction(id, requestId, comment); Iterator iter = items.iterator(); while (iter.hasNext()) { HTransactionItem item = (HTransactionItem) iter.next(); unp.addItem(item.getBook(), item.getAmount()); } return new PostedTransaction(unp, transactionTime); } private String id; private String requestId; private Date transactionTime; private String comment; private Set items; } |