@@ -73,7 +73,11 @@ private void createApiLogTableIfNotExists() {
7373 `player_uuid` CHAR(36) NULL DEFAULT NULL,
7474 `player_world` VARCHAR(100) NULL DEFAULT NULL,
7575 `created_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
76- PRIMARY KEY (`log_no`)
76+ PRIMARY KEY (`log_no`),
77+ INDEX `idx_streamer_id` (`streamer_id`),
78+ INDEX `idx_player_uuid` (`player_uuid`),
79+ INDEX `idx_created_at` (`created_at`),
80+ INDEX `idx_isRun` (`isRun`)
7781 ) COLLATE='utf8mb4_general_ci' ENGINE=InnoDB;
7882 """ ;
7983
@@ -224,96 +228,6 @@ INSERT INTO api_log (server_ip, server_name, streamer_id, username,
224228 }
225229 }
226230
227- @ Override
228- public List <ApiLog > getApiLogsByStreamerId (String streamerId ) {
229- List <ApiLog > logs = new ArrayList <>();
230- String sql = "SELECT * FROM api_log WHERE streamer_id = ?" ;
231-
232- try (Connection conn = dataSource .getConnection ();
233- PreparedStatement stmt = conn .prepareStatement (sql )) {
234- stmt .setString (1 , streamerId );
235- ResultSet rs = stmt .executeQuery ();
236-
237- while (rs .next ()) {
238- logs .add (mapResultSetToApiLog (rs ));
239- }
240- } catch (SQLException e ) {
241- e .printStackTrace ();
242- }
243- return logs ;
244- }
245-
246- @ Override
247- public List <ApiLog > getApiLogsByPlayerUuid (String playerUuid ) {
248- List <ApiLog > logs = new ArrayList <>();
249- String sql = "SELECT * FROM api_log WHERE player_uuid = ?" ;
250-
251- try (Connection conn = dataSource .getConnection ();
252- PreparedStatement stmt = conn .prepareStatement (sql )) {
253- stmt .setString (1 , playerUuid );
254- ResultSet rs = stmt .executeQuery ();
255-
256- while (rs .next ()) {
257- logs .add (mapResultSetToApiLog (rs ));
258- }
259- } catch (SQLException e ) {
260- e .printStackTrace ();
261- }
262- return logs ;
263- }
264-
265- @ Override
266- public List <ApiLog > getApiLogsByDateRange (LocalDateTime start , LocalDateTime end ) {
267- List <ApiLog > logs = new ArrayList <>();
268- String sql = "SELECT * FROM api_log WHERE created_at BETWEEN ? AND ?" ;
269-
270- try (Connection conn = dataSource .getConnection ();
271- PreparedStatement stmt = conn .prepareStatement (sql )) {
272- stmt .setTimestamp (1 , Timestamp .valueOf (start ));
273- stmt .setTimestamp (2 , Timestamp .valueOf (end ));
274- ResultSet rs = stmt .executeQuery ();
275-
276- while (rs .next ()) {
277- logs .add (mapResultSetToApiLog (rs ));
278- }
279- } catch (SQLException e ) {
280- e .printStackTrace ();
281- }
282- return logs ;
283- }
284-
285- @ Override
286- public List <ApiLog > getPendingApiLogs () {
287- List <ApiLog > logs = new ArrayList <>();
288- String sql = "SELECT * FROM api_log WHERE isRun = 'N'" ;
289-
290- try (Connection conn = dataSource .getConnection ();
291- PreparedStatement stmt = conn .prepareStatement (sql );
292- ResultSet rs = stmt .executeQuery ()) {
293-
294- while (rs .next ()) {
295- logs .add (mapResultSetToApiLog (rs ));
296- }
297- } catch (SQLException e ) {
298- e .printStackTrace ();
299- }
300- return logs ;
301- }
302-
303- @ Override
304- public void updateApiLogStatus (Long logNo , ApiLog .IsRun status ) {
305- String sql = "UPDATE api_log SET isRun = ? WHERE log_no = ?" ;
306-
307- try (Connection conn = dataSource .getConnection ();
308- PreparedStatement stmt = conn .prepareStatement (sql )) {
309- stmt .setString (1 , status .name ());
310- stmt .setLong (2 , logNo );
311- stmt .executeUpdate ();
312- } catch (SQLException e ) {
313- e .printStackTrace ();
314- }
315- }
316-
317231 private ApiConnection mapResultSetToConnection (ResultSet rs ) throws SQLException {
318232 return new ApiConnection (
319233 rs .getString ("uuid" ),
0 commit comments