Search in sources :

Example 1 with AQjmsConnectionFactory

use of oracle.jms.AQjmsConnectionFactory in project helidon by oracle.

the class AqConnectorImpl method createAqFactory.

private AQjmsConnectionFactory createAqFactory(Config c) throws javax.jms.JMSException {
    ConfigValue<String> user = c.get(USERNAME_ATTRIBUTE).asString();
    ConfigValue<String> password = c.get(PASSWORD_ATTRIBUTE).asString();
    ConfigValue<String> url = c.get(URL_ATTRIBUTE).asString();
    ConfigValue<String> dataSourceName = c.get(DATASOURCE_ATTRIBUTE).asString();
    AQjmsConnectionFactory fact = new AQjmsConnectionFactory();
    if (dataSourceName.isPresent()) {
        if (user.isPresent()) {
            throw new MessagingException("When " + DATASOURCE_ATTRIBUTE + " is set, properties " + String.join(", ", USERNAME_ATTRIBUTE, PASSWORD_ATTRIBUTE, URL_ATTRIBUTE) + " are forbidden!");
        }
        // DataSource provided via SE builder
        DataSource seDataSource = dataSourceMap.get(dataSourceName.get());
        if (seDataSource != null) {
            fact.setDatasource(seDataSource);
        }
        // DataSource provided via CDI as named bean
        if (IS_CDI.get()) {
            Instance<DataSource> dataSources = CDI.current().select(DataSource.class, NamedLiteral.of(dataSourceName.get()));
            if (dataSources.isResolvable()) {
                fact.setDatasource(dataSources.get());
            } else {
                throw new MessagingException("Datasource " + dataSourceName.get() + (dataSources.isAmbiguous() ? " is ambiguous!" : " not found!"));
            }
        }
    }
    if (url.isPresent()) {
        fact.setJdbcURL(url.get());
    }
    if (user.isPresent()) {
        fact.setUsername(user.get());
    }
    if (password.isPresent()) {
        fact.setPassword(password.get());
    }
    return fact;
}
Also used : AQjmsConnectionFactory(oracle.jms.AQjmsConnectionFactory) MessagingException(io.helidon.messaging.MessagingException) DataSource(javax.sql.DataSource)

Aggregations

MessagingException (io.helidon.messaging.MessagingException)1 DataSource (javax.sql.DataSource)1 AQjmsConnectionFactory (oracle.jms.AQjmsConnectionFactory)1