diff --git a/README.md b/README.md index ba65f78..210695a 100644 --- a/README.md +++ b/README.md @@ -54,31 +54,31 @@ dependencies { First, you'll define `DataSrc` which manages connections to external data services and creates `DataConn`. Then, you'll define `DataConn` which represents a session-specific connection and implements transactional operations. ```java -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; import com.github.sttk.sabi.DataSrc; import com.github.sttk.sabi.DataConn; import com.github.sttk.sabi.AsyncGroup; class FooDataSrc implements DataSrc { - @Override public void setup(AsyncGroup ag) throws Exc {} + @Override public void setup(AsyncGroup ag) throws Err {} @Override public void close() {} - @Override public DataConn createDataConn() throws Exc { return new FooDataConn(); } + @Override public DataConn createDataConn() throws Err { return new FooDataConn(); } } class FooDataConn implements DataConn { - @Override public void commit(AsyncGroup ag) throws Exc {} + @Override public void commit(AsyncGroup ag) throws Err {} @Override public void rollback(AsyncGroup ag) {} @Override public void close(AsyncGroup ag) {} } class BarDataSrc implements DataSrc { - @Override public void setup(AsyncGroup ag) throws Exc {} + @Override public void setup(AsyncGroup ag) throws Err {} @Override public void close() {} - @Override public DataConn createDataConn() throws Exc { return new BarDataConn(); } + @Override public DataConn createDataConn() throws Err { return new BarDataConn(); } } class BarDataConn implements DataConn { - @Override public void commit(AsyncGroup ag) throws Exc {} + @Override public void commit(AsyncGroup ag) throws Err {} @Override public void rollback(AsyncGroup ag) {} @Override public void close(AsyncGroup ag) {} } @@ -89,16 +89,16 @@ class BarDataConn implements DataConn { Define interfaces and functions that express your application logic. These interfaces are independent of specific data source implementations, improving testability. ```java -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; import com.github.sttk.sabi.Logic; interface MyData { - String getText() throws Exc; - void setText(String text) throws Exc; + String getText() throws Err; + void setText(String text) throws Err; } class MyLogic implements Logic { - @Override public void run(MyData data) throws Exc { + @Override public void run(MyData data) throws Err { String text = data.getText(); data.setText(text); } @@ -110,11 +110,11 @@ class MyLogic implements Logic { The `DataAcc` interface abstracts access to data connections. The methods defined here will be used to obtain data connections via `DataHub` and perform actual data operations. ```java -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; import com.github.sttk.sabi.DataAcc; interface GettingDataAcc extends DataAcc, MyData { - @Override default String getText() throws Exc { + @Override default String getText() throws Err { var conn = getDataConn("foo", FooDataConn.class); // ... return "output text"; @@ -122,7 +122,7 @@ interface GettingDataAcc extends DataAcc, MyData { } interface SettingDataAcc extends DataAcc, MyData { - @Override default void setText(String text) throws Exc { + @Override default void setText(String text) throws Err { var conn = getDataConn("bar", BarDataConn.class); // ... } @@ -134,7 +134,7 @@ interface SettingDataAcc extends DataAcc, MyData { The `DataHub` is the central component that manages all `DataSrc` and `DataConn`, providing access to them for your application logic. By implementing the data interface (`MyData`) from step 2 and the `DataAcc` class from step 3 on `DataHub`, you integrate them. ```java -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; import com.github.sttk.sabi.DataHub; class MyDataHub extends DataHub implements GettingDataAcc, SettingDataAcc {} @@ -145,7 +145,7 @@ class MyDataHub extends DataHub implements GettingDataAcc, SettingDataAcc {} Inside your init function, register your global `DataSrc`. Next, main function calls run function, and inside run function, setup the sabi framework. Then, create an instance of `DataHub` and register the necessary local `DataSrc` using the Uses method. Finally, use the txn method of `DataHub` to execute your defined application logic function (`MyLogic`) within a transaction. This automatically handles transaction commits and rollbacks. ```java -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; import com.github.sttk.sabi.Sabi; public class Main { diff --git a/pom.xml b/pom.xml index 86e7e60..95297ba 100644 --- a/pom.xml +++ b/pom.xml @@ -50,7 +50,7 @@ io.github.sttk errs - 0.1.0 + 0.2.0 compile diff --git a/src/main/java/com/github/sttk/sabi/AsyncGroup.java b/src/main/java/com/github/sttk/sabi/AsyncGroup.java index 82ffbe3..cdb8ee0 100644 --- a/src/main/java/com/github/sttk/sabi/AsyncGroup.java +++ b/src/main/java/com/github/sttk/sabi/AsyncGroup.java @@ -1,6 +1,6 @@ /* * AsyncGroup.java - * Copyright (C) 2023-2025 Takayuki Sato. All Rights Reserved. + * Copyright (C) 2023-2026 Takayuki Sato. All Rights Reserved. */ package com.github.sttk.sabi; @@ -16,14 +16,14 @@ public interface AsyncGroup { /** - * Represents the reason for a new {@link com.github.sttk.errs.Exc} exception object when an + * Represents the reason for a new {@link com.github.sttk.errs.Err} exception object when an * exception occurred during the execution of a {@link Runner} and the exception class was not the - * {@link com.github.sttk.errs.Exc}. + * {@link com.github.sttk.errs.Err}. */ record RunnerFailed() {} /** - * Represents the reason for an {@link com.github.sttk.errs.Exc} exception object when the + * Represents the reason for an {@link com.github.sttk.errs.Err} exception object when the * creation of a thread for asynchronous execution of a {@link Runner} fails. */ record RunnerInterrupted() {} diff --git a/src/main/java/com/github/sttk/sabi/DataAcc.java b/src/main/java/com/github/sttk/sabi/DataAcc.java index e8b1372..2a6855c 100644 --- a/src/main/java/com/github/sttk/sabi/DataAcc.java +++ b/src/main/java/com/github/sttk/sabi/DataAcc.java @@ -1,10 +1,10 @@ /* * DataAcc.java - * Copyright (C) 2023-2025 Takayuki Sato. All Rights Reserved. + * Copyright (C) 2023-2026 Takayuki Sato. All Rights Reserved. */ package com.github.sttk.sabi; -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; /** * An interface designed for implementing data access operations through default methods in its @@ -25,7 +25,7 @@ public interface DataAcc { * @param name The name identifying the specific data connection to retrieve. * @param cls The {@link Class} object representing the type of the desired data connection. * @return A data connection object of the specified type. - * @throws Exc if an error occurs while obtaining the data connection. + * @throws Err if an error occurs while obtaining the data connection. */ - C getDataConn(String name, Class cls) throws Exc; + C getDataConn(String name, Class cls) throws Err; } diff --git a/src/main/java/com/github/sttk/sabi/DataConn.java b/src/main/java/com/github/sttk/sabi/DataConn.java index 1b2ed07..6240219 100644 --- a/src/main/java/com/github/sttk/sabi/DataConn.java +++ b/src/main/java/com/github/sttk/sabi/DataConn.java @@ -1,10 +1,10 @@ /* * DataConn.java - * Copyright (C) 2022-2025 Takayuki Sato. All Rights Reserved. + * Copyright (C) 2022-2026 Takayuki Sato. All Rights Reserved. */ package com.github.sttk.sabi; -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; /** * The interface that abstracts a connection per session to an external data service, such as a @@ -25,18 +25,18 @@ public interface DataConn { * * @param ag An {@link AsyncGroup} that can be used to perform asynchronous operations if the * commit process is time-consuming. - * @throws Exc if an error occurs during the commit operation. + * @throws Err if an error occurs during the commit operation. */ - void commit(AsyncGroup ag) throws Exc; + void commit(AsyncGroup ag) throws Err; /** * Performs any necessary pre-commit operations. This method is called before the {@link * #commit(AsyncGroup)} method. * * @param ag An {@link AsyncGroup} that can be used for asynchronous pre-commit tasks. - * @throws Exc if an error occurs during the pre-commit operation. + * @throws Err if an error occurs during the pre-commit operation. */ - default void preCommit(AsyncGroup ag) throws Exc {} + default void preCommit(AsyncGroup ag) throws Err {} /** * Performs any necessary post-commit operations. This method is called after the {@link diff --git a/src/main/java/com/github/sttk/sabi/DataHub.java b/src/main/java/com/github/sttk/sabi/DataHub.java index 981179b..d817061 100644 --- a/src/main/java/com/github/sttk/sabi/DataHub.java +++ b/src/main/java/com/github/sttk/sabi/DataHub.java @@ -1,10 +1,10 @@ /* * DataHub.java - * Copyright (C) 2022-2025 Takayuki Sato. All Rights Reserved. + * Copyright (C) 2022-2026 Takayuki Sato. All Rights Reserved. */ package com.github.sttk.sabi; -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; import com.github.sttk.sabi.internal.DataHubInner; import java.util.Map; @@ -25,7 +25,7 @@ public class DataHub implements DataAcc, AutoCloseable { * @param errors A map containing the names of the data sources and the corresponding exceptions * that occurred during their setup. */ - public record FailToSetupGlobalDataSrcs(Map errors) {} + public record FailToSetupGlobalDataSrcs(Map errors) {} /** * Represents an error reason that occurred when failing to set up local {@link DataSrc} @@ -34,7 +34,7 @@ public record FailToSetupGlobalDataSrcs(Map errors) {} * @param errors A map containing the names of the data sources and the corresponding exceptions * that occurred during their setup. */ - public record FailToSetupLocalDataSrcs(Map errors) {} + public record FailToSetupLocalDataSrcs(Map errors) {} /** * Represents an error reason that occurred when failing to commit one or more {@link DataConn} @@ -43,7 +43,7 @@ public record FailToSetupLocalDataSrcs(Map errors) {} * @param errors A map containing the names of the data connections and the corresponding * exceptions that occurred during their commit. */ - public record FailToCommitDataConn(Map errors) {} + public record FailToCommitDataConn(Map errors) {} /** * Represents an error reason that occurred when failing to pre-commit one or more {@link @@ -52,7 +52,7 @@ public record FailToCommitDataConn(Map errors) {} * @param errors A map containing the names of the data connections and the corresponding * exceptions that occurred during their pre-commit. */ - public record FailToPreCommitDataConn(Map errors) {} + public record FailToPreCommitDataConn(Map errors) {} /** * Represents an error reason where no {@link DataSrc} was found to create a {@link DataConn} with @@ -128,11 +128,11 @@ public void disuses(String name) { * @param name The name of the data source from which to get the connection. * @param cls The {@link Class} object representing the desired type of the data connection. * @return A {@link DataConn} instance of the specified type. - * @throws Exc if no data source is found, if the connection cannot be created, if the created + * @throws Err if no data source is found, if the connection cannot be created, if the created * connection is null, or if the connection cannot be cast to the specified class. */ @Override - public C getDataConn(String name, Class cls) throws Exc { + public C getDataConn(String name, Class cls) throws Err { return inner.getDataConn(name, cls); } @@ -146,11 +146,11 @@ public void close() { inner.close(); } - void begin() throws Exc { + void begin() throws Err { inner.begin(); } - void commit() throws Exc { + void commit() throws Err { inner.commit(); } diff --git a/src/main/java/com/github/sttk/sabi/DataSrc.java b/src/main/java/com/github/sttk/sabi/DataSrc.java index 1237c5a..0067ba8 100644 --- a/src/main/java/com/github/sttk/sabi/DataSrc.java +++ b/src/main/java/com/github/sttk/sabi/DataSrc.java @@ -1,10 +1,10 @@ /* * DataSrc.java - * Copyright (C) 2022-2025 Takayuki Sato. All Rights Reserved. + * Copyright (C) 2022-2026 Takayuki Sato. All Rights Reserved. */ package com.github.sttk.sabi; -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; /** * The interface that abstracts a data source responsible for managing connections to external data @@ -21,9 +21,9 @@ public interface DataSrc { * * @param ag An {@link AsyncGroup} that can be used for asynchronous setup operations, especially * if initialization is time-consuming. - * @throws Exc if an error occurs during the setup process. + * @throws Err if an error occurs during the setup process. */ - void setup(AsyncGroup ag) throws Exc; + void setup(AsyncGroup ag) throws Err; /** * Closes the data source, releasing all resources and shutting down connections managed by this @@ -38,7 +38,7 @@ public interface DataSrc { * connection. * * @return A new {@link DataConn} instance for a session. - * @throws Exc if an error occurs while creating the data connection. + * @throws Err if an error occurs while creating the data connection. */ - DataConn createDataConn() throws Exc; + DataConn createDataConn() throws Err; } diff --git a/src/main/java/com/github/sttk/sabi/Logic.java b/src/main/java/com/github/sttk/sabi/Logic.java index 53b449b..0ff1fce 100644 --- a/src/main/java/com/github/sttk/sabi/Logic.java +++ b/src/main/java/com/github/sttk/sabi/Logic.java @@ -1,10 +1,10 @@ /* * Logic.java - * Copyright (C) 2022-2025 Takayuki Sato. All Rights Reserved. + * Copyright (C) 2022-2026 Takayuki Sato. All Rights Reserved. */ package com.github.sttk.sabi; -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; /** * Represents the application's business logic, designed to separate data access concerns from the @@ -15,7 +15,7 @@ * {@link #run(Object)} method should not contain any direct data access code; instead, it should * delegate such operations to methods of the {@code D} object. * - *

If an exceptional condition occurs during the execution of the logic, an {@link Exc} object + *

If an exceptional condition occurs during the execution of the logic, an {@link Err} object * should be thrown. * * @param The type of the data access object through which data operations are performed. @@ -27,7 +27,7 @@ public interface Logic { * on the {@code data} object for all data access needs. * * @param data The data access object, providing methods for interacting with data. - * @throws Exc if an error or exceptional condition occurs during the logic execution. + * @throws Err if an error or exceptional condition occurs during the logic execution. */ - void run(D data) throws Exc; + void run(D data) throws Err; } diff --git a/src/main/java/com/github/sttk/sabi/Runner.java b/src/main/java/com/github/sttk/sabi/Runner.java index 760ac7f..a75277e 100644 --- a/src/main/java/com/github/sttk/sabi/Runner.java +++ b/src/main/java/com/github/sttk/sabi/Runner.java @@ -1,10 +1,10 @@ /* * Runner.java - * Copyright (C) 2022-2025 Takayuki Sato. All Rights Reserved. + * Copyright (C) 2022-2026 Takayuki Sato. All Rights Reserved. */ package com.github.sttk.sabi; -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; /** {@code Runner} is the interface that runs any procedure. */ @FunctionalInterface @@ -12,9 +12,9 @@ public interface Runner { /** * Runs the procedure that this instance represents. This method takes no argument and returns - * nothing. And this method throws an {@link Exc} exception if this method failed. + * nothing. And this method throws an {@link Err} exception if this method failed. * - * @throws Exc If this method failed. + * @throws Err If this method failed. */ - void run() throws Exc; + void run() throws Err; } diff --git a/src/main/java/com/github/sttk/sabi/Sabi.java b/src/main/java/com/github/sttk/sabi/Sabi.java index 022c042..796bf07 100644 --- a/src/main/java/com/github/sttk/sabi/Sabi.java +++ b/src/main/java/com/github/sttk/sabi/Sabi.java @@ -1,10 +1,10 @@ /* * Sabi.java - * Copyright (C) 2022-2025 Takayuki Sato. All Rights Reserved. + * Copyright (C) 2022-2026 Takayuki Sato. All Rights Reserved. */ package com.github.sttk.sabi; -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; import com.github.sttk.sabi.internal.DataHubInner; /** @@ -66,9 +66,9 @@ public static void uses(String name, DataSrc ds) { * * @return An {@link AutoCloseable} object that, when closed, will trigger the global close * operation. - * @throws Exc if an error occurs during the setup of any {@link DataSrc}. + * @throws Err if an error occurs during the setup of any {@link DataSrc}. */ - public static AutoCloseable setup() throws Exc { + public static AutoCloseable setup() throws Err { return DataHubInner.setupGlobals(); } @@ -82,22 +82,22 @@ public static AutoCloseable setup() throws Exc { * @param logic The application logic to execute. * @param hub An instance of a DataHub subclass that inherits the data interface for logic * arguments. - * @throws Exc if an {@link Exc} or {@link RuntimeException} occurs during logic execution or if + * @throws Err if an {@link Err} or {@link RuntimeException} occurs during logic execution or if * the {@code DataHub} cannot be cast to the expected data access type. */ - public static void run(Logic logic, DataHub hub) throws Exc { + public static void run(Logic logic, DataHub hub) throws Err { D data; try { @SuppressWarnings("unchecked") D d = (D) hub; data = d; } catch (Exception e) { - throw new Exc(new FailToCastDataHub(hub.getClass().getName())); + throw new Err(new FailToCastDataHub(hub.getClass().getName())); } try { hub.begin(); logic.run(data); - } catch (Exc | RuntimeException e) { + } catch (Err | RuntimeException e) { throw e; } finally { hub.end(); @@ -108,7 +108,7 @@ public static void run(Logic logic, DataHub hub) throws Exc { * Executes the provided application {@link Logic} within a transactional context. The {@code * DataHub} instance in the parameter is passed as the data access object {@code D} to the {@link * Logic}'s {@code run} method. If the logic completes successfully, a commit operation is - * attempted. If any {@link Exc}, {@link RuntimeException}, or {@link Error} occurs, a rollback + * attempted. If any {@link Err}, {@link RuntimeException}, or {@link Error} occurs, a rollback * operation is performed. * * @param The type of the data access object, which typically is {@code DataHub} or an @@ -116,23 +116,23 @@ public static void run(Logic logic, DataHub hub) throws Exc { * @param logic The application logic to execute transactionally. * @param hub An instance of a DataHub subclass that inherits the data interface for logic * arguments. - * @throws Exc if an {@link Exc}, {@link RuntimeException}, or {@link Error} occurs during logic + * @throws Err if an {@link Err}, {@link RuntimeException}, or {@link Error} occurs during logic * execution, pre-commit, or commit. The original exception is re-thrown after rollback. */ - public static void txn(Logic logic, DataHub hub) throws Exc { + public static void txn(Logic logic, DataHub hub) throws Err { D data; try { @SuppressWarnings("unchecked") D d = (D) hub; data = d; } catch (Exception e) { - throw new Exc(new FailToCastDataHub(hub.getClass().getName())); + throw new Err(new FailToCastDataHub(hub.getClass().getName())); } try { hub.begin(); logic.run(data); hub.commit(); - } catch (Exc | RuntimeException | Error e) { + } catch (Err | RuntimeException | Error e) { hub.rollback(); throw e; } finally { diff --git a/src/main/java/com/github/sttk/sabi/internal/AsyncGroupImpl.java b/src/main/java/com/github/sttk/sabi/internal/AsyncGroupImpl.java index 5f34e8e..f598396 100644 --- a/src/main/java/com/github/sttk/sabi/internal/AsyncGroupImpl.java +++ b/src/main/java/com/github/sttk/sabi/internal/AsyncGroupImpl.java @@ -1,17 +1,17 @@ /* * AsyncGroupImpl.java - * Copyright (C) 2023-2025 Takayuki Sato. All Rights Reserved. + * Copyright (C) 2023-2026 Takayuki Sato. All Rights Reserved. */ package com.github.sttk.sabi.internal; -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; import com.github.sttk.sabi.AsyncGroup; import com.github.sttk.sabi.Runner; import java.util.Map; public class AsyncGroupImpl implements AsyncGroup { - private ExcEntry excHead; - private ExcEntry excLast; + private ErrEntry errHead; + private ErrEntry errLast; private VthEntry vthHead; private VthEntry vthLast; String name; @@ -27,8 +27,8 @@ public void add(final Runner runner) { () -> { try { runner.run(); - } catch (Exc | RuntimeException e) { - addExc(name, e); + } catch (Err | RuntimeException e) { + addErr(name, e); } }); @@ -42,34 +42,34 @@ public void add(final Runner runner) { } } - synchronized void addExc(String name, Exception e) { - var exc = (e instanceof Exc) ? Exc.class.cast(e) : new Exc(new RunnerFailed(), e); - var ent = new ExcEntry(name, exc); + synchronized void addErr(String name, Exception e) { + var err = (e instanceof Err) ? Err.class.cast(e) : new Err(new RunnerFailed(), e); + var ent = new ErrEntry(name, err); - if (this.excLast == null) { - this.excHead = ent; - this.excLast = ent; + if (this.errLast == null) { + this.errHead = ent; + this.errLast = ent; } else { - this.excLast.next = ent; - this.excLast = ent; + this.errLast.next = ent; + this.errLast = ent; } } - void joinAndPutExcsInto(Map excMap) { + void joinAndPutErrsInto(Map errMap) { for (var ent = this.vthHead; ent != null; ent = ent.next) { try { ent.thread.join(); } catch (InterruptedException e) { - addExc(ent.name, new Exc(new RunnerInterrupted(), e)); + addErr(ent.name, new Err(new RunnerInterrupted(), e)); } } - for (var ent = this.excHead; ent != null; ent = ent.next) { - excMap.put(ent.name, ent.exc); + for (var ent = this.errHead; ent != null; ent = ent.next) { + errMap.put(ent.name, ent.err); } clear(); } - void joinAndIgnoreExcs() { + void joinAndIgnoreErrs() { for (var ent = this.vthHead; ent != null; ent = ent.next) { try { ent.thread.join(); @@ -80,21 +80,21 @@ void joinAndIgnoreExcs() { } void clear() { - this.excHead = null; - this.excLast = null; + this.errHead = null; + this.errLast = null; this.vthHead = null; this.vthLast = null; } } -class ExcEntry { +class ErrEntry { final String name; - final Exc exc; - ExcEntry next; + final Err err; + ErrEntry next; - ExcEntry(String name, Exc exc) { + ErrEntry(String name, Err err) { this.name = name; - this.exc = exc; + this.err = err; } } diff --git a/src/main/java/com/github/sttk/sabi/internal/DataHubInner.java b/src/main/java/com/github/sttk/sabi/internal/DataHubInner.java index 369a533..1ed7be8 100644 --- a/src/main/java/com/github/sttk/sabi/internal/DataHubInner.java +++ b/src/main/java/com/github/sttk/sabi/internal/DataHubInner.java @@ -1,10 +1,10 @@ /* * DataHubInner.java - * Copyright (C) 2022-2025 Takayuki Sato. All Rights Reserved. + * Copyright (C) 2022-2026 Takayuki Sato. All Rights Reserved. */ package com.github.sttk.sabi.internal; -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; import com.github.sttk.sabi.DataConn; import com.github.sttk.sabi.DataHub; import com.github.sttk.sabi.DataSrc; @@ -24,12 +24,12 @@ public static void usesGlobal(String name, DataSrc ds) { } } - public static AutoCloseable setupGlobals() throws Exc { + public static AutoCloseable setupGlobals() throws Err { if (GLOBAL_DATA_SRCS_FIXED.compareAndSet(false, true)) { - var excMap = GLOBAL_DATA_SRC_LIST.setupDataSrcs(); - if (!excMap.isEmpty()) { + var errMap = GLOBAL_DATA_SRC_LIST.setupDataSrcs(); + if (!errMap.isEmpty()) { GLOBAL_DATA_SRC_LIST.closeDataSrcs(); - throw new Exc(new DataHub.FailToSetupGlobalDataSrcs(excMap)); + throw new Err(new DataHub.FailToSetupGlobalDataSrcs(errMap)); } } return new AutoShutdown(); @@ -83,19 +83,19 @@ public void close() { this.localDataSrcList.closeDataSrcs(); } - public void begin() throws Exc { + public void begin() throws Err { this.fixed = true; - var excMap = this.localDataSrcList.setupDataSrcs(); + var errMap = this.localDataSrcList.setupDataSrcs(); this.localDataSrcList.copyContainerPtrsDidSetupInto(this.dataSrcMap); - if (!excMap.isEmpty()) { - throw new Exc(new DataHub.FailToSetupLocalDataSrcs(excMap)); + if (!errMap.isEmpty()) { + throw new Err(new DataHub.FailToSetupLocalDataSrcs(errMap)); } } - public void commit() throws Exc { - var excMap = new HashMap(); + public void commit() throws Err { + var errMap = new HashMap(); var ag = new AsyncGroupImpl(); var ptr = this.dataConnList.head; @@ -103,19 +103,19 @@ public void commit() throws Exc { ag.name = ptr.name; try { ptr.conn.preCommit(ag); - } catch (Exc e) { - excMap.put(ptr.name, e); + } catch (Err e) { + errMap.put(ptr.name, e); break; } catch (RuntimeException e) { - excMap.put(ptr.name, new Exc(new DataHub.RuntimeExceptionOccurred(), e)); + errMap.put(ptr.name, new Err(new DataHub.RuntimeExceptionOccurred(), e)); break; } ptr = ptr.next; } - ag.joinAndPutExcsInto(excMap); + ag.joinAndPutErrsInto(errMap); - if (!excMap.isEmpty()) { - throw new Exc(new DataHub.FailToPreCommitDataConn(excMap)); + if (!errMap.isEmpty()) { + throw new Err(new DataHub.FailToPreCommitDataConn(errMap)); } ag = new AsyncGroupImpl(); @@ -124,19 +124,19 @@ public void commit() throws Exc { ag.name = ptr.name; try { ptr.conn.commit(ag); - } catch (Exc e) { - excMap.put(ptr.name, e); + } catch (Err e) { + errMap.put(ptr.name, e); break; } catch (RuntimeException e) { - excMap.put(ptr.name, new Exc(new DataHub.RuntimeExceptionOccurred(), e)); + errMap.put(ptr.name, new Err(new DataHub.RuntimeExceptionOccurred(), e)); break; } ptr = ptr.next; } - ag.joinAndPutExcsInto(excMap); + ag.joinAndPutErrsInto(errMap); - if (!excMap.isEmpty()) { - throw new Exc(new DataHub.FailToCommitDataConn(excMap)); + if (!errMap.isEmpty()) { + throw new Err(new DataHub.FailToCommitDataConn(errMap)); } ag = new AsyncGroupImpl(); @@ -147,7 +147,7 @@ public void commit() throws Exc { ptr = ptr.next; } - ag.joinAndIgnoreExcs(); + ag.joinAndIgnoreErrs(); } public void rollback() { @@ -163,7 +163,7 @@ public void rollback() { ptr = ptr.next; } - ag.joinAndIgnoreExcs(); + ag.joinAndIgnoreErrs(); } public void end() { @@ -172,36 +172,36 @@ public void end() { this.fixed = false; } - public C getDataConn(String name, Class cls) throws Exc { + public C getDataConn(String name, Class cls) throws Err { var connPtr = this.dataConnMap.get(name); if (connPtr != null) { try { return cls.cast(connPtr.conn); } catch (Exception e) { - throw new Exc(new DataHub.FailToCastDataConn(name, cls.getName()), e); + throw new Err(new DataHub.FailToCastDataConn(name, cls.getName()), e); } } var dsPtr = this.dataSrcMap.get(name); if (dsPtr == null) { - throw new Exc(new DataHub.NoDataSrcToCreateDataConn(name, cls.getName())); + throw new Err(new DataHub.NoDataSrcToCreateDataConn(name, cls.getName())); } DataConn conn; try { conn = dsPtr.ds.createDataConn(); - } catch (Exc | RuntimeException e) { - throw new Exc(new DataHub.FailToCreateDataConn(name, cls.getName())); + } catch (Err | RuntimeException e) { + throw new Err(new DataHub.FailToCreateDataConn(name, cls.getName())); } if (conn == null) { - throw new Exc(new DataHub.CreatedDataConnIsNull(name, cls.getName())); + throw new Err(new DataHub.CreatedDataConnIsNull(name, cls.getName())); } C c; try { c = cls.cast(conn); } catch (Exception e) { - throw new Exc(new DataHub.FailToCastDataConn(name, cls.getName()), e); + throw new Err(new DataHub.FailToCastDataConn(name, cls.getName()), e); } connPtr = new DataConnContainer(name, c); diff --git a/src/main/java/com/github/sttk/sabi/internal/DataSrcList.java b/src/main/java/com/github/sttk/sabi/internal/DataSrcList.java index 297f505..b9f32cb 100644 --- a/src/main/java/com/github/sttk/sabi/internal/DataSrcList.java +++ b/src/main/java/com/github/sttk/sabi/internal/DataSrcList.java @@ -1,10 +1,10 @@ /* - * DataSrcContainer.java - * Copyright (C) 2025 Takayuki Sato. All Rights Reserved. + * DataSrcList.java + * Copyright (C) 2025-2026 Takayuki Sato. All Rights Reserved. */ package com.github.sttk.sabi.internal; -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; import com.github.sttk.sabi.DataSrc; import java.util.HashMap; import java.util.Map; @@ -122,11 +122,11 @@ void addDataSrc(String name, DataSrc ds) { this.appendContainerPtrNotSetup(ptr); } - Map setupDataSrcs() { - var excMap = new HashMap(); + Map setupDataSrcs() { + var errMap = new HashMap(); if (this.notSetupHead == null) { - return excMap; + return errMap; } var ag = new AsyncGroupImpl(); @@ -136,28 +136,28 @@ Map setupDataSrcs() { ag.name = ptr.name; try { ptr.ds.setup(ag); - } catch (Exc exc) { - excMap.put(ptr.name, exc); + } catch (Err err) { + errMap.put(ptr.name, err); break; } ptr = ptr.next; } - ag.joinAndPutExcsInto(excMap); + ag.joinAndPutErrsInto(errMap); var firstPtrNotSetupYet = ptr; ptr = this.notSetupHead; while (ptr != null && ptr != firstPtrNotSetupYet) { var next = ptr.next; - if (!excMap.containsKey(ptr.name)) { + if (!errMap.containsKey(ptr.name)) { this.removeContainerPtrNotSetup(ptr); this.appendContainerPtrDidSetup(ptr); } ptr = next; } - return excMap; + return errMap; } void closeDataSrcs() { diff --git a/src/test/java/com/github/sttk/sabi/internal/AsyncGroupImplTest.java b/src/test/java/com/github/sttk/sabi/internal/AsyncGroupImplTest.java index 589c27d..09e4d11 100644 --- a/src/test/java/com/github/sttk/sabi/internal/AsyncGroupImplTest.java +++ b/src/test/java/com/github/sttk/sabi/internal/AsyncGroupImplTest.java @@ -3,7 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.fail; -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; import com.github.sttk.sabi.Runner; import java.util.HashMap; import org.junit.jupiter.api.Test; @@ -15,8 +15,8 @@ private AsyncGroupImplTest() {} void zero() { var ag = new AsyncGroupImpl(); - var m = new HashMap(); - ag.joinAndPutExcsInto(m); + var m = new HashMap(); + ag.joinAndPutErrsInto(m); assertThat(m).hasSize(0); } @@ -38,8 +38,8 @@ void ok() { ag.add(fn); assertThat(executed[0]).isFalse(); - var m = new HashMap(); - ag.joinAndPutExcsInto(m); + var m = new HashMap(); + ag.joinAndPutErrsInto(m); assertThat(m).hasSize(0); assertThat(executed[0]).isTrue(); } @@ -58,15 +58,15 @@ record FailToDoSomething() {} } catch (Exception e) { } executed[0] = true; - throw new Exc(new FailToDoSomething()); + throw new Err(new FailToDoSomething()); }; ag.name = "foo"; ag.add(fn); assertThat(executed[0]).isFalse(); - var m = new HashMap(); - ag.joinAndPutExcsInto(m); + var m = new HashMap(); + ag.joinAndPutErrsInto(m); assertThat(m).hasSize(1); assertThat(executed[0]).isTrue(); @@ -93,7 +93,7 @@ record Reason2() {} } catch (Exception e) { } executed[0] = true; - throw new Exc(new Reason0()); + throw new Err(new Reason0()); }; Runner fn1 = () -> { @@ -102,7 +102,7 @@ record Reason2() {} } catch (Exception e) { } executed[1] = true; - throw new Exc(new Reason1()); + throw new Err(new Reason1()); }; Runner fn2 = () -> { @@ -111,7 +111,7 @@ record Reason2() {} } catch (Exception e) { } executed[2] = true; - throw new Exc(new Reason2()); + throw new Err(new Reason2()); }; ag.name = "foo0"; @@ -121,8 +121,8 @@ record Reason2() {} ag.name = "foo2"; ag.add(fn2); - var m = new HashMap(); - ag.joinAndPutExcsInto(m); + var m = new HashMap(); + ag.joinAndPutErrsInto(m); assertThat(m).hasSize(3); assertThat(executed[0]).isTrue(); assertThat(executed[1]).isTrue(); @@ -130,13 +130,13 @@ record Reason2() {} assertThat(m.get("foo0").toString()) .isEqualTo( - "com.github.sttk.errs.Exc { reason = com.github.sttk.sabi.internal.AsyncGroupImplTest$1Reason0 Reason0[], file = AsyncGroupImplTest.java, line = 96 }"); + "com.github.sttk.errs.Err { reason = com.github.sttk.sabi.internal.AsyncGroupImplTest$1Reason0 Reason0[], file = AsyncGroupImplTest.java, line = 96 }"); assertThat(m.get("foo1").toString()) .isEqualTo( - "com.github.sttk.errs.Exc { reason = com.github.sttk.sabi.internal.AsyncGroupImplTest$1Reason1 Reason1[], file = AsyncGroupImplTest.java, line = 105 }"); + "com.github.sttk.errs.Err { reason = com.github.sttk.sabi.internal.AsyncGroupImplTest$1Reason1 Reason1[], file = AsyncGroupImplTest.java, line = 105 }"); assertThat(m.get("foo2").toString()) .isEqualTo( - "com.github.sttk.errs.Exc { reason = com.github.sttk.sabi.internal.AsyncGroupImplTest$1Reason2 Reason2[], file = AsyncGroupImplTest.java, line = 114 }"); + "com.github.sttk.errs.Err { reason = com.github.sttk.sabi.internal.AsyncGroupImplTest$1Reason2 Reason2[], file = AsyncGroupImplTest.java, line = 114 }"); } @Test @@ -156,7 +156,7 @@ record Reason2() {} } catch (Exception e) { } executed[0] = true; - throw new Exc(new Reason0()); + throw new Err(new Reason0()); }; Runner fn1 = () -> { @@ -165,7 +165,7 @@ record Reason2() {} } catch (Exception e) { } executed[1] = true; - throw new Exc(new Reason1()); + throw new Err(new Reason1()); }; Runner fn2 = () -> { @@ -174,7 +174,7 @@ record Reason2() {} } catch (Exception e) { } executed[2] = true; - throw new Exc(new Reason2()); + throw new Err(new Reason2()); }; ag.name = "foo0"; @@ -184,7 +184,7 @@ record Reason2() {} ag.name = "foo2"; ag.add(fn2); - ag.joinAndIgnoreExcs(); + ag.joinAndIgnoreErrs(); assertThat(executed[0]).isTrue(); assertThat(executed[1]).isTrue(); assertThat(executed[2]).isTrue(); diff --git a/src/test/java/com/github/sttk/sabi/internal/DataAccTest.java b/src/test/java/com/github/sttk/sabi/internal/DataAccTest.java index 91ee6ff..771d881 100644 --- a/src/test/java/com/github/sttk/sabi/internal/DataAccTest.java +++ b/src/test/java/com/github/sttk/sabi/internal/DataAccTest.java @@ -3,7 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.fail; -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; import com.github.sttk.sabi.AsyncGroup; import com.github.sttk.sabi.DataAcc; import com.github.sttk.sabi.DataConn; @@ -37,10 +37,10 @@ static class FooDataSrc implements DataSrc { } @Override - public void setup(AsyncGroup ag) throws Exc { + public void setup(AsyncGroup ag) throws Err { if (this.willFail) { this.logger.add(String.format("FooDataSrc %d failed to setup", this.id)); - throw new Exc("XXX"); + throw new Err("XXX"); } this.logger.add(String.format("FooDataSrc %d setupped", this.id)); } @@ -51,7 +51,7 @@ public void close() { } @Override - public DataConn createDataConn() throws Exc { + public DataConn createDataConn() throws Err { this.logger.add(String.format("FooDataSrc %d created FooDataConn", this.id)); return new FooDataConn(this.id, this.text, this.logger); } @@ -74,13 +74,13 @@ String getText() { } @Override - public void commit(AsyncGroup ag) throws Exc { + public void commit(AsyncGroup ag) throws Err { this.committed = true; this.logger.add(String.format("FooDataConn %d committed", this.id)); } @Override - public void preCommit(AsyncGroup ag) throws Exc { + public void preCommit(AsyncGroup ag) throws Err { this.logger.add(String.format("FooDataConn %d pre committed", this.id)); } @@ -124,10 +124,10 @@ static class BarDataSrc implements DataSrc { } @Override - public void setup(AsyncGroup ag) throws Exc { + public void setup(AsyncGroup ag) throws Err { if (this.willFail) { this.logger.add(String.format("BarDataSrc %d failed to setup", this.id)); - throw new Exc("XXX"); + throw new Err("XXX"); } this.logger.add(String.format("BarDataSrc %d setupped", this.id)); } @@ -139,7 +139,7 @@ public void close() { } @Override - public DataConn createDataConn() throws Exc { + public DataConn createDataConn() throws Err { this.logger.add(String.format("BarDataSrc %d created BarDataConn", this.id)); return new BarDataConn(this.id, this.text, this.logger, this); } @@ -165,14 +165,14 @@ void setText(String s) { } @Override - public void commit(AsyncGroup ag) throws Exc { + public void commit(AsyncGroup ag) throws Err { this.committed = true; this.ds.text = this.text; this.logger.add(String.format("BarDataConn %d committed", this.id)); } @Override - public void preCommit(AsyncGroup ag) throws Exc { + public void preCommit(AsyncGroup ag) throws Err { this.logger.add(String.format("BarDataConn %d pre committed", this.id)); } @@ -206,14 +206,14 @@ public void close() { /// static interface SampleData { - String getValue() throws Exc; + String getValue() throws Err; - void setValue(String text) throws Exc; + void setValue(String text) throws Err; } static class SampleLogic implements Logic { @Override - public void run(SampleData data) throws Exc { + public void run(SampleData data) throws Err { var v = data.getValue(); data.setValue(v); } @@ -221,8 +221,8 @@ public void run(SampleData data) throws Exc { static class FailingLogic implements Logic { @Override - public void run(SampleData data) throws Exc { - throw new Exc("ZZZ"); + public void run(SampleData data) throws Err { + throw new Err("ZZZ"); } } @@ -230,7 +230,7 @@ static interface AllLogicData extends SampleData {} static interface FooDataAcc extends DataAcc, AllLogicData { @Override - default String getValue() throws Exc { + default String getValue() throws Err { var conn = getDataConn("foo", FooDataConn.class); return conn.getText(); } @@ -238,7 +238,7 @@ default String getValue() throws Exc { static interface BarDataAcc extends DataAcc, AllLogicData { @Override - default void setValue(String text) throws Exc { + default void setValue(String text) throws Err { var conn = getDataConn("bar", BarDataConn.class); conn.setText(text); } @@ -395,7 +395,7 @@ void test_not_run_logic_if_fail_to_setup_local_data_src() { data.uses("bar", new BarDataSrc(2, logger, false)); Sabi.run(new SampleLogic(), data); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.FailToSetupLocalDataSrcs r -> { var e2 = r.errors().get("foo"); @@ -572,7 +572,7 @@ void test_not_run_logic_if_fail_to_setup_local_data_src() { data.uses("bar", new BarDataSrc(2, logger, false)); Sabi.txn(new SampleLogic(), data); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.FailToSetupLocalDataSrcs r -> { var e2 = r.errors().get("foo"); @@ -601,7 +601,7 @@ void test_not_run_logic_in_txn_and_rollback() { data.uses("bar", new BarDataSrc(2, logger, false)); Sabi.txn(new FailingLogic(), data); - } catch (Exc e) { + } catch (Err e) { assertThat(e.getReason()).isEqualTo("ZZZ"); } catch (Exception e) { fail(e); diff --git a/src/test/java/com/github/sttk/sabi/internal/DataConnListTest.java b/src/test/java/com/github/sttk/sabi/internal/DataConnListTest.java index c2dcf70..61d4a11 100644 --- a/src/test/java/com/github/sttk/sabi/internal/DataConnListTest.java +++ b/src/test/java/com/github/sttk/sabi/internal/DataConnListTest.java @@ -2,7 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; import com.github.sttk.sabi.AsyncGroup; import com.github.sttk.sabi.DataConn; import java.util.ArrayList; @@ -21,9 +21,9 @@ public SampleDataConn(int id, List logger) { this.logger = logger; } - public void commit(AsyncGroup ag) throws Exc {} + public void commit(AsyncGroup ag) throws Err {} - public void preCommit(AsyncGroup ag) throws Exc {} + public void preCommit(AsyncGroup ag) throws Err {} public void postCommit(AsyncGroup ag) {} diff --git a/src/test/java/com/github/sttk/sabi/internal/DataHubInnerTest.java b/src/test/java/com/github/sttk/sabi/internal/DataHubInnerTest.java index acc8aa9..3227e6a 100644 --- a/src/test/java/com/github/sttk/sabi/internal/DataHubInnerTest.java +++ b/src/test/java/com/github/sttk/sabi/internal/DataHubInnerTest.java @@ -3,7 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.fail; -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; import com.github.sttk.sabi.AsyncGroup; import com.github.sttk.sabi.DataConn; import com.github.sttk.sabi.DataHub; @@ -38,10 +38,10 @@ static class SyncDataSrc implements DataSrc { } @Override - public void setup(AsyncGroup ag) throws Exc { + public void setup(AsyncGroup ag) throws Err { if (this.fail == FAIL__SETUP) { this.logger.add(String.format("SyncDataSrc %d failed to setup", this.id)); - throw new Exc("XXX"); + throw new Err("XXX"); } this.logger.add(String.format("SyncDataSrc %d setupped", this.id)); } @@ -52,10 +52,10 @@ public void close() { } @Override - public DataConn createDataConn() throws Exc { + public DataConn createDataConn() throws Err { if (this.fail == FAIL__CREATE_DATA_CONN) { this.logger.add(String.format("SyncDataSrc %d failed to create a DataConn", this.id)); - throw new Exc("xxx"); + throw new Err("xxx"); } this.logger.add(String.format("SyncDataSrc %d created DataConn", this.id)); var conn = new SyncDataConn(this.id, this.fail, this.logger); @@ -75,7 +75,7 @@ static class AsyncDataSrc implements DataSrc { } @Override - public void setup(AsyncGroup ag) throws Exc { + public void setup(AsyncGroup ag) throws Err { ag.add( () -> { try { @@ -84,7 +84,7 @@ public void setup(AsyncGroup ag) throws Exc { } if (this.fail == FAIL__SETUP) { this.logger.add(String.format("AsyncDataSrc %d failed to setup", this.id)); - throw new Exc("YYY"); + throw new Err("YYY"); } this.logger.add(String.format("AsyncDataSrc %d setupped", this.id)); }); @@ -96,10 +96,10 @@ public void close() { } @Override - public DataConn createDataConn() throws Exc { + public DataConn createDataConn() throws Err { if (this.fail == FAIL__CREATE_DATA_CONN) { this.logger.add(String.format("AsyncDataSrc %d failed to create a DataConn", this.id)); - throw new Exc("yyy"); + throw new Err("yyy"); } this.logger.add(String.format("AsyncDataSrc %d created DataConn", this.id)); var conn = new AsyncDataConn(this.id, this.fail, this.logger); @@ -120,20 +120,20 @@ static class SyncDataConn implements DataConn { } @Override - public void commit(AsyncGroup ag) throws Exc { + public void commit(AsyncGroup ag) throws Err { if (this.fail == FAIL__COMMIT) { this.logger.add(String.format("SyncDataConn %d failed to commit", this.id)); - throw new Exc("ZZZ"); + throw new Err("ZZZ"); } this.committed = true; this.logger.add(String.format("SyncDataConn %d committed", this.id)); } @Override - public void preCommit(AsyncGroup ag) throws Exc { + public void preCommit(AsyncGroup ag) throws Err { if (this.fail == FAIL__PRE_COMMIT) { this.logger.add(String.format("SyncDataConn %d failed to pre commit", this.id)); - throw new Exc("zzz"); + throw new Err("zzz"); } this.logger.add(String.format("SyncDataConn %d pre committed", this.id)); } @@ -177,20 +177,20 @@ static class AsyncDataConn implements DataConn { } @Override - public void commit(AsyncGroup ag) throws Exc { + public void commit(AsyncGroup ag) throws Err { if (this.fail == FAIL__COMMIT) { this.logger.add(String.format("AsyncDataConn %d failed to commit", this.id)); - throw new Exc("VVV"); + throw new Err("VVV"); } this.committed = true; this.logger.add(String.format("AsyncDataConn %d committed", this.id)); } @Override - public void preCommit(AsyncGroup ag) throws Exc { + public void preCommit(AsyncGroup ag) throws Err { if (this.fail == FAIL__PRE_COMMIT) { this.logger.add(String.format("AsyncDataConn %d failed to pre commit", this.id)); - throw new Exc("vvv"); + throw new Err("vvv"); } this.logger.add(String.format("AsyncDataConn %d pre committed", this.id)); } @@ -310,7 +310,7 @@ void fail_to_setup() { try (var ac = DataHubInner.setupGlobals()) { suppressWarnings_unused(ac); fail(); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.FailToSetupGlobalDataSrcs r -> { assertThat(r.errors()).hasSize(2); @@ -833,7 +833,7 @@ void begin_and_end_but_fail_sync() { try { hub.begin(); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.FailToSetupLocalDataSrcs rsn -> { assertThat(rsn.errors()).hasSize(1); @@ -908,7 +908,7 @@ void begin_and_end_but_fail_async() { try { hub.begin(); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.FailToSetupLocalDataSrcs rsn -> { assertThat(rsn.errors()).hasSize(1); @@ -1073,7 +1073,7 @@ void fail_to_cast_new_data_conn() { try { hub.getDataConn("foo", SyncDataConn.class); fail(); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.FailToCastDataConn rsn -> { assertThat(rsn.name()).isEqualTo("foo"); @@ -1089,7 +1089,7 @@ void fail_to_cast_new_data_conn() { try { hub.getDataConn("bar", AsyncDataConn.class); fail(); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.FailToCastDataConn rsn -> { assertThat(rsn.name()).isEqualTo("bar"); @@ -1146,7 +1146,7 @@ void fail_to_cast_reused_data_conn() { try { hub.getDataConn("foo", SyncDataConn.class); fail(); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.FailToCastDataConn rsn -> { assertThat(rsn.name()).isEqualTo("foo"); @@ -1162,7 +1162,7 @@ void fail_to_cast_reused_data_conn() { try { hub.getDataConn("bar", AsyncDataConn.class); fail(); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.FailToCastDataConn rsn -> { assertThat(rsn.name()).isEqualTo("bar"); @@ -1216,7 +1216,7 @@ void fail_to_create_data_conn() { try { hub.getDataConn("bar", AsyncDataConn.class); fail(); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.FailToCreateDataConn rsn -> { assertThat(rsn.name()).isEqualTo("bar"); @@ -1266,7 +1266,7 @@ void fail_to_create_data_conn_because_of_no_data_src() { try { hub.getDataConn("baz", SyncDataConn.class); fail(); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.NoDataSrcToCreateDataConn rsn -> { assertThat(rsn.name()).isEqualTo("baz"); @@ -1282,7 +1282,7 @@ void fail_to_create_data_conn_because_of_no_data_src() { try { hub.getDataConn("qux", AsyncDataConn.class); fail(); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.NoDataSrcToCreateDataConn rsn -> { assertThat(rsn.name()).isEqualTo("qux"); @@ -1377,7 +1377,7 @@ void commit_but_fail_global_sync() { try { hub.commit(); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.FailToCommitDataConn rsn -> { assertThat(rsn.errors()).hasSize(1); @@ -1453,7 +1453,7 @@ void commit_but_fail_global_async() { try { hub.commit(); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.FailToCommitDataConn rsn -> { assertThat(rsn.errors()).hasSize(1); @@ -1528,7 +1528,7 @@ void commit_but_fail_local_sync() { try { hub.commit(); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.FailToCommitDataConn rsn -> { assertThat(rsn.errors()).hasSize(1); @@ -1606,7 +1606,7 @@ void commit_but_fail_local_async() { try { hub.commit(); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.FailToCommitDataConn rsn -> { assertThat(rsn.errors()).hasSize(1); @@ -1683,7 +1683,7 @@ void pre_commit_but_fail_global_sync() { try { hub.commit(); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.FailToPreCommitDataConn rsn -> { assertThat(rsn.errors()).hasSize(1); @@ -1755,7 +1755,7 @@ void pre_commit_but_fail_global_async() { try { hub.commit(); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.FailToPreCommitDataConn rsn -> { assertThat(rsn.errors()).hasSize(1); @@ -1827,7 +1827,7 @@ void pre_commit_but_fail_local_sync() { try { hub.commit(); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.FailToPreCommitDataConn rsn -> { assertThat(rsn.errors()).hasSize(1); @@ -1901,7 +1901,7 @@ void pre_commit_but_fail_local_async() { try { hub.commit(); - } catch (Exc e) { + } catch (Err e) { switch (e.getReason()) { case DataHub.FailToPreCommitDataConn rsn -> { assertThat(rsn.errors()).hasSize(1); diff --git a/src/test/java/com/github/sttk/sabi/internal/DataSrcListTest.java b/src/test/java/com/github/sttk/sabi/internal/DataSrcListTest.java index d37bb71..da381b7 100644 --- a/src/test/java/com/github/sttk/sabi/internal/DataSrcListTest.java +++ b/src/test/java/com/github/sttk/sabi/internal/DataSrcListTest.java @@ -3,7 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.fail; -import com.github.sttk.errs.Exc; +import com.github.sttk.errs.Err; import com.github.sttk.sabi.AsyncGroup; import com.github.sttk.sabi.DataConn; import com.github.sttk.sabi.DataSrc; @@ -27,10 +27,10 @@ static class SyncDataSrc implements DataSrc { } @Override - public void setup(AsyncGroup ag) throws Exc { + public void setup(AsyncGroup ag) throws Err { if (this.willFail) { logger.add(String.format("SyncDataSrc %d failed to setup", this.id)); - throw new Exc("XXX"); + throw new Err("XXX"); } logger.add(String.format("SyncDataSrc %d setupped", this.id)); } @@ -41,7 +41,7 @@ public void close() { } @Override - public DataConn createDataConn() throws Exc { + public DataConn createDataConn() throws Err { logger.add(String.format("SyncDataSrc %d created DataConn", this.id)); var conn = new SyncDataConn(); return conn; @@ -60,7 +60,7 @@ static class AsyncDataSrc implements DataSrc { } @Override - public void setup(AsyncGroup ag) throws Exc { + public void setup(AsyncGroup ag) throws Err { ag.add( () -> { try { @@ -69,7 +69,7 @@ public void setup(AsyncGroup ag) throws Exc { } if (this.willFail) { logger.add(String.format("AsyncDataSrc %d failed to setup", this.id)); - throw new Exc("XXX"); + throw new Err("XXX"); } logger.add(String.format("AsyncDataSrc %d setupped", this.id)); }); @@ -81,7 +81,7 @@ public void close() { } @Override - public DataConn createDataConn() throws Exc { + public DataConn createDataConn() throws Err { logger.add(String.format("AsyncDataSrc %d created DataConn", this.id)); var conn = new AsyncDataConn(); return conn; @@ -90,10 +90,10 @@ public DataConn createDataConn() throws Exc { static class SyncDataConn implements DataConn { @Override - public void commit(AsyncGroup ag) throws Exc {} + public void commit(AsyncGroup ag) throws Err {} @Override - public void preCommit(AsyncGroup ag) throws Exc {} + public void preCommit(AsyncGroup ag) throws Err {} @Override public void postCommit(AsyncGroup ag) {} @@ -115,10 +115,10 @@ public void close() {} static class AsyncDataConn implements DataConn { @Override - public void commit(AsyncGroup ag) throws Exc {} + public void commit(AsyncGroup ag) throws Err {} @Override - public void preCommit(AsyncGroup ag) throws Exc {} + public void preCommit(AsyncGroup ag) throws Err {} @Override public void postCommit(AsyncGroup ag) {} @@ -911,7 +911,7 @@ void test_setupAndCreateDataConnAndClose() { try { var conn = ptr.ds.createDataConn(); assertThat(conn).isNotNull(); - } catch (Exc e) { + } catch (Err e) { fail(e); } @@ -919,7 +919,7 @@ void test_setupAndCreateDataConnAndClose() { try { var conn = ptr.ds.createDataConn(); assertThat(conn).isNotNull(); - } catch (Exc e) { + } catch (Err e) { fail(e); } @@ -972,11 +972,11 @@ void test_failToSetupAsyncAndClose() { var dsSync = new SyncDataSrc(2, logger, false); dsList.addDataSrc("bar", dsSync); - var excMap = dsList.setupDataSrcs(); - assertThat(excMap).hasSize(1); + var errMap = dsList.setupDataSrcs(); + assertThat(errMap).hasSize(1); - var exc = excMap.get("foo"); - assertThat(exc.getReason()).isEqualTo("XXX"); + var err = errMap.get("foo"); + assertThat(err.getReason()).isEqualTo("XXX"); dsList.closeDataSrcs(); @@ -989,8 +989,8 @@ void test_failToSetupAsyncAndClose() { void test_noDataSrc() { var dsList = new DataSrcList(false); - var excMap = dsList.setupDataSrcs(); - assertThat(excMap).hasSize(0); + var errMap = dsList.setupDataSrcs(); + assertThat(errMap).hasSize(0); dsList.closeDataSrcs();