Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public static final class Sessions.Db
- Object
- Sessions.Db
ImplementsSessionStore
Sessions in the server’s database, in cn1_http_session, so every
instance of a server sees every session. Attributes are stored as JSON.
Every row carries a namespace, and every query is limited to the store’s
own. Empty unless cn1.session.namespace is set, so by default every
server using the database shares its sessions – as Spring Session’s JDBC
store shares one table. Browsers do not scope cookies by port, so two
DIFFERENT servers on one host sharing a database then accept each other’s
session, sign-in included; giving each its own namespace keeps them apart,
the way Spring’s table-name setting does, while replicas of one server
keep a shared one.
Constructors
public Db(DataSource pool) | A store in the empty namespace. |
public Db(DataSource pool, String namespace) | A store whose sessions only servers with the same namespace see. |
Methods
public String getNamespace() | The namespace this store reads and writes. |
public HttpSession load(String id)
throws IOException | The session with this id, or null when there is none or it expired. |
public void save(HttpSession session, String previousId)
throws IOException | Two requests of one client load separate copies of the session, and a copy written back whole would replace whatever the other request saved meanwhile – its attributes, and a newer last use with an older one. |
public void delete(String id)
throws IOException | Forgets a session. |
public int purgeExpired(long now)
throws IOException | Drops every session that has expired by now; answers how many. |
public int size() | How many sessions are kept, or -1 when that is expensive to know. |
Inherited methods
Constructor details
Db
public Db(DataSource pool)Db
public Db(DataSource pool, String namespace)namespace see.Method details
getNamespace
public String getNamespace()load
public HttpSession load(String id)
throws IOExceptionThrows
save
public void save(HttpSession session, String previousId)
throws IOExceptionThrows
delete
public void delete(String id)
throws IOExceptionThrows
purgeExpired
public int purgeExpired(long now)
throws IOExceptionnow; answers how many.Throws
size
public int size()