« Making Code Work | HomePage | Wow - Schumi at Grid Start for Montreal »
07 June 2005
Making Code Work
Last so many days were spent on Code Review and Unit Testing for my current project application. I see Code Review as a very important & fruitful exercise. It helps removing many bugs by just following code and those which may not come up in testing, as Test Cases are not always exhaustive for each and every condition. By doing a code review you can mentally test each programming constructs and paths.
Testing brings to surface some very peculiar issues and which makes you hate LN (my project is still for R5). Lotus free form structure for storage is a boon as well as a bane. While it helps rapid development without the need to bother about relational constraints and data structure normalization, but this sometimes leads to issues when Data Integrity is of concern. The behavior of various NotesObjects and their methods which are based on the FT Index are unpredictable unlike RDBMS where you are assured of a consistent implementation. Index update delays or In-memory objects statuses can lead you to bang your head against the Screen figuring out the problem reasons.
So here I have lot of my code using NotesView.getDocumentByKey methods to put basic referential integrity among related data. Yeah a RDBMS would have been a best option here, but as pointed out in the earlier post - Code Works, one of the objective was to reuse the in-place setup of Lotus Workflow/Notes and thus minimize investment costs.
Now we have checks at various places to not allow data duplication if those records with matching keywords exist. This works in ideal situations, situations where after every document delete/update you give Notes sufficient time to update its Index or cache or whatever it is. But our test cases failed when we deleted document and immediately in the same session created new records. So our hidden views, used by getDocumentByKey are not getting immediately refreshed. Even closing all application windows won't work. So is this Indexing problem? Tweaking any View/DB property won't help. And when we restart Notes after deleting documents, the validation works. So is this Notes client cache problem? But these methods don't have any "Nocache" attribute.
Trial and error and we used NotesDatabase.search for these checks instead of NotesView.getDocumentByKey and this works for any kind of monkey-usage of the application. And we had no problem here with View Index or cache or whatever it is. But theres issue of App. performance using this method. Ashish suggested of using NotesView.Refresh before invoking the getDocument methods. Now this method is suppose to update your NotesView objects with the datastore image during the same code process, so any further modifications/reference has access to the current document copies/count. But in my case I am performing a process, close & restart my application and then deleting/updating some documents manually to create Test conditions and again running the code process to repeat the earlier action. This ideally means all my variables/objects are destroyed & recreated - an if recreated then they are suppose to be representing the latest datastore state.
But it worked. A combination of NotesView.refresh and NotesView.getDocumentbykey gives you the current state of data. So this was a case of in-memory objects getting cached for the session. But why can't we have application session which destroys all in-memory objects as soon as when application is out of scope without having to restart Notes or doing manual Object destroy.
20:12 Posted in Lotus , Musings , My Work | Permalink




