Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dialect"></param>
        /// <returns></returns>
        public IIdentifierGenerator CreateIdentifierGenerator(Dialect.Dialect dialect)
        {
            if (uniqueIdentifierGenerator == null)
            {
                uniqueIdentifierGenerator = IdentifierGeneratorFactory.Create(identifierGeneratorStrategy, type, identifierGeneratorProperties, dialect);
            }

            return(uniqueIdentifierGenerator);
        }
 public void NonCreatableStrategy()
 {
     Assert.Throws <IdentifierGenerationException>(() => IdentifierGeneratorFactory.Create("Guid", NHibernateUtil.Guid, null, new MsSql2000Dialect()),
                                                   "Could not interpret id generator strategy: Guid");
 }
Пример #3
0
        public IIdentifierGenerator CreateIdentifierGenerator(Dialect.Dialect dialect, string defaultCatalog,
                                                              string defaultSchema, RootClass rootClass)
        {
            Dictionary <string, string> @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)
            IEnumerator enu = ColumnIterator.GetEnumerator();

            enu.MoveNext();
            string columnName = ((Column)enu.Current).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));
        }