cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Huss <johnth...@gmail.com>
Subject Re: Switch DbEntity schema at runtime
Date Fri, 18 Nov 2016 15:55:36 GMT
The DataMap (model) is shared by the contexts.  To make them different you
need to create two different ServerRuntimes.

On Fri, Nov 18, 2016 at 3:44 AM Markus Reich <markus.reich@markusreich.at>
wrote:

> Hi,
>
> I have a very special requirement :-)
> We need to change the schema after logon (it's a JSF Tomcat WebApp)
>
> I tried the following
>
> After login
>
> final String SESSION_CONTEXT_KEY =
> SessionContextRequestHandler.class.getName() + ".SESSION_CONTEXT";
> ObjectContext context = (ObjectContext)
> session.getAttribute(SESSION_CONTEXT_KEY);
> for (DbEntity dbEntity : context.getEntityResolver().getDbEntities()) {
> if (dbEntity.getSchema().endsWith("crm")) {
> if(Helper.getCrm()!=null) dbEntity.setSchema(Helper.getCrm());
> } else if (dbEntity.getSchema().startsWith("simpleinv_")) {
> if(Helper.getEupar()!=null) dbEntity.setSchema("simpleinv_" +
> Helper.getEupar());
> }
> }
> session.setAttribute(SESSION_CONTEXT_KEY, context);
>
> The switching works, until a second session is opened! The first session
> loses the schema and get the one from the second?
>
> When I debug I have two different instances of the ObjectContext that's
> perfect, but the DbEntities are the same :-/
>
> regards
> Meex
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message