Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Orm/Xtensive.Orm/Orm/Model/TypeIdRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ public void Register(int typeId, TypeInfo type)
EnsureNotLocked();

if (mapping is null) {
if (typeId <= UInt16.MaxValue && type.SharedId <= UInt16.MaxValue) {
if ((uint)typeId <= UInt16.MaxValue && type.SharedId <= UInt16.MaxValue) {
sharedIdToTypeId ??= new UInt16[1];
typeIdToSharedId ??= new UInt16[1];
Array.Resize(ref sharedIdToTypeId, Math.Max(type.SharedId + 1, Math.Max(sharedIdToTypeInfo.Count, sharedIdToTypeId.Length)));
Array.Resize(ref sharedIdToTypeId, Math.Max(type.SharedId + 10, Math.Max(sharedIdToTypeInfo.Count, sharedIdToTypeId.Length)));
sharedIdToTypeId[type.SharedId] = (UInt16)typeId;
Array.Resize(ref typeIdToSharedId, Math.Max(typeIdToSharedId.Length, typeId + 1));
Array.Resize(ref typeIdToSharedId, Math.Max(typeIdToSharedId.Length, typeId + 10));
typeIdToSharedId[typeId] = (UInt16) type.SharedId;
return;
}
Expand Down
57 changes: 16 additions & 41 deletions Orm/Xtensive.Orm/Orm/Providers/ModelMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Created by: Dmitri Maximov
// Created: 2008.09.23

using System;
using System.Collections.Generic;
using System.Linq;
using Xtensive.Core;
Expand All @@ -18,67 +19,49 @@ namespace Xtensive.Orm.Providers
/// </summary>
public sealed class ModelMapping : LockableBase
{
private readonly Dictionary<TypeInfo, Table> tableMap = new Dictionary<TypeInfo, Table>();
private readonly Dictionary<SequenceInfo, SchemaNode> sequenceMap = new Dictionary<SequenceInfo, SchemaNode>();
private Table[] tableMap = new Table[1]; // Indexed by TypeInfo.SharedId
private readonly Dictionary<SequenceInfo, SchemaNode> sequenceMap = new();

private string temporaryTableDatabase;
private string temporaryTableSchema;
private string temporaryTableCollation;

public string TemporaryTableDatabase
{
get { return temporaryTableDatabase; }
set
{
get => temporaryTableDatabase;
set {
EnsureNotLocked();
temporaryTableDatabase = value;
}
}

public string TemporaryTableSchema
{
get { return temporaryTableSchema; }
set
{
get => temporaryTableSchema;
set {
EnsureNotLocked();
temporaryTableSchema = value;
}
}

public string TemporaryTableCollation
{
get { return temporaryTableCollation; }
set
{
get => temporaryTableCollation;
set {
EnsureNotLocked();
temporaryTableCollation = value;
}
}

public Table this[TypeInfo typeInfo]
{
get
{
Table result;
tableMap.TryGetValue(typeInfo, out result);
return result;
}
}
public Table this[TypeInfo typeInfo] => typeInfo.SharedId < tableMap.Length ? tableMap[typeInfo.SharedId] : null;

public SchemaNode this[SequenceInfo sequenceInfo]
{
get
{
SchemaNode result;
sequenceMap.TryGetValue(sequenceInfo, out result);
return result;
}
}
public SchemaNode this[SequenceInfo sequenceInfo] => sequenceMap.GetValueOrDefault(sequenceInfo);

public void Register(TypeInfo typeInfo, Table table)
{
EnsureNotLocked();
tableMap[typeInfo] = table;
Array.Resize(ref tableMap, Math.Max(tableMap.Length, typeInfo.SharedId + 10));
tableMap[typeInfo.SharedId] = table;
}

public void Register(SequenceInfo sequenceInfo, SchemaNode sequence)
Expand All @@ -87,15 +70,7 @@ public void Register(SequenceInfo sequenceInfo, SchemaNode sequence)
sequenceMap[sequenceInfo] = sequence;
}

internal IList<SchemaNode> GetAllSchemaNodes()
{
return tableMap.Values.Union(sequenceMap.Values).ToList();
}

// Constructors

internal ModelMapping()
{
}
internal IEnumerable<SchemaNode> GetAllSchemaNodes() =>
tableMap.Where(static o => o != null).Union(sequenceMap.Values);
}
}
}