User: xtoff
Date: 2010/01/09 02:22 PM
Added:
/ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Bugs/
ARIssue157TestCase.cs
Modified:
/ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/
ActiveRecordTestCase.cs, Castle.ActiveRecord.Tests-vs2008.csproj
/ActiveRecord/trunk/src/Castle.ActiveRecord/Attributes/
PrimaryKeyAttribute.cs, PropertyAttribute.cs
/ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/Internal/
ActiveRecordModelBuilder.cs
Log:
- resolved AR-ISSUE-157 - "Import attribute on a subclass in a type hierarchy
generates invalid HBM" by disallowing Imports on joined subclasses.
- added test for Query by Example.
File Changes:
Directory: /ActiveRecord/trunk/src/Castle.ActiveRecord/Attributes/
==================================================================
File [modified]: PrimaryKeyAttribute.cs
Delta lines: +19 -83
===================================================================
--- ActiveRecord/trunk/src/Castle.ActiveRecord/Attributes/PropertyAttribute.cs
2010-01-09 18:29:30 UTC (rev 6613)
+++ ActiveRecord/trunk/src/Castle.ActiveRecord/Attributes/PropertyAttribute.cs
2010-01-09 21:22:24 UTC (rev 6614)
@@ -47,21 +47,13 @@
[AttributeUsage(AttributeTargets.Property), Serializable]
public class PropertyAttribute : WithAccessOptionalTableAttribute
{
- private string column, formula, @default;
- private string type, uniqueKey, index;
- private string sqlType, check;
- private int length;
- private bool notNull;
- private bool unique;
- private bool update = true;
- private bool insert = true;
- private bool isOverride;
-
/// <summary>
/// Initializes a new instance of the <see
cref="PropertyAttribute"/> class.
/// </summary>
- public PropertyAttribute()
+ public PropertyAttribute()
{
+ Insert = true;
+ Update = true;
}
/// <summary>
@@ -70,7 +62,7 @@
/// <param name="column">The column.</param>
public PropertyAttribute(String column) : this()
{
- this.column = column;
+ Column = column;
}
/// <summary>
@@ -80,86 +72,54 @@
/// <param name="type">The type.</param>
public PropertyAttribute(String column, String type) :
this(column)
{
- this.type = type;
+ ColumnType = type;
}
/// <summary>
/// Gets or sets a value indicating whether this property allow
null.
/// </summary>
/// <value><c>true</c> if allow null; otherwise,
<c>false</c>.</value>
- public bool NotNull
- {
- get { return notNull; }
- set { notNull = value; }
- }
+ public bool NotNull { get; set; }
/// <summary>
/// Gets or sets the length of the property (for strings -
nvarchar(50) )
/// </summary>
/// <value>The length.</value>
- public int Length
- {
- get { return length; }
- set { length = value; }
- }
+ public int Length { get; set; }
/// <summary>
/// Gets or sets the column name
/// </summary>
/// <value>The column.</value>
- public String Column
- {
- get { return column; }
- set { column = value; }
- }
+ public string Column { get; set; }
/// <summary>
/// Set to <c>false</c> to ignore this property when updating
entities of this ActiveRecord class.
/// </summary>
- public bool Update
- {
- get { return update; }
- set { update = value; }
- }
+ public bool Update { get; set; }
/// <summary>
/// Set to <c>false</c> to ignore this property when inserting
entities of this ActiveRecord class.
/// </summary>
- public bool Insert
- {
- get { return insert; }
- set { insert = value; }
- }
+ public bool Insert { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this <see
cref="PropertyAttribute"/> is unique.
/// </summary>
/// <value><c>true</c> if unique; otherwise,
<c>false</c>.</value>
- public bool Unique
- {
- get { return unique; }
- set { unique = value; }
- }
+ public bool Unique { get; set; }
/// <summary>
/// Gets or sets the formula used to calculate this property
/// </summary>
/// <value>The formula.</value>
- public String Formula
- {
- get { return formula; }
- set { formula = value; }
- }
+ public string Formula { get; set; }
/// <summary>
/// Gets or sets the type of the column.
/// </summary>
/// <value>The type of the column.</value>
- public String ColumnType
- {
- get { return type; }
- set { type = value; }
- }
+ public string ColumnType { get; set; }
/// <summary>
/// From NHibernate documentation:
@@ -173,44 +133,28 @@
/// used to name the constraint, only to group the columns
/// in the mapping file.
/// </remarks>
- public string UniqueKey
- {
- get { return uniqueKey; }
- set { uniqueKey = value; }
- }
+ public string UniqueKey { get; set; }
/// <summary>
/// From NHibernate documentation:
/// specifies the name of a (multi-column) index
/// </summary>
/// <value>index name</value>
- public string Index
- {
- get { return index; }
- set { index = value; }
- }
+ public string Index { get; set; }
/// <summary>
/// From NHibernate documentation:
/// overrides the default column type
/// </summary>
/// <value>column_type</value>
- public string SqlType
- {
- get { return sqlType; }
- set { sqlType = value; }
- }
+ public string SqlType { get; set; }
/// <summary>
/// From NHibernate documentation:
/// create an SQL check constraint on either column or table
/// </summary>
/// <value>Sql Expression</value>
- public string Check
- {
- get { return check; }
- set { check = value; }
- }
+ public string Check { get; set; }
/// <summary>
/// Gets or sets the default value for a column (used by schema
generation).
@@ -218,19 +162,11 @@
/// as the default on the database.
/// </summary>
/// <value>The default value for the column.</value>
- public string Default
- {
- get { return @default; }
- set { @default = value; }
- }
+ public string Default { get; set; }
/// <summary>
/// Set to <c>true</c> if this property overrides a property in
a base class
/// </summary>
- public bool IsOverride
- {
- get { return isOverride; }
- set { isOverride = value; }
- }
+ public bool IsOverride { get; set; }
}
File [modified]: PropertyAttribute.cs
Delta lines: +20 -4
===================================================================
---
ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/Internal/ActiveRecordModelBuilder.cs
2010-01-09 18:29:30 UTC (rev 6613)
+++
ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/Internal/ActiveRecordModelBuilder.cs
2010-01-09 21:22:24 UTC (rev 6614)
@@ -123,10 +123,21 @@
{
object[] attrs =
type.GetCustomAttributes(typeof(ImportAttribute), false);
+ if (attrs == null || attrs.Length == 0)
+ {
+ return;
+ }
+
+ if(HasJoinedBase(type))
+ {
+ string message = string.Format("Type {0}
declares Imports but it has a joined base class. " +
+ "All imports
must be declared on a base class.", type);
+ throw new ActiveRecordException(message);
+ }
+
foreach (ImportAttribute att in attrs)
{
- ImportModel im = new ImportModel(att);
- model.Imports.Add(im);
+ model.Imports.Add(new ImportModel(att));
}
}
@@ -264,8 +275,7 @@
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
+ if (HasJoinedBase(type))
{
throw new
ActiveRecordException("You can't specify a PrimaryKeyAttribute in a joined
subclass. " +
"Check type " + model.Type.FullName);
@@ -509,6 +519,12 @@
}
}
+ private static bool HasJoinedBase(Type type)
+ {
+ return type.IsDefined(typeof(JoinedBaseAttribute),
true) && // JoinedBase in a superclass
+ !type.IsDefined(typeof(JoinedBaseAttribute),
false);
+ }
+
private static void
CollectMetaValues(IList<Any.MetaValueAttribute> metaStore, PropertyInfo prop)
{
Directory: /ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Bugs/
==================================================================
File [added]: ARIssue157TestCase.cs
Delta lines: +1 -0
===================================================================
---
ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Castle.ActiveRecord.Tests-vs2008.csproj
2010-01-09 18:29:30 UTC (rev 6613)
+++
ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Castle.ActiveRecord.Tests-vs2008.csproj
2010-01-09 21:22:24 UTC (rev 6614)
@@ -332,6 +332,7 @@
<Compile Include="ActiveRecordDetachedQueryGenericTestCase.cs" />
<Compile Include="ActiveRecordDetachedQueryTestCase.cs" />
<Compile Include="AnyRelationTestCase.cs" />
+ <Compile Include="Bugs\ARIssue157TestCase.cs" />
<Compile Include="CompositeNestedClassTestCase.cs" />
<Compile Include="CompositeUserTypeTestCase.cs" />
Directory: /ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/
=============================================================
File [modified]: ActiveRecordTestCase.cs
Delta lines: +69 -0
===================================================================
--- ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Bugs/ARIssue157TestCase.cs
(rev 0)
+++ ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Bugs/ARIssue157TestCase.cs
2010-01-09 21:22:24 UTC (rev 6614)
@@ -0,0 +1,69 @@
+// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Castle.ActiveRecord.Tests.Bugs
+{
+ using System;
+
+ using Castle.ActiveRecord.Framework;
+
+ using NUnit.Framework;
+
+ [TestFixture]
+ public class ARIssue157TestCase : AbstractActiveRecordTest
+ {
+ public override void Init()
+ {
+ ActiveRecordStarter.ResetInitializationFlag();
+
+
+ }
+
+ [Test]
+ public void Imports_on_joined_subclass_not_allowed()
+ {
+ const string message = "Type
Castle.ActiveRecord.Tests.Bugs.OneKindOfDocument declares Imports " +
+ "but it has a joined base class.
All imports must be declared on a base class.";
+ TestDelegate code = () =>
+
+ ActiveRecordStarter.Initialize(GetConfigSource(),
+
typeof(Document),
+
typeof(OneKindOfDocument));
+
+ Exception exception =
+
+ Assert.Throws(typeof(ActiveRecordException), code);
+ Assert.AreEqual(message, exception.Message);
+ }
+ }
+
+ [ActiveRecord, JoinedBase]
+ public abstract class Document
+ {
+ [PrimaryKey]
+ protected int Id { get; set; }
+ }
+
+ [ActiveRecord]
+ [Import(typeof(DocumentSearchResult), "dsr")]
+ public class OneKindOfDocument : Document
+ {
+ [JoinedKey("comp_id")]
+ public int CompId { get; set; }
+ }
+
+ public class DocumentSearchResult
+ {
+ }
+}
File [modified]: Castle.ActiveRecord.Tests-vs2008.csproj
Delta lines: +0 -0
===================================================================
Directory: /ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/Internal/
==========================================================================
File [modified]: ActiveRecordModelBuilder.cs
Delta lines: +24 -0
===================================================================
--- ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/ActiveRecordTestCase.cs
2010-01-09 18:29:30 UTC (rev 6613)
+++ ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/ActiveRecordTestCase.cs
2010-01-09 21:22:24 UTC (rev 6614)
@@ -104,6 +104,30 @@
}
[Test]
+ public void Query_by_example()
+ {
+ ActiveRecordStarter.Initialize(GetConfigSource(),
typeof(Post), typeof(Blog));
+ Recreate();
+
+ Post.DeleteAll();
+ Blog.DeleteAll();
+
+ Blog[] blogs = Blog.FindAll();
+
+ Assert.IsNotNull(blogs);
+ Assert.AreEqual(0, blogs.Length);
+
+ var blog = new Blog { Name = "hammett's blog", Author =
"hamilton verissimo" };
+ blog.Create();
+
+ var count = Blog.FetchCount(Example.Create(new Blog {
Name = "hammett" })
+
.EnableLike(MatchMode.Start)
+ .ExcludeNulls()
+
.ExcludeZeroes());
+ Assert.AreEqual(1, count);
+ }
+
+ [Test]
public void ComponentAttribute()
{
--
You received this message because you are subscribed to the Google Groups
"Castle Project Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-commits?hl=en.