Sessions
For interacting with Tempus Serva records you need a session.
You can create one like this:
Session session = SessionFactory.getSession(this);
// or, in a codeunit
Session session = getSession();
All sessions need to be terminated after use (releasing DB connections etc.)
session.close();
// or
DbClose.close(session);
// or use try-with
try (Session session = SessionFactory.getSession(this)) {}
All sessions are automatically closed after Policy#apiSessionMaxLifetime (default is 30 seconds).
If you suspect your code might be running for more than that, the session can be marked asĀ long running.
This can be done durring the initialization of the session, or after the fact.
Session session = SessionFactory.getSession(context, this, 30);
// or, in a codeunit
Session session = getSession(30);
// or, after the fact
session.setLongRunningSession(30);
The above code extends the lifetime of the session by 30 seconds.
If you forget to close a session, an entry will be added to the eventlog, like this:
[ClassName] probably forgot to close session