TransactionConfig (Oracle - Berkeley DB Java Edition API)
Date: 2014-12-16

com.sleepycat.je

## Class TransactionConfig

- java.lang.Object
- - com.sleepycat.je.TransactionConfig

- All Implemented Interfaces:
    Cloneable

      public class TransactionConfig
      extends Object
      implements Cloneable

  Specifies the attributes of a database environment transaction.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static TransactionConfig` | `DEFAULT` Default configuration used if null is passed to methods that create a transaction.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TransactionConfig()` An instance created using the default constructor is initialized with the system's default settings.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `TransactionConfig` | `clone()` Returns a copy of this configuration object.
    `ReplicaConsistencyPolicy` | `getConsistencyPolicy()` Returns the consistency policy associated with the configuration.
    `Durability` | `getDurability()` Returns the durability associated with the configuration.
    `boolean` | `getLocalWrite()` Returns whether local-write is configured for this transaction.
    `boolean` | `getNoSync()` Deprecated. replaced by `getDurability()`
    `boolean` | `getNoWait()` Returns true if the transaction is configured to not wait if a lock request cannot be immediately granted.
    `boolean` | `getReadCommitted()` Returns true if the transaction is configured for read committed isolation.
    `boolean` | `getReadOnly()` Returns whether read-only is configured for this transaction.
    `boolean` | `getReadUncommitted()` Returns true if read operations performed by the transaction are configured to return modified but not yet committed data.
    `boolean` | `getSerializableIsolation()` Returns true if the transaction has been explicitly configured to have serializable (degree 3) isolation.
    `boolean` | `getSync()` Returns true if the transaction is configured to write and synchronously flush the log it when commits.
    `boolean` | `getWriteNoSync()` Deprecated. replaced by `getDurability()`
    `TransactionConfig` | `setConsistencyPolicy(ReplicaConsistencyPolicy consistencyPolicy)` Associates a consistency policy with this configuration.
    `TransactionConfig` | `setDurability(Durability durability)` Configures the durability associated with a transaction when it commits.
    `TransactionConfig` | `setLocalWrite(boolean localWrite)` Configures this transaction to allow writing to non-replicated `Database`s in a `ReplicatedEnvironment`.
    `TransactionConfig` | `setNoSync(boolean noSync)` Deprecated. replaced by `setDurability(com.sleepycat.je.Durability)`
    `TransactionConfig` | `setNoWait(boolean noWait)` Configures the transaction to not wait if a lock request cannot be immediately granted.
    `TransactionConfig` | `setReadCommitted(boolean readCommitted)` Configures the transaction for read committed isolation.
    `TransactionConfig` | `setReadOnly(boolean readOnly)` Configures this transaction to disallow write operations, regardless of whether writes are allowed for the `Environment` or the `Database`s that are accessed.
    `TransactionConfig` | `setReadUncommitted(boolean readUncommitted)` Configures read operations performed by the transaction to return modified but not yet committed data.
    `TransactionConfig` | `setSerializableIsolation(boolean serializableIsolation)` Configures this transaction to have serializable (degree 3) isolation.
    `TransactionConfig` | `setSync(boolean sync)` Configures the transaction to write and synchronously flush the log it when commits.
    `TransactionConfig` | `setWriteNoSync(boolean writeNoSync)` Deprecated. replaced by `setDurability(com.sleepycat.je.Durability)`
    `String` | `toString()` Returns the values for each configuration attribute.

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT

          public static final TransactionConfig DEFAULT

      Default configuration used if null is passed to methods that create a transaction.

  - ### Constructor Detail

    - #### TransactionConfig

          public TransactionConfig()

      An instance created using the default constructor is initialized with the system's default settings.

  - ### Method Detail

    - #### setSync

          public TransactionConfig setSync(boolean sync)

      Configures the transaction to write and synchronously flush the log it when commits.

      This behavior may be set for a database environment using the Environment.setMutableConfig method. Any value specified to this method overrides that setting.

      The default is false for this class and true for the database environment.

      If true is passed to both setSync and setNoSync, setSync will take precedence.

      Parameters:
        `sync` - If true, transactions exhibit all the ACID (atomicity, consistency, isolation, and durability) properties.
      Returns:
        this

    - #### getSync

          public boolean getSync()

      Returns true if the transaction is configured to write and synchronously flush the log it when commits.
      Returns:
        true if the transaction is configured to write and synchronously flush the log it when commits.

    - #### setNoSync

          public TransactionConfig setNoSync(boolean noSync)

      Deprecated. replaced by `setDurability(com.sleepycat.je.Durability)`
      Configures the transaction to not write or synchronously flush the log it when commits.

      This behavior may be set for a database environment using the Environment.setMutableConfig method. Any value specified to this method overrides that setting.

      The default is false for this class and the database environment.

      Parameters:
        `noSync` - If true, transactions exhibit the ACI (atomicity, consistency, and isolation) properties, but not D (durability); that is, database integrity will be maintained, but if the application or system fails, it is possible some number of the most recently committed transactions may be undone during recovery. The number of transactions at risk is governed by how many log updates can fit into the log buffer, how often the operating system flushes dirty buffers to disk, and how often the log is checkpointed.
      Returns:
        this

    - #### getNoSync

          public boolean getNoSync()

      Deprecated. replaced by `getDurability()`
      Returns true if the transaction is configured to not write or synchronously flush the log it when commits.
      Returns:
        true if the transaction is configured to not write or synchronously flush the log it when commits.

    - #### setWriteNoSync

          public TransactionConfig setWriteNoSync(boolean writeNoSync)

      Deprecated. replaced by `setDurability(com.sleepycat.je.Durability)`
      Configures the transaction to write but not synchronously flush the log it when commits.

      This behavior may be set for a database environment using the Environment.setMutableConfig method. Any value specified to this method overrides that setting.

      The default is false for this class and the database environment.

      Parameters:
        `writeNoSync` - If true, transactions exhibit the ACI (atomicity, consistency, and isolation) properties, but not D (durability); that is, database integrity will be maintained, but if the operating system fails, it is possible some number of the most recently committed transactions may be undone during recovery. The number of transactions at risk is governed by how often the operating system flushes dirty buffers to disk, and how often the log is checkpointed.
      Returns:
        this

    - #### getWriteNoSync

          public boolean getWriteNoSync()

      Deprecated. replaced by `getDurability()`
      Returns true if the transaction is configured to write but not synchronously flush the log it when commits.
      Returns:
        true if the transaction is configured to not write or synchronously flush the log it when commits.

    - #### setDurability

          public TransactionConfig setDurability(Durability durability)

      Configures the durability associated with a transaction when it commits. Changes to durability are not reflected back to the "sync" booleans -- there isn't a one to one mapping. Note that you should not use both the durability and the XXXSync() apis on the same config object.
      Parameters:
        `durability` - the durability definition
      Returns:
        this

    - #### getDurability

          public Durability getDurability()

      Returns the durability associated with the configuration. If `setDurability(com.sleepycat.je.Durability)` has not been called, this method returns null. When no durability settings have been specified using the `TransactionConfig`, the default durability is applied to the `Transaction` by `Environment.beginTransaction(com.sleepycat.je.Transaction, com.sleepycat.je.TransactionConfig)` using `EnvironmentConfig` settings.
      Returns:
        the durability setting currently associated with this config.

    - #### setConsistencyPolicy

          public TransactionConfig setConsistencyPolicy(ReplicaConsistencyPolicy consistencyPolicy)

      Associates a consistency policy with this configuration.
      Parameters:
        `consistencyPolicy` - the consistency definition
      Returns:
        this

    - #### getConsistencyPolicy

          public ReplicaConsistencyPolicy getConsistencyPolicy()

      Returns the consistency policy associated with the configuration.
      Returns:
        the consistency policy currently associated with this config.

    - #### setNoWait

          public TransactionConfig setNoWait(boolean noWait)

      Configures the transaction to not wait if a lock request cannot be immediately granted.

      The default is false for this class and the database environment.

      Parameters:
        `noWait` - If true, transactions will not wait if a lock request cannot be immediately granted, instead `LockNotAvailableException` will be thrown.
      Returns:
        this

    - #### getNoWait

          public boolean getNoWait()

      Returns true if the transaction is configured to not wait if a lock request cannot be immediately granted.
      Returns:
        true if the transaction is configured to not wait if a lock request cannot be immediately granted.

    - #### setReadUncommitted

          public TransactionConfig setReadUncommitted(boolean readUncommitted)

      Configures read operations performed by the transaction to return modified but not yet committed data.
      Parameters:
        `readUncommitted` - If true, configure read operations performed by the transaction to return modified but not yet committed data.
      Returns:
        this
      See Also:
        `LockMode.READ_UNCOMMITTED`

    - #### getReadUncommitted

          public boolean getReadUncommitted()

      Returns true if read operations performed by the transaction are configured to return modified but not yet committed data.
      Returns:
        true if read operations performed by the transaction are configured to return modified but not yet committed data.
      See Also:
        `LockMode.READ_UNCOMMITTED`

    - #### setReadCommitted

          public TransactionConfig setReadCommitted(boolean readCommitted)

      Configures the transaction for read committed isolation.

      This ensures the stability of the current data item read by the cursor but permits data read by this transaction to be modified or deleted prior to the commit of the transaction.

      Parameters:
        `readCommitted` - If true, configure the transaction for read committed isolation.
      Returns:
        this
      See Also:
        `LockMode.READ_COMMITTED`

    - #### getReadCommitted

          public boolean getReadCommitted()

      Returns true if the transaction is configured for read committed isolation.
      Returns:
        true if the transaction is configured for read committed isolation.
      See Also:
        `LockMode.READ_COMMITTED`

    - #### setSerializableIsolation

          public TransactionConfig setSerializableIsolation(boolean serializableIsolation)

      Configures this transaction to have serializable (degree 3) isolation. By setting serializable isolation, phantoms will be prevented.

      By default a transaction provides Repeatable Read isolation; `EnvironmentConfig.setTxnSerializableIsolation(boolean)` may be called to override the default. If the environment is configured for serializable isolation, all transactions will be serializable regardless of whether this method is called; calling `setSerializableIsolation(boolean)` with a false parameter will not disable serializable isolation.

      The default is false for this class and the database environment.
      Returns:
        this
      See Also:
        `LockMode`

    - #### getSerializableIsolation

          public boolean getSerializableIsolation()

      Returns true if the transaction has been explicitly configured to have serializable (degree 3) isolation.
      Returns:
        true if the transaction has been configured to have serializable isolation.
      See Also:
        `LockMode`

    - #### setReadOnly

          public TransactionConfig setReadOnly(boolean readOnly)

      Configures this transaction to disallow write operations, regardless of whether writes are allowed for the `Environment` or the `Database`s that are accessed.

      If a write operation is attempted using a read-only transaction, an `UnsupportedOperationException` will be thrown.

      For a read-only transaction, the transaction's `Durability` is ignored, even when it is explicitly specified using `setDurability(Durability)`.

      In a `ReplicatedEnvironment`, a read-only transaction implicitly uses `Durability.ReplicaAckPolicy.NONE`. A read-only transaction on a Master will thus not be held up, or throw `InsufficientReplicasException`, if the Master is not in contact with a sufficient number of Replicas at the time the transaction is initiated.

      The default setting is false (writes are allowed).

      Returns:
        this

    - #### getReadOnly

          public boolean getReadOnly()

      Returns whether read-only is configured for this transaction.

    - #### setLocalWrite

          public TransactionConfig setLocalWrite(boolean localWrite)

      Configures this transaction to allow writing to non-replicated `Database`s in a `ReplicatedEnvironment`.

      In a replicated environment, a given transaction may be used to write to either replicated databases or non-replicated databases, but not both. If a write operation to a replicated database is attempted when local-write is true, or to a non-replicated database when local-write is false, an `UnsupportedOperationException` will be thrown.

      Note that for auto-commit transactions (when the `Transaction` parameter is null), the local-write setting is automatically set to correspond to whether the database is replicated. With auto-commit, local-write is always true for a non-replicated database, and always false for a replicated database.

      In a replicated environment, a local-write transaction implicitly uses `Durability.ReplicaAckPolicy.NONE`. A local-write transaction on a Master will thus not be held up, or throw `InsufficientReplicasException`, if the Master is not in contact with a sufficient number of Replicas at the time the transaction is initiated.

      By default the local-write setting is false, meaning that the transaction may only write to replicated Databases in a replicated environment.

      This configuration setting is ignored in a non-replicated Environment since no databases are replicated.

      Returns:
        this
      See Also:

        - #### getLocalWrite

              public boolean getLocalWrite()

          Returns whether local-write is configured for this transaction.

        - #### clone

              public TransactionConfig clone()

          Returns a copy of this configuration object.
          Overrides:
            `clone` in class `Object`

        - #### toString

              public String toString()

          Returns the values for each configuration attribute.
          Overrides:
            `toString` in class `Object`
          Returns:
            the values for each configuration attribute.

Copyright (c) 2004, 2014 Oracle and/or its affiliates. All rights reserved.