|
| 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, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.apache.gravitino.storage.relational.mapper; |
| 20 | + |
| 21 | +import java.util.List; |
| 22 | +import org.apache.gravitino.storage.relational.po.FunctionPO; |
| 23 | +import org.apache.gravitino.storage.relational.po.FunctionVersionPO; |
| 24 | +import org.apache.ibatis.annotations.DeleteProvider; |
| 25 | +import org.apache.ibatis.annotations.InsertProvider; |
| 26 | +import org.apache.ibatis.annotations.One; |
| 27 | +import org.apache.ibatis.annotations.Param; |
| 28 | +import org.apache.ibatis.annotations.Result; |
| 29 | +import org.apache.ibatis.annotations.ResultMap; |
| 30 | +import org.apache.ibatis.annotations.Results; |
| 31 | +import org.apache.ibatis.annotations.Select; |
| 32 | +import org.apache.ibatis.annotations.SelectProvider; |
| 33 | +import org.apache.ibatis.annotations.UpdateProvider; |
| 34 | + |
| 35 | +public interface FunctionMetaMapper { |
| 36 | + String TABLE_NAME = "function_meta"; |
| 37 | + String VERSION_TABLE_NAME = "function_version_info"; |
| 38 | + |
| 39 | + @Results( |
| 40 | + id = "mapToFunctionVersionPO", |
| 41 | + value = { |
| 42 | + @Result(property = "id", column = "id", id = true), |
| 43 | + @Result(property = "metalakeId", column = "version_metalake_id"), |
| 44 | + @Result(property = "catalogId", column = "version_catalog_id"), |
| 45 | + @Result(property = "schemaId", column = "version_schema_id"), |
| 46 | + @Result(property = "functionId", column = "version_function_id"), |
| 47 | + @Result(property = "functionVersion", column = "version"), |
| 48 | + @Result(property = "functionComment", column = "function_comment"), |
| 49 | + @Result(property = "definitions", column = "definitions"), |
| 50 | + @Result(property = "auditInfo", column = "version_audit_info"), |
| 51 | + @Result(property = "deletedAt", column = "version_deleted_at") |
| 52 | + }) |
| 53 | + @Select("SELECT 1") // Dummy SQL to avoid MyBatis error, never be executed |
| 54 | + FunctionVersionPO mapToFunctionVersionPO(); |
| 55 | + |
| 56 | + @InsertProvider(type = FunctionMetaSQLProviderFactory.class, method = "insertFunctionMeta") |
| 57 | + void insertFunctionMeta(@Param("functionMeta") FunctionPO functionPO); |
| 58 | + |
| 59 | + @InsertProvider( |
| 60 | + type = FunctionMetaSQLProviderFactory.class, |
| 61 | + method = "insertFunctionMetaOnDuplicateKeyUpdate") |
| 62 | + void insertFunctionMetaOnDuplicateKeyUpdate(@Param("functionMeta") FunctionPO functionPO); |
| 63 | + |
| 64 | + @Results({ |
| 65 | + @Result(property = "functionId", column = "function_id", id = true), |
| 66 | + @Result(property = "functionName", column = "function_name"), |
| 67 | + @Result(property = "metalakeId", column = "metalake_id"), |
| 68 | + @Result(property = "catalogId", column = "catalog_id"), |
| 69 | + @Result(property = "schemaId", column = "schema_id"), |
| 70 | + @Result(property = "functionType", column = "function_type"), |
| 71 | + @Result(property = "deterministic", column = "deterministic"), |
| 72 | + @Result(property = "returnType", column = "return_type"), |
| 73 | + @Result(property = "functionCurrentVersion", column = "function_current_version"), |
| 74 | + @Result(property = "functionLatestVersion", column = "function_latest_version"), |
| 75 | + @Result(property = "auditInfo", column = "audit_info"), |
| 76 | + @Result(property = "deletedAt", column = "deleted_at"), |
| 77 | + @Result( |
| 78 | + property = "functionVersionPO", |
| 79 | + javaType = FunctionVersionPO.class, |
| 80 | + column = |
| 81 | + "{id,version_metalake_id,version_catalog_id,version_schema_id,version_function_id," |
| 82 | + + "version,function_comment,definitions,version_audit_info,version_deleted_at}", |
| 83 | + one = @One(resultMap = "mapToFunctionVersionPO")) |
| 84 | + }) |
| 85 | + @SelectProvider(type = FunctionMetaSQLProviderFactory.class, method = "listFunctionPOsBySchemaId") |
| 86 | + List<FunctionPO> listFunctionPOsBySchemaId(@Param("schemaId") Long schemaId); |
| 87 | + |
| 88 | + @Results( |
| 89 | + id = "functionPOResultMap", |
| 90 | + value = { |
| 91 | + @Result(property = "functionId", column = "function_id", id = true), |
| 92 | + @Result(property = "functionName", column = "function_name"), |
| 93 | + @Result(property = "metalakeId", column = "metalake_id"), |
| 94 | + @Result(property = "catalogId", column = "catalog_id"), |
| 95 | + @Result(property = "schemaId", column = "schema_id"), |
| 96 | + @Result(property = "functionType", column = "function_type"), |
| 97 | + @Result(property = "deterministic", column = "deterministic"), |
| 98 | + @Result(property = "returnType", column = "return_type"), |
| 99 | + @Result(property = "functionCurrentVersion", column = "function_current_version"), |
| 100 | + @Result(property = "functionLatestVersion", column = "function_latest_version"), |
| 101 | + @Result(property = "auditInfo", column = "audit_info"), |
| 102 | + @Result(property = "deletedAt", column = "deleted_at"), |
| 103 | + @Result( |
| 104 | + property = "functionVersionPO", |
| 105 | + javaType = FunctionVersionPO.class, |
| 106 | + column = |
| 107 | + "{id,version_metalake_id,version_catalog_id,version_schema_id,version_function_id," |
| 108 | + + "version,function_comment,definitions,version_audit_info,version_deleted_at}", |
| 109 | + one = @One(resultMap = "mapToFunctionVersionPO")) |
| 110 | + }) |
| 111 | + @SelectProvider( |
| 112 | + type = FunctionMetaSQLProviderFactory.class, |
| 113 | + method = "listFunctionPOsByFullQualifiedName") |
| 114 | + List<FunctionPO> listFunctionPOsByFullQualifiedName( |
| 115 | + @Param("metalakeName") String metalakeName, |
| 116 | + @Param("catalogName") String catalogName, |
| 117 | + @Param("schemaName") String schemaName); |
| 118 | + |
| 119 | + @ResultMap("functionPOResultMap") |
| 120 | + @SelectProvider( |
| 121 | + type = FunctionMetaSQLProviderFactory.class, |
| 122 | + method = "selectFunctionMetaByFullQualifiedName") |
| 123 | + FunctionPO selectFunctionMetaByFullQualifiedName( |
| 124 | + @Param("metalakeName") String metalakeName, |
| 125 | + @Param("catalogName") String catalogName, |
| 126 | + @Param("schemaName") String schemaName, |
| 127 | + @Param("functionName") String functionName); |
| 128 | + |
| 129 | + @ResultMap("functionPOResultMap") |
| 130 | + @SelectProvider( |
| 131 | + type = FunctionMetaSQLProviderFactory.class, |
| 132 | + method = "selectFunctionMetaBySchemaIdAndName") |
| 133 | + FunctionPO selectFunctionMetaBySchemaIdAndName( |
| 134 | + @Param("schemaId") Long schemaId, @Param("functionName") String functionName); |
| 135 | + |
| 136 | + @UpdateProvider( |
| 137 | + type = FunctionMetaSQLProviderFactory.class, |
| 138 | + method = "softDeleteFunctionMetaByFunctionId") |
| 139 | + Integer softDeleteFunctionMetaByFunctionId(@Param("functionId") Long functionId); |
| 140 | + |
| 141 | + @UpdateProvider( |
| 142 | + type = FunctionMetaSQLProviderFactory.class, |
| 143 | + method = "softDeleteFunctionMetasByCatalogId") |
| 144 | + Integer softDeleteFunctionMetasByCatalogId(@Param("catalogId") Long catalogId); |
| 145 | + |
| 146 | + @UpdateProvider( |
| 147 | + type = FunctionMetaSQLProviderFactory.class, |
| 148 | + method = "softDeleteFunctionMetasByMetalakeId") |
| 149 | + Integer softDeleteFunctionMetasByMetalakeId(@Param("metalakeId") Long metalakeId); |
| 150 | + |
| 151 | + @UpdateProvider( |
| 152 | + type = FunctionMetaSQLProviderFactory.class, |
| 153 | + method = "softDeleteFunctionMetasBySchemaId") |
| 154 | + Integer softDeleteFunctionMetasBySchemaId(@Param("schemaId") Long schemaId); |
| 155 | + |
| 156 | + @DeleteProvider( |
| 157 | + type = FunctionMetaSQLProviderFactory.class, |
| 158 | + method = "deleteFunctionMetasByLegacyTimeline") |
| 159 | + Integer deleteFunctionMetasByLegacyTimeline( |
| 160 | + @Param("legacyTimeline") Long legacyTimeline, @Param("limit") int limit); |
| 161 | + |
| 162 | + @UpdateProvider(type = FunctionMetaSQLProviderFactory.class, method = "updateFunctionMeta") |
| 163 | + Integer updateFunctionMeta( |
| 164 | + @Param("newFunctionMeta") FunctionPO newFunctionPO, |
| 165 | + @Param("oldFunctionMeta") FunctionPO oldFunctionPO); |
| 166 | +} |
0 commit comments