Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move finalizers to private #38

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
@@ -1,6 +1,6 @@
Package: mlr3db
Title: Data Base Backend for 'mlr3'
Version: 0.5.1-9000
Version: 0.5.2
Authors@R:
person(given = "Michel",
family = "Lang",
Expand All @@ -21,7 +21,7 @@ Depends:
mlr3 (>= 0.13.0),
R (>= 3.1.0)
Imports:
R6,
R6 (>= 2.4.0),
backports,
checkmate,
data.table,
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Expand Up @@ -2,6 +2,7 @@

- Bugfix: `DataBackendDuckDB` calculated missing values incorrectly.
- Compatibility with future versions of `dbplyr` (#35).
- Finalizers are now private

# mlr3db 0.5.1

Expand Down
20 changes: 10 additions & 10 deletions R/DataBackendDplyr.R
Expand Up @@ -120,16 +120,6 @@ DataBackendDplyr = R6Class("DataBackendDplyr", inherit = DataBackend, cloneable
self$connector = assert_function(connector, args = character(), null.ok = TRUE)
},

#' @description
#' Finalizer which disconnects from the database.
#' This is called during garbage collection of the instance.
#' @return `logical(1)`, the return value of [DBI::dbDisconnect()].
finalize = function() {
if (isTRUE(self$valid)) {
DBI::dbDisconnect(private$.data$src$con)
}
},

#' @description
#' Returns a slice of the data.
#' Calls [dplyr::filter()] and [dplyr::select()] on the table and converts it to a [data.table::data.table()].
Expand Down Expand Up @@ -271,6 +261,16 @@ DataBackendDplyr = R6Class("DataBackendDplyr", inherit = DataBackend, cloneable
),

private = list(
# @description
# Finalizer which disconnects from the database.
# This is called during garbage collection of the instance.
# @return `logical(1)`, the return value of [DBI::dbDisconnect()].
finalize = function() {
if (isTRUE(self$valid)) {
DBI::dbDisconnect(private$.data$src$con)
}
},

.calculate_hash = function() {
private$.reconnect()
calculate_hash(private$.data)
Expand Down
20 changes: 10 additions & 10 deletions R/DataBackendDuckDB.R
Expand Up @@ -73,16 +73,6 @@ DataBackendDuckDB = R6Class("DataBackendDuckDB", inherit = DataBackend, cloneabl

},

#' @description
#' Finalizer which disconnects from the database.
#' This is called during garbage collection of the instance.
#' @return `logical(1)`, the return value of [DBI::dbDisconnect()].
finalize = function() {
if (isTRUE(self$valid)) {
DBI::dbDisconnect(private$.data, shutdown = TRUE)
}
},

#' @description
#' Returns a slice of the data.
#'
Expand Down Expand Up @@ -243,6 +233,16 @@ DataBackendDuckDB = R6Class("DataBackendDuckDB", inherit = DataBackend, cloneabl
),

private = list(
# @description
# Finalizer which disconnects from the database.
# This is called during garbage collection of the instance.
# @return `logical(1)`, the return value of [DBI::dbDisconnect()].
finalize = function() {
if (isTRUE(self$valid)) {
DBI::dbDisconnect(private$.data, shutdown = TRUE)
}
},

.calculate_hash = function() {
private$.reconnect()
calculate_hash(private$.data@driver@dbdir)
Expand Down
15 changes: 0 additions & 15 deletions man/DataBackendDplyr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions man/DataBackendDuckDB.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/helper.R
Expand Up @@ -29,7 +29,7 @@ disconnect.SQLiteConnection = function(x) {
registerS3method("disconnect", "SQLiteConnection", disconnect.SQLiteConnection)

disconnect.DataBackend = function(x) {
x$finalize()
mlr3misc::get_private(x)$finalize()
}
registerS3method("disconnect", "DataBackend", disconnect.DataBackend)

Expand Down