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 int
MAX_DATA_ACCESSORS
Maximal 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 void
activate(ICelesta celesta, String procName)
Activates CallContext with 'live' Celesta and procName.void
close()
void
commit()
Commits the current transaction.void
decDataAccessorsCount()
Decrements counter of open data accessor objects.ICelesta
getCelesta()
Returns Celesta instance.Connection
getConn()
Returns active database JDBC connection.CallContext
getCopy()
Duplicates callcontext with another JDBC connection.DBAdaptor
getDbAdaptor()
Returns aDBAdaptor
of current Celesta instance.int
getDBPid()
Returns Process Id of current connection to the database.long
getDurationNs()
Returns number of nanoseconds since CallContext activation.BasicDataAccessor
getLastDataAccessor()
Returns the last data accessor object.ILoggingManager
getLoggingManager()
Returns aILoggingManager
of current Celesta instance.IPermissionManager
getPermissionManager()
Returns aIPermissionManager
of current Celesta instance.String
getProcName()
Returns procedure name that was initially called.Score
getScore()
Returns score of current Celesta instance.Date
getStartTime()
Returns the calendar date of CallContext activation.String
getUserId()
Returns name of the current user.void
incDataAccessorsCount()
Increments counter of open data accessor objects.boolean
isClosed()
If this context is closed.void
rollback()
Rollbacks the current transaction.void
setLastDataAccessor(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:
getConn
in 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:
null
for not activated context
-
getScore
public Score getScore()
Returns score of current Celesta instance.- Specified by:
getScore
in 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:
isClosed
in interfaceICallContext
- Returns:
-
getPermissionManager
public IPermissionManager getPermissionManager()
Returns aIPermissionManager
of current Celesta instance.- Returns:
-
getLoggingManager
public ILoggingManager getLoggingManager()
Returns aILoggingManager
of current Celesta instance.- Returns:
-
getDbAdaptor
public DBAdaptor getDbAdaptor()
Returns aDBAdaptor
of current Celesta instance.- Specified by:
getDbAdaptor
in interfaceICallContext
- Returns:
-
close
public final void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceICallContext
-
getCopy
public CallContext getCopy()
Duplicates callcontext with another JDBC connection.- Returns:
-
-