<commit_before>/* 
 * Copyright 2006-2022 www.anyline.org
 *
 * 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 org.anyline.entity;
import com.fasterxml.jackson.databind.JsonNode;
import org.anyline.util.*;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import javax.annotation.Resource;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.*;

public class DataRow extends LinkedHashMap<String, Object> implements Serializable{
	private static final long serialVersionUID = -2098827041540802313L;
	protected static final Logger log = LoggerFactory.getLogger(DataRow.class);

	public static enum KEY_CASE{
		CONFIG				{public String getCode(){return "CONFIG";} 			public String getName(){return "按配置文件";}},
		SRC					{public String getCode(){return "SRC";} 			public String getName(){return "不转换";}},
		UPPER				{public String getCode(){return "UPPER";} 			public String getName(){return "强制大写";}},
		LOWER				{public String getCode(){return "LOWER";} 			public String getName(){return "强制小写";}},
		//以下规则取消
		//下/中划线转成驼峰
		Camel 				{public String getCode(){return "Camel";} 			public String getName(){return "大驼峰";}},
		camel 				{public String getCode(){return "camel";} 			public String getName(){return "小驼峰";}},
		//bean驼峰属性转下划线
		CAMEL_CONFIG		{public String getCode(){return "CAMEL_CONFIG";} 	public String getName(){return "转下划线后按配置文件转换大小写";}},
		CAMEL_SRC			{public String getCode(){return "CAMEL_SRC";} 		public String getName(){return "转下划线后不转换大小写";}},
		CAMEL_UPPER			{public String getCode(){return "CAMEL_UPPER";} 	public String getName(){return "转下划线后强制大写";}},
		CAMEL_LOWER			{public String getCode(){return "CAMEL_LOWER";} 	public String getName(){return "转下划线后强制小写";}},

		AUTO				{public String getCode(){return "AUTO";} 			public String getName(){return "自动识别";}};

		public abstract String getName();
		public abstract String getCode();
	}

	private static EntityAdapter adapter;
	private static boolean is_adapter_load = false;

	@Autowired(required = false)
	@Qualifier("anyline.entity.adapter")
	public void setAdapter(EntityAdapter adapter){
		DataRow.adapter = adapter;
	}
	private static EntityAdapter getAdapter(){
		if(null != adapter){
			return adapter;
		}
		if(!is_adapter_load) {
			try {
				adapter = (EntityAdapter)SpringContextUtil.getBean("anyline.entity.adapter");
			}catch (Exception e){}
			is_adapter_load = true;
		}
		return adapter;
	}

	public static String PARENT 			= "PARENT"						; //上级数据 
	public static String ALL_PARENT 		= "ALL_PARENT"					; //所有上级数据 
	public static String CHILDREN 			= "CHILDREN"					; //子数据 
	public static String PRIMARY_KEY		= ConfigTable.getString("DEFAULT_PRIMARY_KEY","ID");
	public static String ITEMS				= "ITEMS"						; 
	private DataSet container				= null							; //包含当前对象的容器
 
	private List<String> primaryKeys 		= new ArrayList<>()				; //主键
	private List<String> updateColumns 		= new ArrayList<>()				;
	private List<String> ignoreUpdateColumns= new ArrayList<>()				;
	private String datalink					= null							; 
	private String dataSource				= null 							; //数据源(表|视图|XML定义SQL) 
	private String schema					= null							; 
	private String table					= null							;
	private Map<String, Object> queryParams	= new HashMap<String,Object>()				; //查询条件
	private Map<String, Object> attributes 	= new HashMap<String,Object>()				; //属性
	private Object clientTrace				= null							; //客户端数据
	private long createTime 				= 0								; //创建时间
	private long expires 					= -1							; //过期时间(毫秒) 从创建时刻计时expires毫秒后过期 
	protected Boolean isNew 				= false							; //强制新建(适应hibernate主键策略) 
	protected boolean isFromCache 			= false							; //是否来自缓存
	private boolean updateNullColumn 		= ConfigTable.getBoolean("IS_UPDATE_NULL_COLUMN", true);
	private boolean updateEmptyColumn 		= ConfigTable.getBoolean("IS_UPDATE_EMPTY_COLUMN", true);
	private Map<String,String> keymap		= new HashMap<String,String>()				; //keymap
	private KEY_CASE keyCase 				= KEY_CASE.CONFIG				; //列名格式
	private boolean isUpperKey				= false							; //是否已执行大写key转换(影响到驼峰执行)
	private Map<String,String> converts 	= new HashMap<>()				; //key是否已转换<key,src><当前key,原key>
	public boolean skip						= false							; //遍历计算时标记


	public DataRow(){
		String pk = putKey(PRIMARY_KEY);
		if(null != pk){
			primaryKeys.add(PRIMARY_KEY);
		}
		parseKeycase();
		createTime = System.currentTimeMillis();
	}
	private void parseKeycase(){
		if(keyCase == KEY_CASE.CONFIG){
			if(ConfigTable.IS_UPPER_KEY){
				keyCase = KEY_CASE.UPPER;
			}else if(ConfigTable.IS_LOWER_KEY){
				keyCase = KEY_CASE.LOWER;
			}else{
				keyCase = KEY_CASE.SRC;
			}
		}<commit_msg>KEY_CASE<commit_after>/* 
 * Copyright 2006-2022 www.anyline.org
 *
 * 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 org.anyline.entity;
import com.fasterxml.jackson.databind.JsonNode;
import org.anyline.util.*;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import org.anyline.entity.KeyAdapter.KEY_CASE;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.*;

public class DataRow extends LinkedHashMap<String, Object> implements Serializable{
	private static final long serialVersionUID = -2098827041540802313L;
	protected static final Logger log = LoggerFactory.getLogger(DataRow.class);

	private static EntityAdapter adapter;
	private static boolean is_adapter_load = false;

	@Autowired(required = false)
	@Qualifier("anyline.entity.adapter")
	public void setAdapter(EntityAdapter adapter){
		DataRow.adapter = adapter;
	}
	private static EntityAdapter getAdapter(){
		if(null != adapter){
			return adapter;
		}
		if(!is_adapter_load) {
			try {
				adapter = (EntityAdapter)SpringContextUtil.getBean("anyline.entity.adapter");
			}catch (Exception e){}
			is_adapter_load = true;
		}
		return adapter;
	}

	public static String PARENT 			= "PARENT"						; //上级数据 
	public static String ALL_PARENT 		= "ALL_PARENT"					; //所有上级数据 
	public static String CHILDREN 			= "CHILDREN"					; //子数据 
	public static String PRIMARY_KEY		= ConfigTable.getString("DEFAULT_PRIMARY_KEY","ID");
	public static String ITEMS				= "ITEMS"						; 
	private DataSet container				= null							; //包含当前对象的容器
 
	private List<String> primaryKeys 		= new ArrayList<>()				; //主键
	private List<String> updateColumns 		= new ArrayList<>()				;
	private List<String> ignoreUpdateColumns= new ArrayList<>()				;
	private String datalink					= null							; 
	private String dataSource				= null 							; //数据源(表|视图|XML定义SQL) 
	private String schema					= null							; 
	private String table					= null							;
	private Map<String, Object> queryParams	= new HashMap<>()				; //查询条件
	private Map<String, Object> attributes 	= new HashMap<>()				; //属性
	private Object clientTrace				= null							; //客户端数据
	private long createTime 				= 0								; //创建时间
	private long expires 					= -1							; //过期时间(毫秒) 从创建时刻计时expires毫秒后过期 
	protected Boolean isNew 				= false							; //强制新建(适应hibernate主键策略) 
	protected boolean isFromCache 			= false							; //是否来自缓存
	private boolean updateNullColumn 		= ConfigTable.getBoolean("IS_UPDATE_NULL_COLUMN", true);
	private boolean updateEmptyColumn 		= ConfigTable.getBoolean("IS_UPDATE_EMPTY_COLUMN", true);
	private Map<String,String> keymap		= new HashMap<>()				; //keymap
	private KEY_CASE keyCase 				= KEY_CASE.CONFIG				; //列名格式
	private boolean isUpperKey				= false							; //是否已执行大写key转换(影响到驼峰执行)
	private Map<String,String> converts 	= new HashMap<>()				; //key是否已转换<key,src><当前key,原key>
	public boolean skip						= false							; //遍历计算时标记


	public DataRow(){
		String pk = putKey(PRIMARY_KEY);
		if(null != pk){
			primaryKeys.add(PRIMARY_KEY);
		}
		parseKeycase();
		createTime = System.currentTimeMillis();
	}
	private void parseKeycase(){
		if(keyCase == KEY_CASE.CONFIG){
			if(ConfigTable.IS_UPPER_KEY){
				keyCase = KEY_CASE.UPPER;
			}else if(ConfigTable.IS_LOWER_KEY){
				keyCase = KEY_CASE.LOWER;
			}else{
				keyCase = KEY_CASE.SRC;
			}
		}
{'fraction_non_alphanumeric': 0.10890285946055567, 'fraction_numerical': 0.007909146217805718, 'mean_word_length': 3.8182706399609185, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3106076', 'n_tokens_mistral': 3784, 'n_tokens_neox': 3447, 'n_words': 812}