OK, to summarise the stuff below, we have entities:
public class Party {
id;
}
public class Transaction {
party;
transactionDate;
transactionType;
faceValue;
}
and you've defined a class that specifies the aggregated data (I'm omitting
the "ViewModel" suffix.
public class DailySalesTotalForParty {
party;
transactionDate;
totalAmount;
}
There are two ways to address this
1. (as you've done) define a SQL view and use JDO @PersistenceCapable on
DailySalesTotalForParty. So far as Isis is concerned, this class is just
an entity, and so you can define a domain service and query for it in the
usual way). In this case there's NO NEED (I think) for this class to
implement Isis' ViewModel interface.
2. alternatively, you can NOT use a SQL view, and instead only use an Isis
ViewModel. Here the view models are instantiated by a domain service, and
JDO doesn't know anything about them. You can see examples of this in the
todo app [1], [2].
Put another way, in (1) the view is defined in the database layer, in (2)
the view is done in the domain layer.
~~~
In your other email you said you want to show the daily sales for a given
party. So:
a) add a JDO Query so that you can filter the
DailySalesTotalForPartyViewModel by partyId:
@Query(name="dailySales", query= "select from
DailySalesTotalForPartyViewModel where partyId = :partyId)
b) write a domain service that exposes this:
public class DailySalesTotalForPartyService {
@NotContributed(As.ACTION) // ie contributed as a collection
public List<DailySalesTotalForParty> dailySales(Party party) {
return allMatches(new QueryDefault("dailySales", "party", party));
}
}
This "dailySales" action should then appear as a contributed collection, ie
as if there's a "dailySales" collection of Party itself.
~~~
If you want to go use an Isis view model, then you don't need the
@PersistenceCapable annotation or SQL VIEW, but you will need to replicate
aggregation logic in a domain service. That is, you'd still have a service:
public class DailySalesTotalForPartyService {
@NotContributed(As.ACTION) // ie contributed as a collection
public List<DailySalesTotalForParty> dailySales(Party party) {
...
}
}
but what does in the implementation would be similar to [1].
HTH
Dan
[1]
https://github.com/apache/isis/blob/5e9d586a3a1dcb9e4cf23470f6cb4ef43ebae06d/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/app/ToDoItemAnalysis.java
[1]
https://github.com/apache/isis/blob/5e9d586a3a1dcb9e4cf23470f6cb4ef43ebae06d/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/app/ToDoItemsByCategoryViewModel.java