- All Implemented Interfaces:
- Serializable,- Cloneable,- Comparable<DomainContext>,- DomainContext,- SessionHolder
- Author:
- harald
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionDefaultDomainContext(Session session) Creates a mutable default context.DefaultDomainContext(Session session, boolean sessionImmutable) Creates a default context.
- 
Method SummaryModifier 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.Objectfinalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.tentackle.pdo.DomainContextapplyTo, applyTo
- 
Constructor Details- 
DefaultDomainContextCreates a default context.- Parameters:
- session- the session, null if thread-local
- sessionImmutable- true if session cannot be changed anymore
 
- 
DefaultDomainContextCreates a mutable default context.- Parameters:
- session- the session, null if thread-local
 
 
- 
- 
Method Details- 
getNamesDescription 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 interface- DomainContext
- Returns:
- the unmodifiable list of names, never null, never empty, the first element is always the empty string
 
- 
isSessionThreadLocalpublic boolean isSessionThreadLocal()- Specified by:
- isSessionThreadLocalin interface- SessionHolder
 
- 
getSession
 If the context's session is null the thread's local session is returned.- Specified by:
- getSessionin interface- SessionHolder
- See Also:
 
- 
setSession- Specified by:
- setSessionin interface- SessionHolder
 
- 
setSessionImmutablepublic void setSessionImmutable(boolean sessionImmutable) Sets the session to immutable.- Specified by:
- setSessionImmutablein interface- SessionHolder
- Parameters:
- sessionImmutable- true if session cannot be changed anymore
 
- 
isSessionImmutablepublic boolean isSessionImmutable()Returns whether the session is immutable.- Specified by:
- isSessionImmutablein interface- SessionHolder
- Returns:
- true if immutable
 
- 
getSessionInstanceNumberpublic int getSessionInstanceNumber()- Specified by:
- getSessionInstanceNumberin interface- SessionHolder
 
- 
getSessionInfo- Specified by:
- getSessionInfoin interface- SessionHolder
 
- 
assertPermissionspublic 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 interface- DomainContext
 
- 
getContextPdoDescription copied from interface:DomainContextGets the object that spans this context.
 The default implementation returns null.- Specified by:
- getContextPdoin interface- DomainContext
- Returns:
- the root object, null if in default context
 
- 
getContextIdpublic long getContextId()Description copied from interface:DomainContextGets the ID of the context object.
 The default implementation returns 0.- Specified by:
- getContextIdin interface- DomainContext
- Returns:
- the object ID, 0 if in default context
 
- 
isWithinContextpublic 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 interface- DomainContext
- Parameters:
- contextId- the object ID of a context object, 0 = default context
- contextClassId- the class id of the context object, 0 = default context
- Returns:
- true if within that context, false if context does not apply
 
- 
isWithinContextDescription 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 interface- DomainContext
- Parameters:
- name- the requested name
- Returns:
- true if within context, false if not
 
- 
toStringGets 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.
- 
toGenericStringDescription 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 interface- DomainContext
- Returns:
- the String as Classname[contextId]
 
- 
toDiagnosticStringDescription copied from interface:DomainContextGet the long diagnostic string of this context.
 Used for logging, for example.- Specified by:
- toDiagnosticStringin interface- DomainContext
- Returns:
- the long info
 
- 
compareToCompares 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 interface- Comparable<DomainContext>
- Parameters:
- otherContext- the context to compare this context to
 
- 
equalsOverridden 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.
- 
hashCodepublic int hashCode()
- 
cloneKeepRootDescription copied from interface:DomainContextClones this context.
 Same asDomainContext.clone(), but keeps the root entity, if any is set.- Specified by:
- cloneKeepRootin interface- DomainContext
- Returns:
- the context's clone
 
- 
cloneDescription copied from interface:DomainContextClones this context.The clone gets the root entity and sessionImmutable cleared. - Specified by:
- clonein interface- DomainContext
- Overrides:
- clonein class- Object
- Returns:
- the context's clone
 
- 
cloneKeepRootDescription 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 interface- DomainContext
- Parameters:
- name- the name of the new context
- Returns:
- the context's clone
 
- 
cloneDescription 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 interface- DomainContext
- Parameters:
- name- the name of the new context
- Returns:
- the context's clone
 
- 
getClonedContextDescription copied from interface:DomainContextGets the context this context was cloned from.- Specified by:
- getClonedContextin interface- DomainContext
- Returns:
- null if not cloned or original context isn't available anymore (GC'd or was remote)
 
- 
getThreadLocalSessionContextDescription 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 interface- DomainContext
- Returns:
- the context with a thread-local session
 
- 
clearThreadLocalSessionContextpublic void clearThreadLocalSessionContext()Description copied from interface:DomainContextClears the cached clone of this context.
 Forces cloning on nextDomainContext.getThreadLocalSessionContext().- Specified by:
- clearThreadLocalSessionContextin interface- DomainContext
 
- 
getNonRootContextDescription 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 interface- DomainContext
- Returns:
- the non-root context
 
- 
isRootContextpublic boolean isRootContext()Description copied from interface:DomainContextReturns whether this is a root entity context.- Specified by:
- isRootContextin interface- DomainContext
- Returns:
- true if root context
 
- 
getRootContextDescription 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 interface- DomainContext
- Parameters:
- rootEntity- the root entity
- Returns:
- the root context
 
- 
writeReplaceThis 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:
 
- 
getRootEntityDescription copied from interface:DomainContextGets the root entity for this context.- Specified by:
- getRootEntityin interface- DomainContext
- Returns:
- the root entity, null if none
 
- 
getRootClassIdpublic int getRootClassId()Description copied from interface:DomainContextGets the class-ID of the root entity.- Specified by:
- getRootClassIdin interface- DomainContext
- Returns:
- the class-ID, 0 if there is no root entity
 
- 
getRootIdpublic long getRootId()Description copied from interface:DomainContextGets the ID of the root entity.- Specified by:
- getRootIdin interface- DomainContext
- Returns:
- the ID, 0 if root entity is new or there is no root entity
 
 
-