Skip to content

Commit

Permalink
Changed the internal field that SqlInfo has from a Path type to a URL…
Browse files Browse the repository at this point in the history
… type
  • Loading branch information
HidekiSugimoto189 committed Oct 30, 2024
1 parent 4885c7c commit e2788ae
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/main/java/jp/co/future/uroborosql/SqlAgentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1885,8 +1885,8 @@ private void transformContext(final ExecutionContext executionContext) {
.log();
} else if (getSqlResourceManager().existSql(sqlName)) {
debugWith(SQL_LOG)
.setMessage("SQLPath : {}")
.addArgument(() -> getSqlResourceManager().getSqlPath(sqlName))
.setMessage("SQLUrl : {}")
.addArgument(() -> getSqlResourceManager().getSqlUrl(sqlName))
.log();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package jp.co.future.uroborosql.store;

import java.net.URL;
import java.nio.file.Path;
import java.util.List;

Expand Down Expand Up @@ -107,12 +108,12 @@ public interface SqlResourceManager extends ServiceLoggingSupport {
String getSqlName(final Path path);

/**
* SQL名に対して現在有効なファイルパスを取得する
* SQL名に対して現在有効なURLを取得する
*
* @param sqlName SQL名
* @return 現在有効なファイルパス。存在しないSQL名の場合はUroborosqlRuntimeExceptionがスローされる
* @return 現在有効なURL。存在しないSQL名の場合はUroborosqlRuntimeExceptionがスローされる
*/
Path getSqlPath(String sqlName);
URL getSqlUrl(String sqlName);

/**
* ロードしたSQLのパス一覧を取得する
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,12 @@ protected boolean generateSqlInfo(final String sqlName) throws IOException {
try {
var scheme = url.toURI().getScheme().toLowerCase();
var sqlBody = loadSql(url);
var sqlInfo = new SqlInfo(path, loadPath, scheme, sqlBody);
var sqlInfo = new SqlInfo(url, loadPath, scheme, sqlBody);
this.sqlInfos.put(sqlName, sqlInfo);
traceWith(LOG)
.setMessage("SqlInfo - sqlName : {}, path : {}, rootPath : {}, scheme : {}, sqlBody : {}.")
.setMessage("SqlInfo - sqlName : {}, url : {}, rootPath : {}, scheme : {}, sqlBody : {}.")
.addArgument(sqlName)
.addArgument(sqlInfo.getPath())
.addArgument(sqlInfo.getUrl())
.addArgument(sqlInfo.getRootPath())
.addArgument(sqlInfo.getScheme())
.addArgument(sqlInfo.getSqlBody())
Expand Down Expand Up @@ -359,16 +359,16 @@ public String getSqlName(final Path path) {
*
* {@inheritDoc}
*
* @see jp.co.future.uroborosql.store.SqlResourceManager#getSqlPath(java.lang.String)
* @see jp.co.future.uroborosql.store.SqlResourceManager#getSqlUrl(java.lang.String)
*/
@Override
public Path getSqlPath(final String sqlName) {
public URL getSqlUrl(final String sqlName) {
if (existSql(sqlName)) {
return sqlInfos.get(sqlName).getPath();
return sqlInfos.get(sqlName).getUrl();
} else {
try {
if (generateSqlInfo(sqlName)) {
return sqlInfos.get(sqlName).getPath();
return sqlInfos.get(sqlName).getUrl();
} else {
throw new UroborosqlRuntimeException("sql file not found. sqlName : " + sqlName);
}
Expand Down Expand Up @@ -469,8 +469,8 @@ private Path relativePath(final Path path) {
* SQLファイルの情報を保持するオブジェクト
*/
protected static class SqlInfo {
/** sqlNameに対応するPath. */
private final Path path;
/** sqlNameに対応するURL. */
private final URL url;

/** 読み込みを行ったSQLルートパス */
private final Path rootPath;
Expand All @@ -483,24 +483,24 @@ protected static class SqlInfo {

/**
* コンストラクタ
* @param path Path
* @param url URL
* @param rootPath 読み込みを行ったSQLルートパス
* @param scheme 読み込んだファイルのscheme
* @param sqlBody SqlBody
*/
public SqlInfo(final Path path, final Path rootPath, final String scheme, final String sqlBody) {
this.path = path;
public SqlInfo(final URL url, final Path rootPath, final String scheme, final String sqlBody) {
this.url = url;
this.rootPath = rootPath;
this.scheme = scheme;
this.sqlBody = sqlBody;
}

/**
* sqlNameに対応するPath.を取得します.
* @return sqlNameに対応するPath.
* sqlNameに対応するURLを取得します.
* @return sqlNameに対応するURL.
*/
public Path getPath() {
return path;
public URL getUrl() {
return url;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ void testGetSqlPath() throws Exception {
List.of("example/select_test")
.forEach(sqlName -> manager.getSql(sqlName));

assertThat(manager.getSqlPath("example/select_test"), is(Paths.get("sql/h2/example/select_test.sql")));
assertThat(manager.getSqlPath("example/select_test2"), is(Paths.get("sql/example/select_test2.sql")));
assertThat(manager.getSqlPath("example/select_test3"), is(Paths.get("sql/h2/example/select_test3.sql")));
assertThrows(UroborosqlRuntimeException.class, () -> manager.getSqlPath("example/select_test4"));
assertThat(manager.getSqlUrl("example/select_test").getPath(),
containsString("/sql/h2/example/select_test.sql"));
assertThat(manager.getSqlUrl("example/select_test2").getPath(),
containsString("/sql/example/select_test2.sql"));
assertThat(manager.getSqlUrl("example/select_test3").getPath(),
containsString("/sql/h2/example/select_test3.sql"));
assertThrows(UroborosqlRuntimeException.class, () -> manager.getSqlUrl("example/select_test4"));
}

@Test
Expand Down

0 comments on commit e2788ae

Please sign in to comment.