Skip navigation links

Oracle® Coherence Java API Reference
Release 3.6.0.0

E15725-01


com.tangosol.coherence.transaction
Interface Connection


public interface Connection

Represents a logical connection to a Coherence data grid. Acts as a factory for OptimisticNamedCache instances. A connection always has an associated transaction which is scoped within the connection. When a transaction is completed, a new transaction is started. Connections are in auto-commit mode by default. In auto-commit mode, each statement is executed in a distinct transaction and when the statement completes the transaction is committed and the connection is associated with a new transaction. A connection is not thread safe and may not be used by multiple threads concurrently.

Since:
Coherence 3.6
Author:
js 2009.02.01

Method Summary
 void close()
          Close the logical connection.
 void commit()
          Commit the active transaction.
 Isolation getIsolationLevel()
          Determine the isolation level for the connection.
 OptimisticNamedCache getNamedCache(String sTable)
          Obtain an OptimisticNamedCache for the given table name.
 TransactionState getTransactionState()
          Obtain information about the active transaction.
 int getTransactionTimeout()
          Obtain the transaction timeout.
 boolean isAutoCommit()
          Determine whether the connection will produce transactions that are in auto-commit mode.
 boolean isClosed()
          Determine whether the connection has been closed.
 boolean isEager()
          Deterimine wheter connection is in eager mode.
 void rollback()
          Rollback the active transaction.
 void setAutoCommit(boolean fAuto)
          Specify whether transactions created by this connection are in auto-commit mode.
 void setEager(boolean fEager)
          Specify whether transactions produced by this connection will be in eager mode.
 void setIsolationLevel(Isolation isolation)
          Specify the isolation level that will be set on transactions produced by this connection.
 void setTransactionTimeout(int nSeconds)
          Set the transaction timeout.

 

Method Detail

getNamedCache

OptimisticNamedCache getNamedCache(String sTable)
Obtain an OptimisticNamedCache for the given table name.
Parameters:
sTable - the name of the table (cache)
Returns:
the newly created cache
Throws:
ConnectionClosedException - if called after connection is closed

commit

void commit()
Commit the active transaction.
Throws:
IllegalStateException - if the connection is in auto-commit mode
ConnectionClosedException - if called after connection is closed
RollbackException - if commit results in the transaction being rolled back

rollback

void rollback()
Rollback the active transaction.
Throws:
IllegalStateException - if the connection is in auto-commit mode
ConnectionClosedException - if called after connection is closed

close

void close()
Close the logical connection. If the connection has any associated work, the work is rolled back.

isClosed

boolean isClosed()
Determine whether the connection has been closed. The connection may be closed explicitly or as a result of a connection loss with the cluster.
Returns:
true if the connection is closed, false otherwise

getTransactionState

TransactionState getTransactionState()
Obtain information about the active transaction. This object may be held after a transaction completes to determine the outcome of the transaction.
Returns:
the newly created TransactionState object

setAutoCommit

void setAutoCommit(boolean fAuto)
Specify whether transactions created by this connection are in auto-commit mode. In auto-commit mode, a transaction is scoped to a single operation. It is illegal to manually commit or rollback a transaction that is in auto-commit mode. In non auto-commit mode, a transaction may span multiple operations and must be explicitly ended with either a commit or rollback call. <p/> If work has been done on the active transaction when this method is called with a value of "true", the work is rolled back.
Parameters:
fAuto - if true, transactions will be in auto-commit mode
Throws:
ConnectionClosedException - if called after connection is closed

isAutoCommit

boolean isAutoCommit()
Determine whether the connection will produce transactions that are in auto-commit mode.
Returns:
true if in auto-commmit mode, false otherwise

setEager

void setEager(boolean fEager)
Specify whether transactions produced by this connection will be in eager mode. The default value is true. When in eager mode, every operation is immediately flushed to the grid. In non-eager mode, the flush of the operation may be deferred and the operation queued locally if the operation is deferrable. Typically, if an operation does not return a value, it is deferrable. Queueing operations may be more performant since some operations may be batched when they are flushed.
Parameters:
fEager - if true, connection should be in eager mode
Throws:
ConnectionClosedException - if called after connection is closed

isEager

boolean isEager()
Deterimine wheter connection is in eager mode.
Returns:
true if in eager mode, false otherwise

setIsolationLevel

void setIsolationLevel(Isolation isolation)
Specify the isolation level that will be set on transactions produced by this connection. The default value is READ_COMMITTED. This method should be called before doing any work on the active transaction.
Parameters:
isolation - the isolation level
Throws:
IllegalStateException - if transaction has any associated work
ConnectionClosedException - if called after connection is closed

getIsolationLevel

Isolation getIsolationLevel()
Determine the isolation level for the connection.
Returns:
the current isolation level

setTransactionTimeout

void setTransactionTimeout(int nSeconds)
Set the transaction timeout.
Parameters:
nSeconds - the timeout in seconds

getTransactionTimeout

int getTransactionTimeout()
Obtain the transaction timeout.
Returns:
the timeout in seconds

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.6.0.0

E15725-01


Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.