Generics and IDs
August 25th, 2008 Graham Sanderson
Historically in our Teamworks product, identifiers for all objects persisted in the database were BigDecimal. Since there was no type information associated with the BigDecimal, it was possible to introduce bugs where the ID of an object of type A was passed to a method expecting the ID of an object of type B. Depending on the situation, this could cause an exception, or silent incorrect behavior.
When we came to write Blueprint, we had a clean slate, and wanted to do better. In addition we had the (at the time) luxury of using JDK5.0.
IDs in Blueprint, are 64 bit DB-local values. No two entities have the same ID even if they are of different types (this isn’t necessary, but provides added safety and security)
For Blueprint, our main goal was compile time type safety. It should be a compiler error to pass the wrong type of ID to a function. Other than that we wanted IDs to be as small as possible, and we had no requirement for run time introspection of types (by specifying type information everywhere in the source we can guarantee that compile time type safety translates to run type type safety)
Read the rest of this entry »
Posted in Java | No Comments »