Exemple #1
0
        private Item1 Obtain(string name, int structureType, DataType keyDataType, DataType recordDataType, Type keyType, Type recordType)
        {
            Debug.Assert(keyDataType != null);
            Debug.Assert(recordDataType != null);

            Item1 item;

            if (!map.TryGetValue(name, out item))
            {
                if (keyType == null)
                {
                    keyType = DataTypeUtils.BuildType(keyDataType);
                }
                if (recordType == null)
                {
                    recordType = DataTypeUtils.BuildType(recordDataType);
                }

                var    locator = CreateLocator(name, structureType, keyDataType, recordDataType, keyType, recordType);
                XTable table   = new XTable(this, locator);

                map[name] = item = new Item1(locator, table);
            }
            else
            {
                var locator = item.Locator;

                if (locator.StructureType != structureType)
                {
                    throw new ArgumentException(String.Format("Invalid structure type for '{0}'", name));
                }

                if (keyDataType != locator.KeyDataType)
                {
                    throw new ArgumentException("keyDataType");
                }

                if (recordDataType != locator.RecordDataType)
                {
                    throw new ArgumentException("recordDataType");
                }

                if (locator.KeyType == null)
                {
                    locator.KeyType = DataTypeUtils.BuildType(keyDataType);
                }
                else
                {
                    if (keyType != null && keyType != locator.KeyType)
                    {
                        throw new ArgumentException(String.Format("Invalid keyType for table '{0}'", name));
                    }
                }

                if (locator.RecordType == null)
                {
                    locator.RecordType = DataTypeUtils.BuildType(recordDataType);
                }
                else
                {
                    if (recordType != null && recordType != locator.RecordType)
                    {
                        throw new ArgumentException(String.Format("Invalid recordType for table '{0}'", name));
                    }
                }

                locator.AccessTime = DateTime.Now;
            }

            if (!item.Locator.IsReady)
            {
                item.Locator.Prepare();
            }

            if (item.Table == null)
            {
                item.Table = new XTable(this, item.Locator);
            }

            return(item);
        }
Exemple #2
0
 public Item1(Locator locator, XTable table)
 {
     Locator = locator;
     Table   = table;
 }