Class ServerSession

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, CoreSession<ClassDescriptor,​Login,​org.eclipse.persistence.internal.databaseaccess.Platform,​Project,​SessionEventManager>, CommandProcessor, DatabaseSession, Server, Session

    public class ServerSession
    extends org.eclipse.persistence.internal.sessions.DatabaseSessionImpl
    implements Server
    Implementation of Server INTERNAL: The public interface should be used.

    Purpose: A single session that supports multiple user/clients connection at the same time.

    Description: This session supports a shared session that can be used by multiple users or clients in a three-tiered application. It brokers client sessions to allow read and write access through a unified object cache. The server session uses a single connection pool by default, but allows multiple connection pools and separate read/write pools to be configured. All changes to objects and the database must be done through a unit of work acquired from the client session, this allows the changes to occur in a transactional object space and under a exclusive database connection.

    Responsibilities:

    • Connection pooling.
    • Reading objects and maintaining the object cache.
    • Brokering client sessions.
    • Requiring the UnitOfWork to be used for modification.
    See Also:
    Server, ClientSession, UnitOfWork, Serialized Form
    • Field Detail

      • connectionPools

        protected java.util.Map<java.lang.String,​ConnectionPool> connectionPools
      • numberOfNonPooledConnectionsUsed

        protected int numberOfNonPooledConnectionsUsed
      • maxNumberOfNonPooledConnections

        protected int maxNumberOfNonPooledConnections
    • Constructor Detail

      • ServerSession

        public ServerSession​(Login login,
                             int minNumberOfPooledConnection,
                             int maxNumberOfPooledConnection)
        INTERNAL: Create and return a new server session.
        See Also:
        Project.createServerSession(int, int)
      • ServerSession

        public ServerSession​(Project project,
                             int minNumberOfPooledConnection,
                             int maxNumberOfPooledConnection)
        INTERNAL: Create and return a new server session.
        See Also:
        Project.createServerSession(int, int)
      • ServerSession

        public ServerSession​(Project project,
                             int initialNumberOfPooledConnection,
                             int minNumberOfPooledConnection,
                             int maxNumberOfPooledConnection)
        INTERNAL: Create and return a new server session.
        See Also:
        Project.createServerSession(int, int, int)
      • ServerSession

        public ServerSession​(Project project,
                             int minNumberOfPooledConnection,
                             int maxNumberOfPooledConnection,
                             Login readLogin)
        INTERNAL: Create and return a new server session.
        Parameters:
        project - the project associated with this session
        minNumberOfPooledConnection - the minimum number of connections in the pool
        maxNumberOfPooledConnection - the maximum number of connections in the pool
        readLogin - the login used to create the read connection pool
        See Also:
        Project.createServerSession(int, int)
      • ServerSession

        public ServerSession​(Project project,
                             ConnectionPolicy defaultConnectionPolicy,
                             int initialNumberOfPooledConnections,
                             int minNumberOfPooledConnections,
                             int maxNumberOfPooledConnections,
                             Login readLogin,
                             Login sequenceLogin)
        INTERNAL: Create and return a new server session.

        Configure the initial, min and max number of connections for the default pool.

        Configure the default connection policy to be used. This policy is used on the "acquireClientSession()" protocol.

        Use the login from the project for the write pool. Use the passed in login for the read pool, if specified, or the project login if not. Use the sequenceLogin, if specified, for creating a connection pool to be used by sequencing through SequencingConnectionHandler sequenceLogin *MUST*:
        1. specify *NON-JTS* connections (such as NON_JTS driver or read-only datasource);
        2. sequenceLogin.shouldUseExternalTransactionController()==false

        Parameters:
        project - the project associated with this session
        defaultConnectionPolicy - the default connection policy to be used
        initialNumberOfPooledConnections - the minimum number of connections in the pool
        minNumberOfPooledConnections - the minimum number of connections in the pool
        maxNumberOfPooledConnections - the maximum number of connections in the pool
        readLogin - the login used to create the read connection pool
        sequenceLogin - the login used to create a connection pool for sequencing
        See Also:
        Project.createServerSession(int, int)
    • Method Detail

      • acquireClientSession

        public ClientSession acquireClientSession()
                                           throws DatabaseException
        PUBLIC: Return a client session for this server session. Each user/client connected to this server session must acquire there own client session to communicate to the server through. This method allows for a client session to be acquired sharing the same login as the server session.
        Specified by:
        acquireClientSession in interface Server
        Throws:
        DatabaseException
      • acquireClientSession

        public ClientSession acquireClientSession​(java.util.Map properties)
                                           throws DatabaseException
        PUBLIC: Return a client session for this server session. Each user/client connected to this server session must acquire there own client session to communicate to the server through. This method allows for a client session to be acquired sharing the same login as the server session. The properties set into the client session at construction time, before postAcquireClientSession is risen.
        Throws:
        DatabaseException
      • acquireClientSession

        public ClientSession acquireClientSession​(java.lang.String poolName)
                                           throws DatabaseException
        PUBLIC: Return a client session for this server session. Each user/client connected to this server session must acquire there own client session to communicate to the server through. This method allows for a client session to be acquired sharing its connection from a pool of connection allocated on the server session. By default this uses a lazy connection policy.
        Specified by:
        acquireClientSession in interface Server
        Throws:
        DatabaseException
      • acquireClientSession

        public ClientSession acquireClientSession​(java.lang.String poolName,
                                                  java.util.Map properties)
                                           throws DatabaseException
        PUBLIC: Return a client session for this server session. Each user/client connected to this server session must acquire there own client session to communicate to the server through. This method allows for a client session to be acquired sharing its connection from a pool of connection allocated on the server session. By default this uses a lazy connection policy. The properties set into the client session at construction time, before postAcquireClientSession is risen.
        Throws:
        DatabaseException
      • acquireClientSession

        public ClientSession acquireClientSession​(Login login)
                                           throws DatabaseException
        PUBLIC: Return a client session for this server session. Each user/client connected to this server session must acquire there own client session to communicate to the server through. The client must provide its own login to use, and the client session returned will have its own exclusive database connection. This connection will be used to perform all database modification for all units of work acquired from the client session. By default this does not use a lazy connection policy.
        Specified by:
        acquireClientSession in interface Server
        Throws:
        DatabaseException
      • acquireClientSession

        public ClientSession acquireClientSession​(Login login,
                                                  java.util.Map properties)
                                           throws DatabaseException
        PUBLIC: Return a client session for this server session. Each user/client connected to this server session must acquire there own client session to communicate to the server through. The client must provide its own login to use, and the client session returned will have its own exclusive database connection. This connection will be used to perform all database modification for all units of work acquired from the client session. By default this does not use a lazy connection policy. The properties set into the client session at construction time, before postAcquireClientSession is risen.
        Throws:
        DatabaseException
      • acquireUnitOfWork

        public org.eclipse.persistence.internal.sessions.UnitOfWorkImpl acquireUnitOfWork()
        PUBLIC: Return a unit of work for this session. The unit of work is an object level transaction that allows a group of changes to be applied as a unit. First acquire a client session as server session does not allow direct units of work.
        Specified by:
        acquireUnitOfWork in interface Session
        Overrides:
        acquireUnitOfWork in class org.eclipse.persistence.internal.sessions.AbstractSession
        See Also:
        UnitOfWorkImpl
      • addConnectionPool

        public void addConnectionPool​(java.lang.String poolName,
                                      Login login,
                                      int minNumberOfConnections,
                                      int maxNumberOfConnections)
                               throws ValidationException
        PUBLIC: Add the connection pool. Connections are pooled to share and restrict the number of database connections.
        Specified by:
        addConnectionPool in interface Server
        Throws:
        ValidationException
      • addConnectionPool

        public void addConnectionPool​(ConnectionPool pool)
        PUBLIC: Connection are pooled to share and restrict the number of database connections.
        Specified by:
        addConnectionPool in interface Server
      • allocateReadConnection

        public org.eclipse.persistence.internal.databaseaccess.Accessor allocateReadConnection()
        INTERNAL: Return a read connection from the read pool. Note that depending on the type of pool this may be a shared or exclusive connection. Each query execution is assigned a read connection.
      • connect

        public void connect()
        INTERNAL: Startup the server session, also startup all of the connection pools.
        Overrides:
        connect in class org.eclipse.persistence.internal.sessions.DatabaseSessionImpl
      • disconnect

        public void disconnect()
                        throws DatabaseException
        INTERNAL: Disconnect the accessor only.
        Overrides:
        disconnect in class org.eclipse.persistence.internal.sessions.DatabaseSessionImpl
        Throws:
        DatabaseException
      • getAccessors

        public java.util.List<org.eclipse.persistence.internal.databaseaccess.Accessor> getAccessors​(Call call,
                                                                                                     org.eclipse.persistence.internal.sessions.AbstractRecord translationRow,
                                                                                                     DatabaseQuery query)
        INTERNAL: Return the connections to use for the query execution.
        Overrides:
        getAccessors in class org.eclipse.persistence.internal.sessions.AbstractSession
      • executeCall

        public java.lang.Object executeCall​(Call call,
                                            org.eclipse.persistence.internal.sessions.AbstractRecord translationRow,
                                            DatabaseQuery query)
                                     throws DatabaseException
        INTERNAL: Execute the call on the correct connection accessor. By default the server session executes calls using is read connection pool. A connection is allocated for the execution of the query, then released back to the pool. If partitioning is used the partition policy can use a different connection pool, or even execute the call on multiple connections.
        Overrides:
        executeCall in class org.eclipse.persistence.internal.sessions.AbstractSession
        Throws:
        DatabaseException
      • releaseConnectionAfterCall

        public void releaseConnectionAfterCall​(DatabaseQuery query)
        INTERNAL: Release (if required) connection after call.
        Overrides:
        releaseConnectionAfterCall in class org.eclipse.persistence.internal.sessions.AbstractSession
        Parameters:
        query -
      • executeQuery

        public java.lang.Object executeQuery​(DatabaseQuery query,
                                             java.util.List argumentValues)
                                      throws DatabaseException
        PUBLIC: Return the results from executing the database query. The query arguments are passed in as a List of argument values in the same order as the query arguments.
        Specified by:
        executeQuery in interface Session
        Overrides:
        executeQuery in class org.eclipse.persistence.internal.sessions.AbstractSession
        Throws:
        DatabaseException
      • getConnectionPools

        public java.util.Map<java.lang.String,​ConnectionPool> getConnectionPools()
        INTERNAL: Connection are pooled to share and restrict the number of database connections.
      • getDefaultConnectionPolicy

        public ConnectionPolicy getDefaultConnectionPolicy()
        PUBLIC: The default connection policy is used by default by the acquireClientConnection() protocol. By default it is a connection pool with min 5 and max 10 lazy pooled connections.
        Specified by:
        getDefaultConnectionPolicy in interface Server
      • getExecutionSession

        public org.eclipse.persistence.internal.sessions.AbstractSession getExecutionSession​(DatabaseQuery query)
        INTERNAL: Gets the session which this query will be executed on. Generally will be called immediately before the call is translated, which is immediately before session.executeCall.

        Since the execution session also knows the correct datasource platform to execute on, it is often used in the mappings where the platform is needed for type conversion, or where calls are translated.

        Is also the session with the accessor. Will return a ClientSession if it is in transaction and has a write connection.

        Overrides:
        getExecutionSession in class org.eclipse.persistence.internal.sessions.AbstractSession
        Parameters:
        query - may store session name or reference class for brokers case
        Returns:
        a session with a live accessor
      • getMaxNumberOfNonPooledConnections

        public int getMaxNumberOfNonPooledConnections()
        PUBLIC: Return the number of non-pooled database connections allowed. This can be enforced to make up for the resource limitation of most JDBC drivers and database clients. By default this is 50.
        Specified by:
        getMaxNumberOfNonPooledConnections in interface Server
      • getNumberOfNonPooledConnectionsUsed

        public int getNumberOfNonPooledConnectionsUsed()
        INTERNAL: Return the current number of non-pooled connections in use.
      • getReadLogin

        protected Login getReadLogin()
        INTERNAL: Return the login for the read connection. Used by the platform autodetect feature
        Overrides:
        getReadLogin in class org.eclipse.persistence.internal.sessions.DatabaseSessionImpl
      • isConnected

        public boolean isConnected()
        PUBLIC: Return if this session has been connected to the database.
        Specified by:
        isConnected in interface Session
        Overrides:
        isConnected in class org.eclipse.persistence.internal.sessions.AbstractSession
      • isServerSession

        public boolean isServerSession()
        INTERNAL: Return if this session is a server session.
        Specified by:
        isServerSession in interface Session
        Overrides:
        isServerSession in class org.eclipse.persistence.internal.sessions.AbstractSession
      • logout

        public void logout()
        PUBLIC: Shutdown the server session, also shutdown all of the connection pools.
        Specified by:
        logout in interface DatabaseSession
        Overrides:
        logout in class org.eclipse.persistence.internal.sessions.DatabaseSessionImpl
      • releaseReadConnection

        public void releaseReadConnection​(org.eclipse.persistence.internal.databaseaccess.Accessor connection)
        INTERNAL: Release the read connection back into the read pool.
        Overrides:
        releaseReadConnection in class org.eclipse.persistence.internal.sessions.AbstractSession
      • setConnectionPools

        public void setConnectionPools​(java.util.Map<java.lang.String,​ConnectionPool> connectionPools)
        INTERNAL: Connection are pooled to share and restrict the number of database connections.
      • setDefaultConnectionPolicy

        public void setDefaultConnectionPolicy​(ConnectionPolicy defaultConnectionPolicy)
        PUBLIC: The default connection policy is used by default by the acquireClientConnection() protocol. By default it is a connection pool with min 5 and max 10 lazy pooled connections.
        Specified by:
        setDefaultConnectionPolicy in interface Server
      • setDefaultConnectionPool

        public void setDefaultConnectionPool()
        PUBLIC: Creates and adds "default" connection pool using default parameter values
      • setMaxNumberOfNonPooledConnections

        public void setMaxNumberOfNonPooledConnections​(int maxNumberOfNonPooledConnections)
        PUBLIC: Set the number of non-pooled database connections allowed. This can be enforced to make up for the resource limitation of most JDBC drivers and database clients. By default this is 50.
        Specified by:
        setMaxNumberOfNonPooledConnections in interface Server
      • setNumberOfNonPooledConnectionsUsed

        public void setNumberOfNonPooledConnectionsUsed​(int numberOfNonPooledConnectionsUsed)
        INTERNAL: Set the current number of connections being used that are not from a connection pool.
        Parameters:
        numberOfNonPooledConnectionsUsed -
      • setReadConnectionPool

        public void setReadConnectionPool​(ConnectionPool readConnectionPool)
        PUBLIC: Set the read connection pool. The read connection pool handles allocating connection for read queries. If external connection pooling is used, an external connection pool will be used by default.
        Specified by:
        setReadConnectionPool in interface Server
      • setReadConnectionPool

        public void setReadConnectionPool​(Login readLogin)
                                   throws ValidationException
        PUBLIC: Creates and sets the new read connection pool. By default the same connection pool is used for read and write, this allows a different login/pool to be used for reading. By default 32 min/max connections are used in the pool with an initial of 1 connection.
        Throws:
        ValidationException
      • setSynchronized

        public void setSynchronized​(boolean synched)
        INTERNAL: Set isSynchronized flag to indicate that this session is synchronized. The method is ignored on ServerSession and should never be called.
        Overrides:
        setSynchronized in class org.eclipse.persistence.internal.sessions.AbstractSession
      • updateStandardConnectionPools

        protected void updateStandardConnectionPools()
        INTERNAL: Updates standard connection pools. Should not be called after session is connected. This is needed in case of pools' logins been altered after the pool has been created (SessionManager does that) All pools should be re-created in case their type doesn't match their login. In addition, sequenceConnectionPool should be removed in case its login has shouldUseExternaltransactionController()==true (see setSequenceConnectionPool)
      • useReadConnectionPool

        public void useReadConnectionPool​(int minNumerOfConnections,
                                          int maxNumerOfConnections)
        PUBLIC: Configure the read connection pool. The read connection pool handles allocating connection for read queries. If external connection pooling is used, an external connection pool will be used by default. This API uses a ReadConnectionPool which shares read connections. Some JDBC drivers may not support concurrent access to a connection, or have poor concurrency, so an exclusive read connection pool is normally recommended.
        Specified by:
        useReadConnectionPool in interface Server
        maxNumerOfConnections - As multiple readers can use the same connection concurrently fewer connections are needed.
        See Also:
        useExclusiveReadConnectionPool(int, int)
      • useReadConnectionPool

        public void useReadConnectionPool​(int initialNumerOfConnections,
                                          int minNumerOfConnections,
                                          int maxNumerOfConnections)
        PUBLIC: Configure the read connection pool. The read connection pool handles allocating connection for read queries. If external connection pooling is used, an external connection pool will be used by default. This API uses a ReadConnectionPool which shares read connections. Some JDBC drivers may not support concurrent access to a connection, or have poor concurrency, so an exclusive read connection pool is normally recommended.
        Specified by:
        useReadConnectionPool in interface Server
        Parameters:
        initialNumerOfConnections - connections connected at startup
        minNumerOfConnections - connections that are pooled
        maxNumerOfConnections - As multiple readers can use the same connection concurrently fewer connections are needed.
        See Also:
        useExclusiveReadConnectionPool(int, int, int)
      • validateQuery

        public void validateQuery​(DatabaseQuery query)
        INTERNAL: This method will be used to update the query with any settings required For this session. It can also be used to validate execution.
        Overrides:
        validateQuery in class org.eclipse.persistence.internal.sessions.AbstractSession
      • getSequencingServer

        public org.eclipse.persistence.internal.sequencing.SequencingServer getSequencingServer()
        INTERNAL: Return SequencingServer object owned by the session.