|
12 | 12 | using NHibernate.SqlTypes;
|
13 | 13 | using NHibernate.Util;
|
14 | 14 | using NHibernate.AdoNet.Util;
|
| 15 | +using System.Linq; |
15 | 16 |
|
16 | 17 | namespace NHibernate.AdoNet
|
17 | 18 | {
|
@@ -135,6 +136,45 @@ protected void Prepare(DbCommand cmd)
|
135 | 136 | }
|
136 | 137 | }
|
137 | 138 |
|
| 139 | +#if NET6_0_OR_GREATER |
| 140 | + /// <summary> |
| 141 | + /// Prepares the <see cref="DbBatch"/> for execution in the database. |
| 142 | + /// </summary> |
| 143 | + /// <remarks> |
| 144 | + /// This takes care of hooking the <see cref="DbBatch"/> up to an <see cref="DbConnection"/> |
| 145 | + /// and <see cref="DbTransaction"/> if one exists. It will call <c>Prepare</c> if the Driver |
| 146 | + /// supports preparing batches. |
| 147 | + /// </remarks> |
| 148 | + protected void Prepare(DbBatch batch) |
| 149 | + { |
| 150 | + try |
| 151 | + { |
| 152 | + var sessionConnection = _connectionManager.GetConnection(); |
| 153 | + |
| 154 | + if (batch.Connection != null) |
| 155 | + { |
| 156 | + // make sure the commands connection is the same as the Sessions connection |
| 157 | + // these can be different when the session is disconnected and then reconnected |
| 158 | + if (batch.Connection != sessionConnection) |
| 159 | + { |
| 160 | + batch.Connection = sessionConnection; |
| 161 | + } |
| 162 | + } |
| 163 | + else |
| 164 | + { |
| 165 | + batch.Connection = sessionConnection; |
| 166 | + } |
| 167 | + |
| 168 | + _connectionManager.EnlistInTransaction(batch); |
| 169 | + (Driver as IDriverWithBatchSupport).PrepareBatch(batch); |
| 170 | + } |
| 171 | + catch (InvalidOperationException ioe) |
| 172 | + { |
| 173 | + throw new ADOException("While preparing " + string.Join(Environment.NewLine, batch.BatchCommands.Select(x=>x.CommandText)) + " an error occurred", ioe); |
| 174 | + } |
| 175 | + } |
| 176 | +#endif |
| 177 | + |
138 | 178 | public virtual DbCommand PrepareBatchCommand(CommandType type, SqlString sql, SqlType[] parameterTypes)
|
139 | 179 | {
|
140 | 180 | if (sql.Equals(_batchCommandSql) && ArrayHelper.ArrayEquals(parameterTypes, _batchCommandParameterTypes))
|
|
0 commit comments