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 * 列的别名。 033 */ 034 protected String[] alias; 035 036 /** 037 * java entity 定义的属性名称。 038 */ 039 protected String property; 040 041 /** 042 * 属性类型。 043 */ 044 protected Class<?> propertyType; 045 046 /** 047 * 该列对应的 jdbcType。 048 */ 049 protected JdbcType jdbcType; 050 051 /** 052 * 自定义 TypeHandler。 053 */ 054 protected TypeHandler typeHandler; 055 056 /** 057 * 数据脱敏类型。 058 */ 059 protected String maskType; 060 061 062 public String getColumn() { 063 return column; 064 } 065 066 public void setColumn(String column) { 067 this.column = column; 068 } 069 070 public String[] getAlias() { 071 return alias; 072 } 073 074 public void setAlias(String[] alias) { 075 this.alias = alias; 076 } 077 078 public String getProperty() { 079 return property; 080 } 081 082 public void setProperty(String property) { 083 this.property = property; 084 } 085 086 public Class<?> getPropertyType() { 087 return propertyType; 088 } 089 090 public void setPropertyType(Class<?> propertyType) { 091 this.propertyType = propertyType; 092 } 093 094 public JdbcType getJdbcType() { 095 return jdbcType; 096 } 097 098 public void setJdbcType(JdbcType jdbcType) { 099 this.jdbcType = jdbcType; 100 } 101 102 public TypeHandler buildTypeHandler() { 103 104 //优先使用自定义的 typeHandler 105 if (typeHandler != null) { 106 return typeHandler; 107 } 108 //枚举 109 else if (propertyType.isEnum()) { 110 typeHandler = new CompositeEnumTypeHandler(propertyType); 111 } 112 //若用户未定义 typeHandler,而配置了数据脱敏,则使用脱敏的 handler 处理 113 else if (StringUtil.isNotBlank(maskType)) { 114 typeHandler = new MaskTypeHandler(maskType); 115 } 116 117 return typeHandler; 118 } 119 120 public void setTypeHandler(TypeHandler typeHandler) { 121 this.typeHandler = typeHandler; 122 } 123 124 public String getMaskType() { 125 return maskType; 126 } 127 128 public void setMaskType(String maskType) { 129 this.maskType = maskType; 130 } 131 132}