Class SessionBroker

    • Field Detail

      • sessionNamesByClass

        protected java.util.Map<java.lang.Class,​java.lang.String> sessionNamesByClass
      • sessionsByName

        protected java.util.Map<java.lang.String,​AbstractSession> sessionsByName
      • shouldUseDescriptorAliases

        protected boolean shouldUseDescriptorAliases
    • Constructor Detail

      • SessionBroker

        public SessionBroker()
        PUBLIC: Create and return a session broker. Because a session broker has multiple sessions it does not used a login.
      • SessionBroker

        protected SessionBroker​(java.util.Map sessionNames)
        INTERNAL: Create and return a session broker. Used internally to set the Names by Class from the parent. Reduces garbage.
    • Method Detail

      • acquireClientSessionBroker

        public SessionBroker acquireClientSessionBroker()
        PUBLIC: Return a session broker that behaves as a client session broker. An acquire session broker is done under the covers on each session inside the session broker, and a new broker is returned. NOTE: when finished with the client broker, it should be released.
      • acquireClientSessionBroker

        public SessionBroker acquireClientSessionBroker​(java.util.Map<java.lang.String,​ConnectionPolicy> connectionPolicies,
                                                        java.util.Map mapOfProperties)
        PUBLIC: Return a session broker that behaves as a client session broker. An acquire session broker is done under the covers on each session inside the session broker, and a new broker is returned. NOTE: when finished with the client broker, it should be released.
        Parameters:
        connectionPolicies - maps session name to connectionPolicy to be used for this session;
        mapOfProperties - maps session name to properties to be used for this session.
      • releaseJTSConnection

        public void releaseJTSConnection()
        INTERNAL: Called in the end of beforeCompletion of external transaction sychronization listener. Close the managed sql connection corresponding to the external transaction, if applicable releases accessor.
        Overrides:
        releaseJTSConnection in class DatabaseSessionImpl
      • addDescriptors

        public void addDescriptors​(java.util.Vector descriptors)
                            throws ValidationException
        PUBLIC: You cannot add descriptors to a session broker, you must add them to its session.
        Throws:
        ValidationException
      • basicCommitTransaction

        protected void basicCommitTransaction()
                                       throws DatabaseException
        INTERNAL: Commit the transaction on all child sessions. This assumes that the commit of the transaction will not fail because all of the modification has already taken place and no errors would have occurred.
        Overrides:
        basicCommitTransaction in class AbstractSession
        Throws:
        DatabaseException
      • containsQuery

        public boolean containsQuery​(java.lang.String queryName)
        PUBLIC: Return true if the pre-defined query is defined on the session.
        Specified by:
        containsQuery in interface Session
        Overrides:
        containsQuery in class AbstractSession
      • copySessionBroker

        protected SessionBroker copySessionBroker()
        INTERNAL: Return a copy (not using clone) of a session broker.
      • getAccessors

        public java.util.Collection<Accessor> getAccessors​(Call call,
                                                           AbstractRecord translationRow,
                                                           DatabaseQuery query)
        INTERNAL: Return the low-level database accessors. The database accessor is used for direct database access. The right accessor for this broker will be returned.
        Overrides:
        getAccessors in class AbstractSession
      • getExecutionSession

        public 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 AbstractSession
        Parameters:
        query - may store session name or reference class for brokers case
        Returns:
        a session with a live accessor
      • getQuery

        public DatabaseQuery getQuery​(java.lang.String name,
                                      java.util.Vector arguments,
                                      boolean shouldSearchParent)
        PUBLIC: Return the query from the session pre-defined queries with the given name and argument types. This allows for common queries to be pre-defined, reused and executed by name. This method should be used if the Session has multiple queries with the same name but different arguments. The search order is: for ClientSessionBroker: the broker; it's member ClientSessions (but not their parent ServerSessions); the parent SessionBroker. for ServerSession or DatabaseSession SessionBroker: the broker; it's member ServerSessions (or DatabaseSessions).
        Overrides:
        getQuery in class AbstractSession
        shouldSearchParent - indicates whether parent should be searched if query not found.
        See Also:
        AbstractSession.getQuery(String, List)
      • getSessionForQuery

        protected AbstractSession getSessionForQuery​(DatabaseQuery query)
        INTERNAL: Answers the session to be used for the given query.
      • getSessionNamesByClass

        protected java.util.Map<java.lang.Class,​java.lang.String> getSessionNamesByClass()
        INTERNAL: Return sessions indexed by class, each class can only have one default session.
      • getSessionsByName

        public java.util.Map<java.lang.String,​AbstractSession> getSessionsByName()
        INTERNAL: Return sessions indexed by name.
      • initializeDescriptors

        public void initializeDescriptors()
        INTERNAL: Allow each descriptor to initialize any dependencies on this session. This is done in two passes to allow the inheritance to be resolved first. Normally the descriptors are added before login, then initialized on login. Should not be called on client SessoionBroker
        Overrides:
        initializeDescriptors in class DatabaseSessionImpl
      • initializeIdentityMapAccessor

        public void initializeIdentityMapAccessor()
        INTERNAL: Set up the IdentityMapManager. This method allows subclasses of Session to override the default IdentityMapManager functionality.
        Overrides:
        initializeIdentityMapAccessor in class AbstractSession
      • isBroker

        public boolean isBroker()
        INTERNAL: Returns true if the session is a session Broker.
        Overrides:
        isBroker in class AbstractSession
      • isClientSessionBroker

        public boolean isClientSessionBroker()
        PUBLIC: Return if this session is a client session broker.
      • isServerSessionBroker

        public boolean isServerSessionBroker()
        PUBLIC: Return if this session is a server session broker.
      • loginAndDetectDatasource

        public void loginAndDetectDatasource()
                                      throws DatabaseException
        PUBLIC: Connect to the database using the predefined login. During connection, attempt to auto detect the required database platform. This method can be used in systems where for ease of use developers have EclipseLink autodetect the platform. To be safe, however, the platform should be configured directly. The login must have been assigned when or after creating the session.
        Overrides:
        loginAndDetectDatasource in class DatabaseSessionImpl
        Throws:
        DatabaseException
      • login

        public void login​(java.lang.String userName,
                          java.lang.String password)
                   throws DatabaseException
        PUBLIC: Connect to the database using the predefined login. This connects all of the child sessions and expects that they are in a valid state to be connected.
        Specified by:
        login in interface DatabaseSession
        Overrides:
        login in class DatabaseSessionImpl
        Throws:
        DatabaseException
      • postLogin

        public void postLogin()
        INTERNAL: Rise postLogin events for member sessions and the SessionBroker.
        Overrides:
        postLogin in class DatabaseSessionImpl
      • registerSession

        public void registerSession​(java.lang.String name,
                                    AbstractSession session)
        PUBLIC: Register the session under its name. All of the session's descriptors must have already been registered. DatabaseSession/ServerSession should not be connected and descriptors should not be initialized.
      • registerSession

        public void registerSession​(java.lang.String name,
                                    Session session)
        PUBLIC: Register the session under its name. All of the session's descriptors must have already been registered. DatabaseSession/ServerSession should not be connected and descriptors should not be initialized.
      • release

        public void release()
        PUBLIC: Release the session. This does nothing by default, but allows for other sessions such as the ClientSession to do something.
        Specified by:
        release in interface Session
        Overrides:
        release in class AbstractSession
      • setSessionNameByClass

        protected void setSessionNameByClass​(java.util.HashMap sessionNameByClass)
        INTERNAL: Set sessions indexed by class, each class can only have one default session.
      • setSessionsByName

        public void setSessionsByName​(java.util.Map sessionsByName)
        INTERNAL: Set sessions indexed by name.
      • setSynchronized

        public void setSynchronized​(boolean synched)
        INTERNAL: Set isSynchronized flag to indicate that members of session broker are synchronized. This method should only be called by setSynchronized method of UnitOfWork obtained from either DatabaseSession Broker or ClientSession Broker.
        Overrides:
        setSynchronized in class AbstractSession
      • writesCompleted

        public void writesCompleted()
        INTERNAL: This method notifies the accessor that a particular sets of writes has completed. This notification can be used for such thing as flushing the batch mechanism
        Overrides:
        writesCompleted in class AbstractSession
      • initializeSequencing

        public void initializeSequencing()
        ADVANCED: Creates sequencing object for the session broker. Typically there is no need for the user to call this method - it is called by login() and acquireClientSessionBroker.
        Overrides:
        initializeSequencing in class DatabaseSessionImpl
      • howManySequencingCallbacks

        public int howManySequencingCallbacks()
        INTERNAL: Returns a number of member sessions that require sequencing callback. Always returns 0 if sequencing is not connected.
      • isSequencingCallbackRequired

        public boolean isSequencingCallbackRequired()
        INTERNAL: Indicates whether SequencingCallback is required. Always returns false if sequencing is not connected.
        Overrides:
        isSequencingCallbackRequired in class DatabaseSessionImpl
      • shouldUseDescriptorAliases

        public boolean shouldUseDescriptorAliases()
        PUBLIC: Indicates whether descriptors should use aliasDescriptors map. If aliasDescriptors is used then descriptors' aliases should be unique.
      • setShouldUseDescriptorAliases

        public void setShouldUseDescriptorAliases​(boolean shouldUseDescriptorAliases)
        PUBLIC: Indicates whether descriptors should use aliasDescriptors map. If aliasDescriptors is used then descriptors' aliases should be unique.