Discussion:
[Middlegen-user] Generating beans into different packages
Jason Essington
2002-08-28 16:46:03 UTC
Permalink
Aslak what a great tool, thanks!

Everyone, for discussion:

I am trying to divide my tables (actually their generated beans) into
multiple packages that represent their real purpose in life.

currently I have an ejb.entity and an ejb.reporting.entity package and I
am sure I'll have more as I go on.

So here is what I have found:
I can't use multiple <cmp20> elements in the build.xml file as the name=
attribute doesn't seem to take effect until too late and middlegen
assumes both have a name of cmp20 then fails.
I did work around this by creating multiple <plugin> references in the
plugins/entitybean/classes/META-INF/middlegen.xml file that just had
different name attributes. This allowed me to acces the cmp20 plugin as
<cmp20> , <cmp20-2>, etc. Then used embeded <fileproducer> with embeded
<table> tags to limit which plugin produced which tables.

This works but of course in the gui you are presented with 2 plugin tabs
and when a table is selected you are allowed to set its properties in
each tab weather or not that plugin is going to generate the file for
the table. This isn't currently an issue for me as I am only generating
beans from say 14 tables, but when my table count gets too much over 50
tables and I am trying to put the resulting beans into 3 or more
packages, my brain won't be able to remember which tab I should be
setting the properties on.

Would it be possible to for a plugin to check which tables the it is
actually going to generate files for, and only display(allow the editing
of) information on its gui tab for tables it is actually going to
generate a file for?

Or, perhaps, there would be value in making multiple <fileproducer>
elements inside the <cmp20> element that could override many of the
attributes that are currently set in the cmp20 element (package,
interfacepackage, jndiprefix, etc). This would allow the plugin to
define several fileproducers to write the beans out to different
packages, or different jndi contexts, or whatever. This would also leave
only 1 tab in the gui for this plugin thus reducing the possiblity of
configuring a table in a tab that isn't going to produce a file for it
anyway.

for instance if I wanted some of my tables generated into the
.ejb.reporting.entity package but others in the .ejb.entity package.
something like this could be done.

<cmp20
name="cmpEntityBeans"
destination="${build.gen-src.dir}"
package="${name}.ejb.entity"
interfacepackage="${name}.ejb.local"
jndiprefix="ejb"
generatepk="false"
dataobject="true"
viewtype="local"
mergedir="${basedir}/src/middlegen"
readonly="false"
fkcmp="true"
<!-- this fileproducer would just use the values from the
cmp20 element (current behavior)-->
<fileproducer
id="entity-cmp-20"
template="${template.dir}/entity-cmp-20.vm"
<table name="tclients"/>
<table name="tcodes"/>
</fileproducer>

<!-- multiple fileproducers are not currently possible, nor
is overriding attributes of the parent plugin element -->
<!-- but this fileproducer overrides package,
interfacepackage, and jndiprefix -->
<fileproducer
id="entity-cmp-20"
template="${template.dir}/entity-cmp-20.vm"
package="${name}.ejb.reporting.entity"
interfacepackage="${name}.ejb.reporting.local"
jndiprefix="ejb/reporting"
<table name="treportbatches"/>
<table name="treportcmds"/>
</fileproducer>
</cmp20>


Maybe I am trying to do something that has no value to anyone else, or
maybe there is a better way to do this altogether.


-jason
a***@netcom.no
2002-08-29 06:48:03 UTC
Permalink
----- Original Message -----
From: Jason Essington <***@GreenRiverComputing.com>
Date: Wednesday, August 28, 2002 8:45 pm
Subject: [Middlegen-user] Generating beans into different packages
Aslak what a great tool, thanks!
I am trying to divide my tables (actually their generated beans)
into
multiple packages that represent their real purpose in life.
If you put {0} in the package attribute, the {0} will be substituted
with the table name. You'll end up with one package per bean/table.
Maybe that's too fragmented for you?

http://boss.bekk.no/boss/middlegen/plugins/java.html
currently I have an ejb.entity and an ejb.reporting.entity package
and I
am sure I'll have more as I go on.
I can't use multiple <cmp20> elements in the build.xml file as the
name=
attribute doesn't seem to take effect until too late and middlegen
assumes both have a name of cmp20 then fails.
I have fixed the bug. Will commit it when I get near a network that
allows me to connect to CVS. Probably tomorrow.
I did work around this by creating multiple <plugin> references in
the
plugins/entitybean/classes/META-INF/middlegen.xml file that just
had
different name attributes. This allowed me to acces the cmp20
plugin as
<cmp20> , <cmp20-2>, etc. Then used embeded <fileproducer> with
embeded
<table> tags to limit which plugin produced which tables.
This works but of course in the gui you are presented with 2
plugin tabs
and when a table is selected you are allowed to set its properties
in
each tab weather or not that plugin is going to generate the file
for
the table. This isn't currently an issue for me as I am only
generating
beans from say 14 tables, but when my table count gets too much
over 50
tables and I am trying to put the resulting beans into 3 or more
packages, my brain won't be able to remember which tab I should be
setting the properties on.
Would it be possible to for a plugin to check which tables the it
is
actually going to generate files for, and only display(allow the
editing
of) information on its gui tab for tables it is actually going to
generate a file for?
Anything is possible. But this is currently not implemented. Currently
you can make a copy of the entity-cmp-20.vm template as a file, use
<fileproducer> and tell the plugin to use that template. Inside the
<fileproducer> element you can put several <table> elements, telling
the <fileproducer> to generate only for those tables.

Ideally you would be able to put <table> elements directly under the
<cmp20> element.

I could add a new feature that would visually gray out all visual
tables that are not part of the <table> elements corresponding to the
plugin on the selected tab.
Or, perhaps, there would be value in making multiple
<fileproducer>
elements inside the <cmp20> element that could override many of
the
attributes that are currently set in the cmp20 element (package,
interfacepackage, jndiprefix, etc). This would allow the plugin to
define several fileproducers to write the beans out to different
packages, or different jndi contexts, or whatever. This would also
leave
only 1 tab in the gui for this plugin thus reducing the possiblity
of
configuring a table in a tab that isn't going to produce a file
for it
anyway.
That's a bit tricky. Keep in mind that Middlegen (and <fileproducer>)
has nothing EJB-specific to them. So I will not introduce anything EJB-
specific in them either. You see, Middlegen's ultimate goal is to be a
generic database driven code generator.
for instance if I wanted some of my tables generated into the
.ejb.reporting.entity package but others in the .ejb.entity
package.
something like this could be done.
<cmp20
name="cmpEntityBeans"
destination="${build.gen-src.dir}"
package="${name}.ejb.entity"
interfacepackage="${name}.ejb.local"
jndiprefix="ejb"
generatepk="false"
dataobject="true"
viewtype="local"
mergedir="${basedir}/src/middlegen"
readonly="false"
fkcmp="true"
<!-- this fileproducer would just use the values from
the
cmp20 element (current behavior)-->
<fileproducer
id="entity-cmp-20"
template="${template.dir}/entity-cmp-20.vm"
<table name="tclients"/>
<table name="tcodes"/>
</fileproducer>
<!-- multiple fileproducers are not currently
possible, nor
is overriding attributes of the parent plugin element -->
<!-- but this fileproducer overrides package,
interfacepackage, and jndiprefix -->
<fileproducer
id="entity-cmp-20"
template="${template.dir}/entity-cmp-20.vm"
package="${name}.ejb.reporting.entity"
interfacepackage="${name}.ejb.reporting.local"
jndiprefix="ejb/reporting"
<table name="treportbatches"/>
<table name="treportcmds"/>
</fileproducer>
</cmp20>
It would be better to use multiple <cmp20> elements.
Maybe I am trying to do something that has no value to anyone
else, or
maybe there is a better way to do this altogether.
-jason
Let me know if this would work for you.

Aslak
-------------------------------------------------------
This sf.net email is sponsored by: Jabber - The world's fastest
growing
real-time communications platform! Don't just IM. Build it in!
http://www.jabber.com/osdn/xim
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
Jason Essington
2002-08-29 11:51:04 UTC
Permalink
Post by a***@netcom.no
----- Original Message -----
Date: Wednesday, August 28, 2002 8:45 pm
Subject: [Middlegen-user] Generating beans into different packages
<snip>
If you put {0} in the package attribute, the {0} will be substituted
with the table name. You'll end up with one package per bean/table.
Maybe that's too fragmented for you?
That's a few more packages than I was planning on :-)
Post by a***@netcom.no
http://boss.bekk.no/boss/middlegen/plugins/java.html
<snip>
I can't use multiple <cmp20> elements in the build.xml file as the
name=
attribute doesn't seem to take effect until too late and middlegen
assumes both have a name of cmp20 then fails.
I have fixed the bug. Will commit it when I get near a network that
allows me to connect to CVS. Probably tomorrow.
Excellent!
Post by a***@netcom.no
<snip>
Would it be possible to for a plugin to check which tables the it
is
actually going to generate files for, and only display(allow the
editing
of) information on its gui tab for tables it is actually going to
generate a file for?
Anything is possible. But this is currently not implemented. Currently
you can make a copy of the entity-cmp-20.vm template as a file, use
<fileproducer> and tell the plugin to use that template. Inside the
<fileproducer> element you can put several <table> elements, telling
the <fileproducer> to generate only for those tables.
Actually I already do this to add jboss-net specific tags into the
generated
beans.
Post by a***@netcom.no
Ideally you would be able to put <table> elements directly under the
<cmp20> element.
I could add a new feature that would visually gray out all visual
tables that are not part of the <table> elements corresponding to the
plugin on the selected tab.
That is certainly a more reasonable Idea than my ramblings :-)
Post by a***@netcom.no
Or, perhaps, there would be value in making multiple
<fileproducer>
<snip>
That's a bit tricky. Keep in mind that Middlegen (and <fileproducer>)
has nothing EJB-specific to them. So I will not introduce anything EJB-
specific in them either. You see, Middlegen's ultimate goal is to be a
generic database driven code generator.
I Understand this.
Post by a***@netcom.no
<snip/>
It would be better to use multiple <cmp20> elements.
yes, that is what I am doing currently, The problem I have run into
with that is when a table from one plugin has a relation with a table
from another plugin, the two generated beans don't have the package
name of the referenced bean set correctly. each assumes the referenced
bean is in it's own package.
Post by a***@netcom.no
Let me know if this would work for you.
Yes, dimming tables that are not being generated by a particular
template is a very nice feature.

I think that maybe trying to figure out how to fix the relationships
between tables in different plugins may be of little value since it is
conceivable that some tables would have more than 1 plugin generating a
bean. This would require a way to select which generated interface to
be referenced. All in all, sounds like maybe more trouble than it's
worth (I still can write code after all).
Post by a***@netcom.no
Aslak
This is a great tool, thank you.

-jason

Loading...