|
|
@ -3,6 +3,7 @@ package com.alibaba.excel.util; |
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.lang.reflect.Modifier; |
|
|
|
import java.lang.reflect.Modifier; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.HashSet; |
|
|
@ -10,6 +11,7 @@ import java.util.LinkedHashSet; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
import java.util.TreeMap; |
|
|
|
import java.util.TreeMap; |
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
|
|
|
|
|
|
|
@ -23,7 +25,9 @@ import com.alibaba.excel.annotation.write.style.ContentStyle; |
|
|
|
import com.alibaba.excel.converters.AutoConverter; |
|
|
|
import com.alibaba.excel.converters.AutoConverter; |
|
|
|
import com.alibaba.excel.converters.Converter; |
|
|
|
import com.alibaba.excel.converters.Converter; |
|
|
|
import com.alibaba.excel.exception.ExcelCommonException; |
|
|
|
import com.alibaba.excel.exception.ExcelCommonException; |
|
|
|
import com.alibaba.excel.metadata.Holder; |
|
|
|
import com.alibaba.excel.metadata.ConfigurationHolder; |
|
|
|
|
|
|
|
import com.alibaba.excel.metadata.FieldCache; |
|
|
|
|
|
|
|
import com.alibaba.excel.metadata.FieldWrapper; |
|
|
|
import com.alibaba.excel.metadata.property.DateTimeFormatProperty; |
|
|
|
import com.alibaba.excel.metadata.property.DateTimeFormatProperty; |
|
|
|
import com.alibaba.excel.metadata.property.ExcelContentProperty; |
|
|
|
import com.alibaba.excel.metadata.property.ExcelContentProperty; |
|
|
|
import com.alibaba.excel.metadata.property.FontProperty; |
|
|
|
import com.alibaba.excel.metadata.property.FontProperty; |
|
|
@ -32,9 +36,11 @@ import com.alibaba.excel.metadata.property.StyleProperty; |
|
|
|
import com.alibaba.excel.write.metadata.holder.WriteHolder; |
|
|
|
import com.alibaba.excel.write.metadata.holder.WriteHolder; |
|
|
|
|
|
|
|
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
|
|
|
import lombok.Data; |
|
|
|
import lombok.EqualsAndHashCode; |
|
|
|
import lombok.EqualsAndHashCode; |
|
|
|
import lombok.Getter; |
|
|
|
import lombok.Getter; |
|
|
|
import lombok.Setter; |
|
|
|
import lombok.Setter; |
|
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.springframework.cglib.beans.BeanMap; |
|
|
|
import org.springframework.cglib.beans.BeanMap; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -44,7 +50,7 @@ import org.springframework.cglib.beans.BeanMap; |
|
|
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
|
|
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
|
|
|
* (the "License"); you may not use this file except in compliance with |
|
|
|
* (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
|
|
|
|
* the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* |
|
|
|
* <p> |
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
|
@ -55,18 +61,38 @@ import org.springframework.cglib.beans.BeanMap; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class ClassUtils { |
|
|
|
public class ClassUtils { |
|
|
|
|
|
|
|
|
|
|
|
public static final Map<Class<?>, FieldCache> FIELD_CACHE = new ConcurrentHashMap<>(); |
|
|
|
/** |
|
|
|
|
|
|
|
* memory cache |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static final Map<FieldCacheKey, FieldCache> FIELD_CACHE = new ConcurrentHashMap<>(); |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* thread local cache |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private static final ThreadLocal<Map<FieldCacheKey, FieldCache>> FIELD_THREAD_LOCAL = new ThreadLocal<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* The cache configuration information for each of the class
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static final ConcurrentHashMap<Class<?>, Map<String, ExcelContentProperty>> CLASS_CONTENT_CACHE |
|
|
|
|
|
|
|
= new ConcurrentHashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* The cache configuration information for each of the class
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private static final ThreadLocal<Map<Class<?>, Map<String, ExcelContentProperty>>> CLASS_CONTENT_THREAD_LOCAL |
|
|
|
|
|
|
|
= new ThreadLocal<>(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* The cache configuration information for each of the class
|
|
|
|
* The cache configuration information for each of the class
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static final Map<Class<?>, Map<String, ExcelContentProperty>> CLASS_CONTENT_CACHE |
|
|
|
public static final ConcurrentHashMap<ContentPropertyKey, ExcelContentProperty> CONTENT_CACHE |
|
|
|
= new ConcurrentHashMap<>(); |
|
|
|
= new ConcurrentHashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* The cache configuration information for each of the class
|
|
|
|
* The cache configuration information for each of the class
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static final Map<ContentPropertyKey, ExcelContentProperty> CONTENT_CACHE = new ConcurrentHashMap<>(); |
|
|
|
private static final ThreadLocal<Map<ContentPropertyKey, ExcelContentProperty>> CONTENT_THREAD_LOCAL |
|
|
|
|
|
|
|
= new ThreadLocal<>(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Calculate the configuration information for the class
|
|
|
|
* Calculate the configuration information for the class
|
|
|
@ -77,7 +103,8 @@ public class ClassUtils { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static ExcelContentProperty declaredExcelContentProperty(Map<?, ?> dataMap, Class<?> headClazz, |
|
|
|
public static ExcelContentProperty declaredExcelContentProperty(Map<?, ?> dataMap, Class<?> headClazz, |
|
|
|
String fieldName) { |
|
|
|
String fieldName, |
|
|
|
|
|
|
|
ConfigurationHolder configurationHolder) { |
|
|
|
Class<?> clazz = null; |
|
|
|
Class<?> clazz = null; |
|
|
|
if (dataMap instanceof BeanMap) { |
|
|
|
if (dataMap instanceof BeanMap) { |
|
|
|
Object bean = ((BeanMap)dataMap).getBean(); |
|
|
|
Object bean = ((BeanMap)dataMap).getBean(); |
|
|
@ -85,26 +112,50 @@ public class ClassUtils { |
|
|
|
clazz = bean.getClass(); |
|
|
|
clazz = bean.getClass(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return getExcelContentProperty(clazz, headClazz, fieldName); |
|
|
|
return getExcelContentProperty(clazz, headClazz, fieldName, configurationHolder); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static ExcelContentProperty getExcelContentProperty(Class<?> clazz, Class<?> headClass, String fieldName) { |
|
|
|
private static ExcelContentProperty getExcelContentProperty(Class<?> clazz, Class<?> headClass, String fieldName, |
|
|
|
return CONTENT_CACHE.computeIfAbsent(buildKey(clazz, headClass, fieldName), key -> { |
|
|
|
ConfigurationHolder configurationHolder) { |
|
|
|
ExcelContentProperty excelContentProperty = Optional.ofNullable(declaredFieldContentMap(clazz)) |
|
|
|
switch (configurationHolder.globalConfiguration().getFiledCacheLocation()) { |
|
|
|
.map(map -> map.get(fieldName)) |
|
|
|
case THREAD_LOCAL: |
|
|
|
.orElse(null); |
|
|
|
Map<ContentPropertyKey, ExcelContentProperty> contentCacheMap = CONTENT_THREAD_LOCAL.get(); |
|
|
|
ExcelContentProperty headExcelContentProperty = Optional.ofNullable(declaredFieldContentMap(headClass)) |
|
|
|
if (contentCacheMap == null) { |
|
|
|
.map(map -> map.get(fieldName)) |
|
|
|
contentCacheMap = MapUtils.newHashMap(); |
|
|
|
.orElse(null); |
|
|
|
CONTENT_THREAD_LOCAL.set(contentCacheMap); |
|
|
|
ExcelContentProperty combineExcelContentProperty = new ExcelContentProperty(); |
|
|
|
} |
|
|
|
|
|
|
|
return contentCacheMap.computeIfAbsent(buildKey(clazz, headClass, fieldName), key -> { |
|
|
|
combineExcelContentProperty(combineExcelContentProperty, headExcelContentProperty); |
|
|
|
return doGetExcelContentProperty(clazz, headClass, fieldName, configurationHolder); |
|
|
|
if (clazz != headClass) { |
|
|
|
}); |
|
|
|
combineExcelContentProperty(combineExcelContentProperty, excelContentProperty); |
|
|
|
case MEMORY: |
|
|
|
} |
|
|
|
return CONTENT_CACHE.computeIfAbsent(buildKey(clazz, headClass, fieldName), key -> { |
|
|
|
return combineExcelContentProperty; |
|
|
|
return doGetExcelContentProperty(clazz, headClass, fieldName, configurationHolder); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
case NONE: |
|
|
|
|
|
|
|
return doGetExcelContentProperty(clazz, headClass, fieldName, configurationHolder); |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
throw new UnsupportedOperationException("unsupported enum"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static ExcelContentProperty doGetExcelContentProperty(Class<?> clazz, Class<?> headClass, |
|
|
|
|
|
|
|
String fieldName, |
|
|
|
|
|
|
|
ConfigurationHolder configurationHolder) { |
|
|
|
|
|
|
|
ExcelContentProperty excelContentProperty = Optional.ofNullable( |
|
|
|
|
|
|
|
declaredFieldContentMap(clazz, configurationHolder)) |
|
|
|
|
|
|
|
.map(map -> map.get(fieldName)) |
|
|
|
|
|
|
|
.orElse(null); |
|
|
|
|
|
|
|
ExcelContentProperty headExcelContentProperty = Optional.ofNullable( |
|
|
|
|
|
|
|
declaredFieldContentMap(headClass, configurationHolder)) |
|
|
|
|
|
|
|
.map(map -> map.get(fieldName)) |
|
|
|
|
|
|
|
.orElse(null); |
|
|
|
|
|
|
|
ExcelContentProperty combineExcelContentProperty = new ExcelContentProperty(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
combineExcelContentProperty(combineExcelContentProperty, headExcelContentProperty); |
|
|
|
|
|
|
|
if (clazz != headClass) { |
|
|
|
|
|
|
|
combineExcelContentProperty(combineExcelContentProperty, excelContentProperty); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return combineExcelContentProperty; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void combineExcelContentProperty(ExcelContentProperty combineExcelContentProperty, |
|
|
|
public static void combineExcelContentProperty(ExcelContentProperty combineExcelContentProperty, |
|
|
@ -136,164 +187,256 @@ public class ClassUtils { |
|
|
|
return new ContentPropertyKey(clazz, headClass, fieldName); |
|
|
|
return new ContentPropertyKey(clazz, headClass, fieldName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static Map<String, ExcelContentProperty> declaredFieldContentMap(Class<?> clazz) { |
|
|
|
private static Map<String, ExcelContentProperty> declaredFieldContentMap(Class<?> clazz, |
|
|
|
|
|
|
|
ConfigurationHolder configurationHolder) { |
|
|
|
if (clazz == null) { |
|
|
|
if (clazz == null) { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
return CLASS_CONTENT_CACHE.computeIfAbsent(clazz, key -> { |
|
|
|
switch (configurationHolder.globalConfiguration().getFiledCacheLocation()) { |
|
|
|
List<Field> tempFieldList = new ArrayList<>(); |
|
|
|
case THREAD_LOCAL: |
|
|
|
Class<?> tempClass = clazz; |
|
|
|
Map<Class<?>, Map<String, ExcelContentProperty>> classContentCacheMap |
|
|
|
while (tempClass != null) { |
|
|
|
= CLASS_CONTENT_THREAD_LOCAL.get(); |
|
|
|
Collections.addAll(tempFieldList, tempClass.getDeclaredFields()); |
|
|
|
if (classContentCacheMap == null) { |
|
|
|
// Get the parent class and give it to yourself
|
|
|
|
classContentCacheMap = MapUtils.newHashMap(); |
|
|
|
tempClass = tempClass.getSuperclass(); |
|
|
|
CLASS_CONTENT_THREAD_LOCAL.set(classContentCacheMap); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ContentStyle parentContentStyle = clazz.getAnnotation(ContentStyle.class); |
|
|
|
|
|
|
|
ContentFontStyle parentContentFontStyle = clazz.getAnnotation(ContentFontStyle.class); |
|
|
|
|
|
|
|
Map<String, ExcelContentProperty> fieldContentMap = MapUtils.newHashMapWithExpectedSize( |
|
|
|
|
|
|
|
tempFieldList.size()); |
|
|
|
|
|
|
|
for (Field field : tempFieldList) { |
|
|
|
|
|
|
|
ExcelContentProperty excelContentProperty = new ExcelContentProperty(); |
|
|
|
|
|
|
|
excelContentProperty.setField(field); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class); |
|
|
|
|
|
|
|
if (excelProperty != null) { |
|
|
|
|
|
|
|
Class<? extends Converter<?>> convertClazz = excelProperty.converter(); |
|
|
|
|
|
|
|
if (convertClazz != AutoConverter.class) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Converter<?> converter = convertClazz.getDeclaredConstructor().newInstance(); |
|
|
|
|
|
|
|
excelContentProperty.setConverter(converter); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
throw new ExcelCommonException( |
|
|
|
|
|
|
|
"Can not instance custom converter:" + convertClazz.getName()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return classContentCacheMap.computeIfAbsent(clazz, key -> { |
|
|
|
|
|
|
|
return doDeclaredFieldContentMap(clazz); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
case MEMORY: |
|
|
|
|
|
|
|
return CLASS_CONTENT_CACHE.computeIfAbsent(clazz, key -> { |
|
|
|
|
|
|
|
return doDeclaredFieldContentMap(clazz); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
case NONE: |
|
|
|
|
|
|
|
return doDeclaredFieldContentMap(clazz); |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
throw new UnsupportedOperationException("unsupported enum"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ContentStyle contentStyle = field.getAnnotation(ContentStyle.class); |
|
|
|
} |
|
|
|
if (contentStyle == null) { |
|
|
|
|
|
|
|
contentStyle = parentContentStyle; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
excelContentProperty.setContentStyleProperty(StyleProperty.build(contentStyle)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ContentFontStyle contentFontStyle = field.getAnnotation(ContentFontStyle.class); |
|
|
|
private static Map<String, ExcelContentProperty> doDeclaredFieldContentMap(Class<?> clazz) { |
|
|
|
if (contentFontStyle == null) { |
|
|
|
if (clazz == null) { |
|
|
|
contentFontStyle = parentContentFontStyle; |
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<Field> tempFieldList = new ArrayList<>(); |
|
|
|
|
|
|
|
Class<?> tempClass = clazz; |
|
|
|
|
|
|
|
while (tempClass != null) { |
|
|
|
|
|
|
|
Collections.addAll(tempFieldList, tempClass.getDeclaredFields()); |
|
|
|
|
|
|
|
// Get the parent class and give it to yourself
|
|
|
|
|
|
|
|
tempClass = tempClass.getSuperclass(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ContentStyle parentContentStyle = clazz.getAnnotation(ContentStyle.class); |
|
|
|
|
|
|
|
ContentFontStyle parentContentFontStyle = clazz.getAnnotation(ContentFontStyle.class); |
|
|
|
|
|
|
|
Map<String, ExcelContentProperty> fieldContentMap = MapUtils.newHashMapWithExpectedSize( |
|
|
|
|
|
|
|
tempFieldList.size()); |
|
|
|
|
|
|
|
for (Field field : tempFieldList) { |
|
|
|
|
|
|
|
ExcelContentProperty excelContentProperty = new ExcelContentProperty(); |
|
|
|
|
|
|
|
excelContentProperty.setField(field); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class); |
|
|
|
|
|
|
|
if (excelProperty != null) { |
|
|
|
|
|
|
|
Class<? extends Converter<?>> convertClazz = excelProperty.converter(); |
|
|
|
|
|
|
|
if (convertClazz != AutoConverter.class) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Converter<?> converter = convertClazz.getDeclaredConstructor().newInstance(); |
|
|
|
|
|
|
|
excelContentProperty.setConverter(converter); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
throw new ExcelCommonException( |
|
|
|
|
|
|
|
"Can not instance custom converter:" + convertClazz.getName()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
excelContentProperty.setContentFontProperty(FontProperty.build(contentFontStyle)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
excelContentProperty.setDateTimeFormatProperty( |
|
|
|
ContentStyle contentStyle = field.getAnnotation(ContentStyle.class); |
|
|
|
DateTimeFormatProperty.build(field.getAnnotation(DateTimeFormat.class))); |
|
|
|
if (contentStyle == null) { |
|
|
|
excelContentProperty.setNumberFormatProperty( |
|
|
|
contentStyle = parentContentStyle; |
|
|
|
NumberFormatProperty.build(field.getAnnotation(NumberFormat.class))); |
|
|
|
} |
|
|
|
|
|
|
|
excelContentProperty.setContentStyleProperty(StyleProperty.build(contentStyle)); |
|
|
|
|
|
|
|
|
|
|
|
fieldContentMap.put(field.getName(), excelContentProperty); |
|
|
|
ContentFontStyle contentFontStyle = field.getAnnotation(ContentFontStyle.class); |
|
|
|
|
|
|
|
if (contentFontStyle == null) { |
|
|
|
|
|
|
|
contentFontStyle = parentContentFontStyle; |
|
|
|
} |
|
|
|
} |
|
|
|
return fieldContentMap; |
|
|
|
excelContentProperty.setContentFontProperty(FontProperty.build(contentFontStyle)); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
excelContentProperty.setDateTimeFormatProperty( |
|
|
|
|
|
|
|
DateTimeFormatProperty.build(field.getAnnotation(DateTimeFormat.class))); |
|
|
|
|
|
|
|
excelContentProperty.setNumberFormatProperty( |
|
|
|
|
|
|
|
NumberFormatProperty.build(field.getAnnotation(NumberFormat.class))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fieldContentMap.put(field.getName(), excelContentProperty); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return fieldContentMap; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Parsing field in the class
|
|
|
|
* Parsing field in the class
|
|
|
|
* |
|
|
|
* |
|
|
|
* @param clazz Need to parse the class
|
|
|
|
* @param clazz Need to parse the class
|
|
|
|
* @param sortedAllFieldMap Complete the map of sorts |
|
|
|
* @param configurationHolder configuration |
|
|
|
* @param indexFieldMap Use the index to sort fields |
|
|
|
|
|
|
|
* @param ignoreMap You want to ignore field map |
|
|
|
|
|
|
|
* @param needIgnore If you want to ignore fields need to ignore |
|
|
|
|
|
|
|
* @param holder holder |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static void declaredFields(Class<?> clazz, Map<Integer, Field> sortedAllFieldMap, |
|
|
|
public static FieldCache declaredFields(Class<?> clazz, ConfigurationHolder configurationHolder) { |
|
|
|
Map<Integer, Field> indexFieldMap, Map<String, Field> ignoreMap, Boolean needIgnore, Holder holder) { |
|
|
|
switch (configurationHolder.globalConfiguration().getFiledCacheLocation()) { |
|
|
|
FieldCache fieldCache = declaredFields(clazz); |
|
|
|
case THREAD_LOCAL: |
|
|
|
if (fieldCache == null) { |
|
|
|
Map<FieldCacheKey, FieldCache> fieldCacheMap = FIELD_THREAD_LOCAL.get(); |
|
|
|
return; |
|
|
|
if (fieldCacheMap == null) { |
|
|
|
|
|
|
|
fieldCacheMap = MapUtils.newHashMap(); |
|
|
|
|
|
|
|
FIELD_THREAD_LOCAL.set(fieldCacheMap); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return fieldCacheMap.computeIfAbsent(new FieldCacheKey(clazz, configurationHolder), key -> { |
|
|
|
|
|
|
|
return doDeclaredFields(clazz, configurationHolder); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
case MEMORY: |
|
|
|
|
|
|
|
return FIELD_CACHE.computeIfAbsent(new FieldCacheKey(clazz, configurationHolder), key -> { |
|
|
|
|
|
|
|
return doDeclaredFields(clazz, configurationHolder); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
case NONE: |
|
|
|
|
|
|
|
return doDeclaredFields(clazz, configurationHolder); |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
throw new UnsupportedOperationException("unsupported enum"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (ignoreMap != null) { |
|
|
|
} |
|
|
|
ignoreMap.putAll(fieldCache.getIgnoreMap()); |
|
|
|
|
|
|
|
|
|
|
|
private static FieldCache doDeclaredFields(Class<?> clazz, ConfigurationHolder configurationHolder) { |
|
|
|
|
|
|
|
List<Field> tempFieldList = new ArrayList<>(); |
|
|
|
|
|
|
|
Class<?> tempClass = clazz; |
|
|
|
|
|
|
|
// When the parent class is null, it indicates that the parent class (Object class) has reached the top
|
|
|
|
|
|
|
|
// level.
|
|
|
|
|
|
|
|
while (tempClass != null) { |
|
|
|
|
|
|
|
Collections.addAll(tempFieldList, tempClass.getDeclaredFields()); |
|
|
|
|
|
|
|
// Get the parent class and give it to yourself
|
|
|
|
|
|
|
|
tempClass = tempClass.getSuperclass(); |
|
|
|
} |
|
|
|
} |
|
|
|
Map<Integer, Field> tempIndexFieldMap = indexFieldMap; |
|
|
|
// Screening of field
|
|
|
|
if (tempIndexFieldMap == null) { |
|
|
|
Map<Integer, List<FieldWrapper>> orderFieldMap = new TreeMap<>(); |
|
|
|
tempIndexFieldMap = MapUtils.newTreeMap(); |
|
|
|
Map<Integer, FieldWrapper> indexFieldMap = new TreeMap<>(); |
|
|
|
|
|
|
|
Set<String> ignoreSet = new HashSet<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ExcelIgnoreUnannotated excelIgnoreUnannotated = clazz.getAnnotation(ExcelIgnoreUnannotated.class); |
|
|
|
|
|
|
|
for (Field field : tempFieldList) { |
|
|
|
|
|
|
|
declaredOneField(field, orderFieldMap, indexFieldMap, ignoreSet, excelIgnoreUnannotated); |
|
|
|
} |
|
|
|
} |
|
|
|
tempIndexFieldMap.putAll(fieldCache.getIndexFieldMap()); |
|
|
|
Map<Integer, FieldWrapper> sortedFieldMap = buildSortedAllFieldMap(orderFieldMap, indexFieldMap); |
|
|
|
|
|
|
|
FieldCache fieldCache = new FieldCache(sortedFieldMap, indexFieldMap); |
|
|
|
|
|
|
|
|
|
|
|
Map<Integer, Field> originSortedAllFieldMap = fieldCache.getSortedAllFieldMap(); |
|
|
|
if (!(configurationHolder instanceof WriteHolder)) { |
|
|
|
if (!needIgnore) { |
|
|
|
return fieldCache; |
|
|
|
sortedAllFieldMap.putAll(originSortedAllFieldMap); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WriteHolder writeHolder = (WriteHolder)configurationHolder; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean needIgnore = !CollectionUtils.isEmpty(writeHolder.excludeColumnFieldNames()) |
|
|
|
|
|
|
|
|| !CollectionUtils.isEmpty(writeHolder.excludeColumnIndexes()) |
|
|
|
|
|
|
|
|| !CollectionUtils.isEmpty(writeHolder.includeColumnFieldNames()) |
|
|
|
|
|
|
|
|| !CollectionUtils.isEmpty(writeHolder.includeColumnIndexes()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!needIgnore) { |
|
|
|
|
|
|
|
return fieldCache; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ignore filed
|
|
|
|
|
|
|
|
Map<Integer, FieldWrapper> tempSortedFieldMap = MapUtils.newHashMap(); |
|
|
|
int index = 0; |
|
|
|
int index = 0; |
|
|
|
for (Map.Entry<Integer, Field> entry : originSortedAllFieldMap.entrySet()) { |
|
|
|
for (Map.Entry<Integer, FieldWrapper> entry : sortedFieldMap.entrySet()) { |
|
|
|
Integer key = entry.getKey(); |
|
|
|
Integer key = entry.getKey(); |
|
|
|
Field field = entry.getValue(); |
|
|
|
FieldWrapper field = entry.getValue(); |
|
|
|
|
|
|
|
|
|
|
|
// The current field needs to be ignored
|
|
|
|
// The current field needs to be ignored
|
|
|
|
if (((WriteHolder)holder).ignore(entry.getValue().getName(), entry.getKey())) { |
|
|
|
if (writeHolder.ignore(field.getFieldName(), entry.getKey())) { |
|
|
|
if (ignoreMap != null) { |
|
|
|
ignoreSet.add(field.getFieldName()); |
|
|
|
ignoreMap.put(field.getName(), field); |
|
|
|
indexFieldMap.remove(index); |
|
|
|
} |
|
|
|
|
|
|
|
tempIndexFieldMap.remove(index); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Mandatory sorted fields
|
|
|
|
// Mandatory sorted fields
|
|
|
|
if (tempIndexFieldMap.containsKey(key)) { |
|
|
|
if (indexFieldMap.containsKey(key)) { |
|
|
|
sortedAllFieldMap.put(key, field); |
|
|
|
tempSortedFieldMap.put(key, field); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Need to reorder automatically
|
|
|
|
// Need to reorder automatically
|
|
|
|
// Check whether the current key is already in use
|
|
|
|
// Check whether the current key is already in use
|
|
|
|
while (sortedAllFieldMap.containsKey(index)) { |
|
|
|
while (tempSortedFieldMap.containsKey(index)) { |
|
|
|
index++; |
|
|
|
index++; |
|
|
|
} |
|
|
|
} |
|
|
|
sortedAllFieldMap.put(index++, field); |
|
|
|
tempSortedFieldMap.put(index++, field); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
fieldCache.setSortedFieldMap(tempSortedFieldMap); |
|
|
|
|
|
|
|
|
|
|
|
public static void declaredFields(Class<?> clazz, Map<Integer, Field> sortedAllFieldMap, Boolean needIgnore, |
|
|
|
// resort field
|
|
|
|
WriteHolder writeHolder) { |
|
|
|
resortField(writeHolder, fieldCache); |
|
|
|
declaredFields(clazz, sortedAllFieldMap, null, null, needIgnore, writeHolder); |
|
|
|
return fieldCache; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static FieldCache declaredFields(Class<?> clazz) { |
|
|
|
/** |
|
|
|
if (clazz == null) { |
|
|
|
* it only works when {@link WriteHolder#includeColumnFieldNames()} or |
|
|
|
return null; |
|
|
|
* {@link WriteHolder#includeColumnIndexes()} has value |
|
|
|
|
|
|
|
* and {@link WriteHolder#orderByIncludeColumn()} is true |
|
|
|
|
|
|
|
**/ |
|
|
|
|
|
|
|
private static void resortField(WriteHolder writeHolder, FieldCache fieldCache) { |
|
|
|
|
|
|
|
if (!writeHolder.orderByIncludeColumn()) { |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
return FIELD_CACHE.computeIfAbsent(clazz, key -> { |
|
|
|
Map<Integer, FieldWrapper> indexFieldMap = fieldCache.getIndexFieldMap(); |
|
|
|
List<Field> tempFieldList = new ArrayList<>(); |
|
|
|
|
|
|
|
Class<?> tempClass = clazz; |
|
|
|
Collection<String> includeColumnFieldNames = writeHolder.includeColumnFieldNames(); |
|
|
|
// When the parent class is null, it indicates that the parent class (Object class) has reached the top
|
|
|
|
if (!CollectionUtils.isEmpty(includeColumnFieldNames)) { |
|
|
|
// level.
|
|
|
|
// Field sorted map
|
|
|
|
while (tempClass != null) { |
|
|
|
Map<String, Integer> filedIndexMap = MapUtils.newHashMap(); |
|
|
|
Collections.addAll(tempFieldList, tempClass.getDeclaredFields()); |
|
|
|
int fieldIndex = 0; |
|
|
|
// Get the parent class and give it to yourself
|
|
|
|
for (String includeColumnFieldName : includeColumnFieldNames) { |
|
|
|
tempClass = tempClass.getSuperclass(); |
|
|
|
filedIndexMap.put(includeColumnFieldName, fieldIndex++); |
|
|
|
} |
|
|
|
} |
|
|
|
// Screening of field
|
|
|
|
|
|
|
|
Map<Integer, List<Field>> orderFieldMap = new TreeMap<Integer, List<Field>>(); |
|
|
|
// rebuild sortedFieldMap
|
|
|
|
Map<Integer, Field> indexFieldMap = new TreeMap<Integer, Field>(); |
|
|
|
Map<Integer, FieldWrapper> tempSortedFieldMap = MapUtils.newHashMap(); |
|
|
|
Map<String, Field> ignoreMap = new HashMap<String, Field>(16); |
|
|
|
fieldCache.getSortedFieldMap().forEach((index, field) -> { |
|
|
|
|
|
|
|
Integer tempFieldIndex = filedIndexMap.get(field.getFieldName()); |
|
|
|
ExcelIgnoreUnannotated excelIgnoreUnannotated = clazz.getAnnotation(ExcelIgnoreUnannotated.class); |
|
|
|
if (tempFieldIndex != null) { |
|
|
|
for (Field field : tempFieldList) { |
|
|
|
tempSortedFieldMap.put(tempFieldIndex, field); |
|
|
|
declaredOneField(field, orderFieldMap, indexFieldMap, ignoreMap, excelIgnoreUnannotated); |
|
|
|
|
|
|
|
|
|
|
|
// The user has redefined the ordering and the ordering of annotations needs to be invalidated
|
|
|
|
|
|
|
|
if (!tempFieldIndex.equals(index)) { |
|
|
|
|
|
|
|
indexFieldMap.remove(index); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
fieldCache.setSortedFieldMap(tempSortedFieldMap); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Collection<Integer> includeColumnIndexes = writeHolder.includeColumnIndexes(); |
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(includeColumnIndexes)) { |
|
|
|
|
|
|
|
// Index sorted map
|
|
|
|
|
|
|
|
Map<Integer, Integer> filedIndexMap = MapUtils.newHashMap(); |
|
|
|
|
|
|
|
int fieldIndex = 0; |
|
|
|
|
|
|
|
for (Integer includeColumnIndex : includeColumnIndexes) { |
|
|
|
|
|
|
|
filedIndexMap.put(includeColumnIndex, fieldIndex++); |
|
|
|
} |
|
|
|
} |
|
|
|
return new FieldCache(buildSortedAllFieldMap(orderFieldMap, indexFieldMap), indexFieldMap, ignoreMap); |
|
|
|
|
|
|
|
}); |
|
|
|
// rebuild sortedFieldMap
|
|
|
|
|
|
|
|
Map<Integer, FieldWrapper> tempSortedFieldMap = MapUtils.newHashMap(); |
|
|
|
|
|
|
|
fieldCache.getSortedFieldMap().forEach((index, field) -> { |
|
|
|
|
|
|
|
Integer tempFieldIndex = filedIndexMap.get(index); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The user has redefined the ordering and the ordering of annotations needs to be invalidated
|
|
|
|
|
|
|
|
if (tempFieldIndex != null) { |
|
|
|
|
|
|
|
tempSortedFieldMap.put(tempFieldIndex, field); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
fieldCache.setSortedFieldMap(tempSortedFieldMap); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static Map<Integer, Field> buildSortedAllFieldMap(Map<Integer, List<Field>> orderFieldMap, |
|
|
|
private static Map<Integer, FieldWrapper> buildSortedAllFieldMap(Map<Integer, List<FieldWrapper>> orderFieldMap, |
|
|
|
Map<Integer, Field> indexFieldMap) { |
|
|
|
Map<Integer, FieldWrapper> indexFieldMap) { |
|
|
|
|
|
|
|
|
|
|
|
Map<Integer, Field> sortedAllFieldMap = new HashMap<Integer, Field>( |
|
|
|
Map<Integer, FieldWrapper> sortedAllFieldMap = new HashMap<>( |
|
|
|
(orderFieldMap.size() + indexFieldMap.size()) * 4 / 3 + 1); |
|
|
|
(orderFieldMap.size() + indexFieldMap.size()) * 4 / 3 + 1); |
|
|
|
|
|
|
|
|
|
|
|
Map<Integer, Field> tempIndexFieldMap = new HashMap<Integer, Field>(indexFieldMap); |
|
|
|
Map<Integer, FieldWrapper> tempIndexFieldMap = new HashMap<>(indexFieldMap); |
|
|
|
int index = 0; |
|
|
|
int index = 0; |
|
|
|
for (List<Field> fieldList : orderFieldMap.values()) { |
|
|
|
for (List<FieldWrapper> fieldList : orderFieldMap.values()) { |
|
|
|
for (Field field : fieldList) { |
|
|
|
for (FieldWrapper field : fieldList) { |
|
|
|
while (tempIndexFieldMap.containsKey(index)) { |
|
|
|
while (tempIndexFieldMap.containsKey(index)) { |
|
|
|
sortedAllFieldMap.put(index, tempIndexFieldMap.get(index)); |
|
|
|
sortedAllFieldMap.put(index, tempIndexFieldMap.get(index)); |
|
|
|
tempIndexFieldMap.remove(index); |
|
|
|
tempIndexFieldMap.remove(index); |
|
|
@ -307,34 +450,45 @@ public class ClassUtils { |
|
|
|
return sortedAllFieldMap; |
|
|
|
return sortedAllFieldMap; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void declaredOneField(Field field, Map<Integer, List<Field>> orderFieldMap, |
|
|
|
private static void declaredOneField(Field field, Map<Integer, List<FieldWrapper>> orderFieldMap, |
|
|
|
Map<Integer, Field> indexFieldMap, Map<String, Field> ignoreMap, |
|
|
|
Map<Integer, FieldWrapper> indexFieldMap, Set<String> ignoreSet, |
|
|
|
ExcelIgnoreUnannotated excelIgnoreUnannotated) { |
|
|
|
ExcelIgnoreUnannotated excelIgnoreUnannotated) { |
|
|
|
|
|
|
|
String fieldName = FieldUtils.resolveCglibFieldName(field); |
|
|
|
|
|
|
|
FieldWrapper fieldWrapper = new FieldWrapper(); |
|
|
|
|
|
|
|
fieldWrapper.setField(field); |
|
|
|
|
|
|
|
fieldWrapper.setFieldName(fieldName); |
|
|
|
|
|
|
|
|
|
|
|
ExcelIgnore excelIgnore = field.getAnnotation(ExcelIgnore.class); |
|
|
|
ExcelIgnore excelIgnore = field.getAnnotation(ExcelIgnore.class); |
|
|
|
|
|
|
|
|
|
|
|
if (excelIgnore != null) { |
|
|
|
if (excelIgnore != null) { |
|
|
|
ignoreMap.put(field.getName(), field); |
|
|
|
ignoreSet.add(fieldName); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class); |
|
|
|
ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class); |
|
|
|
boolean noExcelProperty = excelProperty == null && excelIgnoreUnannotated != null; |
|
|
|
boolean noExcelProperty = excelProperty == null && excelIgnoreUnannotated != null; |
|
|
|
if (noExcelProperty) { |
|
|
|
if (noExcelProperty) { |
|
|
|
ignoreMap.put(field.getName(), field); |
|
|
|
ignoreSet.add(fieldName); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
boolean isStaticFinalOrTransient = |
|
|
|
boolean isStaticFinalOrTransient = |
|
|
|
(Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) |
|
|
|
(Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) |
|
|
|
|| Modifier.isTransient(field.getModifiers()); |
|
|
|
|| Modifier.isTransient(field.getModifiers()); |
|
|
|
if (excelProperty == null && isStaticFinalOrTransient) { |
|
|
|
if (excelProperty == null && isStaticFinalOrTransient) { |
|
|
|
ignoreMap.put(field.getName(), field); |
|
|
|
ignoreSet.add(fieldName); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// set heads
|
|
|
|
|
|
|
|
if (excelProperty != null) { |
|
|
|
|
|
|
|
fieldWrapper.setHeads(excelProperty.value()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (excelProperty != null && excelProperty.index() >= 0) { |
|
|
|
if (excelProperty != null && excelProperty.index() >= 0) { |
|
|
|
if (indexFieldMap.containsKey(excelProperty.index())) { |
|
|
|
if (indexFieldMap.containsKey(excelProperty.index())) { |
|
|
|
throw new ExcelCommonException("The index of '" + indexFieldMap.get(excelProperty.index()).getName() |
|
|
|
throw new ExcelCommonException( |
|
|
|
+ "' and '" + field.getName() + "' must be inconsistent"); |
|
|
|
"The index of '" + indexFieldMap.get(excelProperty.index()).getFieldName() |
|
|
|
|
|
|
|
+ "' and '" + field.getName() + "' must be inconsistent"); |
|
|
|
} |
|
|
|
} |
|
|
|
indexFieldMap.put(excelProperty.index(), field); |
|
|
|
indexFieldMap.put(excelProperty.index(), fieldWrapper); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -342,34 +496,8 @@ public class ClassUtils { |
|
|
|
if (excelProperty != null) { |
|
|
|
if (excelProperty != null) { |
|
|
|
order = excelProperty.order(); |
|
|
|
order = excelProperty.order(); |
|
|
|
} |
|
|
|
} |
|
|
|
List<Field> orderFieldList = orderFieldMap.computeIfAbsent(order, key -> ListUtils.newArrayList()); |
|
|
|
List<FieldWrapper> orderFieldList = orderFieldMap.computeIfAbsent(order, key -> ListUtils.newArrayList()); |
|
|
|
orderFieldList.add(field); |
|
|
|
orderFieldList.add(fieldWrapper); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class FieldCache { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Map<Integer, Field> sortedAllFieldMap; |
|
|
|
|
|
|
|
private final Map<Integer, Field> indexFieldMap; |
|
|
|
|
|
|
|
private final Map<String, Field> ignoreMap; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public FieldCache(Map<Integer, Field> sortedAllFieldMap, Map<Integer, Field> indexFieldMap, |
|
|
|
|
|
|
|
Map<String, Field> ignoreMap) { |
|
|
|
|
|
|
|
this.sortedAllFieldMap = sortedAllFieldMap; |
|
|
|
|
|
|
|
this.indexFieldMap = indexFieldMap; |
|
|
|
|
|
|
|
this.ignoreMap = ignoreMap; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Map<Integer, Field> getSortedAllFieldMap() { |
|
|
|
|
|
|
|
return sortedAllFieldMap; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Map<Integer, Field> getIndexFieldMap() { |
|
|
|
|
|
|
|
return indexFieldMap; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Map<String, Field> getIgnoreMap() { |
|
|
|
|
|
|
|
return ignoreMap; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -425,4 +553,31 @@ public class ClassUtils { |
|
|
|
private Class<?> headClass; |
|
|
|
private Class<?> headClass; |
|
|
|
private String fieldName; |
|
|
|
private String fieldName; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Data |
|
|
|
|
|
|
|
public static class FieldCacheKey { |
|
|
|
|
|
|
|
private Class<?> clazz; |
|
|
|
|
|
|
|
private Collection<String> excludeColumnFieldNames; |
|
|
|
|
|
|
|
private Collection<Integer> excludeColumnIndexes; |
|
|
|
|
|
|
|
private Collection<String> includeColumnFieldNames; |
|
|
|
|
|
|
|
private Collection<Integer> includeColumnIndexes; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FieldCacheKey(Class<?> clazz, ConfigurationHolder configurationHolder) { |
|
|
|
|
|
|
|
this.clazz = clazz; |
|
|
|
|
|
|
|
if (configurationHolder instanceof WriteHolder) { |
|
|
|
|
|
|
|
WriteHolder writeHolder = (WriteHolder)configurationHolder; |
|
|
|
|
|
|
|
this.excludeColumnFieldNames = writeHolder.excludeColumnFieldNames(); |
|
|
|
|
|
|
|
this.excludeColumnIndexes = writeHolder.excludeColumnIndexes(); |
|
|
|
|
|
|
|
this.includeColumnFieldNames = writeHolder.includeColumnFieldNames(); |
|
|
|
|
|
|
|
this.includeColumnIndexes = writeHolder.includeColumnIndexes(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void removeThreadLocalCache() { |
|
|
|
|
|
|
|
FIELD_THREAD_LOCAL.remove(); |
|
|
|
|
|
|
|
CLASS_CONTENT_THREAD_LOCAL.remove(); |
|
|
|
|
|
|
|
CONTENT_THREAD_LOCAL.remove(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|