001/** 002 * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.mybatisflex.core.table; 017 018import com.mybatisflex.core.handler.CompositeEnumTypeHandler; 019import com.mybatisflex.core.mask.MaskTypeHandler; 020import com.mybatisflex.core.util.StringUtil; 021import org.apache.ibatis.type.JdbcType; 022import org.apache.ibatis.type.TypeHandler; 023 024public class ColumnInfo { 025 026 /** 027 * 数据库列名 028 */ 029 protected String column; 030 031 /** 032 * java entity 定义的属性名称 033 */ 034 protected String property; 035 036 /** 037 * 属性类型 038 */ 039 protected Class<?> propertyType; 040 041 /** 042 * 该列对应的 jdbcType 043 */ 044 protected JdbcType jdbcType; 045 046 /** 047 * 自定义 TypeHandler 048 */ 049 protected TypeHandler typeHandler; 050 051 052 protected String maskType; 053 054 055 public String getColumn() { 056 return column; 057 } 058 059 public void setColumn(String column) { 060 this.column = column; 061 } 062 063 public String getProperty() { 064 return property; 065 } 066 067 public void setProperty(String property) { 068 this.property = property; 069 } 070 071 public Class<?> getPropertyType() { 072 return propertyType; 073 } 074 075 public void setPropertyType(Class<?> propertyType) { 076 this.propertyType = propertyType; 077 } 078 079 public JdbcType getJdbcType() { 080 return jdbcType; 081 } 082 083 public void setJdbcType(JdbcType jdbcType) { 084 this.jdbcType = jdbcType; 085 } 086 087 public TypeHandler buildTypeHandler() { 088 089 //优先使用自定义的 typeHandler 090 if (typeHandler != null) { 091 return typeHandler; 092 } 093 //枚举 094 else if (propertyType.isEnum()) { 095 typeHandler = new CompositeEnumTypeHandler(propertyType); 096 } 097 //若用户未定义 typeHandler,而配置了数据脱敏,则使用脱敏的 handler 处理 098 else if (StringUtil.isNotBlank(maskType)) { 099 typeHandler = new MaskTypeHandler(maskType); 100 } 101 102 return typeHandler; 103 } 104 105 public void setTypeHandler(TypeHandler typeHandler) { 106 this.typeHandler = typeHandler; 107 } 108 109 public String getMaskType() { 110 return maskType; 111 } 112 113 public void setMaskType(String maskType) { 114 this.maskType = maskType; 115 } 116}