public virtual string Generate(IStructureIndex structureIndex)
        {
            if(structureIndex.DataTypeCode == DataTypeCode.Text)
                throw new SisoDbNotSupportedException(ExceptionMessages.DefaultUniquesChecksumGenerator_UnsupportedDataType.Inject(structureIndex.Path));

            return HashService.GenerateHash(SisoEnvironment.StringConverter.AsString(structureIndex.Value));
        }
        public virtual string Generate(IStructureIndex structureIndex)
        {
            if (structureIndex.DataTypeCode == DataTypeCode.Text)
            {
                throw new SisoDbNotSupportedException(ExceptionMessages.DefaultUniquesChecksumGenerator_UnsupportedDataType.Inject(structureIndex.Path));
            }

            return(HashService.GenerateHash(SisoEnvironment.StringConverter.AsString(structureIndex.Value)));
        }
 public bool Equals(IStructureIndex other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.StructureId, StructureId) && Equals(other.Path, Path) && Equals(other.Value, Value));
 }
Example #4
0
        public virtual void SingleInsertOfStringTypeIndex(IStructureIndex structureIndex, string stringishIndexesTableName)
        {
            EnsureValidDbObjectName(stringishIndexesTableName);

            var sql = StringExtensions.Inject(SqlStatements.GetSql("SingleInsertOfStringTypeIndex"), stringishIndexesTableName,
                                              IndexStorageSchema.Fields.StructureId.Name,
                                              IndexStorageSchema.Fields.MemberPath.Name,
                                              IndexStorageSchema.Fields.Value.Name);

            ExecuteNonQuery(sql,
                            new DacParameter(IndexStorageSchema.Fields.StructureId.Name, structureIndex.StructureId.Value),
                            new DacParameter(IndexStorageSchema.Fields.MemberPath.Name, structureIndex.Path),
                            new DacParameter(IndexStorageSchema.Fields.Value.Name, structureIndex.Value == null ? null : structureIndex.Value.ToString()));
        }
Example #5
0
 public static string Format(IStructureIndex index)
 {
     return($"{index.Path}=\"{index.Value}\"");
     //switch (index.DataTypeCode)
     //{
     //    case DataTypeCode.String:
     //    case DataTypeCode.Guid:
     //    case DataTypeCode.Enum:
     //        return $"Path\t{index.Path}=\"{index.Value}\"";
     //    case DataTypeCode.DateTime:
     //        return $"Path\t{index.Path}=\"{((DateTime)index.Value):O}\"";
     //    default:
     //        return $"Path\t{index.Path}={index.Value}";
     //}
 }
Example #6
0
        public virtual void SingleInsertOfValueTypeIndex(IStructureIndex structureIndex, string valueTypeIndexesTableName)
        {
            EnsureValidDbObjectName(valueTypeIndexesTableName);

            var sql = StringExtensions.Inject(SqlStatements.GetSql("SingleInsertOfValueTypeIndex"), valueTypeIndexesTableName,
                                              IndexStorageSchema.Fields.StructureId.Name,
                                              IndexStorageSchema.Fields.MemberPath.Name,
                                              IndexStorageSchema.Fields.Value.Name,
                                              IndexStorageSchema.Fields.StringValue.Name);

            ExecuteNonQuery(sql,
                            new DacParameter(IndexStorageSchema.Fields.StructureId.Name, structureIndex.StructureId.Value),
                            new DacParameter(IndexStorageSchema.Fields.MemberPath.Name, structureIndex.Path),
                            new DacParameter(IndexStorageSchema.Fields.Value.Name, structureIndex.Value),
                            new DacParameter(IndexStorageSchema.Fields.StringValue.Name, SisoEnvironment.StringConverter.AsString(structureIndex.Value)));
        }
Example #7
0
        public IStructureIndex[] CreateIndexes <T>(IStructureSchema structureSchema, T item, IStructureId structureId) where T : class
        {
            var indexes = new IEnumerable <IStructureIndex> [structureSchema.IndexAccessors.Count];

            Parallel.For(0, indexes.Length, c =>
            {
                var indexAccessor        = structureSchema.IndexAccessors[c];
                var values               = indexAccessor.GetValues(item);
                var valuesExists         = values != null && values.Count > 0;
                var isCollectionOfValues = indexAccessor.IsEnumerable || indexAccessor.IsElement || (values != null && values.Count > 1);

                if (!valuesExists)
                {
                    if (!isCollectionOfValues && indexAccessor.IsUnique)
                    {
                        throw new SisoDbException(ExceptionMessages.StructureIndexesFactory_UniqueIndex_IsNull.Inject(structureSchema.Name, indexAccessor.Path));
                    }

                    return;
                }

                if (!isCollectionOfValues)
                {
                    indexes[c] = new[] { new StructureIndex(structureId, indexAccessor.Path, values[0], indexAccessor.DataType, indexAccessor.DataTypeCode, indexAccessor.UniqueMode.ToStructureIndexType()) }
                }
                ;
                else
                {
                    var subIndexes = new IStructureIndex[values.Count];
                    Parallel.For(0, subIndexes.Length, subC =>
                    {
                        if (values[subC] != null)
                        {
                            subIndexes[subC] = new StructureIndex(structureId, indexAccessor.Path, values[subC],
                                                                  indexAccessor.DataType, indexAccessor.DataTypeCode,
                                                                  indexAccessor.UniqueMode.ToStructureIndexType());
                        }
                    });
                    indexes[c] = subIndexes;
                }
            });

            return(indexes.Where(i => i != null).SelectMany(i => i).Where(i => i != null).ToArray());
        }
Example #8
0
        public virtual void SingleInsertOfUniqueIndex(IStructureIndex uniqueStructureIndex, IStructureSchema structureSchema)
        {
            var sql = StringExtensions.Inject(SqlStatements.GetSql("SingleInsertOfUniqueIndex"), structureSchema.GetUniquesTableName(),
                                              UniqueStorageSchema.Fields.StructureId.Name,
                                              UniqueStorageSchema.Fields.UqStructureId.Name,
                                              UniqueStorageSchema.Fields.UqMemberPath.Name,
                                              UniqueStorageSchema.Fields.UqValue.Name);

            var parameters = new IDacParameter[4];

            parameters[0] = new DacParameter(UniqueStorageSchema.Fields.StructureId.Name, uniqueStructureIndex.StructureId.Value);
            parameters[1] = (uniqueStructureIndex.IndexType == StructureIndexType.UniquePerType)
                                ? new DacParameter(UniqueStorageSchema.Fields.UqStructureId.Name, DBNull.Value)
                                : new DacParameter(UniqueStorageSchema.Fields.UqStructureId.Name, uniqueStructureIndex.StructureId.Value);
            parameters[2] = new DacParameter(UniqueStorageSchema.Fields.UqMemberPath.Name, uniqueStructureIndex.Path);
            parameters[3] = new DacParameter(UniqueStorageSchema.Fields.UqValue.Name, UniquesChecksumGenerator.Instance.Generate(uniqueStructureIndex));

            ExecuteNonQuery(sql, parameters);
        }
        protected virtual IndexInsertAction CreateIndexInsertActionGroup(IStructureSchema structureSchema, IndexesTableNames indexesTableNames, DataTypeCode dataTypeCode, IStructureIndex[] indexes)
        {
            var container = new IndexInsertAction { Data = indexes };

            switch (dataTypeCode)
            {
                case DataTypeCode.IntegerNumber:
                    if (container.Data.Length > 1)
                        container.Action = (data, dbClient) => dbClient.BulkInsertIndexes(new ValueTypeIndexesReader(new IndexStorageSchema(structureSchema, indexesTableNames.IntegersTableName), data));
                    if (container.Data.Length == 1)
                        container.Action = (data, dbClient) => dbClient.SingleInsertOfValueTypeIndex(data[0], indexesTableNames.IntegersTableName);
                    break;
                case DataTypeCode.FractalNumber:
                    if (container.Data.Length > 1)
                        container.Action = (data, dbClient) => dbClient.BulkInsertIndexes(new ValueTypeIndexesReader(new IndexStorageSchema(structureSchema, indexesTableNames.FractalsTableName), data));
                    if (container.Data.Length == 1)
                        container.Action = (data, dbClient) => dbClient.SingleInsertOfValueTypeIndex(data[0], indexesTableNames.FractalsTableName);
                    break;
                case DataTypeCode.Bool:
                    if (container.Data.Length > 1)
                        container.Action = (data, dbClient) => dbClient.BulkInsertIndexes(new ValueTypeIndexesReader(new IndexStorageSchema(structureSchema, indexesTableNames.BooleansTableName), data));
                    if (container.Data.Length == 1)
                        container.Action = (data, dbClient) => dbClient.SingleInsertOfValueTypeIndex(data[0], indexesTableNames.BooleansTableName);
                    break;
                case DataTypeCode.DateTime:
                    if (container.Data.Length > 1)
                        container.Action = (data, dbClient) => dbClient.BulkInsertIndexes(new ValueTypeIndexesReader(new IndexStorageSchema(structureSchema, indexesTableNames.DatesTableName), data));
                    if (container.Data.Length == 1)
                        container.Action = (data, dbClient) => dbClient.SingleInsertOfValueTypeIndex(data[0], indexesTableNames.DatesTableName);
                    break;
                case DataTypeCode.Guid:
                    if (container.Data.Length > 1)
                        container.Action = (data, dbClient) => dbClient.BulkInsertIndexes(new ValueTypeIndexesReader(new IndexStorageSchema(structureSchema, indexesTableNames.GuidsTableName), data));
                    if (container.Data.Length == 1)
                        container.Action = (data, dbClient) => dbClient.SingleInsertOfValueTypeIndex(data[0], indexesTableNames.GuidsTableName);
                    break;
                case DataTypeCode.String:
                    if (container.Data.Length > 1)
                        container.Action = (data, dbClient) => dbClient.BulkInsertIndexes(new StringIndexesReader(new IndexStorageSchema(structureSchema, indexesTableNames.StringsTableName), data));
                    if (container.Data.Length == 1)
                        container.Action = (data, dbClient) => dbClient.SingleInsertOfStringTypeIndex(data[0], indexesTableNames.StringsTableName);
                    break;
                case DataTypeCode.Enum:
                    if (container.Data.Length > 1)
                        container.Action = (data, dbClient) => dbClient.BulkInsertIndexes(new StringIndexesReader(new IndexStorageSchema(structureSchema, indexesTableNames.StringsTableName), data));
                    if (container.Data.Length == 1)
                        container.Action = (data, dbClient) => dbClient.SingleInsertOfStringTypeIndex(data[0], indexesTableNames.StringsTableName);
                    break;
                case DataTypeCode.Text:
                    if (container.Data.Length > 1)
                        container.Action = (data, dbClient) => dbClient.BulkInsertIndexes(new TextIndexesReader(new IndexStorageSchema(structureSchema, indexesTableNames.TextsTableName), data));
                    if (container.Data.Length == 1)
                        container.Action = (data, dbClient) => dbClient.SingleInsertOfStringTypeIndex(data[0], indexesTableNames.TextsTableName);
                    break;
                default:
                    container.Action = null;
                    break;
            }

            return container;
        }
 public bool Equals(IStructureIndex other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.StructureId, StructureId) && Equals(other.Path, Path) && Equals(other.Value, Value);
 }
Example #11
0
 internal IndexRow(IStructureId structureId, IStructureIndex[] indexes)
 {
     StructureId = structureId;
     Indexes = indexes;
 }
        protected virtual void BulkInsertUniques(IStructureSchema structureSchema, IStructureIndex[] uniques)
        {
            if (!uniques.Any())
                return;

            var uniquesStorageSchema = new UniqueStorageSchema(structureSchema, structureSchema.GetUniquesTableName());

            using (var uniquesReader = new UniquesReader(uniquesStorageSchema, uniques))
            {
                using (var bulkInserter = MainDbClient.GetBulkCopy())
                {
                    bulkInserter.DestinationTableName = uniquesReader.StorageSchema.Name;
                    bulkInserter.BatchSize = uniques.Length;

                    var fields = uniquesReader.StorageSchema.GetFieldsOrderedByIndex().Where(f => !f.Equals(StructureStorageSchema.Fields.RowId)).ToArray();
                    foreach (var field in fields)
                        bulkInserter.AddColumnMapping(field.Name, field.Name);

                    bulkInserter.Write(uniquesReader);
                }
            }
        }