Project

General

Profile

Bug #7567

use Session.PK instead of DatabaseManager.PRIMARY_KEY wherever possible

Added by Eric Faulhaber 10 months ago. Updated 6 months ago.

Status:
WIP
Priority:
Normal
Target version:
-
Start date:
Due date:
% Done:

80%

billable:
No
vendor_id:
GCD
case_num:

History

#1 Updated by Eric Faulhaber 10 months ago

Session.PK was introduced during our ORM refactoring (when we removed Hibernate from FWD), to represent the configurable name of the surrogate primary key. This role already was being served in part by the static variable DatabaseManager.PRIMARY_KEY, but this class was not available for use in all situations where the primary key name was needed (e.g., database import). This is due to DatabaseManager's separate dependencies on the directory (only used at runtime), from which it pulls configuration for other purposes.

The result is technical debt, in that both variables are used across classes now in a seemingly arbitrary way, which has made a bit of a mess. Furthermore, the runtime value of DatabaseManager.PRIMARY_KEY depends upon the value of Session.PK being set first during server bootstrap.

To the degree possible, I would like to eliminate DatabaseManager.PRIMARY_KEY altogether, and only be left with Session.PK. Some analysis is required to ensure this replacement is safe in all use cases. This includes both normal runtime use, as well as special cases which do not require the FWD server to be running (such as database import).

#3 Updated by Alexandru Lungu 10 months ago

This should also be extended to FWD-H2 direct-access, as it presumes that the primary key column is always named recid, so it doesn't honor the real name. For that, consider propagating the FWD name of the primary key to FWD-H2, so it can properly do the invariant check.

#4 Updated by Alexandru Lungu 9 months ago

  • Status changed from New to WIP
  • Assignee set to Ștefan-Andrei Tocilă

#5 Updated by Alexandru Lungu 8 months ago

  • Assignee changed from Ștefan-Andrei Tocilă to Dănuț Filimon

#6 Updated by Dănuț Filimon 8 months ago

Committed 7567a/rev.14714 and 7567a_h2/rev.27. Removed DatabaseManager.PRIMARY_KEY and replaced it's usage with Session.PK. The flag was removed entirely because Session.PK is instantiated really early at server bootstrap. I managed to test the database import on a customer application and there were no problems at all. Sadly I did not manage to run the customer application (just the server startup which was enough to confirm that DatabaseManager.PRIMARY_KEY is instantiated after Session.PK) because of a configuration problem.

#7 Updated by Alexandru Lungu 6 months ago

  • % Done changed from 0 to 80

7567a_h2 reached FWD-H2 trunk, which ultimately is delivered with the FWD trunk as fwd-h2-1.33-trunk.
I also rebased 7567a to the latest trunk and is now at rev 14793.

Danut, please do a final check of the changes before moving this into the review phase. Please focus on the following scenario:
  • Have the key named RECID and test. We should have close to no Direct access fail.
  • Have the key named ID and test. There should be a lot of Direct access fail, but the application still working.
  • Add your modifications from 7567a and keep the key named ID. We should have (again) close to no Direct access fail.

Do some smoke tests with a large application. I can do regression testing, but it will be a bit time consuming. Therefore, mind having everything in place when moving this into Review.

#8 Updated by Dănuț Filimon 6 months ago

I had to make a few small changes to DirectAccessHelper to fit the changes made in H2. When I tried to test Hotel_GUI, the project did not working even after configuring it again from zero. I can't get past the login screen because it can't find the adm2/smart.p file.

#9 Updated by Alexandru Lungu 6 months ago

Danut, please double check: searchPath and propath in directory.xml and propath in p2j.cfg.xml. Is smart.p at least converted to Java?

#10 Updated by Dănuț Filimon 6 months ago

Alexandru Lungu wrote:

Danut, please double check: searchPath and propath in directory.xml and propath in p2j.cfg.xml. Is smart.p at least converted to Java?

The problem was with the searchPath and propath, they were not configured properly. Thank you!

#11 Updated by Dănuț Filimon 6 months ago

It seems that the "recid" is hard coded in SchemaConfig and is used by the meta database, this causes the server to fail at startup when the primary key name configured in p2j.cfg.xml is different.

#12 Updated by Dănuț Filimon 6 months ago

Here are the current scenarios that I tested with Hotel_GUI:
  • 7567a without changes - primaryKeyName="recid" and persistence/primary-key-name with "recid". Everything worked well, there were no problems during conversion or testing the application.
  • 7567a without changes - primaryKeyName="id" and persistence/primary-key-name with "id". During conversion, I got a lot of org.postgresql.util.PSQLException: ERROR: column "recid" of relation "..." does not exist;
  • 7567a patched and slightly modified to fit the new DirectAccessHelper changes - primaryKeyName="recid" and persistence/primary-key-name with "recid". Worked properly.
  • 7567a patched and slightly modified to fit the new DirectAccessHelper changes - primaryKeyName="id" and persistence/primary-key-name with "id". Same problem during conversion;

There seems to be an existent issue with using a different primary key name or I did not set it up properly. For the configuration I used <schema primaryKeyName="id"> in p2j.cfg.xml and added

<node class="string" name="primary-key-name">
  <node-attribute name="value" value="id"/>
</node>
in the directory.xml file. Another issue is that I could not find any wiki documentation for this, just a configuration in another issue which is quite old and I am not sure if this is how the primary key should be used.

#13 Updated by Greg Shah 6 months ago

If only we completed #7782, we could remove this useless id workaround code. Problems like the above are just extra cost for no value.

Also available in: Atom PDF