Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[CONJS-240] ensuring PREPARE state when caching
- Loading branch information
Showing
10 changed files
with
305 additions
and
139 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 @@ | ||
| 'use strict'; | ||
|
|
||
| const PrepareWrapper = require('./prepare-wrapper'); | ||
|
|
||
| /** | ||
| * Prepare cache wrapper | ||
| * see https://mariadb.com/kb/en/com_stmt_prepare/#com_stmt_prepare_ok | ||
| */ | ||
| class PrepareCacheWrapper { | ||
| #use = 0; | ||
| #cached; | ||
| #prepare; | ||
|
|
||
| constructor(prepare) { | ||
| this.#prepare = prepare; | ||
| this.#cached = true; | ||
| } | ||
|
|
||
| incrementUse() { | ||
| this.#use += 1; | ||
| return new PrepareWrapper(this, this.#prepare); | ||
| } | ||
|
|
||
| unCache() { | ||
| this.#cached = false; | ||
| if (this.#use === 0) { | ||
| this.#prepare.close(); | ||
| } | ||
| } | ||
|
|
||
| decrementUse() { | ||
| this.#use -= 1; | ||
| if (this.#use === 0 && !this.#cached) { | ||
| this.#prepare.close(); | ||
| } | ||
| } | ||
|
|
||
| toString() { | ||
| return 'Prepare{use:' + this.#use + ',cached:' + this.#cached + '}'; | ||
| } | ||
| } | ||
|
|
||
| module.exports = PrepareCacheWrapper; |
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,67 @@ | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Prepare result wrapper | ||
| * This permit to ensure that cache can be close only one time cache. | ||
| */ | ||
| class PrepareWrapper { | ||
| #closed = false; | ||
| #cacheWrapper; | ||
| #prepare; | ||
| #conn; | ||
|
|
||
| constructor(cacheWrapper, prepare) { | ||
| this.#cacheWrapper = cacheWrapper; | ||
| this.#prepare = prepare; | ||
| this.#conn = prepare.conn; | ||
| this.execute = this.#prepare.execute; | ||
| this.executeStream = this.#prepare.executeStream; | ||
| } | ||
| get conn() { | ||
| return this.#conn; | ||
| } | ||
|
|
||
| get id() { | ||
| return this.#prepare.id; | ||
| } | ||
|
|
||
| get parameterCount() { | ||
| return this.#prepare.parameterCount; | ||
| } | ||
|
|
||
| get _placeHolderIndex() { | ||
| return this.#prepare._placeHolderIndex; | ||
| } | ||
|
|
||
| get columns() { | ||
| return this.#prepare.columns; | ||
| } | ||
|
|
||
| set columns(columns) { | ||
| this.#prepare.columns = columns; | ||
| } | ||
| get database() { | ||
| return this.#prepare.database; | ||
| } | ||
|
|
||
| get query() { | ||
| return this.#prepare.query; | ||
| } | ||
|
|
||
| isClose() { | ||
| return this.#closed; | ||
| } | ||
|
|
||
| close() { | ||
| if (!this.#closed) { | ||
| this.#closed = true; | ||
| this.#cacheWrapper.decrementUse(); | ||
| } | ||
| } | ||
|
|
||
| toString() { | ||
| return 'PrepareWrapper{closed:' + this.#closed + ',cache:' + this.#cacheWrapper + '}'; | ||
| } | ||
| } | ||
|
|
||
| module.exports = PrepareWrapper; |
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
Oops, something went wrong.