ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Butler" <jeffgbut...@gmail.com>
Subject Re: Abator Primary Key Forcement
Date Tue, 21 Mar 2006 16:06:42 GMT
Interesting idea, but I think that would be a little misleading.  Since a
view doesn't have a primary key, a "selectByPrimaryKey" method would seem

You can accomplish this function using the selectByExample method and
writing your own "pseudo primary key".  For example:

public class PseudoPrimaryKey {
  private Integer col1;
  private Integer col2;
  // getters and setters

In the DAO, add a method like this:

public Record selectByPseudoPrimaryKey(PseudoPrimaryKey key) {
  RecordExample example = new RecordExample();

  List result = selectByExample(example);
  If (result.size() > 0) {
    return (Record) result.get(0);
  } else {
    return null;

Remember that any method you add to a DAO will survive a re-generation, so
you don't have to worry about adding methods to the Abator generated

I suppose we could change Abator to automatically generate methods and
objects like this, but there are a lot of things to take into consideration
(does the query return one row, or multiple rows, etc.).  I think it would
be better to leave it to the user to create these things by hand.

I wanted the selectByExample method to be very reusable - and this is a
great example of that reuse.  In my own projects, I write lots of methods
like this that reuse the selectByExample method to create custom queries.

Jeff Butler

On 3/21/06, Skrach <daniel.skrach@eunet.co.at > wrote:
> Hi,
> I'm currently evaluating Abator (which I'm really impressed off so far!)
> and
> came over the following limitation/idea:
> During creation of Maps/DAOs/Models, Primary Key classes are automatically
> created, if PK's are found on the DB-Table. For sure, this mechanism
> doesn't
> work for views (which I must use for other reasons).
> Therefore my question: What do you think about forced Primary Key class
> creation (for Domain, Model, Map + selectByPrimaryKey() method) specified
> as
> new element in <table ... primaryKey="a1,a2"" ... /> inside the
> abatorConfig.xml file, which take effect if no primary key is found on the
> table itself?
> Thanks for your help!
> --
> View this message in context:
> http://www.nabble.com/Abator-Primary-Key-Forcement-t1317590.html#a3513218
> Sent from the iBATIS - User - Java forum at Nabble.com<http://nabble.com/>
> .

View raw message