Package ru.curs.celesta
Class CallContext
- java.lang.Object
-
- ru.curs.celesta.CallContext
-
- All Implemented Interfaces:
AutoCloseable,ICallContext
- Direct Known Subclasses:
SystemCallContext
public class CallContext extends Object implements ICallContext
Call context containing a DB connection carrying a transaction and a user identifier.
-
-
Field Summary
Fields Modifier and Type Field Description static intMAX_DATA_ACCESSORSMaximal number of accessors that can be opened within single context.
-
Constructor Summary
Constructors Constructor Description CallContext(String userId)Creates new not activated context.CallContext(String userId, ICelesta celesta, String procName)Creates activated context.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivate(ICelesta celesta, String procName)Activates CallContext with 'live' Celesta and procName.voidclose()voidcommit()Commits the current transaction.voiddecDataAccessorsCount()Decrements counter of open data accessor objects.ICelestagetCelesta()Returns Celesta instance.ConnectiongetConn()Returns active database JDBC connection.CallContextgetCopy()Duplicates callcontext with another JDBC connection.DBAdaptorgetDbAdaptor()Returns aDBAdaptorof current Celesta instance.intgetDBPid()Returns Process Id of current connection to the database.longgetDurationNs()Returns number of nanoseconds since CallContext activation.BasicDataAccessorgetLastDataAccessor()Returns the last data accessor object.ILoggingManagergetLoggingManager()Returns aILoggingManagerof current Celesta instance.IPermissionManagergetPermissionManager()Returns aIPermissionManagerof current Celesta instance.StringgetProcName()Returns procedure name that was initially called.ScoregetScore()Returns score of current Celesta instance.DategetStartTime()Returns the calendar date of CallContext activation.StringgetUserId()Returns name of the current user.voidincDataAccessorsCount()Increments counter of open data accessor objects.booleanisClosed()If this context is closed.voidrollback()Rollbacks the current transaction.voidsetLastDataAccessor(BasicDataAccessor dataAccessor)Set the last data accessor object.
-
-
-
Field Detail
-
MAX_DATA_ACCESSORS
public static final int MAX_DATA_ACCESSORS
Maximal number of accessors that can be opened within single context.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CallContext
public CallContext(String userId)
Creates new not activated context.- Parameters:
userId- User identifier. Cannot be null or empty.
-
-
Method Detail
-
activate
public void activate(ICelesta celesta, String procName)
Activates CallContext with 'live' Celesta and procName.- Parameters:
celesta- Celesta to use CallContext with.procName- Name of the called procedure (for logging/audit needs).
-
getConn
public Connection getConn()
Returns active database JDBC connection.- Specified by:
getConnin interfaceICallContext- Returns:
-
getUserId
public String getUserId()
Returns name of the current user.- Returns:
-
commit
public void commit()
Commits the current transaction. Will cause error for not-activated or closed context.Wraps SQLException into CelestaException.
-
rollback
public void rollback()
Rollbacks the current transaction. Does nothing for not-activated context.Wraps SQLException into CelestaException.
-
getCelesta
public ICelesta getCelesta()
Returns Celesta instance.- Returns:
nullfor not activated context
-
getScore
public Score getScore()
Returns score of current Celesta instance.- Specified by:
getScorein interfaceICallContext- Returns:
-
setLastDataAccessor
public void setLastDataAccessor(BasicDataAccessor dataAccessor)
Set the last data accessor object.- Parameters:
dataAccessor- data accessor object
-
incDataAccessorsCount
public void incDataAccessorsCount()
Increments counter of open data accessor objects.- Throws:
CelestaException- if the maximal limit of data accessors is exceeded.
-
decDataAccessorsCount
public void decDataAccessorsCount()
Decrements counter of open data accessor objects.
-
getLastDataAccessor
public BasicDataAccessor getLastDataAccessor()
Returns the last data accessor object.- Returns:
-
getDBPid
public int getDBPid()
Returns Process Id of current connection to the database.- Returns:
-
getProcName
public String getProcName()
Returns procedure name that was initially called.- Returns:
-
getStartTime
public Date getStartTime()
Returns the calendar date of CallContext activation.- Returns:
-
getDurationNs
public long getDurationNs()
Returns number of nanoseconds since CallContext activation.- Returns:
-
isClosed
public boolean isClosed()
If this context is closed.- Specified by:
isClosedin interfaceICallContext- Returns:
-
getPermissionManager
public IPermissionManager getPermissionManager()
Returns aIPermissionManagerof current Celesta instance.- Returns:
-
getLoggingManager
public ILoggingManager getLoggingManager()
Returns aILoggingManagerof current Celesta instance.- Returns:
-
getDbAdaptor
public DBAdaptor getDbAdaptor()
Returns aDBAdaptorof current Celesta instance.- Specified by:
getDbAdaptorin interfaceICallContext- Returns:
-
close
public final void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceICallContext
-
getCopy
public CallContext getCopy()
Duplicates callcontext with another JDBC connection.- Returns:
-
-