コード例 #1
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;
		}
コード例 #2
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);
				}
			}
		}
コード例 #3
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;
		}
コード例 #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;
		}
コード例 #5
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);
		}
コード例 #6
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 ?? new HbmParam[0])
				results[paramSchema.name] = paramSchema.GetText();

			return results;
		}
コード例 #7
0
ファイル: IdMapper.cs プロジェクト: pontillo/PowerNap
		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;
		}
コード例 #8
0
 public GeneratorMapper(HbmGenerator generator)
 {
     this.generator = generator;
 }