Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jdbi-generator] Java interface to work with @GenerateSqlObject must extends SqlObject #1791

Closed
wbprime opened this issue Dec 1, 2020 · 3 comments

Comments

@wbprime
Copy link

wbprime commented Dec 1, 2020

Given following code, jdbi-generator generates correct impl class of JdbiDao interface:

@GenerateSqlObject
public interface JdbiDao extends SqlObject {
    @SqlUpdate("insert into users (name) values ( ?)")
    @GetGeneratedKeys("id")
    long insert(String name);
}

However for:

@GenerateSqlObject
public interface JdbiDao {
    @SqlUpdate("insert into users (name) values ( ?)")
    @GetGeneratedKeys("id")
    long insert(String name);
}

mvn compile complains :

[ERROR] JdbiDaoImpl.java:[71,5] method does not override or implement a method from a supertype
[ERROR] JdbiDaoImpl.java:[73,78] cannot find symbol
[ERROR] symbol: method getHandle()
[ERROR] location: variable e of type com.example.JdbiDao

The problem locates in generated JdbiDaoImpl.java file, looking like:

public static class OnDemand implements JdbiDao {
    private final Jdbi db;

    public OnDemand(Jdbi db) {
      this.db = db;
    }

    @Override
    public long insert(String name) {
      return (long) db.withExtension(JdbiDao.class, e -> e.insert(name));
    }

    @Override
    public Handle getHandle() {
      return (org.jdbi.v3.core.Handle) db.withExtension(JdbiDao.class, e -> e.getHandle());
    }

    @Override
    public <R, X extends Exception> R withHandle(HandleCallback<R, X> callback) throws X {
      return (R) db.withExtension(JdbiDao.class, e -> e.withHandle(callback));
    }
  }

The generated OnDemand class is not a subclass/implementation of SqlObject, so it failes when compiling the method getHandle & withHandle.

So is this the expected behavior as designed ?

Maybe a generator direction could be added to supress the generation of OnDemand class (add a member in annotation GenerateSqlObject ?).

@stevenschlansker
Copy link
Member

Thanks for reporting this, it is fixed in #1788 which will be in the next release

@wbprime
Copy link
Author

wbprime commented Dec 1, 2020

Got it.

@wbprime wbprime closed this as completed Dec 1, 2020
@stevenschlansker
Copy link
Member

Fixed in 3.18.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants