Top Description Methods
org.eclipse.persistence.sessions

public Interface DatabaseSession

extends Session
Known Direct Subinterfaces
org.eclipse.persistence.sessions.server.Server
Known Direct Implementers
org.eclipse.persistence.internal.sessions.DatabaseSessionImpl
Imports
java.util.*, org.eclipse.persistence.exceptions.*, org.eclipse.persistence.descriptors.ClassDescriptor, org.eclipse.persistence.platform.database.events.DatabaseEventListener, org.eclipse.persistence.platform.server.ServerPlatform, org.eclipse.persistence.sequencing.Sequence, .SequencingControl, org.eclipse.persistence.sessions.coordination.CommandManager

Purpose: Add login and configuration API to that of Session. This interface is to be used during the creation and login of the session only. The Session interface should be used after login for normal reading/writing.

Method Summary

Modifier and TypeMethod and Description
public void
addDescriptor(ClassDescriptor descriptor)

PUBLIC: Add the descriptor to the session.

public void
addDescriptors(Collection<E> descriptors)

PUBLIC: Add the descriptors to the session.

public void
addDescriptors(Project project)

PUBLIC: Add the descriptors to the session from the Project.

public void
addSequence(Sequence sequence)

PUBLIC: Add the sequence to the session.

public void
beginTransaction()

PUBLIC: Begin a transaction on the database.

public void
commitTransaction()

PUBLIC: Commit the active database transaction.

public void
deleteAllObjects(Collection<E> domainObjects)

PUBLIC: delete all of the objects and all of their privately owned parts in the database.

public Object
deleteObject(Object domainObject)

PUBLIC: Delete the object and all of its privately owned parts from the database.

public CommandManager

Returns:

The CommandManager instance that controls the remote command service for this session.
getCommandManager
()

ADVANCED: Return the CommandManager that allows this session to act as a CommandProcessor and receive or propagate commands from/to the EclipseLink cluster.

public DatabaseEventListener
getDatabaseEventListener()

Return the database event listener, this allows database events to invalidate the cache.

public SequencingControl
getSequencingControl()

PUBLIC: Return SequencingControl which used for sequencing setup and customization including management of sequencing preallocation.

public ServerPlatform
getServerPlatform()

Redeclares org.eclipse.persistence.sessions.Session.getServerPlatform.

PUBLIC: Answer the server platform defining server-specific behavior for the receiver (Oc4j, WLS, ...).
public Object
insertObject(Object domainObject)

PUBLIC: Insert the object and all of its privately owned parts into the database.

public boolean
isInTransaction()

PUBLIC: Return if the session is currently in the progress of a database transaction.

public void
login()

PUBLIC: Connect to the database using the predefined login.

public void
login(String userName, String password)

PUBLIC: Connect to the database using the given user name and password.

public void
login(Login login)

PUBLIC: Connect to the database using the given login.

public void
logout()

PUBLIC: Disconnect from the database.

public Object
refreshAndLockObject(Object object)

PUBLIC: Refresh the attributes of the object and of all of its private parts from the database.

public Object
refreshAndLockObject(Object object, short lockMode)

PUBLIC: Refresh the attributes of the object and of all of its private parts from the database.

public void
rollbackTransaction()

PUBLIC: Rollback the active database transaction.

public void
setCommandManager(CommandManager
The CommandManager instance to control the remote command service for this session.
commandManager
)

ADVANCED: Set the CommandManager that allows this session to act as a CommandProcessor and receive or propagate commands from/to the EclipseLink cluster.

public void
setDatabaseEventListener(DatabaseEventListener databaseEventListener)

PUBLIC: Set the database event listener, this allows database events to invalidate the cache.

public void
setDatasourceLogin(Login login)

PUBLIC: Set the login.

public void
public void
setLogin(Login login)

PUBLIC: Set the login.

public void
setServerPlatform(ServerPlatform newServerPlatform)

PUBLIC: Set the server platform defining server-specific behavior for the receiver (Oc4j, WLS, ...

public void
setShouldPropagateChanges(boolean
If true (and the CommandManager is set) then propagation will occur.
choice
)

ADVANCED: Set if cache changes should be propagated to other sessions or applications in a EclipseLink cluster through the Remote Command Manager mechanism.

public boolean

Returns:

true if propagation is set to occur, false if not.
shouldPropagateChanges
()

ADVANCED: Return whether changes should be propagated to other sessions or applications in a EclipseLink cluster through the Remote Command Manager mechanism.

public Object
updateObject(Object domainObject)

PUBLIC: Update the object and all of its privately owned parts in the database.

public void
writeAllObjects(Collection<E> domainObjects)

PUBLIC: Write all of the objects and all of their privately owned parts in the database.

public Object
writeObject(Object domainObject)

PUBLIC: Write the object and all of its privately owned parts in the database.

Inherited from org.eclipse.persistence.sessions.Session:
acquireHistoricalSessionacquireUnitOfWorkacquireUnitOfWorkaddJPAQueryaddQueryclearIntegrityCheckerclearProfilecontainsQuerycopycopydoesObjectExistdontLogMessagesexecuteNonSelectingCallexecuteNonSelectingSQLexecuteQueryexecuteQueryexecuteQueryexecuteQueryexecuteQueryexecuteQueryexecuteQueryexecuteQueryexecuteQueryexecuteQueryexecuteQueryexecuteQueryexecuteSelectingCallexecuteSQLgetActiveSessiongetActiveUnitOfWorkgetAsOfClausegetClassDescriptorgetClassDescriptorgetClassDescriptorForAliasgetDatasourceLogingetDatasourcePlatformgetDefaultReferenceModegetDescriptorgetDescriptorgetDescriptorForAliasgetDescriptorsgetEventManagergetExceptionHandlergetExternalTransactionControllergetIdgetIdentityMapAccessorgetIntegrityCheckergetJPAQueriesgetLoggetLogingetLogLevelgetLogLevelgetNamegetNextSequenceNumberValuegetPartitioningPolicygetPlatformgetProfilergetProjectgetPropertiesgetPropertygetQueriesgetQuerygetQuerygetSerializergetSessionLoghandleExceptionhandleSeverehasDescriptorhasExceptionHandlerhasExternalTransactionControllerisClientSessionisConnectedisDatabaseSessionisDistributedSessionisFinalizersEnabledisInProfileisRemoteSessionisRemoteUnitOfWorkisServerSessionisSessionBrokerisUnitOfWorkloglogMessagereadAllObjectsreadAllObjectsreadAllObjectsreadObjectreadObjectreadObjectreadObjectrefreshObjectreleaseremovePropertyremoveQuerysetDefaultReferenceModesetExceptionHandlersetIntegrityCheckersetIsFinalizersEnabledsetLogsetLogLevelsetNamesetPartitioningPolicysetProfilersetPropertysetQueryTimeoutDefaultsetQueryTimeoutUnitDefaultsetSerializersetSessionLogshouldLogshouldLogMessagesvalidateCache

Method Detail

addDescriptorback to summary
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.

See Also
addDescriptors(Collection), addDescriptors(Project)
addDescriptorsback to summary
public void addDescriptors(Collection<E> 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.

addDescriptorsback to summary
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.

addSequenceback to summary
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.

See Also
addDescriptor, addDescriptors
beginTransactionback to summary
public void beginTransaction() throws DatabaseException

PUBLIC: Begin a transaction on the database. This allows a group of database modification to be committed or rolledback as a unit. All writes/deletes will be sent to the database be will not be visible to other users until commit. Although databases do not allow nested transaction, EclipseLink supports nesting through only committing to the database on the outer commit.

Exceptions
DatabaseException:
if the database connection is lost or the begin is rejected.
See Also
isInTransaction()
commitTransactionback to summary
public void commitTransaction() throws DatabaseException

PUBLIC: Commit the active database transaction. This allows a group of database modification to be committed or rolledback as a unit. All writes/deletes will be sent to the database be will not be visible to other users until commit. Although databases do not allow nested transaction, EclipseLink supports nesting through only committing to the database on the outer commit.

Exceptions
DatabaseException:
most databases validate changes as they are done, normally errors do not occur on commit unless the disk fails or the connection is lost.
ConcurrencyException:
if this session is not within a transaction.
deleteAllObjectsback to summary
public void deleteAllObjects(Collection<E> domainObjects)

PUBLIC: delete all of the objects and all of their privately owned parts in the database. The allows for a group of objects to be deleted as a unit. The objects will be deleted through a single transactions.

Exceptions
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.
deleteObjectback to summary
public Object deleteObject(Object domainObject) throws DatabaseException, OptimisticLockException

PUBLIC: Delete the object and all of its privately owned parts from the database. The delete operation can be customized through using a delete query.

See Also
org.eclipse.persistence.queries.DeleteObjectQuery
getCommandManagerback to summary
public CommandManager getCommandManager()

ADVANCED: Return the CommandManager that allows this session to act as a CommandProcessor and receive or propagate commands from/to the EclipseLink cluster. This can be set to enable cache synchronization in a clustered environment where multiple servers in the cluster update the same database.

Returns:CommandManager

The CommandManager instance that controls the remote command service for this session.

See Also
CommandManager
getDatabaseEventListenerback to summary
public DatabaseEventListener getDatabaseEventListener()

Return the database event listener, this allows database events to invalidate the cache.

getSequencingControlback to summary
public SequencingControl getSequencingControl()

PUBLIC: Return SequencingControl which used for sequencing setup and customization including management of sequencing preallocation.

getServerPlatformback to summary
public ServerPlatform getServerPlatform()

Redeclares org.eclipse.persistence.sessions.Session.getServerPlatform.

PUBLIC: Answer the server platform defining server-specific behavior for the receiver (Oc4j, WLS, ...). 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.

Annotations
@Override
See Also
org.eclipse.persistence.platform.server.ServerPlatformBase
insertObjectback to summary
public Object insertObject(Object domainObject) throws DatabaseException

PUBLIC: Insert the object and all of its privately owned parts into the database. Insert should only be used if the application knows that the object is new, otherwise writeObject should be used. The insert operation can be customized through using an insert query.

See Also
org.eclipse.persistence.queries.InsertObjectQuery, writeObject(Object)
isInTransactionback to summary
public boolean isInTransaction()

PUBLIC: Return if the session is currently in the progress of a database transaction. Because nested transactions are allowed check if the transaction mutex has been acquired.

loginback to summary
public void login() throws DatabaseException

PUBLIC: Connect to the database using the predefined login. The login must have been assign when or after creating the session.

See Also
login(Login)
loginback to summary
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. Under this login mode the password should not stay within the login definition after login.

loginback to summary
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. Under this login mode the password should not stay within the login definition after login.

logoutback to summary
public void logout() throws DatabaseException

PUBLIC: Disconnect from the database.

Exceptions
DatabaseException:
the database will also raise an error if their is an active transaction, or a general error occurs.
EclipseLinkException:
if a transaction is active, you must rollback any active transaction before logout.
refreshAndLockObjectback to summary
public Object refreshAndLockObject(Object object)

PUBLIC: Refresh the attributes of the object and of all of its private parts from the database. The object will be pessimistically locked on the database for the duration of the transaction. If the object is already locked this method will wait until the lock is released. A no wait option is available through setting the lock mode.

See Also
refreshAndLockObject(Object, short)
refreshAndLockObjectback to summary
public Object refreshAndLockObject(Object object, short lockMode)

PUBLIC: Refresh the attributes of the object and of all of its private parts from the database. The object will be pessimistically locked on the database for the duration of the transaction.

Lock Modes: ObjectBuildingQuery.NO_LOCK, LOCK, LOCK_NOWAIT

rollbackTransactionback to summary
public void rollbackTransaction() throws DatabaseException

PUBLIC: Rollback the active database transaction. This allows a group of database modification to be committed or rolled back as a unit. All writes/deletes will be sent to the database be will not be visible to other users until commit. Although databases do not allow nested transaction, EclipseLink supports nesting through only committing to the database on the outer commit.

Exceptions
DatabaseException:
if the database connection is lost or the rollback fails.
ConcurrencyException:
if this session is not within a transaction.
setCommandManagerback to summary
public void setCommandManager(CommandManager commandManager)

ADVANCED: Set the CommandManager that allows this session to act as a CommandProcessor and receive or propagate commands from/to the EclipseLink cluster. This can be used to enable cache synchronization in a clustered environment where multiple servers in the cluster update the same database. To enable cache synchronization you must also set, setShouldPropagateChanges to true.

Parameters
commandManager:CommandManager

The CommandManager instance to control the remote command service for this session.

See Also
setShouldPropagateChanges(boolean), CommandManager
setDatabaseEventListenerback to summary
public void setDatabaseEventListener(DatabaseEventListener databaseEventListener)

PUBLIC: Set the database event listener, this allows database events to invalidate the cache.

setDatasourceLoginback to summary
public void setDatasourceLogin(Login login)

PUBLIC: Set the login.

setExternalTransactionControllerback to summary
public void setExternalTransactionController(ExternalTransactionController etc)

Redeclares org.eclipse.persistence.sessions.Session.setExternalTransactionController.

PUBLIC: Used for JTS integration. If your application requires to have JTS control transactions instead of EclipseLink an external transaction controller must be specified. EclipseLink provides JTS controllers for JTS 1.0 and Weblogic's JTS.

Annotations
@Override
See Also
org.eclipse.persistence.transaction.JTATransactionController, org.eclipse.persistence.platform.server.CustomServerPlatform
setLoginback to summary
public void setLogin(Login login)

PUBLIC: Set the login.

setServerPlatformback to summary
public void setServerPlatform(ServerPlatform newServerPlatform)

PUBLIC: Set the server platform defining server-specific behavior for the receiver (Oc4j, WLS, ... ). 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.

See Also
org.eclipse.persistence.platform.server.ServerPlatformBase
setShouldPropagateChangesback to summary
public void setShouldPropagateChanges(boolean choice)

ADVANCED: Set if cache changes should be propagated to other sessions or applications in a EclipseLink cluster through the Remote Command Manager mechanism. This can be used to enable cache synchronization in a clustered environment where multiple servers in the cluster update the same database. In order for this to occur the CommandManager must be set.

Parameters
choice:boolean

If true (and the CommandManager is set) then propagation will occur.

See Also
setCommandManager(CommandManager)
shouldPropagateChangesback to summary
public boolean shouldPropagateChanges()

ADVANCED: Return whether changes should be propagated to other sessions or applications in a EclipseLink cluster through the Remote Command Manager mechanism. In order for this to occur the CommandManager must be set.

Returns:boolean

true if propagation is set to occur, false if not.

See Also
setCommandManager(CommandManager)
updateObjectback to summary
public Object updateObject(Object domainObject) throws DatabaseException, OptimisticLockException

PUBLIC: Update the object and all of its privately owned parts in the database. Update should only be used if the application knows that the object is new, otherwise writeObject should be used. The update operation can be customized through using an update query.

See Also
org.eclipse.persistence.queries.UpdateObjectQuery, writeObject(Object)
writeAllObjectsback to summary
public void writeAllObjects(Collection<E> domainObjects)

PUBLIC: Write all of the objects and all of their privately owned parts in the database. The allows for a group of objects to be committed as a unit. The objects will be committed through a single transactions.

Exceptions
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.
writeObjectback to summary
public Object writeObject(Object domainObject) throws DatabaseException, OptimisticLockException

PUBLIC: Write the object and all of its privately owned parts in the database. Write will determine if an insert or an update should be done, it may go to the database to determine this (by default will check the identity map). The write operation can be customized through using an write query.

See Also
org.eclipse.persistence.queries.WriteObjectQuery, insertObject(Object), updateObject(Object)