java.lang.Object
org.tentackle.session.SessionUtilities
- Direct Known Subclasses:
DbSessionUtilities
Utility methods for session related stuff.
- Author:
- harald
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReplaces exception cause probably not in the jvm's classpath when the stacktrace gets deserialized in another (usually remote) jvm.void
Sets the temporary flag according to the exception's root cause and the session.createFromRemoteException
(Object relatedObject, RemoteException remoteException) Creates a RuntimeException from aRemoteException
.
Returns the first RuntimeException in chain.protected SessionKeepAliveDaemon
Creates the session keep alive daemon.createLazyExceptionMessage
(String msg, Throwable cause, Identifiable identifiable, Session session) Creates the lazy exception message for aPersistenceException
.int
determineClassId
(Class<?> clazz) Determines the classid from the @ClassId
annotation.determineTablename
(Class<?> clazz) Determines the tablename from the @TableName
annotation.int
getClassId
(String pdoClassName) Gets the classid of a pdo class.getClassName
(int classId) Gets the classname for a classid.getClassName
(String tableName) Gets the classname for tablename.Gets a list of all class names.
Sorted by name.static SessionUtilities
The singleton.getTableName
(String className) Gets the table name of a pdo class.protected boolean
isMultiLineExceptionMessage
(String msg, Throwable cause, Identifiable identifiable, Session session) Returns whether the exception message spans multiple lines.boolean
Returns whether a rollback should log all statements or not.
The rollback should not be logged, if the root-cause is not aPersistenceException
, orTentackleRuntimeException.isTemporary()
or there is another temporary exception in the exception chain.boolean
isSomeRemoved
(long lastSerial, List<IdSerialTuple> expireSet, long maxSerial) Inspects an expiration set and determines whether at least one object has been removed.void
keepAliveIntervalChanged
(Session session) Handles the change of a keep alive interval of a session.void
Starts the keep alive thread if not already running.void
Stops all helper threads.
-
Constructor Details
-
SessionUtilities
public SessionUtilities()Creates a utility instance.
-
-
Method Details
-
getInstance
The singleton.- Returns:
- the singleton
-
getTableName
Gets the table name of a pdo class.- Parameters:
className
- the class name of the object- Returns:
- the tablename, null if no such class or not annotated with @
TableName
-
getClassName
Gets the classname for tablename.- Parameters:
tableName
- the tablename- Returns:
- the name of the class, null if no such tablename
-
getClassId
Gets the classid of a pdo class.- Parameters:
pdoClassName
- the classname of the pdo- Returns:
- the classid, 0 if no such class or not annotated with @
ClassId
.
-
getClassName
Gets the classname for a classid.- Parameters:
classId
- the classid- Returns:
- the name of the class, null if no such classid
-
getClassNames
Gets a list of all class names.
Sorted by name.- Returns:
- the class names
-
determineTablename
Determines the tablename from the @TableName
annotation.- Parameters:
clazz
- the class- Returns:
- the tablename, null if no such annotation
-
determineClassId
Determines the classid from the @ClassId
annotation.- Parameters:
clazz
- the class- Returns:
- the class ID, 0 if no such annotation (maybe an abstract class)
-
startKeepAliveDaemonIfNotRunning
public void startKeepAliveDaemonIfNotRunning()Starts the keep alive thread if not already running. -
terminateHelperThreads
public void terminateHelperThreads()Stops all helper threads. -
keepAliveIntervalChanged
Handles the change of a keep alive interval of a session.- Parameters:
session
- the session
-
isSomeRemoved
Inspects an expiration set and determines whether at least one object has been removed.- Parameters:
lastSerial
- the last known tableserial, ≤0 if unknownexpireSet
- the expiration setmaxSerial
- the current tableserial- Returns:
- true if some object removed
-
alignExceptionCause
Replaces exception cause probably not in the jvm's classpath when the stacktrace gets deserialized in another (usually remote) jvm.- Parameters:
t
- the throwable- Returns:
- the probably replaced throwable
-
alignTemporaryExceptionStatus
Sets the temporary flag according to the exception's root cause and the session.- Parameters:
exception
- the exception
-
isSilentRollbackSufficient
Returns whether a rollback should log all statements or not.
The rollback should not be logged, if the root-cause is not aPersistenceException
, orTentackleRuntimeException.isTemporary()
or there is another temporary exception in the exception chain.Notice that
LockException
s are usually temporary.- Parameters:
t
- the head of the exception chain causing the rollback- Returns:
- true if rollback silently, false if all statements that were rolled back are logged
-
createLazyExceptionMessage
public StringBuilder createLazyExceptionMessage(String msg, Throwable cause, Identifiable identifiable, Session session) Creates the lazy exception message for aPersistenceException
.- Parameters:
msg
- the original messagecause
- the causeidentifiable
- the identifiablesession
- the session- Returns:
- the extended message string builder
-
createFromRemoteException
public RuntimeException createFromRemoteException(Object relatedObject, RemoteException remoteException) Creates a RuntimeException from aRemoteException
.
Returns the first RuntimeException in chain. If the first non-RemoteException is not a RuntimeException, the exception is wrapped by a PersistenceException.- Parameters:
relatedObject
- the optional related object, only used if remote cause is not aPersistenceException
remoteException
- the remote exception- Returns:
- the runtime exception
-
isMultiLineExceptionMessage
protected boolean isMultiLineExceptionMessage(String msg, Throwable cause, Identifiable identifiable, Session session) Returns whether the exception message spans multiple lines.- Parameters:
msg
- the original messagecause
- the causeidentifiable
- the identifiablesession
- the session- Returns:
- true if multiple lines
-
createKeepAliveDaemon
Creates the session keep alive daemon.- Returns:
- the daemon (not started yet!)
-