Skip to content

Commit

Permalink
Refactor ShardingSphereURLLoadEngine (#30144)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Feb 16, 2024
1 parent e7ca0ea commit 0f4f997
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public DataSource get(final String url, final String urlPrefix) {
@SuppressWarnings("unchecked")
private <T extends Throwable> DataSource createDataSource(final ShardingSphereURL url) throws T {
try {
return YamlShardingSphereDataSourceFactory.createDataSource(ShardingSphereURLLoadEngine.loadContent(url));
ShardingSphereURLLoadEngine urlLoadEngine = new ShardingSphereURLLoadEngine(url);
return YamlShardingSphereDataSourceFactory.createDataSource(urlLoadEngine.loadContent());
} catch (final IOException ex) {
throw (T) new SQLException(ex);
} catch (final SQLException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.apache.shardingsphere.driver.jdbc.core.driver.url;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.driver.jdbc.core.driver.url.arg.URLArgumentLineRender;
import org.apache.shardingsphere.driver.jdbc.core.driver.url.arg.URLArgumentPlaceholderTypeFactory;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
Expand All @@ -29,17 +27,23 @@
/**
* ShardingSphere URL load engine.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ShardingSphereURLLoadEngine {

private final ShardingSphereURL url;

private final ShardingSphereURLLoader urlLoader;

public ShardingSphereURLLoadEngine(final ShardingSphereURL url) {
this.url = url;
urlLoader = TypedSPILoader.getService(ShardingSphereURLLoader.class, url.getSourceType());
}

/**
* Load configuration content.
*
* @param url ShardingSphere URL
* @return loaded content
*/
public static byte[] loadContent(final ShardingSphereURL url) {
ShardingSphereURLLoader urlLoader = TypedSPILoader.getService(ShardingSphereURLLoader.class, url.getSourceType());
public byte[] loadContent() {
Collection<String> lines = Arrays.asList(urlLoader.load(url.getConfigurationSubject(), url.getParameters()).split(System.lineSeparator()));
return URLArgumentLineRender.render(lines, URLArgumentPlaceholderTypeFactory.valueOf(url.getParameters()));
}
Expand Down

0 comments on commit 0f4f997

Please sign in to comment.