From 999fc959d8fc5578716e4f1140811337e80689e0 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Mon, 11 Mar 2024 15:22:44 +0800 Subject: [PATCH] =?UTF-8?q?remove:=20=E7=A7=BB=E9=99=A4=20TableDef=20?= =?UTF-8?q?=E7=B1=BB=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mybatisflex/core/table/TableDef.java | 52 ---------- .../com/mybatisflex/core/table/TableDefs.java | 97 ------------------- 2 files changed, 149 deletions(-) delete mode 100644 mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableDef.java delete mode 100644 mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableDefs.java diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableDef.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableDef.java deleted file mode 100644 index 07bd1fc4..00000000 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableDef.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mybatisflex.core.table; - -import com.mybatisflex.core.query.QueryTable; - -import java.io.Serializable; - -/** - * @author michael - */ -public class TableDef implements Serializable { - - private String schema; - private final String tableName; - - public TableDef(String schema, String tableName) { - this.schema = schema; - this.tableName = tableName; - } - - public TableDef(String tableName) { - this.tableName = tableName; - } - - public String getTableName() { - return tableName; - } - - public String getSchema() { - return schema; - } - - public QueryTable as(String alias) { - return new QueryTable(schema, tableName, alias); - } - - -} diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableDefs.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableDefs.java deleted file mode 100644 index 355a287b..00000000 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableDefs.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mybatisflex.core.table; - -import com.mybatisflex.core.query.QueryColumn; -import com.mybatisflex.core.util.ClassUtil; -import com.mybatisflex.core.util.StringUtil; -import org.apache.ibatis.io.ResolverUtil; - -import java.io.Serializable; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * @author michael - */ -public class TableDefs implements Serializable { - - private static final Map TABLE_DEF_MAP = new HashMap<>(); - private static final Map> QUERY_COLUMN_MAP = new HashMap<>(); - - public static void init(String packageName) { - ResolverUtil> resolverUtil = new ResolverUtil<>(); - resolverUtil.find(new ResolverUtil.IsA(TableDef.class), packageName); - Set>> typeSet = resolverUtil.getClasses(); - for (Class type : typeSet) { - if (!type.isAnonymousClass() && !type.isInterface() && !type.isMemberClass()) { - try { - registerTableDef(type); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - } - } - - - public static TableDef getTableDef(Class entityClass, String tableNameWithSchema) { - TableDef tableDef = TABLE_DEF_MAP.get(tableNameWithSchema); - if (tableDef == null) { - init(entityClass.getPackage().getName()); - tableDef = TABLE_DEF_MAP.get(tableNameWithSchema); - } - return tableDef; - } - - - public static QueryColumn getQueryColumn(Class entityClass, String tableNameWithSchema, String column) { - Map queryColumnMap = QUERY_COLUMN_MAP.get(tableNameWithSchema); - if (queryColumnMap == null) { - init(entityClass.getPackage().getName()); - queryColumnMap = QUERY_COLUMN_MAP.get(tableNameWithSchema); - } - return queryColumnMap != null ? queryColumnMap.get(column) : null; - } - - - public static void registerTableDef(Class tableDefClass) throws IllegalAccessException { - TableDef tableDef = (TableDef) ClassUtil.getFirstField(tableDefClass, field -> { - int mod = Modifier.fieldModifiers(); - return Modifier.isPublic(mod) && Modifier.isStatic(mod); - }).get(null); - - String key = StringUtil.buildSchemaWithTable(tableDef.getSchema(), tableDef.getTableName()); - - TABLE_DEF_MAP.put(key, tableDef); - - List allFields = ClassUtil.getAllFields(tableDef.getClass(), field -> field.getType() == QueryColumn.class); - - Map columnMap = new HashMap<>(allFields.size()); - for (Field field : allFields) { - QueryColumn queryColumn = (QueryColumn) field.get(tableDef); - columnMap.put(queryColumn.getName(), queryColumn); - } - - QUERY_COLUMN_MAP.put(key, columnMap); - } - - -}