<commit_before>package org.dborm.core.schema;

import org.dborm.core.domain.ColumnBean;
import org.dborm.core.domain.TableBean;
import org.dborm.core.framework.Cache;
import org.dborm.core.utils.StringUtilsDborm;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.*;

/**
 * 操作Schema
 *
 * @author COCHO
 * @time 2013-5-23下午3:25:42
 */
public class DbormSchemaInit {

    StringUtilsDborm stringUtils = new StringUtilsDborm();


    /**
     * 初始化描述文件
     *
     * @param schemaBasePath 描述文件所在的基础路径（将会扫描该路径下的所有子文件）
     * @throws Exception
     */
    public void initSchema(String schemaBasePath) throws Exception {
        List<String> schemaFiles = getSchemaFiles(schemaBasePath);
        for (String schemaFile : schemaFiles) {
            String schemaFilePath = schemaBasePath + File.separator + schemaFile;
            InputStream schemaInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(schemaFilePath);
            Cache.getCache().putAllTablesCache(getSchemaByFile(schemaInputStream));
        }
    }

    /**
     * 通过描述文件初始化（该接口用于Android端等环境使用）
     *
     * @param schemasInputStream 描述文件的输入流
     * @throws Exception
     */
    public void initSchema(List<InputStream> schemasInputStream) throws Exception {
        for (InputStream schemaInputStream : schemasInputStream) {
            Cache.getCache().putAllTablesCache(getSchemaByFile(schemaInputStream));
        }
    }

    private List<String> getSchemaFiles(String schemaBasePath) throws Exception {
        List<String> schemaFiles = new ArrayList<String>();
        URL url = Thread.currentThread().getContextClassLoader().getResource(schemaBasePath);
        if (url != null) {
            File file = new File(url.toURI());<commit_msg>优化描述文件操作<commit_after>package org.dborm.core.schema;

import org.dborm.core.domain.ColumnBean;
import org.dborm.core.domain.TableBean;
import org.dborm.core.framework.Cache;
import org.dborm.core.utils.StringUtilsDborm;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.*;

/**
 * 操作Schema
 *
 * @author COCHO
 * @time 2013-5-23下午3:25:42
 */
public class DbormSchemaInit {

    StringUtilsDborm stringUtils = new StringUtilsDborm();


    /**
     * 初始化描述文件
     *
     * @param schemaBasePath 描述文件所在的基础路径（将会扫描该路径下的所有子文件）
     * @throws Exception
     */
    public void initSchema(String schemaBasePath) throws Exception {
        List<String> schemaFiles = getSchemaFiles(schemaBasePath);
        for (String schemaFile : schemaFiles) {
            String schemaFilePath = schemaBasePath + File.separator + schemaFile;
            InputStream schemaInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(schemaFilePath);
            Cache.getCache().putAllTablesCache(getSchemaByFile(schemaInputStream));
        }
    }

    /**
     * 通过描述文件初始化（该函数用于Android端等环境使用）
     *
     * @param schemasInputStream 描述文件的输入流
     * @throws Exception
     */
    public void initSchema(List<InputStream> schemasInputStream) throws Exception {
        for (InputStream schemaInputStream : schemasInputStream) {
            Cache.getCache().putAllTablesCache(getSchemaByFile(schemaInputStream));
        }
    }

    private List<String> getSchemaFiles(String schemaBasePath) throws Exception {
        List<String> schemaFiles = new ArrayList<String>();
        URL url = Thread.currentThread().getContextClassLoader().getResource(schemaBasePath);
        if (url != null) {
            File file = new File(url.toURI());
{'fraction_non_alphanumeric': 0.1040141378439788, 'fraction_numerical': 0.008078767987881848, 'mean_word_length': 3.590961761297798, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '4624059', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1251, 'n_words': 213}