Skip to content

Commit

Permalink
JDBCResourceStore: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsCharlier committed Dec 15, 2015
1 parent 89a795d commit f7da4a1
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 235 deletions.
1 change: 0 additions & 1 deletion src/community/jdbcconfig/pom.xml
Expand Up @@ -46,7 +46,6 @@
<dependency> <dependency>
<groupId>commons-dbcp</groupId> <groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId> <artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency> </dependency>


<dependency> <dependency>
Expand Down
Expand Up @@ -131,7 +131,7 @@ protected Optional<DataSource> getJNDIDataSource(Optional<String> name) {
try { try {
Optional<DataSource> ds = Optional.of((DataSource)jndiCtx.lookup(name.get())); Optional<DataSource> ds = Optional.of((DataSource)jndiCtx.lookup(name.get()));
if(LOGGER.isLoggable(Level.INFO)) { if(LOGGER.isLoggable(Level.INFO)) {
LOGGER.log(Level.INFO, "JDBCLoaer using JNDI DataSource {0}", name.get()); LOGGER.log(Level.INFO, "JDBCLoader using JNDI DataSource {0}", name.get());
} }
config.setDatasourceId(name.get()); config.setDatasourceId(name.get());
return ds; return ds;
Expand Down
Expand Up @@ -28,15 +28,15 @@ public abstract class JDBCLoaderPropertiesFactoryBean extends PropertiesFactoryB


private static final Logger LOGGER = Logging.getLogger(JDBCGeoServerLoader.class); private static final Logger LOGGER = Logging.getLogger(JDBCGeoServerLoader.class);


protected static final String CONFIG_FILE = "${pref}.properties"; protected static final String CONFIG_FILE = "${prefix}.properties";


protected static final String CONFIG_SYSPROP = "${pref}.properties"; protected static final String CONFIG_SYSPROP = "${prefix}.properties";


protected static final String JDBCURL_SYSPROP = "${pref}.jdbcurl"; protected static final String JDBCURL_SYSPROP = "${prefix}.jdbcurl";


protected static final String INITDB_SYSPROP = "${pref}.initdb"; protected static final String INITDB_SYSPROP = "${prefix}.initdb";


protected static final String IMPORT_SYSPROP = "${pref}.import"; protected static final String IMPORT_SYSPROP = "${prefix}.import";


protected ResourceStore resourceStore; protected ResourceStore resourceStore;


Expand All @@ -55,8 +55,8 @@ public JDBCLoaderPropertiesFactoryBean(ResourceStore resourceStore, String prefi


protected abstract String[] getSampleConfigurations(); protected abstract String[] getSampleConfigurations();


protected String pref(String s) { protected String replacePrefix(String s) {
return s.replace("${pref}", prefix); return s.replace("${prefix}", prefix);
} }


@Override @Override
Expand Down Expand Up @@ -105,24 +105,24 @@ private JDBCLoaderProperties loadConfig() throws IOException {


protected JDBCLoaderProperties loadDefaultConfig() throws IOException { protected JDBCLoaderProperties loadDefaultConfig() throws IOException {
JDBCLoaderProperties config = createConfig(); JDBCLoaderProperties config = createConfig();
config.load(getClass().getResourceAsStream("/" + pref(CONFIG_FILE))); config.load(getClass().getResourceAsStream("/" + replacePrefix(CONFIG_FILE)));
return config; return config;
} }


protected boolean loadConfigFromSysProps(JDBCLoaderProperties config) throws IOException { protected boolean loadConfigFromSysProps(JDBCLoaderProperties config) throws IOException {
String jdbcUrl = System.getProperty(pref(JDBCURL_SYSPROP)); String jdbcUrl = System.getProperty(replacePrefix(JDBCURL_SYSPROP));
if (jdbcUrl != null) { if (jdbcUrl != null) {
config.setJdbcUrl(jdbcUrl); config.setJdbcUrl(jdbcUrl);


config.setInitDb(Boolean.getBoolean(pref(INITDB_SYSPROP))); config.setInitDb(Boolean.getBoolean(replacePrefix(INITDB_SYSPROP)));
config.setImport(Boolean.getBoolean(pref(IMPORT_SYSPROP))); config.setImport(Boolean.getBoolean(replacePrefix(IMPORT_SYSPROP)));


if (LOGGER.isLoggable(Level.INFO)) { if (LOGGER.isLoggable(Level.INFO)) {
StringBuilder msg = StringBuilder msg =
new StringBuilder("Configuring jdbcloader from system properties:\n"); new StringBuilder("Configuring jdbcloader from system properties:\n");
msg.append(" ").append(pref(JDBCURL_SYSPROP)).append("=").append(jdbcUrl).append("\n"); msg.append(" ").append(replacePrefix(JDBCURL_SYSPROP)).append("=").append(jdbcUrl).append("\n");
msg.append(" ").append(pref(INITDB_SYSPROP)).append("=").append(config.isInitDb()).append("\n"); msg.append(" ").append(replacePrefix(INITDB_SYSPROP)).append("=").append(config.isInitDb()).append("\n");
msg.append(" ").append(pref(IMPORT_SYSPROP)).append("=").append(config.isImport()).append("\n"); msg.append(" ").append(replacePrefix(IMPORT_SYSPROP)).append("=").append(config.isImport()).append("\n");
LOGGER.info(msg.toString()); LOGGER.info(msg.toString());
} }
return true; return true;
Expand All @@ -131,7 +131,7 @@ protected boolean loadConfigFromSysProps(JDBCLoaderProperties config) throws IOE
} }


private boolean loadConfigFromURL(JDBCLoaderProperties config) throws IOException { private boolean loadConfigFromURL(JDBCLoaderProperties config) throws IOException {
String propUrl = System.getProperty(pref(CONFIG_SYSPROP)); String propUrl = System.getProperty(replacePrefix(CONFIG_SYSPROP));
if (propUrl == null) { if (propUrl == null) {
return false; return false;
} }
Expand Down Expand Up @@ -166,12 +166,12 @@ private boolean loadConfigFromURL(JDBCLoaderProperties config) throws IOExceptio
return true; return true;
} }


LOGGER.severe("System property " + pref(CONFIG_SYSPROP) + " specified " + propUrl + " but could not be read, ignoring."); LOGGER.severe("System property " + replacePrefix(CONFIG_SYSPROP) + " specified " + propUrl + " but could not be read, ignoring.");
return false; return false;
} }


private boolean loadConfigFromDataDir(JDBCLoaderProperties config) throws IOException { private boolean loadConfigFromDataDir(JDBCLoaderProperties config) throws IOException {
Resource propFile = getBaseDir().get(pref(CONFIG_FILE)); Resource propFile = getBaseDir().get(replacePrefix(CONFIG_FILE));
if (Resources.exists(propFile)) { if (Resources.exists(propFile)) {
LOGGER.info("Loading jdbcloader properties from " + propFile.path()); LOGGER.info("Loading jdbcloader properties from " + propFile.path());
InputStream stream = propFile.in(); InputStream stream = propFile.in();
Expand All @@ -190,7 +190,7 @@ void saveConfig(JDBCLoaderProperties config) throws IOException {
} }


private void saveConfig(JDBCLoaderProperties config, String comment) throws IOException { private void saveConfig(JDBCLoaderProperties config, String comment) throws IOException {
Resource propFile = getBaseDir().get(pref(CONFIG_FILE)); Resource propFile = getBaseDir().get(replacePrefix(CONFIG_FILE));


try { try {
OutputStream out = propFile.out(); OutputStream out = propFile.out();
Expand Down
Expand Up @@ -240,7 +240,7 @@ public Resource get(String resourcePath) {
public List<Resource> list() { public List<Resource> list() {
if (getType() != Type.DIRECTORY) { if (getType() != Type.DIRECTORY) {
return Collections.EMPTY_LIST; return Collections.EMPTY_LIST;
} }


List<Resource> list = new ArrayList<Resource>(); List<Resource> list = new ArrayList<Resource>();


Expand Down
Expand Up @@ -50,18 +50,11 @@ public void setCacheChildren(boolean cacheChildren) {


void cacheData(Resource res, File file) throws IOException { void cacheData(Resource res, File file) throws IOException {
assert res.getType()==Type.RESOURCE; assert res.getType()==Type.RESOURCE;
OutputStream out = new FileOutputStream(file); try (OutputStream out = new FileOutputStream(file)) {
try { try (InputStream in = res.in()) {
InputStream in = res.in();
try {
IOUtils.copy(in, out); IOUtils.copy(in, out);
} finally {
in.close();
} }
} finally {
out.close();
} }

} }


void cacheChildren(Resource res, File file) throws IOException { void cacheChildren(Resource res, File file) throws IOException {
Expand Down

0 comments on commit f7da4a1

Please sign in to comment.