Package de.espirit.or
Interface Session
public interface Session
Session is the entry point for a connection to a database. The metadata (schema) for the session is available via
All changes are persisted to the database when you call
A session may be
Most methods may throw the (unchecked)
getSchema(). To create new entites (i.e. database entries) call createEntity(String), providing
an entity type name. To retrive existing entities use on of the 'find' methods
(find(String, Object...), findNotNull(String, Object...), etc.) or use a
select to execute a query to retrieve a
list of entities. To delete an entity call delete(Entity).
All changes are persisted to the database when you call
commit(). Prior to commit() no database
locks are held except read locks when an entity is explicitly or transparently (re)loaded. You may also
rollback() all changes. The set of changed entities could be requested by calling getChanged().
This will return an empty collection if hasChanges() delivers false.
A session may be
read-only, then every modification will be rejected.
Schema changes may be synced to the database.
Most methods may throw the (unchecked)
ORException.- Since:
- 4.0.17
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddSessionListener(@NotNull de.espirit.or.SessionListener listener) Add thelistenerto this session.voidclose()Close the session and release all used resources.voidcommit()Make all changes since the last commit or rollback persistent.voidMake all changes since the last commit or rollback persistent with the givencommentas revision comment.@NotNull EntitycreateEntity(@NotNull String type) Create a new entity of the giventype@NotNull SelectcreateSelect(@NotNull String name) Create a select for the entity type with the providedname.voidMark theentityas deleted.@NotNull EntityListexecuteQuery(@NotNull Select select) Execute the provided query and returns the matching entities.extractSchemaFromDB(String schemaName) Update the assigned schema with the structure of DB schemaschemaName.fetchEntities(@NotNull String entityTypeName, @NotNull Collection<UUID> entityGids) Fetches all entities specified by givengids.
Attention: List could containnullentries for GIDs no entity could be found for.@Nullable Entityfind(@NotNull EntityType type, String uuid) Returns the entity specified by given EntityType and uuid string
Important: Only supported if the schema istemporal.@Nullable Entityfind(@NotNull EntityType type, UUID uuid) Returns the entity specified by given EntityType and uuid.@NotNull Entityfind(@NotNull Identifier identifier) Return the entity with the givenidentifier.@Nullable EntityReturn the entity with the givenkeyValue.@Nullable EntityReturn the entity of typeentityTypeNamewith the idkey.@NotNull EntityfindNotNull(@NotNull KeyValue keyValue) Returns an entity with the givenkeyValueeven if it doesn't exist.@NotNull EntityfindNotNull(@NotNull String entityTypeName, @NotNull Object... key) Returns an entity of typeentityTypeNamewith the idkeyeven if it doesn't exists.Return the set of modified and not yet committed entities in this session.getDeletedEntities(@NotNull String entityTypeName) Get all deleted entities from typeentityTypeName.getHistory(@NotNull KeyValue keyValue) Return the history of the entity with the givenkeyValue.getInvalidEntities(@NotNull KeyValue keyValue) Return a list of invalid entities of the givenkeyValue.longgetLastChangeTime(@NotNull Select select) Get the timestamp of the last change of the result set of the specified select.longgetLastChangeTime(@NotNull Select select, long after) Get the timestamp of the last change of the result set of the specified select after the specified timestamp.getReleasedDeleted(@NotNull String entityTypeName) Get the key values of all entities of the given entity type which are deleted but still released.getReleaseRevision(@NotNull Identifier identifier, @NotNull String languageAbbreviation) GetEntityin language dependent release revision if available.@NotNull SchemaReturn the schema assigned with this session.booleanbooleanIf the session is read only no modifications are permitted.booleanReturn true if this session is a release session else false.booleanrefresh()Refresh the session if there are no uncommitted changes.voidRelease the givenentity.voidremoveSessionListener(@NotNull de.espirit.or.SessionListener listener) Remove thelistenerfrom this session.voidrestore(@NotNull Identifier identifier) Restore the deleted entity with the specifiedidentifier.voidrollback()Undo all changes since the last commit or rollback.syncSchemaWithDB(@NotNull Schema schema, boolean createKeys) Update the database structure with the givenschema.@NotNull Selectxml2Select(@NotNull String queryXml) Construct a select from the xml documentqueryXml.
-
Method Details
-
getSchema
Return the schema assigned with this session.- Since:
- 4.0.17
-
createEntity
Create a new entity of the giventype- Since:
- 4.0.17
-
find
Return the entity with the givenkeyValue.- Since:
- 4.0.17
-
findNotNull
Returns an entity with the givenkeyValueeven if it doesn't exist. In that case the entity'sstateisNOT_EXISTS.- Since:
- 4.1.2
-
find
@Nullable @Nullable Entity find(@NotNull @NotNull String entityTypeName, @NotNull @NotNull Object... key) Return the entity of typeentityTypeNamewith the idkey.- Parameters:
entityTypeName- Name of the target entity type.key- Primary key values.- Since:
- 4.0.17
-
findNotNull
@NotNull @NotNull Entity findNotNull(@NotNull @NotNull String entityTypeName, @NotNull @NotNull Object... key) Returns an entity of typeentityTypeNamewith the idkeyeven if it doesn't exists. In that case the entity'sstateisNOT_EXISTS.- Parameters:
entityTypeName- Name of the target entity type.key- Primary key values.- Since:
- 4.1.2
-
find
Returns the entity specified by given EntityType and uuid string
Important: Only supported if the schema istemporal.- Parameters:
type- Target entity type.uuid- UUID as string.- Since:
- 5.0.100
- See Also:
-
find
Returns the entity specified by given EntityType and uuid.
Important: Only supported if the schema istemporal.- Parameters:
type- Target entity type.uuid- UUID as object.- Since:
- 5.0.100
- See Also:
-
find
Return the entity with the givenidentifier.
Important: Keep in mind the difference between anIdentifierandKeyValuefor atemporal schema, usefind(KeyValue)if possible.- Since:
- 4.0.17
-
createSelect
Create a select for the entity type with the providedname.- Parameters:
name- Entity type name.- Since:
- 4.0.17
-
xml2Select
Construct a select from the xml documentqueryXml.- Parameters:
queryXml- Xml string describing the select statement.- Since:
- 4.0.17
-
delete
Mark theentityas deleted. The state of the entity will change toEntity.PersistentState.DELETING. The change is persisted with the nextcommit().- Parameters:
entity- Entity to delete.- Since:
- 4.0.17
-
executeQuery
Execute the provided query and returns the matching entities. The items of the result list are loaded lazy when requested.- Parameters:
select- Select statement.- Returns:
- A list of
entities. - Since:
- 4.0.17
- See Also:
-
fetchEntities
IdentifierList<UUID,Entity> fetchEntities(@NotNull @NotNull String entityTypeName, @NotNull @NotNull Collection<UUID> entityGids) Fetches all entities specified by givengids.
Attention: List could containnullentries for GIDs no entity could be found for.- Since:
- 5.0.412
-
getDeletedEntities
Get all deleted entities from typeentityTypeName.- Since:
- 4.0.19
-
getReleasedDeleted
Get the key values of all entities of the given entity type which are deleted but still released.
For a non-temporalschema this method delivers an empty set.- Parameters:
entityTypeName- Entity type to filter on.- Returns:
- A collection of
keysof matching entities. - Since:
- 4.0.91
-
getInvalidEntities
Return a list of invalid entities of the givenkeyValue.
For a non-temporalschema this method delivers an empty list.- Parameters:
keyValue- Key of the entity.- Returns:
- A history of changes for the specified entity.
- Since:
- 4.0.22
- See Also:
-
getHistory
Return the history of the entity with the givenkeyValue. In contrast togetInvalidEntities(de.espirit.or.schema.KeyValue)the returned list includes the also the most actual value of the entity.
For non-temporalschema this method delivers an empty list.- Parameters:
keyValue- Key of the entity.- Returns:
- A history of changes for the specified entity.
- Since:
- 4.2.44
- See Also:
-
restore
Restore the deleted entity with the specifiedidentifier.
Important: Only supported if the schema istemporal.- Parameters:
identifier- Identifier of entity to restore.- Since:
- 4.0.20
-
rollback
void rollback()Undo all changes since the last commit or rollback.- Since:
- 4.0.17
-
refresh
boolean refresh()Refresh the session if there are no uncommitted changes. The operation itself is fast, but invalidates already loaded entities so that they are re-loaded on the next access.- Returns:
trueif refresh was performed,falseif refresh is skipped because there are uncommitted changes.- Since:
- 5.2.501
- See Also:
-
commit
void commit()Make all changes since the last commit or rollback persistent.- Since:
- 4.0.17
-
commit
Make all changes since the last commit or rollback persistent with the givencommentas revision comment.- Parameters:
comment- Revision comment.- Since:
- 4.0.27
-
close
void close()Close the session and release all used resources. All pending changes are becommitted.- Since:
- 4.0.17
-
release
Release the givenentity. The state of the entity will change toEntity.PersistentState.RELEASING, the operation will be made persistent with the nextcommit.
Important: Only supported if the schema istemporal.- Parameters:
entity- Entity to release.- Since:
- 4.0.17
-
isRelease
boolean isRelease()Return true if this session is a release session else false. All entities manages by a release session must be in the release state. A release session supports only the delete and find / select operations.
All other operations e.g. like create a new entitycreateEntity(String), create a new schema form the databaseextractSchemaFromDB(String)and update the database structuresyncSchemaWithDB(Schema, boolean)are not supported.
AnUnsupportedOperationExceptionwill be thrown if these methods are called in a release session.
Important: Only supported if the schema istemporal.- Returns:
trueif this session operates on the release state, elsefalse.- Since:
- 4.0.17
-
extractSchemaFromDB
Update the assigned schema with the structure of DB schemaschemaName.- Parameters:
schemaName- Name of schema to extract.- Since:
- 4.0.17
-
syncSchemaWithDB
Update the database structure with the givenschema. IfimportModeistruethen no primary and foreign keys are created during the sync.- Parameters:
schema- Schema containing the structure to sync with the database.createKeys- Create keys in the database.- Since:
- 4.0.17
-
isReadOnly
boolean isReadOnly()If the session is read only no modifications are permitted.- Returns:
trueif no changes are permitted through this session instance.- Since:
- 4.0.17
-
hasChanges
boolean hasChanges()- Returns:
trueif there arepending changes.- Since:
- 4.0.17
- See Also:
-
getChanged
Return the set of modified and not yet committed entities in this session.- Returns:
- Set of modified and not yet commited entities.
- Since:
- 4.0.17
-
getLastChangeTime
Get the timestamp of the last change of the result set of the specified select. Only changes of theresult entity typeare considered.
Important: Only supported if the schema istemporal.- Parameters:
select- Select statement.- Returns:
- Time stamp of last change of all matching entities.
- Since:
- 4.0.19
-
getLastChangeTime
Get the timestamp of the last change of the result set of the specified select after the specified timestamp. Only changes of theresult entity typeare considered.
Only supported for temporal schema.- Parameters:
select- Select statement.after- Additional time stamp restriction.- Returns:
- Time stamp of last change of all matching entities.
- Since:
- 4.2.400
- See Also:
-
addSessionListener
void addSessionListener(@NotNull @NotNull de.espirit.or.SessionListener listener) Add thelistenerto this session.- Parameters:
listener- Listener to add.- Since:
- 4.0.17
-
removeSessionListener
void removeSessionListener(@NotNull @NotNull de.espirit.or.SessionListener listener) Remove thelistenerfrom this session.- Parameters:
listener- Listener to remove.- Since:
- 4.0.17
-
getReleaseRevision
@Experimental @NotNull @NotNull Optional<Entity> getReleaseRevision(@NotNull @NotNull Identifier identifier, @NotNull @NotNull String languageAbbreviation) throws ORException GetEntityin language dependent release revision if available.- Parameters:
identifier- The entity identifier.languageAbbreviation- The language for the language dependent release revision.- Throws:
ORException- Since:
- 5.2.250604
-