public interface Session
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 alist of entities
. To delete an entity call delete(Entity)
. All changes are persisted to the database when you call commit()
. Prior to commit()
no databaselocks are held with exception of 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
.Modifier and Type | Method and Description |
---|---|
void |
addSessionListener(de.espirit.or.SessionListener listener)
Add the
listener to this session. |
void |
close()
Close the session and release all used resources.
|
void |
commit()
Make all changes since the last commit or rollback persistent.
|
void |
commit(String comment)
Make all changes since the last commit or rollback persistent with the given
comment as revision comment. |
Entity |
createEntity(String type)
Create a new entity of the given
type |
Select |
createSelect(String name)
Create a select for the entity type with the provided
name . |
void |
delete(Entity entity)
Mark the
entity as deleted. |
EntityList |
executeQuery(Select select)
Execute the provided query and returns the matching entities.
|
Schema |
extractSchemaFromDB(String schemaName)
Update the assigned schema with the structure of DB schema
schemaName . |
IdentifierList<UUID,Entity> |
fetchEntities(String entityTypeName,
Collection<UUID> entityGids)
Fetches all entities specified by given
gids . |
Entity |
find(EntityType type,
String uuid)
Returns the entity specififed by given EntityType and uuid string Important: Only supported if the schema is
temporal . |
Entity |
find(EntityType type,
UUID uuid)
Returns the entity specififed by given EntityType and uuid.
|
Entity |
find(Identifier identifier)
Return the entity with the given
identifier . |
Entity |
find(KeyValue keyValue)
Return the entity with the given
keyValue . |
Entity |
find(String entityTypeName,
Object... key)
Return the entity of type
entityTypeName with the id key . |
Entity |
findNotNull(KeyValue keyValue)
Returns an entity with the given
keyValue even if it doesn't exist. |
Entity |
findNotNull(String entityTypeName,
Object... key)
Returns an entity of type
entityTypeName with the id key even if it doesn't exists.In that case the entity's state is NOT_EXISTS . |
Set<Entity> |
getChanged()
Return the set of modified and not yet committed entities in this session.
|
List<Entity> |
getDeletedEntities(String entityTypeName)
Get all deleted entities from type
entityTypeName . |
List<Entity> |
getHistory(KeyValue keyValue)
Return the history of the entity with the given
keyValue . |
List<Entity> |
getInvalidEntities(KeyValue keyValue)
Return a list of invalid entities of the given
keyValue . |
long |
getLastChangeTime(Select select)
Get the timestamp of the last change of the result set of the specified select.
|
long |
getLastChangeTime(Select select,
long after)
Get the timestamp of the last change of the result set of the specified select after the specified timestamp.
|
Set<KeyValue> |
getReleasedDeleted(String entityTypeName)
Get the key values of all entities of the given entity type which are deleted but still released.
|
Schema |
getSchema()
Return the schema assigned with this session.
|
boolean |
hasChanges()
|
boolean |
isReadOnly()
If the session is read only no modifications are permitted.
|
boolean |
isRelease()
Return true if this session is a release session else false.
|
boolean |
refresh()
Refresh the session if there are no uncommitted changes.
|
void |
release(Entity entity)
Release the given
entity . |
void |
removeSessionListener(de.espirit.or.SessionListener listener)
Remove the
listener from this session. |
void |
restore(Identifier identifier)
Restore the deleted entity with the specified
identifier . |
void |
rollback()
Undo all changes since the last commit or rollback.
|
Schema |
syncSchemaWithDB(Schema schema,
boolean createKeys)
Update the database structure with the given
schema . |
Select |
xml2Select(String queryXml)
Construct a select from the xml document
queryXml . |
@NotNull Entity createEntity(@NotNull String type)
type
@Nullable Entity find(@NotNull KeyValue keyValue)
keyValue
.@NotNull Entity findNotNull(@NotNull KeyValue keyValue)
keyValue
even if it doesn't exist. In that case theentity's state
is NOT_EXISTS
.@Nullable Entity find(@NotNull String entityTypeName, @NotNull Object... key)
entityTypeName
with the id key
.entityTypeName
- Name of the target entity type.key
- Primary key values.@NotNull Entity findNotNull(@NotNull String entityTypeName, @NotNull Object... key)
entityTypeName
with the id key
even if it doesn't exists.In that case the entity's state
is NOT_EXISTS
.entityTypeName
- Name of the target entity type.key
- Primary key values.@Nullable Entity find(@NotNull EntityType type, String uuid)
temporal
.type
- Target entity type.uuid
- UUID as string.find(EntityType,UUID)
@Nullable Entity find(@NotNull EntityType type, UUID uuid)
temporal
.type
- Target entity type.uuid
- UUID as object.find(EntityType,String)
@NotNull Entity find(@NotNull Identifier identifier)
identifier
. Important: Keep in mind the difference between an Identifier
and KeyValue
fora temporal schema
, use find(KeyValue)
if possible.@NotNull Select createSelect(@NotNull String name)
name
.name
- Enity type name.@NotNull Select xml2Select(@NotNull String queryXml)
queryXml
.queryXml
- Xml string describing the select statement.void delete(@NotNull Entity entity)
entity
as deleted. The state of the entity will change to Entity.PersistentState.DELETING
. The change is persisted with the next commit()
.entity
- Entity to delete.@NotNull EntityList executeQuery(@NotNull Select select)
select
- Select statement.entities
.createSelect(String)
,
xml2Select(String)
IdentifierList<UUID,Entity> fetchEntities(@NotNull String entityTypeName, @NotNull Collection<UUID> entityGids)
gids
.null
entries for gids no entity could be found for.@NotNull List<Entity> getDeletedEntities(@NotNull String entityTypeName)
entityTypeName
.@NotNull Set<KeyValue> getReleasedDeleted(@NotNull String entityTypeName)
temporal
schema this method delivers an empty set.entityTypeName
- Entity type to filter on.keys
of matching entities.@NotNull List<Entity> getInvalidEntities(@NotNull KeyValue keyValue)
keyValue
. For a non- temporal
schema this method delivers an empty list.keyValue
- Key of the entity.getHistory(de.espirit.or.schema.KeyValue)
@NotNull List<Entity> getHistory(@NotNull KeyValue keyValue)
keyValue
. In contrast to getInvalidEntities(de.espirit.or.schema.KeyValue)
the returned list includes the alsothe most actual value of the entity. For non- temporal
schema this method delivers an empty list.keyValue
- Key of the entity.getInvalidEntities(de.espirit.or.schema.KeyValue)
void restore(@NotNull Identifier identifier)
identifier
. Important: Only supported if the schema is temporal
.identifier
- Identifier of entity to restore.void rollback()
boolean refresh()
true
if refresh was performed, false
if refresh is skipped because there areuncommitted changes.rollback()
,
hasChanges()
void commit()
void commit(String comment)
comment
as revision comment.comment
- Revision comment.void close()
committed
.void release(@NotNull Entity entity)
entity
. The state of the entity will change to Entity.PersistentState.RELEASING
, the operation will be made persistent with the next commit
. Important: Only supported if the schema is temporal
.entity
- Entity to release.boolean isRelease()
createEntity(String)
, create a new schema form the database extractSchemaFromDB(String)
andupdate the database structure syncSchemaWithDB(Schema,boolean)
are not supported.UnsupportedOperationException
will be thrown if these methods are called in a release session. Important: Only supported if the schema is temporal
.true
if this session operates on the release state, else false
.Schema extractSchemaFromDB(String schemaName)
schemaName
.schemaName
- Name of schema to extract.Schema syncSchemaWithDB(@NotNull Schema schema, boolean createKeys)
schema
. If importMode
is true
then no primary and foreign keys are created during the sync.schema
- Schema containing the structure to sync with the database.createKeys
- Create keys in the database.boolean isReadOnly()
true
if no changes are permitted through this session instance.boolean hasChanges()
true
if there are pending changes
.commit
,
rollback
Set<Entity> getChanged()
long getLastChangeTime(@NotNull Select select)
result entity type
are considered. Important: Only supported if the schema is temporal
.select
- Select statement.long getLastChangeTime(@NotNull Select select, long after)
result entity type
areconsidered. Only supported for temporal schema.select
- Select statement.after
- Additional time stamp restriction.getLastChangeTime(de.espirit.or.query.Select)
void addSessionListener(@NotNull de.espirit.or.SessionListener listener)
listener
to this session.listener
- Listener to add.void removeSessionListener(@NotNull de.espirit.or.SessionListener listener)
listener
from this session.listener
- Listener to remove.Copyright © 2021 e-Spirit AG. All Rights Reserved. Build 5.2.210210