コード例 #1
0
		/// <summary>
		/// Dispatches the call to the extensions.
		/// </summary>
		/// <param name="pi">The property info reflection object.</param>
		/// <param name="hasManyModel">The has many model.</param>
		/// <param name="model">The model.</param>
		public void ProcessHasManyToAny(PropertyInfo pi, HasManyToAnyModel hasManyModel, ActiveRecordModel model)
		{
			foreach(IModelBuilderExtension extension in extensions)
			{
				extension.ProcessHasManyToAny(pi, hasManyModel, model);
			}
		}
コード例 #2
0
		private static void ProcessProperties(Type type, ActiveRecordModel model)
		{
			// Check persistent properties of the base class as well
			if (ShouldCheckBase(type))
			{
				ProcessProperties(type.BaseType, model);
			}

			PropertyInfo[] props = type.GetProperties(DefaultBindingFlags);

			foreach (PropertyInfo prop in props)
			{
				bool isArProperty = false;
				AnyModel anyModel;
				HasManyToAnyModel hasManyToAnyModel;

				object[] valAtts = prop.GetCustomAttributes(typeof(AbstractValidationAttribute), true);

				foreach (AbstractValidationAttribute valAtt in valAtts)
				{
					IValidator validator = valAtt.Build();
					validator.Initialize(validatorRegistry, prop);

					model.Validators.Add(validator);
				}

				foreach (object attribute in prop.GetCustomAttributes(false))
				{
					if (attribute is PrimaryKeyAttribute)
					{
						PrimaryKeyAttribute propAtt = attribute as PrimaryKeyAttribute;
						isArProperty = true;

						// Joined Subclasses must not have PrimaryKey
						if (type.IsDefined(typeof(JoinedBaseAttribute), true) && // JoinedBase in a superclass
							!type.IsDefined(typeof(JoinedBaseAttribute), false)) // but not here
						{
							throw new ActiveRecordException("You can't specify a PrimaryKeyAttribute in a joined subclass. " +
															"Check type " + model.Type.FullName);
						}

						if (prop.PropertyType.IsDefined(typeof(CompositeKeyAttribute), true))
						{
							object[] att = prop.PropertyType.GetCustomAttributes(typeof(CompositeKeyAttribute), true);

							CompositeKeyAttribute cAtt = att[0] as CompositeKeyAttribute;

							model.CompositeKey = new CompositeKeyModel(prop, cAtt);
						}
						else
						{
							model.PrimaryKey = new PrimaryKeyModel(prop, propAtt);
						}
					}
					else if (attribute is CompositeKeyAttribute)
					{
						CompositeKeyAttribute propAtt = attribute as CompositeKeyAttribute;
						isArProperty = true;

						model.CompositeKey = new CompositeKeyModel(prop, propAtt);
					}
					else if (attribute is AnyAttribute)
					{
						AnyAttribute anyAtt = attribute as AnyAttribute;
						isArProperty = true;
						anyModel = new AnyModel(prop, anyAtt);
						model.Anys.Add(anyModel);

						CollectMetaValues(anyModel.MetaValues, prop);
					}
					else if (attribute is PropertyAttribute)
					{
						PropertyAttribute propAtt = attribute as PropertyAttribute;
						isArProperty = true;

						model.Properties.Add(new PropertyModel(prop, propAtt));
					}
					else if (attribute is NestedAttribute)
					{
						NestedAttribute propAtt = attribute as NestedAttribute;
						isArProperty = true;

						ActiveRecordModel nestedModel = new ActiveRecordModel(prop.PropertyType);

						nestedModel.IsNestedType = true;

						Type nestedType = propAtt.MapType != null ? propAtt.MapType : prop.PropertyType;
						nestedModel.IsNestedCompositeType = model.IsNestedCompositeType;
						ProcessProperties(nestedType, nestedModel);
						ProcessFields(nestedType, nestedModel);

						model.Components.Add(new NestedModel(prop, propAtt, nestedModel));
					}
					else if (attribute is NestedParentReferenceAttribute)
					{
						NestedParentReferenceAttribute nestedParentAtt = attribute as NestedParentReferenceAttribute;
						isArProperty = true;

						model.ComponentParent.Add(new NestedParentReferenceModel(prop, nestedParentAtt));
					}
					else if (attribute is JoinedKeyAttribute)
					{
						JoinedKeyAttribute propAtt = attribute as JoinedKeyAttribute;
						isArProperty = true;

						if (model.Key != null)
						{
							throw new ActiveRecordException("You can't specify more than one JoinedKeyAttribute. " +
															"Check type " + model.Type.FullName);
						}

						model.Key = new KeyModel(prop, propAtt);
					}
					else if (attribute is VersionAttribute)
					{
						VersionAttribute propAtt = attribute as VersionAttribute;
						isArProperty = true;

						if (model.Version != null)
						{
							throw new ActiveRecordException("You can't specify more than one VersionAttribute. " +
															"Check type " + model.Type.FullName);
						}

						model.Version = new VersionModel(prop, propAtt);
					}
					else if (attribute is TimestampAttribute)
					{
						TimestampAttribute propAtt = attribute as TimestampAttribute;
						isArProperty = true;

						if (model.Timestamp != null)
						{
							throw new ActiveRecordException("You can't specify more than one TimestampAttribute. " +
															"Check type " + model.Type.FullName);
						}

						model.Timestamp = new TimestampModel(prop, propAtt);
					}
					// Relations
					else if (attribute is OneToOneAttribute)
					{
						OneToOneAttribute propAtt = attribute as OneToOneAttribute;
						isArProperty = true;

						model.OneToOnes.Add(new OneToOneModel(prop, propAtt));
					}
					else if (attribute is BelongsToAttribute)
					{
						BelongsToAttribute propAtt = attribute as BelongsToAttribute;
						isArProperty = true;

						model.BelongsTo.Add(new BelongsToModel(prop, propAtt));
					}
					// The ordering is important here, HasManyToAny must comes before HasMany!
					else if (attribute is HasManyToAnyAttribute)
					{
						HasManyToAnyAttribute propAtt = attribute as HasManyToAnyAttribute;
						isArProperty = true;

						hasManyToAnyModel = new HasManyToAnyModel(prop, propAtt);
						model.HasManyToAny.Add(hasManyToAnyModel);

						CollectMetaValues(hasManyToAnyModel.MetaValues, prop);
					}
					else if (attribute is HasManyAttribute)
					{
						HasManyAttribute propAtt = attribute as HasManyAttribute;
						isArProperty = true;

						HasManyModel hasManyModel = new HasManyModel(prop, propAtt);
						if (propAtt.DependentObjects)
						{
							ActiveRecordModel dependentObjectModel = new ActiveRecordModel(propAtt.MapType);
							dependentObjectModel.IsNestedType = true;
							dependentObjectModel.IsNestedCompositeType = true;
							ProcessProperties(propAtt.MapType, dependentObjectModel);

							hasManyModel.DependentObjectModel = new DependentObjectModel(prop, propAtt, dependentObjectModel);
						}
						model.HasMany.Add(hasManyModel);
					}
					else if (attribute is HasAndBelongsToManyAttribute)
					{
						HasAndBelongsToManyAttribute propAtt = attribute as HasAndBelongsToManyAttribute;
						isArProperty = true;

						model.HasAndBelongsToMany.Add(new HasAndBelongsToManyModel(prop, propAtt));
					}
					else if (attribute is Any.MetaValueAttribute)
					{
						if (prop.GetCustomAttributes(typeof(HasManyToAnyAttribute), false).Length == 0 &&
							prop.GetCustomAttributes(typeof(AnyAttribute), false).Length == 0
							)
							throw new ActiveRecordException(
								"You can't specify an Any.MetaValue without specifying the Any or HasManyToAny attribute. " +
								"Check type " + prop.DeclaringType.FullName);
					}
					else if (attribute is CompositeUserTypeAttribute)
					{
						CompositeUserTypeAttribute propAtt = attribute as CompositeUserTypeAttribute;
						isArProperty = true;

						model.CompositeUserType.Add(new CompositeUserTypeModel(prop, propAtt));
					}

					if (attribute is CollectionIDAttribute)
					{
						CollectionIDAttribute propAtt = attribute as CollectionIDAttribute;

						model.CollectionIDs.Add(new CollectionIDModel(prop, propAtt));
					}
					if (attribute is HiloAttribute)
					{
						HiloAttribute propAtt = attribute as HiloAttribute;

						model.Hilos.Add(new HiloModel(prop, propAtt));
					}
				}

				if (!isArProperty)
				{
					model.NotMappedProperties.Add(prop);
				}
			}
		}
コード例 #3
0
		/// <summary>
		/// Visits the has many to any config.
		/// </summary>
		/// <param name="model">The model.</param>
		public override void VisitHasManyToAnyConfig(HasManyToAnyModel.Config model)
		{
			HasManyToAnyAttribute att = model.Parent.HasManyToAnyAtt;
			AppendF("<many-to-any{0}{1}>",
			        MakeCustomTypeAtt("id-type", att.IdType),
			        MakeCustomTypeAttIfNotNull("meta-type", att.MetaType));
			Ident();

			// This is here so the XmlGenerationVisitor will always
			// output the meta-values in consistent order, to aid the tests,
			// MetaValueAttribute implements IComparable
			List<Any.MetaValueAttribute> sortedMetaValues = new List<Any.MetaValueAttribute>(model.Parent.MetaValues);
			sortedMetaValues.Sort();
			foreach(Any.MetaValueAttribute meta in sortedMetaValues)
			{
				AppendF("<meta-value{0}{1} />",
				        MakeAtt("value", meta.Value),
				        MakeCustomTypeAtt("class", meta.Class)
					);
			}

			AppendF("<column{0} />",
			        MakeAtt("name", att.TypeColumn));
			AppendF("<column{0} />",
			        MakeAtt("name", att.IdColumn));
			Dedent();
			AppendF("</many-to-any>");
		}
コード例 #4
0
		/// <summary>
		/// Visit the has many to any
		/// </summary>
		/// <param name="model">The model.</param>
		public override void VisitHasManyToAny(HasManyToAnyModel model)
		{
			if (model.HasManyToAnyAtt.MapType == null)
				model.HasManyToAnyAtt.MapType = GuessType(null, model.Property.PropertyType);

			model.HasManyToAnyAtt.RelationType = GuessRelation(model.Property, model.HasManyToAnyAtt.RelationType);

			if (model.HasManyToAnyAtt.RelationType == RelationType.List && model.HasManyToAnyAtt.Index == null)
			{
				throw new ActiveRecordException(String.Format(
													"A HasMany with type List requires that you specify an 'Index', use the Index property {0}.{1}  ",
													model.Property.DeclaringType.Name, model.Property.Name));
			}


			base.VisitHasManyToAny(model);
		}
コード例 #5
0
		/// <summary>
		/// Visits the has many to any.
		/// </summary>
		/// <param name="model">The model.</param>
		public override void VisitHasManyToAny(HasManyToAnyModel model)
		{
			HasManyToAnyAttribute att = model.HasManyToAnyAtt;

			Type mapType = GuessType(att.MapType, model.Property.PropertyType);
			WriteCollection(att.Cascade, mapType, att.RelationType, model.Property.Name,
			                model.HasManyToAnyAtt.AccessString, att.Table, att.Schema, att.Lazy, att.Inverse, att.OrderBy,
			                att.Where, att.Sort, att.ColumnKey, null, null, null, null, null, model.Configuration, att.Index,
			                att.IndexType,
							att.Cache, att.CacheRegion, att.NotFoundBehaviour, att.Fetch, att.BatchSize, att.CollectionType);
		}
コード例 #6
0
 /// <summary>
 /// Visits the has many to any config.
 /// </summary>
 /// <param name="hasManyToAnyConfigModel">The has many to any config model.</param>
 public virtual void VisitHasManyToAnyConfig(HasManyToAnyModel.Config hasManyToAnyConfigModel)
 {
 }
コード例 #7
0
 /// <summary>
 /// Visits the has many to any.
 /// </summary>
 /// <param name="model">The model.</param>
 public virtual void VisitHasManyToAny(HasManyToAnyModel model)
 {
 }
コード例 #8
0
			/// <summary>
			/// Initializes a new instance of the <see cref="Config"/> class.
			/// </summary>
			/// <param name="parent">The parent.</param>
			internal Config(HasManyToAnyModel parent)
			{
				this.parent = parent;
			}
コード例 #9
0
		/// <summary>
		/// Visit the has many to any
		/// </summary>
		/// <param name="model">The model.</param>
		public override void VisitHasManyToAny(HasManyToAnyModel model)
		{
			if (model.HasManyToAnyAtt.MapType == null)
				model.HasManyToAnyAtt.MapType = GuessType(null, model.Property.PropertyType);

			model.HasManyToAnyAtt.RelationType = GuessRelation(model.Property, model.HasManyToAnyAtt.RelationType);

			base.VisitHasManyToAny(model);
		}