Throw exception if schema used connection string is incorrect

Posts   
 
    
Posts: 62
Joined: 14-Feb-2017
# Posted on: 28-May-2020 18:50:13   

Hi,

I'm using LLBLGEN with .net core/oracle and need to overwrite the name of the schema because I schema used to generate the entities can be different on our customer databases.

To do it,I use the AddSchemaNameOverwrite(fromName, toName) method and it works but...

For some reason, we add to rename the schema of the database which we use to generate the entities. To do it, we just open the llblgenproj, find/replace the schema name but forgot to the rename the "[b]fromName[/b]" parameter of the AddSchemaNameOverwrite.

And it works ... until we launch the application on a schema which differ from the one used to generate the entities.

Exemple : * AddSchemaNameOverwrite("NEPTUNE_AC", "XXXXX") * Rename NEPTUNE_AC to NEPTUNE_AC_DEV

Because NEPTUNE_AC doesn't exist anymore in llblgenproj, AddSchemaNameOverwrite doesn't find anything to overwrite.

=> Don't really know how you implemented this replacement but would it be possible for you to check that the fromName exists and throw an exception if not ?

Actually, I have an OracleException "ORA-00932 Table or view doesn't exist".

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39761
Joined: 17-Aug-2003
# Posted on: 29-May-2020 09:45:53   

gilles.marceau wrote:

Hi,

I'm using LLBLGEN with .net core/oracle and need to overwrite the name of the schema because I schema used to generate the entities can be different on our customer databases.

To do it,I use the AddSchemaNameOverwrite(fromName, toName) method and it works but...

For some reason, we add to rename the schema of the database which we use to generate the entities. To do it, we just open the llblgenproj, find/replace the schema name but forgot to the rename the "[b]fromName[/b]" parameter of the AddSchemaNameOverwrite.

If you want to rename a schema, just rightclick the name in catalog explorer -> rename.

And it works ... until we launch the application on a schema which differ from the one used to generate the entities.

Exemple : * AddSchemaNameOverwrite("NEPTUNE_AC", "XXXXX") * Rename NEPTUNE_AC to NEPTUNE_AC_DEV

Because NEPTUNE_AC doesn't exist anymore in llblgenproj, AddSchemaNameOverwrite doesn't find anything to overwrite.

The generated code contains the name of the schema. To rename that at runtime you can either do that through config file/RuntimeConfiguration settings which are global. Or you can do it per call on the DataAccessAdapter class https://www.llblgen.com/Documentation/5.7/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/Adapter/gencode_dataaccessadapter_adapter.htm#multi-tenancy-support-schema-specific-persistence-info-db2-oracle-postgresql-sql-server

But I don't really understand what you want to do: the generated code has schema XYZ, you need to run that on a database with schema ABC, then rename XYZ to ABC using the config file settings. If you then have to run it on another database EFG, change ABC in the config file to EFG...

=> Don't really know how you implemented this replacement but would it be possible for you to check that the fromName exists and throw an exception if not ?

Well, I think the solution is to properly define your schema name as it is in development and then you can define it at runtime to whatever you want. Or create a small config file yourself which defines for that generated code the from/to if you need to. It feels you created this problem to yourself? simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Posts: 62
Joined: 14-Feb-2017
# Posted on: 29-May-2020 11:53:14   

f you want to rename a schema, just rightclick the name in catalog explorer -> rename.

Now, I know this command exists smile

But I don't really understand what you want to do: the generated code has schema XYZ, you need to run that on a database with schema ABC, then rename XYZ to ABC using the config file settings. If you then have to run it on another database EFG, change ABC in the config file to EFG...

Yes but if XYZ has been renamed to ZYX in the designer then rename XYZ to ABC using the config file settings will not do anything and an error table or view doesn't exist will be thrown instead of something like "you try to overwrite the schema XYZ to ABC but XYZ schema doesn't exist" Does it make sense?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39761
Joined: 17-Aug-2003
# Posted on: 30-May-2020 11:31:36   

gilles.marceau wrote:

f you want to rename a schema, just rightclick the name in catalog explorer -> rename.

Now, I know this command exists smile

But I don't really understand what you want to do: the generated code has schema XYZ, you need to run that on a database with schema ABC, then rename XYZ to ABC using the config file settings. If you then have to run it on another database EFG, change ABC in the config file to EFG...

Yes but if XYZ has been renamed to ZYX in the designer then rename XYZ to ABC using the config file settings will not do anything and an error table or view doesn't exist will be thrown instead of something like "you try to overwrite the schema XYZ to ABC but XYZ schema doesn't exist" Does it make sense?

If XYZ was renamed to ZYX in the designer, then the config file has to be adjusted, but that's the thing: someone renamed that schema in the designer. When the code for production (where the rename is required) is generated, I think it's known what was renamed to what?

Or is this caused by some merge conflict resolve? Someone ordered to rename the schema, right?

Frans Bouma | Lead developer LLBLGen Pro
Posts: 62
Joined: 14-Feb-2017
# Posted on: 02-Jun-2020 09:00:28   

If XYZ was renamed to ZYX in the designer, then the config file has to be adjusted, but that's the thing: someone renamed that schema in the designer. When the code for production (where the rename is required) is generated, I think it's known what was renamed to what?

For sure

Or is this caused by some merge conflict resolve? Someone ordered to rename the schema, right?

Exactly.

This is something we can live this but I thought it could be great if tools can help us to find the reason. If you don't find useful, close the issue, no matter

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39761
Joined: 17-Aug-2003
# Posted on: 02-Jun-2020 10:35:56   

gilles.marceau wrote:

If XYZ was renamed to ZYX in the designer, then the config file has to be adjusted, but that's the thing: someone renamed that schema in the designer. When the code for production (where the rename is required) is generated, I think it's known what was renamed to what?

For sure

Or is this caused by some merge conflict resolve? Someone ordered to rename the schema, right?

Exactly.

This is something we can live this but I thought it could be great if tools can help us to find the reason. If you don't find useful, close the issue, no matter

I think it's so specific for your project that it's not really useful to add code for this. Additionally, the problem is that the error reported by Oracle is generic, so we can't really do anything there either, even if we would do anything... as the solution you'd want of course is that the code would see the exception and then automatically rename the schema to the right one (whatever that is). Sorry, but that's not in the cards right now.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 62
Joined: 14-Feb-2017
# Posted on: 03-Jun-2020 09:24:22   

No, you misunderstood what I wanted. I just wanted you to throw an exception when the AddSchemaNameOverwrite(fromName, toName) method is used with a fromName parameter you don't find during the replacement because it doesn't exist.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39761
Joined: 17-Aug-2003
# Posted on: 03-Jun-2020 10:18:50   

It then still needs to be opt-in, as it might be the system as it is at that time has for instance 3 name overwrites defined, and one is active at that moment.

So an opt-in setting which throws when a name-overwrite doesn't match an existing from name. That's doable, however not sure if the end result is any less problematic: you still get an exception. It now doesn't have an Oracle error but our own exception: you still have to manually go in and change the from name. The oracle error also is a give away that the from name isn't present. What do you have in mind to do with the exception?

Frans Bouma | Lead developer LLBLGen Pro
Posts: 62
Joined: 14-Feb-2017
# Posted on: 04-Jun-2020 10:33:16   

OK, I close