Thank you so much Andriy and Andrus for your detailed explanations and examples you provided.
Sabiha
Andriy Shapochka <ashapochk..otmail.com> wrote:One more code snippet to illustrate a possible way to deal with caching data
objects using Data Views and LookupCache. This piece performed when the
application is started or the data gets globally reloaded from the database.
You see here (cacheLookups) how we can automatically track and cache all the
needed lookup data objects for further usage in various Swing controls
(comboboxes and such) the method of importance is
clientDataView.getLookupObjEntityViewFields();
class Session {
DataView clientDataView;
Map dataObjectCache;
private void reset(DataDomain reqframeworkDomain, ClientPlugin clientPlugin)
{
clientDataView = createClientDataView(requirementContext);
dataObjectCache = new HashMap();
loadPatterns();
loadPatternMatrix();
loadApprovals();
loadAccountabilityMatrix();
loadQuestionnaires();
cacheLookups();
}
private void cacheLookups() {
Set lookupFields = clientDataView.getLookupObjEntityViewFields();
for (Iterator i = lookupFields.iterator(); i.hasNext(); ) {
ObjEntityViewField field = (ObjEntityViewField)i.next();
ObjEntity entity = field.getOwner().getObjEntity();
DataObjectList dataObjects =
(DataObjectList)dataObjectCache.get(entity);
if (dataObjects == null) {
dataObjects = new DataObjectList(
CayenneUtils.fetchAll(getDataContext(), entity), false);
dataObjectCache.put(entity, dataObjects);
}
clientDataView.getLookupCache().cache(field, dataObjects);
}
}
private void loadPatterns() {
DataObjectList patterns = new DataObjectList(fetchAll(
RequirementPattern.class,
"name",
Collections.singletonList("requirementPatternItems")),
false);
dataObjectCache.put(
getDataContext().getEntityResolver().lookupObjEntity(RequirementPattern.clas
s),
patterns);
prefetchPatternBlockings(patterns);
for (Iterator i = patterns.iterator(); i.hasNext(); ) {
RequirementPattern pattern = (RequirementPattern)i.next();
pattern.load();
pattern.setEditable(false);
}
}
...
}
----- Original Message -----
From: "Andrus Adamchik"
To:
Cc: "Andriy Shapochka"
Sent: Friday, June 18, 2004 8:33 PM
Subject: Re: Data Views
As promised, here is a DataViews example showing how to build a simple
Swing app, configuring combo boxes and tables using DataViews. An app
is a standard Swing MVC application without using any third party MVC
frameworks. While it uses JGoodies forms and plastic look, this is
totally irrelevant for the purpose of DataViews demo. I just needed
decent layout tools. See the README.txt file in the download for
details.
http://objectstyle.org/downloads/cayenne/demos/HRDataView.tar.gz
README.txt mentions a bug that I fixed in DVModeler. In short, if you
want to use "display format" feature, you'll have to wait till
tomorrow's nightly build, or edit XML file by hand as current DVModeler
would corrupt display format settings.
Also, this was my first experience with data views, and I should say I
am impressed! That makes "classic" Swing development with DataObjects
so much easier and consistent.
Andrus
On Jun 16, 2004, at 8:56 AM, sabiha wrote:
> Hi,
>
> I have a swing application working with Cayenne, and by now I used
> swing components, like JTree, and it’s easy to use it with Cayenne
> model, but now I want to use table and I read about Cayenne Data Views
> but can’t figure out how to make it working with that. I saw example
> in User guide but it didn’t help me a lot. I would appreciate if
> someone could briefly just explain me what I need to do to simply
> present attributes of one object in table.
>
>
>
> Thanks a lot
>
>
> Sabiha
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
This archive was generated by hypermail 2.0.0 : Mon Jun 21 2004 - 09:45:07 EDT