@@ -29,76 +29,51 @@ public SequenceQuery BuildNextValueQuery(SchemaNode generatorNode, NodeConfigura
29
29
? SequenceQueryCompartment . SameSession
30
30
: compartment ;
31
31
32
- var postCompilerConfiguration = ( nodeConfiguration != null )
33
- ? new SqlPostCompilerConfiguration ( nodeConfiguration . GetDatabaseMapping ( ) , nodeConfiguration . GetSchemaMapping ( ) )
34
- : new SqlPostCompilerConfiguration ( ) ;
32
+ var postCompilerConfiguration = GetPostCompilerConfig ( nodeConfiguration ) ;
35
33
36
34
var sqlNext = hasSequences
37
35
? GetSequenceBasedNextImplementation ( generatorNode , increment )
38
36
: GetTableBasedNextImplementation ( generatorNode ) ;
39
37
40
- var requiresSeparateSession = ! hasSequences ;
41
- var batch = sqlNext as SqlBatch ;
42
- if ( batch == null || hasBatches )
38
+ if ( sqlNext is not SqlBatch batch || hasBatches ) {
43
39
// There are batches or there is single statement, so we can run this as a single request
44
- return new SequenceQuery ( Compile ( sqlNext , nodeConfiguration ) . GetCommandText ( postCompilerConfiguration ) , actualCompartment ) ;
45
-
46
- // No batches, so we must execute this manually
47
- if ( ! storesAutoIncrementSettingsInMemory )
48
- return new SequenceQuery (
49
- Compile ( ( ISqlCompileUnit ) batch [ 0 ] , nodeConfiguration ) . GetCommandText ( postCompilerConfiguration ) ,
50
- Compile ( ( ISqlCompileUnit ) batch [ 1 ] , nodeConfiguration ) . GetCommandText ( postCompilerConfiguration ) ,
51
- actualCompartment ) ;
52
- return new SequenceQuery (
53
- Compile ( ( ISqlCompileUnit ) batch [ 0 ] , nodeConfiguration ) . GetCommandText ( postCompilerConfiguration ) ,
54
- Compile ( ( ISqlCompileUnit ) batch [ 1 ] , nodeConfiguration ) . GetCommandText ( postCompilerConfiguration ) ,
55
- Compile ( ( ISqlCompileUnit ) batch [ 2 ] , nodeConfiguration ) . GetCommandText ( postCompilerConfiguration ) ,
56
- actualCompartment ) ;
57
- }
58
-
59
- public SequenceQuery BuildNextValueQuery ( SchemaNode generatorNode , NodeConfiguration nodeConfiguration , long increment )
60
- {
61
- return BuildNextValueQuery ( generatorNode , nodeConfiguration , increment , false ) ;
40
+ return new SequenceQuery ( driver . Compile ( sqlNext ) . GetCommandText ( postCompilerConfiguration ) , actualCompartment ) ;
41
+ }
42
+ else {
43
+ // No batches, so we must execute this manually
44
+ return ! storesAutoIncrementSettingsInMemory
45
+ ? new SequenceQuery (
46
+ driver . Compile ( ( ISqlCompileUnit ) batch [ 0 ] ) . GetCommandText ( postCompilerConfiguration ) ,
47
+ driver . Compile ( ( ISqlCompileUnit ) batch [ 1 ] ) . GetCommandText ( postCompilerConfiguration ) ,
48
+ actualCompartment )
49
+ : new SequenceQuery (
50
+ driver . Compile ( ( ISqlCompileUnit ) batch [ 0 ] ) . GetCommandText ( postCompilerConfiguration ) ,
51
+ driver . Compile ( ( ISqlCompileUnit ) batch [ 1 ] ) . GetCommandText ( postCompilerConfiguration ) ,
52
+ driver . Compile ( ( ISqlCompileUnit ) batch [ 2 ] ) . GetCommandText ( postCompilerConfiguration ) ,
53
+ actualCompartment ) ;
54
+ }
62
55
}
63
56
64
- public SequenceQuery BuildNextValueQuery ( SchemaNode generatorNode , long increment , bool forcedSameSessionExecution )
65
- {
66
- return BuildNextValueQuery ( generatorNode , null , increment , forcedSameSessionExecution ) ;
67
- }
57
+ public SequenceQuery BuildNextValueQuery ( SchemaNode generatorNode , long increment , bool forcedSameSessionExecution ) =>
58
+ BuildNextValueQuery ( generatorNode , null , increment , forcedSameSessionExecution ) ;
68
59
69
- public SequenceQuery BuildNextValueQuery ( SchemaNode generatorNode , long increment )
70
- {
71
- return BuildNextValueQuery ( generatorNode , null , increment ) ;
72
- }
60
+ public SequenceQuery BuildNextValueQuery ( SchemaNode generatorNode , long increment ) =>
61
+ BuildNextValueQuery ( generatorNode , null , increment , false ) ;
73
62
74
- public string BuildCleanUpQuery ( SchemaNode generatorNode )
75
- {
76
- return BuildCleanUpQuery ( generatorNode , null ) ;
77
- }
63
+ public string BuildCleanUpQuery ( SchemaNode generatorNode ) =>
64
+ BuildCleanUpQuery ( generatorNode , null ) ;
78
65
79
66
public string BuildCleanUpQuery ( SchemaNode generatorNode , NodeConfiguration nodeConfiguration )
80
67
{
81
- var postCompilerConfiguration = ( nodeConfiguration != null )
82
- ? new SqlPostCompilerConfiguration ( nodeConfiguration . GetDatabaseMapping ( ) , nodeConfiguration . GetSchemaMapping ( ) )
83
- : new SqlPostCompilerConfiguration ( ) ;
68
+ var postCompilerConfiguration = GetPostCompilerConfig ( nodeConfiguration ) ;
84
69
85
- var table = ( Table ) generatorNode ;
70
+ var table = ( Table ) generatorNode ;
86
71
var delete = SqlDml . Delete ( SqlDml . TableRef ( table ) ) ;
87
- return Compile ( delete , nodeConfiguration ) . GetCommandText ( postCompilerConfiguration ) ;
88
- }
89
-
90
-
91
- private SqlCompilationResult Compile ( ISqlCompileUnit unit , NodeConfiguration nodeConfiguration )
92
- {
93
- if ( nodeConfiguration != null )
94
- return driver . Compile ( unit , nodeConfiguration ) ;
95
- return driver . Compile ( unit ) ;
72
+ return driver . Compile ( delete ) . GetCommandText ( postCompilerConfiguration ) ;
96
73
}
97
74
98
- private ISqlCompileUnit GetSequenceBasedNextImplementation ( SchemaNode generatorNode , long increment )
99
- {
100
- return SqlDml . Select ( SqlDml . NextValue ( ( Sequence ) generatorNode , ( int ) increment ) ) ;
101
- }
75
+ private ISqlCompileUnit GetSequenceBasedNextImplementation ( SchemaNode generatorNode , long increment ) =>
76
+ SqlDml . Select ( SqlDml . NextValue ( ( Sequence ) generatorNode , ( int ) increment ) ) ;
102
77
103
78
private ISqlCompileUnit GetTableBasedNextImplementation ( SchemaNode generatorNode )
104
79
{
@@ -116,20 +91,26 @@ private ISqlCompileUnit GetTableBasedNextImplementation(SchemaNode generatorNode
116
91
}
117
92
118
93
var result = SqlDml . Batch ( ) ;
119
- if ( storesAutoIncrementSettingsInMemory )
94
+ if ( storesAutoIncrementSettingsInMemory ) {
120
95
result . Add ( delete ) ;
96
+ }
121
97
result . Add ( insert ) ;
122
98
result . Add ( SqlDml . Select ( SqlDml . LastAutoGeneratedId ( ) ) ) ;
123
99
return result ;
124
100
}
125
101
102
+ private static SqlPostCompilerConfiguration GetPostCompilerConfig ( NodeConfiguration nodeConfiguration ) =>
103
+ ( nodeConfiguration != null )
104
+ ? new SqlPostCompilerConfiguration ( nodeConfiguration . GetDatabaseMapping ( ) , nodeConfiguration . GetSchemaMapping ( ) )
105
+ : new SqlPostCompilerConfiguration ( ) ;
106
+
126
107
private static TableColumn GetColumn ( Table table , string columnName )
127
108
{
128
109
var idColumn = table . TableColumns [ columnName ] ;
129
- if ( idColumn == null )
130
- throw new InvalidOperationException ( string . Format (
131
- Strings . ExColumnXIsNotFoundInTableY , columnName , table . Name ) ) ;
132
- return idColumn ;
110
+ return idColumn == null
111
+ ? throw new InvalidOperationException ( string . Format (
112
+ Strings . ExColumnXIsNotFoundInTableY , columnName , table . Name ) )
113
+ : idColumn ;
133
114
}
134
115
135
116
public SequenceQueryBuilder ( StorageDriver driver )
0 commit comments