kyters / jlibs

Automatically exported from code.google.com/p/jlibs
1 stars 0 forks source link

Generate friendly creator method for DAO base class #18

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use an abstract base class for a JDBC DAO

Please provide any additional information below.

It's inconvenient to get an instance of the DAO class converted to the base 
class type when using @Table(extend=...)

  final X x = (X)DAO.create(Y.class, dataSource);

It would be nice for the generated DAO code to include its own create() method:

  public static X create (final DataSource dataSource) {
    return (X)jlibs.jdbc.DAO.create(Y.class, dataSource);
  }

Thus making it possible to write the cleaner:

  final X x = X.create(dataSource);

Right now, it's obviously possible to get this by simply putting that method 
into the base class manually, but it would be friendlier for the API to 
generate it.

Original issue reported on code.google.com by eire...@gmail.com on 3 Jun 2011 at 6:54

GoogleCodeExporter commented 9 years ago
@Table(extend=X.class)
class Y{
}

class X extends DAO<Y>{
}

then the generated DAO will be:

class _X extends X{
    ....
}

if I add the mentioned static method to _X,

then you need to do:
    final X x = _X.create(dataSource);

i.e you are directly referencing the generated class _X in your source. I think 
it would be bad idea to use generated class _X directly in the code.

what is your opinion?

Original comment by santhosh.tekuri@gmail.com on 5 Jun 2011 at 5:06

GoogleCodeExporter commented 9 years ago
You're right.  That would not be an improvement...  As a convenience method, 
it's nice to have, but it has to be added to the "extend" class.

Original comment by eire...@gmail.com on 6 Jun 2011 at 10:00

GoogleCodeExporter commented 9 years ago

Original comment by santhosh.tekuri@gmail.com on 11 Jun 2011 at 5:28