- All Implemented Interfaces:
Serializable
,Cloneable
,Comparable<DomainContext>
,DomainContext
,SessionHolder
- Author:
- harald
- See Also:
-
Constructor Summary
ConstructorDescriptionDefaultDomainContext
(Session session) Creates a mutable default context.DefaultDomainContext
(Session session, boolean sessionImmutable) Creates a default context. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Asserts that this context is allowed to be used by the current user.
Only invoked when session is updated after deserialization (objects traveling between JVMs).void
Clears the cached clone of this context.
Forces cloning on nextDomainContext.getThreadLocalSessionContext()
.clone()
Clones this context.Clones this context with another context name.Clones this context.
Same asDomainContext.clone()
, but keeps the root entity, if any is set.cloneKeepRoot
(String name) Clones this context with another context name.
Same asDomainContext.clone(String)
, but keeps the root entity, if any is set.int
compareTo
(DomainContext otherContext) Compares this domain context with another domain context.
The default implementation just compares the class, the contextId and the session.
Checking against the null context returns 1.boolean
Gets the context this context was cloned from.long
Gets the ID of the context object.
The default implementation returns 0.Gets the object that spans this context.
The default implementation returns null.getNames()
Gets the names of this context.Gets a domain context which does not belong to a root entity.
This is the original context the root-context has been cloned from.int
Gets the class-ID of the root entity.getRootContext
(PersistentDomainObject<?> rootEntity) Creates a root context for a given root entity.
If this context is already a root context for the same root-entity, nothing will be created and this context returned.Gets the root entity for this context.long
Gets the ID of the root entity.
If the context's session is null the thread's local session is returned.int
Gets a clone of this context with a thread-local session.int
hashCode()
boolean
Returns whether this is a root entity context.boolean
Returns whether the session is immutable.boolean
boolean
isWithinContext
(long contextId, int contextClassId) Determines whether this context belongs to an inheritance hierarchy that is created from a given context object.boolean
isWithinContext
(String name) Checks whether the given name equals the name of this or one of its parent contexts.
Notice that the empty string is always within the context, since the topmost parent context is always unnamed.void
setSession
(Session session) void
setSessionImmutable
(boolean sessionImmutable) Sets the session to immutable.Get the long diagnostic string of this context.
Used for logging, for example.Returns the generic string representation of this context.toString()
Gets the string representation of this context.This does the trick to set up the non-transient rootId and rootClassId when sent via rmi the first time.Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.tentackle.pdo.DomainContext
applyTo, applyTo
-
Constructor Details
-
DefaultDomainContext
Creates a default context.- Parameters:
session
- the session, null if thread-localsessionImmutable
- true if session cannot be changed anymore
-
DefaultDomainContext
Creates a mutable default context.- Parameters:
session
- the session, null if thread-local
-
-
Method Details
-
getNames
Description copied from interface:DomainContext
Gets the names of this context.Notice: the names must not be part in equals, hashCode or compareTo implementations, because they denote only sub contexts. As a result, all sub contexts of the same root context are considered logically equal from a multi-tenancy perspective.
- Specified by:
getNames
in interfaceDomainContext
- Returns:
- the unmodifiable list of names, never null, never empty, the first element is always the empty string
-
isSessionThreadLocal
public boolean isSessionThreadLocal()- Specified by:
isSessionThreadLocal
in interfaceSessionHolder
-
getSession
If the context's session is null the thread's local session is returned.- Specified by:
getSession
in interfaceSessionHolder
- See Also:
-
setSession
- Specified by:
setSession
in interfaceSessionHolder
-
setSessionImmutable
public void setSessionImmutable(boolean sessionImmutable) Sets the session to immutable.- Specified by:
setSessionImmutable
in interfaceSessionHolder
- Parameters:
sessionImmutable
- true if session cannot be changed anymore
-
isSessionImmutable
public boolean isSessionImmutable()Returns whether the session is immutable.- Specified by:
isSessionImmutable
in interfaceSessionHolder
- Returns:
- true if immutable
-
getSessionInstanceNumber
public int getSessionInstanceNumber()- Specified by:
getSessionInstanceNumber
in interfaceSessionHolder
-
getSessionInfo
- Specified by:
getSessionInfo
in interfaceSessionHolder
-
assertPermissions
public void assertPermissions()Description copied from interface:DomainContext
Asserts that this context is allowed to be used by the current user.
Only invoked when session is updated after deserialization (objects traveling between JVMs).If it is not allowed, a
PersistenceException
must be thrown.
Override the method in middle tier servers, usually only necessary in multi-tenant applications. The default implementation does nothing.- Specified by:
assertPermissions
in interfaceDomainContext
-
getContextPdo
Description copied from interface:DomainContext
Gets the object that spans this context.
The default implementation returns null.- Specified by:
getContextPdo
in interfaceDomainContext
- Returns:
- the root object, null if in default context
-
getContextId
public long getContextId()Description copied from interface:DomainContext
Gets the ID of the context object.
The default implementation returns 0.- Specified by:
getContextId
in interfaceDomainContext
- Returns:
- the object ID, 0 if in default context
-
isWithinContext
public boolean isWithinContext(long contextId, int contextClassId) Description copied from interface:DomainContext
Determines whether this context belongs to an inheritance hierarchy that is created from a given context object.The method is invoked from the security manager to check whether a security rule applies to a given context. Note that contextClassId is the class id of the context object's class.
The default implementation returns
contextId < 0 || contextId == getContextId()
.
This is sufficient for zero or one level of context inheritance. For more than one level this method must be overridden in each level. Example:boolean isWithinContext(long contextId, int contextClassId) { return contextClassId == BLAH_CLASS_ID && contextId == getContextId() || super.isWithinContext(contextId, contextClassId); }
If the object IDs of the context objects are unique among all context entities the contextClass can be ignored and the method reduces to:boolean isWithinContext(long contextId, int contextClassId) { return contextId == getContextId() || super.isWithinContext(contextId, contextClassId); }
- Specified by:
isWithinContext
in interfaceDomainContext
- Parameters:
contextId
- the object ID of a context object, 0 = default contextcontextClassId
- the class id of the context object, 0 = default context- Returns:
- true if within that context, false if context does not apply
-
isWithinContext
Description copied from interface:DomainContext
Checks whether the given name equals the name of this or one of its parent contexts.
Notice that the empty string is always within the context, since the topmost parent context is always unnamed.- Specified by:
isWithinContext
in interfaceDomainContext
- Parameters:
name
- the requested name- Returns:
- true if within context, false if not
-
toString
Gets the string representation of this context. The default implementation returns the string of the context object, or the empty string (not the null-string!), if no such object, which is the case for the plain context. -
toGenericString
Description copied from interface:DomainContext
Returns the generic string representation of this context.Use this for logging as it will not invoke methods on other objects.
- Specified by:
toGenericString
in interfaceDomainContext
- Returns:
- the String as
Classname[contextId]
-
toDiagnosticString
Description copied from interface:DomainContext
Get the long diagnostic string of this context.
Used for logging, for example.- Specified by:
toDiagnosticString
in interfaceDomainContext
- Returns:
- the long info
-
compareTo
Compares this domain context with another domain context.
The default implementation just compares the class, the contextId and the session.
Checking against the null context returns 1.- Specified by:
compareTo
in interfaceComparable<DomainContext>
- Parameters:
otherContext
- the context to compare this context to
-
equals
Overridden to check whether contexts are equal.
The default implementation checks the class, the contextId and session for equality. Checking against the null context returns false. -
hashCode
public int hashCode() -
cloneKeepRoot
Description copied from interface:DomainContext
Clones this context.
Same asDomainContext.clone()
, but keeps the root entity, if any is set.- Specified by:
cloneKeepRoot
in interfaceDomainContext
- Returns:
- the context's clone
-
clone
Description copied from interface:DomainContext
Clones this context.The clone gets the root entity and sessionImmutable cleared.
- Specified by:
clone
in interfaceDomainContext
- Overrides:
clone
in classObject
- Returns:
- the context's clone
-
cloneKeepRoot
Description copied from interface:DomainContext
Clones this context with another context name.
Same asDomainContext.clone(String)
, but keeps the root entity, if any is set.- Specified by:
cloneKeepRoot
in interfaceDomainContext
- Parameters:
name
- the name of the new context- Returns:
- the context's clone
-
clone
Description copied from interface:DomainContext
Clones this context with another context name.Same as
DomainContext.clone()
, but appends the given name to the current context names.
The new name must be different from the current ones, not null, not containing only whitespaces and not containing a colon (: is used to concatenate the context names in toGenericString).- Specified by:
clone
in interfaceDomainContext
- Parameters:
name
- the name of the new context- Returns:
- the context's clone
-
getClonedContext
Description copied from interface:DomainContext
Gets the context this context was cloned from.- Specified by:
getClonedContext
in interfaceDomainContext
- Returns:
- null if not cloned or original context isn't available anymore (GC'd or was remote)
-
getThreadLocalSessionContext
Description copied from interface:DomainContext
Gets a clone of this context with a thread-local session.Notice: A thread-local domain context is always a non-root context.
- Specified by:
getThreadLocalSessionContext
in interfaceDomainContext
- Returns:
- the context with a thread-local session
-
clearThreadLocalSessionContext
public void clearThreadLocalSessionContext()Description copied from interface:DomainContext
Clears the cached clone of this context.
Forces cloning on nextDomainContext.getThreadLocalSessionContext()
.- Specified by:
clearThreadLocalSessionContext
in interfaceDomainContext
-
getNonRootContext
Description copied from interface:DomainContext
Gets a domain context which does not belong to a root entity.
This is the original context the root-context has been cloned from.- Specified by:
getNonRootContext
in interfaceDomainContext
- Returns:
- the non-root context
-
isRootContext
public boolean isRootContext()Description copied from interface:DomainContext
Returns whether this is a root entity context.- Specified by:
isRootContext
in interfaceDomainContext
- Returns:
- true if root context
-
getRootContext
Description copied from interface:DomainContext
Creates a root context for a given root entity.
If this context is already a root context for the same root-entity, nothing will be created and this context returned.- Specified by:
getRootContext
in interfaceDomainContext
- Parameters:
rootEntity
- the root entity- Returns:
- the root context
-
writeReplace
This does the trick to set up the non-transient rootId and rootClassId when sent via rmi the first time.- Returns:
- me
- Throws:
ObjectStreamException
- to fulfill the signature only- See Also:
-
getRootEntity
Description copied from interface:DomainContext
Gets the root entity for this context.- Specified by:
getRootEntity
in interfaceDomainContext
- Returns:
- the root entity, null if none
-
getRootClassId
public int getRootClassId()Description copied from interface:DomainContext
Gets the class-ID of the root entity.- Specified by:
getRootClassId
in interfaceDomainContext
- Returns:
- the class-ID, 0 if there is no root entity
-
getRootId
public long getRootId()Description copied from interface:DomainContext
Gets the ID of the root entity.- Specified by:
getRootId
in interfaceDomainContext
- Returns:
- the ID, 0 if root entity is new or there is no root entity
-