Skip to content
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
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}
Expand All @@ -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<MyData> {
@Override public void run(MyData data) throws Exc {
@Override public void run(MyData data) throws Err {
String text = data.getText();
data.setText(text);
}
Expand All @@ -110,19 +110,19 @@ class MyLogic implements Logic<MyData> {
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";
}
}

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);
// ...
}
Expand All @@ -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 {}
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<dependency>
<groupId>io.github.sttk</groupId>
<artifactId>errs</artifactId>
<version>0.1.0</version>
<version>0.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/github/sttk/sabi/AsyncGroup.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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() {}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/github/sttk/sabi/DataAcc.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 extends DataConn> C getDataConn(String name, Class<C> cls) throws Exc;
<C extends DataConn> C getDataConn(String name, Class<C> cls) throws Err;
}
12 changes: 6 additions & 6 deletions src/main/java/com/github/sttk/sabi/DataConn.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/github/sttk/sabi/DataHub.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<String, Exc> errors) {}
public record FailToSetupGlobalDataSrcs(Map<String, Err> errors) {}

/**
* Represents an error reason that occurred when failing to set up local {@link DataSrc}
Expand All @@ -34,7 +34,7 @@ public record FailToSetupGlobalDataSrcs(Map<String, Exc> 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<String, Exc> errors) {}
public record FailToSetupLocalDataSrcs(Map<String, Err> errors) {}

/**
* Represents an error reason that occurred when failing to commit one or more {@link DataConn}
Expand All @@ -43,7 +43,7 @@ public record FailToSetupLocalDataSrcs(Map<String, Exc> 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<String, Exc> errors) {}
public record FailToCommitDataConn(Map<String, Err> errors) {}

/**
* Represents an error reason that occurred when failing to pre-commit one or more {@link
Expand All @@ -52,7 +52,7 @@ public record FailToCommitDataConn(Map<String, Exc> 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<String, Exc> errors) {}
public record FailToPreCommitDataConn(Map<String, Err> errors) {}

/**
* Represents an error reason where no {@link DataSrc} was found to create a {@link DataConn} with
Expand Down Expand Up @@ -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 extends DataConn> C getDataConn(String name, Class<C> cls) throws Exc {
public <C extends DataConn> C getDataConn(String name, Class<C> cls) throws Err {
return inner.getDataConn(name, cls);
}

Expand All @@ -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();
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/github/sttk/sabi/DataSrc.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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;
}
10 changes: 5 additions & 5 deletions src/main/java/com/github/sttk/sabi/Logic.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
*
* <p>If an exceptional condition occurs during the execution of the logic, an {@link Exc} object
* <p>If an exceptional condition occurs during the execution of the logic, an {@link Err} object
* should be thrown.
*
* @param <D> The type of the data access object through which data operations are performed.
Expand All @@ -27,7 +27,7 @@ public interface Logic<D> {
* 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;
}
10 changes: 5 additions & 5 deletions src/main/java/com/github/sttk/sabi/Runner.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/*
* 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
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;
}
Loading