Skip to content

Commit c974442

Browse files
committed
IgnoreRule: added Index property
1 parent 804b84a commit c974442

File tree

4 files changed

+107
-52
lines changed

4 files changed

+107
-52
lines changed
Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2013 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2013 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Alexey Kulakov
55
// Created: 2013.08.16
66

@@ -19,21 +19,25 @@ public class IgnoreRuleElement : ConfigurationCollectionElementBase
1919
private const string SchemaElementName = "schema";
2020
private const string TableElementName = "table";
2121
private const string ColumnElementName = "column";
22+
private const string IndexElementName = "index";
2223

2324
/// <inheritdoc />
24-
public override object Identifier
25-
{
26-
get { return new Tuple<string, string, string, string>(Database ?? string.Empty, Schema ?? string.Empty, Table ?? string.Empty, Column ?? string.Empty); }
27-
}
25+
public override object Identifier =>
26+
new Tuple<string, string, string, string, string>(
27+
Database ?? string.Empty,
28+
Schema ?? string.Empty,
29+
Table ?? string.Empty,
30+
Column ?? string.Empty,
31+
Index ?? string.Empty);
2832

2933
/// <summary>
3034
/// <see cref="IgnoreRule.Database" copy="true"/>
3135
/// </summary>
3236
[ConfigurationProperty(DatabaseElementName)]
3337
public string Database
3438
{
35-
get { return (string)this[DatabaseElementName]; }
36-
set { this[DatabaseElementName] = value; }
39+
get => (string) this[DatabaseElementName];
40+
set => this[DatabaseElementName] = value;
3741
}
3842

3943
/// <summary>
@@ -42,8 +46,8 @@ public string Database
4246
[ConfigurationProperty(SchemaElementName)]
4347
public string Schema
4448
{
45-
get { return (string) this[SchemaElementName]; }
46-
set { this[SchemaElementName] = value; }
49+
get => (string) this[SchemaElementName];
50+
set => this[SchemaElementName] = value;
4751
}
4852

4953
/// <summary>
@@ -52,8 +56,8 @@ public string Schema
5256
[ConfigurationProperty(TableElementName)]
5357
public string Table
5458
{
55-
get { return (string) this[TableElementName]; }
56-
set { this[TableElementName] = value; }
59+
get => (string) this[TableElementName];
60+
set => this[TableElementName] = value;
5761
}
5862

5963
/// <summary>
@@ -62,17 +66,24 @@ public string Table
6266
[ConfigurationProperty(ColumnElementName)]
6367
public string Column
6468
{
65-
get { return (string)this[ColumnElementName]; }
66-
set { this[ColumnElementName] = value; }
69+
get => (string) this[ColumnElementName];
70+
set => this[ColumnElementName] = value;
6771
}
6872

6973
/// <summary>
70-
/// Converts this instance to corresponding <see cref="IgnoreRule"/>.
74+
/// <see cref="IgnoreRule.Index"/>
7175
/// </summary>
72-
/// <returns>Result of conversion.</returns>
73-
public IgnoreRule ToNative()
76+
[ConfigurationProperty(IndexElementName)]
77+
public string Index
7478
{
75-
return new IgnoreRule(Database, Schema, Table, Column);
79+
get => (string) this[IndexElementName];
80+
set => this[IndexElementName] = value;
7681
}
82+
83+
/// <summary>
84+
/// Converts this instance to corresponding <see cref="IgnoreRule"/>.
85+
/// </summary>
86+
/// <returns>Result of conversion.</returns>
87+
public IgnoreRule ToNative() => new IgnoreRule(Database, Schema, Table, Column, Index);
7788
}
7889
}
Lines changed: 65 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,119 @@
1-
// Copyright (C) 2013 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2013-2022 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Alexey Kulakov
55
// Created: 2013.08.16
66

7+
using System;
78
using System.Text;
89
using Xtensive.Core;
910

1011
namespace Xtensive.Orm.Configuration
1112
{
1213
/// <summary>
13-
/// Ignore rules for presistent types
14+
/// Ignore rule for items in database (tables, columns, indexes).
1415
/// </summary>
1516
public sealed class IgnoreRule : LockableBase
1617
{
1718
private string database;
1819
private string schema;
1920
private string table;
2021
private string column;
21-
22+
private string index;
2223

2324
/// <summary>
24-
/// Gets database that is assigned to ignored type when this rule is applied
25+
/// Gets database that the rule should be applied to.
2526
/// If this property is set to null or empty value <see cref="DomainConfiguration.DefaultDatabase"/>
2627
/// is used instead.
2728
/// </summary>
2829
public string Database
2930
{
30-
get { return database; }
31-
set
32-
{
31+
get => database;
32+
set {
3333
EnsureNotLocked();
3434
database = value;
3535
}
3636
}
3737

3838
/// <summary>
39-
/// Get schema that is assigned to ignored type when this rule is applied
39+
/// Get schema that the rule should be applied to.
4040
/// If this property is set to null or empty value <see cref="DomainConfiguration.DefaultSchema"/>
4141
/// is used instead.
4242
/// </summary>
4343
public string Schema
4444
{
45-
get { return schema; }
46-
set
47-
{
45+
get => schema;
46+
set {
4847
EnsureNotLocked();
4948
schema = value;
5049
}
5150
}
5251

5352

5453
/// <summary>
55-
/// Gets table condition.
56-
/// When type is declared in the specified table, this rule is applied.
54+
/// Gets table condition (exact name, prefix or suffix by using asterisk).
5755
/// If this property is set to null value, any table matches this rule.
5856
/// </summary>
5957
public string Table
6058
{
61-
get { return table; }
62-
set
63-
{
59+
get => table;
60+
set {
6461
EnsureNotLocked();
6562
table = value;
6663
}
6764
}
6865

6966
/// <summary>
70-
/// Gets column condition
71-
/// When type is declared in the specified column, this rule is applied.
67+
/// Gets column condition (exact name, prefix or suffix by using asterisk).
7268
/// If this property is set to null value, any culumn matches this rule.
7369
/// </summary>
70+
/// <remarks>Either <see cref="Column"/> or <see cref="Index"/> can be declared.</remarks>
7471
public string Column
7572
{
76-
get { return column; }
77-
set
78-
{
73+
get => column;
74+
set {
75+
EnsureNotLocked();
76+
SetColumnWithCheck(value);
77+
}
78+
}
79+
80+
/// <summary>
81+
/// Gets index condition (exact name, prefix or suffix by using asterisk).
82+
/// If this property is set to null value, any index matches this rule.
83+
/// </summary>
84+
/// <remarks>Either <see cref="Index"/> or <see cref="Column"/> can be declared.</remarks>
85+
public string Index
86+
{
87+
get => index;
88+
set {
7989
EnsureNotLocked();
80-
column = value;
90+
SetIndexWithCheck(value);
8191
}
8292
}
8393

8494
/// <inheritdoc />
8595
public override string ToString()
8696
{
8797
var separator = ", ";
88-
StringBuilder sb = new StringBuilder();
89-
98+
9099
var databasePart = !string.IsNullOrEmpty(database) ? $"Database = {database}" : "<default database>";
91100
var schemaPart = !string.IsNullOrEmpty(schema) ? $"Schema = {schema}" : "<default schema>";
92101
var tablePart = !string.IsNullOrEmpty(table) ? $"Table = {table}" : "<any table>";
93-
var columnPart = !string.IsNullOrEmpty(column) ? $"Column = {column}" : "<any column>";
94-
sb.Append(databasePart)
102+
103+
var columnOrIndexPart = !string.IsNullOrEmpty(column)
104+
? $"Column = {column}"
105+
: (!string.IsNullOrEmpty(index))
106+
? $"Index = {index}"
107+
: "<any column> OR <any index>";
108+
109+
return new StringBuilder(databasePart)
95110
.Append(separator)
96111
.Append(schemaPart)
97112
.Append(separator)
98113
.Append(tablePart)
99114
.Append(separator)
100-
.Append(columnPart);
101-
102-
return sb.ToString();
115+
.Append(columnOrIndexPart)
116+
.ToString();
103117
}
104118

105119
/// <summary>
@@ -108,7 +122,23 @@ public override string ToString()
108122
/// <returns>Cloned instance</returns>
109123
public IgnoreRule Clone()
110124
{
111-
return new IgnoreRule(database, schema, table, column);
125+
return new IgnoreRule(database, schema, table, column, index);
126+
}
127+
128+
private void SetColumnWithCheck(in string columnToSet)
129+
{
130+
if (!string.IsNullOrEmpty(columnToSet) && !string.IsNullOrEmpty(index)) {
131+
throw new InvalidOperationException(string.Format(Strings.ExIgnoreRuleIsAlreadyConfiguredForX, nameof(Index)));
132+
}
133+
column = columnToSet;
134+
}
135+
136+
private void SetIndexWithCheck(in string indexToSet)
137+
{
138+
if (!string.IsNullOrEmpty(indexToSet) && !string.IsNullOrEmpty(column)) {
139+
throw new InvalidOperationException(string.Format(Strings.ExIgnoreRuleIsAlreadyConfiguredForX, nameof(Column)));
140+
}
141+
index = indexToSet;
112142
}
113143

114144
//Constructors
@@ -127,12 +157,14 @@ public IgnoreRule()
127157
/// <param name="schema">Value for <see cref="Schema"/></param>
128158
/// <param name="table">Value for <see cref="Table"/></param>
129159
/// <param name="column">Value for <see cref="Column"/></param>
130-
public IgnoreRule (string database, string schema, string table, string column)
160+
/// <param name="index">Value for <see cref="Index"/></param>
161+
internal IgnoreRule(in string database, in string schema, in string table, in string column, in string index)
131162
{
132163
Database = database;
133164
Schema = schema;
134165
Table = table;
135166
Column = column;
167+
Index = index;
136168
}
137169
}
138170
}

Orm/Xtensive.Orm/Strings.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Orm/Xtensive.Orm/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2582,4 +2582,7 @@ Error: {1}</value>
25822582
<data name="ExGivenTypeHasNoOrMoreThanOneCtorWithGivenParameters" xml:space="preserve">
25832583
<value>The given type has no constructor with given parameters or more than one suitable constructor.</value>
25842584
</data>
2585+
<data name="ExIgnoreRuleIsAlreadyConfiguredForX" xml:space="preserve">
2586+
<value>Rule is already configured for {0}.</value>
2587+
</data>
25852588
</root>

0 commit comments

Comments
 (0)