cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: Switch DbEntity schema at runtime
Date Mon, 21 Nov 2016 06:48:44 GMT
Yeah, that's pretty much the only way. Any other tricks will likely cause object id collisions
in the cache, etc.

Andrus

> On Nov 18, 2016, at 6:55 PM, John Huss <johnthuss@gmail.com> wrote:
> 
> 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
View raw message