Yes, it works! Thanks@all.

First I have built a template model for the database objects in one
slave schema (all slave schemas are identical). The plist file contains
no schema name for the DB objects and has the wrong connection (to the
template slave account).

Now I have an EOModel for the table within the master account which
holds all the slave schema names. It is loaded into the default model
group. The schema name list I read in an array and then I go through the
elements:

for (Schema s : schemaList) {

try {
  EOModelGroup group = new EOModelGroup();
  EOSchemaModel model = new EOSchemaModel(s.oraUname(), def.toURL());

  model.setConnectionDictionary(masterConnect);
  model.setUserInfo(NSDictionary.EmptyDictionary);

  group.addModel(model);
  EOObjectStoreCoordinator coord = new EOObjectStoreCoordinator();
  EOModelGroup.setModelGroupForObjectStoreCoordinator(coord, group);
                                
  coordList.put(s.oraUname(), coord);

} catch (Exception ex) {
  NSLog.out.appendln(ex);
}
}

The variable "def" contains a File instance to the template model
definition folder on the server (slaveTemp.eomodeld). Btw, is there a
short way to the user.dir/Contents/Resources folder, without hard-coded
folder names?

Instead the EOModel I have used a subclass called EOSchemaModel:

public class EOSchemaModel extends EOModel {

 private final String schemaName;

 public EOSchemaModel(String schemaName, URL url) {
  super(url);   // FIXME: this could be problematic
  this.schemaName = schemaName;
 }

 @Override
 public Object _addEntityWithPropertyList(Object propertyList) throws
   InstantiationException, IllegalAccessException {

  String externalName = (String)
    ((NSDictionary)propertyList).objectForKey("externalName");

  if (externalName != null) {
   if (!externalName.startsWith(this.schemaName)) {
        ((NSDictionary) propertyList).remove("externalName");
        ((NSDictionary) propertyList).put("externalName",
            this.schemaName + "." + externalName);
   }
  }
  return super._addEntityWithPropertyList(propertyList);
 }
}

The FIXME above points to the situation, that the EOModel is already
initialized, but the schemaName is not set yet. If the constructor of
EOModel calls _addEntityWithPropertyList(), I will get wrong externalNames.

I stored the EOObjectStoreCoordinator list within the Application class,
so I have access with the schema name to the dedicated
EOObjectStoreCoordinator instance, which helps me to create an
EOEditingContext for the schema.

The users of my webservice can access multiple slaves, but only one with
one service request, so it is very easy to look into the right model.
Every request points to a specific project name, which is related to one
(and only one) slave schema.

Thank you for all ideas!
André

On 16.12.2017 00:35, Chuck Hill wrote:
> Yeah, it is not straight-forward at all.  You need to always know where
> you are getting your data from.  If it is session based, you just set
> this up when the session is created which simplified things somewhat. 
> These EOF stacks need to be strictly isolated, so getting a few of Foos
> across multiple slaves is just not possible in terms of a single fetch. 
> You can fetch on each slave and then mash them together in an array, but
> the objects in the array will not all share the same EC.  Personally,
> I’d run away.
> 
>  
> 
> Chuck
> 
>  
> 
>  
> 
> *From: *Paul Hoadley <pa...@logicsquad.net>
> *Date: *Friday, December 15, 2017 at 2:54 PM
> *To: *Chuck Hill <ch...@gevityinc.com>
> *Cc: *André Rothe <andre.ro...@phosco.info>, WebObjects-Dev
> <webobjects-dev@lists.apple.com>
> *Subject: *Re: Using database objects in different schemas
> 
>  
> 
> Hi Chuck,
> 
>  
> 
> On 16 Dec 2017, at 6:17 am, Chuck Hill <ch...@gevityinc.com
> <mailto:ch...@gevityinc.com>> wrote:
> 
>  
> 
>     I think you can make it work, but it is going to need a database
>     connection for each slave.  And there can’t be relationships between
>     slaves or between the master and the slave.  And it is going to be
>     susceptible to “bad assumption” errors in Wonder (I think that
>     version of EOF is OK).
> 
>      
> 
>     What you would need to do is to create a new EOModelGroup for each
>     slave and copy (not a reference, a brand new object) the models into
>     it, adding the schema to the table names.  That avoids the need to
>     tweak the SQL. They you need to create a new
>     EOObjectStoreCoordinator for each of these groups. 
>     EOObjectStoreCoordinators don’t co-operate so the duplicate GID
>     should be OK.  Then make sure that your code uses the correct
>     EOObjectStoreCoordinator to create EOEditingContexts in. 
> 
>      
> 
>     I **think** that will work, I have never tried it.  Using the
>     EOSharedEditingContext with objects in the slave tables is going to
>     challenging as a lot of code is going to assume that there is only
>     one, not per EOObjectStoreCoordinator.  I’d avoid the
>     EOSharedEditingContext.  The other place where you may run into
>     problems is notifications that are not scoped to the
>     EOObjectStoreCoordinator. 
> 
>      
> 
>     But all in all, this is not really what EOF is meant for.  With EOF
>     you would use a different data model for this sort of multi-tenant
>     solution.
> 
>  
> 
> Does all of this require “deep” knowledge at the application level of
> what’s going on in the database? To get it set up, as you describe
> above, obviously it does, but then beyond that, say André wants a
> particular Foo object—does he need to know where to ask for it from? Or
> say he wants all Foo objects—doesn’t he now need to go ask for all Foos
> from each stack? I got the impression from the original post that he
> wanted a kind of merged view over all these tables, which presumably
> just isn’t possible.
> 
>  
> 
>  
> 
> -- 
> Paul Hoadley
> https://logicsquad.net/
> https://www.linkedin.com/company/logic-squad/
> 
>  
> 
>  
> 
> 
> 
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/andre.rothe%40zks.uni-leipzig.de
> 
> This email sent to andre.ro...@zks.uni-leipzig.de
> 

-- 
UNIVERSITÄT LEIPZIG
Medizinische Fakultät
Zentrum für Klinische Studien Leipzig – KKS
André Rothe
CIO
Härtelstr. 16-18, 04107 Leipzig

Tel: 0341/ 97 16118
Fax: 0341/ 97 16189
WWW: http://www.zks.uni-leipzig.de

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to