[OCP 11 Complete Study Guide] [OCP 11 Programmer I Book] [OCP 11 Programmer II Book] [OCP 11 Practice Tests Book] [OCA 8 Book] [OCP 8 Book] [OCP 8 Practice Tests Book] [Blog]
Graeme Byers wrote:2. In real life most inserts will work - so why check first before inserting ? It's a waste of a call.
Graeme Byers wrote:3. The idea that PKs should preferably be generated by sequences seems silly - a PK might be customerNumber + paymentDate or a String.
[OCP 11 Complete Study Guide] [OCP 11 Programmer I Book] [OCP 11 Programmer II Book] [OCP 11 Practice Tests Book] [OCA 8 Book] [OCP 8 Book] [OCP 8 Practice Tests Book] [Blog]
Paul Sturrock wrote:...though just to add unless you are pessimistically locking a table to perform an insert this approach can't work 100% of the time. For primary keys I prefer delegating to a trustable key generation pattern, e.g. a sequence. I agree otherwise - conditional logic based on exception is bad.
[OCP 11 Complete Study Guide] [OCP 11 Programmer I Book] [OCP 11 Programmer II Book] [OCP 11 Practice Tests Book] [OCA 8 Book] [OCP 8 Book] [OCP 8 Practice Tests Book] [Blog]
Martin Vajsar wrote:With application key generator, you need a lot of work (I'm inferring this much from the statement "They are wonderful things when implemented correctly.") to implement a feature that is already present in the database.
Martin Vajsar wrote:I personally see database independence as one of the worst paradigms perpetuating the Java world.
Martin Vajsar wrote:If I had to design database independent architecture, I'd probably try to put all the dependent logic into stored procedures
[OCP 11 Complete Study Guide] [OCP 11 Programmer I Book] [OCP 11 Programmer II Book] [OCP 11 Practice Tests Book] [OCA 8 Book] [OCP 8 Book] [OCP 8 Practice Tests Book] [Blog]
Scott Selikoff wrote:The advantage is that you can do multiple inserts on a single trip to the database since you can create all ids ahead of time. For example, let's say you need to insert a user and 3 addresses (4 records total). By using an application-level key generator you can set the parent-child relationship on all 4 records before ever communicating with the database. If you rely on database sequences, you need to insert the user first then read the generated keys before being able to insert the addresses, requiring multiple trips [alternatively you could use a stored procedure].
Scott Selikoff wrote:And because I hear this all the time, "Yes, it is possible to change an applications database in the real world". I've been hired to do it multiple times and its rarely 'fun', definitely not for the faint of heart.
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Consider Paul's rocket mass heater. |