Package lumis.portal.dao.hibernate
Class TransactionHibernate
- java.lang.Object
-
- lumis.portal.dao.hibernate.TransactionHibernate
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,ITransactionHibernate
,ITransactionJdbc
,ITransactionJPA
,ITransaction
,ITransactionSPI
,ITransaction
public class TransactionHibernate extends java.lang.Object implements ITransactionHibernate, ITransactionSPI
Implements a transaction object- Since:
- 4.0.0
- Version:
- $Revision: 24477 $ $Date: 2021-04-28 11:30:36 -0300 (Wed, 28 Apr 2021) $
-
-
Constructor Summary
Constructors Constructor Description TransactionHibernate()
Creates a new transaction object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addObserver(ITransactionObserver observer)
Adds an observer for this transaction.boolean
addObserverFirst(ITransactionObserver observer)
Adds an observer for this transaction as the first observer in the observer list.void
begin()
void
close()
Closes this transaction, rolling back any changes not committed by a previous call toITransaction.commit()
, and removes any association of this transaction from the current thread.void
commit()
void
dispose()
protected void
finalize()
java.lang.Object
getAttribute(java.lang.String name)
Returns the value of the named attribute, ornull
if no attribute of the given name exists.long
getBeginTimeMillis()
Returns the time when this transaction began in milliseconds since January 1, 1970 UTC.ITransaction
getByConnectionId(java.lang.String id)
Returns anITransaction
that represents the same transaction but that returns the connection with the given id as default.java.sql.Connection
getConnection()
Returns the default jdbc connection for this transaction.java.sql.Connection
getConnection(java.lang.String databaseId)
Returns the jdbc connection associated with the specified id.long
getCreationTimeMillis()
Returns the time this transaction object was created.EntityManager
getEntityManager()
Returns the default entity manager for this transaction.EntityManager
getEntityManager(java.lang.String databaseId)
Returns the entity manager associated with the specified database.org.hibernate.Session
getSession()
Returns the default hibernate session for this transaction.org.hibernate.Session
getSession(java.lang.String databaseId)
Returns the hibernate session associated with the specified database.java.lang.Throwable
getTransactionCreationTrace()
Returns a throwable used just as a trace to the transaction creation.boolean
isActive()
Returns true if the transaction is currently active, false otherwise.void
removeAttribute(java.lang.String name)
Removes an attribute from this transaction.boolean
removeObserver(ITransactionObserver observer)
Removes an observer for this transaction.void
rollback()
void
setAttribute(java.lang.String name, java.lang.Object value)
Stores an attribute in this transaction.void
setTransactionProviderCallback(ITransactionProviderCallback callback)
Sets the transaction provider callback object to be used by this transaction.
-
-
-
Constructor Detail
-
TransactionHibernate
public TransactionHibernate()
Creates a new transaction object. Do not create this object directly, usePortalTransactionFactory
instead.- Since:
- 6.2.0
- See Also:
PortalTransactionFactory.createTransaction()
-
-
Method Detail
-
getEntityManager
public EntityManager getEntityManager()
Description copied from interface:ITransactionJPA
Returns the default entity manager for this transaction.- Specified by:
getEntityManager
in interfaceITransactionJPA
- Returns:
- the default entity manager for this transaction.
-
getEntityManager
public EntityManager getEntityManager(java.lang.String databaseId)
Description copied from interface:ITransactionJPA
Returns the entity manager associated with the specified database.- Specified by:
getEntityManager
in interfaceITransactionJPA
- Parameters:
databaseId
- the database id.- Returns:
- the entity manager.
-
getSession
public org.hibernate.Session getSession() throws DaoException
Description copied from interface:ITransactionHibernate
Returns the default hibernate session for this transaction.- Specified by:
getSession
in interfaceITransactionHibernate
- Returns:
- the default hibernate session for this transaction.
- Throws:
DaoException
-
getSession
public org.hibernate.Session getSession(java.lang.String databaseId) throws DaoException
Description copied from interface:ITransactionHibernate
Returns the hibernate session associated with the specified database.- Specified by:
getSession
in interfaceITransactionHibernate
- Parameters:
databaseId
- the database id.- Returns:
- the hibernate session.
- Throws:
DaoException
-
dispose
public void dispose() throws DaoException
- Specified by:
dispose
in interfaceITransaction
- Throws:
DaoException
-
close
public void close()
Description copied from interface:ITransaction
Closes this transaction, rolling back any changes not committed by a previous call toITransaction.commit()
, and removes any association of this transaction from the current thread.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceITransaction
-
finalize
protected void finalize() throws java.lang.Throwable
- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
isActive
public boolean isActive()
Description copied from interface:ITransaction
Returns true if the transaction is currently active, false otherwise.- Specified by:
isActive
in interfaceITransaction
- Returns:
- true if the transaction is currently active, false otherwise.
-
begin
public void begin() throws DaoException
- Specified by:
begin
in interfaceITransaction
- Throws:
DaoException
-
commit
public void commit() throws DaoException
- Specified by:
commit
in interfaceITransaction
- Throws:
DaoException
-
rollback
public void rollback() throws DaoException
- Specified by:
rollback
in interfaceITransaction
- Throws:
DaoException
-
getConnection
public java.sql.Connection getConnection() throws DaoException
Description copied from interface:ITransactionJdbc
Returns the default jdbc connection for this transaction.- Specified by:
getConnection
in interfaceITransactionJdbc
- Returns:
- the default jdbc connection for this transaction.
- Throws:
DaoException
-
getConnection
public java.sql.Connection getConnection(java.lang.String databaseId) throws DaoException
Description copied from interface:ITransactionJdbc
Returns the jdbc connection associated with the specified id.- Specified by:
getConnection
in interfaceITransactionJdbc
- Parameters:
databaseId
- the connection id.- Returns:
- the jdbc connection.
- Throws:
DaoException
-
getByConnectionId
public ITransaction getByConnectionId(java.lang.String id) throws DaoException
Description copied from interface:ITransaction
Returns anITransaction
that represents the same transaction but that returns the connection with the given id as default. How the id represents the connection is defined by the concrete class that implements this interface.- Specified by:
getByConnectionId
in interfaceITransaction
- Specified by:
getByConnectionId
in interfaceITransaction
- Parameters:
id
- the connection id.- Returns:
- the ITransaction object.
- Throws:
DaoException
-
addObserver
public boolean addObserver(ITransactionObserver observer) throws PortalException
Description copied from interface:ITransaction
Adds an observer for this transaction. The observer is added only if the current observer list does not already contain it.- Specified by:
addObserver
in interfaceITransaction
- Parameters:
observer
- the observer.- Returns:
- true if the observer was added, false otherwise.
- Throws:
PortalException
-
addObserverFirst
public boolean addObserverFirst(ITransactionObserver observer) throws PortalException
Description copied from interface:ITransactionSPI
Adds an observer for this transaction as the first observer in the observer list. The observer is added only if the current observer list does not already contain it.- Specified by:
addObserverFirst
in interfaceITransactionSPI
- Parameters:
observer
- the observer.- Returns:
- true if the observer was added, false otherwise.
- Throws:
PortalException
-
removeObserver
public boolean removeObserver(ITransactionObserver observer) throws PortalException
Description copied from interface:ITransaction
Removes an observer for this transaction. If the current observer list does not contain the given observer nothing happens.- Specified by:
removeObserver
in interfaceITransaction
- Parameters:
observer
- the observer.- Returns:
- true if the observer was removed, false otherwise.
- Throws:
PortalException
-
getBeginTimeMillis
public long getBeginTimeMillis()
Description copied from interface:ITransactionSPI
Returns the time when this transaction began in milliseconds since January 1, 1970 UTC.- Specified by:
getBeginTimeMillis
in interfaceITransactionSPI
- Returns:
- the time when this transaction began in milliseconds since January 1, 1970 UTC.
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
Description copied from interface:ITransaction
Returns the value of the named attribute, ornull
if no attribute of the given name exists.Different transaction instances that refer to the same transaction (see
ITransaction.getByConnectionId(String)
) share the same attributes.- Specified by:
getAttribute
in interfaceITransaction
- Parameters:
name
- the name of the attribute.- Returns:
- the value of the attribute, or null if the attribute does not exist.
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object value)
Description copied from interface:ITransaction
Stores an attribute in this transaction. If the value passed in isnull
, the effect is the same as callingITransaction.removeAttribute(String)
.- Specified by:
setAttribute
in interfaceITransaction
- Parameters:
name
- the name of the attribute.value
- the value to be stored.
-
removeAttribute
public void removeAttribute(java.lang.String name)
Description copied from interface:ITransaction
Removes an attribute from this transaction.- Specified by:
removeAttribute
in interfaceITransaction
- Parameters:
name
- the name of the attribute.
-
setTransactionProviderCallback
public void setTransactionProviderCallback(ITransactionProviderCallback callback)
Description copied from interface:ITransactionSPI
Sets the transaction provider callback object to be used by this transaction.- Specified by:
setTransactionProviderCallback
in interfaceITransactionSPI
- Parameters:
callback
- the callback object.
-
getTransactionCreationTrace
public java.lang.Throwable getTransactionCreationTrace()
Description copied from interface:ITransactionSPI
Returns a throwable used just as a trace to the transaction creation. Instead of manually manipulatingStackTraceElement
, using a throwable also provides higher-level methods.- Specified by:
getTransactionCreationTrace
in interfaceITransactionSPI
- See Also:
Throwable.getStackTrace()
-
getCreationTimeMillis
public long getCreationTimeMillis()
Description copied from interface:ITransactionSPI
Returns the time this transaction object was created.- Specified by:
getCreationTimeMillis
in interfaceITransactionSPI
- Returns:
- the difference, measured in milliseconds, between this object creation time and midnight, January 1, 1970 UTC.
-
-