|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package org.apache.amoro.server.persistence.mapper; |
| 20 | + |
| 21 | +import org.apache.amoro.server.persistence.converter.Long2TsConverter; |
| 22 | +import org.apache.amoro.server.table.cleanup.CleanupOperation; |
| 23 | +import org.apache.amoro.server.table.cleanup.TableCleanupProcessMeta; |
| 24 | +import org.apache.ibatis.annotations.Delete; |
| 25 | +import org.apache.ibatis.annotations.Insert; |
| 26 | +import org.apache.ibatis.annotations.Param; |
| 27 | +import org.apache.ibatis.annotations.Result; |
| 28 | +import org.apache.ibatis.annotations.Results; |
| 29 | +import org.apache.ibatis.annotations.Select; |
| 30 | +import org.apache.ibatis.annotations.Update; |
| 31 | + |
| 32 | +import java.util.List; |
| 33 | + |
| 34 | +public interface TableCleanupMapper { |
| 35 | + String TABLE_NAME = "table_cleanup_process"; |
| 36 | + |
| 37 | + /** Insert a new table cleanup process record */ |
| 38 | + @Insert( |
| 39 | + "INSERT INTO " |
| 40 | + + TABLE_NAME |
| 41 | + + " (cleanup_process_id, table_id, catalog_name, db_name, table_name, cleanup_operation_code, last_cleanup_end_time) " |
| 42 | + + "VALUES (#{cleanupProcessMeta.cleanupProcessId}," |
| 43 | + + " #{cleanupProcessMeta.tableId}, #{cleanupProcessMeta.catalogName}, " |
| 44 | + + "#{cleanupProcessMeta.dbName}, #{cleanupProcessMeta.tableName}," |
| 45 | + + "#{cleanupProcessMeta.cleanupOperation," |
| 46 | + + " typeHandler=org.apache.amoro.server.persistence.converter.CleanupOperationConverter}," |
| 47 | + + "#{cleanupProcessMeta.lastCleanupEndTime," |
| 48 | + + " typeHandler=org.apache.amoro.server.persistence.converter.Long2TsConverter})") |
| 49 | + void insertTableCleanupProcess( |
| 50 | + @Param("cleanupProcessMeta") TableCleanupProcessMeta cleanupProcessMeta); |
| 51 | + |
| 52 | + /** Update lastCleanupEndTime field by table_id and cleanup_operation_code */ |
| 53 | + @Update( |
| 54 | + "UPDATE " |
| 55 | + + TABLE_NAME |
| 56 | + + " SET last_cleanup_end_time = #{lastCleanupEndTime, typeHandler=org.apache.amoro.server.persistence.converter.Long2TsConverter} " |
| 57 | + + "WHERE table_id = #{tableId} AND cleanup_operation_code = #{cleanupOperation," |
| 58 | + + " typeHandler=org.apache.amoro.server.persistence.converter.CleanupOperationConverter}") |
| 59 | + int updateLastCleanupEndTimeByTableIdAndCleanupOperation( |
| 60 | + @Param("tableId") long tableId, |
| 61 | + @Param("cleanupOperation") CleanupOperation cleanupOperation, |
| 62 | + @Param("lastCleanupEndTime") long lastCleanupEndTime); |
| 63 | + |
| 64 | + /** |
| 65 | + * Select table_id and last_cleanup_end_time by cleanup_operation_code and table_ids If |
| 66 | + * last_cleanup_end_time is NULL in database, it will be converted to 0L as default value |
| 67 | + */ |
| 68 | + @Select( |
| 69 | + "<script>" |
| 70 | + + "SELECT table_id,last_cleanup_end_time " |
| 71 | + + "FROM " |
| 72 | + + TABLE_NAME |
| 73 | + + " WHERE cleanup_operation_code = #{cleanupOperation," |
| 74 | + + " typeHandler=org.apache.amoro.server.persistence.converter.CleanupOperationConverter}" |
| 75 | + + " AND table_id IN " |
| 76 | + + "<foreach item='tableId' collection='tableIds' open='(' separator=',' close=')'>" |
| 77 | + + "#{tableId}" |
| 78 | + + "</foreach>" |
| 79 | + + "</script>") |
| 80 | + @Results({ |
| 81 | + @Result(property = "tableId", column = "table_id"), |
| 82 | + @Result( |
| 83 | + property = "lastCleanupEndTime", |
| 84 | + column = "last_cleanup_end_time", |
| 85 | + typeHandler = Long2TsConverter.class) |
| 86 | + }) |
| 87 | + List<TableCleanupProcessMeta> selectTableIdAndLastCleanupEndTime( |
| 88 | + @Param("tableIds") List<Long> tableIds, |
| 89 | + @Param("cleanupOperation") CleanupOperation cleanupOperation); |
| 90 | + |
| 91 | + /** Delete all cleanup process records for a specific table */ |
| 92 | + @Delete("DELETE FROM " + TABLE_NAME + " WHERE table_id = #{tableId}") |
| 93 | + void deleteTableCleanupProcesses(@Param("tableId") long tableId); |
| 94 | +} |
0 commit comments