Class Sessions.Db
java.lang.Object
com.codename1.backend.Sessions.Db
- All Implemented Interfaces:
SessionStore
- Enclosing class:
Sessions
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.
-
Constructor Summary
ConstructorsConstructorDescriptionDb(DataSource pool) A store in the empty namespace.Db(DataSource pool, String namespace) A store whose sessions only servers with the samenamespacesee. -
Method Summary
Modifier and TypeMethodDescriptionvoidForgets a session.The namespace this store reads and writes.The session with this id, or null when there is none or it expired.intpurgeExpired(long now) Drops every session that has expired bynow; answers how many.voidsave(HttpSession session, String previousId) 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.intsize()How many sessions are kept, or -1 when that is expensive to know.
-
Constructor Details
-
Db
A store in the empty namespace. -
Db
A store whose sessions only servers with the samenamespacesee.
-
-
Method Details
-
getNamespace
The namespace this store reads and writes. -
load
Description copied from interface:SessionStoreThe session with this id, or null when there is none or it expired.- Specified by:
loadin interfaceSessionStore- Throws:
IOException
-
save
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. So an existing session is saved by re-reading the row, applying only the attributes THIS request set or removed, and writing it back only if its version has not moved; the last use only ever goes forward.- Specified by:
savein interfaceSessionStore- Throws:
IOException
-
delete
Description copied from interface:SessionStoreForgets a session.- Specified by:
deletein interfaceSessionStore- Throws:
IOException
-
purgeExpired
Description copied from interface:SessionStoreDrops every session that has expired bynow; answers how many.- Specified by:
purgeExpiredin interfaceSessionStore- Throws:
IOException
-
size
public int size()Description copied from interface:SessionStoreHow many sessions are kept, or -1 when that is expensive to know.- Specified by:
sizein interfaceSessionStore
-