Skip to main content

Timeline for Generic DAO written in Java

Current License: CC BY-SA 3.0

8 events
when toggle format what by license comment
Dec 3, 2013 at 17:55 comment added David Harkness @AseemBansal A common approach taken by ORMs is to require a Serializable primary key. This handles Integer, Timestamp and even compound keys such as VehicleKey { String state, String plate }.
Dec 3, 2013 at 16:02 comment added Aseem Bansal About mapping the pojo for determining whether a row with the primary key exists, I did that to make the generic-ness of the DAO consistent. Suppose a table had a primary key stored as Timestamp then it would need a Timestamp object passed. If I added a type parameter for primary key's data type then there will be a huge maintainability problem in case the schema changes i.e. all function calls from other tiers of architecture will have to be changed. Pojo aka DTO was the only thing I placed the restriction on. That's the least denominator that I thought people could maintain.
Dec 3, 2013 at 14:23 comment added Aseem Bansal I'll take a look at reflection. I got the same suggestion on programmers also. Currently the whole thing is small but it will become a huge monster, at least Oracle Specifics will, in the long run. Your response is much appreciated.
Dec 3, 2013 at 14:20 comment added Aseem Bansal Good point about inlining the return statements. About there being nothing Oracle Specific. Yeah totally correct. Currently there isn't anything. I had to deal with Oracle so I made Oracle classes only. But the structure of the DAO itself allows it to be used for others, I think. I kept it separate for extensibility. About TableName enum containing specific state I'll update the question. I know that the current implementation is not actually generic (plain English intended). The Oracle Specifics and the lower classes are a big concern.
Dec 3, 2013 at 6:01 history edited h.j.k. CC BY-SA 3.0
changed post-edit numbered list to bulleted list to minimize confusion.
Dec 3, 2013 at 5:40 history edited h.j.k. CC BY-SA 3.0
added link to Spring class, and more additions post-edit (clearly marked).
Dec 3, 2013 at 5:30 comment added David Harkness +1 Nice catch on #3! Change the first method to simply look for the PK without loading the POJO.
Dec 3, 2013 at 4:14 history answered h.j.k. CC BY-SA 3.0