Software Architecture and Design Document

greasyservantInternet και Εφαρμογές Web

30 Ιουλ 2012 (πριν από 4 χρόνια και 10 μήνες)

242 εμφανίσεις

1.1.1

Required Changes to Hibernate Source Code for CMT in WAS 6.0

1.1.1.1

WebSphereExtendedJTATransactionLookup

1.1.1.1.1

Synchronization Callback Method Change

Old Code:

registerSynchronizationMethod =
Class.forName("com.ibm.websphere.jtaextensions.ExtendedJTATransaction")



.g
etMethod( "registerSynchronizationCallback", new Class[] {
synchronizationCallbackClass } );


New Code:

registerSynchronizationMethod =
Class.forName("com.ibm.websphere.jtaextensions.ExtendedJTATransaction")

.getMethod( "registerSynchronizationCallback
ForC
urrentTran
", new Class[] {
synchronizationCallbackClass } );


1.1.1.1.2

getStatus() Method Change

Old Code:

throw new UnsupportedOperationException();

New Code:

return 0;


1.1.1.1.3

invoke(..) Method Changes

Old Code:

if ( "afterCompletion".equals( method.getName() ) ) {



int status = args[3].equals(Boolean.TRUE) ?




Status.STATUS_COMMITTED :



Status.STATUS_UNKNOWN;

synchronization.afterCompletion(status);

}

else if ( "beforeCompletion".equals( method.getName() ) ) {

synchronization.beforeCompletion();

}

return null
;








New Code:




private static final Log log =
LogFactory.getLog(WebSphereExtendedJTATransactionLookup.class);



if ( "afterCompletion".equals( method.getName() ) ) {



int status = args[
2
].equals(Boolean.TRUE) ?




Status.STATUS_COMMITTED
:



Status.STATUS_UNKNOWN;

synchronization.afterCompletion(status);

}

else if ( "beforeCompletion".equals( method.getName() ) ) {

synchronization.beforeCompletion();

}

else if ( "toString".equals( method.getName() ) ) {

return synchronization.toString();

}

else {

log.debug(" Unknown method: " + method.getName());

}

return null;



1.1.1.2

CacheSynchronization

1.1.1.2.1

New toString() Method

New Code:

public String toString() {

return "org.hibernate.engine.CacheSynchronization";

}


1.1.1.2.2

Modifications to beforeCompletion() and afte
rCompletion() Methods

Old Code:

public void beforeCompletion() {

log.trace("transaction before completion callback");


final boolean flush;


try {



flush = session.getFlushMode()!=FlushMode.NEVER &&




session.getFactory().isFlushBeforeCompletionEnabled()

&&




!JTAHelper.isRollback( transaction.getStatus() );


}


catch (SystemException se) {



log.error("could not determine transaction status", se);



throw new TransactionException("could not determine transaction status in
beforeCompletion()", se);


}





try {



if (flush) {




log.trace("automatically flushing session");




session.flush();



}


}


finally {



if ( session.getFactory().isAutoCloseSessionEnabled() && session.isOpen() ) {




log.trace("automatically closing session");




session.close();


}

}


public void afterCompletion(int status) {

if ( log.isTraceEnabled() ) log.trace("transaction after completion callback, status: " +
status);


session.afterTransactionCompletion(status==Status.STATUS_COMMITTED);



}


New Code:

public void beforeComple
tion() {

log.trace("transaction before completion callback");


final boolean flush;


try {



flush = session.getFlushMode()!=FlushMode.NEVER &&




session.getFactory().isFlushBeforeCompletionEnabled() &&




!JTAHelper.isRollback( transaction.getStatus() );


}


catch (SystemException se) {



log.error("could not determine transaction status", se);



throw new TransactionException("could not determine transaction status in
beforeCompletion()", se);


}





try {



if (flush) {




log.trace("automatically flush
ing session");




session.flush();



}


}


finally {}


}


public void afterCompletion(int status) {


try {


if ( log.isTraceEnabled() ) log.trace("transaction after completion callback,
status: " + status);



session.afterTransactionCompletion(status==Stat
us.STATUS_COMMITTED);



}


finally {



if ( session.getFactory().isAutoCloseSessionEnabled() && session.isOpen() ) {




log.trace("automatically closing session");




session.close();


}

}


1.1.1.3

Hibernate.cfg.xml

These 4 attributes must be set in order to suppo
rt JTA in a managed environment.

<property name="
hibernate.transaction.factory_class
">


org.hibernate.transaction.JTATransactionFactory

</property>

<property name="
hibernate.transaction.manager_lookup_class
">


org.hibernate.transaction.WebSphereExtend
edJTATransactionLookup

</property>

<property name="
hibernate.transaction.flush_before_completion
">


true

</property>

<property name="
hibernate.transaction.auto_close_session
">


true

</property>


1.1.1.4

Other Notes Related to JTA



The standard Hibernate Transac
tion API will not work in WAS 6.0. But, one does not need to be
concerned with explicitly demarcating Hibernate transactions in CMT. The container will manage
these transactions.



It is not necessary to close the Hibernate Session when working in a WA
S 6.0 managed
environment. By setting the auto_close_session to true, the container will close the session once
all pending transactions are committed. If a data access object explicitly closes the session, the
container will no longer be able to manage
that session, which will result in that database
transaction being rolled back.