You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cayenne.apache.org by Adrian Wiesmann <aw...@somap.org> on 2007/08/09 23:51:03 UTC
Some ideas extending Cayenne
Hello all
I am having a few ideas concerning extending Cayenne and I would like to
hear your comments. Probably some of these ideas already would be possible
or some were discussed before? Would they be difficult to implement? Are
there others interested in such extensions?
- Typed Keys: Primary keys are generated for all DataObjects and it would
be possible to use typed keys while programming. (The fill method in the
table module extension below could be called with a typed key lowering the
possibility of coding/conversion errors.)
- Implementation of Table Data Gateway design pattern: The process to load
and persist data is managed in a typed gateway class so that it would be
possible to rewrite or add "elements" of a query (think about filling a
logical unmapped field on a DataObject with a subquery). I know I could do
something like this with callbacks. But with callbacks I can't extend the
query for a performant loading of records.
- Implementation of Table Module design pattern: Currently DataObjects are
a mixture between a "Data Row" and a "Table Module". The idea of a typed
table module per DataObject is that business logic for all rows would be
put into the table module and logic for one row would be put into the row
(table module: fill, fillbyforeignkey, persist. data object: row
validation).
Above extensions would require some changes to the ObjectContext (it
should know the loaded table modules) and on other core elements of
Cayenne. Would that be a problem for others or result in many side
effects?
And: I am currently thinking about completely remodeling DataViews. One
of the ideas I have is that the UI could be built from an XML definition
which is transformed into an object tree. That object tree could be used
by a renderer to generate a Swing interface, an xsl-fo tree (for PDF
generation) or HTML (for webapps). Have you ever thought about something
like this?
Thanks for your comments.
Regards,
Adrian
Re: Some ideas extending Cayenne
Posted by Mike Kienenberger <mk...@gmail.com>.
On 8/14/07, Adrian Wiesmann <aw...@somap.org> wrote:
> Talking about generating classes from a DataMap. What would be the best
> way to generate personalised classes from a DataMap? I want to create at
> least two classes per DataObject. Would writing my own set of Velocity
> template transformations make sense? Or did I miss some hook in Cayenne
> which I could use? Afaik the cgen Ant task is not that flexible?
The cgen Ant task is very flexible. I have generated entire web
applications directly from the database model using cgen ant task and
templates. I think the modeler now supports most of the cgen ant
task options and you can also use the modeler if you want.
Here's a couple of examples:
<target name="entity stub" depends="failure check"
description="internal:generate entity stub">
<mkdir dir="${dataMapModelPackageDir}/entity/stub/generated"/>
<cgen map="${template.datamap}"
additionalMaps="${additional.template.datamaps}"
version="1.2"
makepairs="false"
overwrite="true"
mode="entity"
outputPattern="_*StubImpl.java"
destDir="${dataMapModelPackageDir}/entity/stub/generated"
superpkg="${dataMapModelPackage}.entity.cayenne.generated"
template="${template.superclass.stub}"
usepkgpath="false">
</cgen>
<mkdir dir="${dataMapModelPackageDir}/entity/stub"/>
<cgen map="${template.datamap}"
additionalMaps="${additional.template.datamaps}"
version="1.2"
makepairs="false"
overwrite="false"
mode="entity"
outputPattern="*StubImpl.java"
destDir="${dataMapModelPackageDir}/entity/stub"
superpkg="${dataMapModelPackage}.entity.cayenne.generated"
template="${template.subclass.stub}"
usepkgpath="false">
</cgen>
</target>
<vppconfig id="vppconfig.datamap" >
<context>
<property key="dataMapName" value="${dataMapClassPrefix}" />
<property key="dataMapPkg" value="${dataMapPkg}" />
<tool key="metaDataTool" classname="com.xyz.velocity.tool.MetaDataTool" />
</context>
<engine>
<property key="file.resource.loader.path" add="yes"
value="${java.templates}" />
</engine>
</vppconfig>
<target name="datastore interface" depends="failure check"
description="internal:generate datastore">
<mkdir dir="${framework-cayenne.java.src.generated}/datastore"/>
<cgen map="${template.datamap}"
additionalMaps="${additional.template.datamaps}"
version="1.2"
makepairs="false"
overwrite="true"
mode="datamap"
includeEntities="${template.entity}"
template="${java.templates}/_DataMapDataStore.java.vm"
destDir="${framework-cayenne.java.src.generated}/datastore"
outputPattern="_${dataMapClassPrefix}DataStore.java"
usepkgpath="false">
<config refid="vppconfig.datamap" />
</cgen>
<mkdir dir="${dataMapModelPackageDir}/business"/>
<cgen map="${template.datamap}"
additionalMaps="${additional.template.datamaps}"
version="1.2"
makepairs="false"
overwrite="false"
mode="datamap"
includeEntities="${template.entity}"
template="${java.templates}/DataMapDataStore.java.vm"
destDir="${dataMapModelPackageDir}/business"
outputPattern="${dataMapClassPrefix}DataStore.java"
usepkgpath="false">
<config refid="vppconfig.datamap" />
</cgen>
</target>
Re: Some ideas extending Cayenne
Posted by Adrian Wiesmann <aw...@somap.org>.
Hello Andrus
Thanks for your help.
> What is a typed key? Is it a custom Java class used for PK? If so,
> you sort of can do that by mapping a meaningful PK and using an
> ExtendedType to map a custom class for PK.
Yes, I meant a strong typed class for every primary key. Sounds like
ExtendedType is what I am looking for.
Talking about generating classes from a DataMap. What would be the best
way to generate personalised classes from a DataMap? I want to create at
least two classes per DataObject. Would writing my own set of Velocity
template transformations make sense? Or did I miss some hook in Cayenne
which I could use? Afaik the cgen Ant task is not that flexible?
> There are two more extension points in Cayenne 3.0 that may help you
> to do that - custom queries and ObjectContext decorators (so you may
> intercept certain queries/operation and rewrite them to your liking).
> So essentially it should be possible to build what you are describing
> as a complimentary module to Cayenne first, and then see if it is
> worth integrating it in the core.
ObjectContext decorator is probably what I am looking for. The only
problem is that this decorator works on the whole ObjectContext and not on
DataObject level. But that is solveable and I will try this one out.
> Many people did (I even started a project called JStaple that never
> took off). Not sure if anybody succeeded in building something usable
> though.
Yes, I am wondering why there is nothing for Swing. Although the DataViews
are cool, they somewhat are limited. I have worked now some time with a
framework which builds an object tree based on some xml syntax, binds the
data and then uses that tree to render HTML and PDF. But why not render
Swing as well. Swing is not that different...
I guess I have to try this out, interested adventurers are welcome :)
Regards,
Adrian
Re: Some ideas extending Cayenne
Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Adrian,
On Aug 9, 2007, at 5:51 PM, Adrian Wiesmann wrote:
> - Typed Keys: Primary keys are generated for all DataObjects and it
> would
> be possible to use typed keys while programming. (The fill method
> in the
> table module extension below could be called with a typed key
> lowering the
> possibility of coding/conversion errors.)
What is a typed key? Is it a custom Java class used for PK? If so,
you sort of can do that by mapping a meaningful PK and using an
ExtendedType to map a custom class for PK.
> - Implementation of Table Data Gateway design pattern: The process
> to load
> and persist data is managed in a typed gateway class so that it
> would be
> possible to rewrite or add "elements" of a query (think about
> filling a
> logical unmapped field on a DataObject with a subquery). I know I
> could do
> something like this with callbacks. But with callbacks I can't
> extend the
> query for a performant loading of records.
There are two more extension points in Cayenne 3.0 that may help you
to do that - custom queries and ObjectContext decorators (so you may
intercept certain queries/operation and rewrite them to your liking).
So essentially it should be possible to build what you are describing
as a complimentary module to Cayenne first, and then see if it is
worth integrating it in the core.
> And: I am currently thinking about completely remodeling DataViews.
> One
> of the ideas I have is that the UI could be built from an XML
> definition
> which is transformed into an object tree. That object tree could be
> used
> by a renderer to generate a Swing interface, an xsl-fo tree (for PDF
> generation) or HTML (for webapps). Have you ever thought about
> something
> like this?
Many people did (I even started a project called JStaple that never
took off). Not sure if anybody succeeded in building something usable
though.
Andrus