TableName override?

Posts   
 
    
twaindev avatar
twaindev
User
Posts: 178
Joined: 08-Oct-2007
# Posted on: 18-Nov-2015 17:46:21   

Instead of CatalogName or SchemaName overrides I need a (partial) TableName override (don't ask me why).

I have a multi-tenant situation where the table names differ per tenant like so:

TenantA$Table1 TenantA$Table2 TenantA$Table3

TenantB$Table1 TenantB$Table2 TenantB$Table3

TenantC$Table1 TenantC$Table2 TenantC$Table3

The table definitions for the tables are exactly the same for each tenant, so I would like to access the tables by overriding the Tenant?$ prefix.

Is this possible?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 19-Nov-2015 06:25:42   

Please elaborate more. What are the real names in you DB? How are you mapping them in your model? How are you accesing them in your code? How should it be?

LLBLGen version?

David Elizondo | LLBLGen Support Team
twaindev avatar
twaindev
User
Posts: 178
Joined: 08-Oct-2007
# Posted on: 19-Nov-2015 09:34:15   

The table names in the database are like above.

Because the definitions of the sets for each tenant are exactly the same I only want to include the entities for tenantA in my model and then access the tables for the other tenants by overriding the first part of the table name. This will be for different adapter instances.

Just like you can specify another catalog or schema for each DataAccessAdapter instance, I want to access the different sets of tables by overriding part of the table names.

Using the August 2nd, 2015 version.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 19-Nov-2015 09:58:42   

Not possible at this moment: there's no logic in place which allows you to do this.

Frans Bouma | Lead developer LLBLGen Pro
twaindev avatar
twaindev
User
Posts: 178
Joined: 08-Oct-2007
# Posted on: 19-Nov-2015 10:46:30   

Was already afraid of this. Just checking I did not overlook something.

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 19-Nov-2015 10:49:22   

twaindev wrote:

Was already afraid of this. Just checking I did not overlook something.

Thanks.

To be clear: of course you can hack it in yourself in the DQE, but it's not going to be easy and gives maintenance problems. The schema looks like it comes from a DB without schemas. I'd migrate it to a catalog with schemas, but of course that might not be possible due to other software accessing it too disappointed

Frans Bouma | Lead developer LLBLGen Pro
twaindev avatar
twaindev
User
Posts: 178
Joined: 08-Oct-2007
# Posted on: 19-Nov-2015 11:03:09   

I have to deal with the database as-is. It's not mine. I indeed would have used schemas or databases for each tenant, but MS decided otherwise rage .

Any clues where to look if I want to hack it in? I will take the maintenance problem for granted as generating and using separate models (10+) will also be bothersome in this case.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 19-Nov-2015 11:15:23   

In SqlServer DQE, the SqlServerSpecificCreator class, go to the method 'CreateObjectName'. Override that in a derived class and alter 'elementName'. elementName is the name from the mapping, so the target table name. The creator is created in the DynamicQueryEngine, in CreateDbSpecificCreator(). An override of that should create your new creator which can modify the name.

The DQE is created in the DataAccessAdapter class, so a derived class of that allows you to create your custom DQE instance with the modified creator and you can then e.g. pass the string to append/transform for elementName. DQEs are created per query, as it takes no time, so if you want to use a static name read from the config file, you have to store it in a static variable too. This is done in the static ctor of DynamicQueryEngine, which isn't overridable, so that's trickier.

Frans Bouma | Lead developer LLBLGen Pro
twaindev avatar
twaindev
User
Posts: 178
Joined: 08-Oct-2007
# Posted on: 19-Nov-2015 13:14:31   

Thank you for pointing me in the right direction. I'm glad I can probably solve this with my favorite tool simple_smile

twaindev avatar
twaindev
User
Posts: 178
Joined: 08-Oct-2007
# Posted on: 20-Nov-2015 15:12:54   

Works like a charm!

Thanks again for your support.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 20-Nov-2015 16:40:50   

No problem, glad it worked out well simple_smile

Frans Bouma | Lead developer LLBLGen Pro