When I saw this Side Bar Thread I knew I had to reply in a new post.
In an old company I worked for, I found a nice pice of code... repeated on every part of the application.
"The Coder", who obviously didn't knew about Sessions in Web Applications, faced the problem of a "conversational" dialog in the app. "Input 1" took parameters, retrieved some data from db, directed the user to "Listin' 1", where the user would change some values or perform some actions and finally a "Process 1" page would finish the job.
There are multiple ways to do something like that, for example a framework for working with dialogs, store some data in session and clean it at the end, use id's to reference the items / things and pass'em as parameters to the next part where the actions will be done, etc. But "The Coder" was much more "cleverest" than that, the Temporary Table was the solution.
Form 1 --> Retrieve everything and store in a "Temporary Table". "Listin' 1" --> alter Temporary Table's data. "Process 1" load temporary table data and merge in the db. This is not "too" bad, in some circumstances would be impossed by architecture or prerrequistes, but, believe me, this was not the case:
- Read Contract Header. Create Temporary Table for contract lines. Input Lines. Save Contract. Lines are stored in the Temporary Table (instead of a Map, Collection, lines table, etc).
But wait, there's more... how do you create a temporary table? "Create temporary table..." maybe? Nah, that'd be too easy... lets do it enterprisey:
String sql = "Create Table "+user.getUserName()+"_contracts_temp"+ ... columns ...
Obviously, working in multiple browser windows didn't work, too often (the table was not deleted if the user didn't use "Save Contract" button) strange things happened mixing lines from old contracts into new ones, and much more funny things.
The bad thing, those tables were present in 75% of the application, which was running a 8.000M€ (european millions, that's like 8.000.000.000€) company and providing near 100M revenues to the developing company. Five years after, having not repaired redone the application, SAP came and the contract was lost.