Esempio n. 1
0
		private void AddToNewlyCreated(ActiveRecordDescriptor descriptor)
		{
			if (!_newlyCreated.Contains(descriptor))
			{
				_newlyCreated.Add(descriptor);
			}
		}
 public ActiveRecordPropertyRelationDescriptor(String columnName, String columnTypeName,
                                               String propertyName, String relationType, ActiveRecordDescriptor targetType) :
     base(columnName, columnTypeName, propertyName)
 {
     _relationType = relationType;
     _targetType   = targetType;
 }
Esempio n. 3
0
		public void AddPendentDescriptor(object key, ActiveRecordDescriptor descriptor)
		{
			if (!_key2Desc.Contains(key))
			{
				_key2Desc[key] = descriptor;
			}
		}
		public void PostBelongsToBlog()
		{
			InitKernel();
			IRelationshipInferenceService relService = ObtainService();

			TableDefinition blogTable;
			TableDefinition postTable;

			BuildBlogPostsStructure(out blogTable, out postTable);

			BuildContext context = new BuildContext();

			ActiveRecordDescriptor arDesc = new ActiveRecordDescriptor();

			ActiveRecordPropertyDescriptor[] descs = relService.InferRelations( arDesc, postTable, context );

			Assert.IsNotNull(descs);
			Assert.AreEqual( 1, descs.Length );

			ActiveRecordBelongsToDescriptor desc1 = descs[0] as ActiveRecordBelongsToDescriptor;
			Assert.IsNotNull(desc1);
			Assert.IsNotNull(desc1.TargetType);
			Assert.IsNull(desc1.PropertyType);

			Assert.AreEqual( "Blog", desc1.PropertyName );
			Assert.AreEqual( "blog_id", desc1.ColumnName );

			ActiveRecordDescriptor targetARDescriptor = context.GetNextPendent();
			Assert.AreSame( blogTable, targetARDescriptor.Table );
		}
Esempio n. 5
0
		public EditRelationDialog(ActiveRecordDescriptor descriptor, Project project, ActiveRecordPropertyRelationDescriptor prop) : base(descriptor, project)
		{
			// This call is required by the Windows Form Designer.
			InitializeComponent();

			AssociationEnum assoc = AssociationEnum.Undefined;

			if (prop is ActiveRecordHasManyDescriptor)
			{
				hasManyButton.Checked = true;
				assoc = AssociationEnum.HasMany;
			}
			else if (prop is ActiveRecordBelongsToDescriptor)
			{
				belongsToButton.Checked = true;
				assoc = AssociationEnum.BelongsTo;
			}
			else if (prop is ActiveRecordHasAndBelongsToManyDescriptor)
			{
				hasAndBelongsToManyButton.Checked = true;
				assoc = AssociationEnum.HasAndBelongsToMany;
			}

			SelectedTarget = prop.TargetType;

			SwitchViewTo(assoc);

		}
 public ActiveRecordHasAndBelongsToManyDescriptor(String columnName, String associationtable,
                                                  String propertyName, ActiveRecordDescriptor targetType, String columnKey) :
     base(columnName, String.Empty, propertyName, "HasAndBelongsToMany", targetType)
 {
     _associationtable = associationtable;
     _columnKey        = columnKey;
     _propertyType     = typeof(IList);
 }
Esempio n. 7
0
		public RelationshipInfo(AssociationEnum association, ActiveRecordDescriptor descriptor, ActiveRecordDescriptor targetDescriptor)
		{
			if (association == AssociationEnum.Undefined) throw new ArgumentException("association");
			if (descriptor == null) throw new ArgumentNullException("descriptor");
			if (targetDescriptor == null) throw new ArgumentNullException("targetDescriptor");

			this.association = association;
			this.descriptor = descriptor;
			this.targetDescriptor = targetDescriptor;
		}
		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;
		}
Esempio n. 9
0
		public void RemovePendent(ActiveRecordDescriptor descriptor)
		{
			foreach(DictionaryEntry entry in _key2Desc)
			{
				if (entry.Value == descriptor)
				{
					_key2Desc.Remove(entry.Key);
					break;
				}
			}

			AddToNewlyCreated(descriptor);
		}
Esempio n. 10
0
		private void AddProperties(ActiveRecordDescriptor arDescriptor, CodeTypeDeclaration declaration)
		{
			foreach(ActiveRecordPropertyDescriptor property in arDescriptor.Properties)
			{
				if (!property.Generate) continue;

				CodeMemberProperty memberProperty = CreatePropertyMember(property, declaration);

				AddAppropriateAttribute(memberProperty, property);

				declaration.Members.Add( memberProperty );
			}
		}
Esempio n. 11
0
		public void Run(ActiveRecordDescriptor descriptor)
		{
			using(NewSubClassDialog dialog = new NewSubClassDialog())
			{
				if (dialog.ShowDialog(Workspace.ActiveWindow) == DialogResult.OK)
				{
					ActiveRecordDescriptorSubClass subclass = new ActiveRecordDescriptorSubClass(descriptor);
					subclass.Table = descriptor.Table;
					subclass.DiscriminatorValue = dialog.DiscriminatorValue;
					subclass.ClassName = dialog.ClassName;
					
					Model.CurrentProject.AddActiveRecordDescriptor(subclass);
					Model.Update();
				}
			}
		}
		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) );
		}
		public ActiveRecordPropertiesDialog(ActiveRecordDescriptor descriptor, Project project)
		{
			_project = project;
			_descriptor = descriptor;

			if (descriptor is ActiveRecordDescriptorSubClass)
			{
				_parent = ((ActiveRecordDescriptorSubClass) descriptor).BaseClass;
			}

			InitializeComponent();

			Title = descriptor.ClassName + " Properties";

			FillClassDetails(descriptor);
			FillClassProperties(descriptor);
			FillClassRelationships(descriptor);
		}
Esempio n. 14
0
		public AddRelationDialog(ActiveRecordDescriptor descriptor, Project project) : this()
		{
			_descriptor = descriptor;
			_project = project;

			_relationBuilder = (IRelationshipBuilder) ServiceRegistry.Instance[ typeof(IRelationshipBuilder) ];

			className.Text = _descriptor.ClassName;

			targetTableList.ValueMember = "ClassName";

			foreach(IActiveRecordDescriptor desc in _project.Descriptors)
			{
				if (desc is ActiveRecordBaseDescriptor) continue;
				if (desc.ClassName == null) continue;

				targetTableList.Items.Add( desc );
			}
		}
Esempio n. 15
0
		public NewARClassWizard(Model model) : base(model)
		{
//			if (shape.ActiveRecordDescriptor == null)
//			{
//				throw new ArgumentException("No AR instance in shape");
//			}

			_arDesc = new ActiveRecordDescriptor();
			Context["ardesc"] = _arDesc;

			InitializeComponent();

			Title = "New ActiveRecord class";

			AddPage(new WelcomePage());
			AddPage(new TableSelectionPage());
			AddPage(new MappingPage());
			AddPage(new RelationsPage());
			AddPage(new ClassNamePage());
		}
		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);
					}
				}
			}
		}
		public void HasMany()
		{
			InitKernel();
			IRelationshipBuilder relService = ObtainService();

			TableDefinition blogTable;
			TableDefinition postTable;

			BuildBlogPostsStructure(out blogTable, out postTable);

			ActiveRecordDescriptor desc = new ActiveRecordDescriptor("Blog");
			ActiveRecordDescriptor targetDesc = new ActiveRecordDescriptor("Post");

			RelationshipInfo info = new RelationshipInfo( AssociationEnum.HasMany, desc, targetDesc );
			info.ChildCol = new ColumnDefinition("blog_id", false, true, true, false, OleDbType.Numeric);

			ActiveRecordPropertyRelationDescriptor propDesc = relService.Build( info );
			Assert.IsNotNull(propDesc);
			Assert.IsNotNull(propDesc as ActiveRecordHasManyDescriptor);
			Assert.AreEqual( "Posts", propDesc.PropertyName );
			Assert.AreEqual( targetDesc, propDesc.TargetType );
			Assert.AreEqual( "blog_id", propDesc.ColumnName );
		}
		public void CreateJoinedSubClass(ActiveRecordDescriptor descriptor)
		{
			createJoinedSub.Run(descriptor);
		}
Esempio n. 19
0
 public ActiveRecordDescriptorSubClass(ActiveRecordDescriptor baseClass)
 {
     _baseClass = baseClass;
 }
		public void HasÁndBelongsToMany()
		{
			InitKernel();
			IRelationshipBuilder relService = ObtainService();

			DatabaseDefinition dbdef = new DatabaseDefinition("alias");

			TableDefinition compTable = new TableDefinition("companies", dbdef );
			compTable.AddColumn( new ColumnDefinition("id", true, false, true, false, OleDbType.Integer) );
			compTable.AddColumn( new ColumnDefinition("name", false, false, false, false, OleDbType.VarChar) );

			TableDefinition peopleTable = new TableDefinition("people", dbdef );
			peopleTable.AddColumn( new ColumnDefinition("id", true, false, true, false, OleDbType.Integer) );
			peopleTable.AddColumn( new ColumnDefinition("name", false, false, false, false, OleDbType.VarChar) );

			TableDefinition assocTable = new TableDefinition("companiespeople", dbdef );
			assocTable.AddColumn( new ColumnDefinition("comp_id", true, true, true, false, OleDbType.Integer) );
			assocTable.AddColumn( new ColumnDefinition("person_id", true, true, false, false, OleDbType.Integer) );

			ActiveRecordDescriptor desc = new ActiveRecordDescriptor("Company");
			ActiveRecordDescriptor targetDesc = new ActiveRecordDescriptor("Person");

			RelationshipInfo info = new RelationshipInfo( AssociationEnum.HasAndBelongsToMany, desc, targetDesc );
			info.AssociationTable = assocTable;
			info.ParentCol = new ColumnDefinition("comp_id", false, true, false, true, OleDbType.Integer);
			info.ChildCol = new ColumnDefinition("person_id", false, true, false, true, OleDbType.Integer);

			ActiveRecordPropertyRelationDescriptor propDesc = relService.Build( info );
			Assert.IsNotNull(propDesc as ActiveRecordHasAndBelongsToManyDescriptor);
			Assert.IsNotNull(propDesc);
			Assert.AreEqual( "People", propDesc.PropertyName );
			Assert.AreEqual( targetDesc, propDesc.TargetType );
			Assert.AreEqual( "person_id", propDesc.ColumnName );
			Assert.AreEqual( "comp_id", (propDesc as ActiveRecordHasAndBelongsToManyDescriptor).ColumnKey);
		}
		private void FillClassProperties(ActiveRecordDescriptor descriptor)
		{
			listView1.Items.Clear();

			IList added = new ArrayList();

			foreach(ActiveRecordPropertyDescriptor prop in descriptor.Properties)
			{
				ListViewItem item = listView1.Items.Add(prop.PropertyName);
				item.Tag = prop;
				item.Checked = prop.Generate;
				item.SubItems.Add( prop.PropertyType.ToString() );
				item.SubItems.Add( prop.ColumnName );
				item.SubItems.Add( prop.ColumnTypeName );
				item.SubItems.Add( (prop is ActiveRecordPrimaryKeyDescriptor) ? "Yes" : "" );

				added.Add(prop);
			}

			if (descriptor is ActiveRecordDescriptorSubClass)
			{
				// This code might look strange, but we're
				// only showing the fields on the parent class that haven't been
				// marked for generation, so the user might have the
				// oportunity to add them

				foreach(ActiveRecordPropertyDescriptor prop in _parent.Properties)
				{
					if (prop.Generate || added.Contains(prop)) continue;

					ListViewItem item = listView1.Items.Add(prop.PropertyName);
					item.Tag = prop;
					item.Checked = prop.Generate;
					item.SubItems.Add( prop.PropertyType.ToString() );
					item.SubItems.Add( prop.ColumnName );
					item.SubItems.Add( prop.ColumnTypeName );
					item.SubItems.Add( (prop is ActiveRecordPrimaryKeyDescriptor) ? "Yes" : "" );
				}
			}
		}
 public ActiveRecordHasManyDescriptor(String columnName,
                                      String propertyName, ActiveRecordDescriptor targetType) :
     base(columnName, String.Empty, propertyName, "HasMany", targetType)
 {
     _propertyType = typeof(IList);
 }
		private void FillClassRelationships(ActiveRecordDescriptor descriptor)
		{
			listView2.Items.Clear();

			IList added = new ArrayList();

			foreach(ActiveRecordPropertyRelationDescriptor prop in descriptor.PropertiesRelations)
			{
				ListViewItem item = listView2.Items.Add(prop.PropertyName);
				item.Tag = prop;
				item.Checked = prop.Generate;

				if (prop.TargetType == null)
				{
					throw new ApplicationException("Information missing");
				}

				item.SubItems.Add( prop.TargetType.ClassName );
				item.SubItems.Add( prop.RelationType );
				item.SubItems.Add( prop.ColumnName );

				added.Add(prop);
			}

			if (descriptor is ActiveRecordDescriptorSubClass)
			{
				// This code might look strange, but we're
				// only showing the fields on the parent class that haven't been
				// marked for generation, so the user might have the
				// oportunity to add them

				foreach(ActiveRecordPropertyRelationDescriptor prop in _parent.PropertiesRelations)
				{
					if (prop.Generate || added.Contains(prop)) continue;

					ListViewItem item = listView2.Items.Add(prop.PropertyName);
					item.Tag = prop;
					item.Checked = prop.Generate;

					if (prop.TargetType == null)
					{
						throw new ApplicationException("Information missing");
					}

					item.SubItems.Add( prop.TargetType.ClassName );
					item.SubItems.Add( prop.RelationType );
					item.SubItems.Add( prop.ColumnName );
				}
			}
		}
		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);
			}
		}
Esempio n. 25
0
		public void Run(ActiveRecordDescriptor descriptor)
		{
			throw new NotImplementedException();
		}
		public ActiveRecordDescriptorSubClass(ActiveRecordDescriptor baseClass)
		{
			_baseClass = baseClass;
		}
		private void FillClassDetails(ActiveRecordDescriptor descriptor)
		{
			className.Text = descriptor.ClassName;
	
			parentClass.Items.Add( "ActiveRecordBase" );
	
			foreach(TableDefinition table in descriptor.Table.DatabaseDefinition.Tables)
			{
				if (table.RelatedDescriptor == null) continue;
				if (table.RelatedDescriptor.ClassName == null) continue;
				if (table.RelatedDescriptor == descriptor) continue;

				parentClass.Items.Add( table.RelatedDescriptor.ClassName );
			}
	
			parentClass.Enabled = false;
			groupBox2.Enabled = false;
	
			discColumn.ValueMember = "Name";
	
			foreach(ColumnDefinition col in descriptor.Table.Columns)
			{
				discColumn.Items.Add( col );
				
				if (col.Name.Equals(descriptor.DiscriminatorField))
				{
					discColumn.SelectedItem = col;
				}
			}

			useDiscriminator.Checked = descriptor.DiscriminatorField != null;

			if (descriptor.DiscriminatorValue != null)
			{
				discValue.Text = descriptor.DiscriminatorValue;
			}
	
			if (descriptor is ActiveRecordDescriptorSubClass ||
				descriptor is ActiveRecordDescriptorJoinedSubClass )
			{
				useDiscriminator.Enabled = false;
				isJoinedSubClass.Enabled = false;
			}
		}
		public void SelfReference()
		{
			InitKernel();
			IRelationshipInferenceService relService = ObtainService();

			DatabaseDefinition dbdef = new DatabaseDefinition("alias");

			TableDefinition categoryTable = new TableDefinition("categories", dbdef );
			categoryTable.AddColumn( new ColumnDefinition("id", true, false, true, false, OleDbType.Integer) );
			categoryTable.AddColumn( new ColumnDefinition("name", false, false, false, false, OleDbType.VarChar) );
			categoryTable.AddColumn( new ColumnDefinition("parent_id", false, true, false, false, OleDbType.Integer, categoryTable) );
	
			categoryTable.AddManyRelation(categoryTable);

			BuildContext context = new BuildContext();

			ActiveRecordDescriptor arDesc = new ActiveRecordDescriptor();

			ActiveRecordPropertyDescriptor[] descs = relService.InferRelations( arDesc, categoryTable, context );

			Assert.IsFalse(context.HasPendents);

			Assert.IsNotNull(descs);
			Assert.AreEqual( 2, descs.Length );

			ActiveRecordHasManyDescriptor desc1 = descs[0] as ActiveRecordHasManyDescriptor;
			Assert.IsNotNull(desc1);
			Assert.IsNotNull(desc1.TargetType);
			Assert.IsNotNull(desc1.PropertyType);

			Assert.AreEqual( "Categories", desc1.PropertyName );
			Assert.AreEqual( "parent_id", desc1.ColumnName );
			Assert.AreEqual( typeof(IList), desc1.PropertyType );

			ActiveRecordBelongsToDescriptor desc2 = descs[1] as ActiveRecordBelongsToDescriptor;
			Assert.IsNotNull(desc2);
			Assert.IsNotNull(desc2.TargetType);
			Assert.IsNull(desc2.PropertyType);
			Assert.AreEqual( "Category", desc2.PropertyName );
			Assert.AreEqual( "parent_id", desc2.ColumnName );
		}
Esempio n. 29
0
		private void AddActiveRecordAttribute(CodeTypeDeclaration declaration, ActiveRecordDescriptor descriptor)
		{
			CodeAttributeDeclaration att = new CodeAttributeDeclaration("ActiveRecord");

			if (!(descriptor is ActiveRecordDescriptorSubClass))
			{
				att.Arguments.Add( new CodeAttributeArgument( 
					new CodeSnippetExpression(Quote(descriptor.Table.Name)) ) );

				if (descriptor.DiscriminatorField != null && descriptor.DiscriminatorField.Length != 0)
				{
					att.Arguments.Add( new CodeAttributeArgument( "DiscriminatorColumn",
						new CodeSnippetExpression(Quote(descriptor.DiscriminatorField)) ) );
				}
				if (descriptor.DiscriminatorType != null && descriptor.DiscriminatorType.Length != 0)
				{
					att.Arguments.Add( new CodeAttributeArgument( "DiscriminatorType",
						new CodeSnippetExpression(Quote(descriptor.DiscriminatorType)) ) );
				}
			}

			if (descriptor.DiscriminatorValue != null && descriptor.DiscriminatorValue.Length != 0)
			{
				att.Arguments.Add( new CodeAttributeArgument( "DiscriminatorValue",
					new CodeSnippetExpression(Quote(descriptor.DiscriminatorValue)) ) );
			}


			declaration.CustomAttributes.Add( att );
		}
 public ActiveRecordBelongsToDescriptor(String columnName,
                                        String propertyName, ActiveRecordDescriptor targetType) :
     base(columnName, String.Empty, propertyName, "BelongsTo", targetType)
 {
 }
Esempio n. 31
0
		private void AddRelations(ActiveRecordDescriptor descriptor, CodeTypeDeclaration declaration)
		{
			foreach(ActiveRecordPropertyRelationDescriptor property in descriptor.PropertiesRelations)
			{
				if (!property.Generate) continue;

				CodeAttributeDeclaration att = null;
				CodeMemberProperty memberProperty = CreatePropertyMember(property, declaration);;

				if (property is ActiveRecordBelongsToDescriptor)
				{
					att = new CodeAttributeDeclaration("BelongsTo");

					att.Arguments.Add( new CodeAttributeArgument(new CodeSnippetExpression(Quote(property.ColumnName)) ) );
				}
				else if (property is ActiveRecordHasAndBelongsToManyDescriptor)
				{
					att = new CodeAttributeDeclaration("HasAndBelongsToMany");

					ActiveRecordHasAndBelongsToManyDescriptor hasAndBelongsProp = property as ActiveRecordHasAndBelongsToManyDescriptor;

					att.Arguments.Add( new CodeAttributeArgument(new CodeTypeOfExpression(property.TargetType.ClassName) ) );

//					att.Arguments.Add( new CodeAttributeArgument(new CodeSnippetExpression("RelationType.Bag") ) );

//					att.Arguments.Add( new CodeAttributeArgument("Key", new CodeSnippetExpression(Quote(property.PropertyName)) ) );

					att.Arguments.Add( new CodeAttributeArgument("Table", new CodeSnippetExpression(Quote(property.TargetType.Table.Name)) ) );

					att.Arguments.Add( new CodeAttributeArgument("ColumnRef", new CodeSnippetExpression(Quote(property.ColumnName)) ) );
					
					att.Arguments.Add( new CodeAttributeArgument("ColumnKey", new CodeSnippetExpression(Quote(hasAndBelongsProp.ColumnKey)) ) );
				}
				else if (property is ActiveRecordHasManyDescriptor)
				{
					att = new CodeAttributeDeclaration("HasMany");

					att.Arguments.Add( new CodeAttributeArgument(new CodeTypeOfExpression(property.TargetType.ClassName) ) );

//					att.Arguments.Add( new CodeAttributeArgument(new CodeSnippetExpression("RelationType.Bag") ) );

					att.Arguments.Add( new CodeAttributeArgument("Table", new CodeSnippetExpression(Quote(property.TargetType.Table.Name)) ) );

					att.Arguments.Add( new CodeAttributeArgument("ColumnKey", new CodeSnippetExpression(Quote(property.ColumnName)) ) );
				}
				else if (property is ActiveRecordHasOneDescriptor)
				{
					att = new CodeAttributeDeclaration("HasOne");
				}

				if (property.Cascade != null && property.Cascade != String.Empty)
				{
					att.Arguments.Add( new CodeAttributeArgument("Cascade", new CodeSnippetExpression(Quote(property.Cascade)) ) );
				}
				if (property.Where != null && property.Where != String.Empty)
				{
					att.Arguments.Add( new CodeAttributeArgument("Where", new CodeSnippetExpression(Quote(property.Where)) ) );
				}
				if (property.OrderBy != null && property.OrderBy != String.Empty)
				{
					att.Arguments.Add( new CodeAttributeArgument("OrderBy", new CodeSnippetExpression(Quote(property.OrderBy)) ) );
				}
				if (property.OuterJoin != null && !"auto".Equals(property.OuterJoin))
				{
					att.Arguments.Add( new CodeAttributeArgument("OuterJoin", new CodeSnippetExpression(Quote(property.OuterJoin)) ) );
				}
				if (property.Proxy == true)
				{
					att.Arguments.Add( new CodeAttributeArgument("Proxy", new CodeSnippetExpression("true") ) );
				}
				if (property.Inverse == true)
				{
					att.Arguments.Add( new CodeAttributeArgument("Inverse", new CodeSnippetExpression("true") ) );
				}

				memberProperty.CustomAttributes.Add(att);
				declaration.Members.Add(memberProperty);
			}
		}
 public ActiveRecordHasOneDescriptor(String _columnName,
                                     String _propertyName, ActiveRecordDescriptor _targetType) :
     base(_columnName, String.Empty, _propertyName, "HasOne", _targetType)
 {
 }
Esempio n. 33
0
		private void AddOperations(ActiveRecordDescriptor descriptor, CodeTypeDeclaration declaration)
		{
			CodeMemberMethod deleteAll = new CodeMemberMethod();
			deleteAll.Name = "DeleteAll";
			deleteAll.Attributes = MemberAttributes.Static|MemberAttributes.Public;
			deleteAll.Statements.Add( new CodeExpressionStatement(
				new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("ActiveRecordBase"), 
					"DeleteAll", new CodeTypeOfExpression(descriptor.ClassName) ) ));
			declaration.Members.Add(deleteAll);

			CodeMemberMethod findAll = new CodeMemberMethod();
			findAll.Name = "FindAll";
			findAll.ReturnType = new CodeTypeReference( descriptor.ClassName, 1 );
			findAll.Attributes = MemberAttributes.Static|MemberAttributes.Public;
			findAll.Statements.Add( new CodeMethodReturnStatement(
				new CodeCastExpression(findAll.ReturnType,
				new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("ActiveRecordBase"), 
				"FindAll", new CodeTypeOfExpression(descriptor.ClassName) ) )));
			declaration.Members.Add(findAll);

			CodeMemberMethod find = new CodeMemberMethod();

			ActiveRecordPrimaryKeyDescriptor primaryKey = descriptor.PrimaryKeyProperty;
			if (primaryKey != null)
			{
				find.Name = "Find";
				find.ReturnType = new CodeTypeReference( descriptor.ClassName );
				find.Attributes = MemberAttributes.Static|MemberAttributes.Public;
				find.Parameters.Add( new CodeParameterDeclarationExpression(primaryKey.PropertyType, primaryKey.PropertyName) );
				find.Statements.Add( new CodeMethodReturnStatement(
					new CodeCastExpression(find.ReturnType,
					new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("ActiveRecordBase"), 
					"FindByPrimaryKey", new CodeTypeOfExpression(descriptor.ClassName), new CodeArgumentReferenceExpression(primaryKey.PropertyName) ) )));
				declaration.Members.Add(find);
			}
		}
Esempio n. 34
0
		protected void SwitchViewTo(AssociationEnum association)
		{
			// Nothing's changed?
			if (_oldDescSelection == SelectedTarget && association == _association)
			{
				// Aparently not
				return;
			}

			// Saves 
			_oldDescSelection = SelectedTarget;
			_association = association;

			// Disabling
			associationTable.Enabled = associationTableLabel.Enabled = false;
			parentCols.Enabled = parentColsLabel.Enabled = false;
			relatedCols.Enabled = relatedColsLabel.Enabled = false;

			if (association == AssociationEnum.BelongsTo)
			{
				parentCols.Enabled = parentColsLabel.Enabled = true;

				PopulateColumnsInListBox( parentCols, _descriptor.Table);
			}
			else if (association == AssociationEnum.HasAndBelongsToMany)
			{
				associationTable.Enabled = associationTableLabel.Enabled = true;
				parentCols.Enabled = parentColsLabel.Enabled = true;
				relatedCols.Enabled = relatedColsLabel.Enabled = true;

				associationTable.SelectedIndex = -1;

				parentCols.Items.Clear();
				relatedCols.Items.Clear();

				PopulateTablesInComboBox(associationTable, _descriptor.Table.DatabaseDefinition);
			}
			else if (association == AssociationEnum.HasMany)
			{
				relatedCols.Enabled = relatedColsLabel.Enabled = true;

				PopulateColumnsInListBox( relatedCols, SelectedTarget.Table);
			}
		}
		public ActiveRecordDescriptorJoinedSubClass(ActiveRecordDescriptor baseClass, String keyColumn)
		{
			_baseClass = baseClass;
			_keyColumn = keyColumn;
		}
 public ActiveRecordDescriptorJoinedSubClass(ActiveRecordDescriptor baseClass, String keyColumn)
 {
     _baseClass = baseClass;
     _keyColumn = keyColumn;
 }
		public ActiveRecordHasAndBelongsToManyDescriptor(String columnName, String associationtable, 
			String propertyName, ActiveRecordDescriptor targetType, String columnKey) : 
			base(columnName, String.Empty, propertyName, "HasAndBelongsToMany", targetType)
		{
			_associationtable = associationtable;
			_columnKey = columnKey;
			_propertyType = typeof(IList);
		}