public void First_WhenCalled_MovesToFirstCell()
        {
            _iterator.Next();
            _iterator.Next();
            _iterator.First();

            Assert.AreEqual(1, _iterator.GetCurrent().Value);
        }
Пример #2
0
        public IIdentifierGenerator CreateIdentifierGenerator(Dialect.Dialect dialect, string defaultCatalog,
                                                              string defaultSchema, RootClass rootClass)
        {
            var @params = new Dictionary <string, string>();

            //if the hibernate-mapping did not specify a schema/catalog, use the defaults
            //specified by properties - but note that if the schema/catalog were specified
            //in hibernate-mapping, or as params, they will already be initialized and
            //will override the values set here (they are in identifierGeneratorProperties)
            if (!string.IsNullOrEmpty(defaultSchema))
            {
                @params[PersistentIdGeneratorParmsNames.Schema] = defaultSchema;
            }
            if (!string.IsNullOrEmpty(defaultCatalog))
            {
                @params[PersistentIdGeneratorParmsNames.Catalog] = defaultCatalog;
            }

            //pass the entity-name, if not a collection-id
            if (rootClass != null)
            {
                @params[IdGeneratorParmsNames.EntityName] = rootClass.EntityName;
            }

            //init the table here instead of earlier, so that we can get a quoted table name
            //TODO: would it be better to simply pass the qualified table name, instead of
            //      splitting it up into schema/catalog/table names
            string tableName = Table.GetQuotedName(dialect);

            @params[PersistentIdGeneratorParmsNames.Table] = tableName;

            //pass the column name (a generated id almost always has a single column and is not a formula)
            string columnName = ((Column)ColumnIterator.First()).GetQuotedName(dialect);

            @params[PersistentIdGeneratorParmsNames.PK] = columnName;

            if (rootClass != null)
            {
                StringBuilder tables      = new StringBuilder();
                bool          commaNeeded = false;
                foreach (Table identityTable in rootClass.IdentityTables)
                {
                    if (commaNeeded)
                    {
                        tables.Append(StringHelper.CommaSpace);
                    }
                    commaNeeded = true;
                    tables.Append(identityTable.GetQuotedName(dialect));
                }
                @params[PersistentIdGeneratorParmsNames.Tables] = tables.ToString();
            }
            else
            {
                @params[PersistentIdGeneratorParmsNames.Tables] = tableName;
            }

            if (identifierGeneratorProperties != null)
            {
                ArrayHelper.AddAll(@params, identifierGeneratorProperties);
            }

            return(IdentifierGeneratorFactory.Create(identifierGeneratorStrategy, Type, @params, dialect));
        }