Ejemplo n.º 1
0
        public void BindGenerator(SimpleValue id, HbmGenerator generatorMapping)
        {
            if (generatorMapping != null)
            {
                if (generatorMapping.@class == null)
                {
                    throw new MappingException("no class given for generator");
                }

                // NH Differen behavior : specific feature NH-1817
                TypeDef typeDef = mappings.GetTypeDef(generatorMapping.@class);
                if (typeDef != null)
                {
                    id.IdentifierGeneratorStrategy = typeDef.TypeClass;
                    // parameters on the property mapping should override parameters in the typedef
                    var allParameters = new Dictionary <string, string>(typeDef.Parameters);
                    ArrayHelper.AddAll(allParameters, GetGeneratorProperties(generatorMapping, id.Table.Schema));

                    id.IdentifierGeneratorProperties = allParameters;
                }
                else
                {
                    id.IdentifierGeneratorStrategy   = generatorMapping.@class;
                    id.IdentifierGeneratorProperties = GetGeneratorProperties(generatorMapping, id.Table.Schema);
                }
            }
        }
Ejemplo n.º 2
0
        private IDictionary <string, string> GetGeneratorProperties(HbmGenerator generatorMapping, string schema)
        {
            var results = new Dictionary <string, string>();

            // By default, any tables for the id generator will be in the same schema as
            // the owning entity table. If this isn't specified, grab it from the root
            // mappings element instead. It can also be overriden with a parameter in the
            // <generator> clause itself.

            if (schema != null)
            {
                results[Id.PersistentIdGeneratorParmsNames.Schema] = schema;
            }
            else if (mappings.SchemaName != null)
            {
                results[Id.PersistentIdGeneratorParmsNames.Schema] = mappings.SchemaName;
            }

            if (mappings.PreferPooledValuesLo != null)
            {
                results[Environment.PreferPooledValuesLo] = mappings.PreferPooledValuesLo;
            }

            foreach (HbmParam paramSchema in generatorMapping.param ?? System.Array.Empty <HbmParam>())
            {
                results[paramSchema.name] = paramSchema.GetText();
            }

            return(results);
        }
Ejemplo n.º 3
0
        private void ApplyGenerator(IGeneratorDef generator)
        {
            var hbmGenerator = new HbmGenerator {
                @class = generator.Class
            };

            if (hbmId.name == null)
            {
                // no member for the id
                var defaultReturnType = generator.DefaultReturnType;
                // where a DefaultReturnType is not available, let NH discover it during the mapping-binding process
                if (defaultReturnType != null)
                {
                    hbmId.type1 = defaultReturnType.GetNhTypeName();
                }
            }
            object generatorParameters = generator.Params;

            if (generatorParameters != null)
            {
                hbmGenerator.param = (from pi in generatorParameters.GetType().GetProperties()
                                      let pname = pi.Name
                                                  let pvalue = pi.GetValue(generatorParameters, null)
                                                               select
                                                               new HbmParam {
                    name = pname, Text = new[] { ReferenceEquals(pvalue, null) ? "null" : pvalue.ToString() }
                }).
                                     ToArray();
            }
            else
            {
                hbmGenerator.param = null;
            }
            hbmId.generator = hbmGenerator;
        }
Ejemplo n.º 4
0
        private IDictionary <string, string> GetGeneratorProperties(HbmGenerator generatorMapping, string schema)
        {
            var results = new Dictionary <string, string>();

            if (schema != null)
            {
                results[Id.PersistentIdGeneratorParmsNames.Schema] = schema;
            }
            if (mappings.SchemaName != null)
            {
                results[Id.PersistentIdGeneratorParmsNames.Schema] = mappings.Dialect.QuoteForSchemaName(mappings.SchemaName);
            }

            if (mappings.PreferPooledValuesLo != null)
            {
                results[Environment.PreferPooledValuesLo] = mappings.PreferPooledValuesLo;
            }

            foreach (HbmParam paramSchema in generatorMapping.param ?? new HbmParam[0])
            {
                results[paramSchema.name] = paramSchema.GetText();
            }

            return(results);
        }
Ejemplo n.º 5
0
        private void ApplyGenerator(IGeneratorDef generator)
        {
            var hbmGenerator = new HbmGenerator {
                @class = generator.Class
            };

            if (hbmId.name == null)
            {
                // no member for the id
                hbmId.type1 = generator.DefaultReturnType.GetNhTypeName();
            }
            object generatorParameters = generator.Params;

            if (generatorParameters != null)
            {
                hbmGenerator.param = (from pi in generatorParameters.GetType().GetProperties()
                                      let pname = pi.Name
                                                  let pvalue = pi.GetValue(generatorParameters, null)
                                                               select
                                                               new HbmParam {
                    name = pname, Text = new[] { ReferenceEquals(pvalue, null) ? "null" : pvalue.ToString() }
                }).
                                     ToArray();
            }
            else
            {
                hbmGenerator.param = null;
            }
            hbmId.generator = hbmGenerator;
        }
Ejemplo n.º 6
0
        private void ApplyGenerator(IGeneratorDef generator)
        {
            var hbmGenerator = new HbmGenerator {
                @class = generator.Class
            };
            object generatorParameters = generator.Params;

            if (generatorParameters != null)
            {
                hbmGenerator.param = (from pi in generatorParameters.GetType().GetProperties()
                                      let pname = pi.Name
                                                  let pvalue = pi.GetValue(generatorParameters, null)
                                                               select
                                                               new HbmParam {
                    name = pname, Text = new[] { ReferenceEquals(pvalue, null) ? "null" : pvalue.ToString() }
                }).
                                     ToArray();
            }
            else
            {
                hbmGenerator.param = null;
            }
            hbmId.generator = hbmGenerator;
            AutosetTypeThroughGeneratorDef(generator);
        }
Ejemplo n.º 7
0
        public void Add(MappedPropertyInfo info)
        {
            if (info.Type != PropertyMappingType.Id)
            {
                return;
            }

            HbmId        id        = info.HbmObject <HbmId>();
            HbmGenerator generator = id.generator;

            if (generator != null)
            {
                switch (generator.@class)
                {
                case "sequence":
                {
                    HbmParam[] parameters = generator.param;
                    string[]   text       = parameters[0].Text;
                    _builder.AddLine(string.Format(".{0}.{1}(\"{2}\")", FluentNHibernateNames.GeneratedBy, FluentNHibernateNames.Sequence, text[0]));
                    break;
                }

                case "assigned":
                    _builder.AddLine(string.Format(".{0}.{1}()", FluentNHibernateNames.GeneratedBy, FluentNHibernateNames.Assigned));
                    break;

                case "guid.comb":
                    _builder.AddLine(string.Format(".{0}.{1}()", FluentNHibernateNames.GeneratedBy, FluentNHibernateNames.GuidComb));
                    break;

                case "guid":
                    _builder.AddLine(string.Format(".{0}.{1}()", FluentNHibernateNames.GeneratedBy, FluentNHibernateNames.Guid));
                    break;

                case "native":
                    _builder.AddLine(string.Format(".{0}.{1}()", FluentNHibernateNames.GeneratedBy, FluentNHibernateNames.Native));
                    break;

                case "identity":
                    _builder.AddLine(string.Format(".{0}.{1}()", FluentNHibernateNames.GeneratedBy, FluentNHibernateNames.Identity));
                    break;

                default:
                    _builder.AddLine(string.Format(".{0}.{1} ?", FluentNHibernateNames.GeneratedBy, generator.@class));
                    break;
                }
            }
        }
Ejemplo n.º 8
0
        private IDictionary <string, string> GetGeneratorProperties(HbmGenerator generatorMapping, string schema)
        {
            var results = new Dictionary <string, string>();

            if (schema != null)
            {
                results.Add(Id.PersistentIdGeneratorParmsNames.Schema, schema);
            }
            else if (mappings.SchemaName != null)
            {
                results.Add(Id.PersistentIdGeneratorParmsNames.Schema, mappings.Dialect.QuoteForSchemaName(mappings.SchemaName));
            }

            foreach (HbmParam paramSchema in generatorMapping.param ?? new HbmParam[0])
            {
                results.Add(paramSchema.name, paramSchema.GetText());
            }

            return(results);
        }
Ejemplo n.º 9
0
 public GeneratorMapper(HbmGenerator generator)
 {
     _generator = generator;
 }
Ejemplo n.º 10
0
 public GeneratorMapper(HbmGenerator generator)
 {
     this.generator = generator;
 }