- All Implemented Interfaces:
Serializable,Cloneable,Comparable<DomainContext>,DomainContext,SessionHolder
- Author:
- harald
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultDomainContext(Session session) Creates a mutable default context.DefaultDomainContext(Session session, boolean sessionImmutable) Creates a default context. -
Method Summary
Modifier and TypeMethodDescriptionvoidAsserts that this context is allowed to be used by the current user.
Only invoked when session is updated after deserialization (objects traveling between JVMs).voidClears 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.intcompareTo(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.booleanGets the context this context was cloned from.longGets 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.intGets 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.longGets the ID of the root entity.
If the context's session is null the thread's local session is returned.intGets a clone of this context with a thread-local session.inthashCode()booleanReturns whether this is a root entity context.booleanReturns whether the session is immutable.booleanbooleanisWithinContext(long contextId, int contextClassId) Determines whether this context belongs to an inheritance hierarchy that is created from a given context object.booleanisWithinContext(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.voidsetSession(Session session) voidsetSessionImmutable(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, waitMethods 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:DomainContextGets 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:
getNamesin 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:
isSessionThreadLocalin interfaceSessionHolder
-
getSession
If the context's session is null the thread's local session is returned.- Specified by:
getSessionin interfaceSessionHolder- See Also:
-
setSession
- Specified by:
setSessionin interfaceSessionHolder
-
setSessionImmutable
public void setSessionImmutable(boolean sessionImmutable) Sets the session to immutable.- Specified by:
setSessionImmutablein interfaceSessionHolder- Parameters:
sessionImmutable- true if session cannot be changed anymore
-
isSessionImmutable
public boolean isSessionImmutable()Returns whether the session is immutable.- Specified by:
isSessionImmutablein interfaceSessionHolder- Returns:
- true if immutable
-
getSessionInstanceNumber
public int getSessionInstanceNumber()- Specified by:
getSessionInstanceNumberin interfaceSessionHolder
-
getSessionInfo
- Specified by:
getSessionInfoin interfaceSessionHolder
-
assertPermissions
public void assertPermissions()Description copied from interface:DomainContextAsserts 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
PersistenceExceptionmust be thrown.
Override the method in middle tier servers, usually only necessary in multi-tenant applications. The default implementation does nothing.- Specified by:
assertPermissionsin interfaceDomainContext
-
getContextPdo
Description copied from interface:DomainContextGets the object that spans this context.
The default implementation returns null.- Specified by:
getContextPdoin interfaceDomainContext- Returns:
- the root object, null if in default context
-
getContextId
public long getContextId()Description copied from interface:DomainContextGets the ID of the context object.
The default implementation returns 0.- Specified by:
getContextIdin interfaceDomainContext- Returns:
- the object ID, 0 if in default context
-
isWithinContext
public boolean isWithinContext(long contextId, int contextClassId) Description copied from interface:DomainContextDetermines 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:
isWithinContextin 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:DomainContextChecks 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:
isWithinContextin 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:DomainContextReturns the generic string representation of this context.Use this for logging as it will not invoke methods on other objects.
- Specified by:
toGenericStringin interfaceDomainContext- Returns:
- the String as
Classname[contextId]
-
toDiagnosticString
Description copied from interface:DomainContextGet the long diagnostic string of this context.
Used for logging, for example.- Specified by:
toDiagnosticStringin 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:
compareToin 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:DomainContextClones this context.
Same asDomainContext.clone(), but keeps the root entity, if any is set.- Specified by:
cloneKeepRootin interfaceDomainContext- Returns:
- the context's clone
-
clone
Description copied from interface:DomainContextClones this context.The clone gets the root entity and sessionImmutable cleared.
- Specified by:
clonein interfaceDomainContext- Overrides:
clonein classObject- Returns:
- the context's clone
-
cloneKeepRoot
Description copied from interface:DomainContextClones this context with another context name.
Same asDomainContext.clone(String), but keeps the root entity, if any is set.- Specified by:
cloneKeepRootin interfaceDomainContext- Parameters:
name- the name of the new context- Returns:
- the context's clone
-
clone
Description copied from interface:DomainContextClones 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:
clonein interfaceDomainContext- Parameters:
name- the name of the new context- Returns:
- the context's clone
-
getClonedContext
Description copied from interface:DomainContextGets the context this context was cloned from.- Specified by:
getClonedContextin interfaceDomainContext- Returns:
- null if not cloned or original context isn't available anymore (GC'd or was remote)
-
getThreadLocalSessionContext
Description copied from interface:DomainContextGets a clone of this context with a thread-local session.Notice: A thread-local domain context is always a non-root context.
- Specified by:
getThreadLocalSessionContextin interfaceDomainContext- Returns:
- the context with a thread-local session
-
clearThreadLocalSessionContext
public void clearThreadLocalSessionContext()Description copied from interface:DomainContextClears the cached clone of this context.
Forces cloning on nextDomainContext.getThreadLocalSessionContext().- Specified by:
clearThreadLocalSessionContextin interfaceDomainContext
-
getNonRootContext
Description copied from interface:DomainContextGets 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:
getNonRootContextin interfaceDomainContext- Returns:
- the non-root context
-
isRootContext
public boolean isRootContext()Description copied from interface:DomainContextReturns whether this is a root entity context.- Specified by:
isRootContextin interfaceDomainContext- Returns:
- true if root context
-
getRootContext
Description copied from interface:DomainContextCreates 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:
getRootContextin 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:DomainContextGets the root entity for this context.- Specified by:
getRootEntityin interfaceDomainContext- Returns:
- the root entity, null if none
-
getRootClassId
public int getRootClassId()Description copied from interface:DomainContextGets the class-ID of the root entity.- Specified by:
getRootClassIdin interfaceDomainContext- Returns:
- the class-ID, 0 if there is no root entity
-
getRootId
public long getRootId()Description copied from interface:DomainContextGets the ID of the root entity.- Specified by:
getRootIdin interfaceDomainContext- Returns:
- the ID, 0 if root entity is new or there is no root entity
-