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

StringIndexOutOfBoundsException when using RXReactiveVertxGenerator #104

Open
paninics opened this issue Mar 1, 2019 · 3 comments
Open

Comments

@paninics
Copy link

paninics commented Mar 1, 2019

jOOQ version: 3.11.9
vert-jooq version: 4.1.0

I'm looking at the generated DAOs and notice that the constructor, as shown below, refers to the JDBCRXQueryExecutor

    public AddressDao(Configuration configuration, io.vertx.reactivex.core.Vertx vertx) {
        super(AddressTable.ADDRESS, Address.class, new JDBCRXQueryExecutor<AddressRecord,Address,UUID>(configuration,Address.class,vertx));
    }

However, I want to specify that the ReactiveRXGenericQueryExecutor be used instead as the run time code relies on it. I looked through the documentation and did not find any jOOQ code generation settings to enable this scenario. How can I do it?

@paninics
Copy link
Author

paninics commented Mar 1, 2019

I was able to figure it out. My custom code generator extended RXJDBCVertxGenerator instead of RXReactiveVertxGenerator. But now, I run into a possible bug as I get the below exception.

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
	at java.lang.String.substring(String.java:1967)
	at io.github.jklingsporn.vertx.jooq.generate.builder.VertxGeneratorBuilder$ExecutionStepImpl.lambda$withPostgresReactiveDriver$30(VertxGeneratorBuilder.java:411)
	at io.github.jklingsporn.vertx.jooq.generate.builder.ComponentBasedVertxGenerator.writeDAOConstructor(ComponentBasedVertxGenerator.java:83)
	at io.github.jklingsporn.vertx.jooq.generate.builder.DelegatingVertxGenerator.writeDAOConstructor(DelegatingVertxGenerator.java:64)
	at io.github.jklingsporn.vertx.jooq.generate.VertxGenerator.generateDAO(VertxGenerator.java:564)
	at io.github.jklingsporn.vertx.jooq.generate.VertxGenerator.generateDao(VertxGenerator.java:501)
	at org.jooq.codegen.JavaGenerator.generateDao(JavaGenerator.java:2867)
	at org.jooq.codegen.JavaGenerator.generateDaos(JavaGenerator.java:2854)
	at io.github.jklingsporn.vertx.jooq.generate.VertxGenerator.generateDaos(VertxGenerator.java:234)
	at org.jooq.codegen.JavaGenerator.generate(JavaGenerator.java:512)
	at org.jooq.codegen.JavaGenerator.generate(JavaGenerator.java:458)
	at org.jooq.codegen.JavaGenerator.generate(JavaGenerator.java:380)
	at org.jooq.codegen.GenerationTool.run(GenerationTool.java:752)
	at org.jooq.codegen.GenerationTool.generate(GenerationTool.java:222)

Upon debugging, it appears that the code in VertxGeneratorBuilder is making assumptions about the path / package name space that is incorrect.

@paninics paninics changed the title Code generation and RXQueryExecutor mismatch StringIndexOutOfBoundsException when using RXReactiveVertxGenerator Mar 1, 2019
@paninics
Copy link
Author

paninics commented Mar 1, 2019

And here's a simple way to reproduce the problem. Use a custom code generator strategy, shown below, along with RXReactiveVertxGenerator.

public class TestGeneratorStrategy extends VertxGeneratorStrategy {

    @Override
    public String getJavaClassName(Definition definition, Mode mode) {
        String s = super.getJavaClassName(definition, mode);
        if (mode == Mode.DEFAULT && definition instanceof TableDefinition) {
            s = s + "Table";
        }
        return s;
    }
}

The issue has something to do with Mode.DEFAULT as if we remove the partial check (i.e. mode == Mode.DEFAULT) in the above if clause, we would no longer get the error. Also to be noted, if we switch to using RXJDBCVertxGenerator along with the above code generator strategy as is, it works!

@paninics
Copy link
Author

paninics commented Mar 1, 2019

Upon further experimenting, it appears that the generation code is expecting the class names for the pojo and table objects to be the same. Below is a slight variation to the custom code generator strategy to demonstrate that you would no longer get the error, though of course the pojo class names does not make sense in this example. In summary, we need these names to be decoupled.

public class TestGeneratorStrategy extends VertxGeneratorStrategy {
    @Override
    public String getJavaClassName(Definition definition, Mode mode) {
        String s = super.getJavaClassName(definition, mode);
        if (mode == Mode.DEFAULT && definition instanceof TableDefinition) {
            s = s + "Table";
        } else if (mode == Mode.POJO) {
            s = s + "Table";
        }
        return s;
    }
}

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

No branches or pull requests

1 participant