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 strange.
 
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();
  example.setCol1(key.getCol1());
  example.setCol1_Indicator(RecordExample.EXAMPLE_EQUALS);
  example.setCol2(key.getCol2());
  example.setCol2_Indicator(RecordExample.EXAMPLE_EQUALS);
 
  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 classes.

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 <[EMAIL PROTECTED] > 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.


Reply via email to