Class ConnectionPolicy

java.lang.Object
org.eclipse.persistence.sessions.server.ConnectionPolicy
All Implemented Interfaces:
Serializable, Cloneable

public class ConnectionPolicy extends Object implements Cloneable, Serializable

Purpose: Used to specify how a client session's should be allocated.

Description: The ConnectionPolicy is used to indicate how a client session will interact with the internal or external JDBC connection pool/data source. The default ConnectionPolicy is held on the ServerSession but this can be overridden for any specific client session when it is acquired.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Default value Transactional causes creation of ClientSession, the other two values - ExclusiveIsolatedClientSession.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    This attribute is used by the ServerSession to determine if a client session with an exclusive connection should be built and how the exclusive connection should be used.
    protected boolean
    Determines if the write/exclusive connection is acquired only when first requested (lazy, this is the default) or immediately when the client session is acquired.
    protected Login
    The login information used to create a JDBC connection or acquire one from an external pool/data-source.
    protected String
    Name of the pool to be used.
    protected Map
    This attribute will provide a mechanism by which customers will be able to pass connection information to events to enable further customization.
  • Constructor Summary

    Constructors
    Constructor
    Description
    PUBLIC: A connection policy is used to define how the client session connection should be acquired.
    PUBLIC: A connection policy is used to define how the client session connection should be acquired.
    PUBLIC: A connection policy is used to define how the client session connection should be acquired.
  • Method Summary

    Modifier and Type
    Method
    Description
    INTERNAL: Clone the query
    void
    PUBLIC: A lazy connection only acquires a physical connection when a transaction is started and releases the connection when the transaction completes.
    PUBLIC: Returns exclusive mode.
    PUBLIC: Return the login to use for this connection.
    PUBLIC: Return the pool name or null if not part of a pool.
    ADVANCED: This method will return the collection of custom properties set on the Connection policy.
    PUBLIC: Returns the property associated with the corresponding key.
    boolean
    PUBLIC: Return if a login is used, only one of login and pool can be used.
    boolean
    PUBLIC: Returns true if properties are available on the Connection Policy
    boolean
    PUBLIC: Indicates whether ExclusiveIsolatedClientSession should be created.
    boolean
    PUBLIC: Indicates whether exclusiveMode is Always.
    boolean
    PUBLIC: Indicates whether exclusiveMode is Isolated.
    boolean
    PUBLIC: Return if a lazy connection should be used, a lazy connection only acquire a physical connection when a transaction is started and releases the connection when the transaction completes.
    boolean
    INTERNAL: Return if part of a connection pool.
    boolean
    INTERNAL: Return if part of a connection pool.
    PUBLIC: This method is used to remove a custom property from the Connection Policy.
    void
    PUBLIC: Sets exclusive mode, if null is passed sets the default value.
    void
    setIsLazy(boolean isLazy)
    PUBLIC: Set if a lazy connection should be used, a lazy connection only acquire a physical connection when a transaction is started and releases the connection when the transaction completes.
    void
    setLogin(Login login)
    PUBLIC: Set the login to use for this connection.
    void
    setPoolName(String poolName)
    PUBLIC: Set the pool name or null if not part of a pool.
    void
    setProperty(Object key, Object property)
    PUBLIC: Use this method to set custom properties on the Connection Policy.
    INTERNAL: return a string representation of this ConnectionPolicy
    void
    PUBLIC: A lazy connection only acquires a physical connection when a transaction is started and releases the connection when the transaction completes.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • login

      protected Login login
      The login information used to create a JDBC connection or acquire one from an external pool/data-source. Typically this is constant within a single persistence unit but in some advanced usages users can customize connections for each client session.
    • poolName

      protected String poolName
      Name of the pool to be used. If neither pool name nor login provided then default pool will be used. If no pool name is provided but there's a login then the login is used to create connection which the ClientSession will use.
    • isLazy

      protected boolean isLazy
      Determines if the write/exclusive connection is acquired only when first requested (lazy, this is the default) or immediately when the client session is acquired. After write/exclusive connection is acquired if isLazy is true and exclusiveMode is Transactional then it's held until transaction is committed or rolled back, otherwise until the client session is released.
    • exclusiveMode

      protected ConnectionPolicy.ExclusiveMode exclusiveMode
      This attribute is used by the ServerSession to determine if a client session with an exclusive connection should be built and how the exclusive connection should be used.
    • properties

      protected Map properties
      This attribute will provide a mechanism by which customers will be able to pass connection information to events to enable further customization.
  • Constructor Details

    • ConnectionPolicy

      public ConnectionPolicy()
      PUBLIC: A connection policy is used to define how the client session connection should be acquired.
    • ConnectionPolicy

      public ConnectionPolicy(String poolName)
      PUBLIC: A connection policy is used to define how the client session connection should be acquired.
    • ConnectionPolicy

      public ConnectionPolicy(Login login)
      PUBLIC: A connection policy is used to define how the client session connection should be acquired.
  • Method Details

    • clone

      public Object clone()
      INTERNAL: Clone the query
      Overrides:
      clone in class Object
    • dontUseLazyConnection

      public void dontUseLazyConnection()
      PUBLIC: A lazy connection only acquires a physical connection when a transaction is started and releases the connection when the transaction completes.
    • getLogin

      public Login getLogin()
      PUBLIC: Return the login to use for this connection. Client sessions support using a separate user login for database modification.
    • getPoolName

      public String getPoolName()
      PUBLIC: Return the pool name or null if not part of a pool.
    • getProperties

      public Map getProperties()
      ADVANCED: This method will return the collection of custom properties set on the Connection policy. Note that this will cause the lazy initialization of the HashMap.
    • getProperty

      public Object getProperty(Object object)
      PUBLIC: Returns the property associated with the corresponding key. These properties will be available to connection events.
    • hasLogin

      public boolean hasLogin()
      PUBLIC: Return if a login is used, only one of login and pool can be used.
    • hasProperties

      public boolean hasProperties()
      PUBLIC: Returns true if properties are available on the Connection Policy
    • isExclusiveIsolated

      public boolean isExclusiveIsolated()
      PUBLIC: Indicates whether exclusiveMode is Isolated.
    • isExclusiveAlways

      public boolean isExclusiveAlways()
      PUBLIC: Indicates whether exclusiveMode is Always.
    • isExclusive

      public boolean isExclusive()
      PUBLIC: Indicates whether ExclusiveIsolatedClientSession should be created.
    • isLazy

      public boolean isLazy()
      PUBLIC: Return if a lazy connection should be used, a lazy connection only acquire a physical connection when a transaction is started and releases the connection when the transaction completes.
    • isPooled

      public boolean isPooled()
      INTERNAL: Return if part of a connection pool.
    • isUserDefinedConnection

      public boolean isUserDefinedConnection()
      INTERNAL: Return if part of a connection pool.
    • removeProperty

      public Object removeProperty(Object key)
      PUBLIC: This method is used to remove a custom property from the Connection Policy. This method will return the propery removed. If it was not found then null will be returned.
    • setIsLazy

      public void setIsLazy(boolean isLazy)
      PUBLIC: Set if a lazy connection should be used, a lazy connection only acquire a physical connection when a transaction is started and releases the connection when the transaction completes.
    • setLogin

      public void setLogin(Login login)
      PUBLIC: Set the login to use for this connection. Client sessions support using a separate user login for database modification. Pooled connections must use the pool's login and cannot define their own.
    • setPoolName

      public void setPoolName(String poolName)
      PUBLIC: Set the pool name or null if not part of a pool.
    • setProperty

      public void setProperty(Object key, Object property)
      PUBLIC: Use this method to set custom properties on the Connection Policy. These properties will be available from within connection events but have no effect on the connection directly.
    • getExclusiveMode

      public ConnectionPolicy.ExclusiveMode getExclusiveMode()
      PUBLIC: Returns exclusive mode.
    • setExclusiveMode

      public void setExclusiveMode(ConnectionPolicy.ExclusiveMode exclusiveMode)
      PUBLIC: Sets exclusive mode, if null is passed sets the default value.
    • toString

      public String toString()
      INTERNAL: return a string representation of this ConnectionPolicy
      Overrides:
      toString in class Object
    • useLazyConnection

      public void useLazyConnection()
      PUBLIC: A lazy connection only acquires a physical connection when a transaction is started and releases the connection when the transaction completes.