| | | 1 | | /* |
| | | 2 | | * Copyright 2017 Stanislav Muhametsin. All rights Reserved. |
| | | 3 | | * |
| | | 4 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
| | | 5 | | * you may not use this file except in compliance with the License. |
| | | 6 | | * You may obtain a copy of the License at |
| | | 7 | | * |
| | | 8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
| | | 9 | | * |
| | | 10 | | * Unless required by applicable law or agreed to in writing, software |
| | | 11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
| | | 12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| | | 13 | | * implied. |
| | | 14 | | * |
| | | 15 | | * See the License for the specific language governing permissions and |
| | | 16 | | * limitations under the License. |
| | | 17 | | */ |
| | | 18 | | using AsyncEnumeration.Abstractions; |
| | | 19 | | using AsyncEnumeration.Implementation.Enumerable; |
| | | 20 | | using CBAM.Abstractions.Implementation; |
| | | 21 | | using System; |
| | | 22 | | using System.Collections.Generic; |
| | | 23 | | using System.Text; |
| | | 24 | | using System.Threading; |
| | | 25 | | using System.Threading.Tasks; |
| | | 26 | | using UtilPack; |
| | | 27 | | |
| | | 28 | | namespace CBAM.SQL.Implementation |
| | | 29 | | { |
| | | 30 | | using TStatementExecutionTaskParameter = System.ValueTuple<SQLStatementExecutionResult, Func<ValueTask<(Boolean, SQLS |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// This class extends <see cref="ConnectionFunctionalitySU{TStatement, TStatementInformation, TStatementCreationArgs |
| | | 34 | | /// </summary> |
| | | 35 | | /// <typeparam name="TVendor">The actual type of <see cref="SQLConnectionVendorFunctionality"/>.</typeparam> |
| | | 36 | | public abstract class SQLConnectionFunctionalitySU<TVendor> : ConnectionFunctionalitySU<SQLStatementBuilder, SQLState |
| | | 37 | | where TVendor : SQLConnectionVendorFunctionality |
| | | 38 | | { |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Initializes new instance of <see cref="SQLConnectionFunctionalitySU{TVendor}"/> with given vendor. |
| | | 42 | | /// </summary> |
| | | 43 | | /// <param name="vendor">The vendor functionality.</param> |
| | | 44 | | /// <param name="asyncProvider">The <see cref="IAsyncProvider"/> to use.</param> |
| | | 45 | | public SQLConnectionFunctionalitySU( TVendor vendor, IAsyncProvider asyncProvider ) |
| | 24 | 46 | | : base( vendor, asyncProvider ) |
| | | 47 | | { |
| | 24 | 48 | | } |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// This method implements <see cref="ConnectionFunctionalitySU{TStatement, TStatementInformation, TStatementCreat |
| | | 52 | | /// </summary> |
| | | 53 | | /// <param name="stmt">The <see cref="SQLStatementBuilderInformation"/> to use.</param> |
| | | 54 | | /// <param name="reservationObject">The <see cref="ReservedForStatement"/> object of this execution.</param> |
| | | 55 | | /// <returns>The result of <see cref="ExecuteStatementAsBatch(SQLStatementBuilderInformation, ReservedForStatement |
| | | 56 | | protected override async ValueTask<(SQLStatementExecutionResult, Boolean, Func<ValueTask<(Boolean, SQLStatementExe |
| | | 57 | | { |
| | 91 | 58 | | var retVal = await ( stmt.HasBatchParameters() ? |
| | 91 | 59 | | this.ExecuteStatementAsBatch( stmt, reservationObject ) : ( |
| | 91 | 60 | | stmt.SQLParameterCount > 0 ? |
| | 91 | 61 | | this.ExecuteStatementAsPrepared( stmt, reservationObject ) : |
| | 91 | 62 | | this.ExecuteStatementAsSimple( stmt, reservationObject ) |
| | 91 | 63 | | ) ); |
| | | 64 | | |
| | 98 | 65 | | return (retVal.Item1, retVal.Item1 != null, retVal.Item2); |
| | 98 | 66 | | } |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// Implements <see cref="DefaultConnectionFunctionality{TStatement, TStatementInformation, TStatementCreationArgs |
| | | 70 | | /// </summary> |
| | | 71 | | /// <param name="statement">The <see cref="SQLStatementBuilder"/>.</param> |
| | | 72 | | /// <returns>The result of <see cref="SQLStatementBuilder.StatementBuilderInformation"/>.</returns> |
| | | 73 | | protected override SQLStatementBuilderInformation GetInformationFromStatement( SQLStatementBuilder statement ) |
| | | 74 | | { |
| | 94 | 75 | | return statement?.StatementBuilderInformation; |
| | | 76 | | } |
| | | 77 | | |
| | | 78 | | /// <summary> |
| | | 79 | | /// Derived classes should implement this method in order to execute <see cref="SQLStatementBuilderInformation"/> |
| | | 80 | | /// </summary> |
| | | 81 | | /// <param name="stmt">The <see cref="SQLStatementBuilderInformation"/> to use.</param> |
| | | 82 | | /// <param name="reservationObject">The <see cref="ReservedForStatement"/> object of this execution.</param> |
| | | 83 | | /// <returns>Asynchronously returns the tuple of <see cref="SQLStatementExecutionResult"/> resulted from executing |
| | | 84 | | protected abstract ValueTask<TStatementExecutionTaskParameter> ExecuteStatementAsSimple( SQLStatementBuilderInform |
| | | 85 | | |
| | | 86 | | /// <summary> |
| | | 87 | | /// Derived classes should implement this method in order to execute <see cref="SQLStatementBuilderInformation"/> |
| | | 88 | | /// </summary> |
| | | 89 | | /// <param name="stmt">The <see cref="SQLStatementBuilderInformation"/> to use.</param> |
| | | 90 | | /// <param name="reservationObject">The <see cref="ReservedForStatement"/> object of this execution.</param> |
| | | 91 | | /// <returns>Asynchronously returns the tuple of <see cref="SQLStatementExecutionResult"/> resulted from executing |
| | | 92 | | protected abstract ValueTask<TStatementExecutionTaskParameter> ExecuteStatementAsPrepared( SQLStatementBuilderInfo |
| | | 93 | | |
| | | 94 | | /// <summary> |
| | | 95 | | /// Derived classes should implement this method in order to execute <see cref="SQLStatementBuilderInformation"/> |
| | | 96 | | /// </summary> |
| | | 97 | | /// <param name="stmt">The <see cref="SQLStatementBuilderInformation"/> to use.</param> |
| | | 98 | | /// <param name="reservationObject">The <see cref="ReservedForStatement"/> object of this execution.</param> |
| | | 99 | | /// <returns>Asynchronously returns the tuple of <see cref="SQLStatementExecutionResult"/> resulted from executing |
| | | 100 | | protected abstract ValueTask<TStatementExecutionTaskParameter> ExecuteStatementAsBatch( SQLStatementBuilderInforma |
| | | 101 | | |
| | | 102 | | } |
| | | 103 | | |
| | | 104 | | } |