Search in sources :

Example 1 with JDBCConfigSourceConfiguration

use of fish.payara.nucleus.microprofile.config.spi.JDBCConfigSourceConfiguration in project Payara by payara.

the class SetJDBCConfigSourceConfiguration method execute.

@Override
public void execute(AdminCommandContext acc) {
    final ActionReport actionReport = acc.getActionReport();
    final Config targetConfig = targetUtil.getConfig(target);
    if (targetConfig == null) {
        actionReport.setMessage("No such config named: " + target);
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    JDBCConfigSourceConfiguration jdbcConfigSourceConfiguration = targetConfig.getExtensionByType(JDBCConfigSourceConfiguration.class);
    try {
        ConfigSupport.apply(configProxy -> {
            if (jndiName != null) {
                configProxy.setJndiName(jndiName);
            }
            if (tableName != null) {
                configProxy.setTableName(tableName);
            }
            if (keyColumnName != null) {
                configProxy.setKeyColumnName(keyColumnName);
            }
            if (valueColumnName != null) {
                configProxy.setValueColumnName(valueColumnName);
            }
            actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
            return configProxy;
        }, jdbcConfigSourceConfiguration);
    } catch (TransactionFailure ex) {
        actionReport.failure(LOGGER, "Failed to update JDBC Config Source configuration", ex);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JDBCConfigSourceConfiguration(fish.payara.nucleus.microprofile.config.spi.JDBCConfigSourceConfiguration) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport)

Example 2 with JDBCConfigSourceConfiguration

use of fish.payara.nucleus.microprofile.config.spi.JDBCConfigSourceConfiguration in project Payara by payara.

the class GetJDBCConfigSourceConfiguration method execute.

@Override
public void execute(AdminCommandContext acc) {
    final ActionReport actionReport = acc.getActionReport();
    final Config targetConfig = targetUtil.getConfig(target);
    if (targetConfig == null) {
        actionReport.setMessage("No such config named: " + target);
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    JDBCConfigSourceConfiguration jdbcConfigSourceConfiguration = targetConfig.getExtensionByType(JDBCConfigSourceConfiguration.class);
    ColumnFormatter columnFormatter = new ColumnFormatter(OUTPUT_HEADERS);
    Object[] outputValues = { jdbcConfigSourceConfiguration.getJndiName(), jdbcConfigSourceConfiguration.getTableName(), jdbcConfigSourceConfiguration.getKeyColumnName(), jdbcConfigSourceConfiguration.getValueColumnName() };
    columnFormatter.addRow(outputValues);
    actionReport.appendMessage(columnFormatter.toString());
    Map<String, Object> extraPropertiesMap = new HashMap<>();
    extraPropertiesMap.put("jndiName", jdbcConfigSourceConfiguration.getJndiName());
    extraPropertiesMap.put("tableName", jdbcConfigSourceConfiguration.getTableName());
    extraPropertiesMap.put("keyColumnName", jdbcConfigSourceConfiguration.getKeyColumnName());
    extraPropertiesMap.put("valueColumnName", jdbcConfigSourceConfiguration.getValueColumnName());
    Properties extraProperties = new Properties();
    extraProperties.put("jdbcConfigSourceConfiguration", extraPropertiesMap);
    actionReport.setExtraProperties(extraProperties);
}
Also used : JDBCConfigSourceConfiguration(fish.payara.nucleus.microprofile.config.spi.JDBCConfigSourceConfiguration) HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)2 JDBCConfigSourceConfiguration (fish.payara.nucleus.microprofile.config.spi.JDBCConfigSourceConfiguration)2 ActionReport (org.glassfish.api.ActionReport)2 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1