@@ -29,76 +29,51 @@ public SequenceQuery BuildNextValueQuery(SchemaNode generatorNode, NodeConfigura
2929 ? SequenceQueryCompartment . SameSession
3030 : compartment ;
3131
32- var postCompilerConfiguration = ( nodeConfiguration != null )
33- ? new SqlPostCompilerConfiguration ( nodeConfiguration . GetDatabaseMapping ( ) , nodeConfiguration . GetSchemaMapping ( ) )
34- : new SqlPostCompilerConfiguration ( ) ;
32+ var postCompilerConfiguration = GetPostCompilerConfig ( nodeConfiguration ) ;
3533
3634 var sqlNext = hasSequences
3735 ? GetSequenceBasedNextImplementation ( generatorNode , increment )
3836 : GetTableBasedNextImplementation ( generatorNode ) ;
3937
40- var requiresSeparateSession = ! hasSequences ;
41- var batch = sqlNext as SqlBatch ;
42- if ( batch == null || hasBatches )
38+ if ( sqlNext is not SqlBatch batch || hasBatches ) {
4339 // 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+ }
6255 }
6356
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 ) ;
6859
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 ) ;
7362
74- public string BuildCleanUpQuery ( SchemaNode generatorNode )
75- {
76- return BuildCleanUpQuery ( generatorNode , null ) ;
77- }
63+ public string BuildCleanUpQuery ( SchemaNode generatorNode ) =>
64+ BuildCleanUpQuery ( generatorNode , null ) ;
7865
7966 public string BuildCleanUpQuery ( SchemaNode generatorNode , NodeConfiguration nodeConfiguration )
8067 {
81- var postCompilerConfiguration = ( nodeConfiguration != null )
82- ? new SqlPostCompilerConfiguration ( nodeConfiguration . GetDatabaseMapping ( ) , nodeConfiguration . GetSchemaMapping ( ) )
83- : new SqlPostCompilerConfiguration ( ) ;
68+ var postCompilerConfiguration = GetPostCompilerConfig ( nodeConfiguration ) ;
8469
85- var table = ( Table ) generatorNode ;
70+ var table = ( Table ) generatorNode ;
8671 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 ) ;
9673 }
9774
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 ) ) ;
10277
10378 private ISqlCompileUnit GetTableBasedNextImplementation ( SchemaNode generatorNode )
10479 {
@@ -116,20 +91,26 @@ private ISqlCompileUnit GetTableBasedNextImplementation(SchemaNode generatorNode
11691 }
11792
11893 var result = SqlDml . Batch ( ) ;
119- if ( storesAutoIncrementSettingsInMemory )
94+ if ( storesAutoIncrementSettingsInMemory ) {
12095 result . Add ( delete ) ;
96+ }
12197 result . Add ( insert ) ;
12298 result . Add ( SqlDml . Select ( SqlDml . LastAutoGeneratedId ( ) ) ) ;
12399 return result ;
124100 }
125101
102+ private static SqlPostCompilerConfiguration GetPostCompilerConfig ( NodeConfiguration nodeConfiguration ) =>
103+ ( nodeConfiguration != null )
104+ ? new SqlPostCompilerConfiguration ( nodeConfiguration . GetDatabaseMapping ( ) , nodeConfiguration . GetSchemaMapping ( ) )
105+ : new SqlPostCompilerConfiguration ( ) ;
106+
126107 private static TableColumn GetColumn ( Table table , string columnName )
127108 {
128109 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 ;
133114 }
134115
135116 public SequenceQueryBuilder ( StorageDriver driver )
0 commit comments