Skip to content

Commit 7039e3f

Browse files
committed
Easier inherited implementations (DNET-754).
1 parent a19ebb0 commit 7039e3f

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

Provider/src/EntityFramework.Firebird/DefaultFbMigrationSqlGeneratorBehavior.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* express or implied. See the License for the specific
1313
* language governing rights and limitations under the License.
1414
*
15-
* Copyright (c) 2014 Jiri Cincura ([email protected])
15+
* Copyright (c) 2014,2017 Jiri Cincura ([email protected])
1616
* All Rights Reserved.
1717
*
1818
*/
@@ -28,24 +28,23 @@ namespace FirebirdSql.Data.EntityFramework6
2828
{
2929
public class DefaultFbMigrationSqlGeneratorBehavior : IFbMigrationSqlGeneratorBehavior
3030
{
31-
const string IdentitySequenceName = "GEN_IDENTITY";
32-
33-
public IEnumerable<string> CreateIdentityForColumn(string columnName, string tableName)
31+
public virtual IEnumerable<string> CreateIdentityForColumn(string columnName, string tableName)
3432
{
33+
var identitySequenceName = CreateIdentitySequenceName(columnName, tableName);
3534
using (var writer = FbMigrationSqlGenerator.SqlWriter())
3635
{
3736
writer.WriteLine("EXECUTE BLOCK");
3837
writer.WriteLine("AS");
3938
writer.WriteLine("BEGIN");
4039
writer.Indent++;
4140
writer.Write("if (not exists(select 1 from rdb$generators where rdb$generator_name = '");
42-
writer.Write(IdentitySequenceName);
41+
writer.Write(identitySequenceName);
4342
writer.Write("')) then");
4443
writer.WriteLine();
4544
writer.WriteLine("begin");
4645
writer.Indent++;
4746
writer.Write("execute statement 'create sequence ");
48-
writer.Write(IdentitySequenceName);
47+
writer.Write(identitySequenceName);
4948
writer.Write("';");
5049
writer.WriteLine();
5150
writer.Indent--;
@@ -74,7 +73,7 @@ public IEnumerable<string> CreateIdentityForColumn(string columnName, string tab
7473
writer.Write("new.");
7574
writer.Write(FbMigrationSqlGenerator.Quote(columnName));
7675
writer.Write(" = next value for ");
77-
writer.Write(IdentitySequenceName);
76+
writer.Write(identitySequenceName);
7877
writer.Write(";");
7978
writer.WriteLine();
8079
writer.Indent--;
@@ -85,7 +84,7 @@ public IEnumerable<string> CreateIdentityForColumn(string columnName, string tab
8584
}
8685
}
8786

88-
public IEnumerable<string> DropIdentityForColumn(string columnName, string tableName)
87+
public virtual IEnumerable<string> DropIdentityForColumn(string columnName, string tableName)
8988
{
9089
var triggerName = CreateTriggerName(columnName, tableName);
9190
using (var writer = FbMigrationSqlGenerator.SqlWriter())
@@ -112,9 +111,14 @@ public IEnumerable<string> DropIdentityForColumn(string columnName, string table
112111
}
113112
}
114113

115-
static string CreateTriggerName(string columnName, string tableName)
114+
protected virtual string CreateTriggerName(string columnName, string tableName)
116115
{
117116
return string.Format("ID_{0}_{1}", tableName, columnName);
118117
}
118+
119+
protected virtual string CreateIdentitySequenceName(string columnName, string tableName)
120+
{
121+
return "GEN_IDENTITY";
122+
}
119123
}
120124
}

0 commit comments

Comments
 (0)