Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/odmg In directory sc8-pr-cvs1:/tmp/cvs-serv14211/src/net/sf/hibernate/odmg Modified Files: Database.java Implementation.java Name.java OQLQuery.java Transaction.java Log Message: reformatted code with beautiful, shiny, happy TABS! improved an exception Index: Database.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/odmg/Database.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Database.java 1 Jan 2003 13:56:28 -0000 1.1.1.1 --- Database.java 4 Jan 2003 11:15:29 -0000 1.2 *************** *** 18,22 **** * up objects by name.<br> * <br> ! * Applications may create an instance by calling * <tt>Implementation.newDatabase()</tt> or by instantiating this class * directly. The application should then call <tt>open()</tt> to associate --- 18,22 ---- * up objects by name.<br> * <br> ! * Applications may create an instance by calling * <tt>Implementation.newDatabase()</tt> or by instantiating this class * directly. The application should then call <tt>open()</tt> to associate *************** *** 44,48 **** this.sessionFactory=factory; } ! /** * Get the <tt>Session</tt> underlying the <tt>Transaction</tt> associated --- 44,48 ---- this.sessionFactory=factory; } ! /** * Get the <tt>Session</tt> underlying the <tt>Transaction</tt> associated *************** *** 52,56 **** return currentTransaction().getSession(); } ! /** * Get the <tt>SessionFactory</tt> underlying this <tt>Database</tt>. --- 52,56 ---- return currentTransaction().getSession(); } ! /** * Get the <tt>SessionFactory</tt> underlying this <tt>Database</tt>. *************** *** 94,98 **** }*/ } ! /** * Close the <tt>Database</tt> (but not the underlying <tt>SessionFactory</tt>). --- 94,98 ---- }*/ } ! /** * Close the <tt>Database</tt> (but not the underlying <tt>SessionFactory</tt>). *************** *** 105,109 **** //TODO: remove it from ThreadLocal storage on Implementation } ! /** * Bind a name to a persistent object, making the object persistent if necessary. --- 105,109 ---- //TODO: remove it from ThreadLocal storage on Implementation } ! /** * Bind a name to a persistent object, making the object persistent if necessary. *************** *** 124,128 **** } } ! /** * Retrieve the persistent object bound to the given name. --- 124,128 ---- } } ! /** * Retrieve the persistent object bound to the given name. *************** *** 148,152 **** } } ! /** * Unbind the given name. --- 148,152 ---- } } ! /** * Unbind the given name. *************** *** 172,176 **** } } ! /** * Make the given object persistent. --- 172,176 ---- } } ! /** * Make the given object persistent. *************** *** 203,206 **** } } ! } --- 203,209 ---- } } ! } + + + Index: Implementation.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/odmg/Implementation.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Implementation.java 1 Jan 2003 13:56:28 -0000 1.1.1.1 --- Implementation.java 4 Jan 2003 11:15:30 -0000 1.2 *************** *** 19,24 **** import net.sf.hibernate.engine.SessionImplementor; /** ! * Singleton class implementing the ODMG <tt>Implementation</tt> interface. ! * Maintains a reference to a default <tt>Database</tt> and also associations * between a <tt>Database</tt> and the creating <tt>Thread</tt>. */ --- 19,24 ---- import net.sf.hibernate.engine.SessionImplementor; /** ! * Singleton class implementing the ODMG <tt>Implementation</tt> interface. ! * Maintains a reference to a default <tt>Database</tt> and also associations * between a <tt>Database</tt> and the creating <tt>Thread</tt>. */ *************** *** 50,54 **** /** ! * Get the <tt>Database</tt> associated with the current thread (the most recent * database created by the current thread or the default database). */ --- 50,54 ---- /** ! * Get the <tt>Database</tt> associated with the current thread (the most recent * database created by the current thread or the default database). */ *************** *** 83,87 **** } /** ! * Instantiate an <tt>OQLQuery</tt> for the <tt>Database</tt> associated with * the current thread * @see org.odmg.Implementation#newOQLQuery() --- 83,87 ---- } /** ! * Instantiate an <tt>OQLQuery</tt> for the <tt>Database</tt> associated with * the current thread * @see org.odmg.Implementation#newOQLQuery() *************** *** 133,137 **** } /** ! * Get the <tt>Database</tt> associated with the current thread (the most recent * database created by the current thread or the default database). * @see org.odmg.Implementation#getDatabase(Object) --- 133,137 ---- } /** ! * Get the <tt>Database</tt> associated with the current thread (the most recent * database created by the current thread or the default database). * @see org.odmg.Implementation#getDatabase(Object) *************** *** 143,144 **** --- 143,147 ---- } + + + Index: Name.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/odmg/Name.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Name.java 1 Jan 2003 13:56:29 -0000 1.1.1.1 --- Name.java 4 Jan 2003 11:15:30 -0000 1.2 *************** *** 1 **** ! //$Id$ package net.sf.hibernate.odmg; import java.io.Serializable; /** * An ODMG name that may be bound to a persistent object. */ public class Name { private String name; private Class persistentClass; private Serializable id; public Name(String name, Class persistentClass, Serializable id) { this.name = name; this.persistentClass = persistentClass; this.id = id; } public Name() {} /** * Returns the name. * @return String */ public String getName() { return name; } /** * Returns the persistentClass. * @return Class */ public Class getPersistentClass() { return persistentClass; } /** * Sets the name. * @param name The name to set */ public void setName(String name) { this.name = name; } /** * Sets the persistentClass. * @param persistentClass The persistentClass to set */ public void setPersistentClass(Class persistentClass) { this.persistentClass = persistentClass; } /** * Returns the id. * @return Serializable */ public Serializable getId() { return id; } /** * Sets the id. * @param id The id to set */ public void setId(Serializable id) { this.id = id; } } \ No newline at end of file --- 1,3 ---- ! //$Id$ package net.sf.hibernate.odmg; import java.io.Serializable; /** * An ODMG name that may be bound to a persistent object. */ public class Name { private String name; private Class persistentClass; private Serializable id; public Name(String name, Class persistentClass, Serializable id) { this.name = name; this.persistentClass = persistentClass; this.id = id; } public Name() {} /** * Returns the name. * @return String */ public String getName() { return name; } /** * Returns the persistentClass. * @return Class */ public Class getPersistentClass() { return persistentClass; } /** * Sets the name. * @param name The name to set */ public void setName(String name) { this.name = name; } /** * Sets the persistentClass. * @param persistentClass The persistentClass to set */ public void setPersistentClass(Class persistentClass) { this.persistentClass = persistentClass; } /** * Returns the id. * @return Serializable */ public Serializable getId() { return id; } /** * Sets the id. * @param id The id to set */ public void setId(Serializable id) { this.id = id; } } ! ! Index: OQLQuery.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/odmg/OQLQuery.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** OQLQuery.java 1 Jan 2003 13:56:29 -0000 1.1.1.1 --- OQLQuery.java 4 Jan 2003 11:15:30 -0000 1.2 *************** *** 1 **** ! //$Id$ package net.sf.hibernate.odmg; import java.sql.SQLException; import org.odmg.ODMGRuntimeException; import org.odmg.QueryException; import org.odmg.QueryInvalidException; import org.odmg.QueryParameterCountInvalidException; import org.odmg.QueryParameterTypeInvalidException; import net.sf.hibernate.HibernateException; import net.sf.hibernate.Query; /** Experimental implementation of the ODMG <tt>OQLQuery</tt> interface. The supported query language is actually the Hibernate query language and the <tt>execute()</tt> method returns results in the same format as <tt>Session.find()</tt>.<br> <br> Warning: this implementation will change significantly as ODMG support matures! */ public class OQLQuery implements org.odmg.OQLQuery { private Transaction tx; private Query query; private int param=0; /** * Instantiate an <tt>OQLQuery</tt> for the current transaction. */ public OQLQuery(Database db) { this.tx = db.currentTransaction(); } /** * Instantiate an <tt>OQLQuery</tt> for the given transaction. */ public OQLQuery(Transaction tx) { this.tx = tx; } /** * Instantiate an <tt>OQLQuery</tt> for the current transaction. */ public OQLQuery() { this.tx = (Transaction) Implementation.getInstance().currentTransaction(); } /** * Get the underlying Hibernate <tt>Query</tt>. */ public Query getQuery() { return query; } /** * Set the HIbernate query string. Scalar return values are not supported. * @see org.odmg.OQLQuery#create(String) */ public void create(String queryString) throws QueryInvalidException { //TODO: the right exception try { this.query = tx.getSession().createQuery(queryString); } catch (HibernateException he) { throw new ODMGRuntimeException( he.getMessage() ); } } /** * Bind a value to the next <tt>?</tt> style parameter. * @see org.odmg.OQLQuery#bind(Object) */ public void bind(Object parameter) throws QueryParameterCountInvalidException, QueryParameterTypeInvalidException { //TODO: the right exception try { query.setParameter(param++, parameter); } catch (HibernateException he) { throw new ODMGRuntimeException( he.getMessage() ); } } /** * Get the query results as a collection. * @see org.odmg.OQLQuery#execute() */ public Object execute() throws QueryException { //TODO: how are results meant to be returned in ODMG? try { return query.list(); } catch (SQLException sqle) { throw new QueryException( sqle.getMessage() ); } catch (HibernateException he) { throw new QueryException( he.getMessage() ); } } } \ No newline at end of file --- 1,3 ---- ! //$Id$ package net.sf.hibernate.odmg; import java.sql.SQLException; import org.odmg.ODMGRuntimeException; import org.odmg.QueryException; import org.odmg.QueryInvalidException; import org.odmg.QueryParameterCountInvalidException; import org.odmg.QueryParameterTypeInvalidException; import net.sf.hibernate.HibernateException; import net.sf.hibernate.Query; /** Experimental implementation of the ODMG <tt>OQLQuery</tt> interface. The supported query language is actually the Hibernate query language and the <tt>execute()</tt> method returns results in the same format as <tt>Session.find()</tt>.<br> <br> Warning: this implementation will change significantly as ODMG support matures! */ public class OQLQuery implements org.odmg.OQLQuery { private Transaction tx; private Query query; private int param=0; /** * Instantiate an <tt>OQLQuery</tt> for the current transaction. */ public OQLQuery(Database db) { this.tx = db.currentTransaction(); } /** * Instantiate an <tt>OQLQuery</tt> for the given transaction. */ public OQLQuery(Transaction tx) { this.tx = tx; } /** * Instantiate an <tt>OQLQuery</tt> for the current transaction. */ public OQLQuery() { this.tx = (Transaction) Implementation.getInstance().currentTransaction(); } /** * Get the underlying Hibernate <tt>Query</tt>. */ public Query getQuery() { return query; } /** * Set the HIbernate query string. Scalar return values are not supported. * @see org.odmg.OQLQuery#create(String) */ public void create(String queryString) throws QueryInvalidException { //TODO: the right exception try { this.query = tx.getSession().createQuery(queryString); } catch (HibernateException he) { throw new ODMGRuntimeException( he.getMessage() ); } } /** * Bind a value to the next <tt>?</tt> style parameter. * @see org.odmg.OQLQuery#bind(Object) */ public void bind(Object parameter) throws QueryParameterCountInvalidException, QueryParameterTypeInvalidException { //TODO: the right exception try { query.setParameter(param++, parameter); } catch (HibernateException he) { throw new ODMGRuntimeException( he.getMessage() ); } } /** * Get the query results as a collection. * @see org.odmg.OQLQuery#execute() */ public Object execute() throws QueryException { //TODO: how are results meant to be returned in ODMG? try { return query.list(); } catch (SQLException sqle) { throw new QueryException( sqle.getMessage() ); } catch (HibernateException he) { throw new QueryException( he.getMessage() ); } } } ! ! Index: Transaction.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/odmg/Transaction.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Transaction.java 1 Jan 2003 13:56:31 -0000 1.1.1.1 --- Transaction.java 4 Jan 2003 11:15:30 -0000 1.2 *************** *** 1 **** ! //$Id$ package net.sf.hibernate.odmg; import java.sql.SQLException; import org.odmg.LockNotGrantedException; import org.odmg.ODMGException; import org.odmg.ODMGRuntimeException; import net.sf.hibernate.HibernateException; import net.sf.hibernate.LockMode; import net.sf.hibernate.Session; /** * Implements the ODMG <tt>Transaction</tt> API. */ public class Transaction implements org.odmg.Transaction { private final Database database; private final Session session; private net.sf.hibernate.Transaction tx; /** * Instantiate a <tt>Transaction</tt> for the given <tt>Database</tt>. */ public Transaction(org.odmg.Database database) throws ODMGException { this.database = (Database) database; try { this.session = this.database.getSessionFactory().openSession(); } catch (SQLException sqle) { throw new ODMGException( sqle.getMessage() ); } this.database.associateThread(this); } /** * Instantiate a <tt>Transaction</tt> for a <tt>Database</tt> created * by the current thread. */ public Transaction() throws ODMGException { this( Implementation.getInstance().currentDatabase() ); } /** * Get the underlying Hibernate <tt>Session</tt>. (Very useful!) */ public Session getSession() { return session; } /** * Associate the current thread with this <tt>Transaction</tt> and * disassociate the thread from any other <tt>Transaction</tt>. * @see org.odmg.Transaction#join() */ public void join() { //database.disassociateThread(); database.associateThread(this); } /** * Disassociate the thread the <tt>Transaction</tt>. * @see org.odmg.Transaction#leave() */ public void leave() { database.disassociateThread(); } /** * Begin the transaction. * @see org.odmg.Transaction#begin() */ public void begin() { try { tx = session.beginTransaction(); } catch (HibernateException he) { throw new ODMGRuntimeException( he.getMessage() ); } } /** * Is the transaction open? Returns true if <tt>begin()</tt> was called but * neither <tt>commit()</tt> nor <tt>abort()</tt> was called. * @see org.odmg.Transaction#isOpen() */ public boolean isOpen() { return tx==null; } /** * Commit the transaction. * @see org.odmg.Transaction#commit() */ public void commit() { database.disassociateThread(); try { tx.commit(); } catch (HibernateException he) { throw new ODMGRuntimeException( he.getMessage() ); } catch (SQLException sqle) { throw new ODMGRuntimeException( sqle.getMessage() ); } finally { tx=null; try { session.close(); } catch (HibernateException he) { throw new ODMGRuntimeException( he.getMessage() ); } catch (SQLException sqle) { throw new ODMGRuntimeException( sqle.getMessage() ); } } } /** * Abort the transaction. * @see org.odmg.Transaction#abort() */ public void abort() { database.disassociateThread(); try { tx.rollback(); } catch (HibernateException he) { throw new ODMGRuntimeException( he.getMessage() ); } finally { tx=null; try { session.close(); } catch (HibernateException he) { throw new ODMGRuntimeException( he.getMessage() ); } catch (SQLException sqle) { throw new ODMGRuntimeException( sqle.getMessage() ); } } } /** * Commit the changes, but leave the transaction open. This implementation * does not have quite the same semantics os ODMG (locks are not retained). * So you should only use this with versioned data. * @see org.odmg.Transaction#checkpoint() */ public void checkpoint() { try { tx.commit(); tx = session.beginTransaction(); } catch (HibernateException he) { throw new ODMGRuntimeException( he.getMessage() ); } catch (SQLException sqle) { throw new ODMGRuntimeException( sqle.getMessage() ); } } /** * Obtain a lock upon the given object. In the present implementation, * <tt>READ</tt> lock mode is ignored while <tt>UPGRADE</tt> and * <tt>WRITE</tt> lock modes obtain an <tt>UPGRADE</tt> lock for databases * which support <tt>for update</tt>. We should improve this eventually.... * @see org.odmg.Transaction#lock(Object, int) */ public void lock(Object obj, int lockMode) throws LockNotGrantedException { //TODO: check the semantics of this... try { if ( lockMode==org.odmg.Transaction.READ ) { session.lock(obj, LockMode.READ); } else { session.lock(obj, LockMode.UPGRADE); } } catch (HibernateException he) { throw new ODMGRuntimeException( he.getMessage() ); } catch (SQLException sqle) { throw new ODMGRuntimeException( sqle.getMessage() ); } } /** * Not implemented. * @see org.odmg.Transaction#tryLock(Object, int) */ public boolean tryLock(Object obj, int lockMode) { throw new UnsupportedOperationException("try using lock()"); } } \ No newline at end of file --- 1,3 ---- ! //$Id$ package net.sf.hibernate.odmg; import java.sql.SQLException; import org.odmg.LockNotGrantedException; import org.odmg.ODMGException; import org.odmg.ODMGRuntimeException; import net.sf.hibernate.HibernateException; import net.sf.hibernate.LockMode; import net.sf.hibernate.Session; /** * Implements the ODMG <tt>Transaction</tt> API. */ public class Transaction implements org.odmg.Transaction { private final Database database; private final Session session; private net.sf.hibernate.Transaction tx; /** * Instantiate a <tt>Transaction</tt> for the given <tt>Database</tt>. */ public Transaction(org.odmg.Database database) throws ODMGException { this.database = (Database) database; try { this.session = this.database.getSessionFactory().openSession(); } catch (SQLException sqle) { throw new ODMGException( sqle.getMessage() ); } this.database.associateThread(this); } /** * Instantiate a <tt>Transaction</tt> for a <tt>Database</tt> created * by the current thread. */ public Transaction() throws ODMGException { this( Implementation.getInstance().currentDatabase() ); } /** * Get the underlying Hibernate <tt>Session</tt>. (Very useful!) */ public Session getSession() { return session; } /** * Associate the current thread with this <tt>Transaction</tt> and * disassociate the thread from any other <tt>Transaction</tt>. * @see org.odmg.Transaction#join() */ public void join() { //database.disassociateThread(); database.associateThread(this); } /** * Disassociate the thread the <tt>Transaction</tt>. * @see org.odmg.Transaction#leave() */ public void leave() { database.disassociateThread(); } /** * Begin the transaction. * @see org.odmg.Transaction#begin() */ public void begin() { try { tx = session.beginTransaction(); } catch (HibernateException he) { throw new ODMGRuntimeException( he.getMessage() ); } } /** * Is the transaction open? Returns true if <tt>begin()</tt> was called but * neither <tt>commit()</tt> nor <tt>abort()</tt> was called. * @see org.odmg.Transaction#isOpen() */ public boolean isOpen() { return tx==null; } /** * Commit the transaction. * @see org.odmg.Transaction#commit() */ public void commit() { database.disassociateThread(); try { tx.commit(); } catch (HibernateException he) { throw new ODMGRuntimeException( he.getMessage() ); } catch (SQLException sqle) { throw new ODMGRuntimeException( sqle.getMessage() ); } finally { tx=null; try { session.close(); } catch (HibernateException he) { throw new ODMGRuntimeException( he.getMessage() ); } catch (SQLException sqle) { throw new ODMGRuntimeException( sqle.getMessage() ); } } } /** * Abort the transaction. * @see org.odmg.Transaction#abort() */ public void abort() { database.disassociateThread(); try { tx.rollback(); } catch (HibernateException he) { throw new ODMGRuntimeException( he.getMessage() ); } finally { tx=null; try { session.close(); } catch (HibernateException he) { throw new ODMGRuntimeException( he.getMessage() ); } catch (SQLException sqle) { throw new ODMGRuntimeException( sqle.getMessage() ); } } } /** * Commit the changes, but leave the transaction open. This implementation * does not have quite the same semantics os ODMG (locks are not retained). * So you should only use this with versioned data. * @see org.odmg.Transaction#checkpoint() */ public void checkpoint() { try { tx.commit(); tx = session.beginTransaction(); } catch (HibernateException he) { throw new ODMGRuntimeException( he.getMessage() ); } catch (SQLException sqle) { throw new ODMGRuntimeException( sqle.getMessage() ); } } /** * Obtain a lock upon the given object. In the present implementation, * <tt>READ</tt> lock mode is ignored while <tt>UPGRADE</tt> and * <tt>WRITE</tt> lock modes obtain an <tt>UPGRADE</tt> lock for databases * which support <tt>for update</tt>. We should improve this eventually.... * @see org.odmg.Transaction#lock(Object, int) */ public void lock(Object obj, int lockMode) throws LockNotGrantedException { //TODO: check the semantics of this... try { if ( lockMode==org.odmg.Transaction.READ ) { session.lock(obj, LockMode.READ); } else { session.lock(obj, LockMode.UPGRADE); } } catch (HibernateException he) { throw new ODMGRuntimeException( he.getMessage() ); } catch (SQLException sqle) { throw new ODMGRuntimeException( sqle.getMessage() ); } } /** * Not implemented. * @see org.odmg.Transaction#tryLock(Object, int) */ public boolean tryLock(Object obj, int lockMode) { throw new UnsupportedOperationException("try using lock()"); } } ! ! |