001: package auction.persistence;
002:
003: import auction.dao.*;
004: import auction.dao.hibernate.*;
005: import auction.model.Address;
006: import auction.model.Category;
007: import auction.model.User;
008: import java.net.URL;
009: import java.util.Iterator;
010: import java.util.LinkedList;
011: import java.util.List;
012: import java.util.Set;
013: import net.xoetrope.optional.data.pojo.XPersistentDataBindingContext;
014: import net.xoetrope.optional.data.pojo.XPersistenceController;
015: import net.xoetrope.optional.data.pojo.XPojoContext;
016: import net.xoetrope.optional.data.pojo.XPersistentPojoModel;
017: import net.xoetrope.optional.data.pojo.XPojoModel;
018: import net.xoetrope.xui.XProject;
019: import net.xoetrope.xui.data.XModel;
020: import org.hibernate.LockMode;
021: import org.hibernate.Session;
022: import org.hibernate.Transaction;
023: import org.hibernate.FlushMode;
024:
025: public class PersistenceController extends XPersistenceController {
026: private int beginTransactionCounter = 0;
027: private int commitTransactionCounter = 0;
028:
029: private Object root = null;
030: private XProject currentProject;
031: private Session session;
032: private Transaction transaction;
033:
034: public Object getRoot() {
035: if (root == null)
036: root = new PojoBase("xpojobase");
037: return root;
038: }
039:
040: public void setProject(XProject project) {
041: currentProject = project;
042: }
043:
044: public void configure(URL configFileURL) {
045: }
046:
047: // XPersistenceController implementation
048: public void beginTransaction() {
049: session = HibernateUtil.getSessionFactory().getCurrentSession();
050: transaction = session.beginTransaction();
051: }
052:
053: public void commitTransaction() {
054: session = HibernateUtil.getSessionFactory().getCurrentSession();
055:
056: if ((transaction != null) && (transaction.isActive())) {
057: transaction.commit();
058: if (session.isOpen())
059: session.close();
060: }
061: }
062:
063: public void rollbackTransaction() {
064: if ((transaction != null) && transaction.isActive())
065: transaction.rollback();
066: transaction = null;
067: }
068:
069: public boolean isTransactionActive() {
070: return ((transaction != null) && transaction.isActive());
071: }
072:
073: public Object getTransactionObject() {
074: return transaction;
075: }
076:
077: public void persist(Object object) {
078: session.saveOrUpdate(object);
079: }
080:
081: public void delete(Object object) {
082: session.delete(object);
083: }
084:
085: public void evict(Object object) {
086: session.evict(object);
087: }
088:
089: public void lock(Object object) {
090: session.lock(object, LockMode.NONE);
091: }
092:
093: public Object merge(Object object) {
094: return session.merge(object);
095: }
096:
097: public void flush() {
098: session.flush();
099: }
100:
101: }
|