Skip to content

Commit 9d36498

Browse files
committed
remove unused methods in DbActions and DbHelper
1 parent 8243f92 commit 9d36498

File tree

2 files changed

+0
-184
lines changed

2 files changed

+0
-184
lines changed

src/main/java/net/javadiscord/javabot/data/h2db/DbActions.java

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
import java.sql.*;
1111
import java.util.Optional;
12-
import java.util.concurrent.CompletableFuture;
13-
import java.util.concurrent.ExecutorService;
14-
import java.util.function.Function;
1512

1613
import javax.sql.DataSource;
1714

@@ -22,36 +19,9 @@
2219
@Service
2320
@RequiredArgsConstructor
2421
public class DbActions {
25-
private final ExecutorService asyncPool;
2622
@Getter
2723
private final DataSource dataSource;
2824

29-
/**
30-
* Consumes an action based on the given {@link ConnectionConsumer}.
31-
*
32-
* @param consumer The {@link ConnectionConsumer}.
33-
* @throws SQLException If an error occurs.
34-
*/
35-
public void doAction(@NotNull ConnectionConsumer consumer) throws SQLException {
36-
try (Connection c = dataSource.getConnection()) {
37-
consumer.consume(c);
38-
}
39-
}
40-
41-
/**
42-
* Maps an action based on the given {@link ConnectionFunction}.
43-
*
44-
* @param function The {@link ConnectionFunction}.
45-
* @param <T> The generic type.
46-
* @return A generic type.
47-
* @throws SQLException If an error occurs.
48-
*/
49-
public <T> T map(@NotNull ConnectionFunction<T> function) throws SQLException {
50-
try (Connection c = dataSource.getConnection()) {
51-
return function.apply(c);
52-
}
53-
}
54-
5525
/**
5626
* Maps a query.
5727
*
@@ -70,28 +40,6 @@ public <T> T mapQuery(@NotNull String query, @NotNull StatementModifier modifier
7040
}
7141
}
7242

73-
/**
74-
* Maps a query asynchronous.
75-
*
76-
* @param query The query.
77-
* @param modifier The {@link StatementModifier}.
78-
* @param mapper The {@link ResultSetMapper}.
79-
* @param <T> The generic type.
80-
* @return A generic type.
81-
*/
82-
public <T> @NotNull CompletableFuture<T> mapQueryAsync(@NotNull String query, @NotNull StatementModifier modifier, @NotNull ResultSetMapper<T> mapper) {
83-
CompletableFuture<T> cf = new CompletableFuture<>();
84-
asyncPool.submit(() -> {
85-
try {
86-
cf.complete(mapQuery(query, modifier, mapper));
87-
} catch (SQLException e) {
88-
ExceptionLogger.capture(e, DbActions.class.getSimpleName());
89-
cf.completeExceptionally(e);
90-
}
91-
});
92-
return cf;
93-
}
94-
9543
/**
9644
* Gets a count, using a query which <strong>must</strong> return a long
9745
* integer value as the first column of the result set.
@@ -133,23 +81,6 @@ public long count(@NotNull String query) {
13381
}
13482
}
13583

136-
/**
137-
* Convenience method similar to {@link DbActions#count(String, StatementModifier)}
138-
* which allows for getting the count from a query using simple string
139-
* formatting instead of having to define a statement modifier.
140-
* <p>
141-
* <strong>WARNING</strong>: This method should NEVER be called with
142-
* user-provided data.
143-
* </p>
144-
*
145-
* @param queryFormat The format string.
146-
* @param args The set of arguments to pass to the formatter.
147-
* @return The count.
148-
*/
149-
public long countf(@NotNull String queryFormat, @NotNull Object... args) {
150-
return count(String.format(queryFormat, args));
151-
}
152-
15384
/**
15485
* Updates a database table.
15586
*
@@ -168,71 +99,6 @@ public int update(@NotNull String query, Object @NotNull ... params) throws SQLE
16899
}
169100
}
170101

171-
/**
172-
* Does an asynchronous database action using the bot's async pool.
173-
*
174-
* @param consumer The consumer that will use a connection.
175-
* @return A future that completes when the action is complete.
176-
*/
177-
public @NotNull CompletableFuture<Void> doAsyncAction(ConnectionConsumer consumer) {
178-
CompletableFuture<Void> future = new CompletableFuture<>();
179-
asyncPool.submit(() -> {
180-
try (Connection c = dataSource.getConnection()) {
181-
consumer.consume(c);
182-
future.complete(null);
183-
} catch (SQLException e) {
184-
ExceptionLogger.capture(e, DbActions.class.getSimpleName());
185-
future.completeExceptionally(e);
186-
}
187-
});
188-
return future;
189-
}
190-
191-
/**
192-
* Does an asynchronous database action using the bot's async pool, and
193-
* wraps access to the connection behind a data access object that can be
194-
* built using the provided dao constructor.
195-
*
196-
* @param daoConstructor A function to build a DAO using a connection.
197-
* @param consumer The consumer that does something with the DAO.
198-
* @param <T> The type of data access object. Usually some kind of repository.
199-
* @return A future that completes when the action is complete.
200-
*/
201-
public <T> @NotNull CompletableFuture<Void> doAsyncDaoAction(Function<Connection, T> daoConstructor, DaoConsumer<T> consumer) {
202-
CompletableFuture<Void> future = new CompletableFuture<>();
203-
asyncPool.submit(() -> {
204-
try (Connection c = dataSource.getConnection()) {
205-
T dao = daoConstructor.apply(c);
206-
consumer.consume(dao);
207-
future.complete(null);
208-
} catch (SQLException e) {
209-
ExceptionLogger.capture(e, DbActions.class.getSimpleName());
210-
future.completeExceptionally(e);
211-
}
212-
});
213-
return future;
214-
}
215-
216-
/**
217-
* Maps a {@link ConnectionFunction} asynchronous.
218-
*
219-
* @param function The {@link ConnectionFunction}.
220-
* @param <T> The generic type.
221-
* @return A generic type.
222-
*/
223-
public <T> @NotNull CompletableFuture<T> mapAsync(ConnectionFunction<T> function) {
224-
CompletableFuture<T> future = new CompletableFuture<>();
225-
asyncPool.submit(() -> {
226-
try (Connection c = dataSource.getConnection()) {
227-
future.complete(function.apply(c));
228-
} catch (SQLException e) {
229-
ExceptionLogger.capture(e, DbActions.class.getSimpleName());
230-
future.completeExceptionally(e);
231-
}
232-
});
233-
return future;
234-
}
235-
236102
/**
237103
* Fetches a single result from the database.
238104
*

src/main/java/net/javadiscord/javabot/data/h2db/DbHelper.java

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import java.util.Arrays;
2424
import java.util.List;
2525
import java.util.concurrent.ExecutorService;
26-
import java.util.function.BiFunction;
27-
import java.util.function.Function;
2826
import java.util.regex.Matcher;
2927
import java.util.regex.Pattern;
3028
import java.util.stream.Collectors;
@@ -86,54 +84,6 @@ public class DbHelper {
8684
return ds;
8785
}
8886

89-
/**
90-
* Does an asynchronous database action using the bot's async pool.
91-
*
92-
* @param consumer The consumer that will use a connection.
93-
*/
94-
public void doDbAction(ConnectionConsumer consumer) {
95-
asyncPool.submit(() -> {
96-
try (Connection c = dataSource.getConnection()) {
97-
consumer.consume(c);
98-
} catch (SQLException e) {
99-
ExceptionLogger.capture(e, DbHelper.class.getSimpleName());
100-
}
101-
});
102-
}
103-
104-
/**
105-
* Does an asynchronous database action using the bot's async pool, and
106-
* wraps access to the connection behind a data access object that can be
107-
* built using the provided dao constructor.
108-
*
109-
* @param daoConstructor A function to build a DAO using a connection.
110-
* @param consumer The consumer that does something with the DAO.
111-
* @param <T> The type of data access object. Usually some kind of repository.
112-
*/
113-
public <T> void doDaoAction(Function<Connection, T> daoConstructor, DaoConsumer<T> consumer) {
114-
doDaoAction((con,conf)->daoConstructor.apply(con), consumer);
115-
}
116-
117-
/**
118-
* Does an asynchronous database action using the bot's async pool, and
119-
* wraps access to the connection behind a data access object that can be
120-
* built using the provided dao constructor.
121-
*
122-
* @param daoConstructor A function to build a DAO using a connection.
123-
* @param consumer The consumer that does something with the DAO.
124-
* @param <T> The type of data access object. Usually some kind of repository.
125-
*/
126-
public <T> void doDaoAction(BiFunction<Connection, BotConfig, T> daoConstructor, DaoConsumer<T> consumer) {
127-
asyncPool.submit(() -> {
128-
try (Connection c = dataSource.getConnection()) {
129-
T dao = daoConstructor.apply(c, botConfig);
130-
consumer.consume(dao);
131-
} catch (SQLException e) {
132-
ExceptionLogger.capture(e, DbHelper.class.getSimpleName());
133-
}
134-
});
135-
}
136-
13787
private static boolean shouldInitSchema(String jdbcUrl) {
13888
Pattern p = Pattern.compile("jdbc:h2:tcp://localhost:\\d+/(.*)");
13989
Matcher m = p.matcher(jdbcUrl);

0 commit comments

Comments
 (0)