Database Design and Implementation 2ndを読みつつ、Java関連を学んだ足跡

Chapter 2: JDBC

Explicit Transaction Handling

  • JDBCで、setAutoCommit(false)を明示的にすることでトランザクション境界を制御するが、Spring BootなどのFWでは、Controller In/Outでそのようになっているのか

    • @Transactional の宣言的アノテーションを使うと、そのメソッドがトランザクション境界となる
  • この@Transactional のようなアノテーションの仕組み(AOPの実装)は?

    • 実行時にclass fileを書き換える、作成する といった黒魔術的な技術によって支えられている

    • Javaのclass fileはフォーマットがかっちりしているので、ごにょごにょできるわけだ

    • 黒魔術は危険な側面もあるが、便利な側面もある

      However, this picture changes when creating libraries that need to interact with arbitrary code and unknown type hierarchies. In this context, a library implementer must often choose between either requiring a user to implement library-proprietary interfaces or to generate code at runtime when the user’s type hierarchy becomes first known to the library.

      Byte Buddy - runtime code generation for the Java virtual machine

      なるほど。インタフェースを実装してもらうか、ランタイムに情報を集めるしか無い。
      黒魔術によって、POJO化できる。
      が、ソースコードを追ってるとき、裏で何をやってるかわけわからん みたいなことにはなる。

    • Spring Frameworkでは、Proxyという仕組みと呼ばれており、そのインスタンスが実際には実行され、周辺処理が挟み込みされる.

    • AspectJ

    • 参考

© 2022 blah blah blah All Rights Reserved.
Theme by hiero