public ActiveRecordDescriptor Build(TableDefinition tableDef, BuildContext context)
		{
			ActiveRecordDescriptor desc = ObtainDescriptor(tableDef);

			// ClassName

			desc.ClassName = _namingService.CreateClassName( tableDef.Name );

			// Plain fields

			desc.Properties.AddRange( _plainFieldsService.InferProperties(tableDef) );

			// Relations

			desc.PropertiesRelations.AddRange( _relationsService.InferRelations(desc, tableDef, context) );

			// Operations

			// TODO!

			context.RemovePendent(desc);

			Build(context);

			return desc;
		}
		public ActiveRecordDescriptor[] Build(BuildContext context)
		{
			while(context.HasPendents)
			{
				ActiveRecordDescriptor pendent = context.GetNextPendent();
				Build(pendent.Table, context);
			}
			
			ActiveRecordDescriptor[] array = new ActiveRecordDescriptor[context.NewlyCreatedDescriptors.Count];
			context.NewlyCreatedDescriptors.CopyTo(array, 0);
			return array;
		}
Пример #3
0
		public ActiveRecordPropertyRelationDescriptor[] InferRelations(ActiveRecordDescriptor desc, 
			TableDefinition tableDef, BuildContext context)
		{
			if (desc == null) throw new ArgumentNullException("desc");
			if (tableDef == null) throw new ArgumentNullException("tableDef");
			if (context == null) throw new ArgumentNullException("context");
//			if (tableDef.RelatedDescriptor != null && tableDef.RelatedDescriptor != desc) {
//				throw new ArgumentException("Different descriptors");
//			}

			ArrayList list = new ArrayList();

			CreateHasManyRelations(desc, tableDef, list, context);

			CreateBelongsToRelations(desc, tableDef, list, context);

			return (ActiveRecordPropertyRelationDescriptor[]) list.ToArray( typeof(ActiveRecordPropertyRelationDescriptor) );
		}
Пример #4
0
		private void CreateBelongsToRelations(ActiveRecordDescriptor desc, TableDefinition tableDef, 
			IList list, BuildContext context)
		{
			foreach(ColumnDefinition col in tableDef.Columns)
			{
				if (col.RelatedTable != null)
				{
					bool pendentNecessary = false;
					String propertyName = _namingService.CreateClassName(col.RelatedTable.Name);

					ActiveRecordDescriptor targetType = null;

					if (col.RelatedTable.RelatedDescriptor == null && col.RelatedTable != tableDef)
					{
						col.RelatedTable.RelatedDescriptor = new ActiveRecordDescriptor(col.RelatedTable);

						pendentNecessary = true;
					}
					else if (col.RelatedTable == tableDef)
					{
						targetType = desc;
					}

					if (targetType == null)
					{
						targetType = col.RelatedTable.RelatedDescriptor;
					}

					ActiveRecordBelongsToDescriptor belongsTo = 
						new ActiveRecordBelongsToDescriptor(col.Name, 
							propertyName, targetType);

					list.Add(belongsTo);

					if (pendentNecessary)
					{
						context.AddPendentDescriptor(belongsTo, col.RelatedTable.RelatedDescriptor);
					}
				}
			}
		}
Пример #5
0
		public override void Deactivated(System.Collections.IDictionary context)
		{
			context["selectedtable"] = listBox1.SelectedItem;
			context["buildcontext"] = new BuildContext();

			ActiveRecordDescriptor ar = context["ardesc"] as ActiveRecordDescriptor;
			ar.Table = listBox1.SelectedItem as TableDefinition;
		}
Пример #6
0
		private void CreateHasManyRelations(ActiveRecordDescriptor desc, TableDefinition tableDef, 
			IList list, BuildContext context)
		{
			foreach(TableDefinition fkTable in tableDef.TablesReferencedByHasRelation)
			{
				String propertyName = _namingService.CreateRelationName(fkTable.Name);
				ActiveRecordDescriptor targetType = null;
				String colName = null;
				bool pendentNecessary = false;
				ColumnDefinition selectedCol = null;

				foreach(ColumnDefinition col in fkTable.Columns)
				{
					if (col.RelatedTable == tableDef)
					{
						colName = col.Name;

						if (col.RelatedTable.RelatedDescriptor == null && col.RelatedTable != fkTable)
						{
							col.RelatedTable.RelatedDescriptor = new ActiveRecordDescriptor(fkTable);

							pendentNecessary = true;
						}
						else if (col.RelatedTable == tableDef)
						{
							targetType = desc;
						}
						
						if (targetType == null)
						{
							targetType = col.RelatedTable.RelatedDescriptor;
						}

						selectedCol = col;

						break;
					}
				}

				// Just to protect ourselves from awkward conditions
				if (colName == null) continue;

				ActiveRecordHasManyDescriptor hasMany = 
					new ActiveRecordHasManyDescriptor(colName, propertyName, targetType);

				if (pendentNecessary)
				{
					context.AddPendentDescriptor(hasMany, selectedCol.RelatedTable.RelatedDescriptor);
				}
				
				list.Add(hasMany);
			}
		}