Bug #7567
use Session.PK instead of DatabaseManager.PRIMARY_KEY wherever possible
80%
History
#1 Updated by Eric Faulhaber about 3 years 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 about 3 years 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 almost 3 years ago
- Status changed from New to WIP
- Assignee set to Ștefan-Andrei Tocilă
#5 Updated by Alexandru Lungu almost 3 years ago
- Assignee changed from Ștefan-Andrei Tocilă to Dănuț Filimon
#6 Updated by Dănuț Filimon almost 3 years 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 over 2 years 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.
- Have the key named
RECIDand test. We should have close to noDirect access fail. - Have the key named
IDand test. There should be a lot ofDirect access fail, but the application still working. - Add your modifications from 7567a and keep the key named
ID. We should have (again) close to noDirect 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 over 2 years 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 over 2 years 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 over 2 years ago
Alexandru Lungu wrote:
Danut, please double check:
searchPathandpropathin 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 over 2 years 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 over 2 years ago
- 7567a without changes -
primaryKeyName="recid"andpersistence/primary-key-namewith "recid". Everything worked well, there were no problems during conversion or testing the application. - 7567a without changes -
primaryKeyName="id"andpersistence/primary-key-namewith "id". During conversion, I got a lot oforg.postgresql.util.PSQLException: ERROR: column "recid" of relation "..." does not exist; - 7567a patched and slightly modified to fit the new DirectAccessHelper changes -
primaryKeyName="recid"andpersistence/primary-key-namewith "recid". Worked properly. - 7567a patched and slightly modified to fit the new DirectAccessHelper changes -
primaryKeyName="id"andpersistence/primary-key-namewith "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 over 2 years 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.