Saturday 19 May 2012

Java Learnings

1. Never try to create two Iterators of the same underlying object:
for e.g

iterator1 = odiJoins.iterator()
iterator2= odiJoins.iterator()

the second iterator will never be able to manipulate objects.
use this instead.:

iterator1=odiJoins.iterator()

//processing using iterator1


iterator1 =odiJoins.iterator()

//again some processing using iterator1


2. Whenver iterator is used


always use


iterator.hasNext() for looping .



ODI SDK NOTES:

oracle.odi.core.persistence.transaction.support.TransactionCallbackWithoutResult
implements ITransactionCallback

TransactionCallbackWithoutResult is a convenient class for ITransactionCallback interface. It helps in defining a doInTransaction() without the need for a return statement. 

doInTransaction(ITransactionStatus pStatus) 

doInTransaction() is called by TransactionTemplate.execute(ITransactionCallback)


Interface ITransactionCallback

oracle.odi.core.persistence.transaction.support.ITransactionCallback

Callback interface for transactional code. Used with TransactionTemplate's execute method, often as anonymous class within a method implementation.

java.lang.object doInTransaction(ITransactionStatus pStatus)

gets called by TransactionTemplate.execute(ITransactionCallbac) within a transactional context does not need to care about the transaction itself. This method can return an ODI entity or a collection of ODI entities created within the transaction.

Class TransactionTemplate

oracle.odi.core.persistence.transaction.support.TransactionTemplate extends DefaultTransactionDefinition
All Implemented Interfaces:
ITransactionDefinition
Class TransactinTemplate  simplifies programmatic transaction demarcation and transaction exception handling against an ITransactionManager. The method execute(ITransactionCallBack) is key to this class, supporting transactional code that implements ITransactionCallback interface. 
Note: this template handles the transaction lifecycle and possible exceptions such that neither the ITransactionCallback implementation nor the calling code need to handle transactions. 

Constructor:

TransacitonTemplate(ITransactionManager)
Constructs a new transaction template using the given transaction manager.

TransactionTemplate(ITransactionManager, ITransactionDefinition)
Constructs a new transaction template using the given transaction manager

Method: execute(ITransactionCallback)
execute the action specified by the given callback object within a given transaction.
Returns a result object created by the callback of null.

Interface ITransactionManager


oracle.odi.core.persistence.transaction 

Transaction management interface. 

methods:

1. void commit(ITransactionStatus)

2. ITransactionStatus getTransaction(ITransactionDefinition )
gets the currently Active transaction or creates a new one according to the given transaction definition(containing a propagation behavior). If the given definition is null a default definition will be used (with default propagation behavior and isolation level). Parameters like isolation level and timeout will only be applied to new transactions and will be ignored when participating with active ones. 

It returns transaction status object representing the new or current transaction.

3. rollback(ITransactionStatus)
Perform a rollback of the given transaction.




Java Exception Handling

A good read about Java exception handling:

https://today.java.net/article/2003/11/20/three-rules-effective-exception-handling








No comments:

Post a Comment