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

Utility improvements #85

Merged
merged 8 commits into from
Jan 15, 2025
Merged

Utility improvements #85

merged 8 commits into from
Jan 15, 2025

Conversation

AugustNagro
Copy link
Owner

@AugustNagro AugustNagro commented Dec 7, 2024

  • Add connect & transact methods directly on Transactor
  • Add commonly used classes under magnum.common.* export, so users don't get swamped by every class living in the magnum package
  • Add magzio.Transactor.semaphore to save memory when not using the Virtual-Thread based blocking executor

Closes #76
Closes #77
Closes #74

Todo: Update readme MR

please review @guizmaii

Unverified

No user is associated with the committer email.
* Add connect & transact methods directly on Transactor
* Add commonly used classes under magnum.common.* export, so users don't get swamped by every class living in the magnum package
* Add magzio.Transactor.semaphore to save memory when not using the Virtual-Thread based blocking executor
* Add .uninteruptable to magzio.Transactor.connect method like it is for Transactor, remove null check
import scala.reflect.ClassTag
import scala.util.control.{ControlThrowable, NonFatal}

class Transactor private (
Copy link
Contributor

@guizmaii guizmaii Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows for more JIT optimisation and it's not supposed to be extended anyway

Suggested change
class Transactor private (
final class Transactor private (

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's actually not a single final keyword in the magnum codebase despite almost every class NOT being designed for extension. So to be consistent, we would want to make this change almost everywhere. (I'd like to defer to separate MR for that reason).

The two exceptions are Repo and ImmutableRepo, which are declared open. (I do prefer composition over inheritance when using these, and will update the docs to show an example , but it's nice to support extension like you can do in Spring Data).

https://docs.scala-lang.org/scala3/reference/other-new-features/open-classes.html

My thought is that open is much better than final, since a whitelist is more restrictive than blacklist, and less work. And in Scala 3.4+ extending a class that isn't open results in a feature warning.

I don't think I agree that adding the final keyword to a class will improve performance (at least, I can't seem to find any articles about it online). I do agree with final fields (haha, but even then the JVM can have trust issues.. https://shipilev.net/jvm/anatomy-quarks/17-trust-nonstatic-final-fields/ )

*/
case class Transactor(
/** Datasource to be used */
class Transactor private (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class Transactor private (
final class Transactor private (

Copy link
Contributor

@guizmaii guizmaii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments/suggestions

guizmaii and others added 5 commits January 14, 2025 20:05
@AugustNagro
Copy link
Owner Author

Thanks for the review @guizmaii . I'll go ahead and merge; we can address the final question in another MR if need be.

@AugustNagro AugustNagro merged commit 31de10b into master Jan 15, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants