In last few years I was lucky and I had the opportunity to work with some new and powerful java frameworks and with the newest software design approaches, and in particular I specialised in DDD (Domain Driven Design).
When you try to develop a software following DDD principles you need to use some frameworks that help you to thinking only to domain, example the ORM for the persistence or user interface generator for the user interaction.
Now I want focus on persistence because in my work experience I found some gap in the persistence frameworks.
Explain the gap:
if you are using java probably you want define all rules and all behaviour of your domain using only java, and this is almost possible,
Just define a domain:
And try to persist the domain(JPA api):
OK you can do all CRUD(create read update delete) only with java, this is good!! but what happen if you try to search something??"select * from Person where name=:name"
I have to use another SQL-like language (JPQL,JDOQL,HQL. etc...) this is not java ... not good.
The reasons why this is not good are many:
- if you want refactoring your code you have to check all SQL-like everywhere
- You can't check at compile time if something is wrong like types field names
- have to learn another language
- at least i broken my DDD principles ;)
OK now we need something of different but before start an hard work I'll try to check on Internet if someone did it!
Yes i found it:JPA type safe query
JDO type safe query
SQL type safe query
Yes good, someone(of big) have the same my problem and they try to solve it... but i don't like this kind of solution! you have to define manually or generate automatically another static class that expose a reflection of your domain end then if you change something you have to update it!
OK ... Is my time ! I try find a better solution!
I worked with java for years and I had discovered there is three main way to write implementation independent code:
- Statically with simple java interface(all know it)
- Dynamically with reflection (almost all know it)
- Dynamically with proxy (almost all use it, but just someone know it)
usually when we want execute a query in a DDD approach we want an object that describe the query, where we set the target of query the conditions and all we need:
1 ObjectQuery<Person> query = new GenericObjectQuery<Person>(Person.class);
But ... is not finished here .... to complete it I have to fix lot of problems... but this is another post ;)