logo       

roller/src/org/roller/business/hibernate HibernateStrategy.java,1.3,1.4: msg#00046

java.roller.cvs

Subject: roller/src/org/roller/business/hibernate HibernateStrategy.java,1.3,1.4

Update of /cvsroot/roller/roller/src/org/roller/business/hibernate
In directory sc8-pr-cvs1:/tmp/cvs-serv6890/src/org/roller/business/hibernate

Modified Files:
HibernateStrategy.java
Log Message:
Changes to HibernateStrategy as suggested by Gavin,
updates to Atom work,
'better' logging output (timestamps)

Index: HibernateStrategy.java
===================================================================
RCS file:
/cvsroot/roller/roller/src/org/roller/business/hibernate/HibernateStrategy.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** HibernateStrategy.java 3 Sep 2003 21:21:13 -0000 1.3
--- HibernateStrategy.java 8 Sep 2003 14:39:33 -0000 1.4
***************
*** 4,7 ****
--- 4,9 ----
package org.roller.business.hibernate;

+ import java.util.List;
+
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.ObjectNotFoundException;
***************
*** 16,21 ****
import org.roller.pojos.PersistentObject;

- import java.util.List;
-


///////////////////////////////////////////////////////////////////////////////
--- 18,21 ----
***************
*** 28,32 ****
private SessionFactory mSessionFactory;

! private ThreadLocal mSessionTLS = new ThreadLocal();

private static Log mLogger =
--- 28,32 ----
private SessionFactory mSessionFactory;

! private ThreadLocal mSessionTLS = new ThreadLocal();

private static Log mLogger =
***************
*** 35,39 ****
public HibernateStrategy(SessionFactory factory) throws RollerException
{
! mSessionFactory = factory;
}

--- 35,43 ----
public HibernateStrategy(SessionFactory factory) throws RollerException
{
! mSessionFactory = factory;
! }
!
! private boolean isAvailable() {
! return mSessionTLS.get()!=null;
}

***************
*** 41,78 ****
protected Session getSession()
{
! Session ses = (Session)mSessionTLS.get();
! if ( ses == null )
! {
! try
! {
! ses = mSessionFactory.openSession();
! mLogger.debug("OPENED session "+ses);
! }
! catch (HibernateException e)
! {
! mLogger.error("ERROR opening session");
! throw new RuntimeException();
! }
! mSessionTLS.set(ses);
! mLogger.debug("ADDED session to TLS"+ses);
! }
! return ses;
}

public void release() throws RollerException
{
! try
! {
! mLogger.debug("CLOSING session "+getSession());
! getSession().close();

! mLogger.debug("REMOVING session from TLS"+getSession());
! mSessionTLS.set(null);
! }
! catch (HibernateException e)
! {
! mLogger.error("During CLOSE",e);
! throw new RollerException(e);
! }
}

--- 45,83 ----
protected Session getSession()
{
! Session ses = (Session)mSessionTLS.get();
! if ( ses == null )
! {
! try
! {
! ses = mSessionFactory.openSession();
! mLogger.debug("OPENED session "+ses);
! }
! catch (HibernateException e)
! {
! mLogger.error("ERROR opening session");
! throw new RuntimeException();
! }
! mSessionTLS.set(ses);
! mLogger.debug("ADDED session to TLS"+ses);
! }
! return ses;
}

public void release() throws RollerException
{
! try
! {
! mLogger.debug("CLOSING session "+getSession());
! getSession().flush();
! getSession().close();

! mLogger.debug("REMOVING session from TLS"+getSession());
! mSessionTLS.set(null);
! }
! catch (HibernateException e)
! {
! mLogger.error("During CLOSE",e);
! throw new RollerException(e);
! }
}

***************
*** 87,112 ****
throws RollerException
{
! if ( id == null )
! {
! throw new RollerException("NULL is not a valid id");
! }

! if ( clazz == null )
! {
! throw new RollerException("NULL is not a valid class");
! }

! try
! {
! // Create persistent instance and delete it
! Object obj = getSession().load(clazz,id);
! getSession().delete(obj);
! getSession().flush();
! }
! catch (Throwable e)
! {
! mLogger.error("During DELETE",e);
! throw new RollerException(e);
! }
}

--- 92,117 ----
throws RollerException
{
! if ( id == null )
! {
! throw new RollerException("NULL is not a valid id");
! }

! if ( clazz == null )
! {
! throw new RollerException("NULL is not a valid class");
! }

! try
! {
! // Create persistent instance and delete it
! Object obj = getSession().load(clazz,id);
! getSession().delete(obj);
! getSession().flush();
! }
! catch (Throwable e)
! {
! mLogger.error("During DELETE",e);
! throw new RollerException(e);
! }
}

***************
*** 122,157 ****
throws RollerException
{
! if ( id == null )
! {
! throw new RollerException("NULL is not a valid id");
! }

! if ( clazz == null )
! {
! throw new RollerException("NULL is not a valid class");
! }

! Object obj = null;
! Session ses = getSession();
! try
! {
! obj = (PersistentObject)ses.load( clazz, id );
! }
! catch (ObjectNotFoundException ignored)
! {
! // Roller persistence managers are supposed to return
null
! // if the requested object is not found.
! }
! catch (HibernateException e)
! {
! String msg = "During LOAD of "+id+"of class
"+clazz.getName();
! mLogger.warn(msg,e);
! }
! catch (Throwable e)
! {
! mLogger.error("During LOAD",e);
! throw new RollerException(e);
! }
! return (PersistentObject)obj;
}

--- 127,162 ----
throws RollerException
{
! if ( id == null )
! {
! throw new RollerException("NULL is not a valid id");
! }

! if ( clazz == null )
! {
! throw new RollerException("NULL is not a valid class");
! }

! Object obj = null;
! Session ses = getSession();
! try
! {
! obj = (PersistentObject)ses.load( clazz, id );
! }
! catch (ObjectNotFoundException ignored)
! {
! // Roller persistence managers are supposed to return null
! // if the requested object is not found.
! }
! catch (HibernateException e)
! {
! String msg = "During LOAD of "+id+"of class "+clazz.getName();
! mLogger.warn(msg,e);
! }
! catch (Throwable e)
! {
! mLogger.error("During LOAD",e);
! throw new RollerException(e);
! }
! return (PersistentObject)obj;
}

***************
*** 165,205 ****
throws RollerException
{
! if ( obj == null )
! {
! throw new RollerException("NULL passed into
storeValueObject()");
! }

! Session ses = getSession();
! try
! {
! if ( obj.getId() == null ||
obj.getId().trim().equals("") )
! {
! // Object has never been written to database,
so save it.
! // This makes obj into a persistent instance.
! obj.setId(null);
! ses.save(obj);
! }

! if ( !ses.contains(obj) )
! {
! // Object has been written to database, but
instance passed in
! // is not a persistent instance, so must be
loaded into session.
! PersistentObject vo =
(PersistentObject)ses.load(obj.getClass(),obj.getId());
! vo.setData(obj);
! obj = vo;
! }

! // Write current session state to database
! ses.flush();

! //ses.connection().commit(); // TODO can't call when
autocommit=true
! }
! catch (Exception e) // HibernateException or SQLException
! {
! String msg = "ERROR storing object";
! mLogger.error(msg,e);
! throw new RollerException(msg,e);
! }
! return obj;
}

--- 170,212 ----
throws RollerException
{
! if ( obj == null )
! {
! throw new RollerException("NULL passed into storeValueObject()");
! }

! Session ses = getSession();
! try
! {
! /*if ( obj.getId() == null || obj.getId().trim().equals("") )
! {
! // Object has never been written to database, so save it.
! // This makes obj into a persistent instance.
! obj.setId(null);
! ses.save(obj);
! }

! if ( !ses.contains(obj) )
! {
! // Object has been written to database, but instance passed in
! // is not a persistent instance, so must be loaded into
session.
! PersistentObject vo =
(PersistentObject)ses.load(obj.getClass(),obj.getId());
! vo.setData(obj);
! obj = vo;
! }*/

! ses.saveOrUpdate(obj);

! // Write current session state to database
! //ses.flush();
!
! //ses.connection().commit(); // TODO can't call when
autocommit=true
! }
! catch (Exception e) // HibernateException or SQLException
! {
! String msg = "ERROR storing object";
! mLogger.error(msg,e);
! throw new RollerException(msg,e);
! }
! return obj;
}

***************
*** 208,212 ****
public List query( String query, Object[] args, Object[] types) throws
RollerException
{
! return query(query, args, (Type[])types);
}

--- 215,219 ----
public List query( String query, Object[] args, Object[] types) throws
RollerException
{
! return query(query, args, (Type[])types);
}

***************
*** 214,278 ****
throws RollerException
{
! if ( query == null )
! {
! throw new RollerException("NULL is not a valid
query");
! }

! if ( args == null )
! {
! throw new RollerException("NULL is not a valid arg
array");
! }

! if ( types == null )
! {
! throw new RollerException("NULL is not a valid type
array");
! }

! try
! {
if (query.indexOf("$") > -1)
{
query = query.replaceAll("\\$\\d+", "\\?");
}
! return getSession().find(query,args,types);
! }
! catch (HibernateException e)
! {
! mLogger.error("During QUERY",e);
! throw new RollerException("During QUERY",e);
! }
}

! public List query( String query )
! throws RollerException
! {
! try
! {
if (query.indexOf("$") > -1)
{
query = query.replaceAll("\\$\\d+", "\\?");
}
! return getSession().find(query);
! }
! catch (HibernateException e)
! {
! mLogger.error("During QUERY",e);
! throw new RollerException("During QUERY",e);
! }
! }

/**
*
*/
! public void commit() throws RollerException
{
//if (mTranx != null) mTranx.commit();
! //if (isAvailable()) mSession.flush();
}

! public void rollback() throws RollerException
{
! //if (mTranx != null) mTranx.rollback();
! //if (isAvailable()) mSession.connection().rollback();
}

--- 221,290 ----
throws RollerException
{
! if ( query == null )
! {
! throw new RollerException("NULL is not a valid query");
! }

! if ( args == null )
! {
! throw new RollerException("NULL is not a valid arg array");
! }

! if ( types == null )
! {
! throw new RollerException("NULL is not a valid type array");
! }

! try
! {
if (query.indexOf("$") > -1)
{
query = query.replaceAll("\\$\\d+", "\\?");
}
! return getSession().find(query,args,types);
! }
! catch (HibernateException e)
! {
! mLogger.error("During QUERY",e);
! throw new RollerException("During QUERY",e);
! }
}

! public List query( String query )
! throws RollerException
! {
! try
! {
if (query.indexOf("$") > -1)
{
query = query.replaceAll("\\$\\d+", "\\?");
}
! return getSession().find(query);
! }
! catch (HibernateException e)
! {
! mLogger.error("During QUERY",e);
! throw new RollerException("During QUERY",e);
! }
! }

/**
*
*/
! public void commit() throws RollerException
{
//if (mTranx != null) mTranx.commit();
! try {
! if (isAvailable()) getSession().flush();
! }
! catch (HibernateException he) {
! throw new RollerException(he);
! }
}

! public void rollback() throws RollerException
{
! //if (mTranx != null) mTranx.rollback();
! //if (isAvailable()) mSession.connection().rollback();
}





-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise