HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Interfacing Transaction Services: Part 2"
Volume: 3 Issue: 7, p. 32

	

Listing 1: CosTransactions Module (OMG IDL). 

//The CosTransactions Module 

#include <Corba.idl> 
module CosTransactions  
{ 
  //DATATYPES 
  enum Status  
  {  
    StatusActive, 
    StatusMarkedRollback, 
    StatusPrepared, 
    StatusCommitted, 
    StatusRolledBack, 
    StatusUnknown, 
    StatusNoTransaction, 
    StatusPreparing, 
    StatusCommitting, 
    StatusRollingBack 
  }; 
  enum Vote  
  { 
    VoteCommit, 
    VoteRollback, 
    VoteReadOnly 
  }; 

  //Structure definitions 
  struct otid_t  
  { 
    long formatID; /*format identifier. 0 is OSI TP */ 
    long bqual_length; 
    sequence <octet> tid; 
  }; 
  struct TransIdentity  
  { 
    Coordinator coord; 
    Terminator term; 
    otid_t otid; 
  }; 
  struct PropagationContext  
  { 
    unsigned long timeout; 
    TransIdentity current; 
    sequence <TransIdentity> parents; 
    any implementation_specific_data; 
  }; 

//Forward references for interfaces defined later in module 
interface Current; 
interface TransactionFactory; 
interface Control; 
interface Terminator; 
interface Coordinator; 
interface RecoveryCoordinator; 
interface Resource; 
interface Synchronization; 
interface SubtransactionAwareResource; 
interface TransactionalObject; 

//Heuristic exceptions 
exception HeuristicRollback {}; 
exception HeuristicCommit {}; 
exception HeuristicMixed {}; 
exception HeuristicHazard {}; 

//Other transaction-specific exceptions 
exception SubtransactionsUnavailable {}; 
exception NotSubtransaction {}; 
exception Inactive {}; 
exception NotPrepared {}; 
exception NoTransaction {}; 
exception InvalidControl {}; 
exception Unavailable {}; 
exception SynchronizationUnavailable {}; 

//Current transaction 
interface Current : CORBA::Current  
{ 
void begin() 
raises(SubtransactionsUnavailable); 
void commit(in boolean report_heuristics) 
raises( 
NoTransaction, 
HeuristicMixed, 
HeuristicHazard 
); 
void rollback() 
raises(NoTransaction); 
void rollback_only() 
raises(NoTransaction); 
Status get_status(); 
string get_transaction_name(); 
void set_timeout(in unsigned long seconds); 
Control get_control(); 
Control suspend(); 
void resume(in Control which) 
raises(InvalidControl); 
}; 
interface TransactionFactory { 
Control create(in unsigned long time_out); 
Control recreate(in PropagationContext ctx); 
}; 
interface Control { 
Terminator get_terminator() 
raises(Unavailable); 
Coordinator get_coordinator() 
raises(Unavailable); 
}; 
interface Terminator { 
void commit(in boolean report_heuristics) 
raises( 
HeuristicMixed, 
HeuristicHazard 
); 
void rollback(); 
}; 
interface Coordinator { 
Status get_status(); 
Status get_parent_status(); 
Status get_top_level_status(); 
boolean is_same_transaction(in Coordinator tc); 
boolean is_related_transaction(in Coordinator tc); 
boolean is_ancestor_transaction(in Coordinator tc); 
boolean is_descendant_transaction(in Coordinator tc); 
boolean is_top_level_transaction(); 
unsigned long hash_transaction(); 
unsigned long hash_top_level_tran(); 
RecoveryCoordinator register_resource(in Resource r) 
raises(Inactive); 
void register_synchronization (in Synchronization sync) 
raises(Inactive, SynchronizationUnavailable); 
void register_subtran_aware(in SubtransactionAwareResource r) 
raises(Inactive, NotSubtransaction); 
void rollback_only() 
raises(Inactive); 
string get_transaction_name(); 
Control create_subtransaction() 
raises(SubtransactionsUnavailable, Inactive); 
PropagationContext get_txcontext () 
raises(Unavailable); 
}; 
interface RecoveryCoordinator { 
Status replay_completion(in Resource r) 
raises(NotPrepared); 
}; 
interface Resource { 
Vote prepare() 
raises( 
HeuristicMixed, 
HeuristicHazard 
); 
void rollback() 
raises( 
HeuristicCommit, 
HeuristicMixed, 
HeuristicHazard 
); 
void commit() 
raises( 
NotPrepared, 
HeuristicRollback, 
HeuristicMixed, 
HeuristicHazard 
); 
void commit_one_phase() 
raises( 
HeuristicHazard 
); 
void forget(); 
}; 
interface TransactionalObject { 
}; 
interface Synchronization : TransactionalObject { 
void before_completion(); 
void after_completion(in Status status); 
}; 
interface SubtransactionAwareResource : Resource { 
void commit_subtransaction(in Coordinator parent); 
void rollback_subtransaction(); 
}; 
}; // End of CosTransactions Module 

The CosTSPortability Module 
module CosTSPortability  
{ // PIDL 
  typedef long ReqId; 
  interface Sender  
  { 
    void sending_request(in ReqId id, out CosTransactions::PropagationContext ctx); 
    void received_reply(in ReqId id, in CosTransactions::PropagationContext ctx, in CORBA::Environment env); 
  }; 
  interface Receiver  
  { 
    void received_request(in ReqId id, in CosTransactions::PropagationContext ctx); 
    void sending_reply(in ReqId id, out CosTransactions::PropagationContext ctx); 
  }; 
}; 

Listing 2: JTS UserTransaction Interface. 

package javax.jts; 

public interface UserTransaction extends java.lang.Object 
{ 
  //Variables 
  public static final int STATUS_ACTIVE; 
  public static final int STATUS_MARKED_ROLLBACK; 
  public static final int STATUS_PREPARED; 
  public static final int STATUS_COMMITTED; 
  public static final int STATUS_ROLLEDBACK; 
  public static final int STATUS_UNKNOWN; 
  public static final int STATUS_NO_TRANSACTION; 
  public static final int STATUS_PREPARING; 
  public static final int STATUS_COMMITTING; 
  public static final int STATUS_ROLLING_BACK; 

  //Methods 
  public abstract void begin() 
    throws IllegalStateException; 

  public abstract void commit()  
    throws TransactionRolledbackException, HeuristicMixedException,  
    HeuristicRollbackException, SecurityException, IllegalStateException; 
  
  public abstract void rollback() 
    throws IllegalStateException, SecurityException; 

  public abstract void setRollbackOnly() 
    throws IllegalStateException; 

  public abstract int getStatus(); 

  public abstract void setTransactionTimeout(int seconds) 
  
      
 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.