forked from ralmsdeveloper/EntityFrameworkCore.FirebirdSQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
281 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2017-2018 Rafael Almeida ([email protected]) | ||
* | ||
* EntityFrameworkCore.FirebirdSql | ||
* | ||
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED | ||
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK. | ||
* | ||
* Permission is hereby granted to use or copy this program | ||
* for any purpose, provided the above notices are retained on all copies. | ||
* Permission to modify the code and to distribute modified code is granted, | ||
* provided the above notices are retained, and a notice that the code was | ||
* modified is included with the above copyright notice. | ||
* | ||
*/ | ||
|
||
using System.Linq; | ||
using Microsoft.EntityFrameworkCore; | ||
using Xunit; | ||
|
||
namespace EFCore.FirebirdSql.FunctionalTests | ||
{ | ||
public class TestWithLock | ||
{ | ||
private TestContext CreateContext() => new TestContext(); | ||
|
||
[Fact] | ||
public void Hint_with_lock() | ||
{ | ||
using (var db = CreateContext()) | ||
{ | ||
var query = db | ||
.Set<Author>() | ||
.WithLock() | ||
.Select(p=>new { p.AuthorId, p.Active}) | ||
.ToSql(); | ||
|
||
Assert.Equal( | ||
query, | ||
@"SELECT ""p"".""AuthorId"", ""p"".""Active"" | ||
FROM ""Author"" ""p"" WITH LOCK"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2017-2018 Rafael Almeida ([email protected]) | ||
* | ||
* EntityFrameworkCore.FirebirdSql | ||
* | ||
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED | ||
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK. | ||
* | ||
* Permission is hereby granted to use or copy this program | ||
* for any purpose, provided the above notices are retained on all copies. | ||
* Permission to modify the code and to distribute modified code is granted, | ||
* provided the above notices are retained, and a notice that the code was | ||
* modified is included with the above copyright notice. | ||
* | ||
*/ | ||
|
||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
|
||
namespace Microsoft.EntityFrameworkCore | ||
{ | ||
public static class FbQueryableExtensions | ||
{ | ||
internal static readonly MethodInfo WithLockMethodInfo | ||
= typeof(FbQueryableExtensions) | ||
.GetTypeInfo().GetDeclaredMethods(nameof(WithLock)) | ||
.Single(); | ||
|
||
public static IQueryable<TEntity> WithLock<TEntity>( | ||
this IQueryable<TEntity> source) | ||
where TEntity : class | ||
{ | ||
return source.Provider.CreateQuery<TEntity>( | ||
Expression.Call( | ||
null, | ||
WithLockMethodInfo.MakeGenericMethod(typeof(TEntity)), | ||
source.Expression)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2017-2018 Rafael Almeida ([email protected]) | ||
* | ||
* EntityFrameworkCore.FirebirdSql | ||
* | ||
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED | ||
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK. | ||
* | ||
* Permission is hereby granted to use or copy this program | ||
* for any purpose, provided the above notices are retained on all copies. | ||
* Permission to modify the code and to distribute modified code is granted, | ||
* provided the above notices are retained, and a notice that the code was | ||
* modified is included with the above copyright notice. | ||
* | ||
*/ | ||
|
||
using Microsoft.EntityFrameworkCore.Query.Internal; | ||
using Microsoft.EntityFrameworkCore.Query.ResultOperators.Internal; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query | ||
{ | ||
public class FbCompilationQueryableFactory : RelationalQueryCompilationContextFactory | ||
{ | ||
public FbCompilationQueryableFactory( | ||
QueryCompilationContextDependencies dependencies, | ||
RelationalQueryCompilationContextDependencies relationalDependencies) | ||
: base(dependencies,relationalDependencies) | ||
{ | ||
relationalDependencies | ||
.NodeTypeProviderFactory | ||
.RegisterMethods(WithLockExpressionNode.SupportedMethods, typeof(WithLockExpressionNode)); | ||
} | ||
|
||
public override QueryCompilationContext Create(bool async) | ||
=> async | ||
? new RelationalQueryCompilationContext( | ||
Dependencies, | ||
new AsyncLinqOperatorProvider(), | ||
new AsyncQueryMethodProvider(), | ||
TrackQueryResults) | ||
: new RelationalQueryCompilationContext( | ||
Dependencies, | ||
new LinqOperatorProvider(), | ||
new QueryMethodProvider(), | ||
TrackQueryResults); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
EFCore.FirebirdSql/Query/Operators/WithLockExpressionNode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2017-2018 Rafael Almeida ([email protected]) | ||
* | ||
* EntityFrameworkCore.FirebirdSql | ||
* | ||
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED | ||
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK. | ||
* | ||
* Permission is hereby granted to use or copy this program | ||
* for any purpose, provided the above notices are retained on all copies. | ||
* Permission to modify the code and to distribute modified code is granted, | ||
* provided the above notices are retained, and a notice that the code was | ||
* modified is included with the above copyright notice. | ||
* | ||
*/ | ||
|
||
using System.Collections.Generic; | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
using Remotion.Linq.Clauses; | ||
using Remotion.Linq.Parsing.Structure.IntermediateModel; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query.ResultOperators.Internal | ||
{ | ||
public class WithLockExpressionNode : ResultOperatorExpressionNodeBase | ||
{ | ||
public static readonly IReadOnlyCollection<MethodInfo> SupportedMethods = new[] | ||
{ FbQueryableExtensions.WithLockMethodInfo }; | ||
|
||
public WithLockExpressionNode( | ||
MethodCallExpressionParseInfo parseInfo, | ||
ConstantExpression WithLockExpressionExpression) | ||
: base(parseInfo, null, null) | ||
{ | ||
} | ||
|
||
protected override ResultOperatorBase CreateResultOperator(ClauseGenerationContext clauseGenerationContext) | ||
=> new WithLockResultOperator(); | ||
|
||
public override Expression Resolve( | ||
ParameterExpression inputParameter, | ||
Expression expressionToBeResolved, | ||
ClauseGenerationContext clauseGenerationContext) | ||
=> Source.Resolve(inputParameter, expressionToBeResolved, clauseGenerationContext); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
EFCore.FirebirdSql/Query/Operators/WithLockResultOperator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2017-2018 Rafael Almeida ([email protected]) | ||
* | ||
* EntityFrameworkCore.FirebirdSql | ||
* | ||
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED | ||
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK. | ||
* | ||
* Permission is hereby granted to use or copy this program | ||
* for any purpose, provided the above notices are retained on all copies. | ||
* Permission to modify the code and to distribute modified code is granted, | ||
* provided the above notices are retained, and a notice that the code was | ||
* modified is included with the above copyright notice. | ||
* | ||
*/ | ||
|
||
using System; | ||
using System.Linq.Expressions; | ||
using Remotion.Linq; | ||
using Remotion.Linq.Clauses; | ||
using Remotion.Linq.Clauses.ResultOperators; | ||
using Remotion.Linq.Clauses.StreamedData; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query.ResultOperators.Internal | ||
{ | ||
public class WithLockResultOperator : SequenceTypePreservingResultOperatorBase, IQueryAnnotation | ||
{ | ||
public virtual IQuerySource QuerySource { get; set; } | ||
public virtual QueryModel QueryModel { get; set; } | ||
public virtual string Hint => ToString(); | ||
public override ResultOperatorBase Clone(CloneContext cloneContext) | ||
=> new WithLockResultOperator(); | ||
|
||
public override void TransformExpressions(Func<Expression, Expression> transformation) | ||
{ | ||
} | ||
|
||
public override StreamedSequence ExecuteInMemory<T>(StreamedSequence input) | ||
=> input; | ||
|
||
public override string ToString() => " WITH LOCK"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters