<commit_before>
/*
 * Copyright (C) 2012 <NAME>. All rights reserved.
 *
 * $Id$
 */

package org.dellroad.stuff.xml;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

/**
 * Outputs the result of an SQL query as XML.
 *
 * <p>
 * For example, the query <code>SELECT ID, LAST_NAME, FIRST_NAME FROM EMPLOYEE</code> might become:
 * <pre>
 *  &lt;result-set&gt;
 *      &lt;query&gt;&lt;![CDATA[SELECT ID, LAST_NAME, FIRST_NAME FROM EMPLOYEE]]&gt;&lt;/query&gt;
 *      &lt;columns&gt;
 *          &lt;column index="1" name="ID" precision="20" type="BIGINT" typeName="BIGINT" nullable="false"/&gt;
 *          &lt;column index="2" name="LAST_NAME" precision="255" type="VARCHAR" typeName="VARCHAR" nullable="false"/&gt;
 *          &lt;column index="3" name="FIRST_NAME" precision="255" type="VARCHAR" typeName="VARCHAR" nullable="false"/&gt;
 *      &lt;/columns&gt;
 *      &lt;data&gt;
 *          &lt;row&gt;
 *              &lt;column index="1"&gt;1302&lt;/column&gt;
 *              &lt;column index="2"&gt;Washington&lt;/column&gt;
 *              &lt;column index="3"&gt;George&lt;/column&gt;
 *          &lt;/row&gt;
 *          &lt;row&gt;
 *              &lt;column index="1"&gt;1303&lt;/column&gt;
 *              &lt;column index="2"&gt;Lincoln&lt;/column&gt;
 *              &lt;column index="3"&gt;Abraham&lt;/column&gt;
 *          &lt;/row&gt;
 *          ...
 *      &lt;/data&gt;
 *  &lt;/result-set&gt;
 * </pre>
 * </p>
 */
public class XMLResultSetWriter {

    /**
     * Mapping from result set {@link Types} values to their corresponding names.
     */
    public static final Map<Integer, String> TYPE_NAMES;
    static {
        HashMap<Integer, String> map = new HashMap<Integer, String>();
        for (Field field : Types.class.getDeclaredFields()) {
            if (field.getType() != Integer.TYPE || field.getModifiers() != (Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL))
                continue;
            try {
                map.put(field.getInt(null), field.getName());
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
        TYPE_NAMES = Collections.unmodifiableMap(map);
    }

    private static final String DATE_FORMAT = "dd-MM-yyyy";
    private static final String TIMESTAMP_FORMAT = DATE_FORMAT + " HH:mm:ss";<commit_msg>Fix to r490.<commit_after>
/*
 * Copyright (C) 2012 <NAME>. All rights reserved.
 *
 * $Id$
 */

package org.dellroad.stuff.xml;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

/**
 * Outputs the result of an SQL query as XML.
 *
 * <p>
 * For example, the query <code>SELECT ID, LAST_NAME, FIRST_NAME FROM EMPLOYEE</code> might become:
 * <pre>
 *  &lt;result-set&gt;
 *      &lt;query&gt;&lt;![CDATA[SELECT ID, LAST_NAME, FIRST_NAME FROM EMPLOYEE]]&gt;&lt;/query&gt;
 *      &lt;columns&gt;
 *          &lt;column index="1" name="ID" precision="20" type="BIGINT" typeName="BIGINT" nullable="false"/&gt;
 *          &lt;column index="2" name="LAST_NAME" precision="255" type="VARCHAR" typeName="VARCHAR" nullable="false"/&gt;
 *          &lt;column index="3" name="FIRST_NAME" precision="255" type="VARCHAR" typeName="VARCHAR" nullable="false"/&gt;
 *      &lt;/columns&gt;
 *      &lt;data&gt;
 *          &lt;row&gt;
 *              &lt;column index="1"&gt;1302&lt;/column&gt;
 *              &lt;column index="2"&gt;Washington&lt;/column&gt;
 *              &lt;column index="3"&gt;George&lt;/column&gt;
 *          &lt;/row&gt;
 *          &lt;row&gt;
 *              &lt;column index="1"&gt;1303&lt;/column&gt;
 *              &lt;column index="2"&gt;Lincoln&lt;/column&gt;
 *              &lt;column index="3"&gt;Abraham&lt;/column&gt;
 *          &lt;/row&gt;
 *          ...
 *      &lt;/data&gt;
 *  &lt;/result-set&gt;
 * </pre>
 * </p>
 */
public class XMLResultSetWriter {

    /**
     * Mapping from result set {@link Types} values to their corresponding names.
     */
    public static final Map<Integer, String> TYPE_NAMES;
    static {
        HashMap<Integer, String> map = new HashMap<Integer, String>();
        for (Field field : Types.class.getDeclaredFields()) {
            if (field.getType() != Integer.TYPE || field.getModifiers() != (Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL))
                continue;
            try {
                map.put(field.getInt(null), field.getName());
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
        TYPE_NAMES = Collections.unmodifiableMap(map);
    }

    private static final String DATE_FORMAT = "yyyy-MM-dd";
    private static final String TIMESTAMP_FORMAT = DATE_FORMAT + " HH:mm:ss";
{'fraction_non_alphanumeric': 0.15597950892068538, 'fraction_numerical': 0.010775481363716657, 'mean_word_length': 2.97054698457223, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '5932790', 'n_tokens_mistral': 1922, 'n_tokens_neox': 1861, 'n_words': 369}