Skip to content

Commit

Permalink
Merge pull request eclipse#534 from Emily-Jiang/configsource-issue
Browse files Browse the repository at this point in the history
eclipse#431 improve configsource api
  • Loading branch information
dmlloyd authored Mar 10, 2020
2 parents 102386b + fafb7ce commit 7f2f0b9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
******************************************************************************
* Copyright (c) 2009-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2009-2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -28,6 +28,7 @@
*******************************************************************************/
package org.eclipse.microprofile.config.spi;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -108,10 +109,16 @@ public interface ConfigSource {
*
* @return a map containing properties of this configuration source
*/
Map<String, String> getProperties();
default Map<String, String> getProperties() {
Map<String, String> props = new HashMap<>();
getPropertyNames().stream().forEach((prop) -> props.put(prop, getValue(prop)));
return props;
}



/**
* Gets all property names known to this configuration source, without evaluating the values.
* Gets all property names known to this configuration source, potentially without evaluating the values.
* <p>
* For backwards compatibility, there is a default implementation that just returns the keys of {@code getProperties()}.
* Implementations should consider replacing this with a more performant implementation.
Expand All @@ -120,9 +127,7 @@ public interface ConfigSource {
*
* @return a set of property names that are known to this configuration source
*/
default Set<String> getPropertyNames() {
return getProperties().keySet();
}
Set<String> getPropertyNames();

/**
* Return the ordinal priority value of this configuration source.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
* @author <a href="mailto:struberg@apache.org">Mark Struberg</a>
*
*/
@org.osgi.annotation.versioning.Version("1.4")
@org.osgi.annotation.versioning.Version("2.0")
package org.eclipse.microprofile.config.spi;
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import javax.enterprise.context.Dependent;
import javax.enterprise.inject.spi.CDI;
Expand Down Expand Up @@ -310,5 +311,10 @@ public String getValue(String propertyName) {
public String getName() {
return this.getClass().getName();
}

@Override
public Set<String> getPropertyNames() {
return properties.keySet();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.eclipse.microprofile.config.spi.ConfigSource;

Expand All @@ -41,12 +42,6 @@ public CustomDbConfigSource() {
public int getOrdinal() {
return 112;
}

@Override
public Map<String, String> getProperties() {
return readPropertiesFromDb();
}

@Override
public String getValue(String key) {
return readPropertyFromDb(key);
Expand All @@ -57,13 +52,15 @@ public String getName() {
return "customDbConfig";
}

private Map<String, String> readPropertiesFromDb() {
return configValues;
}

private String readPropertyFromDb(String key) {
return configValues.get(key);
}

@Override
public Set<String> getPropertyNames() {

return configValues.keySet();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.eclipse.microprofile.config.spi.ConfigSource;

Expand All @@ -40,11 +41,6 @@ public int getOrdinal() {
return 110;
}

@Override
public Map<String, String> getProperties() {
return config;
}

@Override
public String getValue(String key) {
return config.get(key);
Expand All @@ -55,4 +51,10 @@ public String getName() {
return null;
}

@Override
public Set<String> getPropertyNames() {

return config.keySet();
}

}

0 comments on commit 7f2f0b9

Please sign in to comment.