<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DbShell.Driver.Common.CommonDataLayer;
using DbShell.Driver.Common.Structure;
using DbShell.Driver.Common.Utility;

namespace DbShell.DataSet.DataSetModels
{
    public class DataSetClass
    {
        private TableInfo _targetTable;
        private DataSetModel _model;

        public string IdentityColumn;
        public int IdentityColumnOrdinal = -1;

        //private string _identityColumn;
        //private int _identityColumnOrdinal = -1;
        public string[] Columns;
        public string[] ComplexPkCols;
        public int[] ComplexPkColIndexes;
        public string[] LookupFields;
        public int[] LookupFieldIndexes;
        public string SimplePkCol;
        public int SimplePkColIndex = -1;

        public bool LoadMissingInstances;
        public bool KeepKey;

        //public string IdentityColumn
        //{
        //    get { return KeepKey ? null : _identityColumn; }
        //}
        //public int IdentityColumnOrdinal
        //{
        //    get { return KeepKey ? -1 : _identityColumnOrdinal; }
        //}

        public List<DataSetReference> References = new List<DataSetReference>();
        public List<DataSetInstance> AllInstances = new List<DataSetInstance>();
        public Dictionary<int, DataSetInstance> InstancesBySimpleKey = new Dictionary<int, DataSetInstance>();
        public Dictionary<string, DataSetInstance> InstancesByComplexPk = new Dictionary<string, DataSetInstance>();

        // dict old lookup value -> lookup mapping tuple
        public Dictionary<int, string[]> LookupValues = new Dictionary<int, string[]>();

        // dict old lookup value -> lookup variable (for WriteSql)
        public Dictionary<int, int> LookupVariables = new Dictionary<int, int>();

        public Dictionary<string, int> ColumnOrdinals = new Dictionary<string, int>();
        public Dictionary<string, UndefinedReferenceReport> _undefinedReferences = new Dictionary<string, UndefinedReferenceReport>();
        public List<string> AddRowsRequests = new List<string>();
        public HashSet<string> RequiredPks = new HashSet<string>();

        public DataSetClass(DataSetModel model, TableInfo targetTable)
        {
            _targetTable = targetTable;
            _model = model;
        }

        public ICdlReader CreateReader()
        {
            return new DataSetClassReader(this);
        }

        public void InitializeClass()
        {
            foreach (var fk in _targetTable.ForeignKeys)
            {
                if (fk.Columns.Count > 1) continue;
                if (fk.RefTableFullName == targetTable.FullName) continue;

                var target = _model.GetClass(fk.RefTableName);
                var r = new DataSetReference
                    {
                        BaseClass = this,
                        ReferencedClass = target,
                        BindingColumn = fk.Columns[0].Name,
                        Mandatory = fk.Columns[0].RefColumn.NotNull,
                    };

                References.Add(r);
            }
<commit_msg>bugfix<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DbShell.Driver.Common.CommonDataLayer;
using DbShell.Driver.Common.Structure;
using DbShell.Driver.Common.Utility;

namespace DbShell.DataSet.DataSetModels
{
    public class DataSetClass
    {
        private TableInfo _targetTable;
        private DataSetModel _model;

        public string IdentityColumn;
        public int IdentityColumnOrdinal = -1;

        //private string _identityColumn;
        //private int _identityColumnOrdinal = -1;
        public string[] Columns;
        public string[] ComplexPkCols;
        public int[] ComplexPkColIndexes;
        public string[] LookupFields;
        public int[] LookupFieldIndexes;
        public string SimplePkCol;
        public int SimplePkColIndex = -1;

        public bool LoadMissingInstances;
        public bool KeepKey;

        //public string IdentityColumn
        //{
        //    get { return KeepKey ? null : _identityColumn; }
        //}
        //public int IdentityColumnOrdinal
        //{
        //    get { return KeepKey ? -1 : _identityColumnOrdinal; }
        //}

        public List<DataSetReference> References = new List<DataSetReference>();
        public List<DataSetInstance> AllInstances = new List<DataSetInstance>();
        public Dictionary<int, DataSetInstance> InstancesBySimpleKey = new Dictionary<int, DataSetInstance>();
        public Dictionary<string, DataSetInstance> InstancesByComplexPk = new Dictionary<string, DataSetInstance>();

        // dict old lookup value -> lookup mapping tuple
        public Dictionary<int, string[]> LookupValues = new Dictionary<int, string[]>();

        // dict old lookup value -> lookup variable (for WriteSql)
        public Dictionary<int, int> LookupVariables = new Dictionary<int, int>();

        public Dictionary<string, int> ColumnOrdinals = new Dictionary<string, int>();
        public Dictionary<string, UndefinedReferenceReport> _undefinedReferences = new Dictionary<string, UndefinedReferenceReport>();
        public List<string> AddRowsRequests = new List<string>();
        public HashSet<string> RequiredPks = new HashSet<string>();

        public DataSetClass(DataSetModel model, TableInfo targetTable)
        {
            _targetTable = targetTable;
            _model = model;
        }

        public ICdlReader CreateReader()
        {
            return new DataSetClassReader(this);
        }

        public void InitializeClass()
        {
            foreach (var fk in _targetTable.ForeignKeys)
            {
                if (fk.Columns.Count > 1) continue;
                if (_targetTable != null && fk.RefTableFullName == _targetTable.FullName) continue;

                var target = _model.GetClass(fk.RefTableName);
                var r = new DataSetReference
                    {
                        BaseClass = this,
                        ReferencedClass = target,
                        BindingColumn = fk.Columns[0].Name,
                        Mandatory = fk.Columns[0].RefColumn.NotNull,
                    };

                References.Add(r);
            }

{'fraction_non_alphanumeric': 0.08511979823455233, 'fraction_numerical': 0.0022068095838587644, 'mean_word_length': 2.238897396630934, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6977480', 'n_tokens_mistral': 1594, 'n_tokens_neox': 1549, 'n_words': 416}