Skip to content

Commit a96f447

Browse files
committed
Renamed database methods
* void read -> readAndConsume * T write -> writeAndProvide
1 parent 224d3fe commit a96f447

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

application/src/main/java/org/togetherjava/tjbot/commands/componentids/ComponentIdStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public void putOrThrow(@NotNull UUID uuid, @NotNull ComponentId componentId,
234234
private void heatRecord(@NotNull UUID uuid) {
235235
int updatedRecords;
236236
synchronized (storeLock) {
237-
updatedRecords = database.write(context -> {
237+
updatedRecords = database.writeAndProvide(context -> {
238238
return context.update(ComponentIds.COMPONENT_IDS)
239239
.set(ComponentIds.COMPONENT_IDS.LAST_USED, Instant.now())
240240
.where(ComponentIds.COMPONENT_IDS.UUID.eq(uuid.toString()))

application/src/main/java/org/togetherjava/tjbot/commands/tags/TagSystem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ boolean hasTag(String id) {
9797
// Execute closes resources; without curly braces on the lambda, the call would be ambiguous
9898
@SuppressWarnings({"resource", "java:S1602"})
9999
void deleteTag(String id) {
100-
int deletedRecords = database.write(context -> {
100+
int deletedRecords = database.writeAndProvide(context -> {
101101
return context.deleteFrom(Tags.TAGS).where(Tags.TAGS.ID.eq(id)).execute();
102102
});
103103
if (deletedRecords == 0) {

database/src/main/java/org/togetherjava/tjbot/db/Database.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,13 @@ public <T> T read(
7171
}
7272

7373
/**
74-
* Acquires read-only access to the database.
74+
* Acquires read-only access to the database and consumes the result directly.
7575
*
7676
* @param action the action that consumes the DSL context, e.g. a query
7777
* @throws DatabaseException if an error occurs in the given action
7878
*/
79-
public void read(CheckedConsumer<? super DSLContext, ? extends DataAccessException> action) {
79+
public void readAndConsume(
80+
CheckedConsumer<? super DSLContext, ? extends DataAccessException> action) {
8081
read(context -> {
8182
action.accept(context);
8283
// noinspection ReturnOfNull
@@ -85,14 +86,14 @@ public void read(CheckedConsumer<? super DSLContext, ? extends DataAccessExcepti
8586
}
8687

8788
/**
88-
* Acquires read and write access to the database.
89+
* Acquires read and write access to the database and provides the computed result.
8990
*
9091
* @param action the action to apply to the DSL context, e.g. a query
9192
* @param <T> the type returned by the given action
9293
* @return the result returned by the given action
9394
* @throws DatabaseException if an error occurs in the given action
9495
*/
95-
public <T> T write(
96+
public <T> T writeAndProvide(
9697
CheckedFunction<? super DSLContext, T, ? extends DataAccessException> action) {
9798
writeLock.lock();
9899
try {
@@ -111,7 +112,7 @@ public <T> T write(
111112
* @throws DatabaseException if an error occurs in the given action
112113
*/
113114
public void write(CheckedConsumer<? super DSLContext, ? extends DataAccessException> action) {
114-
write(context -> {
115+
writeAndProvide(context -> {
115116
action.accept(context);
116117
// noinspection ReturnOfNull
117118
return null;
@@ -141,13 +142,13 @@ public <T> T readTransaction(
141142
}
142143

143144
/**
144-
* Acquires a transaction that can only read from the database.
145+
* Acquires a transaction that can only read from the database and consumes the result directly.
145146
*
146147
* @param handler the handler that is executed within the context of the transaction. It has no
147148
* return value.
148149
* @throws DatabaseException if an error occurs in the given handler function
149150
*/
150-
public void readTransaction(
151+
public void readTransactionAndConsume(
151152
CheckedConsumer<? super DSLContext, ? extends DataAccessException> handler) {
152153
readTransaction(dsl -> {
153154
handler.accept(dsl);
@@ -157,15 +158,16 @@ public void readTransaction(
157158
}
158159

159160
/**
160-
* Acquires a transaction that can read and write to the database.
161+
* Acquires a transaction that can read and write to the database and provides the computed
162+
* result.
161163
*
162164
* @param handler the handler that is executed within the context of the transaction. The
163165
* handler will be called once and its return value is returned from the transaction.
164166
* @param <T> the return type of the handler
165167
* @return the object that is returned by the given handler
166168
* @throws DatabaseException if an error occurs in the given handler function
167169
*/
168-
public <T> T writeTransaction(
170+
public <T> T writeTransactionAndProvide(
169171
CheckedFunction<? super DSLContext, T, DataAccessException> handler) {
170172
var holder = new ResultHolder<T>();
171173

@@ -190,7 +192,7 @@ public <T> T writeTransaction(
190192
*/
191193
public void writeTransaction(
192194
CheckedConsumer<? super DSLContext, ? extends DataAccessException> handler) {
193-
writeTransaction(dsl -> {
195+
writeTransactionAndProvide(dsl -> {
194196
handler.accept(dsl);
195197
// noinspection ReturnOfNull
196198
return null;

0 commit comments

Comments
 (0)