<commit_before>﻿// Copyright 2018-2018 by PeopleWare n.v..
// 
// 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.

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;

using PPWCode.Util.OddsAndEnds.II.ConfigHelper;
using PPWCode.Vernacular.Exceptions.II;

using Environment = NHibernate.Cfg.Environment;

namespace PPWCode.Vernacular.NHibernate.I.Implementations.DbConstraint
{
    public abstract class DbConstraints : IDbConstraints
    {
        private static readonly ISet<DbConstraintMetadata> _emptyDbConstraintMetadatas =
            new HashSet<DbConstraintMetadata>();

        private volatile IDictionary<string, DbConstraintMetadata> _constraints;
        protected abstract string ProviderInvariantName { get; }

        public ISet<DbConstraintMetadata> Constraints
            => _constraints != null
                   ? new HashSet<DbConstraintMetadata>(_constraints.Values)
                   : _emptyDbConstraintMetadatas;

        public DbConstraintMetadata GetByConstraintName(string constraintName)
        {
            if (_constraints != null)
            {
                DbConstraintMetadata contraint;
                _constraints.TryGetValue(constraintName, out contraint);
                return contraint;
            }

            return null;
        }

        public void Initialize(IDictionary<string, string> properties)
        {
            if (_constraints == null)
            {
                OnInitialize(properties);
            }
        }

        protected abstract DbCommand GetCommand(DbConnection connection, DbTransaction transaction);
        protected abstract DbConstraintMetadata GetDbConstraintMetadata(DbDataReader reader);

        protected virtual DbConnection GetConnection(IDictionary<string, string> properties)
        {
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            if (ProviderInvariantName != null)
            {
                bool providerExists =
                    DbProviderFactories<commit_msg>Fix typo<commit_after>﻿// Copyright 2018-2018 by PeopleWare n.v..
// 
// 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.

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;

using PPWCode.Util.OddsAndEnds.II.ConfigHelper;
using PPWCode.Vernacular.Exceptions.II;

using Environment = NHibernate.Cfg.Environment;

namespace PPWCode.Vernacular.NHibernate.I.Implementations.DbConstraint
{
    public abstract class DbConstraints : IDbConstraints
    {
        private static readonly ISet<DbConstraintMetadata> _emptyDbConstraintMetadatas =
            new HashSet<DbConstraintMetadata>();

        private volatile IDictionary<string, DbConstraintMetadata> _constraints;
        protected abstract string ProviderInvariantName { get; }

        public ISet<DbConstraintMetadata> Constraints
            => _constraints != null
                   ? new HashSet<DbConstraintMetadata>(_constraints.Values)
                   : _emptyDbConstraintMetadatas;

        public DbConstraintMetadata GetByConstraintName(string constraintName)
        {
            if (_constraints != null)
            {
                DbConstraintMetadata constraint;
                _constraints.TryGetValue(constraintName, out constraint);
                return constraint;
            }

            return null;
        }

        public void Initialize(IDictionary<string, string> properties)
        {
            if (_constraints == null)
            {
                OnInitialize(properties);
            }
        }

        protected abstract DbCommand GetCommand(DbConnection connection, DbTransaction transaction);
        protected abstract DbConstraintMetadata GetDbConstraintMetadata(DbDataReader reader);

        protected virtual DbConnection GetConnection(IDictionary<string, string> properties)
        {
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            if (ProviderInvariantName != null)
            {
                bool providerExists =
                    DbProviderFactories
{'fraction_non_alphanumeric': 0.06958473625140292, 'fraction_numerical': 0.004489337822671156, 'mean_word_length': 2.550464807436919, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2408332', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1225, 'n_words': 380}