malavock
malavock

Reputation: 371

Dropwizard JDBI query how to use dynamic table name

Our application uses Dropwizard and JDBI to handle queries to a Postgres database.

Normally we would have a different database for production and staging, but now we are integrating with a new system and this shares the same database for staging and prod, but uses a different set of tables.

For example we would have the table users and users_stg

Is there a way to pass the table name in a dynamic way to the query, so that we can set the table names in the properties file?

Example of current query

public interface UsersDao {
@SqlUpdate("update table users ...")
    void updateUsers();
}

Example of wanted query

@SqlUpdate("update table :table ...")
    void updateUsers(@Bind String table);

Of course the @Bind won't work as it is meant for parameters only, but would there be any other way that could work with table names?

If Dropwizard didn't require an Interface i could have an attribute in the dao, but being an interface I cannot initialise it either.

Upvotes: 0

Views: 325

Answers (1)

malavock
malavock

Reputation: 371

This worked

@SqlUpdate("update table ...") void updateUsers(@Define String table);

Upvotes: 0

Related Questions