Controlling Catalog Names with Mulitple Catalogs

Posts   
 
    
acradyn
User
Posts: 57
Joined: 03-Apr-2004
# Posted on: 24-Jun-2005 17:40:54   

Here is a list of the databases I would like to use LLBLGen for.

Catelog 1: "DB_SHARED" Catelog 2: "DB_Client_ABC" Catelog 3: "DB_Client_ZYX" Catelog n: "DB_Client_n"

I would like to generate 1 set of LLBLGen dll's that contains tables from the shared catalog called "DB_SHARED" and one set of the 'CLIENT' catelogs. As you can see, for each client, we will have a separate database set up for them but the schema in those catalog will be identical.

Example configurations:

For Client ABC, they will use these databases. Catelog 1: "DB_SHARED" Catelog 2: "DB_Client_ABC"

For Client XYZ, they will use these databases. Catelog 1: "DB_SHARED" Catelog 2: "DB_Client_XYZ"

Am I able to configure LLBLGen to use certain catalogs for certain entities? Essentially I need to specify a different catalog for some entities only.

Thanks. -Jeff

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 24-Jun-2005 18:16:08   

Yes, with adapter you will be able to specify the catalog on a per-call basis. Please consult the manual on this: Using the generated code -> Adapter -> DataAccessAdapter functionality, and then the SqlServer specific section about catalog name overwriting.

You should create a little factory which creates DataAccessAdapter instances with the catalog name set, so you can use it right away. Keep in mind that the complete object graph is saved in the catalog specified. You can't keep multiple catalogs in the same project, the name overwriting is for all catalog references.

Is this too strict for you?

Frans Bouma | Lead developer LLBLGen Pro
acradyn
User
Posts: 57
Joined: 03-Apr-2004
# Posted on: 24-Jun-2005 19:38:46   

I guess it is a little too strict. Correct me if I'm wrong, I can either override the catalog for all entities or keep the different design-time generated names in the case of using multiple catalogs.

Ideally, I need to override the catalog name for only certain entities that had a certain design-time catalog.

Is there anyway that I can customize the DataAccessAdapter in order to do this?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 25-Jun-2005 11:47:27   

acradyn wrote:

I guess it is a little too strict. Correct me if I'm wrong, I can either override the catalog for all entities or keep the different design-time generated names in the case of using multiple catalogs.

You can overwrite catalog names by config file as well, though if you have to target multiple customer databases in the same running application at runtime, that's of couse not a solution.

Ideally, I need to override the catalog name for only certain entities that had a certain design-time catalog. Is there anyway that I can customize the DataAccessAdapter in order to do this?

Yes you can do that. It requires some customization but it's possible.

The name overwriting is done in the DataAccessAdapter class at the bottom, in the HandleCatalogName routine.

That routine is called in the GetFieldPersistenceInfo* routines. Now, you can create your own daaAdapter template, by copying the original one and make some modifications to it so you get only name overwriting in the case of a special catalog name. This is best done by making the HandleCatalogName* routines protected virtual.

You then can derive a class from DataAccessAdapter and override these to do special overwriting.

Though, it's still a bit unclear to me if you want to overwrite one catalog name to a fixed different name, per running application, or per call.

Frans Bouma | Lead developer LLBLGen Pro
acradyn
User
Posts: 57
Joined: 03-Apr-2004
# Posted on: 25-Jun-2005 16:07:21   

That sounds like it might work. I'll modify the template for the DataAccessAdapter then override HandleCatalogName method. I assume I can use IFieldPersistenceInfo.SourceObjectName to get the name of the orginal entity and I'll have to keep my own meta data as to which entity goes with each catalog.

Is this called on every query for every entity? If so, this might work. Here's an example query that I need produced. (it's not real but shows my issue)

Select 

[DB_SHARED].[dba].[AllProducts].[ProductID],
[DB_SHARED].[dba].[AllProducts].[ProductName]
etc

where 

[DB_SHARED].[dba].[AllProducts].[ProductID] = [DB_CLIENT_XYZ].[dba].[OtherProducts][ProductID]

The key is overriding the catalog for certain entities, or have the ability to have multiple catalogs in one project assembly.

Though, it's still a bit unclear to me if you want to overwrite one catalog name to a fixed different name, per running application, or per call.

There are scenarios where I would do both. My application can handle data access on the client or the application server. In the later case, I would need to override it on everycall, depending on who the user is.

As long as were on the subject, how is the Multiple Catalog support supposed to work? Does it only work when the CatalogNameUsage.Default enum is used? Let's say I imported entities from 2 catalogs into my project, it appears that if any other enum value is used, the queries could look in the wrong catalog for some entities.

And, thanks for your responses!

-Jeff

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 27-Jun-2005 11:41:46   

acradyn wrote:

That sounds like it might work. I'll modify the template for the DataAccessAdapter then override HandleCatalogName method. I assume I can use IFieldPersistenceInfo.SourceObjectName to get the name of the orginal entity and I'll have to keep my own meta data as to which entity goes with each catalog.

correct.

Is this called on every query for every entity? If so, this might work. Here's an example query that I need produced. (it's not real but shows my issue)

Yes, GetFieldPersistenceInfo* methods are called for every query. There's a special catalog name handler for stored procedures, which is called from teh stored procedure call code in the adapter. If you're not using procs, don't bother simple_smile

Though, it's still a bit unclear to me if you want to overwrite one catalog name to a fixed different name, per running application, or per call.

There are scenarios where I would do both. My application can handle data access on the client or the application server. In the later case, I would need to override it on everycall, depending on who the user is.

Ok. If you need fixed name overwriting (so for this app A, you always have to overwrite the catalogname 'Foo' to 'Bar', please check the section 'Using the generated code -> Application configuration through .config files' which illustrates how to setup name overwriting in the config file for more than 1 catalog for example.

As long as were on the subject, how is the Multiple Catalog support supposed to work? Does it only work when the CatalogNameUsage.Default enum is used? Let's say I imported entities from 2 catalogs into my project, it appears that if any other enum value is used, the queries could look in the wrong catalog for some entities.

CatalogNameUsage was added to the adapter prior to the feature to support multiple catalogs in a project was added.

Normally, when you import 3 catalogs for example into your llblgen pro project, the code will just work on these 3 catalogs, transparently: you just use the single entity set.

This works because the catalog name is contained in the persistence info. If you want to target a different catalog for some of them, you have to use the .config settings to set up from-to name pairs. This isn't per call, but in almost all cases this is sufficient as name overwriting is required most of the time in situations where the development takes place on different catalogs than the production database uses.

Frans Bouma | Lead developer LLBLGen Pro
acradyn
User
Posts: 57
Joined: 03-Apr-2004
# Posted on: 27-Jun-2005 16:33:30   

Another satisfied customer! smile Thanks Frans. I'll let you know how it goes.