Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed the internal field that SqlInfo has from a Path type to a URL type #345

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading