private void validate() { if (StringUtils.isBlank(getUrl())) { throw new MotechConfigurationException("Motech SQL URL cannot be null or empty."); } if (StringUtils.isBlank(getDriver())) { throw new MotechConfigurationException("Motech SQL Driver cannot be null or empty."); } if (!getUrl().matches("jdbc:(\\w+:)+//(\\w+\\.)*\\w+:\\d+/")) { throw new MotechConfigurationException("Motech SQL URL is invalid."); } } }
private void setSqlProperties() { SQLDBConfig sqlConfig = coreConfigurationService.loadBootstrapConfig().getSqlConfig(); String sqlUrl = sqlConfig.getUrl(); sqlProperties.setProperty("sql.url", sqlUrl); String sqlUser = sqlConfig.getUsername(); if (sqlUser != null) { sqlProperties.setProperty("sql.user", sqlUser); } String sqlPassword = sqlConfig.getPassword(); if (sqlPassword != null) { sqlProperties.setProperty("sql.password", sqlPassword); } String sqlDriver = sqlConfig.getDriver(); if (sqlDriver != null) { sqlProperties.setProperty("sql.driver", sqlDriver); } }
/** * Map from BootstrapConfig to Properties * * @param bootstrapConfig * @return Properties mapped from provided bootstrapConfig. */ public static Properties toProperties(BootstrapConfig bootstrapConfig) { Properties properties = new Properties(); properties.setProperty(BootstrapConfig.COUCHDB_URL, bootstrapConfig.getCouchDbConfig().getUrl()); setIfNotBlank(properties, BootstrapConfig.COUCHDB_USERNAME, bootstrapConfig.getCouchDbConfig().getUsername()); setIfNotBlank(properties, BootstrapConfig.COUCHDB_PASSWORD, bootstrapConfig.getCouchDbConfig().getPassword()); properties.setProperty(BootstrapConfig.SQL_URL, bootstrapConfig.getSqlConfig().getUrl()); properties.setProperty(BootstrapConfig.SQL_DRIVER, bootstrapConfig.getSqlConfig().getDriver()); setIfNotBlank(properties, BootstrapConfig.SQL_USER, bootstrapConfig.getSqlConfig().getUsername()); setIfNotBlank(properties, BootstrapConfig.SQL_PASSWORD, bootstrapConfig.getSqlConfig().getPassword()); properties.setProperty(BootstrapConfig.TENANT_ID, bootstrapConfig.getTenantId()); properties.setProperty(BootstrapConfig.CONFIG_SOURCE, bootstrapConfig.getConfigSource().getName()); return properties; }