Hi Lukas,
Sure I can post some code...here is our JOOQ configuration. This is
probably where we are doing things wrong as we aren't doing anything with
the SPIs in the Configuration, we are just using defaults. We call this
method several times when our application starts and pass the Connection
instances to several DAO instances. Note this is not a Singleton but could
be if that is better.
public Configuration getConfiguration() throws OdinDomainConfigurationException
{
try
{
final InputStream resourceAsStream =
getClass().getResourceAsStream("/conf/config.json");
JsonObject jsonObject = new JsonObject(new
String(IOUtils.toByteArray(resourceAsStream)));
final String dbHost = jsonObject.getString("db.host", "odindb");
final Integer dbPort = jsonObject.getInteger("db.port", 5432);
final String dbUser = jsonObject.getString("db.user", "odin_owner");
final String dbDatabase = jsonObject.getString("db.database", "odindb");
final String dbEncryptedPassword =
jsonObject.getString("db.password.encrypted");
String dbPassword = encryptEngine.decryptString(dbEncryptedPassword);
final DefaultConfiguration configuration = new DefaultConfiguration();
configuration.set(SQLDialect.POSTGRES_9_4);
final Properties properties = new Properties();
properties.setProperty("password", dbPassword);
configuration.set(new PgConnection(
new HostSpec[]{new HostSpec(dbHost, dbPort)},
dbUser,
dbDatabase,
properties,
String.format("jdbc:postgresql://%s:%d/%s", dbHost, dbPort,
dbDatabase)));
return configuration;
}
catch (Exception e)
{
throw new OdinDomainConfigurationException("Failed to connect to the
database", e);
}
}
Thanks,
-Dave
On Thursday, May 3, 2018 at 8:05:10 AM UTC-6, Lukas Eder wrote:
>
> Hi David,
>
> Well, perhaps the information about the third party plugin wasn't strictly
> necessary to get to the bottom of the issue. It's always helpful to provide
> an MVCE (minimal complete verifiable example)
> https://stackoverflow.com/help/mcve
>
> Such examples with code usually beat prose any time :)
>
> 2018-05-03 15:51 GMT+02:00 David Hoffer <[email protected] <javascript:>>:
>
>> Okay I can get with the author of the customized code generator for more
>> specifics but I believe that just adds a bit of functionality on top of
>> standard JOOQ generated code. I understand the plugin itself is from JOOQ.
>>
>> Specifically it is just using the standard JOOQ Configuration class and
>> all the DAOs extend from DAOImpl which too is standard JOOQ.
>>
>> So for those two classes how should things be structured so that we never
>> loose DB connection? E.g. what is the lifecycle of those classes/instances?
>>
>
> They don't have a lifecycle. All lifecycle objects are inside of the
> Configuration.
>
>
>> Currently we are assuming we can create any number of
>> DefaultConfiguration instances and they each last indefinitely and we can
>> use those instances in any number of DAOs which also last indefinitely.
>> However is that correct?
>>
>
> Could be. Neither the configuration itself, nor the DAOs have anything to
> do with lifecycles. The important SPIs are *inside* of the Configuration
>
>
>> E.g. we are not expecting any lifecycle/termination of either objects.
>> However perhaps that is not the case or we need more than a
>> DefaultConfiguration? Also should our DefaultConfiguration instance be a
>> Singleton? Currently it is not. Also are there any DB connection pools we
>> need to be concerned with?
>>
>
> You're completely responsible yourself for those connection pools. jOOQ
> works with JDBC Connection or DataSource instances. jOOQ doesn't care how
> they're created / maintained. If you want, jOOQ works just like JDBC itself.
>
>
>> We are just looking for guidance on how to bootstrap JOOQ's DB
>> configuration with DAOImpl instances. Are there code examples of this?
>>
>
> There's the manual:
> https://www.jooq.org/doc/latest/manual/sql-execution/daos
>
> But you won't get anything out of there that I haven't mentioned above. If
> you can make your verticles work with JDBC, they can work with jOOQ as well.
>
> This *should* be really simple, but without seeing any code /
> configuration, it's very difficult to asses where it went wrong. Most
> probably outside of jOOQ, though.
>
> I hope this helps,
> Lukas
>
--
You received this message because you are subscribed to the Google Groups "jOOQ
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.