Skip to content

Commit d1e4da8

Browse files
authored
Merge pull request #289 from DataObjects-NET/master-shared-model-improvements
Improved mechanism of schema and catalog name replacement when ShareSchemaOverNodes option is activated
2 parents e0f0fd2 + d8ccca3 commit d1e4da8

File tree

29 files changed

+392
-303
lines changed

29 files changed

+392
-303
lines changed

ChangeLog/7.1.0-Beta-2-dev.txt

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
[main] Obsolete Query's members have been removed
88
[main] Obsolete members of DelayedScalarQuery<T> have been removed
99
[main] Obsolete FieldInfo.IsDynalicallyDefined property's been removed (FieldInfo.IsDynamicallyDefined is still there)
10+
[main] Changed translation of queries when DomainConfiguration.ShareStorageSchemaOverNodes set to true
11+
[main] StorageDriver.Compile(ISqlCompileUnit, NodeConfiguration) became obsolete
12+
[main] SqlNodeActualizer became obsolete
13+
[main] SqlCompilerConfiguration's DatabaseMapping and SchemaMapping moved to SqlPostCompilerConfiguration
1014
[main] Some EventArgs inheritors that were sealed classes transformed to read-only structures
1115
[main] DbCommandEventArgs became read-only structure
1216
[main] SqlCustomFunctionCall and SqlFunctionCall share one base type

Orm/Xtensive.Orm.MySql/Sql.Drivers.MySql/v5_0/Translator.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ public override void Translate(SqlCompilerContext context, SqlConcat node, NodeS
215215
}
216216

217217
/// <inheritdoc/>
218-
public override void Translate(SqlCompilerContext context, SchemaNode node) => TranslateIdentifier(context.Output, node.Name);
218+
public override void Translate(SqlCompilerContext context, SchemaNode node) =>
219+
base.Translate(context, node);
219220

220221
/// <inheritdoc/>
221222
public override void Translate(SqlCompilerContext context, SqlCreateTable node, CreateTableSection section)
@@ -578,21 +579,20 @@ protected virtual string TranslateClrType(Type type)
578579

579580
public virtual void Translate(SqlCompilerContext context, SqlRenameColumn action) //TODO: Work on this.
580581
{
581-
string schemaName = action.Column.Table.Schema.DbName;
582-
string tableName = action.Column.Table.DbName;
583-
string columnName = action.Column.DbName;
582+
var column = action.Column;
583+
var tableName = column.Table.DbName;
584584

585585
//alter table `actor` change column last_name1 last_name varchar(45)
586586

587587
var output = context.Output;
588588
_ = output.Append("ALTER TABLE ");
589589
TranslateIdentifier(output, tableName);
590590
_ = output.Append(" CHANGE COLUMN ");
591-
TranslateIdentifier(output, columnName);
591+
TranslateIdentifier(output, column.DbName);
592592
_ = output.AppendSpace();
593593
TranslateIdentifier(output, action.NewName);
594594
_ = output.AppendSpace()
595-
.Append(Translate(action.Column.DataType));
595+
.Append(Translate(column.DataType));
596596
}
597597

598598
// Constructors

Orm/Xtensive.Orm.PostgreSql/Sql.Drivers.PostgreSql/v8_0/Extractor.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2009-2020 Xtensive LLC.
1+
// Copyright (C) 2009-2022 Xtensive LLC.
22
// This code is distributed under MIT license terms.
33
// See the License.txt file in the project root for more information.
44

@@ -1250,15 +1250,15 @@ protected virtual ISqlCompileUnit BuildExtractSequencesQuery(ExtractionContext c
12501250
var sequenceMap = context.SequenceMap;
12511251
foreach (var (segId, seq) in sequenceMap) {
12521252
if (query.Length == 0) {
1253-
query.AppendFormat("SELECT * FROM (\nSELECT {0} as id, * FROM {1}", segId,
1254-
Driver.Translator.TranslateToString(null, seq)); // context is not used in PostrgreSQL translator
1253+
_ = query.AppendFormat("SELECT * FROM (\nSELECT {0} as id, * FROM {1}", segId,
1254+
SqlHelper.Quote(SqlHelper.EscapeSetup.WithQuotes, new[] { seq.Schema.DbName, seq.DbName }));
12551255
}
12561256
else {
1257-
query.AppendFormat("\nUNION ALL\nSELECT {0} as id, * FROM {1}", segId,
1258-
Driver.Translator.TranslateToString(null, seq)); // context is not used in PostgreSQL translator
1257+
_ = query.AppendFormat("\nUNION ALL\nSELECT {0} as id, * FROM {1}", segId,
1258+
SqlHelper.Quote(SqlHelper.EscapeSetup.WithQuotes, new[] { seq.Schema.DbName, seq.DbName }));
12591259
}
12601260
}
1261-
query.Append("\n) all_sequences\nORDER BY id");
1261+
_ = query.Append("\n) all_sequences\nORDER BY id");
12621262
}
12631263
return SqlDml.Fragment(SqlDml.Native(query.ToString()));
12641264
}

Orm/Xtensive.Orm.PostgreSql/Sql.Drivers.PostgreSql/v8_0/Translator.cs

+19-14
Original file line numberDiff line numberDiff line change
@@ -222,23 +222,28 @@ public override void Translate(IOutput output, SqlMatchType mt)
222222
});
223223
}
224224

225+
///// <inheritdoc/>
226+
//public override string TranslateToString(SqlCompilerContext context, SchemaNode node)
227+
//{
228+
// //temporary tables need no schema qualifier
229+
// if (node is TemporaryTable || node.Schema == null) {
230+
// return QuoteIdentifier(new[] { node.Name });
231+
// }
232+
// return QuoteIdentifier(new[] { node.Schema.Name, node.Name });
233+
//}
234+
225235
/// <inheritdoc/>
226-
public override string TranslateToString(SqlCompilerContext context, SchemaNode node)
236+
public override void Translate(SqlCompilerContext context, SchemaNode node)
227237
{
228-
//temporary tables need no schema qualifier
229-
if (!(node is TemporaryTable) && node.Schema != null) {
230-
return context == null
231-
? QuoteIdentifier(new[] { node.Schema.Name, node.Name })
232-
: QuoteIdentifier(new[] { context.SqlNodeActualizer.Actualize(node.Schema), node.Name });
233-
238+
if (node is TemporaryTable) {
239+
TranslateIdentifier(context.Output, node.Name);
240+
}
241+
else {
242+
base.Translate(context, node);
234243
}
235-
return QuoteIdentifier(new[] { node.Name });
244+
//context.Output.Append(TranslateToString(context, node));
236245
}
237246

238-
/// <inheritdoc/>
239-
public override void Translate(SqlCompilerContext context, SchemaNode node) =>
240-
context.Output.Append(TranslateToString(context, node));
241-
242247
/// <inheritdoc/>
243248
public override void Translate(SqlCompilerContext context, SqlCreateTable node, CreateTableSection section)
244249
{
@@ -309,9 +314,9 @@ protected virtual void AppendIndexStorageParameters(IOutput output, Index index)
309314
/// <inheritdoc/>
310315
public override void Translate(SqlCompilerContext context, SqlDropIndex node)
311316
{
317+
var index = node.Index;
312318
_ = context.Output.Append("DROP INDEX ");
313-
TranslateIdentifier(context.Output,
314-
context.SqlNodeActualizer.Actualize(node.Index.DataTable.Schema), node.Index.Name);
319+
TranslateIdentifier(context.Output, index.DataTable.Schema.DbName, index.DbName);
315320
}
316321

317322
/// <inheritdoc/>

Orm/Xtensive.Orm.SqlServer/Sql.Drivers.SqlServer/v11/Translator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private void TranslateSequenceStatement(SqlCompilerContext context, Sequence seq
8383
AddUseStatement(context, sequence.Schema.Catalog);
8484
_ = context.Output.Append(action)
8585
.Append(" SEQUENCE ");
86-
TranslateIdentifier(context.Output, sequence.Schema.Name, sequence.Name);
86+
TranslateIdentifier(context.Output, sequence.Schema.DbName, sequence.DbName);
8787
}
8888

8989
public Translator(SqlDriver driver)

Orm/Xtensive.Orm.Sqlite/Sql.Drivers.Sqlite/v3/Translator.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,9 @@ public override void Translate(SqlCompilerContext context, SqlCreateIndex node,
306306
/// <inheritdoc/>
307307
public override void Translate(SqlCompilerContext context, SqlDropIndex node)
308308
{
309-
_ = context.Output.Append("DROP INDEX ")
310-
.Append(context.SqlNodeActualizer.Actualize(node.Index.DataTable.Schema))
311-
.Append(".");
312-
TranslateIdentifier(context.Output, node.Index.DbName);
309+
var index = node.Index;
310+
_ = context.Output.Append("DROP INDEX ");
311+
TranslateIdentifier(context.Output, index.DataTable.Schema.DbName, index.DbName);
313312
}
314313

315314
/// <inheritdoc/>

0 commit comments

Comments
 (0)