Discussion:
[Middlegen-user] Primary key class
David Cowan
2002-04-23 17:56:13 UTC
Permalink
I am wondering if there is a way to make middlegen generate primary key
classes. Currently I have to use the gui and select every table and set the
primary key to class. It defaults to byte[] for my particular field. Is
there a flag that can be passed into the middlegen section of the build
file?

Thanks,

David

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
Aslak Hellesøy
2002-04-23 20:09:04 UTC
Permalink
Hi David, can you please inform me about when you last updated your CVS
copy?
-----Original Message-----
Cowan
Sent: 23. april 2002 21:53
Subject: [Middlegen-user] Primary key class
I am wondering if there is a way to make middlegen generate primary key
I think you know this, but for the sake of clarity:

Middlegen only generates one file per database table: The Bean
implementation (XXXBean.java) All the rest is generated by XDoclet (which is
invoked by the samples' build script *after* Middlegen exits). The
XXXBean.java files generated by Middlegen have @tags in it that XDoclet uses
to generate other files (like Primary Key classes).
classes. Currently I have to use the gui and select every table
and set the
primary key to class. It defaults to byte[] for my particular field. Is
I'll explain how it works:

The deafult behaviour for PK type is to use the default java type for the
primary key's SQL type (unless we're dealing with a compound key). You'll
find the mapping logic at the end of the Sql2Java class (population of the
_preferredJavaTypeForSqlType Map) and in the
getPreferredJavaType(int,int,int) method.

As you see, in order to get byte[] your primary key field must be of SQL
type BINARY or VARBINARY. I find that a bit odd... Maybe you're using an old
(read: more than three days old) CVS copy? -Or my code might be faulty in
some way...
What database and driver are you using? Versions please.

Anyway, there should definitley be a way to obtain what you want. There
isn't currently. Please make a feature request here:
http://sourceforge.net/tracker/?group_id=36044
Here is a mini guide on how to write a useful FQ:

GUI: I want to be able to click on the banana icon and drag
it over the strawberry field. Then the magic will happen.

ANT: I want to achieve this by inserting a <banana> element
under the <strawberry> element putting all the info in
the lemon attribute.

SOMETHING ELSE: If I wrote a foo file on bar format containing xxx entries
stored in yyy, that would also do the trick.

Hope this helps,

Cheers,
Aslak
there a flag that can be passed into the middlegen section of the build
file?
Thanks,
David
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
Aslak Hellesøy
2002-04-23 20:23:05 UTC
Permalink
-----Original Message-----
Cowan
Sent: 23. april 2002 21:53
Subject: [Middlegen-user] Primary key class
I am wondering if there is a way to make middlegen generate primary key
classes. Currently I have to use the gui and select every table
and set the
primary key to class. It defaults to byte[] for my particular field. Is
there a flag that can be passed into the middlegen section of the build
file?
I forgot to mention: This feature request
https://sourceforge.net/tracker/index.php?func=detail&aid=541446&group_id=36
044&atid=415993
is partly implemented, but has a remaining issue: MG should store the PK
type in the preferences, so that next time you run, Middlegen will remember.
It's related, but it doesn't *quite* solve your problem. Just so you know.

Cheers,
Aslak
Thanks,
David
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
Aslak Hellesøy
2002-04-24 16:55:19 UTC
Permalink
I am using MS SQL 2000. It will return BINARY'S on the fields
that are my
primary key. We are using UNIQUEIDENTIFIER types which are
guid's 16 byte
fields basically. It all works fine if I use a primary key
class. I will
add a feature request to sourceforge for an option to force primary key
class generation.
Aaah I see now ;-). Do a CVS update. I've left some homework for you in
MiddlegenPopulator. Search for your name, and send me a patch of the
required changes.
bye the way just want to complement you on an awesome
application. It has
definately been a time saver for me.
Sweet! Keep on reporting bugs and FRs.

Cheers,
Aslak
a***@netcom.no
2002-04-25 13:23:48 UTC
Permalink
Hi David, (p.s. cc to middlegen-user)

There are two issuses here:
-How to make the default java type for uniqueidentifier be
java.lang.String, and not byte[]
-How to tell Middlegen to always suggest custom PK classes.

I'll explain in more detail...

If a table's primary key consists of only one field, there is
(according to the EJB spec) no need to make your own primary key class
for your EJB. Primary key classes are only needed if the table's
primary key consistes of more than one field, in which case you need a
compound primary key.

Middlegen will therefore by default suggest to use the preferred java
type of the single pk field when the table's pk is only one field. Why?
It makes the code simpler, and might increase the performance slightly
since a wrapper key object around a String won't need to be created.

The JDBC spec suggests allowed and preferred mappings between SQL types
and SQL types. This is shown in one of the png files under
middlegen/doc and implemented in Sql2Java.

In some cases (like yours) the suggested mapping is not good. You
probably want the MSSQL uniqueidentifier type (which your driver
reports as type java.sql.Types.BINARY doesn't it?) to map as default to
a String. I've added that code to the tune method in
MiddlegenPopulator. It's untested (and obviously doesn't work, since
you apparently still get byte[] as preferred type for BINARY). It would
be nice if you could help me.

The other issue is how to make Middlegen always suggest a PK class, no
matter if the pk consists of a single field. I'm not in front of the
code now, so I don't remember exactly where it is. I think it is
somewhere in the Table hierarchy: A method called setSimplePk(boolean)
or something. I can add an option to the cmp20 subtask which lets you
override this, ao that you always get a pk class no matter what.

Here's the deal:
-You verify my code in MiddlegenPopulator (where your name is) and make
sure the suggested type for BINARY is something else than byte[] when
running your driver.
-I implement functionality to override so you always get Pk class.

Deal?

Aslak

----- Original Message -----
From: ***@apcc.com
Date: Thursday, April 25, 2002 4:37 pm
Subject: Re: Fwd: RE: [Middlegen-user] Primary key class
Alright I got it compiling and detecting my driver now. Can you
point me
in the right direction as to were to look for what causes the
Primary Key
class to populate with byte[] I have attached a screen shot.
Were is the
code that determines what the Primary key class should be. It
always comes
up with byte[] I would like for it to be a primary key class.
(Embedded image moved to file: pic04041.pcx)(Embedded image moved
pic03602.pcx)
Thanks david
"David Cowan"
[Middlegen-user] Primary key class
04/25/2002
09:28 AM
Subject: RE: [Middlegen-user] Primary key class
Date: Wed, 24 Apr 2002 23:58:08 +0200
I can't get the latest cvs to build. I get 56 errors. most of
them having
to do with plugin classes.
Sorry, I was a bit quick. If you update, build clean and then
build, it
should be ok...
Aslak
_________________________________________________________________
Get your FREE download of MSN Explorer at
http://explorer.msn.com/intl.asp.
Loading...