Class DatabaseSessionImpl

All Implemented Interfaces:
Serializable, Cloneable, CoreSession<ClassDescriptor,Login,Platform,Project,SessionEventManager>, CommandProcessor, DatabaseSession, Session
Direct Known Subclasses:
DistributedSession, ServerSession, SessionBroker

public class DatabaseSessionImpl extends AbstractSession implements DatabaseSession
Implementation of org.eclipse.persistence.sessions.DatabaseSession The public interface should be used.
See Also:
  • Field Details

    • databaseEventListener

      protected DatabaseEventListener databaseEventListener
      Database event listener, this allows database events to invalidate the cache.
    • sequencingHome

      protected SequencingHome sequencingHome
      INTERNAL: sequencingHome for this session.
    • serverPlatform

      protected ServerPlatform serverPlatform
      Used to store the server platform that handles server-specific functionality for Oc4j, WLS, etc.
    • tuner

      protected SessionTuner tuner
      Stores the tuner used to tune the configuration of this session.
    • connectedTime

      protected long connectedTime
      INTERNAL: connectedTime indicates the exact time this session was logged in.
    • isLoggedIn

      protected volatile boolean isLoggedIn
      INTERNAL Indicate if this session is logged in.
  • Constructor Details

    • DatabaseSessionImpl

      public DatabaseSessionImpl()
      INTERNAL: Create and return a new default database session. Used for EJB SessionManager to instantiate a database session
    • DatabaseSessionImpl

      public DatabaseSessionImpl(Login login)
      PUBLIC: Create and return a new session. By giving the login information on creation this allows the session to initialize itself to the platform given in the login. This constructor does not return a connected session. To connect the session to the database login() must be sent to it. The login(userName, password) method may also be used to connect the session, this allows for the user name and password to be given at login but for the other database information to be provided when the session is created.
    • DatabaseSessionImpl

      public DatabaseSessionImpl(Project project)
      PUBLIC: Create and return a new session. This constructor does not return a connected session. To connect the session to the database login() must be sent to it. The login(userName, password) method may also be used to connect the session, this allows for the user name and password to be given at login but for the other database information to be provided when the session is created.
  • Method Details

    • setSequencingHome

      protected void setSequencingHome(SequencingHome sequencingHome)
      INTERNAL: Set the SequencingHome object used by the session.
    • getSequencingHome

      protected SequencingHome getSequencingHome()
      INTERNAL: Return SequencingHome which used to obtain all sequence-related interfaces for DatabaseSession
    • isLoggedIn

      public boolean isLoggedIn()
      INTERNAL: Return if the session was logged in. This may slight differ to isConnected which asks the JDBC Connection if it is connected.
    • getDatabaseEventListener

      public DatabaseEventListener getDatabaseEventListener()
      Return the database event listener, this allows database events to invalidate the cache.
      Specified by:
      getDatabaseEventListener in interface DatabaseSession
    • setDatabaseEventListener

      public void setDatabaseEventListener(DatabaseEventListener databaseEventListener)
      PUBLIC: Set the database event listener, this allows database events to invalidate the cache.
      Specified by:
      setDatabaseEventListener in interface DatabaseSession
    • setDatasourceAndInitialize

      public void setDatasourceAndInitialize() throws DatabaseException
      INTERNAL: Issue any pre connect and post connect without an actual connection to the database. Descriptors are initialized in postConnectDatasource and are used in DDL generation. This will look to set the schema platform via the JPA 2.1 properties or through a detection on the connection before DDL generation.
      Throws:
      DatabaseException
    • setOrDetectDatasource

      protected void setOrDetectDatasource(boolean throwException)
      INTERNAL: Will set the platform from specified schema generation properties or by detecting it through the connection (if one is available). Any connection that is open for detection is closed before this method returns.
      Parameters:
      throwException - - set to true if the caller cares to throw exceptions, false to swallow them.
    • getSequencingControl

      public SequencingControl getSequencingControl()
      PUBLIC: Return SequencingControl which used for sequencing setup and customization including management of sequencing preallocation.
      Specified by:
      getSequencingControl in interface DatabaseSession
    • getSequencing

      public Sequencing getSequencing()
      PUBLIC: Return the Sequencing object used by the session.
      Overrides:
      getSequencing in class AbstractSession
    • isSequencingCallbackRequired

      public boolean isSequencingCallbackRequired()
      INTERNAL: Indicates whether SequencingCallback is required. Always returns false if sequencing is not connected.
    • initializeSequencing

      public void initializeSequencing()
      INTERNAL: Creates sequencing object
    • addDescriptorsToSequencing

      public void addDescriptorsToSequencing(Collection<ClassDescriptor> descriptors)
      INTERNAL: If sequencing is connected then initializes sequences referenced by the passed descriptors, otherwise connects sequencing.
      Parameters:
      descriptors - class descriptors
    • releaseJTSConnection

      public void releaseJTSConnection()
      INTERNAL: Called in the end of beforeCompletion of external transaction synchronization listener. Close the managed sql connection corresponding to the external transaction.
      Overrides:
      releaseJTSConnection in class AbstractSession
    • addDescriptor

      public void addDescriptor(ClassDescriptor descriptor)
      PUBLIC: Add the descriptor to the session. All persistent classes must have a descriptor registered for them with the session. It is best to add the descriptors before login, if added after login the order in which descriptors are added is dependent on inheritance and references unless the addDescriptors method is used.
      Specified by:
      addDescriptor in interface DatabaseSession
      See Also:
    • addDescriptors

      public void addDescriptors(Collection descriptors)
      PUBLIC: Add the descriptors to the session. All persistent classes must have a descriptor registered for them with the session. This method allows for a batch of descriptors to be added at once so that EclipseLink can resolve the dependencies between the descriptors and perform initialization optimally.
      Specified by:
      addDescriptors in interface DatabaseSession
      Parameters:
      descriptors - The descriptors to be added to the session and project.
    • addDescriptors

      public void addDescriptors(Project project)
      PUBLIC: Add the descriptors to the session from the Project. This can be used to combine the descriptors from multiple projects into a single session. This can be called after the session has been connected as long as there are no external dependencies.
      Specified by:
      addDescriptors in interface DatabaseSession
    • addSequence

      public void addSequence(Sequence sequence)
      PUBLIC: Add the sequence to the session. Allows to add a new sequence to the session even if the session is connected. If the session is connected then the sequence is added only if there is no sequence with the same name already in use. Call this method before addDescriptor(s) if need to add new descriptor with a new non-default sequence to connected session.
      Specified by:
      addSequence in interface DatabaseSession
      See Also:
    • connect

      public void connect() throws DatabaseException
      INTERNAL: Connect the session only.
      Throws:
      DatabaseException
    • disconnect

      public void disconnect() throws DatabaseException
      INTERNAL: Disconnect the accessor only.
      Throws:
      DatabaseException
    • getServerPlatform

      public ServerPlatform getServerPlatform()
      PUBLIC: Answer the server platform to handle server specific behavior for WLS, Oc4j, etc. If the user wants a different external transaction controller class or to provide some different behavior than the provided ServerPlatform(s), we recommend subclassing org.eclipse.persistence.platform.server.ServerPlatformBase (or a subclass), and overriding: ServerPlatformBase.getExternalTransactionControllerClass() ServerPlatformBase.registerMBean() ServerPlatformBase.unregisterMBean() for the desired behavior.
      Specified by:
      getServerPlatform in interface DatabaseSession
      Specified by:
      getServerPlatform in interface Session
      Overrides:
      getServerPlatform in class AbstractSession
      See Also:
    • setServerPlatform

      public void setServerPlatform(ServerPlatform newServerPlatform)
      PUBLIC: Set the server platform to handle server specific behavior for WLS, Oc4j, etc This is not permitted after the session is logged in. If the user wants a different external transaction controller class or to provide some different behavior than the provided ServerPlatform(s), we recommend subclassing org.eclipse.persistence.platform.server.ServerPlatformBase (or a subclass), and overriding: ServerPlatformBase.getExternalTransactionControllerClass() ServerPlatformBase.registerMBean() ServerPlatformBase.unregisterMBean() for the desired behavior.
      Specified by:
      setServerPlatform in interface DatabaseSession
      See Also:
    • finalize

      protected void finalize() throws DatabaseException
      INTERNAL: Logout in case still connected.
      Overrides:
      finalize in class Object
      Throws:
      DatabaseException
    • getPlatform

      public DatabasePlatform getPlatform()
      INTERNAL: Return the database platform currently connected to. The platform is used for database specific behavior. NOTE: this must only be used for relational specific usage, it will fail for non-relational datasources.
      Specified by:
      getPlatform in interface Session
      Overrides:
      getPlatform in class AbstractSession
    • getDatasourcePlatform

      public Platform getDatasourcePlatform()
      INTERNAL: Return the database platform currently connected to. The platform is used for database specific behavior.
      Specified by:
      getDatasourcePlatform in interface CoreSession<ClassDescriptor,Login,Platform,Project,SessionEventManager>
      Specified by:
      getDatasourcePlatform in interface Session
      Overrides:
      getDatasourcePlatform in class AbstractSession
    • getPlatform

      public Platform getPlatform(Class<?> domainClass)
      INTERNAL: Return the database platform currently connected to for specified class. The platform is used for database specific behavior.
      Overrides:
      getPlatform in class AbstractSession
    • initializeDescriptorIfSessionAlive

      public void initializeDescriptorIfSessionAlive(ClassDescriptor descriptor)
      INTERNAL: A descriptor may have been added after the session is logged in. In this case the descriptor must be allowed to initialize any dependencies on this session. Normally the descriptors are added before login, then initialized on login.
    • 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.
    • initializeDescriptors

      public void initializeDescriptors(Map descriptors)
      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. The descriptors session must be used, not the broker. Sequencing is (re)initialized: disconnected (if has been already connected), then connected.
    • initializeDescriptors

      public void initializeDescriptors(Collection descriptors)
    • initializeDescriptors

      public void initializeDescriptors(Map descriptors, boolean shouldInitializeSequencing)
      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. The descriptors session must be used, not the broker. If shouldInitializeSequencing parameter is true then sequencing is (re)initialized: disconnected (if has been connected), then connected. If shouldInitializeSequencing parameter is false then if sequencing has been already connected, then it stays connected: only the new sequences used by the passed descriptors are initialized; otherwise, if sequencing has NOT been connected then it is connected (just like in shouldInitializeSequencing==true case); disconnected (if has been connected), then connected.
    • initializeDescriptors

      public void initializeDescriptors(Collection descriptors, boolean shouldInitializeSequencing)
    • isDatabaseSession

      public boolean isDatabaseSession()
      INTERNAL: Return if this session is a database session.
      Specified by:
      isDatabaseSession in interface Session
      Overrides:
      isDatabaseSession in class AbstractSession
    • isProtectedSession

      public boolean isProtectedSession()
      PUBLIC: Returns true if Protected Entities should be built within this session
      Overrides:
      isProtectedSession in class AbstractSession
    • getReadLogin

      protected Login getReadLogin()
      INTERNAL: Return the login for the read connection. Used by the platform autodetect feature
    • 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.
      Throws:
      DatabaseException
    • login

      public void login() throws DatabaseException
      PUBLIC: Connect to the database using the predefined login. The login must have been assigned when or after creating the session.
      Specified by:
      login in interface DatabaseSession
      Throws:
      DatabaseException
      See Also:
    • preConnectDatasource

      protected void preConnectDatasource()
      INTERNAL: This method includes all of the code that is issued before the datasource is connected to.
    • postConnectDatasource

      protected void postConnectDatasource()
      INTERNAL: This method includes all of the code that is issued after the datasource is connected to.
    • postLogin

      public void postLogin()
      INTERNAL: Rise postLogin event.
    • login

      public void login(String userName, String password) throws DatabaseException
      PUBLIC: Connect to the database using the given user name and password. The additional login information must have been preset in the session's login attribute. This is the login that should be used if each user has their own id, but all users share the same database configuration.
      Specified by:
      login in interface DatabaseSession
      Throws:
      DatabaseException
    • login

      public void login(Login login) throws DatabaseException
      PUBLIC: Connect to the database using the given login. The login may also the preset and the login() protocol called. This is the login should only be used if each user has their own database configuration.
      Specified by:
      login in interface DatabaseSession
      Throws:
      DatabaseException
    • logout

      public void logout() throws DatabaseException
      PUBLIC: Disconnect from the database.
      Specified by:
      logout in interface DatabaseSession
      Throws:
      EclipseLinkException - if a transaction is active, you must rollback any active transaction before logout.
      DatabaseException - the database will also raise an error if their is an active transaction, or a general error occurs.
    • initializeConnectedTime

      public void initializeConnectedTime()
      PUBLIC: Initialize the time that this session got connected. This can help determine how long a session has been connected.
    • getConnectedTime

      public long getConnectedTime()
      PUBLIC: Answer the time that this session got connected. This can help determine how long a session has been connected.
    • writeAllObjects

      public void writeAllObjects(Collection domainObjects) throws DatabaseException, OptimisticLockException
      PUBLIC: Write all of the objects and all of their privately owned parts in the database. The objects will be committed through a single transaction.
      Specified by:
      writeAllObjects in interface DatabaseSession
      Throws:
      DatabaseException - if an error occurs on the database, these include constraint violations, security violations and general database errors.
      OptimisticLockException - if the object's descriptor is using optimistic locking and the object has been updated or deleted by another user since it was last read.
    • writeAllObjects

      public void writeAllObjects(Vector domainObjects) throws DatabaseException, OptimisticLockException
      PUBLIC: Write all of the objects and all of their privately owned parts in the database. The objects will be committed through a single transaction.
      Throws:
      DatabaseException - if an error occurs on the database, these include constraint violations, security violations and general database errors.
      OptimisticLockException - if the object's descriptor is using optimistic locking and the object has been updated or deleted by another user since it was last read.
    • retryQuery

      public Object retryQuery(DatabaseQuery query, AbstractRecord row, DatabaseException databaseException, int retryCount, AbstractSession executionSession)
      INTERNAL: A query execution failed due to an invalid query. Re-connect and retry the query.
      Overrides:
      retryQuery in class AbstractSession
    • getTuner

      public SessionTuner getTuner()
      Return the tuner used to tune the configuration of this session.
    • setTuner

      public void setTuner(SessionTuner tuner)
      Set the tuner used to tune the configuration of this session.