Advance Usage of DMT Framework
This example show you how to use DMT Framework bring your Domain Model
Back in the way you want.
First you need to setup your project to use
DMT Framework
Suppose you have a class called UserAccount, It has
Reference to Address and
Company. And, it has
following attributes:
- private String userName;
- private String accountNumber;
- private String spouseName;
- private Long moneyReserve;
-
- private Address address;
- private Company company;
-
- private Long id;
- private int version;
- private Date createDateTime;
- private Date lastModifiedDateTime;
- private String createdBy;
- private String modifiedBy;
You want bring back the UserAccount with attributes only need for the
client side, let's say(userName,
accountNumber, moneyReserve,
company), for other attributes you
don't want them because it is redaundent data to your current user
interface display. And, you have All
the companys maintained in your
client side cache, you don't want transport them again every time when
you call getUserAccount Command.
To achieve this, you need:
<dmtschema
name="getUserAccount"
version="0">
<default_dmtspec>
<exclude name="createDateTime"/>
<exclude name="lastModifiedDateTime"/>
<exclude name="createdBy"/>
<exclude name="modifiedBy"/>
</default_dmtspec>
<externalizer
type_name="Company">CompanyExternalizer</externalizer>
<dmtspec
classname="UserAccount">
<include>userName</include>
<include>accountNumber</include>
<include>moneyReserve</include>
<include>company</include>
</dmtspec>
</dmtschema>
To define this schema in hand
might becomes a tedious job, we have developed an eclipse plugin, you can
generate this schema very easily
- Save as a file (e.g. getUserAccountSchema.xml)
- add Java System property
-Ddmdf.dmt.schema.filenames=getUserAccountSchema.xml
- put your fine in your class path
- if you have multi schema, just append them by separated with ","
- Create your GetUserAccountCommand
which implements CommandInterface
- Then you are done!. The UserAccountObject what you get back from
server is what you wanted.