_images/doma.png

Welcome to DomaĀ¶

Doma ćÆ Java 恮DBć‚¢ć‚Æć‚»ć‚¹ćƒ•ćƒ¬ćƒ¼ćƒ ćƒÆćƒ¼ć‚Æ恧恙怂

Doma ć®ćƒćƒ¼ć‚øćƒ§ćƒ³ć«ćÆ 1 ćØ 2 ćŒć‚ć‚Šć¾ć™ćŒć€ ć“ć®ćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆćÆ ćƒćƒ¼ć‚øćƒ§ćƒ³ 2 悒åÆ¾č±”ćØć—ć¦ć„ć¾ć™ć€‚

Doma 2 恫ćÆ仄äø‹ć®ē‰¹å¾“ćŒć‚ć‚Šć¾ć™ć€‚

  • ę³Ø釈処ē†ć‚’ä½æē”Ø恗恦 ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ę™‚ ć«ć‚³ćƒ¼ćƒ‰ć®ē”Ÿęˆć‚„ć‚³ćƒ¼ćƒ‰ć®ę¤œčØ¼ć‚’č”Œć†
  • ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹äøŠć®ć‚«ćƒ©ćƒ ć®å€¤ć‚’ęŒÆć‚‹čˆžć„ć‚’ęŒć£ćŸ Java ć‚Ŗ惖ć‚ø悧ć‚Æćƒˆć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć§ćć‚‹
  • 2-way SQL ćØå‘¼ć°ć‚Œć‚‹ SQL ćƒ†ćƒ³ćƒ—ćƒ¬ćƒ¼ćƒˆć‚’åˆ©ē”Ø恧恍悋
  • Java 8 恮 java.time.LocalDate 悄 java.util.Optional 悄 java.util.stream.Stream ć‚’åˆ©ē”Ø恧恍悋
  • JRE ä»„å¤–ć®ćƒ©ć‚¤ćƒ–ćƒ©ćƒŖćøć®ä¾å­˜ćŒäø€åˆ‡ćŖ恄

ć“ć®ćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆćÆ複ꕰ恮悻ć‚Æć‚·ćƒ§ćƒ³ć‹ć‚‰ęˆć‚Šć¾ć™ć€‚

User DocumentationĀ¶

Getting StartedĀ¶

ꦂ要Ā¶

開ē™ŗē’°å¢ƒć®ć‚»ćƒƒćƒˆć‚¢ćƒƒćƒ—ę–¹ę³•ćØåŸŗęœ¬ēš„ćŖćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć‚¢ć‚Æć‚»ć‚¹ć®å®Ÿč”Œę–¹ę³•ć‚’ē“¹ä»‹ć—ć¾ć™ć€‚

ćƒŽćƒ¼ćƒˆ

ć“ć®ćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆć§ćÆ态IDE ćØ恗恦 Eclipse 悒ē”Øć„ć¾ć™ćŒć€ Eclipse ć®ä»£ć‚ć‚Šć« IntelliJ IDEA ć‚’åˆ©ē”Ø恗恦開ē™ŗ恙悋恓ćØ悂åÆčƒ½ć§ć™ć€‚ IntelliJ IDEA ć‚’åˆ©ē”Øć™ć‚‹å “åˆćÆ态 IntelliJ Doma support plugin ć®ä½µē”Ø悒恊å„Øć‚ć—ć¾ć™ć€‚

JDK ć®ć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«Ā¶

JDK 8 ć‚’ć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«ć—ć¦ćć ć•ć„ć€‚

Eclipse ć®ć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«Ā¶

Eclipse Standard 4.4 ć‚’ć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«ć—ć¦ćć ć•ć„ć€‚

ćƒŽćƒ¼ćƒˆ

Eclipse IDE for Java EE Developers ćŖć©ä»–ć®ćƒ‘ćƒƒć‚±ćƒ¼ć‚øć§ć‚‚å‹•ä½œć—ć¾ć™ćŒ ć“ć®ćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆć§ćÆ Eclipse Standard 悒åÆ¾č±”ćØć—ć¾ć™ć€‚

Eclipse ćƒ—ćƒ©ć‚°ć‚¤ćƒ³ Doma Tools ć®ć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«Ā¶

Doma Tools ćÆ Java ćƒ•ć‚”ć‚¤ćƒ«ćØ SQL ćƒ•ć‚”ć‚¤ćƒ«ć®ē›øäŗ’遷ē§»ć‚’åÆčƒ½ć«ć™ć‚‹ćƒ—ćƒ©ć‚°ć‚¤ćƒ³ć§ć™ć€‚ Doma ć®åˆ©ē”Ø恫åæ…é ˆć§ćÆć‚ć‚Šć¾ć›ć‚“ćŒć€ć“ć®ćƒ—ćƒ©ć‚°ć‚¤ćƒ³ć‚’ä½æē”Ø恙悋ćØē”Ÿē”£ę€§ćŒé«˜ć¾ć‚Šć¾ć™ć€‚

Eclipse ćƒ”ćƒ‹ćƒ„ćƒ¼ćƒćƒ¼ć‹ć‚‰ Help > Install New Software... ćØ進ćæ态 ‘Work With’ ć®ćƒ†ć‚­ć‚¹ćƒˆćƒœćƒƒć‚Æć‚¹ć«ę¬”ć®URLć‚’å…„åŠ›ć—ć¦ćć ć•ć„ć€‚

http://dl.bintray.com/domaframework/eclipse/

仄äø‹ć®å›³ć®ć‚ˆć†ć«ć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«åÆčƒ½ćŖćƒ—ćƒ©ć‚°ć‚¤ćƒ³ć®å€™č£œćŒč”Øē¤ŗć•ć‚Œć‚‹ć®ć§ Doma Tools ć®ęœ€ę–°ćƒćƒ¼ć‚øćƒ§ćƒ³ć«ćƒć‚§ćƒƒć‚Æć‚’ć¤ć‘ć¦ćƒ€ć‚¤ć‚¢ćƒ­ć‚°ć‚’é€²ć‚ ć‚¤ćƒ³ć‚¹ćƒ¼ćƒˆćƒ«ć‚’å®Œäŗ†ć—ć¦ćć ć•ć„ć€‚

_images/install-doma-tools.png

ćƒ•ć‚”ć‚¤ćƒ«ć®é–¢é€£ć„ć‘Ā¶

Doma Tools ćÆ态 SQL ćƒ•ć‚”ć‚¤ćƒ«ć®ę›“ę–°ć‚’ćƒ•ćƒƒć‚Æ恗恦ę³Ø釈処ē†ć‚’å®Ÿč”Œć—ć¾ć™ć€‚ ćć®ćŸć‚ć«ćÆ态 SQL ćƒ•ć‚”ć‚¤ćƒ«ć‚’ Eclipse å†…ć§é–‹ćåæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚

ćƒ”ćƒ‹ćƒ„ćƒ¼ćƒćƒ¼ć‹ć‚‰ Eclipse > ē’°å¢ƒčح定... 悂恗恏ćÆ Window > Preference ćØéøꊞ恗态čح定ē”»é¢ć‚’é–‹ć„ć¦ćć ć•ć„ć€‚

仄äø‹ć®å›³ćŒē¤ŗć™ć‚ˆć†ć« .sql ć®ę‹”å¼µå­ć‚’ć‚‚ć¤ćƒ•ć‚”ć‚¤ćƒ«ć‚’ Text Editor ć«é–¢é€£ć„ć‘ć¦ćć ć•ć„ć€‚

_images/sql-file-association.png

åŒę§˜ć« .script ć®ę‹”å¼µå­ć‚’ć‚‚ć¤ćƒ•ć‚”ć‚¤ćƒ«ć‚’ Text Editor ć«é–¢é€£ć„ć‘ć¦ćć ć•ć„ć€‚

_images/script-file-association.png

ćƒŽćƒ¼ćƒˆ

Eclipse IDE for Java EE Developers ć‚’åˆ©ē”Øć™ć‚‹å “åˆćÆ态 ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§SQLćƒ•ć‚”ć‚¤ćƒ«ćŒå°‚ē”Ø恮ć‚Øćƒ‡ć‚£ć‚æć«é–¢é€£ć„ć‘ć‚‰ć‚Œć¦ć„ć‚‹ćŸć‚ ć“ć®ę‰‹é †ć‚’ć‚¹ć‚­ćƒƒćƒ—ć§ćć¾ć™ć€‚

ćƒŽćƒ¼ćƒˆ

SQL ćÆ RDBMS å›ŗęœ‰ć®ćƒ„ćƒ¼ćƒ«ļ¼ˆOracle SQL Developer 悄 pgAdminļ¼‰ć§ä½œęˆć—态 å®Œęˆć—ćŸć‚‚ć®ć‚’ Eclipse 恮ć‚Øćƒ‡ć‚£ć‚æćƒ¼ć«ć‚³ćƒ”ćƒ¼ć™ć‚‹ćØć„ć£ćŸ 開ē™ŗć‚¹ć‚æć‚¤ćƒ«ć‚’ćŠå„Øć‚ć—ć¾ć™ć€‚

é››å½¢ćƒ—ćƒ­ć‚ø悧ć‚Æćƒˆć®ć‚¤ćƒ³ćƒćƒ¼ćƒˆĀ¶

GitHub 恋悉 simple-boilerplate 悒 clone ć—ć¦ćć ć•ć„ć€‚

$ git clone https://github.com/domaframework/simple-boilerplate.git

clone ć•ć‚ŒćŸćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖ恫ē§»å‹•ć—ć¾ć™ć€‚

$ cd simple-boilerplate

ę¬”ć®ć‚³ćƒžćƒ³ćƒ‰ć§ Eclipse ē”Ø恮čØ­å®šćƒ•ć‚”ć‚¤ćƒ«ć‚’ē”Ÿęˆć—ć¾ć™ć€‚

$ ./gradlew eclipse

ćƒŽćƒ¼ćƒˆ

Windows ē’°å¢ƒć§ćÆ ./gradlew eclipse ćØć™ć‚‹ä»£ć‚ć‚Šć« gradlew eclipse ćØć—ć¦ćć ć•ć„ć€‚

ćƒŽćƒ¼ćƒˆ

ē’°å¢ƒå¤‰ę•° JAVA_HOME 恫 JDK 8 ć‚’ć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«ć—ćŸćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖ悒čØ­å®šć—ć¦ćŠć„ć¦ćć ć•ć„ć€‚ gradlew ć®å®Ÿč”Œć«åæ…要恧恙怂

Eclipse ć®ćƒ”ćƒ‹ćƒ„ćƒ¼ć‹ć‚‰File > Import... ć‚’å®Ÿč”Œć— ‘Existing Projects into Workspace’ 悒éø悓恧 simple-boilerplate ć‚’ć‚¤ćƒ³ćƒćƒ¼ćƒˆć—ć¾ć™ć€‚

_images/import.png

ć‚¤ćƒ³ćƒćƒ¼ćƒˆćŒęˆåŠŸć—ćŸć“ćØ悒ē¢ŗčŖć™ć‚‹ćŸć‚ć«ćƒ—ćƒ­ć‚ø悧ć‚Æ惈悒éøꊞ恗恦 JUnit ć‚’å®Ÿč”Œć—ć¦ćć ć•ć„ć€‚ ćƒ†ć‚¹ćƒˆćŒ1ä»¶ęˆåŠŸć™ć‚Œć°ę­£åøøć«ć‚¤ćƒ³ćƒćƒ¼ćƒˆć§ćć¦ć„ć¾ć™ć€‚

é››å½¢ćƒ—ćƒ­ć‚ø悧ć‚Æćƒˆć®ę§‹ęˆĀ¶

惗惭ć‚ø悧ć‚Æćƒˆć®ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ć®ę§‹ęˆćÆę¬”ć®ć‚ˆć†ć«ćŖć£ć¦ć„ć¾ć™ć€‚

ā”€ src
  ā”œā”€ā”€ main
  ā”‚Ā Ā  ā”œā”€ā”€ java
  ā”‚Ā Ā  ā”‚Ā Ā  ā””ā”€ā”€ boilerplate
  ā”‚Ā Ā  ā”‚Ā Ā      ā”œā”€ā”€ AppConfig.java
  ā”‚Ā Ā  ā”‚Ā Ā      ā”œā”€ā”€ dao
  ā”‚Ā Ā  ā”‚Ā Ā      ā”‚Ā Ā  ā”œā”€ā”€ AppDao.java
  ā”‚Ā Ā  ā”‚Ā Ā      ā”‚Ā Ā  ā””ā”€ā”€ EmployeeDao.java
  ā”‚Ā Ā  ā”‚Ā Ā      ā””ā”€ā”€ entity
  ā”‚Ā Ā  ā”‚Ā Ā          ā””ā”€ā”€ Employee.java
  ā”‚Ā Ā  ā””ā”€ā”€ resources
  ā”‚Ā Ā      ā””ā”€ā”€ META-INF
  ā”‚Ā Ā          ā””ā”€ā”€ boilerplate
  ā”‚Ā Ā              ā””ā”€ā”€ dao
  ā”‚Ā Ā                  ā”œā”€ā”€ AppDao
  ā”‚Ā Ā                  ā”‚Ā Ā  ā”œā”€ā”€ create.script
  ā”‚Ā Ā                  ā”‚Ā Ā  ā””ā”€ā”€ drop.script
  ā”‚Ā Ā                  ā””ā”€ā”€ EmployeeDao
  ā”‚Ā Ā                      ā”œā”€ā”€ selectAll.sql
  ā”‚Ā Ā                      ā””ā”€ā”€ selectById.sql
  ā””ā”€ā”€ test
      ā”œā”€ā”€ java
      ā”‚Ā Ā  ā””ā”€ā”€ boilerplate
      ā”‚Ā Ā      ā”œā”€ā”€ DbResource.java
      ā”‚Ā Ā      ā””ā”€ā”€ dao
      ā”‚Ā Ā          ā””ā”€ā”€ EmployeeDaoTest.java
      ā””ā”€ā”€ resources

äø»č¦ćŖ悂恮恫恤恄恦čŖ¬ę˜Žć—ć¾ć™ć€‚

AppConfig.java
Doma ć‚’å®Ÿč”Œć™ć‚‹ćŸć‚ć«åæ…要ćŖ čح定 恧恙怂
AppDao.java
ć“ć®ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć§åˆ©ē”Øć™ć‚‹ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć®ć‚¹ć‚­ćƒ¼ćƒžć‚’å®Ÿč”Œę™‚ć«ä½œęˆ/ē “ę£„ć™ć‚‹ćƒ¦ćƒ¼ćƒ†ć‚£ćƒŖćƒ†ć‚£ć§ć™ć€‚ 実ē’°å¢ƒć§ćÆäøč¦ć«ćŖć‚Šć¾ć™ć€‚ ć‚¹ć‚­ćƒ¼ćƒžć®ä½œęˆćØē “ę£„ć«ćÆ META-INF/boilerplate/dao/AppDao/ 仄äø‹ć®ć‚¹ć‚ÆćƒŖćƒ—ćƒˆćƒ•ć‚”ć‚¤ćƒ«ć‚’ä½æē”Øć—ć¾ć™ć€‚
Employee.java
ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć® EMPLOYEE ćƒ†ćƒ¼ćƒ–ćƒ«ć«åƾåæœć™ć‚‹ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ 恧恙怂
EmployeeDao.java
Employee ć‚Æćƒ©ć‚¹ć®å–å¾—ć‚„ę›“ę–°ćŖć©ć‚’č”Œć† Daoć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ 恧恙怂 META-INF/boilerplate/dao/EmployeeDao/ 仄äø‹ć® SQLćƒ•ć‚”ć‚¤ćƒ« 悒ä½æē”Øć—ć¾ć™ć€‚
EmployeeDaoTest.java
EmployeeDao 悒ä½æć£ćŸćƒ†ć‚¹ćƒˆć§ć™ć€‚ ć“ć®ćƒ•ć‚”ć‚¤ćƒ«ć«ćƒ†ć‚¹ćƒˆć‚±ćƒ¼ć‚¹ć‚’čæ½åŠ ć—ćŖ恌悉 Doma ć®å­¦ēæ’ćŒć§ćć¾ć™ć€‚ ćƒ†ć‚¹ćƒˆćƒ”ć‚½ćƒƒćƒ‰ć”ćØć«ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć‚¹ć‚­ćƒ¼ćƒžć®ä½œęˆćØē “ę£„ć‚’č”Œć£ć¦ć„ć‚‹ćŸć‚ ćƒ‡ćƒ¼ć‚æć®ę›“ę–°ć«ć‚ˆć£ć¦ä»–ć®ćƒ†ć‚¹ćƒˆćŒå½±éŸæć‚’å—ć‘ć‚‹ć“ćØćÆć‚ć‚Šć¾ć›ć‚“ć€‚

Java ćØ SQL 恮ē›øäŗ’遷ē§»Ā¶

EmployeeDao.java 恧ćÆę¬”ć®ć‚ˆć†ć«å®šē¾©ć•ć‚Œć¦ć„ć¾ć™ć€‚

@Dao(config = AppConfig.class)
public interface EmployeeDao {

    @Select
    List<Employee> selectAll();

    @Select
    Employee selectById(Integer id);

    @Insert
    int insert(Employee employee);

    @Update
    int update(Employee employee);

    @Delete
    int delete(Employee employee);

}

Eclipse 恮ć‚Øćƒ‡ć‚£ć‚æäøŠć§ selectById ćƒ”ć‚½ćƒƒćƒ‰ć«ć‚«ćƒ¼ć‚½ćƒ«ć‚’åˆć‚ć›å³ć‚ÆćƒŖ惃ć‚ÆćŖ恩恧 ć‚³ćƒ³ćƒ†ć‚­ć‚¹ćƒˆćƒ”ćƒ‹ćƒ„ćƒ¼ć‚’č”Øē¤ŗć•ć›ć¦ćć ć•ć„ć€‚ ćƒ”ćƒ‹ćƒ„ćƒ¼ć®äø­ć‹ć‚‰ Doma > Jump to SQL 悒éøꊞ恙悋ćØ META-INF/boilerplate/dao/EmployeeDao/selectById.sql ćƒ•ć‚”ć‚¤ćƒ«ćø遷ē§»ć§ćć¾ć™ć€‚

ꬔ恫态META-INF/boilerplate/dao/EmployeeDao/selectById.sql ćƒ•ć‚”ć‚¤ćƒ«ć®ä»»ę„ć®å “ę‰€ć« ć‚«ćƒ¼ć‚½ćƒ«ć‚’ē½®ćć€ć‚³ćƒ³ćƒ†ć‚­ć‚¹ćƒˆćƒ”ćƒ‹ćƒ„ćƒ¼ć‚’č”Øē¤ŗć•ć›ć¦ćć ć•ć„ć€‚ ćƒ”ćƒ‹ćƒ„ćƒ¼ć®äø­ć‹ć‚‰ Doma > Jump to Java 悒éøꊞ恙悋ćØ EmployeeDao.java ćƒ•ć‚”ć‚¤ćƒ«ćøęˆ»ć£ć¦ć“ć‚‰ć‚Œć¾ć™ć€‚

SQL ćƒ•ć‚”ć‚¤ćƒ«Ā¶

META-INF/boilerplate/dao/EmployeeDao/selectById.sql ćƒ•ć‚”ć‚¤ćƒ«ć‚’é–‹ć„ć¦ćć ć•ć„ć€‚ ć“ć®ćƒ•ć‚”ć‚¤ćƒ«ć«ćÆę¬”ć®ć‚ˆć†ć«čؘčæ°ć•ć‚Œć¦ć„ć¾ć™ć€‚

select
    /*%expand*/*
from
    employee
where
    id = /* id */0

/*%expand*/ ćÆ Java ćƒ”ć‚½ćƒƒćƒ‰ć§ćƒžćƒƒćƒƒćƒ”ćƒ³ć‚°ć•ć‚ŒćŸ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć®å®šē¾©ć‚’参ē…§ć—ć¦ć‚«ćƒ©ćƒ ćƒŖć‚¹ćƒˆć‚’å±•é–‹ć™ć‚‹ć“ćØ悒ē¤ŗć—ć¦ć„ć¾ć™ć€‚

/* id */ ćÆ Java ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®å€¤ćŒć“ć® SQL ćøćƒć‚¤ćƒ³ćƒ‰ć•ć‚Œć‚‹ć“ćØ悒 ē¤ŗć—ć¦ć„ć¾ć™ć€‚

å¾Œć‚ć«ć‚ć‚‹ 0 ćÆćƒ†ć‚¹ćƒˆē”Øć®ćƒ‡ćƒ¼ć‚æ恧恙怂 ć“ć®ćƒ†ć‚¹ćƒˆćƒ‡ćƒ¼ć‚æć‚’å«ć‚ć‚‹ć“ćØ恧态 SQL ć‚’ćƒ„ćƒ¼ćƒ«ć§å®Ÿč”Œć—ć¦ę§‹ę–‡äøŠć® čŖ¤ć‚ŠćŒćŖ恄恓ćØć‚’å®¹ę˜“ć«ē¢ŗčŖć§ćć¾ć™ć€‚ ćƒ†ć‚¹ćƒˆē”Øć®ćƒ‡ćƒ¼ć‚æćÆ Java ćƒ—ćƒ­ć‚°ćƒ©ćƒ å®Ÿč”Œę™‚ć«ćÆä½æć‚ć‚Œć¾ć›ć‚“ć€‚

č©³ē“°ć«ć¤ć„恦ćÆ态 SQL ć‚’å‚ē…§ć—ć¦ćć ć•ć„ć€‚

ꤜē“¢Ā¶

ꤜē“¢ 処ē†ć‚’å®Ÿč”Œć™ć‚‹ć«ćÆ态 @Select 恌ę³Ø釈恕悌恟 Dao ćƒ”ć‚½ćƒƒćƒ‰ć‚’å‘¼ć³å‡ŗć—ć¾ć™ć€‚

ꤜē“¢å‡¦ē†ć®čæ½åŠ Ā¶

ć‚ć‚‹å¹“é½¢ć‚ˆć‚Šå°ć•ć„å¾“ę„­å“”ć‚’ę¤œē“¢ć™ć‚‹å‡¦ē†ć‚’čæ½åŠ ć™ć‚‹ę‰‹é †ć‚’ē¤ŗć—ć¾ć™ć€‚

EmployeeDao ć«ę¬”ć®ć‚³ćƒ¼ćƒ‰ć‚’čæ½åŠ ć—ć¦ćć ć•ć„ć€‚

@Select
List<Employee> selectByAge(Integer age);

恓恮ćØ恍态ę³Ø釈処ē†ć«ć‚ˆć‚Šę¬”恮ć‚Øćƒ©ćƒ¼ćƒ”ćƒƒć‚»ćƒ¼ć‚ø恌 Eclilpse äøŠć«č”Øē¤ŗć•ć‚Œć¾ć™ć€‚

[DOMA4019] ćƒ•ć‚”ć‚¤ćƒ«[META-INF/boilerplate/dao/EmployeeDao/selectByAge.sql]恌
ć‚Æćƒ©ć‚¹ćƒ‘ć‚¹ć‹ć‚‰č¦‹ć¤ć‹ć‚Šć¾ć›ć‚“ć§ć—ćŸć€‚

Eclipse 恮ć‚Øćƒ‡ć‚£ć‚æäøŠć§ selectByAge ćƒ”ć‚½ćƒƒćƒ‰ć«ć‚«ćƒ¼ć‚½ćƒ«ć‚’åˆć‚ć›å³ć‚ÆćƒŖ惃ć‚ÆćŖ恩恧 ć‚³ćƒ³ćƒ†ć‚­ć‚¹ćƒˆćƒ”ćƒ‹ćƒ„ćƒ¼ć‚’č”Øē¤ŗć•ć›ć€ćƒ”ćƒ‹ćƒ„ćƒ¼ć®äø­ć‹ć‚‰ Doma > Jump to SQL 悒éøęŠžć—ć¦ćć ć•ć„ć€‚

SQL ćƒ•ć‚”ć‚¤ćƒ«ć®ę–°č¦ä½œęˆć‚’č”Œć†ćŸć‚ć®ćƒ€ć‚¤ć‚¢ćƒ­ć‚°ćŒę¬”ć®ć‚ˆć†ć«č”Øē¤ŗć•ć‚Œć¾ć™ć€‚

_images/new-sql-file.png

‘Finish’ ć‚’ęŠ¼ć—ć¦ćƒ•ć‚”ć‚¤ćƒ«ć‚’ä½œęˆć—ć¦ćć ć•ć„ć€‚

ćƒ•ć‚”ć‚¤ćƒ«ä½œęˆå¾Œć€ćƒ•ć‚”ć‚¤ćƒ«ć‚’ē©ŗć®ć¾ć¾äæē®”恗恦 EmployeeDao ć«ęˆ»ć‚‹ćØ ć‚Øćƒ©ćƒ¼ćƒ”ćƒƒć‚»ćƒ¼ć‚øć®å†…å®¹ćŒå¤‰ć‚ć‚Šć¾ć™ć€‚

[DOMA4020] SQLćƒ•ć‚”ć‚¤ćƒ«[META-INF/boilerplate/dao/EmployeeDao/selectByAge.sql]恌ē©ŗ恧恙怂

selectByAge.sql ćƒ•ć‚”ć‚¤ćƒ«ć«ęˆ»ć£ć¦ę¬”ć® SQL 悒čؘčæ°ć—ć¦ćć ć•ć„ć€‚

select
    /*%expand*/*
from
    employee
where
    age < /* age  */0

恓悌恧ć‚Øćƒ©ćƒ¼ćŒč§£ę¶ˆć•ć‚Œć¾ć™ć€‚

ꤜē“¢å‡¦ē†ć®å®Ÿč”ŒĀ¶

äøŠčØ˜ć§ä½œęˆć—ćŸę¤œē“¢å‡¦ē†ć‚’å®Ÿéš›ć«å®Ÿč”Œć—ć¾ć™ć€‚

EmployeeDaoTest ć«ę¬”ć®ć‚³ćƒ¼ćƒ‰ć‚’čæ½åŠ ć—ć¦ćć ć•ć„ć€‚

@Test
public void testSelectByAge() {
    TransactionManager tm = AppConfig.singleton().getTransactionManager();
    tm.required(() -> {
        List<Employee> employees = dao.selectByAge(35);
        assertEquals(2, employees.size());
    });
}

JUnit ć‚’å®Ÿč”Œć—ć€ć“ć®ć‚³ćƒ¼ćƒ‰ćŒå‹•ä½œć™ć‚‹ć“ćØ悒ē¢ŗčŖć—ć¦ćć ć•ć„ć€‚

恓恮ćØ恍ē™ŗč”Œć•ć‚Œć‚‹ę¤œē“¢ć®ćŸć‚ć® SQL ćÆꬔ恮悂恮恧恙怂

select
    age, id, name, version
from
    employee
where
    age < 35

ęŒæå…„Ā¶

ęŒæå…„ 処ē†ć‚’å®Ÿč”Œć™ć‚‹ć«ćÆ态 @Insert 恌ę³Ø釈恕悌恟 Dao ćƒ”ć‚½ćƒƒćƒ‰ć‚’å‘¼ć³å‡ŗć—ć¾ć™ć€‚

ęŒæ兄処ē†ć®å®Ÿč”ŒĀ¶

EmployeeDao ć«ę¬”ć®ć‚³ćƒ¼ćƒ‰ćŒå­˜åœØ恙悋恓ćØ悒ē¢ŗčŖć—ć¦ćć ć•ć„ć€‚

@Insert
int insert(Employee employee);

ć“ć®ć‚³ćƒ¼ćƒ‰ć‚’åˆ©ē”Ø恗恦ęŒæ兄処ē†ć‚’å®Ÿč”Œć—ć¾ć™ć€‚

EmployeeDaoTest ć«ę¬”ć®ć‚³ćƒ¼ćƒ‰ć‚’čæ½åŠ ć—ć¦ćć ć•ć„ć€‚

@Test
public void testInsert() {
    TransactionManager tm = AppConfig.singleton().getTransactionManager();

    Employee employee = new Employee();

    // ęœ€åˆć®ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³
    // ęŒæå…„ć‚’å®Ÿč”Œć—ć¦ć„ć‚‹
    tm.required(() -> {
        employee.name = "HOGE";
        employee.age = 20;
        dao.insert(employee);
        assertNotNull(employee.id);
    });

    // 2ē•Ŗē›®ć®ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³
    // ęŒæå…„ćŒęˆåŠŸć—ć¦ć„ć‚‹ć“ćØ悒ē¢ŗčŖć—恦恄悋
    tm.required(() -> {
        Employee employee2 = dao.selectById(employee.id);
        assertEquals("HOGE", employee2.name);
        assertEquals(Integer.valueOf(20), employee2.age);
        assertEquals(Integer.valueOf(1), employee2.version);
    });
}

JUnit ć‚’å®Ÿč”Œć—ć€ć“ć®ć‚³ćƒ¼ćƒ‰ćŒå‹•ä½œć™ć‚‹ć“ćØ悒ē¢ŗčŖć—ć¦ćć ć•ć„ć€‚

恓恮ćØ恍ē™ŗč”Œć•ć‚Œć‚‹ęŒæå…„ć®ćŸć‚ć® SQL ćÆꬔ恮悂恮恧恙怂

insert into Employee (age, id, name, version) values (20, 100, 'HOGE', 1)

č­˜åˆ„å­ćØćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗå·ćŒč‡Ŗå‹•ć§čØ­å®šć•ć‚Œć¦ć„ć¾ć™ć€‚

ꛓꖰĀ¶

ꛓꖰ 処ē†ć‚’å®Ÿč”Œć™ć‚‹ć«ćÆ态 @Update 恌ę³Ø釈恕悌恟 Dao ćƒ”ć‚½ćƒƒćƒ‰ć‚’å‘¼ć³å‡ŗć—ć¾ć™ć€‚

ę›“ę–°å‡¦ē†ć®å®Ÿč”ŒĀ¶

EmployeeDao ć«ę¬”ć®ć‚³ćƒ¼ćƒ‰ćŒå­˜åœØ恙悋恓ćØ悒ē¢ŗčŖć—ć¦ćć ć•ć„ć€‚

@Update
int update(Employee employee);

ć“ć®ć‚³ćƒ¼ćƒ‰ć‚’åˆ©ē”Øć—ć¦ę›“ę–°å‡¦ē†ć‚’å®Ÿč”Œć—ć¾ć™ć€‚

EmployeeDaoTest ć«ę¬”ć®ć‚³ćƒ¼ćƒ‰ć‚’čæ½åŠ ć—ć¦ćć ć•ć„ć€‚

@Test
public void testUpdate() {
    TransactionManager tm = AppConfig.singleton().getTransactionManager();

    // ęœ€åˆć®ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³
    // ꤜē“¢ć—恦 age ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć‚’ę›“ę–°ć—ć¦ć„ć‚‹
    tm.required(() -> {
        Employee employee = dao.selectById(1);
        assertEquals("ALLEN", employee.name);
        assertEquals(Integer.valueOf(30), employee.age);
        assertEquals(Integer.valueOf(0), employee.version);
        employee.age = 50;
        dao.update(employee);
        assertEquals(Integer.valueOf(1), employee.version);
    });

    // 2ē•Ŗē›®ć®ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³
    // ę›“ę–°ćŒęˆåŠŸć—ć¦ć„ć‚‹ć“ćØ悒ē¢ŗčŖć—恦恄悋
    tm.required(() -> {
        Employee employee = dao.selectById(1);
        assertEquals("ALLEN", employee.name);
        assertEquals(Integer.valueOf(50), employee.age);
        assertEquals(Integer.valueOf(1), employee.version);
    });
}

JUnit ć‚’å®Ÿč”Œć—ć€ć“ć®ć‚³ćƒ¼ćƒ‰ćŒå‹•ä½œć™ć‚‹ć“ćØ悒ē¢ŗčŖć—ć¦ćć ć•ć„ć€‚

恓恮ćØ恍ē™ŗč”Œć•ć‚Œć‚‹ę›“ę–°ć®ćŸć‚ć® SQL ćÆꬔ恮悂恮恧恙怂

update Employee set age = 50, name = 'ALLEN', version = 0 + 1 where id = 1 and version = 0

ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ć®ćŸć‚ć®ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗå·ćŒč‡Ŗå‹•ć§ć‚¤ćƒ³ć‚ÆćƒŖćƒ”ćƒ³ćƒˆć•ć‚Œć¦ć„ć¾ć™ć€‚

削除Ā¶

削除 処ē†ć‚’å®Ÿč”Œć™ć‚‹ć«ćÆ态 @Delete 恌ę³Ø釈恕悌恟 Dao ćƒ”ć‚½ćƒƒćƒ‰ć‚’å‘¼ć³å‡ŗć—ć¾ć™ć€‚

削除処ē†ć®å®Ÿč”ŒĀ¶

EmployeeDao ć«ę¬”ć®ć‚³ćƒ¼ćƒ‰ćŒå­˜åœØ恙悋恓ćØ悒ē¢ŗčŖć—ć¦ćć ć•ć„ć€‚

@Delete
int delete(Employee employee);

ć“ć®ć‚³ćƒ¼ćƒ‰ć‚’åˆ©ē”Øć—ć¦å‰Šé™¤å‡¦ē†ć‚’å®Ÿč”Œć—ć¾ć™ć€‚

EmployeeDaoTest ć«ę¬”ć®ć‚³ćƒ¼ćƒ‰ć‚’čæ½åŠ ć—ć¦ćć ć•ć„ć€‚

@Test
public void testDelete() {
    TransactionManager tm = AppConfig.singleton().getTransactionManager();

    // ęœ€åˆć®ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³
    // å‰Šé™¤ć‚’å®Ÿč”Œć—ć¦ć„ć‚‹
    tm.required(() -> {
        Employee employee = dao.selectById(1);
        dao.delete(employee);
    });

    // 2ē•Ŗē›®ć®ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³
    // å‰Šé™¤ćŒęˆåŠŸć—ć¦ć„ć‚‹ć“ćØ悒ē¢ŗčŖć—恦恄悋
    tm.required(() -> {
        Employee employee = dao.selectById(1);
        assertNull(employee);
    });
}

JUnit ć‚’å®Ÿč”Œć—ć€ć“ć®ć‚³ćƒ¼ćƒ‰ćŒå‹•ä½œć™ć‚‹ć“ćØ悒ē¢ŗčŖć—ć¦ćć ć•ć„ć€‚

恓恮ćØ恍ē™ŗč”Œć•ć‚Œć‚‹å‰Šé™¤ć®ćŸć‚ć® SQL ćÆꬔ恮悂恮恧恙怂

delete from Employee where id = 1 and version = 0

č­˜åˆ„å­ć«åŠ ćˆćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗå·ć‚‚ę¤œē“¢ę”ä»¶ć«ęŒ‡å®šć•ć‚Œć¾ć™ć€‚

čح定Ā¶

Doma恫åÆ¾ć™ć‚‹čح定ćÆ态 Confing ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć®å®Ÿč£…ć‚Æćƒ©ć‚¹ć§č”Øē¾ć—ć¾ć™ć€‚

čح定項ē›®Ā¶

čح定åæ…é ˆćØ꘎ē¤ŗ恗恦恄ćŖ恄項ē›®ć«ć¤ć„恦ćÆćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®å€¤ćŒä½æē”Øć•ć‚Œć¾ć™ć€‚

ćƒ‡ćƒ¼ć‚æć‚½ćƒ¼ć‚¹Ā¶

DataSource 悒 getDataSource ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”ć—ć¦ćć ć•ć„ć€‚ ćƒ­ćƒ¼ć‚«ćƒ«ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ć‚’åˆ©ē”Øć™ć‚‹å “åˆćÆ态 LocalTransactionDataSource 悒čæ”ć—ć¦ćć ć•ć„ć€‚

ćƒŽćƒ¼ćƒˆ

恓恮項ē›®ćÆčح定åæ…é ˆć§ć™ć€‚

ćƒ‡ćƒ¼ć‚æć‚½ćƒ¼ć‚¹ć®åå‰Ā¶

ćƒ‡ćƒ¼ć‚æć‚½ćƒ¼ć‚¹åć‚’ć‚ć‚‰ć‚ć™ String 悒 getDataSourceName ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”ć—ć¦ćć ć•ć„ć€‚ ćƒ‡ćƒ¼ć‚æć‚½ćƒ¼ć‚¹åćÆć€č¤‡ę•°ć®ćƒ‡ćƒ¼ć‚æć‚½ćƒ¼ć‚¹ć‚’åˆ©ē”Ø恙悋ē’°å¢ƒć§é‡č¦ć§ć™ć€‚ ćƒ‡ćƒ¼ć‚æć‚½ćƒ¼ć‚¹åćÆćƒ‡ćƒ¼ć‚æć‚½ćƒ¼ć‚¹ć”ćØ恫č‡Ŗ動ē”Ÿęˆć•ć‚Œć‚‹č­˜åˆ„å­ć‚’åŒŗåˆ„ć™ć‚‹ćŸć‚ć«ä½æē”Øć•ć‚Œć¾ć™ć€‚ č¤‡ę•°ćƒ‡ćƒ¼ć‚æć‚½ćƒ¼ć‚¹ć‚’åˆ©ē”Øć™ć‚‹å “åˆćÆ态恝悌恞悌ē•°ćŖć‚‹åå‰ć‚’čæ”ć™ć‚ˆć†ć«ć—ć¦ćć ć•ć„ć€‚

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®å®Ÿč£…ć§ćÆ态 Config ć®å®Ÿč£…ć‚Æćƒ©ć‚¹ć®å®Œå…Øäæ®é£¾åćŒä½æē”Øć•ć‚Œć¾ć™ć€‚

ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć®ę–¹č؀Ā¶

Dialect 悒 getDialect ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”ć—ć¦ćć ć•ć„ć€‚ Dialect ćÆRDBMSć®ę–¹čØ€ć‚’č”Øć™ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć§ć™ć€‚ Dialect 恫ćÆę¬”ć®ć‚‚ć®ćŒć‚ć‚Šć¾ć™ć€‚

ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ Dialect čŖ¬ę˜Ž
DB2 Db2Dialect  
H2 Database Engine 1.2.126 H212126Dialect H2 Database Engine 1.2.126恧ēؼ動
H2 Database H2Dialect H2 Database Engine 1.3.171ä»„é™ć«åƾåæœ
HSQLDB HsqldbDialect  
Microsoft SQL Server 2008 Mssql2008Dialect Microsoft SQL Server 2008恫åƾåæœ
Microsoft SQL Server MssqlDialect Microsoft SQL Server 2012ä»„é™ć«åƾåæœ
MySQL MySqlDialect  
Oracle Database OracleDialect  
PostgreSQL PostgresDialect  
SQLite SqliteDialect  

ćƒŽćƒ¼ćƒˆ

恓恮項ē›®ćÆčح定åæ…é ˆć§ć™ć€‚

惭悰å‡ŗåŠ›ćƒ©ć‚¤ćƒ–ćƒ©ćƒŖćøć®ć‚¢ćƒ€ćƒ—ć‚æĀ¶

JdbcLogger 悒 getJdbcLogger ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”ć—ć¦ćć ć•ć„ć€‚ JdbcLogger ćÆćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć‚¢ć‚Æć‚»ć‚¹ć«é–¢ć™ć‚‹ćƒ­ć‚°ć‚’ę‰±ć†ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć§ć™ć€‚ å®Ÿč£…ć‚Æćƒ©ć‚¹ć«ćÆę¬”ć®ć‚‚ć®ćŒć‚ć‚Šć¾ć™ć€‚

  • org.seasar.doma.jdbc.UtilLoggingJdbcLogger

UtilLoggingJdbcLogger ćÆ java.util.logging ć®ćƒ­ć‚¬ćƒ¼ć‚’ä½æē”Øć™ć‚‹å®Ÿč£…ć§ć€ ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ä½æē”Øć•ć‚Œć¾ć™ć€‚

SQLćƒ•ć‚”ć‚¤ćƒ«ć®ćƒŖ惝ć‚ø惈ćƒŖĀ¶

SqlFileRepository 悒 getSqlFileRepository ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”ć—ć¦ćć ć•ć„ć€‚ SqlFileRepository ćÆ SQL ćƒ•ć‚”ć‚¤ćƒ«ć®ćƒŖ惝ć‚ø惈ćƒŖć‚’ę‰±ć†ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć§ć™ć€‚ å®Ÿč£…ć‚Æćƒ©ć‚¹ć«ćÆę¬”ć®ć‚‚ć®ćŒć‚ć‚Šć¾ć™ć€‚

  • org.seasar.doma.jdbc.GreedyCacheSqlFileRepository
  • org.seasar.doma.jdbc.NoCacheSqlFileRepository

GreedyCacheSqlFileRepository ćÆ态čŖ­ćæč¾¼ć‚“ć SQLćƒ•ć‚”ć‚¤ćƒ«ć®å†…å®¹ć‚’ćƒ‘ćƒ¼ć‚¹ć—ć€ ćć®ēµęžœć‚’ćƒ”ćƒ¢ćƒŖ恌čØ±ć™é™ć‚Šęœ€å¤§é™ć«ć‚­ćƒ£ćƒƒć‚·ćƒ„ć—ć¾ć™ć€‚

NoCacheSqlFileRepository ćÆ态äø€åˆ‡ć‚­ćƒ£ćƒƒć‚·ćƒ„ć‚’č”Œć„ć¾ć›ć‚“ć€‚ ęÆŽå›žć€SQLćƒ•ć‚”ć‚¤ćƒ«ć‹ć‚‰SQL悒čŖ­ćæå–ć‚Šćƒ‘ćƒ¼ć‚¹ć—ć¾ć™ć€‚

ćƒ”ćƒ¢ćƒŖć®åˆ©ē”Øć«åŽ³ć—ć„åˆ¶é™ćŒć‚ć‚‹ē’°å¢ƒć‚„态ꉱ恆SQLćƒ•ć‚”ć‚¤ćƒ«ćŒč†Øå¤§ć«ć‚ć‚‹ē’°å¢ƒć§ćÆ态 適切ćŖć‚­ćƒ£ćƒƒć‚·ćƒ„ć‚¢ćƒ«ć‚“ćƒŖć‚ŗćƒ ć‚’ć‚‚ć£ćŸå®Ÿč£…ć‚Æćƒ©ć‚¹ć‚’ä½œęˆć—ä½æē”Øć—ć¦ćć ć•ć„ć€‚

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆ GreedyCacheSqlFileRepository 恌ä½æē”Øć•ć‚Œć¾ć™ć€‚

REQUIRES_NEW å±žę€§ć®ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ćØć®é€£å‹•Ā¶

RequiresNewController 悒 getRequiresNewController ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”ć—ć¦ćć ć•ć„ć€‚ RequiresNewController ćÆ REQUIRES_NEW ć®å±žę€§ć‚’ć‚‚ć¤ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ć‚’ åˆ¶å¾”ć™ć‚‹ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć§ć™ć€‚

ć“ć®ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ćÆ态 @TableGenerator ć§ć€č­˜åˆ„å­ć‚’č‡Ŗ動ē”Ÿęˆć™ć‚‹éš›ć«ć—恋ä½æć‚ć‚Œć¾ć›ć‚“ć€‚ @TableGenerator ć‚’åˆ©ē”Ø恗ćŖć„å “åˆćÆ态恓恮čح定項ē›®ć‚’č€ƒę…®ć™ć‚‹åæ…要ćÆć‚ć‚Šć¾ć›ć‚“ć€‚ ć¾ćŸć€ @TableGenerator ć‚’åˆ©ē”Øć™ć‚‹å “åˆć§ć‚ć£ć¦ć‚‚ć€ č­˜åˆ„å­ć‚’ęŽ”ē•Ŗć™ć‚‹ćŸć‚ć®ę›“ę–°ćƒ­ćƒƒć‚ÆćŒå•é”Œć«ćŖ悉ćŖ恄ē؋åŗ¦ć®ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ę•°ć§ć‚ć‚Œć°ć€ čØ­å®šć™ć‚‹åæ…č¦ć‚ć‚Šć¾ć›ć‚“ć€‚

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®å®Ÿč£…ćÆä½•ć®å‡¦ē†ć‚‚ć—ć¾ć›ć‚“ć€‚

ć‚Æćƒ©ć‚¹ć®ćƒ­ćƒ¼ćƒ‰ę–¹ę³•Ā¶

ClassHelper 悒 getClassHelper ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”ć—ć¦ćć ć•ć„ć€‚ ClassHelper ćÆć‚Æćƒ©ć‚¹ć®ćƒ­ćƒ¼ćƒ‰ć«é–¢ć—ć¦ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć‚µćƒ¼ćƒć‚„ ćƒ•ćƒ¬ćƒ¼ćƒ ćƒÆćƒ¼ć‚Æć®å·®ē•°ć‚’ęŠ½č±”åŒ–ć™ć‚‹ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć§ć™ć€‚

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®å®Ÿč£…ćÆ java.lang.Class.forName(name) 悒ē”Ø恄恦ć‚Æćƒ©ć‚¹ć‚’ćƒ­ćƒ¼ćƒ‰ć—ć¾ć™ć€‚

ä¾‹å¤–ćƒ”ćƒƒć‚»ćƒ¼ć‚øć«å«ć‚ć‚‹SQL恮ēخ刄Ā¶

ä¾‹å¤–ćƒ”ćƒƒć‚»ćƒ¼ć‚øć«å«ć‚ć‚‹SQL恮ć‚æ悤惗悒恂悉悏恙 SqlLogType 悒 getExceptionSqlLogType ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”ć—ć¦ćć ć•ć„ć€‚ ć“ć®å€¤ćÆ态Doma ćŒć‚¹ćƒ­ćƒ¼ć™ć‚‹ä¾‹å¤–ć«ć©ć®ć‚ˆć†ćŖå½¢å¼ć®SQLć‚’å«ć‚ć‚‹ć‹ć‚’ę±ŗå®šć—ć¾ć™ć€‚

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®å®Ÿč£…ć§ćÆć€ćƒ•ć‚©ćƒ¼ćƒžćƒƒćƒˆć•ć‚ŒćŸ SQL ć‚’å«ć‚ć¾ć™ć€‚

ęœŖēŸ„ć®ć‚«ćƒ©ćƒ ć®ćƒćƒ³ćƒ‰ćƒ©Ā¶

UnknownColumnHandler 悒 getUnknownColumnHandler ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”ć—ć¦ćć ć•ć„ć€‚ UnknownColumnHandler ćÆ ꤜē“¢ 恮ēµęžœć‚’ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć™ć‚‹éš›ć€ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć«ćØć£ć¦ęœŖēŸ„ć®ć‚«ćƒ©ćƒ ćŒå­˜åœØć™ć‚‹å “åˆć«å®Ÿč”Œć•ć‚Œć¾ć™ć€‚

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆ态 UnknownColumnException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

ćƒ†ćƒ¼ćƒ–ćƒ«ć‚„ć‚«ćƒ©ćƒ ć«ćŠć‘ć‚‹ćƒćƒ¼ćƒŸćƒ³ć‚°č¦ē“„ć®åˆ¶å¾”Ā¶

Naming 悒 getNaming ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”ć—ć¦ćć ć•ć„ć€‚

Naming ćÆ态 @Entity 恮 name 要ē“ ć«ęŒ‡å®šć•ć‚ŒćŸļ¼ˆć‚‚ć—ććÆęŒ‡å®šć•ć‚ŒćŖ恄ļ¼‰ NamingType ć‚’ć©ć®ć‚ˆć†ć«é©ē”Øć™ć‚‹ć‹ć«ć¤ć„ć¦åˆ¶å¾”ć™ć‚‹ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć§ć™ć€‚ ć“ć®ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć‚’ä½æ恆恓ćØć§ć€å€‹åˆ„ć®ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć« NamingType ć‚’ęŒ‡å®šć—ćŖćć¦ć‚‚ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®ć‚Æćƒ©ć‚¹åćØćƒ—ćƒ­ćƒ‘ćƒ†ć‚£åć‹ć‚‰ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć®ćƒ†ćƒ¼ćƒ–ćƒ«åćØć‚«ćƒ©ćƒ åć‚’č§£ę±ŗć§ćć¾ć™ć€‚

Naming 恌ä½æē”Øć•ć‚Œć‚‹ę”ä»¶ćÆ仄äø‹ć®é€šć‚Šć§ć™ć€‚

  • @Table 悄 @Column 恮 name 要ē“ ć«å€¤ćŒęŒ‡å®šć•ć‚Œć¦ć„ćŖ恄怂

äø€čˆ¬ēš„ćŖćƒ¦ćƒ¼ć‚¹ć‚±ćƒ¼ć‚¹ć‚’å®Ÿē¾ć™ć‚‹ćŸć‚ć®å®Ÿč£…ćÆ态 Naming 恮 static ćŖćƒ”ćƒ³ćƒć«å®šē¾©ć•ć‚Œć¦ć„ć¾ć™ć€‚

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆ态 Naming.NONE 恌ä½æē”Øć•ć‚Œć¾ć™ć€‚ ć“ć®å®Ÿč£…ćÆ态ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć«ęŒ‡å®šć•ć‚ŒćŸ NamingType 悒ä½æ恄态 ęŒ‡å®šćŒćŖć„å “åˆćÆä½•ć®č¦ē“„悂適ē”Øć—ć¾ć›ć‚“ć€‚

ä¾‹ćˆć°ć€ęŒ‡å®šćŒćŖć„å “åˆć«ć‚¹ćƒćƒ¼ć‚Æć‚±ćƒ¼ć‚¹ć®å¤§ę–‡å­—ć‚’é©ē”Ø恗恟恄ćØć„ć†ć‚±ćƒ¼ć‚¹ć§ćÆ态 Naming.SNAKE_UPPER_CASE 悒ä½æē”Øć§ćć¾ć™ć€‚

ćƒžćƒƒćƒ—ć®ć‚­ćƒ¼ć®ćƒćƒ¼ćƒŸćƒ³ć‚°č¦ē“„ć®åˆ¶å¾”Ā¶

MapKeyNaming 悒 getMapKeyNaming ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”ć—ć¦ćć ć•ć„ć€‚ MapKeyNaming ćÆꤜē“¢ēµęžœć‚’ java.util.Map<String, Object> ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć™ć‚‹å “åˆć«å®Ÿč”Œć•ć‚Œć¾ć™ć€‚

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆ态 @Select ćŖ恩恮 mapKeyNaming 要ē“ ć«ęŒ‡å®šć•ć‚ŒćŸč¦ē“„悒適ē”Øć—ć¾ć™ć€‚

ćƒ­ćƒ¼ć‚«ćƒ«ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ćƒžćƒćƒ¼ć‚øćƒ£ćƒ¼Ā¶

LocalTransactionManager 悒 getTransactionManager ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”ć—ć¦ćć ć•ć„ć€‚ getTransactionManager ćƒ”ć‚½ćƒƒćƒ‰ćÆć€ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ UnsupportedOperationException ć‚’ć‚¹ćƒ­ćƒ¼ć—ć¾ć™ć€‚

ćƒŽćƒ¼ćƒˆ

恓恮項ē›®ćÆčح定åæ…é ˆć§ćÆć‚ć‚Šć¾ć›ć‚“ćŒć€ org.seasar.doma.jdbc.tx.TransactionManager ć®ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć§ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ć‚’åˆ©ē”Øć—ćŸć„å “åˆćÆčØ­å®šć—ć¦ćć ć•ć„ć€‚ čØ­å®šę–¹ę³•ć«ć¤ć„ć¦ćÆ ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ ć‚’å‚ē…§ć—ć¦ćć ć•ć„ć€‚

SQLć®č­˜åˆ„å­ć®čæ½čؘĀ¶

Commenter 悒 getCommenter ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”ć—ć¦ćć ć•ć„ć€‚ Commenter ćÆSQLć®č­˜åˆ„å­ļ¼ˆSQL恮ē™ŗč”Œē®‡ę‰€ē­‰ć‚’ē‰¹å®šć™ć‚‹ćŸć‚ć®ę–‡å­—列ļ¼‰ć‚’SQLć‚³ćƒ”ćƒ³ćƒˆćØ恗恦čæ½čØ˜ć™ć‚‹ćŸć‚ć®ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć§ć™ć€‚

å®Ÿč£…ć‚Æćƒ©ć‚¹ć«ćÆę¬”ć®ć‚‚ć®ćŒć‚ć‚Šć¾ć™ć€‚

  • org.seasar.doma.jdbc.CallerCommenter

CallerCommenter ćÆ态SQLć®å‘¼ć³å‡ŗć—å…ƒć®ć‚Æćƒ©ć‚¹åćØćƒ”ć‚½ćƒƒćƒ‰åć‚’č­˜åˆ„å­ćØ恗恦ä½æē”Øć—ć¾ć™ć€‚

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®å®Ÿč£…ć§ćÆ态 č­˜åˆ„å­ć‚’čæ½čØ˜ć—ć¾ć›ć‚“ć€‚

Command ć®å®Ÿč£…Ā¶

CommandImplementors 悒 getCommandImplementors ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”ć—ć¦ćć ć•ć„ć€‚ CommandImplementors ć‚’å®Ÿč£…ć™ć‚‹ćØ ć‚Æć‚ØćƒŖ ć®å®Ÿč”Œć‚’ć‚«ć‚¹ć‚æ惞悤ć‚ŗć§ćć¾ć™ć€‚

恟ćØ恈恰态 JDBC 恮 API 悒ē›“ęŽ„å‘¼ć³å‡ŗ恙恓ćØćŒć§ćć¾ć™ć€‚

Query ć®å®Ÿč£…Ā¶

QueryImplementors 悒 getQueryImplementors ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”ć—ć¦ćć ć•ć„ć€‚ QueryImplementors ć‚’å®Ÿč£…ć™ć‚‹ćØ ć‚Æć‚ØćƒŖ ć®å†…å®¹ć‚’ć‚«ć‚¹ć‚æ惞悤ć‚ŗć§ćć¾ć™ć€‚

恟ćØ恈恰态č‡Ŗ動ē”Ÿęˆć•ć‚Œć‚‹ SQL 恮äø€éƒØ悒ę›ø恍ꏛ恈åÆčƒ½ć§ć™ć€‚

ć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆĀ¶

ć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆļ¼ˆē§’ļ¼‰ć‚’ć‚ć‚‰ć‚ć™ int 悒 getQueryTimeout ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”ć—ć¦ćć ć•ć„ć€‚ ć“ć®å€¤ćÆć™ć¹ć¦ć® ć‚Æć‚ØćƒŖ ć«ćŠć„ć¦ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆå€¤ćØ恗恦ä½æć‚ć‚Œć¾ć™ć€‚

ęœ€å¤§ä»¶ę•°Ā¶

SELECTę™‚ć®ęœ€å¤§č”Œę•°ć‚’ć‚ć‚‰ć‚ć™ int 悒 getMaxRows ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”ć—ć¾ć™ć€‚ ć“ć®å€¤ćÆć™ć¹ć¦ć® ꤜē“¢ ć«ćŠć„ć¦ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆå€¤ćØ恗恦ä½æć‚ć‚Œć¾ć™ć€‚

ćƒ•ć‚§ćƒƒćƒć‚µć‚¤ć‚ŗĀ¶

SELECTę™‚ć®ćƒ•ć‚§ćƒƒćƒć‚µć‚¤ć‚ŗ悒恂悉悏恙 int 悒 getFetchSize ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”ć—ć¾ć™ć€‚ ć“ć®å€¤ćÆć™ć¹ć¦ć® ꤜē“¢ ć«ćŠć„ć¦ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆå€¤ćØ恗恦ä½æć‚ć‚Œć¾ć™ć€‚

ćƒćƒƒćƒć‚µć‚¤ć‚ŗĀ¶

ćƒćƒƒćƒć‚µć‚¤ć‚ŗ悒恂悉悏恙 int 悒 getBatchSize ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”ć—ć¾ć™ć€‚ ć“ć®å€¤ćÆ 惐惃惁ęŒæå…„ ć€ćƒćƒƒćƒę›“ę–° ć€ćƒćƒƒćƒå‰Šé™¤ ć«ćŠć„ć¦ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆå€¤ćØ恗恦ä½æć‚ć‚Œć¾ć™ć€‚

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ć®å–å¾—Ā¶

EntityListenerProvider 悒 getEntityListenerProvider ćƒ”ć‚½ćƒƒćƒ‰ć§čæ”恗恦äø‹ć•ć„怂

EntityListenerProvider 恮 get ćƒ”ć‚½ćƒƒćƒ‰ćÆ EntityListener å®Ÿč£…ć‚Æćƒ©ć‚¹ć® Class ćØ EntityListener å®Ÿč£…ć‚Æćƒ©ć‚¹ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’čæ”恙 Supplier ć‚’å¼•ę•°ć«å–ć‚Š EntityListener ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’čæ”ć—ć¾ć™ć€‚ ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®å®Ÿč£…ć§ćÆ Supplier.get ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”Œć—ć¦å¾—ćŸć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’čæ”ć—ć¾ć™ć€‚

EntityListener å®Ÿč£…ć‚Æćƒ©ć‚¹ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’DIć‚³ćƒ³ćƒ†ćƒŠć‹ć‚‰å–å¾—ć—ćŸć„ćŖ恩态 ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹å–å¾—ę–¹ę³•ć‚’ć‚«ć‚¹ć‚æ惞悤ć‚ŗć™ć‚‹å “åˆćÆ EntityListenerProvider ć‚’å®Ÿč£…ć—ćŸć‚Æćƒ©ć‚¹ć‚’ä½œęˆć—ć€ getEntityListenerProvider ćƒ”ć‚½ćƒƒćƒ‰ć§ćć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’čæ”ć™ć‚ˆć†čØ­å®šć—ć¦ćć ć•ć„ć€‚

JDBC ćƒ‰ćƒ©ć‚¤ćƒć®ćƒ­ćƒ¼ćƒ‰Ā¶

ć‚Æćƒ©ć‚¹ćƒ‘ć‚¹ćŒé€šć£ć¦ć„ć‚Œć° JDBC ćƒ‰ćƒ©ć‚¤ćƒćÆ ć‚µćƒ¼ćƒ“ć‚¹ćƒ—ćƒ­ćƒć‚¤ćƒ€ćƒ”ć‚«ćƒ‹ć‚ŗ惠 ć«ć‚ˆć‚Šč‡Ŗå‹•ć§ćƒ­ćƒ¼ćƒ‰ć•ć‚Œć¾ć™ć€‚

č­¦å‘Š

å®Ÿč”Œē’°å¢ƒć«ć‚ˆć£ć¦ćÆ态 JDBC ćƒ‰ćƒ©ć‚¤ćƒćŒč‡Ŗå‹•ć§ćƒ­ćƒ¼ćƒ‰ć•ć‚ŒćŖ恄恓ćØćŒć‚ć‚Šć¾ć™ć€‚ 恟ćØ恈恰 Tomcat äøŠć§ćÆ WEB-INF/lib ć«é…ē½®ć•ć‚ŒćŸ JDBC ćƒ‰ćƒ©ć‚¤ćƒćÆč‡Ŗå‹•ć§ćƒ­ćƒ¼ćƒ‰ć•ć‚Œć¾ć›ć‚“ 怂 ćć®ć‚ˆć†ćŖē’°å¢ƒć«ćŠć„恦ćÆć€ćć®ē’°å¢ƒć«åæœć˜ćŸé©åˆ‡ćÆę–¹ę³•ć‚’ęŽ”ć£ć¦ćć ć•ć„ć€‚ 恟ćØ恈恰 Tomcat äøŠć§å‹•ä½œć•ć›ć‚‹ćŸć‚ć®ć«ćÆ态äøŠčØ˜ć®ćƒŖćƒ³ć‚Æå…ˆć®ęŒ‡ē¤ŗć«å¾“ć£ć¦ ServletContextListener ć‚’åˆ©ē”Øć—ćŸćƒ­ćƒ¼ćƒ‰ćØć‚¢ćƒ³ćƒ­ćƒ¼ćƒ‰ć‚’č”Œć£ć¦ćć ć•ć„ć€‚

定ē¾©ćØ利ē”Ø例Ā¶

ć‚·ćƒ³ćƒ—ćƒ«Ā¶

ć‚·ćƒ³ćƒ—ćƒ«ćŖ定ē¾©ćÆę¬”ć®å “åˆć«é©ć—ć¦ć„ć¾ć™ć€‚

  • DIć‚³ćƒ³ćƒ†ćƒŠć§ē®”ē†ć—ćŖ恄
  • ćƒ­ćƒ¼ć‚«ćƒ«ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ć‚’ä½æē”Ø恙悋

å®Ÿč£…ä¾‹ć§ć™ć€‚

@SingletonConfig
public class AppConfig implements Config {

    private static final AppConfig CONFIG = new AppConfig();

    private final Dialect dialect;

    private final LocalTransactionDataSource dataSource;

    private final TransactionManager transactionManager;

    private AppConfig() {
        dialect = new H2Dialect();
        dataSource = new LocalTransactionDataSource(
                "jdbc:h2:mem:tutorial;DB_CLOSE_DELAY=-1", "sa", null);
        transactionManager = new LocalTransactionManager(
                dataSource.getLocalTransaction(getJdbcLogger()));
    }

    @Override
    public Dialect getDialect() {
        return dialect;
    }

    @Override
    public DataSource getDataSource() {
        return dataSource;
    }

    @Override
    public TransactionManager getTransactionManager() {
        return transactionManager;
    }

    public static AppConfig singleton() {
        return CONFIG;
    }
}

ćƒŽćƒ¼ćƒˆ

ć‚Æćƒ©ć‚¹ć« @SingletonConfig 悒ę³Øé‡ˆć™ć‚‹ć®ć‚’åæ˜ć‚ŒćŖć„ć‚ˆć†ć«ć—ć¦ćć ć•ć„ć€‚

利ē”Øä¾‹ć§ć™ć€‚ 定ē¾©ć—ćŸčح定ć‚Æćƒ©ć‚¹ćÆ态@Daoć«ęŒ‡å®šć—ć¾ć™ć€‚

@Dao(config = AppConfig.class)
public interface EmployeeDao {

    @Select
    Employee selectById(Integer id);
}

ć‚¢ćƒ‰ćƒćƒ³ć‚¹ćƒ‰Ā¶

ć‚¢ćƒ‰ćƒćƒ³ć‚¹ćƒ‰ćŖ定ē¾©ćÆę¬”ć®å “åˆć«é©ć—ć¦ć„ć¾ć™ć€‚

  • DIć‚³ćƒ³ćƒ†ćƒŠć§ć‚·ćƒ³ć‚°ćƒ«ćƒˆćƒ³ćØ恗恦ē®”ē†ć™ć‚‹
  • DIć‚³ćƒ³ćƒ†ćƒŠć‚„ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć‚µćƒ¼ćƒćƒ¼ćŒęä¾›ć™ć‚‹ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ē®”ē†ę©Ÿčƒ½ć‚’ä½æ恆

å®Ÿč£…ä¾‹ć§ć™ć€‚ dialect ćØ dataSource ćÆDIć‚³ćƒ³ćƒ†ćƒŠć«ć‚ˆć£ć¦ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć•ć‚Œć‚‹ć“ćØć‚’ęƒ³å®šć—ć¦ć„ć¾ć™ć€‚

public class AppConfig implements Config {

    private Dialect dialect;

    private DataSource dataSource;

    @Override
    public Dialect getDialect() {
        return dialect;
    }

    public void setDialect(Dialect dialect) {
        this.dialect = dialect;
    }

    @Override
    public DataSource getDataSource() {
        return dataSource;
    }

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }
}

利ē”Øä¾‹ć§ć™ć€‚ 定ē¾©ć—ćŸčح定ć‚Æćƒ©ć‚¹ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ćŒDIć‚³ćƒ³ćƒ†ćƒŠć«ć‚ˆć£ć¦ć‚¤ćƒ³ć‚ø悧ć‚Æćƒˆć•ć‚Œć‚‹ć‚ˆć†ć«ć—ć¾ć™ć€‚

@Dao
@AnnotateWith(annotations = {
    @Annotation(target = AnnotationTarget.CONSTRUCTOR, type = javax.inject.Inject.class),
    @Annotation(target = AnnotationTarget.CONSTRUCTOR_PARAMETER, type = javax.inject.Named.class, elements = "\"config\"") })
public interface EmployeeDao {

    @Select
    Employee selectById(Integer id);
}

äøŠčØ˜ć®ä¾‹ć§ćÆ @AnnotateWith 恮čؘčæ°ć‚’Dao恔ćØ恫ē¹°ć‚Ščæ”恗čؘčæ°ć™ć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚ ē¹°ć‚Ščæ”恗悒éæć‘ćŸć„å “åˆćÆć€ä»»ę„ć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć«äø€åŗ¦ć ć‘ @AnnotateWith 悒čؘčæ°ć—态 Dao恫ćÆćć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ę³Øé‡ˆć—ć¦ćć ć•ć„ć€‚

@AnnotateWith(annotations = {
    @Annotation(target = AnnotationTarget.CONSTRUCTOR, type = javax.inject.Inject.class),
    @Annotation(target = AnnotationTarget.CONSTRUCTOR_PARAMETER, type = javax.inject.Named.class, elements = "\"config\"") })
public @interface InjectConfig {
}
@Dao
@InjectConfig
public interface EmployeeDao {

    @Select
    Employee selectById(Integer id);
}

åŸŗęœ¬åž‹Ā¶

Doma恧ćÆć€ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć®ć‚«ćƒ©ćƒ ć«ćƒžćƒƒćƒ”ćƒ³ć‚°åÆčƒ½ćŖJavać®åž‹ć‚’åŸŗęœ¬åž‹ćØå‘¼ć³ć¾ć™ć€‚

ēخ锞Ā¶

åŸŗęœ¬åž‹ć«ćÆ仄äø‹ć®ēØ®é”žćŒć‚ć‚Šć¾ć™ć€‚

  • 惗ćƒŖćƒŸćƒ†ć‚£ćƒ–åž‹ćØćć®ćƒ©ćƒƒćƒ‘ćƒ¼åž‹ļ¼ˆćŸć ć— char ćØ java.lang.Character ćÆ除恏ļ¼‰
  • åˆ—ęŒ™åž‹
  • byte[]
  • java.lang.String
  • java.lang.Object
  • java.math.BigDecimal
  • java.math.BigInteger
  • java.time.LocalDate
  • java.time.LocalTime
  • java.time.LocalDateTime
  • java.sql.Date
  • java.sql.Time
  • java.sql.Timestamp
  • java.sql.Array
  • java.sql.Blob
  • java.sql.Clob
  • java.sql.SQLXML
  • java.util.Date

ę—„ä»˜/ę™‚åˆ»åž‹Ā¶

ę—„ä»˜ćØę™‚åˆ»ć®åž‹ć®é•ć„ć«ć¤ć„ć¦čŖ¬ę˜Žć—ć¾ć™ć€‚

java.time.LocalDate
SQLęؙęŗ–恮DATE型 (ę—„ä»˜ć®ćæ)悒č”Øć—ć¾ć™ć€‚
java.time.LocalTime
SQLęؙęŗ–恮TIME型 (ę™‚åˆ»ć®ćæ)悒č”Øć—ć¾ć™ć€‚
java.time.LocalDateTime
SQLęؙęŗ–恮TIMESTAMP型 (ę—„ä»˜ćØę™‚åˆ»)悒č”Øć—ć¾ć™ć€‚RDBMSćŒć‚µćƒćƒ¼ćƒˆć—ć¦ć„ć‚‹å “åˆćƒŠćƒŽē§’ć‚’äæęŒć—ć¾ć™ć€‚
java.sql.Date
SQLęؙęŗ–恮DATE型 (ę—„ä»˜ć®ćæ)悒č”Øć—ć¾ć™ć€‚
java.sql.Time
SQLęؙęŗ–恮TIME型 (ę™‚åˆ»ć®ćæ)悒č”Øć—ć¾ć™ć€‚
java.sql.Timestamp
SQLęؙęŗ–恮TIMESTAMP型 (ę—„ä»˜ćØę™‚åˆ»)悒č”Øć—ć¾ć™ć€‚RDBMSćŒć‚µćƒćƒ¼ćƒˆć—ć¦ć„ć‚‹å “åˆćƒŠćƒŽē§’ć‚’äæęŒć—ć¾ć™ć€‚
java.util.Date
SQLęؙęŗ–恮TIMESTAMP型 (ę—„ä»˜ćØę™‚åˆ»)悒č”Øć—ć¾ć™ć€‚ćƒŠćƒŽē§’ć‚’äæęŒć—ć¾ć›ć‚“ć€‚

利ē”Ø例Ā¶

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹Ā¶

@Entity
public class Employee {

    @Id
    Integer employeeId;

    Optional<String> employeeName;

    @Version
    Long versionNo;

    ...
}

ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹Ā¶

@Domain(valueType = String.class)
public class PhoneNumber {

    private final String value;

    public PhoneNumber(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }
}

Daoć‚Æćƒ©ć‚¹Ā¶

@Dao(config = AppConfig.class)
public interface EmployeeDao {

    @Select
    Employee selectById(Integer employeeId);

    @Select
    List<String> selectAllName();
}

ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹Ā¶

Domain ļ¼ˆćƒ‰ćƒ”ć‚¤ćƒ³ļ¼‰ć‚Æćƒ©ć‚¹ć®å®šē¾©ę–¹ę³•ć‚’ē¤ŗć—ć¾ć™ć€‚

Doma 恧ćÆć€ćƒ†ćƒ¼ćƒ–ćƒ«ć®ć‚«ćƒ©ćƒ ć®å€¤ć‚’ ćƒ‰ćƒ”ć‚¤ćƒ³ ćØå‘¼ć°ć‚Œć‚‹ Java ć‚Ŗ惖ć‚ø悧ć‚Æćƒˆć§ę‰±ćˆć¾ć™ć€‚ ćƒ‰ćƒ”ć‚¤ćƒ³ćØćÆå€¤ć®ćØć‚Šå¾—ć‚‹ēÆ„å›²ć€ć¤ć¾ć‚Šå®šē¾©åŸŸć®ć“ćØ恧恙怂

ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć‚’åˆ©ē”Ø恙悋恓ćØć§ć€ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹äøŠć®ć‚«ćƒ©ćƒ ć®åž‹ćŒåŒć˜ć‚ć£ć¦ć‚‚ ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³äøŠę„å‘³ćŒē•°ćŖć‚‹ć‚‚ć®ć‚’åˆ„ć®Javać®åž‹ć§č”Øē¾ć§ćć¾ć™ć€‚ ć“ć‚Œć«ć‚ˆć‚Šę„å‘³ć‚’ę˜Žē¢ŗć«ć—ćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°ćƒŸć‚¹ć‚’äŗ‹å‰ć«é˜²ćŽć‚„ć™ććŖć‚Šć¾ć™ć€‚ ć¾ćŸć€ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć«ęŒÆ悋舞恄悒ꌁ恟恛悋恓ćØć§ć‚ˆć‚Šć‚ć‹ć‚Šć‚„ć™ć„ćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°ćŒåÆčƒ½ć§ć™ć€‚

ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć®ä½œęˆćØ利ē”ØćÆä»»ę„ć§ć™ć€‚ ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć‚’åˆ©ē”Ø恗ćŖćć¦ć‚‚ Integer 悄 String ćŖ恩åŸŗęœ¬åž‹ć®ćæć§ćƒ‡ćƒ¼ć‚æć‚¢ć‚Æć‚»ć‚¹ćÆåÆčƒ½ć§ć™ć€‚

ćƒ‰ćƒ”ć‚¤ćƒ³ćÆć€å®šē¾©ć®ä»•ę–¹ć«ć‚ˆć‚Šå†…éƒØćƒ‰ćƒ”ć‚¤ćƒ³ćØ外éƒØćƒ‰ćƒ”ć‚¤ćƒ³ć«åˆ†ć‘ć‚‰ć‚Œć¾ć™ć€‚

内éƒØćƒ‰ćƒ”ć‚¤ćƒ³Ā¶

ćƒ‰ćƒ”ć‚¤ćƒ³ćØć—ć¦ę‰±ć„ćŸć„åÆ¾č±”ć®ć‚Æćƒ©ć‚¹ć®ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ć«ē›“ęŽ„å®šē¾©ć‚’čؘčæ°ć—ć¾ć™ć€‚

内éƒØćƒ‰ćƒ”ć‚¤ćƒ³ć‚’å®šē¾©ć™ć‚‹ć«ćÆ态ć‚Æćƒ©ć‚¹ć« @Domain 悒ę³Øé‡ˆć—ć¾ć™ć€‚

@Domain 恮 valueType 要ē“ ć«ćÆ åŸŗęœ¬åž‹ ć‚’ęŒ‡å®šć—ć¾ć™ć€‚

ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ恧ē”Ÿęˆć™ć‚‹ę–¹ę³•Ā¶

@Domain 恮 factoryMethod 要ē“ ć®ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®å€¤ćÆ new 恧恂悊态 非privatećŖć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æć§ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ē”Ÿęˆć™ć‚‹ć“ćØ悒ē¤ŗć—ć¾ć™ć€‚ ćć®ćŸć‚ć€ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ恧ē”Ÿęˆć™ć‚‹å “合ćÆ factoryMethod 要ē“ ć‚’ēœē•„ć§ćć¾ć™ć€‚ ę¬”ć®ä¾‹ć§ćÆ态 public ćŖć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æć‚’ęŒć¤ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć‚’ä½œęˆć—ć¦ć„ć¾ć™ć€‚ 恓恮ć‚Æćƒ©ć‚¹ćÆ電話ē•Ŗå·ć‚’č”Øć—ć¦ć„ć¾ć™ć€‚

@Domain(valueType = String.class)
public class PhoneNumber {

    private final String value;

    public PhoneNumber(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }

    public String getAreaCode() {
       // ćƒ‰ćƒ”ć‚¤ćƒ³ć«å›ŗęœ‰ć®ęŒÆ悋舞恄悒čؘčæ°ć§ćć‚‹ć€‚
       ...
    }
}

ćƒ•ć‚”ć‚Æ惈ćƒŖćƒ”ć‚½ćƒƒćƒ‰ć§ē”Ÿęˆć™ć‚‹ę–¹ę³•Ā¶

ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ悒privateć«ć—ćƒ•ć‚”ć‚Æ惈ćƒŖćƒ”ć‚½ćƒƒćƒ‰ć‚’ä½æć£ć¦ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ē”Ÿęˆć—ćŸć„å “合ćÆ态 staticćŖ非privatećŖćƒ”ć‚½ćƒƒćƒ‰ć‚’å®šē¾©ć— @Domain 恮 factoryMethod 要ē“ ć«ćć®ćƒ”ć‚½ćƒƒćƒ‰ć®åå‰ć‚’ęŒ‡å®šć—ć¾ć™ć€‚ ę¬”ć®ä¾‹ć§ćÆ态publicćŖćƒ•ć‚”ć‚Æ惈ćƒŖćƒ”ć‚½ćƒƒćƒ‰ć‚’ć‚‚ć¤ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć‚’ä½œęˆć—ć¦ć„ć¾ć™ć€‚ 恓恮ć‚Æćƒ©ć‚¹ćÆ電話ē•Ŗå·ć‚’č”Øć—ć¦ć„ć¾ć™ć€‚

@Domain(valueType = String.class, factoryMethod = "of")
public class PhoneNumber {

    private final String value;

    private PhoneNumber(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }

    public String getAreaCode() {
       // ćƒ‰ćƒ”ć‚¤ćƒ³ć«å›ŗęœ‰ć®ęŒÆ悋舞恄悒čؘčæ°ć§ćć‚‹ć€‚
       ...
    }

    public static PhoneNumber of(String value) {
        return new PhoneNumber(value);
    }
}

ę¬”ć®ä¾‹ć§ćÆ态 public ćŖćƒ•ć‚”ć‚Æ惈ćƒŖćƒ”ć‚½ćƒƒćƒ‰ć‚’ć‚‚ć¤åˆ—ęŒ™åž‹ć‚’ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ćØć—ć¦ä½œęˆć—ć¦ć„ć¾ć™ć€‚ ć“ć®åˆ—ęŒ™åž‹ćÆ仕äŗ‹ć®ēØ®åˆ„ć‚’č”Øć—ć¦ć„ć¾ć™ć€‚

@Domain(valueType = String.class, factoryMethod = "of")
public enum JobType {
    SALESMAN("10"),
    MANAGER("20"),
    ANALYST("30"),
    PRESIDENT("40"),
    CLERK("50");

    private final String value;

    private JobType(String value) {
        this.value = value;
    }

    public static JobType of(String value) {
        for (JobType jobType : JobType.values()) {
            if (jobType.value.equals(value)) {
                return jobType;
            }
        }
        throw new IllegalArgumentException(value);
    }

    public String getValue() {
        return value;
    }
}

åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚’åˆ©ē”Øć™ć‚‹ę–¹ę³•Ā¶

ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć«ćÆä»»ę„ć®ę•°ć®åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚’å®£čØ€ć§ćć¾ć™ć€‚ ę¬”ć®ä¾‹ć§ćÆ态1ć¤ć®åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚’ęŒć”ć€ć•ć‚‰ć« public ćŖć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ悒ꌁ恤 ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć‚’ä½œęˆć—ć¦ć„ć¾ć™ć€‚ 恓恮ć‚Æćƒ©ć‚¹ćÆč­˜åˆ„å­ć‚’č”Øć—ć¦ć„ć¾ć™ć€‚

@Domain(valueType = int.class)
public class Identity<T> {

    private final int value;

    public Identity(int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }
}

åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚’ęŒć£ćŸćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ćÆćƒ•ć‚”ć‚Æ惈ćƒŖćƒ”ć‚½ćƒƒćƒ‰ć§ē”Ÿęˆć™ć‚‹ć“ćØ悂åÆčƒ½ć§ć™ć€‚ ć“ć®å “åˆć€ćƒ•ć‚”ć‚Æ惈ćƒŖćƒ”ć‚½ćƒƒćƒ‰ć«ćÆć‚Æćƒ©ć‚¹ć®åž‹å¤‰ę•°å®£č؀ćØ同ē­‰ć®å®£čØ€ćŒåæ…要恧恙怂

@Domain(valueType = int.class, factoryMethod = "of")
public class Identity<T> {

    private final int value;

    private Identity(int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    public static <T> Identity<T> of(int value) {
        return new Identity<T>(value);
    }
}

外éƒØćƒ‰ćƒ”ć‚¤ćƒ³Ā¶

ćƒ‰ćƒ”ć‚¤ćƒ³ćØć—ć¦ę‰±ć„ćŸć„åÆ¾č±”ć®ć‚Æćƒ©ć‚¹ćØćÆåˆ„ć®ć‚Æćƒ©ć‚¹ć«å®šē¾©ć‚’čؘčæ°ć—ć¾ć™ć€‚

外éƒØćƒ‰ćƒ”ć‚¤ćƒ³ćÆć€ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ć«ę‰‹ć‚’åŠ ćˆć‚‰ć‚ŒćŖ恄态 Doma ćøä¾å­˜ć•ć›ćŸććŖ恄态 ćØć„ć£ćŸē†ē”±ćŒć‚ć‚‹å “åˆć«ęœ‰åŠ¹ć§ć™ć€‚ 外éƒØćƒ‰ćƒ”ć‚¤ćƒ³ć‚’å®šē¾©ć™ć‚‹ć«ćÆ态 DomainConverter ć®å®Ÿč£…ć‚Æćƒ©ć‚¹ć« @ExternalDomain 悒ę³Øé‡ˆć—ć¦ē¤ŗć—ć¾ć™ć€‚

ä¾‹ćˆć°ć€ę¬”ć®ć‚ˆć†ćŖ PhoneNumber ćØ恄恆ć‚Æćƒ©ć‚¹ćŒć‚ć‚Šć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ć«ę‰‹ć‚’åŠ ćˆć‚‰ć‚ŒćŖ恄ćØć—ć¾ć™ć€‚

public class PhoneNumber {

    private final String value;

    public PhoneNumber(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }

    public String getAreaCode() {
       ...
    }
}

äøŠčØ˜ć® PhoneNumber ć‚’ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ćØ恗恦ꉱ恆恫ćÆć€ę¬”ć®ć‚ˆć†ćŖć‚Æćƒ©ć‚¹ć‚’ä½œęˆć—ć¾ć™ć€‚

@ExternalDomain
public class PhoneNumberConverter implements DomainConverter<PhoneNumber, String> {

    public String fromDomainToValue(PhoneNumber domain) {
        return domain.getValue();
    }

    public PhoneNumber fromValueToDomain(String value) {
        if (value == null) {
            return null;
        }
        return new PhoneNumber(value);
    }
}

ć“ć‚Œć§å¤–éƒØćƒ‰ćƒ”ć‚¤ćƒ³å®šē¾©ćÆå®Œęˆć§ć™ćŒć€ć“ć‚Œć ć‘ć§ćÆć¾ć åˆ©ē”Øć§ćć¾ć›ć‚“ć€‚ 外éƒØćƒ‰ćƒ”ć‚¤ćƒ³å®šē¾©ć‚’ @DomainConverters ćøē™»éŒ²ć—ć¾ć™ć€‚ @DomainConverters 恫ćÆč¤‡ę•°ć®å¤–éƒØćƒ‰ćƒ”ć‚¤ćƒ³å®šē¾©ć‚’ē™»éŒ²åÆčƒ½ć§ć™ć€‚

@DomainConverters({ PhoneNumberConverter.class })
public class DomainConvertersProvider {
}

ćć—ć¦ęœ€å¾Œć«ć€ @DomainConverters 恌ę³Ø釈恕悌恟ć‚Æćƒ©ć‚¹ć®å®Œå…Øäæ®é£¾åć‚’ ę³Ø釈処ē† 恮ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć«ęŒ‡å®šć—ć¾ć™ć€‚ ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć®keyćÆ态 doma.domain.converters 恧恙怂

åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚’åˆ©ē”Øć™ć‚‹ę–¹ę³•Ā¶

ä»»ę„ć®ę•°ć®åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚’ęŒć£ćŸć‚Æćƒ©ć‚¹ć‚’ę‰±ćˆć¾ć™ć€‚ ę¬”ć®ä¾‹ć®ć‚ˆć†ćŖ1ć¤ć®åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ悒ꌁ恤ć‚Æćƒ©ć‚¹ćŒć‚ć‚‹ćØć—ć¾ć™ć€‚ 恓恮ć‚Æćƒ©ć‚¹ćÆč­˜åˆ„å­ć‚’č”Øć—ć¦ć„ć¾ć™ć€‚

public class Identity<T> {

    private final int value;

    public Identity(int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }
}

äøŠčØ˜ć® Identity ć‚’ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ćØ恗恦ꉱ恆恫ćÆć€ę¬”ć®ć‚ˆć†ćŖć‚Æćƒ©ć‚¹ć‚’ä½œęˆć—ć¾ć™ć€‚ Identity ć®åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫ćÆćƒÆć‚¤ćƒ«ćƒ‰ć‚«ćƒ¼ćƒ‰ ? ć‚’ęŒ‡å®šć—ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

@ExternalDomain
public class IdentityConverter implements DomainConverter<Identity<?>, String> {

    public String fromDomainToValue(Identity<?> domain) {
        return domain.getValue();
    }

    @SuppressWarnings("rawtypes")
    public Identity<?> fromValueToDomain(String value) {
        if (value == null) {
            return null;
        }
        return new Identity(value);
    }
}

ćć®ä»–ć®čØ­å®šę–¹ę³•ć«ć¤ć„ć¦ćÆć€åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ悒ä½æē”Ø恗ćŖć„å “åˆćØåŒę§˜ć§ć™ć€‚

利ē”Ø例Ā¶

ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ćŒåž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚’ęŒć¤å “åˆć€åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫ćÆ具体ēš„ćŖåž‹ćŒåæ…要恧恙怂 ćƒÆć‚¤ćƒ«ćƒ‰ć‚«ćƒ¼ćƒ‰ ? ć‚„åž‹å¤‰ę•°ć®ęŒ‡å®šćÆć‚µćƒćƒ¼ćƒˆć•ć‚Œć¦ć„ć¾ć›ć‚“ć€‚

@Entity
public class Employee {

    @Id
    Identity<Employee> employeeId;

    String employeeName;

    PhoneNumber phoneNumber;

    JobType jobType;

    @Version
    Integer versionNo();

    ...
}
@Dao(config = AppConfig.class)
public interface EmployeeDao {

    @Select
    Employee selectById(Identity<Employee> employeeId);

    @Select
    Employee selectByPhoneNumber(PhoneNumber phoneNumber);

    @Select
    List<PhoneNumber> selectAllPhoneNumber();

    @Select
    Employee selectByJobType(JobType jobType);

    @Select
    List<JobType> selectAllJobTypes();
}

ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«ć‚Æćƒ©ć‚¹Ā¶

Embeddableļ¼ˆć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«ļ¼‰ćÆć€ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć®ćƒ†ćƒ¼ćƒ–ćƒ«ć‚„ć‚Æć‚ØćƒŖ恮ēµęžœć‚»ćƒƒćƒˆč¤‡ę•°ć‚«ćƒ©ćƒ ć‚’ć‚°ćƒ«ćƒ¼ćƒ—åŒ–ć—ć¾ć™ć€‚

ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«å®šē¾©Ā¶

ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«ć‚Æćƒ©ć‚¹ćÆ @Enbeddable 悒ę³Øé‡ˆć—ć¦ē¤ŗć—ć¾ć™ć€‚ ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ恫ćÆę°øē¶šēš„ćŖćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć«åƾåæœć™ć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恌åæ…要恧恙怂

@Embeddalbe
public class Address {

    final String city;

    final String street;

    @Column(name = "ZIP_CODE")
    final String zip;

    public Address(String city, String street, String zip) {
        this.city = city;
        this.street = street;
        this.zip = zip;
    }
}

ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«ć‚Æćƒ©ć‚¹ćÆ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ ć®ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ćØ恗恦ä½æē”Øć—ć¾ć™ć€‚

@Entity
public class Employee {
    @Id
    Integer id;

    Address address;
}

ćƒ†ćƒ¼ćƒ–ćƒ«ć‚„ēµęžœć‚»ćƒƒćƒˆćØć®ćƒžćƒƒćƒ”ćƒ³ć‚°ć«ćŠć„ć¦ć€äøŠčØ˜ć®ć‚Æćƒ©ć‚¹å®šē¾©ćÆäø‹čØ˜ć®ć‚Æćƒ©ć‚¹å®šē¾©ćØ同ē­‰ć§ć™ć€‚

@Entity
public class Employee {
    @Id
    Integer id;

    String city;

    String street;

    @Column(name = "ZIP_CODE")
    String zip;
}

ćƒćƒ¼ćƒŸćƒ³ć‚°č¦ē“„Ā¶

ćƒćƒ¼ćƒŸćƒ³ć‚°č¦ē“„ćÆ态ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«ć‚Æćƒ©ć‚¹ć‚’äæęœ‰ć™ć‚‹ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ ć‹ć‚‰å¼•ćē¶™ćŽć¾ć™ć€‚

ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰å®šē¾©Ā¶

ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«ć‚Æćƒ©ć‚¹ć®ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ćÆćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ę°øē¶šēš„恧恙怂 ć¤ć¾ć‚Šć€ćƒ†ćƒ¼ćƒ–ćƒ«ć‚„ēµęžœć‚»ćƒƒćƒˆć®ć‚«ćƒ©ćƒ ć«åƾåæœć—ć¾ć™ć€‚ ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć®åž‹ćÆę¬”ć®ć„ćšć‚Œć‹ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

@Embeddalbe
public class Address {
    ...
    String street;
}

ć‚«ćƒ©ćƒ Ā¶

ć‚«ćƒ©ćƒ ęƒ…å ±ć‚’ęŒ‡å®šć™ć‚‹ć«ćÆ态 @Column 悒ä½æē”Øć—ć¾ć™ć€‚

@Column(name = "ZIP_CODE")
final String zip;

č­˜åˆ„å­Ā¶

ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«ć‚Æćƒ©ć‚¹ć«ćÆč­˜åˆ„å­(äø»ć‚­ćƒ¼)ć‚’å®šē¾©ć§ćć¾ć›ć‚“怂

ćƒćƒ¼ć‚øćƒ§ćƒ³Ā¶

ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«ć‚Æćƒ©ć‚¹ć«ćÆę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ē”Øć®ćƒćƒ¼ć‚øćƒ§ćƒ³ć‚’å®šē¾©ć§ćć¾ć›ć‚“怂

非ę°øē¶šēš„ćŖćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰Ā¶

非ę°øē¶šēš„ćŖćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ćÆ态@Transient 悒ę³Øé‡ˆć—ć¦ē¤ŗć—ć¾ć™ć€‚

å–å¾—ę™‚ć®ēŠ¶ę…‹ć‚’ē®”ē†ć™ć‚‹ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰Ā¶

ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«ć‚Æćƒ©ć‚¹ć«ćÆå–å¾—ę™‚ć®ēŠ¶ę…‹ć‚’ē®”ē†ć™ć‚‹ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć‚’定ē¾©ć§ćć¾ć›ć‚“怂

ćƒ”ć‚½ćƒƒćƒ‰å®šē¾©Ā¶

ćƒ”ć‚½ćƒƒćƒ‰ć®å®šē¾©ć«åˆ¶é™ćÆć‚ć‚Šć¾ć›ć‚“ć€‚

ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć®åÆ視ꀧ悒 protected ć‚„ćƒ‘ćƒƒć‚±ćƒ¼ć‚øćƒ—ćƒ©ć‚¤ćƒ™ćƒ¼ćƒˆć«ć—ć¦ public ćŖćƒ”ć‚½ćƒƒćƒ‰ēµŒē”±ć§ ć‚¢ć‚Æć‚»ć‚¹ć™ć‚‹ć“ćØć‚‚ć€ćƒ”ć‚½ćƒƒćƒ‰ć‚’äø€åˆ‡ä½æē”Ø恛恚 public ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć«ē›“ęŽ„ć‚¢ć‚Æć‚»ć‚¹ć™ć‚‹ć“ćØ ć‚‚ć©ć”ć‚‰ć‚‚ć‚µćƒćƒ¼ćƒˆć•ć‚Œć¦ć„ć¾ć™ć€‚

利ē”Ø例Ā¶

ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹åŒ–ć—ć¦åˆ©ē”Øć—ć¾ć™ć€‚

Employee employee = new Employee(); // ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£
Address address = new Address("Tokyo", "Yaesu", "103-0028"); // ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«
employee.setAddress(address);

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹Ā¶

Entityļ¼ˆć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ļ¼‰ćÆć€ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć®ćƒ†ćƒ¼ćƒ–ćƒ«ć‚„ć‚Æć‚ØćƒŖ恮ēµęžœć‚»ćƒƒćƒˆć«åƾåæœć—ć¾ć™ć€‚

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£å®šē¾©Ā¶

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ćÆ @Entity 悒ę³Øé‡ˆć—ć¦ē¤ŗć—ć¾ć™ć€‚

@Entity
public class Employee {
    ...
}

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼Ā¶

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćŒćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć«åÆ¾ć—ęŒæå…„ć€ę›“ę–°ć€å‰Šé™¤ć•ć‚Œć‚‹ē›“前/ē›“å¾Œć«å‡¦ē†ć‚’å®Ÿč”Œć—ćŸć„å “åˆć€ @Entity 恮 listener 要ē“ ć« EntityListener ć®å®Ÿč£…ć‚Æćƒ©ć‚¹ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Entity(listener = EmployeeEntityListener.class)
public class Employee {
    ...
}

listener 要ē“ ć«ä½•ć‚‚ęŒ‡å®šć—ćŖć„å “åˆć€ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ćŒä»–ć®ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć‚’ē¶™ę‰æ 恗恦恄悋恋恩恆恋恧ꎔē”Ø恙悋čØ­å®šćŒå¤‰ć‚ć‚Šć¾ć™ć€‚

  • ē¶™ę‰æć—ć¦ć„ć‚‹å “åˆć€č¦Ŗć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć®čØ­å®šć‚’å¼•ćē¶™ćŽć¾ć™
  • ē¶™ę‰æ恗恦恄ćŖć„å “åˆć€ä½•ć‚‚č”Œć„ć¾ć›ć‚“ļ¼ˆ NullEntityListener 恌ä½æē”Øć•ć‚Œć¾ć™ļ¼‰

ćƒćƒ¼ćƒŸćƒ³ć‚°č¦ē“„Ā¶

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć«åƾåæœć™ć‚‹ćƒ†ćƒ¼ćƒ–ćƒ«åć‚„ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć«åƾåæœć™ć‚‹ć‚«ćƒ©ćƒ åć‚’č§£ę±ŗć™ć‚‹ćŸć‚ć®ćƒćƒ¼ćƒŸćƒ³ć‚°č¦ē“„ ć‚’å¤‰ę›“ć—ćŸć„å “åˆć€ naming 要ē“ ć« NamingType ć®åˆ—ęŒ™åž‹ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Entity(naming = NamingType.SNAKE_UPPER_CASE)
public class EmployeeInfo {
    ...
}

naming 要ē“ ć«ä½•ć‚‚ęŒ‡å®šć—ćŖć„å “åˆć€ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ćŒä»–ć®ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć‚’ē¶™ę‰æ恗恦恄悋 恋恩恆恋恧ꎔē”Ø恙悋čØ­å®šćŒå¤‰ć‚ć‚Šć¾ć™ć€‚

  • ē¶™ę‰æć—ć¦ć„ć‚‹å “åˆć€č¦Ŗć‚Øćƒ³ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć®čØ­å®šć‚’å¼•ćē¶™ćŽć¾ć™
  • ē¶™ę‰æ恗恦恄ćŖć„å “åˆć€ä½•ć‚‚č”Œć„ć¾ć›ć‚“ļ¼ˆ NamingType.NONE 恌ä½æē”Øć•ć‚Œć¾ć™ļ¼‰

NamingType.SNAKE_UPPER_CASE ćÆ态ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£åć‚„ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£åć‚’ ć‚¹ćƒćƒ¼ć‚Æć‚±ćƒ¼ć‚¹ļ¼ˆć‚¢ćƒ³ćƒ€ćƒ¼ć‚¹ć‚³ć‚¢åŒŗåˆ‡ć‚Šļ¼‰ć®å¤§ę–‡å­—ć«å¤‰ę›ć—ć¾ć™ć€‚ ć“ć®ä¾‹ć®å “åˆć€ćƒ†ćƒ¼ćƒ–ćƒ«åćÆEMPLOYEE_INFO恫ćŖć‚Šć¾ć™ć€‚

naming 要ē“ ć«ä½•ć‚‚ęŒ‡å®šć—ćŖć„å “åˆć€ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆć€ćƒ†ćƒ¼ćƒ–ćƒ«åć«ćÆć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć®å˜ē“”åć€ ć‚«ćƒ©ćƒ åć«ćÆćƒ—ćƒ­ćƒ‘ćƒ†ć‚£åćŒä½æē”Øć•ć‚Œć¾ć™ć€‚

ćƒćƒ¼ćƒŸćƒ³ć‚°č¦ē“„ćÆ态 @Table 悄 @Colum 恮 name 要ē“ ćŒęŒ‡å®šć•ć‚ŒćŖć„å “åˆć®ćæä½æē”Øć•ć‚Œć¾ć™ć€‚ @Table 悄 @Colum 恮 name 要ē“ ćŒęŒ‡å®šć•ć‚ŒćŸå “合ćÆ态 name 要ē“  ć«ęŒ‡å®šć—ćŸå€¤ćŒä½æē”Øć•ć‚Œć€ćƒćƒ¼ćƒŸćƒ³ć‚°č¦ē“„ćÆ適ē”Øć•ć‚Œć¾ć›ć‚“ć€‚

ć‚¤ćƒŸćƒ„ćƒ¼ć‚æćƒ–ćƒ«ćŖć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£Ā¶

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚’ć‚¤ćƒŸćƒ„ćƒ¼ć‚æćƒ–ćƒ«ćŖć‚Ŗ惖ć‚ø悧ć‚Æ惈ćØć—ć¦ę‰±ć„ćŸć„å “åˆćÆ @Entity 恮 immutable 要ē“ ć« true 悒čØ­å®šć—ć¾ć™ć€‚

@Entity(immutable = true)
public class Employee {
    @Id
    final Integer id;
    final String name;
    @Version
    final Integer version;

    public Employee(Integer id, String name, Integer version) {
        this.id = id;
        this.name = name;
        this.version = version;
    }
}

ę°øē¶šēš„ćŖćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć«ćÆ final äæ®é£¾å­ćŒåæ…é ˆć§ć™ć€‚

ćƒ†ćƒ¼ćƒ–ćƒ«Ā¶

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć«åƾåæœć™ć‚‹ćƒ†ćƒ¼ćƒ–ćƒ«ęƒ…å ±ć‚’ęŒ‡å®šć™ć‚‹ć«ćÆ态 @Table 悒ä½æē”Øć—ć¾ć™ć€‚

name 要ē“ ć§ćƒ†ćƒ¼ćƒ–ćƒ«åć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Entity
@Table(name = "EMP")
public class Employee {
    ...
}

@Table 悒ä½æē”Ø恗ćŖ恄态悂恗恏ćÆ @Table 恮 name 要ē“ ć‚’ä½æē”Ø恗ćŖć„å “åˆć€ ćƒ†ćƒ¼ćƒ–ćƒ«åćÆ ćƒćƒ¼ćƒŸćƒ³ć‚°č¦ē“„ ć«ć‚ˆć‚Šč§£ę±ŗć•ć‚Œć¾ć™ć€‚

ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰å®šē¾©Ā¶

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć®ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ćÆćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ę°øē¶šēš„恧恙怂 ć¤ć¾ć‚Šć€ćƒ†ćƒ¼ćƒ–ćƒ«ć‚„ēµęžœć‚»ćƒƒćƒˆć®ć‚«ćƒ©ćƒ ć«åƾåæœć—ć¾ć™ć€‚ ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć®åž‹ćÆę¬”ć®ć„ćšć‚Œć‹ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

@Entity
public class Employee {
    ...
    Integer employeeId;
}

ć‚«ćƒ©ćƒ Ā¶

ć‚«ćƒ©ćƒ ęƒ…å ±ć‚’ęŒ‡å®šć™ć‚‹ć«ćÆ态 @Column 悒ä½æē”Øć—ć¾ć™ć€‚

name 要ē“ ć§ć‚«ćƒ©ćƒ åć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Column(name = "ENAME")
String employeeName;

insertable 要ē“ ć‚„ updatable 要ē“ ć§ęŒæå…„ć‚„ę›“ę–°ć®åÆ¾č±”ćØć™ć‚‹ć‹ć©ć†ć‹ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Column(insertable = false, updatable = false)
String employeeName;

@Column 悒ä½æē”Ø恗ćŖ恄态悂恗恏ćÆ @Column 恮 name 要ē“ ć‚’ä½æē”Ø恗ćŖć„å “åˆć€ ć‚«ćƒ©ćƒ åćÆ ćƒćƒ¼ćƒŸćƒ³ć‚°č¦ē“„ ć«ć‚ˆć‚Šč§£ę±ŗć•ć‚Œć¾ć™ć€‚

ćƒŽćƒ¼ćƒˆ

ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć®åž‹ćŒ ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«ć‚Æćƒ©ć‚¹ ć®å “åˆć€ć€€@Column ćÆęŒ‡å®šć§ćć¾ć›ć‚“ć€‚

č­˜åˆ„å­Ā¶

č­˜åˆ„å­(äø»ć‚­ćƒ¼)恧恂悋恓ćØć‚’ęŒ‡å®šć™ć‚‹ć«ćÆ态 @Id 悒ä½æć„ć¾ć™ć€‚

@Id
Integer id;

č¤‡åˆäø»ć‚­ćƒ¼ć®å “合ćÆ @Id ć‚’č¤‡ę•°ęŒ‡å®šć—ć¾ć™ć€‚

@Id
Integer id;

@Id
Integer id2;

ćƒŽćƒ¼ćƒˆ

ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć®åž‹ćŒ ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«ć‚Æćƒ©ć‚¹ ć®å “åˆć€ć€€@Id ćÆęŒ‡å®šć§ćć¾ć›ć‚“ć€‚

č­˜åˆ„å­ć®č‡Ŗ動ē”ŸęˆĀ¶

č­˜åˆ„å­ć‚’č‡Ŗ動ē”Ÿęˆć™ć‚‹ć«ćÆ @GeneratedValue 悒ę³Øé‡ˆć—ć¦ē¤ŗć—ć¾ć™ć€‚ ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć®åž‹ćÆ仄äø‹ć®ć„ćšć‚Œć‹ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

  • java.lang.Number ć®ć‚µćƒ–ć‚æ悤惗
  • java.lang.Number ć®ć‚µćƒ–ć‚æć‚¤ćƒ—ć‚’å€¤ćØ恙悋 ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹
  • äøŠčØ˜ć®ć„ćšć‚Œć‹ć‚’č¦ē“ ć®åž‹ćØ恙悋 java.util.Optional
  • OptionalInt
  • OptionalLong
  • OptionalDouble
  • ę•°å€¤ć®ćƒ—ćƒŖćƒŸćƒ†ć‚£ćƒ–åž‹

ćƒŽćƒ¼ćƒˆ

惗ćƒŖćƒŸćƒ†ć‚£ćƒ–åž‹ć‚’ä½æć†å “åˆć€č‡Ŗ動ē”Ÿęˆć•ć‚ŒćŸå€¤ćŒē¢ŗå®Ÿć«čØ­å®šć•ć‚Œć‚‹ć‚ˆć†ć«ć™ć‚‹ć«ćÆåˆęœŸå€¤ć« -1 ćŖ恩 0 ęœŖęŗ€ć®å€¤ć‚’ę˜Žē¤ŗć—ć¦ćć ć•ć„ć€‚

IDENTITY悒ä½æć£ćŸč­˜åˆ„å­ć®č‡Ŗ動ē”ŸęˆĀ¶

ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć®IDENTITYč‡Ŗ動ē”Ÿęˆę©Ÿčƒ½ć‚’利ē”Øć™ć‚‹ę–¹ę³•ć§ć™ć€‚ RDBMSć«ć‚ˆć£ć¦ćÆć‚µćƒćƒ¼ćƒˆć•ć‚Œć¦ć„ć¾ć›ć‚“ć€‚ ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć«åƾåæœć™ć‚‹ć‚«ćƒ©ćƒ ć®å®šē¾©ć§IDENTITYč‡Ŗ動ē”Ÿęˆć‚’ęœ‰åŠ¹ć«ć—ć¦ćŠćåæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Integer id;
ć‚·ćƒ¼ć‚±ćƒ³ć‚¹ć‚’ä½æć£ćŸč­˜åˆ„å­ć®č‡Ŗ動ē”ŸęˆĀ¶

ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć®ć‚·ćƒ¼ć‚±ćƒ³ć‚¹ć‚’åˆ©ē”Øć™ć‚‹ę–¹ę³•ć§ć™ć€‚ RDBMSć«ć‚ˆć£ć¦ćÆć‚µćƒćƒ¼ćƒˆć•ć‚Œć¦ć„ć¾ć›ć‚“ć€‚

@SequenceGenerator 恧ćÆć€ć‚·ćƒ¼ć‚±ćƒ³ć‚¹ć®åå‰ć€å‰²ć‚Šå½“ć¦ć‚µć‚¤ć‚ŗć€åˆęœŸå€¤ē­‰ć‚’čØ­å®šć§ćć¾ć™ć€‚ ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć«ć‚ć‚‰ć‹ć˜ć‚ć‚·ćƒ¼ć‚±ćƒ³ć‚¹ć‚’å®šē¾©ć—ć¦ćŠćåæ…č¦ćŒć‚ć‚Šć¾ć™ćŒć€ ćć®å®šē¾©ćÆ @SequenceGenerator ć®å®šē¾©ćØć‚ć‚ć›ć¦ćŠćåæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@SequenceGenerator(sequence = "EMPLOYEE_SEQ")
Integer id;
ćƒ†ćƒ¼ćƒ–ćƒ«ć‚’ä½æć£ćŸč­˜åˆ„å­ć®č‡Ŗå‹•ęŽ”ē•ŖĀ¶

ē”Ÿęˆć•ć‚Œć‚‹č­˜åˆ„å­ć‚’ćƒ†ćƒ¼ćƒ–ćƒ«ć§ē®”ē†ć™ć‚‹ę–¹ę³•ć§ć™ć€‚ ć™ć¹ć¦ć®RDBMSć§åˆ©ē”Øć§ćć¾ć™ć€‚

@TableGenerator 恧ćÆć€ćƒ†ćƒ¼ćƒ–ćƒ«åć€å‰²ć‚Šå½“ć¦ć‚µć‚¤ć‚ŗć€åˆęœŸå€¤ē­‰ć‚’čØ­å®šć§ćć¾ć™ć€‚ ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć«ć‚ć‚‰ć‹ć˜ć‚ćƒ†ćƒ¼ćƒ–ćƒ«ć‚’å®šē¾©ć—ć¦ćŠćåæ…č¦ćŒć‚ć‚Šć¾ć™ćŒć€ ćć®å®šē¾©ćÆ @TableGenerator ć®å®šē¾©ćØć‚ć‚ć›ć¦ćŠćåæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚ ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆ态 ID_GENERATOR ćØć„ć†åå‰ć®ćƒ†ćƒ¼ćƒ–ćƒ«ć«ć€ę–‡å­—åˆ—åž‹ć® PK ćØę•°å€¤åž‹ć® VALUE ćØ恄恆2ć¤ć®ć‚«ćƒ©ćƒ ćŒå®šē¾©ć•ć‚Œć¦ć„悋悂恮ćØć—ć¦å‹•ä½œć—ć¾ć™ļ¼ˆ PK ć‚«ćƒ©ćƒ ćŒäø»ć‚­ćƒ¼ć§ć™ļ¼‰ć€‚ PK ć‚«ćƒ©ćƒ ć«ćÆć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć”ćØ恮äø€ę„ćŖåå‰ć€ VALUE ć‚«ćƒ©ćƒ ć«ćÆč­˜åˆ„å­ć®å€¤ćŒę ¼ē“ć•ć‚Œć¾ć™ć€‚ ćƒ†ćƒ¼ćƒ–ćƒ«ć«ćÆ态ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć”ćØć®ćƒ¬ć‚³ćƒ¼ćƒ‰ć‚’ć‚ć‚‰ć‹ć˜ć‚ē™»éŒ²ć—ć¦ćŠćåæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚

@Id
@GeneratedValue(strategy = GenerationType.TABLE)
@TableGenerator(pkColumnValue = "EMPLOYEE_ID")
Integer id;

@TableGenerator 恮 pkColumnValue 要ē“ ć«ćÆ态 č­˜åˆ„å­ć‚’ē®”ē†ć™ć‚‹ćƒ†ćƒ¼ćƒ–ćƒ« ļ¼ˆćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆ态 ID_GENERATOR ćØć„ć†åå‰ć®ćƒ†ćƒ¼ćƒ–ćƒ«ļ¼‰ć®äø»ć‚­ćƒ¼ć®å€¤ć‚’ęŒ‡å®šć—ć¾ć™ć€‚

ćƒćƒ¼ć‚øćƒ§ćƒ³Ā¶

ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ē”Øć®ćƒćƒ¼ć‚øćƒ§ćƒ³ćÆ @Version 悒ę³Øé‡ˆć—ć¦ē¤ŗć—ć¾ć™ć€‚ ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć®åž‹ćÆ仄äø‹ć®ć„ćšć‚Œć‹ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

  • java.lang.Number ć®ć‚µćƒ–ć‚æ悤惗
  • java.lang.Number ć®ć‚µćƒ–ć‚æć‚¤ćƒ—ć‚’å€¤ćØ恙悋 ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹
  • äøŠčØ˜ć®ć„ćšć‚Œć‹ć‚’č¦ē“ ć®åž‹ćØ恙悋 java.util.Optional
  • OptionalInt
  • OptionalLong
  • OptionalDouble
  • ę•°å€¤ć®ćƒ—ćƒŖćƒŸćƒ†ć‚£ćƒ–åž‹
@Version
Integer version;

ćƒŽćƒ¼ćƒˆ

ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć®åž‹ćŒ ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«ć‚Æćƒ©ć‚¹ ć®å “åˆć€ć€€@Version ćÆęŒ‡å®šć§ćć¾ć›ć‚“ć€‚

非ę°øē¶šēš„ćŖćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰Ā¶

非ę°øē¶šēš„ćŖćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ćÆć€ćƒ†ćƒ¼ćƒ–ćƒ«ć‚„ēµęžœć‚»ćƒƒćƒˆć®ć‚«ćƒ©ćƒ ć«åƾåæœć—ć¾ć›ć‚“ć€‚

@Transient 悒ę³Øé‡ˆć—ć¦ē¤ŗć—ć¾ć™ć€‚

ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć®åž‹ć‚„åÆč¦–ę€§ć«åˆ¶é™ćÆć‚ć‚Šć¾ć›ć‚“ć€‚

@Transient
List<String> nameList;

å–å¾—ę™‚ć®ēŠ¶ę…‹ć‚’ē®”ē†ć™ć‚‹ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰Ā¶

å–å¾—ę™‚ć®ēŠ¶ę…‹ćØćÆ态ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćŒDaoć‹ć‚‰å–å¾—ć•ć‚ŒćØćć®å…Øćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®å€¤ć§ć™ć€‚ å–å¾—ę™‚ć®ēŠ¶ę…‹ć‚’äæęŒć—ć¦ćŠćć“ćØć§ć€ę›“ę–°å‡¦ē†ć‚’å®Ÿč”Œć™ć‚‹éš›ć€UPDATEꖇ恮SETå„ć«å¤‰ę›“ć—ćŸćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć®ćæć‚’å«ć‚ć‚‰ć‚Œć¾ć™ć€‚ å–å¾—ę™‚ć®ēŠ¶ę…‹ć‚’ē®”ē†ć™ć‚‹ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ćÆć€ćƒ†ćƒ¼ćƒ–ćƒ«ć‚„ēµęžœć‚»ćƒƒćƒˆć®ć‚«ćƒ©ćƒ ć«åƾåæœć—ć¾ć›ć‚“ć€‚

@OriginalStates 悒ę³Øé‡ˆć—ć¦ē¤ŗć—ć¾ć™ć€‚

@OriginalStates
Employee originalStates;

ćƒŽćƒ¼ćƒˆ

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć®ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć« ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«ć‚Æćƒ©ć‚¹ ćŒå«ć¾ć‚Œć¦ć„ć‚‹å “åˆć€ć€€@OriginalStates ćÆä½æē”Øć§ćć¾ć›ć‚“ć€‚

ćƒ”ć‚½ćƒƒćƒ‰å®šē¾©Ā¶

ćƒ”ć‚½ćƒƒćƒ‰ć®å®šē¾©ć«åˆ¶é™ćÆć‚ć‚Šć¾ć›ć‚“ć€‚

ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć®åÆ視ꀧ悒 protected ć‚„ćƒ‘ćƒƒć‚±ćƒ¼ć‚øćƒ—ćƒ©ć‚¤ćƒ™ćƒ¼ćƒˆć«ć—ć¦ public ćŖćƒ”ć‚½ćƒƒćƒ‰ēµŒē”±ć§ ć‚¢ć‚Æć‚»ć‚¹ć™ć‚‹ć“ćØć‚‚ć€ćƒ”ć‚½ćƒƒćƒ‰ć‚’äø€åˆ‡ä½æē”Ø恛恚 public ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć«ē›“ęŽ„ć‚¢ć‚Æć‚»ć‚¹ć™ć‚‹ć“ćØ ć‚‚ć©ć”ć‚‰ć‚‚ć‚µćƒćƒ¼ćƒˆć•ć‚Œć¦ć„ć¾ć™ć€‚

利ē”Ø例Ā¶

ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹åŒ–ć—ć¦åˆ©ē”Øć—ć¾ć™ć€‚

Employee employee = new Employee();
employee.setEmployeeId(1);
employee.setEmployeeName("SMITH");
employee.setSalary(new BigDecimal(1000));

Daoć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹Ā¶

Data Access Object ļ¼ˆDaoļ¼‰ ćÆćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć‚¢ć‚Æć‚»ć‚¹ć®ćŸć‚ć®ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć§ć™ć€‚

Dao定ē¾©Ā¶

DaoćÆ @Dao 恌ę³Øé‡ˆć•ć‚ŒćŸć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ćØć—ć¦å®šē¾©ć—ć¾ć™ć€‚

ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć®å®Ÿč£…ć‚Æćƒ©ć‚¹ćÆaptć«ć‚ˆć‚Šć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ę™‚ć«č‡Ŗ動ē”Ÿęˆć•ć‚Œć¾ć™ć€‚

ć‚Æć‚ØćƒŖ定ē¾©Ā¶

ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ä½æć£ć¦ ć‚Æć‚ØćƒŖ ć‚’å®šē¾©ć§ćć¾ć™ć€‚

Javać‚³ćƒ¼ćƒ‰ć§ä»»ę„ć®ć‚Æć‚ØćƒŖ悒ēµ„ćæē«‹ć¦ć‚‹ć«ćÆ ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆćƒ”ć‚½ćƒƒćƒ‰ 恮äø­ć§ ć‚Æć‚ØćƒŖćƒ“ćƒ«ćƒ€ 悒ä½æē”Øć—ć¦ćć ć•ć„ć€‚

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆćƒ”ć‚½ćƒƒćƒ‰Ā¶

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆćƒ”ć‚½ćƒƒćƒ‰ć§ćÆä»»ę„ć®å‡¦ē†ć‚’čؘčæ°ć§ćć¾ć™ć€‚

Config.get 恫Daoć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ęø”恙ćØDaoć«é–¢é€£ć„ć‘ć‚‰ć‚ŒćŸ Config ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’å–å¾—ć§ćć¾ć™ć€‚

@Dao(config = AppConfig.class)
public interface EmployeeDao {

    default int count() {
        Config config = Config.get(this);
        SelectBuilder builder = SelectBuilder.newInstance(config);
        builder.sql("select count(*) from employee");
        return builder.getScalarSingleResult(int.class);
    }
}

利ē”Ø例Ā¶

ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć™ć‚‹ćØę³Ø釈処ē†ć«ć‚ˆć‚Šå®Ÿč£…ć‚Æćƒ©ć‚¹ćŒē”Ÿęˆć•ć‚Œć¾ć™ć€‚ å®Ÿč£…ć‚Æćƒ©ć‚¹ć‚’ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹åŒ–ć—ć¦ä½æē”Øć—ć¦ćć ć•ć„ć€‚ 恟恠恗态čح定ć‚Æćƒ©ć‚¹ć‚’DIć‚³ćƒ³ćƒ†ćƒŠć§ē®”ē†ć™ć‚‹å “åˆć€ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹åŒ–ćÆDIć‚³ćƒ³ćƒ†ćƒŠć§åˆ¶å¾”ć—ć¦ćć ć•ć„ć€‚

EmployeeDao employeeDao = new EmployeeDaoImpl();
Employee employee = employeeDao.selectById(1);

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆć€å®Ÿč£…ć‚Æćƒ©ć‚¹ć®åå‰ćÆć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć®åå‰ć« Impl ć‚’ć‚µćƒ•ć‚£ćƒƒć‚Æć‚¹ć—ćŸć‚‚ć®ć«ćŖć‚Šć¾ć™ć€‚ ćƒ‘ćƒƒć‚±ćƒ¼ć‚øć‚„ć‚µćƒ•ć‚£ćƒƒć‚Æć‚¹ć‚’å¤‰ę›“ć™ć‚‹ć«ćÆ ę³Ø釈処ē† ć‚’å‚ē…§ć—ć¦ćć ć•ć„ć€‚

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ悒ä½æē”Øć—ćŸå “åˆćÆ态 @Dao 恮 config 要ē“ ć«ęŒ‡å®šć—ćŸčØ­å®šć«ć‚ˆć‚Š DataSource 恌ę±ŗå®šć•ć‚Œć¾ć™ćŒć€ ē‰¹å®šć® DataSource ć‚’ęŒ‡å®šć—ć¦ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹åŒ–ć™ć‚‹ć“ćØ悂åÆčƒ½ć§ć™ć€‚

DataSource dataSource = ...;
EmployeeDao employeeDao = new EmployeeDaoImpl(dataSource);
Employee employee = employeeDao.selectById(1);

ć¾ćŸåŒę§˜ć«ć€ Connection ć‚’ęŒ‡å®šć—ć¦ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹åŒ–ć™ć‚‹ć“ćØ悂åÆčƒ½ć§ć™ć€‚

Connection connection = ...;
EmployeeDao employeeDao = new EmployeeDaoImpl(connection);
Employee employee = employeeDao.selectById(1);

Daoć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ćÆć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ćØ1åƾ1恧ēµć³ć¤ć„ć¦ć„ć‚‹ć‚ć‘ć§ćÆć‚ć‚Šć¾ć›ć‚“ć€‚ ć²ćØ恤恮Daoć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć§č¤‡ę•°ć®ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć‚’ę‰±ćˆć¾ć™ć€‚

@Dao(config = AppConfig.class)
public interface MyDao {

    @Select
    Employee selectEmployeeById(int id);

    @Select
    Department selectDepartmentByName(String name);

    @Update
    int updateAddress(Address address);
}

ć‚Æć‚ØćƒŖĀ¶

ꤜē“¢Ā¶

ꤜē“¢ć‚’č”Œć†ć«ćÆ态 @Select 悒Daoć®ćƒ”ć‚½ćƒƒćƒ‰ć«ę³Øé‡ˆć—ć¾ć™ć€‚

@Config(config = AppConfig.class)
public interface EmployeeDao {
    @Select
    List<Employee> selectByDepartmentName(String departmentName);
    ...
}

ꤜē“¢ć§ćÆ态 SQLćƒ•ć‚”ć‚¤ćƒ«ćŒåæ…é ˆ 恧恙怂 ꤜē“¢ē³»ć®SQL悒č‡Ŗ動ē”Ÿęˆć™ć‚‹ę©Ÿčƒ½ćÆć‚ć‚Šć¾ć›ć‚“ć€‚

ćƒŽćƒ¼ćƒˆ

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć‚’åˆ©ē”Øć™ć‚‹å “åˆć€ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ćÆ ꤜē“¢ēµęžœć«åæœć˜ć¦ ä½œęˆć™ć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚ 恟ćØ恈恰态EMPLOYEEćƒ†ćƒ¼ćƒ–ćƒ«ć«åƾåæœć™ć‚‹Employeeć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ćŒå®šē¾©ć•ć‚Œć¦ć„ć‚‹å “åˆć€ EMPLOYEEćƒ†ćƒ¼ćƒ–ćƒ«ć®ć‚«ćƒ©ćƒ ć‚’å«ć‚€ēµęžœć‚»ćƒƒćƒˆćÆEmployeeć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć§å—ć‘ć‚‰ć‚Œć¾ć™ćŒć€ EMPLOYEEćƒ†ćƒ¼ćƒ–ćƒ«ćØDEPARTMENTćƒ†ćƒ¼ćƒ–ćƒ«ć‚’ēµåˆć—ć¦å¾—ć‚‰ć‚Œć‚‹ēµęžœć‚»ćƒƒćƒˆć«åÆ¾ć—ć¦ćÆ态 Employeeć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ćØćÆåˆ„ć®ć‚Æćƒ©ć‚¹ļ¼ˆćŸćØ恈恰EmployeeDepartmentć‚Æćƒ©ć‚¹ļ¼‰ćŒåæ…要恧恙怂

å•ć„åˆć‚ć›ę”ä»¶Ā¶

å•ć„åˆć‚ć›ę”ä»¶ć«ćÆćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ悒ä½æē”Øć—ć¾ć™ć€‚ 利ē”Øć§ćć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆ仄äø‹ć®ć‚‚恮恧恙怂

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®ę•°ć«åˆ¶é™ćÆć‚ć‚Šć¾ć›ć‚“ć€‚ ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćŒ åŸŗęœ¬åž‹ 悂恗恏ćÆ ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ ć®å “åˆć€å¼•ę•°ć‚’ null ć«ć§ćć¾ć™ć€‚ ćć‚Œä»„å¤–ć®åž‹ć®å “åˆć€å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚

åŸŗęœ¬åž‹ć‚„ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć‚’ä½æć£ćŸå•ć„åˆć‚ć›Ā¶

ćƒ”ć‚½ćƒƒćƒ‰ć‚„ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫 åŸŗęœ¬åž‹ 悄 ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ ć‚’å®šē¾©ć—ć¾ć™ć€‚

@Select
List<Employee> selectByNameAndSalary(String name, Salary salary);

SQLćƒ•ć‚”ć‚¤ćƒ«ć§ćÆSQLć‚³ćƒ”ćƒ³ćƒˆć‚’ä½æć„ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ悒SQLć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć•ć›ć¾ć™ć€‚ SQLć‚³ćƒ”ćƒ³ćƒˆć§ćÆćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æåć‚’å‚ē…§ć—ć¾ć™ć€‚

select * from employee where employee_name = /* name */'hoge' and salary > /* salary */100
ä»»ę„ć®åž‹ć‚’ä½æć£ćŸå•ć„åˆć‚ć›Ā¶

ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć«ä»»ę„ć®åž‹ć‚’ä½æē”Øć™ć‚‹å “åˆćÆ态惉惃惈 . ć§ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć«ć‚¢ć‚Æć‚»ć‚¹ć—ćŸć‚Šćƒ”ć‚½ćƒƒćƒ‰ć‚’å‘¼ć³å‡ŗ恙ćŖ恩恗恦SQLć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć•ć›ć¾ć™ć€‚

@Select
List<Employee> selectByExample(Employee employee);
select * from employee where employee_name = /* employee.name */'hoge' and salary > /* employee.getSalary() */100

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆč¤‡ę•°ęŒ‡å®šć§ćć¾ć™ć€‚

@Select
List<Employee> selectByEmployeeAndDepartment(Employee employee, Department department);
Iterable悒ä½æć£ćŸIN叄ćøć®ćƒžćƒƒćƒ”ćƒ³ć‚°Ā¶

java.lang.Iterable ć®ć‚µćƒ–ć‚æ悤惗ćÆ态 INå„ć‚’åˆ©ē”Ø恗恟ꤜē“¢ć‚’č”Œć†å “åˆć«ä½æē”Øć—ć¾ć™ć€‚

@Select
List<Employee> selectByNames(List<String> names);
select * from employee where employee_name in /* names */('aaa','bbb','ccc')

1ä»¶ę¤œē“¢Ā¶

1ä»¶ć‚’ę¤œē“¢ć™ć‚‹ć«ćÆć€ćƒ”ć‚½ćƒƒćƒ‰ć®ęˆ»ć‚Šå€¤ć®åž‹ć‚’ę¬”ć®ć„ćšć‚Œć‹ć«ć—ć¾ć™ć€‚

@Select
Employee selectByNameAndSalary(String name, BigDecimal salary);

ęˆ»ć‚Šå€¤ć®åž‹ćŒ Optional 恧ćŖ恏态恋恤态ēµęžœćŒ0件恮ćØ恍ćÆ null 恌čæ”ć•ć‚Œć¾ć™ć€‚ ꤜē“¢ēµęžœć®äæčؼ ć‚’ęœ‰åŠ¹ć«ć—ćŸå “åˆćÆć€ęˆ»ć‚Šå€¤ć®åž‹ć«é–¢äæ‚ćŖ恏ēµęžœćŒ0件ćŖć‚‰ć°ä¾‹å¤–ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

ēµęžœćŒ2件仄äøŠå­˜åœØ恙悋ćØ恍ćÆ态 NonUniqueResultException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

č¤‡ę•°ä»¶ę¤œē“¢Ā¶

č¤‡ę•°ä»¶ć‚’ę¤œē“¢ć™ć‚‹ć«ćÆć€ćƒ”ć‚½ćƒƒćƒ‰ć®ęˆ»ć‚Šå€¤ć®åž‹ć‚’ java.util.List ć«ć—ć¾ć™ć€‚ List 恮要ē“ ć®åž‹ć«ćÆę¬”ć®ć‚‚ć®ćŒä½æē”Øć§ćć¾ć™ć€‚

@Select
List<Employee> selectByNameAndSalary(String name, Salary salary);

ēµęžœćŒ0件恮ćØ恍ćÆ null 恧ćÆćŖ恏ē©ŗ恮List恌čæ”ć•ć‚Œć¾ć™ć€‚ 恟恠恗态 ꤜē“¢ēµęžœć®äæčؼ ć‚’ęœ‰åŠ¹ć«ć—ćŸå “åˆć€ēµęžœćŒ0件ćŖć‚‰ć°ä¾‹å¤–ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

ć‚¹ćƒˆćƒŖćƒ¼ćƒ ę¤œē“¢Ā¶

å…Ø件悒äø€åŗ¦ć« java.util.List ć§å—ć‘å–ć‚‹ć®ć§ćÆćŖ恏 java.util.stream.Stream ć§ę‰±ć„ćŸć„å “åˆćÆć€ć‚¹ćƒˆćƒŖćƒ¼ćƒ ę¤œē“¢ć‚’利ē”Øć§ćć¾ć™ć€‚

ć‚¹ćƒˆćƒŖćƒ¼ćƒ ę¤œē“¢ć«ćÆ态 Stream 悒 java.util.Function ćøęø”ć™ę–¹ę³•ćØęˆ»ć‚Šå€¤ć§čæ”ć™ę–¹ę³•ć®2ēØ®é”žćŒć‚ć‚Šć¾ć™ć€‚

Functionćøęø”ć™ę–¹ę³•Ā¶

@Select 恮 strategy 要ē“ ć« SelectType.STREAM 悒čØ­å®šć—ć€ ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫 java.util.Function<Stream<TARGET>, RESULT> 悂恗恏ćÆ java.util.Function<Stream<TARGET>, RESULT> ć®ć‚µćƒ–ć‚æć‚¤ćƒ—ć‚’å®šē¾©ć—ć¾ć™ć€‚

@Select(strategy = SelectType.STREAM)
BigDecimal selectByNameAndSalary(String name, BigDecimal salary, Function<Stream<Employee>, BigDecimal> mapper);

å‘¼ć³å‡ŗć—å…ƒćÆć‚¹ćƒˆćƒŖćƒ¼ćƒ ć‚’å—ć‘å–ć£ć¦ēµęžœć‚’čæ”ć™ćƒ©ćƒ ćƒ€å¼ć‚’ęø”ć—ć¾ć™ć€‚

EmployeeDao dao = new EmployeeDaoImpl();
BigDecimal result = dao.selectByNameAndSalary(name, salary, stream -> {
    return ...;
});

Function<Stream<TARGET>, RESULT> ć®åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ TARGET ćÆę¬”ć®ć„ćšć‚Œć‹ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ RESULT ćÆDaoć®ćƒ”ć‚½ćƒƒćƒ‰ć®ęˆ»ć‚Šå€¤ć«åˆć‚ć›ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

ꤜē“¢ēµęžœć®äæčؼ ć‚’ęœ‰åŠ¹ć«ć—ćŸå “åˆć€ēµęžœćŒ0件ćŖć‚‰ć°ä¾‹å¤–ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

ęˆ»ć‚Šå€¤ć§čæ”ć™ę–¹ę³•Ā¶

ćƒ”ć‚½ćƒƒćƒ‰ć®ęˆ»ć‚Šå€¤ć®åž‹ć‚’ java.util.stream.Stream ć«ć—ć¾ć™ć€‚ Stream 恮要ē“ ć®åž‹ć«ćÆę¬”ć®ć‚‚ć®ćŒä½æē”Øć§ćć¾ć™ć€‚

@Select
Stream<Employee> selectByNameAndSalary(String name, BigDecimal salary);

å‘¼ć³å‡ŗć—å…ƒć§ć™ć€‚

EmployeeDao dao = new EmployeeDaoImpl();
try (Stream<Employee> stream = dao.selectByNameAndSalary(name, salary)) {
  ...
}

ꤜē“¢ēµęžœć®äæčؼ ć‚’ęœ‰åŠ¹ć«ć—ćŸå “åˆć€ēµęžœćŒ0件ćŖć‚‰ć°ä¾‹å¤–ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

č­¦å‘Š

ćƒŖć‚½ćƒ¼ć‚¹ć®č§£ę”¾ę¼ć‚Œć‚’é˜²ććŸć‚ć«ć‚¹ćƒˆćƒŖćƒ¼ćƒ ćÆåæ…恚ć‚Æćƒ­ćƒ¼ć‚ŗć—ć¦ćć ć•ć„ć€‚ ć‚¹ćƒˆćƒŖćƒ¼ćƒ ć‚’ć‚Æćƒ­ćƒ¼ć‚ŗ恗ćŖ恄ćØ态 java.sql.ResultSet 态 java.sql.PreparedStatement 态 java.sql.Connection 恮ć‚Æćƒ­ćƒ¼ć‚ŗćŒč”Œć‚ć‚Œć¾ć›ć‚“ć€‚

ćƒŽćƒ¼ćƒˆ

ęˆ»ć‚Šå€¤ć§čæ”ć™ę–¹ę³•ćÆćƒŖć‚½ćƒ¼ć‚¹č§£ę”¾ę¼ć‚Œć®ćƒŖć‚¹ć‚Æ恌恂悋恟悁态ē‰¹ć«ē†ē”±ćŒćŖ恄限悊ćÆ态 Functionćøęø”ć™ę–¹ę³•ć®ęŽ”ē”Ø悒ꤜčØŽć—ć¦ćć ć•ć„ć€‚ ę³Øꄏ悒äæƒć™ćŸć‚ć«Daoć®ćƒ”ć‚½ćƒƒćƒ‰ć«åÆ¾ć—ć¦č­¦å‘Šćƒ”ćƒƒć‚»ćƒ¼ć‚ø悒č”Øē¤ŗć—ć¾ć™ć€‚ č­¦å‘Šć‚’ęŠ‘åˆ¶ć™ć‚‹ć«ćÆ仄äø‹ć®ć‚ˆć†ć« @Suppress ć‚’ęŒ‡å®šć—ć¦ćć ć•ć„ć€‚

@Select
@Suppress(messages = { Message.DOMA4274 })
Stream<Employee> selectByNameAndSalary(String name, BigDecimal salary);

ć‚³ćƒ¬ć‚Æ惈ꤜē“¢Ā¶

ꤜē“¢ēµęžœć‚’ java.util.Collector ć§å‡¦ē†ć—ćŸć„å “合ćÆć€ć‚³ćƒ¬ć‚Æ惈ꤜē“¢ć‚’利ē”Øć§ćć¾ć™ć€‚

ć‚³ćƒ¬ć‚Æ惈ꤜē“¢ć‚’å®Ÿę–½ć™ć‚‹ć«ćÆ态 @Select 恮 strategy 要ē“ ć« SelectType.COLLECT 悒čØ­å®šć—ć€ ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫 java.stream.Collector<TARGET, ACCUMULATION, RESULT> 悂恗恏ćÆ java.stream.Collector<TARGET, ?, RESULT> ć®ć‚µćƒ–ć‚æć‚¤ćƒ—ć‚’å®šē¾©ć—ć¾ć™ć€‚

@Select(strategy = SelectType.COLLECT)
<RESULT> RESULT selectBySalary(BigDecimal salary, Collector<Employee, ?, RESULT> collector);

å‘¼ć³å‡ŗć—å…ƒćÆ Collector ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ęø”ć—ć¾ć™ć€‚

EmployeeDao dao = new EmployeeDaoImpl();
Map<Integer, List<Employee>> result =
    dao.selectBySalary(salary, Collectors.groupingBy(Employee::getDepartmentId));

Collector<TARGET, ACCUMULATION, RESULT> ć®åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ TARGET ćÆę¬”ć®ć„ćšć‚Œć‹ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ RESULT ćÆDaoć®ćƒ”ć‚½ćƒƒćƒ‰ć®ęˆ»ć‚Šå€¤ć«åˆć‚ć›ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

ꤜē“¢ēµęžœć®äæčؼ ć‚’ęœ‰åŠ¹ć«ć—ćŸå “åˆć€ēµęžœćŒ0件ćŖć‚‰ć°ä¾‹å¤–ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

ćƒŽćƒ¼ćƒˆ

ć‚³ćƒ¬ć‚Æ惈ꤜē“¢ćÆć‚¹ćƒˆćƒŖćƒ¼ćƒ ę¤œē“¢ć®Function恫ęø”ć™ę–¹ę³•ć®ć‚·ćƒ§ćƒ¼ćƒˆć‚«ćƒƒćƒˆć§ć™ć€‚ ć‚¹ćƒˆćƒŖćƒ¼ćƒ ę¤œē“¢ć§å¾—ć‚‰ć‚Œć‚‹ Stream ć‚Ŗ惖ć‚ø悧ć‚Æ惈恮 collect ćƒ”ć‚½ćƒƒćƒ‰ć‚’ä½æć£ć¦åŒē­‰ć®ć“ćØćŒć§ćć¾ć™ć€‚

ꤜē“¢ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć‚’åˆ©ē”Ø恗恟ꤜē“¢Ā¶

ꤜē“¢ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć‚’č”Ø恙 SelectOptions 悒ä½æē”Ø恙悋恓ćØ恧态SELECTꖇ恌čؘčæ°ć•ć‚ŒćŸSQLćƒ•ć‚”ć‚¤ćƒ«ć‚’ćƒ™ćƒ¼ć‚¹ć«ć—ć€ ćƒšćƒ¼ć‚øćƒ³ć‚°å‡¦ē†ć‚„ę‚²č¦³ēš„ęŽ’ä»–åˆ¶å¾”ē”Ø恮SQL悒č‡Ŗå‹•ć§ē”Ÿęˆć§ćć¾ć™ć€‚

SelectOptions ćÆ态 1ä»¶ę¤œē“¢ 态 č¤‡ę•°ä»¶ę¤œē“¢ 态 ć‚¹ćƒˆćƒŖćƒ¼ćƒ ę¤œē“¢ ćØēµ„ćæåˆć‚ć›ć¦ä½æē”Øć—ć¾ć™ć€‚

SelectOptions ćÆ态Daoć®ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćØć—ć¦å®šē¾©ć—ć¾ć™ć€‚

@Config(config = AppConfig.class)
public interface EmployeeDao {
    @Select
    List<Employee> selectByDepartmentName(String departmentName, SelectOptions options);
    ...
}

SelectOptions ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ćÆ态staticćŖ get ćƒ”ć‚½ćƒƒćƒ‰ć«ć‚ˆć‚Šå–å¾—ć§ćć¾ć™ć€‚

SelectOptions options = SelectOptions.get();
ćƒšćƒ¼ć‚øćƒ³ć‚°Ā¶

SelectOptions 恮 offset ćƒ”ć‚½ćƒƒćƒ‰ć§é–‹å§‹ä½ē½®ć€ limit ćƒ”ć‚½ćƒƒćƒ‰ć§å–å¾—ä»¶ę•°ć‚’ęŒ‡å®šć—ć€ SelectOptions ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’Daoć®ćƒ”ć‚½ćƒƒćƒ‰ć«ęø”ć—ć¾ć™ć€‚

SelectOptions options = SelectOptions.get().offset(5).limit(10);
EmployeeDao dao = new EmployeeDaoImpl();
List<Employee> list = dao.selectByDepartmentName("ACCOUNT", options);

ćƒšćƒ¼ć‚øćƒ³ć‚°ćÆć€ćƒ•ć‚”ć‚¤ćƒ«ć«čؘčæ°ć•ć‚Œć¦ć„ć‚‹ć‚ŖćƒŖć‚øćƒŠćƒ«ć®SQL悒ę›øćę›ćˆå®Ÿč”Œć™ć‚‹ć“ćØć§å®Ÿē¾ć•ć‚Œć¦ć„ć¾ć™ć€‚ ć‚ŖćƒŖć‚øćƒŠćƒ«ć®SQLćÆę¬”ć®ę”ä»¶ć‚’ęŗ€ćŸć—恦恄ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

  • SELECTꖇ恧恂悋
  • ꜀äøŠä½ć®ćƒ¬ćƒ™ćƒ«ć§UNION态EXCEPT态INTERSECTē­‰ć®é›†åˆę¼”ē®—ć‚’č”Œć£ć¦ć„ćŖ恄ļ¼ˆć‚µćƒ–ć‚Æć‚ØćƒŖć§åˆ©ē”Øć—ć¦ć„ć‚‹å “åˆćÆåÆļ¼‰
  • ćƒšćƒ¼ć‚øćƒ³ć‚°å‡¦ē†ć‚’å«ć‚“ć§ć„ćŖ恄

ć•ć‚‰ć«ć€ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć®ę–¹čØ€ć«ć‚ˆć£ć¦ćÆē‰¹å®šć®ę”件悒ęŗ€ćŸć—恦恄ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

Dialect ę”ä»¶
Db2Dialect offsetć‚’ęŒ‡å®šć™ć‚‹å “åˆć€ORDER BYå„ć‚’ęŒć”ORDER BYå„ć§ęŒ‡å®šć™ć‚‹ ć‚«ćƒ©ćƒ ć™ć¹ć¦ć‚’SELECTå„ć«å«ć‚“ć§ć„ć‚‹
Mssql2008Dialect offsetć‚’ęŒ‡å®šć™ć‚‹å “åˆć€ORDER BYå„ć‚’ęŒć”ORDER BYå„ć§ęŒ‡å®šć™ć‚‹ ć‚«ćƒ©ćƒ ć™ć¹ć¦ć‚’SELECTå„ć«å«ć‚“ć§ć„ć‚‹
MssqlDialect offsetć‚’ęŒ‡å®šć™ć‚‹å “åˆć€ORDER BYå„ć‚’ęŒć¤åæ…č¦ćŒć‚ć‚Šć¾ć™
StandardDialect ORDER BYå„ć‚’ęŒć”ORDER BYå„ć§ęŒ‡å®šć™ć‚‹ ć‚«ćƒ©ćƒ ć™ć¹ć¦ć‚’SELECTå„ć«å«ć‚“ć§ć„ć‚‹
ę‚²č¦³ēš„ęŽ’ä»–åˆ¶å¾”Ā¶

SelectOptions 恮 forUpdate ćƒ”ć‚½ćƒƒćƒ‰ć§ę‚²č¦³ēš„ęŽ’ä»–åˆ¶å¾”ć‚’č”Œć†ć“ćØ悒ē¤ŗ恗态 SelectOptionsć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’Daoć®ćƒ”ć‚½ćƒƒćƒ‰ć«ęø”ć—ć¾ć™ć€‚

SelectOptions options = SelectOptions.get().forUpdate();
EmployeeDao dao = new EmployeeDaoImpl();
List<Employee> list = dao.selectByDepartmentName("ACCOUNT", options);

SelectOptions 恫ćÆ态惭惃ć‚ÆåÆ¾č±”ć®ćƒ†ćƒ¼ćƒ–ćƒ«ć‚„ć‚«ćƒ©ćƒ ć®ć‚Ø悤ćƒŖć‚¢ć‚¹ć‚’ęŒ‡å®šć§ćć‚‹ forUpdate ćƒ”ć‚½ćƒƒćƒ‰ć‚„ć€ 惭惃ć‚Æć®å–å¾—ć‚’å¾…ę©Ÿć—ćŖ恄 forUpdateNowait ćŖć©ć€åå‰ćŒ forUpdate ć§å§‹ć¾ć‚‹ę‚²č¦³ēš„ęŽ’ä»–åˆ¶å¾”ē”Øć®ćƒ”ć‚½ćƒƒćƒ‰ćŒē”Øę„ć•ć‚Œć¦ć„ć¾ć™ć€‚

ę‚²č¦³ēš„ęŽ’ä»–åˆ¶å¾”ćÆć€ćƒ•ć‚”ć‚¤ćƒ«ć«čؘčæ°ć•ć‚Œć¦ć„ć‚‹ć‚ŖćƒŖć‚øćƒŠćƒ«ć®SQL悒ę›øćę›ćˆć¦å®Ÿč”Œć—ć¦ć„ć¾ć™ć€‚ ć‚ŖćƒŖć‚øćƒŠćƒ«ć®SQLćÆę¬”ć®ę”ä»¶ć‚’ęŗ€ćŸć—恦恄ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

  • SELECTꖇ恧恂悋
  • ꜀äøŠä½ć®ćƒ¬ćƒ™ćƒ«ć§UNION态EXCEPT态INTERSECTē­‰ć®é›†åˆę¼”ē®—ć‚’č”Œć£ć¦ć„ćŖ恄ļ¼ˆć‚µćƒ–ć‚Æć‚ØćƒŖć§åˆ©ē”Øć—ć¦ć„ć‚‹å “åˆćÆåÆļ¼‰
  • ę‚²č¦³ēš„ęŽ’ä»–åˆ¶å¾”ć®å‡¦ē†ć‚’å«ć‚“ć§ć„ćŖ恄

ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć®ę–¹čØ€ć«ć‚ˆć£ć¦ćÆć€ę‚²č¦³ēš„ęŽ’ä»–åˆ¶å¾”ē”Øć®ćƒ”ć‚½ćƒƒćƒ‰ć®ć™ć¹ć¦ć‚‚ć—ććÆäø€éƒØ恌ä½æē”Øć§ćć¾ć›ć‚“ć€‚

Dialect čŖ¬ę˜Ž
Db2Dialect forUpdate()悒ä½æē”Ø恧恍悋
H2Dialect forUpdate()悒ä½æē”Ø恧恍悋
HsqldbDialect forUpdate()悒ä½æē”Ø恧恍悋
Mssql2008Dialect forUpdate()ćØforUpdateNoWait()悒ä½æē”Ø恧恍悋怂 恟恠恗态ć‚ŖćƒŖć‚øćƒŠćƒ«ć®SQL恮FROM叄ćÆ1ć¤ć®ćƒ†ćƒ¼ćƒ–ćƒ«ć ć‘ć‹ć‚‰ęˆć‚‰ć­ć°ćŖ悉ćŖ恄怂
MysqlDialect forUpdate()悒ä½æē”Ø恧恍悋
OracleDialect forUpdate()态forUpdate(String... aliases)态 forUpdateNowait()态forUpdateNowait(String... aliases)态 forUpdateWait(int waitSeconds)态 forUpdateWait(int waitSeconds, String... aliases)悒ä½æē”Ø恧恍悋
PostgresDialect forUpdate()ćØforUpdate(String... aliases)悒ä½æē”Ø恧恍悋
StandardDialect ę‚²č¦³ēš„ęŽ’ä»–åˆ¶å¾”ē”Øć®ćƒ”ć‚½ćƒƒćƒ‰ć™ć¹ć¦ć‚’ä½æē”Ø恧恍ćŖ恄
集č؈Ā¶

SelectOptions 恮 count ćƒ”ć‚½ćƒƒćƒ‰ć‚’å‘¼ć³å‡ŗ恙恓ćØ恧集čØˆä»¶ę•°ć‚’å–å¾—ć§ćć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć™ć€‚ 通åøøć€ćƒšćƒ¼ć‚øćƒ³ć‚°ć®ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ćØēµ„ćæåˆć‚ć›ć¦ä½æē”Øć—ć€ćƒšćƒ¼ć‚øćƒ³ć‚°ć§ēµžć‚Šč¾¼ć¾ćŖć„å “åˆć®å…Øä»¶ę•°ć‚’å–å¾—ć™ć‚‹å “åˆć«ä½æć„ć¾ć™ć€‚

SelectOptions options = SelectOptions.get().offset(5).limit(10).count();
EmployeeDao dao = new EmployeeDaoImpl();
List<Employee> list = dao.selectByDepartmentName("ACCOUNT", options);
long count = options.getCount();

集čØˆä»¶ę•°ćÆ态Daoć®ćƒ”ć‚½ćƒƒćƒ‰å‘¼å‡ŗć—å¾Œć« SelectOptions 恮 getCount ćƒ”ć‚½ćƒƒćƒ‰ć‚’ä½æć£ć¦å–å¾—ć—ć¾ć™ć€‚ ćƒ”ć‚½ćƒƒćƒ‰å‘¼ć³å‡ŗć—ć®å‰ć« count ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”Œć—ć¦ć„ćŖć„å “åˆć€ getCount ćƒ”ć‚½ćƒƒćƒ‰ćÆ -1 悒čæ”ć—ć¾ć™ć€‚

ꤜē“¢ēµęžœć®äæčؼĀ¶

ꤜē“¢ēµęžœćŒ1件仄äøŠå­˜åœØ恙悋恓ćØ悒äæčØ¼ć—ćŸć„å “åˆćÆ态 @Select 恮 ensureResult 要ē“ ć« true ć‚’ęŒ‡å®šć—ć¾ć™ć€‚

@Select(ensureResult = true)
Employee selectById(Integer id);

ꤜē“¢ēµęžœćŒ0件ćŖ悉恰 NoResultException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

ꤜē“¢ēµęžœć®ćƒžćƒƒćƒ”ćƒ³ć‚°ć®äæčؼĀ¶

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć™ć¹ć¦ć«åÆ¾ć—ć¦ę¼ć‚ŒćŖ恏ēµęžœć‚»ćƒƒćƒˆć®ć‚«ćƒ©ćƒ ć‚’ćƒžćƒƒćƒ”ćƒ³ć‚°ć™ć‚‹ć“ćØ悒äæčØ¼ć—ćŸć„å “åˆćÆ态 @Select 恮 ensureResultMapping 要ē“ ć« true ć‚’ęŒ‡å®šć—ć¾ć™ć€‚

@Select(ensureResultMapping = true)
Employee selectById(Integer id);

ēµęžœć‚»ćƒƒćƒˆć®ć‚«ćƒ©ćƒ ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć•ć‚ŒćŖć„ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒå­˜åœØć™ć‚‹å “åˆ ResultMappingException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

ć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆĀ¶

@Select 恮 queryTimeout 要ē“ ć«ć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆć®ē§’ę•°ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Select(queryTimeout = 10)
List<Employee> selectAll();

å€¤ć‚’ęŒ‡å®šć—ćŖć„å “åˆć€ čح定 ć«ęŒ‡å®šć•ć‚ŒćŸć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆćŒä½æē”Øć•ć‚Œć¾ć™ć€‚

ćƒ•ć‚§ćƒƒćƒć‚µć‚¤ć‚ŗĀ¶

@Select 恮 fetchSize 要ē“ ć«ćƒ•ć‚§ćƒƒćƒć‚µć‚¤ć‚ŗć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Select(fetchSize = 20)
List<Employee> selectAll();

å€¤ć‚’ęŒ‡å®šć—ćŖć„å “åˆć€ čح定 ć«ęŒ‡å®šć•ć‚ŒćŸćƒ•ć‚§ćƒƒćƒć‚µć‚¤ć‚ŗ恌ä½æē”Øć•ć‚Œć¾ć™ć€‚

ęœ€å¤§č”Œę•°Ā¶

@Select 恮 maxRows 要ē“ ć«ęœ€å¤§č”Œę•°ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Select(maxRows = 100)
List<Employee> selectAll();

å€¤ć‚’ęŒ‡å®šć—ćŖć„å “åˆć€ čح定 ć«ęŒ‡å®šć•ć‚ŒćŸęœ€å¤§č”Œę•°ćŒä½æē”Øć•ć‚Œć¾ć™ć€‚

ćƒžćƒƒćƒ—ć®ć‚­ćƒ¼ć®ćƒćƒ¼ćƒŸćƒ³ć‚°č¦ē“„Ā¶

ꤜē“¢ēµęžœć‚’ java.util.Map<String, Object> ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć™ć‚‹å “åˆć€ @Select 恮 mapKeyNaming 要ē“ ć«ćƒžćƒƒćƒ—ć®ć‚­ćƒ¼ć®ćƒćƒ¼ćƒŸćƒ³ć‚°č¦ē“„ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Select(mapKeyNaming = MapKeyNamingType.CAMEL_CASE)
List<Map<String, Object>> selectAll();

MapKeyNamingType.CAMEL_CASE ćÆć€ć‚«ćƒ©ćƒ åć‚’ć‚­ćƒ£ćƒ”ćƒ«ć‚±ćƒ¼ć‚¹ć«å¤‰ę›ć™ć‚‹ć“ćØ悒ē¤ŗć—ć¾ć™ć€‚ ćć®ć»ć‹ć«ć‚«ćƒ©ćƒ åć‚’å¤§ę–‡å­—ć‚„å°ę–‡å­—ć«å¤‰ę›ć™ć‚‹č¦ē“„ćŒć‚ć‚Šć¾ć™ć€‚

꜀ēµ‚ēš„ćŖå¤‰ę›ēµęžœćÆć€ć“ć“ć«ęŒ‡å®šć—ćŸå€¤ćØ čح定 ć«ęŒ‡å®šć•ć‚ŒćŸ MapKeyNaming ć®å®Ÿč£…ć«ć‚ˆć‚Šę±ŗć¾ć‚Šć¾ć™ć€‚

SQL ć®ćƒ­ć‚°å‡ŗ力形式Ā¶

@Select 恮 sqlLog 要ē“ ć« SQL ć®ćƒ­ć‚°å‡ŗåŠ›å½¢å¼ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Select(sqlLog = SqlLogType.RAW)
List<Employee> selectById(Integer id);

SqlLogType.RAW ćÆćƒć‚¤ćƒ³ćƒ‰ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æļ¼ˆ?ļ¼‰ä»˜ćć® SQL 悒惭悰å‡ŗåŠ›ć™ć‚‹ć“ćØ悒č”Øć—ć¾ć™ć€‚

ęŒæå…„Ā¶

ęŒæå…„ć‚’č”Œć†ć«ćÆ态 @Insert 悒Daoć®ćƒ”ć‚½ćƒƒćƒ‰ć«ę³Øé‡ˆć—ć¾ć™ć€‚

@Config(config = AppConfig.class)
public interface EmployeeDao {
    @Insert
    int insert(Employee employee);

    @Insert
    Result<ImmutableEmployee> insert(ImmutableEmployee employee);
}

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆ态INSERTꖇ恌č‡Ŗ動ē”Ÿęˆć•ć‚Œć¾ć™ć€‚ @Insert 恮 sqlFile 要ē“ ć« true 悒čØ­å®šć™ć‚‹ć“ćØć§ć€ä»»ę„ć®SQLćƒ•ć‚”ć‚¤ćƒ«ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć§ćć¾ć™ć€‚

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮 ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ 恫ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ćŒęŒ‡å®šć•ć‚Œć¦ć„ć‚‹å “åˆć€ ęŒæå…„ć®å®Ÿč”Œå‰ć«ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ć® preInsert ćƒ”ć‚½ćƒƒćƒ‰ćŒå‘¼ć³å‡ŗć•ć‚Œć¾ć™ć€‚ ć¾ćŸć€ęŒæå…„ć®å®Ÿč”Œå¾Œć«ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ć® postInsert ćƒ”ć‚½ćƒƒćƒ‰ćŒå‘¼ć³å‡ŗć•ć‚Œć¾ć™ć€‚

ęˆ»ć‚Šå€¤Ā¶

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćŒć‚¤ćƒŸćƒ„ćƒ¼ć‚æćƒ–ćƒ«ćŖć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć®å “åˆć€ ęˆ»ć‚Šå€¤ćÆćć®ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć‚’č¦ē“ ćØ恙悋 org.seasar.doma.jdbc.Result 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

äøŠčØ˜ć®ę”ä»¶ć‚’ęŗ€ćŸć•ćŖ恄ćŖć„å “åˆć€ęˆ»ć‚Šå€¤ćÆꛓꖰ件ꕰ悒č”Ø恙 int 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

SQL恮č‡Ŗ動ē”Ÿęˆć«ć‚ˆć‚‹ęŒæå…„Ā¶

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ęŒ‡å®šć§ćć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ꕰćÆ1恤恧恙怂 å¼•ę•°ćÆnullć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚

@Insert
int insert(Employee employee);

@Insert
Result<ImmutableEmployee> insert(ImmutableEmployee employee);
č­˜åˆ„å­Ā¶

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ ć®č­˜åˆ„å­ć«ć€ @GeneratedValue 恌ę³Øé‡ˆć•ć‚Œć¦ć„ć‚‹å “åˆć€ č­˜åˆ„å­ćŒč‡Ŗ動ēš„恫ē”Ÿęˆć•ć‚ŒčØ­å®šć•ć‚Œć¾ć™ć€‚

ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号Ā¶

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ 恫 @Version 恌ę³Øé‡ˆć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć‚ć‚‹å “åˆć€ ćć®ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć«ę˜Žē¤ŗēš„恫 0 仄äøŠć®å€¤ćŒčØ­å®šć•ć‚Œć¦ć„ć‚Œć°ćć®å€¤ć‚’ä½æē”Øć—ć¾ć™ć€‚ 悂恗čØ­å®šć•ć‚Œć¦ć„ćŖ恄恋态 0 ęœŖęŗ€ć®å€¤ćŒčØ­å®šć•ć‚Œć¦ć„ć‚Œć° 1 悒č‡Ŗå‹•ć§čØ­å®šć—ć¾ć™ć€‚

ęŒæå…„åÆ¾č±”ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®åˆ¶å¾”Ā¶
insertableĀ¶

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć« @Column 恌ę³Øé‡ˆć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć‚ć‚‹å “åˆć€ @Column 恮 insertable 要ē“ ćŒ false 恮悂恮ćÆęŒæå…„åÆ¾č±”å¤–ć§ć™ć€‚

excludeĀ¶

@Insert 恮 exclude 要ē“ ć«ęŒ‡å®šć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć‚’ęŒæå…„åÆ¾č±”å¤–ćØć—ć¾ć™ć€‚ ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć“ć®č¦ē“ ć«ęŒ‡å®šć•ć‚Œć¦ć„ć‚Œć°ć€ @Column 恮 insertable 要ē“ ćŒ true ć§ć‚ć£ć¦ć‚‚ęŒæå…„åÆ¾č±”å¤–ć§ć™ć€‚

@Insert(exclude = {"name", "salary"})
int insert(Employee employee);
includeĀ¶

@Insert 恮 include 要ē“ ć«ęŒ‡å®šć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®ćæ悒ęŒæå…„åÆ¾č±”ćØć—ć¾ć™ć€‚ @Insert 恮 include 要ē“ ćØ exclude 要ē“ ć®äø”ę–¹ć«åŒć˜ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒęŒ‡å®šć•ć‚ŒćŸå “åˆć€ ćć®ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćÆęŒæå…„åÆ¾č±”å¤–ć«ćŖć‚Šć¾ć™ć€‚

ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć“ć®č¦ē“ ć«ęŒ‡å®šć•ć‚Œć¦ć„恦悂态 @Column 恮 insertable 要ē“ ćŒ false 恧恂悌恰ęŒæå…„åÆ¾č±”å¤–ć§ć™ć€‚

@Insert(include = {"name", "salary"})
int insert(Employee employee);
excludeNullĀ¶

@Insert 恮 excludeNull 要ē“ ćŒ true ć®å “åˆć€ å€¤ćŒ null ć®ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć‚’ęŒæå…„åÆ¾č±”å¤–ćØć—ć¾ć™ć€‚ 恓恮要ē“ ćŒ true ć®å “åˆć€ @Column 恮 insertable 要ē“ ćŒ true ć§ć‚ć£ćŸć‚Šć€ @Insert 恮 include 要ē“ ć«ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒęŒ‡å®šć•ć‚Œć¦ć„ć¦ć‚‚ć€å€¤ćŒ null 恧恂悌恰ęŒæå…„åÆ¾č±”å¤–ć§ć™ć€‚

@Insert(excludeNull = true)
int insert(Employee employee);

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ć‚ˆć‚‹ęŒæå…„Ā¶

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ć‚ˆć‚‹ęŒæå…„ć‚’č”Œć†ć«ćÆ态 @Insert 恮 sqlFile 要ē“ ć« true 悒čØ­å®šć—ć€ ćƒ”ć‚½ćƒƒćƒ‰ć«åƾåæœć™ć‚‹SQLćƒ•ć‚”ć‚¤ćƒ«ć‚’ē”Øę„ć—ć¾ć™ć€‚

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫ćÆä»»ę„ć®åž‹ćŒä½æē”Øć§ćć¾ć™ć€‚ ęŒ‡å®šć§ćć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®ę•°ć«åˆ¶é™ćÆć‚ć‚Šć¾ć›ć‚“ć€‚ ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćŒåŸŗęœ¬åž‹ć‚‚ć—ććÆćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć®å “åˆć€å¼•ę•°ć‚’ null ć«ć§ćć¾ć™ć€‚ ćć‚Œä»„å¤–ć®åž‹ć®å “åˆć€å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚

@Insert(sqlFile = true)
int insert(Employee employee);

@Insert(sqlFile = true)
Result<ImmutableEmployee> insert(ImmutableEmployee employee);

恟ćØ恈恰态äøŠčØ˜ć®ćƒ”ć‚½ćƒƒćƒ‰ć«åƾåæœć™ć‚‹SQLćÆę¬”ć®ć‚ˆć†ć«čؘčæ°ć—ć¾ć™ć€‚

insert into employee (id, name, salary, version)
values (/* employee.id */0,
        /* employee.name */'hoge',
        /* employee.salary */100,
        /* employee.version */0)

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ć‚ˆć‚‹ęŒæå…„ć§ćÆć€č­˜åˆ„å­ć®č‡Ŗ動čØ­å®šć‚„ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗå·ć®č‡Ŗ動čح定ćÆč”Œć‚ć‚Œć¾ć›ć‚“ć€‚ ć¾ćŸć€ @Insert 恮 exclude 要ē“ ć€ include 要ē“ ć€ excludeNull 要ē“ ćÆ参ē…§ć•ć‚Œć¾ć›ć‚“怂

äø€ę„åˆ¶ē“„違反Ā¶

äø€ę„åˆ¶ē“„é•åćŒē™ŗē”Ÿć—ćŸå “合ćÆ态SQLćƒ•ć‚”ć‚¤ćƒ«ć®ä½æē”Øć®ęœ‰ē„”ć«é–¢äæ‚ćŖ恏 UniqueConstraintException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

ć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆĀ¶

@Insert 恮 queryTimeout 要ē“ ć«ć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆć®ē§’ę•°ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Insert(queryTimeout = 10)
int insert(Employee employee);

ć“ć®ęŒ‡å®šćÆ态SQLćƒ•ć‚”ć‚¤ćƒ«ć®ä½æē”Øć®ęœ‰ē„”ć«é–¢äæ‚ćŖćé©ē”Øć•ć‚Œć¾ć™ć€‚ queryTimeout 要ē“ ć«å€¤ć‚’ęŒ‡å®šć—ćŖć„å “åˆć€ čح定 ć«ęŒ‡å®šć•ć‚ŒćŸć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆćŒä½æē”Øć•ć‚Œć¾ć™ć€‚

SQL ć®ćƒ­ć‚°å‡ŗ力形式Ā¶

@Insert 恮 sqlLog 要ē“ ć« SQL ć®ćƒ­ć‚°å‡ŗåŠ›å½¢å¼ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Insert(sqlLog = SqlLogType.RAW)
int insert(Employee employee);

SqlLogType.RAW ćÆćƒć‚¤ćƒ³ćƒ‰ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æļ¼ˆ?ļ¼‰ä»˜ćć® SQL 悒惭悰å‡ŗåŠ›ć™ć‚‹ć“ćØ悒č”Øć—ć¾ć™ć€‚

ꛓꖰĀ¶

ę›“ę–°ć‚’č”Œć†ć«ćÆ态 @Update 悒Daoć®ćƒ”ć‚½ćƒƒćƒ‰ć«ę³Øé‡ˆć—ć¾ć™ć€‚

@Config(config = AppConfig.class)
public interface EmployeeDao {
    @Update
    int update(Employee employee);

    @Update
    Result<ImmutableEmployee> update(ImmutableEmployee employee);
}

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆ态UPDATEꖇ恌č‡Ŗ動ē”Ÿęˆć•ć‚Œć¾ć™ć€‚ @Update 恮 sqlFile 恫true悒čØ­å®šć™ć‚‹ć“ćØć§ć€ä»»ę„ć®SQLćƒ•ć‚”ć‚¤ćƒ«ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć§ćć¾ć™ć€‚

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć«ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ćŒęŒ‡å®šć•ć‚Œć¦ć„ć‚‹å “åˆć€ ę›“ę–°ć®å®Ÿč”Œå‰ć«ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ć® preUpdate ćƒ”ć‚½ćƒƒćƒ‰ć‚’å‘¼ć³å‡ŗć•ć‚Œć¾ć™ć€‚ ć¾ćŸć€ę›“ę–°ć®å®Ÿč”Œå¾Œć«ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ć® postUpdate ćƒ”ć‚½ćƒƒćƒ‰ć‚’å‘¼ć³å‡ŗć•ć‚Œć¾ć™ć€‚

ęˆ»ć‚Šå€¤Ā¶

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćŒć‚¤ćƒŸćƒ„ćƒ¼ć‚æćƒ–ćƒ«ćŖć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć®å “åˆć€ ęˆ»ć‚Šå€¤ćÆćć®ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć‚’č¦ē“ ćØ恙悋 org.seasar.doma.Result 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

äøŠčØ˜ć®ę”ä»¶ć‚’ęŗ€ćŸć•ćŖ恄ćŖć„å “åˆć€ęˆ»ć‚Šå€¤ćÆꛓꖰ件ꕰ悒č”Ø恙 int 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

SQL恮č‡Ŗ動ē”Ÿęˆć«ć‚ˆć‚‹ę›“ꖰĀ¶

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ęŒ‡å®šć§ćć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ꕰćÆ1恤恧恙怂 å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚

@Update
int update(Employee employee);

@Update
Result<ImmutableEmployee> update(ImmutableEmployee employee);
SQLč‡Ŗ動ē”Ÿęˆć«ćŠć‘ć‚‹ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćØę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”Ā¶

ę¬”ć®ę”ä»¶ć‚’ęŗ€ćŸć™å “åˆć«ć€ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ćŒč”Œć‚ć‚Œć¾ć™ć€‚

  • ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć«@Version恌ę³Øé‡ˆć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć‚ć‚‹
  • @Update恮ignoreVersion要ē“ ćŒfalse恧恂悋

ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ćŒęœ‰åŠ¹ć§ć‚ć‚Œć°ć€ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćÆč­˜åˆ„å­ćØćØć‚‚ć«ę›“ę–°ę”ä»¶ć«å«ć¾ć‚Œć€ 1å¢—åˆ†ć—ć¦ę›“ę–°ć•ć‚Œć¾ć™ć€‚ 恓恮ćØćć®ę›“ę–°ä»¶ę•°ćŒ0ä»¶ć®å “åˆć€ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ć®å¤±ę•—ć‚’ē¤ŗ恙 OptimisticLockException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚ ć¾ćŸć€ę›“ę–°ä»¶ę•°ćŒ0件恧ćŖć„å “åˆć€ OptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œćšć€ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®ćƒćƒ¼ć‚øćƒ§ćƒ³ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®å€¤ćŒ1å¢—åˆ†ć•ć‚Œć¾ć™ć€‚

ignoreVersionĀ¶

@Update 恮 ignoreVersion 要ē“ ćŒtrueć®å “åˆć€ ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćÆę›“ę–°ę”ä»¶ć«ćÆå«ć¾ć‚Œćšć€UPDATEꖇ恮SETå„ć«å«ć¾ć‚Œć¾ć™ć€‚ ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćÆć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć§čØ­å®šć—ćŸå€¤ć§ę›“ę–°ć•ć‚Œć¾ć™ć€‚ ć“ć®å “åˆć€ę›“ę–°ä»¶ę•°ćŒ0ä»¶ć§ć‚ć£ć¦ć‚‚ć€ OptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć›ć‚“ć€‚

@Update(ignoreVersion = true)
int update(Employee employee);
suppressOptimisticLockExceptionĀ¶

@Update 恮 suppressOptimisticLockException 要ē“ ćŒ true ć®å “åˆć€ @Version 恌ę³Øé‡ˆć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć‚ć‚Œć°ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćÆę›“ę–°ę”ä»¶ć«å«ć¾ć‚Œå¢—åˆ†ć‚‚ć•ć‚Œć¾ć™ćŒć€ ę›“ę–°ä»¶ę•°ćŒ0ä»¶ć§ć‚ć£ć¦ć‚‚ OptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć›ć‚“ć€‚ 恟恠恗态ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®ćƒćƒ¼ć‚øćƒ§ćƒ³ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®å€¤ćÆ1å¢—åˆ†ć•ć‚Œć¾ć™ć€‚

@Update(suppressOptimisticLockException = true)
int update(Employee employee);
ꛓꖰåÆ¾č±”ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®åˆ¶å¾”Ā¶
updatableĀ¶

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć« @Column 恌ę³Øé‡ˆć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć‚ć‚‹å “åˆć€ @Column 恮 updatable 要ē“ ćŒfalse恮悂恮ćÆꛓꖰåÆ¾č±”å¤–ć§ć™ć€‚

excludeĀ¶

@Update 恮 exclude 要ē“ ć«ęŒ‡å®šć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć‚’ę›“ꖰåÆ¾č±”å¤–ćØć—ć¾ć™ć€‚ ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć“ć®č¦ē“ ć«ęŒ‡å®šć•ć‚Œć¦ć„ć‚Œć°ć€ @Column 恮 updatable 要ē“ ćŒ true ć§ć‚ć£ć¦ć‚‚ę›“ę–°åÆ¾č±”å¤–ć§ć™ć€‚

@Update(exclude = {"name", "salary"})
int update(Employee employee);
includeĀ¶

@Update 恮 include 要ē“ ć«ęŒ‡å®šć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®ćæ悒ꛓꖰåÆ¾č±”ćØć—ć¾ć™ć€‚ @Update 恮 include 要ē“ ćØ exclude 要ē“ ć®äø”ę–¹ć« åŒć˜ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒęŒ‡å®šć•ć‚ŒćŸå “åˆć€ćć®ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćÆꛓꖰåÆ¾č±”å¤–ć«ćŖć‚Šć¾ć™ć€‚ ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć“ć®č¦ē“ ć«ęŒ‡å®šć•ć‚Œć¦ć„恦悂态 @Column 恮 updatable 要ē“ ćŒ false ć§ć‚ć‚Œć°ę›“ę–°åÆ¾č±”å¤–ć§ć™ć€‚

@Update(include = {"name", "salary"})
int update(Employee employee);
excludeNullĀ¶

@Update 恮 excludeNull 要ē“ ćŒ true ć®å “åˆć€ å€¤ćŒ null ć®ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć‚’å‰Šé™¤åÆ¾č±”å¤–ćØć—ć¾ć™ć€‚ 恓恮要ē“ ćŒ true ć®å “åˆć€ @Column 恮 updatable 要ē“ ćŒ true ć§ć‚ć£ćŸć‚Šć€ @Update 恮 include 要ē“ ć«ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒęŒ‡å®šć•ć‚Œć¦ć„ć¦ć‚‚ć€ å€¤ćŒ null ć§ć‚ć‚Œć°ę›“ę–°åÆ¾č±”å¤–ć§ć™ć€‚

@Update(excludeNull = true)
int update(Employee employee);
includeUnchangedĀ¶

恓恮要ē“ ćÆ态ꛓꖰåÆ¾č±”ć®ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć« @OriginalStates 恌ę³Øé‡ˆć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć‚ć‚‹å “åˆć«ć®ćæęœ‰åŠ¹ć§ć™ć€‚

恓恮要ē“ ćŒtrueć®å “åˆć€ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®å…Øćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒę›“ę–°åÆ¾č±”ćØćŖć‚Šć¾ć™ć€‚ ć¤ć¾ć‚Šć€å…Øćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć«åƾåæœć™ć‚‹ć‚«ćƒ©ćƒ ćŒUPDATEꖇ恮SETå„ć«å«ć¾ć‚Œć¾ć™ć€‚

恓恮要ē“ ćŒ false ć®å “åˆć€ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćŒå–å¾—ć•ć‚Œć¦ć‹ć‚‰å®Ÿéš›ć«å¤‰ę›“ć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®ćæćŒę›“ę–°åÆ¾č±”ć«ćŖć‚Šć¾ć™ć€‚ ć¤ć¾ć‚Šć€å¤‰ę›“ć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć«åƾåæœć™ć‚‹ć‚«ćƒ©ćƒ ć®ćæ恌UPDATEꖇ恮SETå„ć«å«ć¾ć‚Œć¾ć™ć€‚

@Update(includeUnchanged = true)
int update(Employee employee);

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ć‚ˆć‚‹ę›“ę–°Ā¶

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ć‚ˆć‚‹ę›“ę–°ć‚’č”Œć†ć«ćÆ态 @Update 恮 sqlFile 要ē“ ć« true 悒čØ­å®šć—ć€ ćƒ”ć‚½ćƒƒćƒ‰ć«åƾåæœć™ć‚‹SQLćƒ•ć‚”ć‚¤ćƒ«ć‚’ē”Øę„ć—ć¾ć™ć€‚

ćƒŽćƒ¼ćƒˆ

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ć‚ˆć‚‹ę›“ę–°ćÆ态 ę›“ę–°ć‚«ćƒ©ćƒ ćƒŖć‚¹ćƒˆē”Ÿęˆć‚³ćƒ”ćƒ³ćƒˆ ć®åˆ©ē”Ø꜉ē„”ć«ć‚ˆć‚Šćƒ«ćƒ¼ćƒ«ćŒē•°ćŖć‚Šć¾ć™ć€‚

ę›“ę–°ć‚«ćƒ©ćƒ ćƒŖć‚¹ćƒˆē”Ÿęˆć‚³ćƒ”ćƒ³ćƒˆć‚’ä½æē”Øć™ć‚‹å “åˆĀ¶

ęœ€åˆć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ęŒ‡å®šć§ćć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®ę•°ć«åˆ¶é™ćÆć‚ć‚Šć¾ć›ć‚“ć€‚ ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćŒåŸŗęœ¬åž‹ć‚‚ć—ććÆćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć®å “åˆć€å¼•ę•°ć‚’ null ć«ć§ćć¾ć™ć€‚ ćć‚Œä»„å¤–ć®åž‹ć®å “åˆć€å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚

@Update(sqlFile = true)
int update(Employee employee, BigDecimal salary);

@Update(sqlFile = true)
Result<ImmutableEmployee> update(ImmutableEmployee employee, , BigDecimal salary);

恟ćØ恈恰态äøŠčØ˜ć®ćƒ”ć‚½ćƒƒćƒ‰ć«åƾåæœć™ć‚‹SQLćÆę¬”ć®ć‚ˆć†ć«čؘčæ°ć—ć¾ć™ć€‚

update employee set /*%populate*/ id = id where salary > /* salary */0

ꛓꖰåÆ¾č±”ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®åˆ¶å¾”ć«é–¢ć™ć‚‹ćƒ«ćƒ¼ćƒ«ćÆ态 SQL恮č‡Ŗ動ē”Ÿęˆć«ć‚ˆć‚‹ę›“ꖰ ćØåŒć˜ć§ć™ć€‚

ę›“ę–°ć‚«ćƒ©ćƒ ćƒŖć‚¹ćƒˆē”Ÿęˆć‚³ćƒ”ćƒ³ćƒˆć‚’ä½æē”Ø恗ćŖć„å “åˆĀ¶

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫ćÆä»»ę„ć®åž‹ćŒä½æē”Øć§ćć¾ć™ć€‚ ęŒ‡å®šć§ćć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®ę•°ć«åˆ¶é™ćÆć‚ć‚Šć¾ć›ć‚“ć€‚ ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćŒåŸŗęœ¬åž‹ć‚‚ć—ććÆćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć®å “åˆć€å¼•ę•°ć‚’ null ć«ć§ćć¾ć™ć€‚ ćć‚Œä»„å¤–ć®åž‹ć®å “åˆć€å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚

@Update(sqlFile = true)
int update(Employee employee);

@Update(sqlFile = true)
Result<ImmutableEmployee> update(ImmutableEmployee employee);

恟ćØ恈恰态äøŠčØ˜ć®ćƒ”ć‚½ćƒƒćƒ‰ć«åƾåæœć™ć‚‹SQLćÆę¬”ć®ć‚ˆć†ć«čؘčæ°ć—ć¾ć™ć€‚

update employee set name = /* employee.name */'hoge', salary = /* employee.salary */100
where id = /* employee.id */0

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ć‚ˆć‚‹ę›“ę–°ć§ćÆ态 @Update 恮 exclude 要ē“ ć€ include 要ē“ ć€ excludeNull 要ē“ ć€ includeUnchanged 要ē“ ćÆ参ē…§ć•ć‚Œć¾ć›ć‚“怂

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ćŠć‘ć‚‹ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćØę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”Ā¶

ę¬”ć®ę”ä»¶ć‚’ęŗ€ćŸć™å “åˆć«ć€ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ćŒč”Œć‚ć‚Œć¾ć™ć€‚

  • ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć‚’å«ć‚€
  • ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®å†…ć€å·¦ć‹ć‚‰ę•°ćˆć¦ęœ€åˆć«ē™»å “恙悋ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć«@Version恌ę³Øé‡ˆć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć‚ć‚‹
  • @Update恮ignoreVersion要ē“ ćŒfalse恧恂悋

恟恠恗态SQLćƒ•ć‚”ć‚¤ćƒ«ć«ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ē”Ø恮SQL悒čؘčæ°ć™ć‚‹ć®ćÆć€ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³é–‹ē™ŗč€…ć®č²¬ä»»ć§ć™ć€‚ 恟ćØ恈恰态äø‹čØ˜ć®SQLć®ć‚ˆć†ć«ć€ WHEREå„ć§ćƒćƒ¼ć‚øćƒ§ćƒ³ć‚’ē•Ŗå·ć‚’ęŒ‡å®šć—SETå„ć§ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗå·ć‚’1ć ć‘å¢—åˆ†ć—ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

update EMPLOYEE set DELETE_FLAG = 1, VERSION = /* employee.version */1 + 1
where ID = /* employee.id */1 and VERSION = /* employee.version */1

恓恮SQLć®ę›“ę–°ä»¶ę•°ćŒ0ä»¶ć®å “åˆć€ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ć®å¤±ę•—ć‚’ē¤ŗ恙 OptimisticLockException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚ ę›“ę–°ä»¶ę•°ćŒ0件恧ćŖć„å “åˆć€ OptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œćšć€ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®ćƒćƒ¼ć‚øćƒ§ćƒ³ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®å€¤ćŒ1å¢—åˆ†ć•ć‚Œć¾ć™ć€‚

ignoreVersionĀ¶

@Update 恮 ignoreVersion 要ē“ ćŒ true ć®å “åˆć€ ę›“ę–°ä»¶ę•°ćŒ0ä»¶ć§ć‚ć£ć¦ć‚‚ć€ OptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć›ć‚“ć€‚ ć¾ćŸć€ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®ćƒćƒ¼ć‚øćƒ§ćƒ³ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®å€¤ćÆå¤‰ę›“ć•ć‚Œć¾ć›ć‚“ć€‚

@Update(sqlFile = true, ignoreVersion = true)
int update(Employee employee);
suppressOptimisticLockExceptionĀ¶

@Update 恮 suppressOptimisticLockException 要ē“ ćŒ true ć®å “åˆć€ ę›“ę–°ä»¶ę•°ćŒ0ä»¶ć§ć‚ć£ć¦ć‚‚ć€ OptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć›ć‚“ć€‚ 恟恠恗态ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®ćƒćƒ¼ć‚øćƒ§ćƒ³ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®å€¤ćÆ1å¢—åˆ†ć•ć‚Œć¾ć™ć€‚

@Update(sqlFile = true, suppressOptimisticLockException = true)
int update(Employee employee);

äø€ę„åˆ¶ē“„違反Ā¶

äø€ę„åˆ¶ē“„é•åćŒē™ŗē”Ÿć—ćŸå “合ćÆ态SQLćƒ•ć‚”ć‚¤ćƒ«ć®ä½æē”Øć®ęœ‰ē„”ć«é–¢äæ‚ćŖ恏 UniqueConstraintException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

ć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆĀ¶

@Update 恮 queryTimeout 要ē“ ć«ć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆć®ē§’ę•°ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Update(queryTimeout = 10)
int update(Employee employee);

ć“ć®ęŒ‡å®šćÆSQLćƒ•ć‚”ć‚¤ćƒ«ć®ä½æē”Øć®ęœ‰ē„”ć«é–¢äæ‚ćŖćé©ē”Øć•ć‚Œć¾ć™ć€‚ queryTimeout 要ē“ ć«å€¤ć‚’ęŒ‡å®šć—ćŖć„å “åˆć€ čح定 ć«ęŒ‡å®šć•ć‚ŒćŸć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆćŒä½æē”Øć•ć‚Œć¾ć™ć€‚

SQL ć®ćƒ­ć‚°å‡ŗ力形式Ā¶

@Update 恮 sqlLog 要ē“ ć« SQL ć®ćƒ­ć‚°å‡ŗåŠ›å½¢å¼ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Update(sqlLog = SqlLogType.RAW)
int update(Employee employee);

SqlLogType.RAW ćÆćƒć‚¤ćƒ³ćƒ‰ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æļ¼ˆ?ļ¼‰ä»˜ćć® SQL 悒惭悰å‡ŗåŠ›ć™ć‚‹ć“ćØ悒č”Øć—ć¾ć™ć€‚

削除Ā¶

å‰Šé™¤ć‚’č”Œć†ć«ćÆ态 @Delete 悒Daoć®ćƒ”ć‚½ćƒƒćƒ‰ć«ę³Øé‡ˆć—ć¾ć™ć€‚

@Config(config = AppConfig.class)
public interface EmployeeDao {
    @Delete
    int delete(Employee employee);
}

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆ态DELETEꖇ恌č‡Ŗ動ē”Ÿęˆć•ć‚Œć¾ć™ć€‚ @Delete 恮 sqlFile 恫 true 悒čØ­å®šć™ć‚‹ć“ćØć§ć€ä»»ę„ć®SQLćƒ•ć‚”ć‚¤ćƒ«ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć§ćć¾ć™ć€‚

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć«ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ćŒęŒ‡å®šć•ć‚Œć¦ć„ć‚‹å “åˆć€ å‰Šé™¤ć®å®Ÿč”Œå‰ć«ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ć® preDelete ćƒ”ć‚½ćƒƒćƒ‰ćŒå‘¼ć³å‡ŗć•ć‚Œć¾ć™ć€‚ ć¾ćŸć€å‰Šé™¤ć®å®Ÿč”Œå¾Œć«ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ć® postDelete ćƒ”ć‚½ćƒƒćƒ‰ć‚’å‘¼ć³å‡ŗć•ć‚Œć¾ć™ć€‚

ęˆ»ć‚Šå€¤Ā¶

ęˆ»ć‚Šå€¤ćÆꛓꖰ件ꕰ悒č”Ø恙 int 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

SQL恮č‡Ŗ動ē”Ÿęˆć«ć‚ˆć‚‹å‰Šé™¤Ā¶

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ęŒ‡å®šć§ćć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ꕰćÆ1恤恧恙怂 å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚

@Delete
int delete(Employee employee);

@Delete
Result<ImmutableEmployee> delete(ImmutableEmployee employee);
SQLč‡Ŗ動ē”Ÿęˆć«ćŠć‘ć‚‹ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćØę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”Ā¶

ę¬”ć®ę”ä»¶ć‚’ęŗ€ćŸć™å “åˆć«ć€ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ćŒč”Œć‚ć‚Œć¾ć™ć€‚

  • ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć«@Version恌ę³Øé‡ˆć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć‚ć‚‹
  • @Delete恮ignoreVersion要ē“ ćŒfalse恧恂悋

ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ćŒęœ‰åŠ¹ć§ć‚ć‚Œć°ć€ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćÆč­˜åˆ„å­ćØćØć‚‚ć«å‰Šé™¤ę”ä»¶ć«å«ć¾ć‚Œć¾ć™ć€‚ ć“ć®å “åˆć€å‰Šé™¤ä»¶ę•°ćŒ0ä»¶ć§ć‚ć‚Œć°ć€ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ć®å¤±ę•—ć‚’ē¤ŗ恙 OptimisticLockException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

ignoreVersionĀ¶

@Delete 恮 ignoreVersion 要ē“ ćŒ true ć®å “åˆć€ ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćÆå‰Šé™¤ę”ä»¶ć«å«ć¾ć‚Œć¾ć›ć‚“ć€‚ ć“ć®å “åˆć€å‰Šé™¤ä»¶ę•°ćŒ0ä»¶ć§ć‚ć£ć¦ć‚‚ć€ OptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć›ć‚“ć€‚

@Delete(includeVersion = true)
int delete(Employee employee);
suppressOptimisticLockExceptionĀ¶

@Delete 恮 suppressOptimisticLockException 要ē“ ćŒ true ć®å “åˆć€ ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćÆå‰Šé™¤ę”ä»¶ć«å«ć¾ć‚Œć¾ć™ć€‚ ć—ć‹ć—ć€ć“ć®å “åˆć€å‰Šé™¤ä»¶ę•°ćŒ0ä»¶ć§ć‚ć£ć¦ć‚‚ć€ OptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć›ć‚“ć€‚

@Delete(suppressOptimisticLockException = true)
int delete(Employee employee);

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ć‚ˆć‚‹å‰Šé™¤Ā¶

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ć‚ˆć‚‹å‰Šé™¤ć‚’č”Œć†ć«ćÆ态 @Delete 恮 sqlFile 要ē“ ć« true 悒čØ­å®šć—ć€ ćƒ”ć‚½ćƒƒćƒ‰ć«åƾåæœć™ć‚‹SQLćƒ•ć‚”ć‚¤ćƒ«ć‚’ē”Øę„ć—ć¾ć™ć€‚

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫ćÆä»»ę„ć®åž‹ćŒä½æē”Øć§ćć¾ć™ć€‚ ęŒ‡å®šć§ćć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®ę•°ć«åˆ¶é™ćÆć‚ć‚Šć¾ć›ć‚“ć€‚ ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćŒåŸŗęœ¬åž‹ć‚‚ć—ććÆćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć®å “åˆć€å¼•ę•°ć‚’ null ć«ć§ćć¾ć™ć€‚ ćć‚Œä»„å¤–ć®åž‹ć®å “åˆć€å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć«ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ćŒęŒ‡å®šć•ć‚Œć¦ć„ć¦ć‚‚ć€ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ć®ćƒ”ć‚½ćƒƒćƒ‰ćÆå‘¼ć³å‡ŗć—ć¾ć›ć‚“ć€‚

@Delete(sqlFile = true)
int delete(Employee employee);

恟ćØ恈恰态äøŠčØ˜ć®ćƒ”ć‚½ćƒƒćƒ‰ć«åƾåæœć™ć‚‹SQLćÆę¬”ć®ć‚ˆć†ć«čؘčæ°ć—ć¾ć™ć€‚

delete from employee where name = /* employee.name */'hoge'
SQLćƒ•ć‚”ć‚¤ćƒ«ć«ćŠć‘ć‚‹ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćØę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”Ā¶

ę¬”ć®ę”ä»¶ć‚’ęŗ€ćŸć™å “åˆć«ć€ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ćŒč”Œć‚ć‚Œć¾ć™ć€‚

  • ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć‚’å«ć‚€
  • ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®å†…ć€å·¦ć‹ć‚‰ę•°ćˆć¦ęœ€åˆć«ē™»å “恙悋ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć«@Version恌ę³Øé‡ˆć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć‚ć‚‹
  • @Delete恮ignoreVersion要ē“ ćŒfalse恧恂悋
  • @Delete恮suppressOptimisticLockException要ē“ ćŒfalse恧恂悋

恟恠恗态SQLćƒ•ć‚”ć‚¤ćƒ«ć«ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ē”Ø恮SQL悒čؘčæ°ć™ć‚‹ć®ćÆć€ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³é–‹ē™ŗč€…ć®č²¬ä»»ć§ć™ć€‚ 恟ćØ恈恰态äø‹čØ˜ć®SQLć®ć‚ˆć†ć«ć€WHEREå„ć§ćƒćƒ¼ć‚øćƒ§ćƒ³ć‚’ē•Ŗå·ć‚’ęŒ‡å®šć—ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

delete from EMPLOYEE where ID = /* employee.id */1 and VERSION = /* employee.version */1

恓恮SQLć®å‰Šé™¤ä»¶ę•°ćŒ0ä»¶ć®å “åˆć€ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ć®å¤±ę•—ć‚’ē¤ŗ恙 OptimisticLockException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚ å‰Šé™¤ä»¶ę•°ćŒ0件恧ćŖć„å “åˆć€ OptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć›ć‚“ć€‚

ignoreVersionĀ¶

@Delete 恮 ignoreVersion 要ē“ ćŒ true ć®å “åˆć€ å‰Šé™¤ä»¶ę•°ćŒ0ä»¶ć§ć‚ć£ć¦ć‚‚ć€ OptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć›ć‚“ć€‚

@Delete(sqlFile = true, includeVersion = true)
int delete(Employee employee);
suppressOptimisticLockExceptionĀ¶

@Delete 恮 suppressOptimisticLockException 要ē“ ćŒ true ć®å “åˆć€ å‰Šé™¤ä»¶ę•°ćŒ0ä»¶ć§ć‚ć£ć¦ć‚‚ć€ OptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć›ć‚“ć€‚

@Delete(sqlFile = true, suppressOptimisticLockException = true)
int delete(Employee employee);

ć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆĀ¶

@Delete 恮 queryTimeout 要ē“ ć«ć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆć®ē§’ę•°ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Delete(queryTimeout = 10)
int delete(Employee employee);

ć“ć®ęŒ‡å®šćÆ态SQLćƒ•ć‚”ć‚¤ćƒ«ć®ä½æē”Øć®ęœ‰ē„”ć«é–¢äæ‚ćŖćé©ē”Øć•ć‚Œć¾ć™ć€‚ queryTimeout 要ē“ ć«å€¤ć‚’ęŒ‡å®šć—ćŖć„å “åˆć€ čح定 ć«ęŒ‡å®šć•ć‚ŒćŸć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆćŒä½æē”Øć•ć‚Œć¾ć™ć€‚

SQL ć®ćƒ­ć‚°å‡ŗ力形式Ā¶

@Delete 恮 sqlLog 要ē“ ć« SQL ć®ćƒ­ć‚°å‡ŗåŠ›å½¢å¼ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Delete(sqlLog = SqlLogType.RAW)
int delete(Employee employee);

SqlLogType.RAW ćÆćƒć‚¤ćƒ³ćƒ‰ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æļ¼ˆ?ļ¼‰ä»˜ćć® SQL 悒惭悰å‡ŗåŠ›ć™ć‚‹ć“ćØ悒č”Øć—ć¾ć™ć€‚

惐惃惁ęŒæå…„Ā¶

惐惃惁ęŒæå…„ć‚’č”Œć†ć«ćÆ态 @BatchInsert 悒Daoć®ćƒ”ć‚½ćƒƒćƒ‰ć«ę³Øé‡ˆć—ć¾ć™ć€‚

@Config(config = AppConfig.class)
public interface EmployeeDao {
    @BatchInsert
    int[] insert(List<Employee> employees);

    @BatchInsert
    BatchResult<ImmutableEmployee> insert(List<ImmutableEmployee> employees);
}

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆ态INSERTꖇ恌č‡Ŗ動ē”Ÿęˆć•ć‚Œć¾ć™ć€‚ @BatchInsert 恮 sqlFile 恫 true 悒čØ­å®šć™ć‚‹ć“ćØć§ć€ä»»ę„ć®SQLćƒ•ć‚”ć‚¤ćƒ«ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć§ćć¾ć™ć€‚

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮要ē“ ć®ć« ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ ćŒęŒ‡å®šć•ć‚Œć¦ć„ć‚‹å “åˆć€ ęŒæå…„ć®å®Ÿč”Œå‰ć«ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ć® preInsert ćƒ”ć‚½ćƒƒćƒ‰ć‚’ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć”ćØć«å‘¼ć³å‡ŗć—ć¾ć™ć€‚ ć¾ćŸć€ęŒæå…„ć®å®Ÿč”Œå¾Œć«ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ć® postInsert ćƒ”ć‚½ćƒƒćƒ‰ć‚’ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć”ćØć«å‘¼ć³å‡ŗć—ć¾ć™ć€‚

ęˆ»ć‚Šå€¤Ā¶

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ Iterable ć®ć‚µćƒ–ć‚æć‚¤ćƒ—ć®č¦ē“ ćŒć‚¤ćƒŸćƒ„ćƒ¼ć‚æćƒ–ćƒ«ćŖć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć®å “åˆć€ ęˆ»ć‚Šå€¤ćÆćć®ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć‚’č¦ē“ ćØ恙悋 org.seasar.doma.BatchResult 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

äøŠčØ˜ć®ę”ä»¶ć‚’ęŗ€ćŸć•ćŖ恄ćŖć„å “åˆć€ęˆ»ć‚Šå€¤ćÆå„ę›“ę–°å‡¦ē†ć®ę›“ꖰ件ꕰ悒č”Ø恙 int[] 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

SQL恮č‡Ŗ動ē”Ÿęˆć«ć‚ˆć‚‹ćƒćƒƒćƒęŒæå…„Ā¶

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ 要ē“ ćØ恙悋 java.lang.Iterable ć®ć‚µćƒ–ć‚æ悤惗恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ęŒ‡å®šć§ćć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ꕰćÆ1恤恧恙怂 å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚ ęˆ»ć‚Šå€¤ć®é…åˆ—ć®č¦ē“ ć®ę•°ćÆćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮 Iterable 恮要ē“ ć®ę•°ćØē­‰ć—恏ćŖć‚Šć¾ć™ć€‚ é…åˆ—ć®ćć‚Œćžć‚Œć®č¦ē“ ćŒę›“ę–°ć•ć‚ŒćŸä»¶ę•°ć‚’čæ”ć—ć¾ć™ć€‚

č­˜åˆ„å­Ā¶

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ ć®č­˜åˆ„å­ć«ć€ @GeneratedValue 恌ę³Øé‡ˆć•ć‚Œć¦ć„ć‚‹å “åˆć€ č­˜åˆ„å­ćŒč‡Ŗ動ēš„恫ē”Ÿęˆć•ć‚ŒčØ­å®šć•ć‚Œć¾ć™ć€‚

ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号Ā¶

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ 恫 @Version 恌ę³Øé‡ˆć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć‚ć‚‹å “åˆć€ ćć®ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć«ę˜Žē¤ŗēš„恫 0 仄äøŠć®å€¤ćŒčØ­å®šć•ć‚Œć¦ć„ć‚Œć°ćć®å€¤ć‚’ä½æē”Øć—ć¾ć™ć€‚ 悂恗čØ­å®šć•ć‚Œć¦ć„ćŖ恄恋态 0 ęœŖęŗ€ć®å€¤ćŒčØ­å®šć•ć‚Œć¦ć„ć‚Œć° 1 悒č‡Ŗå‹•ć§čØ­å®šć—ć¾ć™ć€‚

ęŒæå…„åÆ¾č±”ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£Ā¶
insertableĀ¶

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ 恫 @Column 恌ę³Øé‡ˆć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć‚ć‚‹å “åˆć€ @BatchInsert 恮 insertable 要ē“ ćŒ false 恮悂恮ćÆęŒæå…„åÆ¾č±”å¤–ć§ć™ć€‚

excludeĀ¶

@BatchInsert 恮 exclude 要ē“ ć«ęŒ‡å®šć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć‚’ęŒæå…„åÆ¾č±”å¤–ćØć—ć¾ć™ć€‚ ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć“ć®č¦ē“ ć«ęŒ‡å®šć•ć‚Œć¦ć„ć‚Œć°ć€ @Column 恮 insertable 要ē“ ćŒ true ć§ć‚ć£ć¦ć‚‚ęŒæå…„åÆ¾č±”å¤–ć§ć™ć€‚

@BatchInsert(exclude = {"name", "salary"})
int[] insert(List<Employee> employees);
includeĀ¶

@BatchInsert 恮 include 要ē“ ć«ęŒ‡å®šć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®ćæ悒ęŒæå…„åÆ¾č±”ćØć—ć¾ć™ć€‚ @BatchInsert 恮 include 要ē“ ćØ exclude 要ē“ ć®äø”ę–¹ć«åŒć˜ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒęŒ‡å®šć•ć‚ŒćŸå “åˆć€ ćć®ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćÆęŒæå…„åÆ¾č±”å¤–ć«ćŖć‚Šć¾ć™ć€‚ ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć“ć®č¦ē“ ć«ęŒ‡å®šć•ć‚Œć¦ć„恦悂态 @Column 恮 insertable 要ē“ ćŒ false 恧恂悌恰ęŒæå…„åÆ¾č±”å¤–ć§ć™ć€‚

@BatchInsert(include = {"name", "salary"})
int[] insert(List<Employee> employees);

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ć‚ˆć‚‹ćƒćƒƒćƒęŒæå…„Ā¶

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ć‚ˆć‚‹ćƒćƒƒćƒęŒæå…„ć‚’č”Œć†ć«ćÆ态 @BatchInsert 恮 sqlFile 要ē“ ć« true 悒čØ­å®šć—ć€ ćƒ”ć‚½ćƒƒćƒ‰ć«åƾåæœć™ć‚‹SQLćƒ•ć‚”ć‚¤ćƒ«ć‚’ē”Øę„ć—ć¾ć™ć€‚

@BatchInsert(sqlFile = true)
int[] insert(List<Employee> employees);

@BatchInsert(sqlFile = true)
BatchResult<ImmutableEmployee> insert(List<ImmutableEmployee> employees);

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆä»»ę„ć®åž‹ć‚’č¦ē“ ćØ恙悋 java.lang.Iterable ć®ć‚µćƒ–ć‚æ悤惗恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ęŒ‡å®šć§ćć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ꕰćÆ1恤恧恙怂 å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚ ęˆ»ć‚Šå€¤ć®é…åˆ—ć®č¦ē“ ć®ę•°ćÆćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮 Iterable 恮要ē“ ć®ę•°ćØē­‰ć—恏ćŖć‚Šć¾ć™ć€‚ é…åˆ—ć®ćć‚Œćžć‚Œć®č¦ē“ ćŒę›“ę–°ć•ć‚ŒćŸä»¶ę•°ć‚’čæ”ć—ć¾ć™ć€‚

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ 恫ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ćŒęŒ‡å®šć•ć‚Œć¦ć„ć¦ć‚‚ć€ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ć®ćƒ”ć‚½ćƒƒćƒ‰ćÆå‘¼ć³å‡ŗć—ć¾ć›ć‚“ć€‚

恟ćØ恈恰态äøŠčØ˜ć®ćƒ”ć‚½ćƒƒćƒ‰ć«åƾåæœć™ć‚‹SQLćÆę¬”ć®ć‚ˆć†ć«čؘčæ°ć—ć¾ć™ć€‚

insert into employee (id, name, salary, version)
values (/* employees.id */0, /* employees.name */'hoge', /* employees.salary */100, /* employees.version */0)

SQLćƒ•ć‚”ć‚¤ćƒ«äøŠć§ćÆć€ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åå‰ćÆ java.lang.Iterable ć®ć‚µćƒ–ć‚æć‚¤ćƒ—ć®č¦ē“ ć‚’ęŒ‡ć—ć¾ć™ć€‚

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ć‚ˆć‚‹ćƒćƒƒćƒęŒæå…„ć§ćÆć€č­˜åˆ„å­ć®č‡Ŗ動čØ­å®šć‚„ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗå·ć®č‡Ŗ動čح定ćÆč”Œć‚ć‚Œć¾ć›ć‚“ć€‚ ć¾ćŸć€ @BatchInsert 恮 exclude 要ē“ ć€ include 要ē“ ćÆ参ē…§ć•ć‚Œć¾ć›ć‚“怂

äø€ę„åˆ¶ē“„違反Ā¶

äø€ę„åˆ¶ē“„é•åćŒē™ŗē”Ÿć—ćŸå “合ćÆ态SQLćƒ•ć‚”ć‚¤ćƒ«ć®ä½æē”Øć®ęœ‰ē„”ć«é–¢äæ‚ćŖ恏 UniqueConstraintException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

ć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆĀ¶

@BatchInsert 恮 queryTimeout 要ē“ ć«ć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆć®ē§’ę•°ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@BatchInsert(queryTimeout = 10)
int[] insert(List<Employee> employees);

ć“ć®ęŒ‡å®šćÆ态SQLćƒ•ć‚”ć‚¤ćƒ«ć®ä½æē”Øć®ęœ‰ē„”ć«é–¢äæ‚ćŖćé©ē”Øć•ć‚Œć¾ć™ć€‚ queryTimeout 要ē“ ć«å€¤ć‚’ęŒ‡å®šć—ćŖć„å “åˆć€ čح定 ć«ęŒ‡å®šć•ć‚ŒćŸć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆćŒä½æē”Øć•ć‚Œć¾ć™ć€‚

ćƒćƒƒćƒć‚µć‚¤ć‚ŗĀ¶

@BatchInsert 恮 batchSize 要ē“ ć«ćƒćƒƒćƒć‚µć‚¤ć‚ŗć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@BatchInsert(batchSize = 10)
int[] insert(List<Employee> employees);

ć“ć®ęŒ‡å®šćÆ态SQLćƒ•ć‚”ć‚¤ćƒ«ć®ä½æē”Øć®ęœ‰ē„”ć«é–¢äæ‚ćŖćé©ē”Øć•ć‚Œć¾ć™ć€‚ batchSize 要ē“ ć«å€¤ć‚’ęŒ‡å®šć—ćŖć„å “åˆć€ čح定 ć«ęŒ‡å®šć•ć‚ŒćŸćƒćƒƒćƒć‚µć‚¤ć‚ŗ恌ä½æē”Øć•ć‚Œć¾ć™ć€‚

SQL ć®ćƒ­ć‚°å‡ŗ力形式Ā¶

@BatchInsert 恮 sqlLog 要ē“ ć« SQL ć®ćƒ­ć‚°å‡ŗåŠ›å½¢å¼ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@BatchInsert(sqlLog = SqlLogType.RAW)
int insert(Employee employee);

SqlLogType.RAW ćÆćƒć‚¤ćƒ³ćƒ‰ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æļ¼ˆ?ļ¼‰ä»˜ćć® SQL 悒惭悰å‡ŗåŠ›ć™ć‚‹ć“ćØ悒č”Øć—ć¾ć™ć€‚

ćƒćƒƒćƒę›“ę–°Ā¶

ćƒćƒƒćƒę›“ę–°ć‚’č”Œć†ć«ćÆ态 @BatchUpdate 悒Daoć®ćƒ”ć‚½ćƒƒćƒ‰ć«ę³Øé‡ˆć—ć¾ć™ć€‚

@Config(config = AppConfig.class)
public interface EmployeeDao {
    @BatchUpdate
    int[] update(List<Employee> employees);

    @BatchUpdate
    BatchResult<ImmutableEmployee> update(List<ImmutableEmployee> employees);
}

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆ态UPDATEꖇ恌č‡Ŗ動ē”Ÿęˆć•ć‚Œć¾ć™ć€‚ @BatchUpdate 恮 sqlFile 恫 true 悒čØ­å®šć™ć‚‹ć“ćØć§ć€ä»»ę„ć®SQLćƒ•ć‚”ć‚¤ćƒ«ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć§ćć¾ć™ć€‚

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮要ē“ ć® ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ 恫ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ćŒęŒ‡å®šć•ć‚Œć¦ć„ć‚‹å “åˆć€ ę›“ę–°ć®å®Ÿč”Œå‰ć«ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ć® preUpdate ćƒ”ć‚½ćƒƒćƒ‰ćŒć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć”ćØć«å‘¼ć³å‡ŗć•ć‚Œć¾ć™ć€‚ ć¾ćŸć€ę›“ę–°ć®å®Ÿč”Œå¾Œć«ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ć® postUpdate ćƒ”ć‚½ćƒƒćƒ‰ćŒć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć”ćØć«å‘¼ć³å‡ŗć•ć‚Œć¾ć™ć€‚

ęˆ»ć‚Šå€¤Ā¶

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ Iterable ć®ć‚µćƒ–ć‚æć‚¤ćƒ—ć®č¦ē“ ćŒć‚¤ćƒŸćƒ„ćƒ¼ć‚æćƒ–ćƒ«ćŖć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć®å “åˆć€ ęˆ»ć‚Šå€¤ćÆćć®ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć‚’č¦ē“ ćØ恙悋 org.seasar.doma.BatchResult 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

äøŠčØ˜ć®ę”ä»¶ć‚’ęŗ€ćŸć•ćŖ恄ćŖć„å “åˆć€ęˆ»ć‚Šå€¤ćÆå„ę›“ę–°å‡¦ē†ć®ę›“ꖰ件ꕰ悒č”Ø恙 int[] 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

SQL恮č‡Ŗ動ē”Ÿęˆć«ć‚ˆć‚‹ćƒćƒƒćƒę›“ꖰĀ¶

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ 悒要ē“ ćØ恙悋 java.lang.Iterable ć®ć‚µćƒ–ć‚æ悤惗恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ęŒ‡å®šć§ćć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ꕰćÆ1恤恧恙怂 å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚ ęˆ»ć‚Šå€¤ć®é…åˆ—ć®č¦ē“ ć®ę•°ćÆćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮 Iterable 恮要ē“ ć®ę•°ćØē­‰ć—恏ćŖć‚Šć¾ć™ć€‚ é…åˆ—ć®ćć‚Œćžć‚Œć®č¦ē“ ćŒę›“ę–°ć•ć‚ŒćŸä»¶ę•°ć‚’čæ”ć—ć¾ć™ć€‚

SQLč‡Ŗ動ē”Ÿęˆć«ćŠć‘ć‚‹ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćØę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”Ā¶

ę¬”ć®ę”ä»¶ć‚’ęŗ€ćŸć™å “åˆć«ć€ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ćŒč”Œć‚ć‚Œć¾ć™ć€‚

  • ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮java.lang.Iterableć®ć‚µćƒ–ć‚æć‚¤ćƒ—ć®č¦ē“ ć§ć‚ć‚‹ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ 恫@Version恌ę³Øé‡ˆć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć‚ć‚‹
  • @BatchUpdate恮ignoreVersion要ē“ ćŒfalse恧恂悋

ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ćŒęœ‰åŠ¹ć§ć‚ć‚Œć°ć€ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćÆč­˜åˆ„å­ćØćØć‚‚ć«ę›“ę–°ę”ä»¶ć«å«ć¾ć‚Œć€ 1å¢—åˆ†ć—ć¦ę›“ę–°ć•ć‚Œć¾ć™ć€‚ 恓恮ćØćć®ę›“ę–°ä»¶ę•°ćŒ0ä»¶ć®å “åˆć€ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ć®å¤±ę•—ć‚’ē¤ŗ恙 BatchOptimisticLockException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚ äø€ę–¹ć€ę›“ę–°ä»¶ę•°ćŒ1ä»¶ć®å “åˆćÆ态 BatchOptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œćšć€ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®ćƒćƒ¼ć‚øćƒ§ćƒ³ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®å€¤ćŒ1å¢—åˆ†ć•ć‚Œć¾ć™ć€‚

ignoreVersionĀ¶

@BatchUpdate 恮 ignoreVersion 要ē“ ćŒ true ć®å “åˆć€ ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćÆę›“ę–°ę”ä»¶ć«ćÆå«ć¾ć‚Œćšć€UPDATEꖇ恮SETå„ć«å«ć¾ć‚Œć¾ć™ć€‚ ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćÆć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć§čØ­å®šć—ćŸå€¤ć§ę›“ę–°ć•ć‚Œć¾ć™ć€‚ ć“ć®å “åˆć€ę›“ę–°ä»¶ę•°ćŒ0ä»¶ć§ć‚ć£ć¦ć‚‚ć€ BatchOptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć›ć‚“ć€‚

@BatchUpdate(ignoreVersion = true)
int[] update(List<Employee> employees);
suppressOptimisticLockExceptionĀ¶

@BatchUpdate 恮 suppressOptimisticLockException 要ē“ ćŒ true ć®å “åˆć€ @Versioni 恌ę³Øé‡ˆć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć‚ć‚Œć°ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćÆę›“ę–°ę”ä»¶ć«å«ć¾ć‚Œå¢—åˆ†ć‚‚ć•ć‚Œć¾ć™ćŒć€ ę›“ę–°ä»¶ę•°ćŒ0ä»¶ć§ć‚ć£ć¦ć‚‚ BatchOptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć›ć‚“ć€‚ 恟恠恗态ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®ćƒćƒ¼ć‚øćƒ§ćƒ³ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®å€¤ćÆ1å¢—åˆ†ć•ć‚Œć¾ć™ć€‚

@BatchUpdate(suppressOptimisticLockException = true)
int[] update(List<Employee> employees);
ꛓꖰåÆ¾č±”ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£Ā¶
updatableĀ¶

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ 恫 @Column 恌ę³Øé‡ˆć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć‚ć‚‹å “åˆć€ @Column 恮 updatable 要ē“ ćŒ false 恮悂恮ćÆꛓꖰåÆ¾č±”å¤–ć§ć™ć€‚

excludeĀ¶

@BatchUpdate 恮 exclude 要ē“ ć«ęŒ‡å®šć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć‚’ę›“ꖰåÆ¾č±”å¤–ćØć—ć¾ć™ć€‚ ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć“ć®č¦ē“ ć«ęŒ‡å®šć•ć‚Œć¦ć„ć‚Œć°ć€ @Column 恮 updatable 要ē“ ćŒ true ć§ć‚ć£ć¦ć‚‚å‰Šé™¤åÆ¾č±”å¤–ć§ć™ć€‚

@BatchUpdate(exclude = {"name", "salary"})
int[] update(List<Employee> employees);
includeĀ¶

@BatchUpdate 恮 include 要ē“ ć«ęŒ‡å®šć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®ćæć‚’å‰Šé™¤åÆ¾č±”ćØć—ć¾ć™ć€‚ @BatchUpdate 恮 include 要ē“ ćØ exclude 要ē“ ć®äø”ę–¹ć«åŒć˜ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒęŒ‡å®šć•ć‚ŒćŸå “åˆć€ćć®ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćÆꛓꖰåÆ¾č±”å¤–ć«ćŖć‚Šć¾ć™ć€‚ ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć“ć®č¦ē“ ć«ęŒ‡å®šć•ć‚Œć¦ć„恦悂态 @Column 恮 updatable 要ē“ ćŒ false ć§ć‚ć‚Œć°ę›“ę–°åÆ¾č±”å¤–ć§ć™ć€‚

@BatchUpdate(include = {"name", "salary"})
int[] update(List<Employee> employees);

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ć‚ˆć‚‹ćƒćƒƒćƒę›“ę–°Ā¶

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ć‚ˆć‚‹ćƒćƒƒćƒę›“ę–°ć‚’č”Œć†ć«ćÆ态 @BatchUpdate 恮 sqlFile 要ē“ ć« true 悒čØ­å®šć—ć€ ćƒ”ć‚½ćƒƒćƒ‰ć«åƾåæœć™ć‚‹SQLćƒ•ć‚”ć‚¤ćƒ«ć‚’ē”Øę„ć—ć¾ć™ć€‚

ćƒŽćƒ¼ćƒˆ

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ć‚ˆć‚‹ćƒćƒƒćƒę›“ę–°ćÆ态 ę›“ę–°ć‚«ćƒ©ćƒ ćƒŖć‚¹ćƒˆē”Ÿęˆć‚³ćƒ”ćƒ³ćƒˆ ć®åˆ©ē”Ø꜉ē„”ć«ć‚ˆć‚Šćƒ«ćƒ¼ćƒ«ćŒē•°ćŖć‚Šć¾ć™ć€‚

ę›“ę–°ć‚«ćƒ©ćƒ ćƒŖć‚¹ćƒˆē”Ÿęˆć‚³ćƒ”ćƒ³ćƒˆć‚’ä½æē”Øć™ć‚‹å “åˆĀ¶
@BatchUpdate(sqlFile = true)
int[] update(List<Employee> employees);

@BatchUpdate
BatchResult<ImmutableEmployee> update(List<ImmutableEmployee> employees);

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ 悒要ē“ ćØ恙悋 java.lang.Iterable ć®ć‚µćƒ–ć‚æ悤惗恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ęŒ‡å®šć§ćć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ꕰćÆ1恤恧恙怂 å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚ ęˆ»ć‚Šå€¤ć®é…åˆ—ć®č¦ē“ ć®ę•°ćÆćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮 Iterable 恮要ē“ ć®ę•°ćØē­‰ć—恏ćŖć‚Šć¾ć™ć€‚ é…åˆ—ć®ćć‚Œćžć‚Œć®č¦ē“ ćŒę›“ę–°ć•ć‚ŒćŸä»¶ę•°ć‚’čæ”ć—ć¾ć™ć€‚

恟ćØ恈恰态äøŠčØ˜ć®ćƒ”ć‚½ćƒƒćƒ‰ć«åƾåæœć™ć‚‹SQLćÆę¬”ć®ć‚ˆć†ć«čؘčæ°ć—ć¾ć™ć€‚

update employee set /*%populate*/ id = id where name = /* employees.name */'hoge'

SQLćƒ•ć‚”ć‚¤ćƒ«äøŠć§ćÆć€ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åå‰ćÆ Iterable ć®ć‚µćƒ–ć‚æć‚¤ćƒ—ć®č¦ē“ ć‚’ęŒ‡ć—ć¾ć™ć€‚

ꛓꖰåÆ¾č±”ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®åˆ¶å¾”ć«é–¢ć™ć‚‹ćƒ«ćƒ¼ćƒ«ćÆ态 SQL恮č‡Ŗ動ē”Ÿęˆć«ć‚ˆć‚‹ćƒćƒƒćƒę›“ꖰ ćØåŒć˜ć§ć™ć€‚

ę›“ę–°ć‚«ćƒ©ćƒ ćƒŖć‚¹ćƒˆē”Ÿęˆć‚³ćƒ”ćƒ³ćƒˆć‚’ä½æē”Ø恗ćŖć„å “åˆĀ¶
@BatchUpdate(sqlFile = true)
int[] update(List<Employee> employees);

@BatchUpdate
BatchResult<ImmutableEmployee> update(List<ImmutableEmployee> employees);

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆä»»ę„ć®åž‹ć‚’č¦ē“ ćØ恙悋 java.lang.Iterable ć®ć‚µćƒ–ć‚æ悤惗恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ęŒ‡å®šć§ćć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ꕰćÆ1恤恧恙怂 å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚ ęˆ»ć‚Šå€¤ć®é…åˆ—ć®č¦ē“ ć®ę•°ćÆćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮 Iterable 恮要ē“ ć®ę•°ćØē­‰ć—恏ćŖć‚Šć¾ć™ć€‚ é…åˆ—ć®ćć‚Œćžć‚Œć®č¦ē“ ćŒę›“ę–°ć•ć‚ŒćŸä»¶ę•°ć‚’čæ”ć—ć¾ć™ć€‚

恟ćØ恈恰态äøŠčØ˜ć®ćƒ”ć‚½ćƒƒćƒ‰ć«åƾåæœć™ć‚‹SQLćÆę¬”ć®ć‚ˆć†ć«čؘčæ°ć—ć¾ć™ć€‚

update employee set name = /* employees.name */'hoge', salary = /* employees.salary */100
where id = /* employees.id */0

SQLćƒ•ć‚”ć‚¤ćƒ«äøŠć§ćÆć€ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åå‰ćÆ Iterable ć®ć‚µćƒ–ć‚æć‚¤ćƒ—ć®č¦ē“ ć‚’ęŒ‡ć—ć¾ć™ć€‚

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ć‚ˆć‚‹ćƒćƒƒćƒę›“ę–°ć§ćÆć€ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗå·ć®č‡Ŗå‹•ę›“ę–°ćÆč”Œć‚ć‚Œć¾ć›ć‚“ć€‚ ć¾ćŸć€ @BatchUpdate 恮 exclude 要ē“ ć€ include 要ē“ ćÆ参ē…§ć•ć‚Œć¾ć›ć‚“怂

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ćŠć‘ć‚‹ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćØę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”Ā¶

ę¬”ć®ę”ä»¶ć‚’ęŗ€ćŸć™å “åˆć«ć€ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ćŒč”Œć‚ć‚Œć¾ć™ć€‚

恟恠恗态SQLćƒ•ć‚”ć‚¤ćƒ«ć«ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ē”Ø恮SQL悒čؘčæ°ć™ć‚‹ć®ćÆć€ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³é–‹ē™ŗč€…ć®č²¬ä»»ć§ć™ć€‚ 恟ćØ恈恰态äø‹čØ˜ć®SQLć®ć‚ˆć†ć«ć€ WHEREå„ć§ćƒćƒ¼ć‚øćƒ§ćƒ³ć‚’ē•Ŗå·ć‚’ęŒ‡å®šć—SETå„ć§ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗå·ć‚’1ć ć‘å¢—åˆ†ć—ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

update EMPLOYEE set DELETE_FLAG = 1, VERSION = /* employees.version */1 + 1
where ID = /* employees.id */1 and VERSION = /* employees.version */1

恓恮SQLć®ę›“ę–°ä»¶ę•°ćŒ0ä»¶ć¾ćŸćÆč¤‡ę•°ä»¶ć®å “åˆć€ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ć®å¤±ę•—ć‚’ē¤ŗ恙 BatchOptimisticLockException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚ ę›“ę–°ä»¶ę•°ćŒ1ä»¶ć®å “åˆć€ BatchOptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œćšć€ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®ćƒćƒ¼ć‚øćƒ§ćƒ³ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®å€¤ćŒ1å¢—åˆ†ć•ć‚Œć¾ć™ć€‚

ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ćŒęœ‰åŠ¹ć§ć‚ć‚Œć°ć€ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćÆč­˜åˆ„å­ćØćØć‚‚ć«ę›“ę–°ę”ä»¶ć«å«ć¾ć‚Œć€ 1å¢—åˆ†ć—ć¦ę›“ę–°ć•ć‚Œć¾ć™ć€‚ 恓恮ćØćć®ę›“ę–°ä»¶ę•°ćŒ0ä»¶ć¾ćŸćÆč¤‡ę•°ä»¶ć®å “åˆć€ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ć®å¤±ę•—ć‚’ē¤ŗ恙 BatchOptimisticLockException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚ äø€ę–¹ć€ę›“ę–°ä»¶ę•°ćŒ1ä»¶ć®å “åˆć€ BatchOptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œćšć€ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®ćƒćƒ¼ć‚øćƒ§ćƒ³ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®å€¤ćŒ1å¢—åˆ†ć•ć‚Œć¾ć™ć€‚

ignoreVersionĀ¶

@BatchUpdate 恮 ignoreVersion 要ē“ ćŒ true ć®å “åˆć€ ę›“ę–°ä»¶ę•°ćŒ0ä»¶ć¾ćŸćÆč¤‡ę•°ä»¶ć§ć‚ć£ć¦ć‚‚ć€ BatchOptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć›ć‚“ć€‚ ć¾ćŸć€ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®ćƒćƒ¼ć‚øćƒ§ćƒ³ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®å€¤ćÆå¤‰ę›“ć•ć‚Œć¾ć›ć‚“ć€‚

@BatchUpdate(sqlFile = true, ignoreVersion = true)
int[] update(List<Employee> employees);
suppressOptimisticLockExceptionĀ¶

@BatchUpdate 恮 suppressOptimisticLockException 要ē“ ćŒ true ć®å “åˆć€ ę›“ę–°ä»¶ę•°ćŒ0ä»¶ć¾ćŸćÆč¤‡ę•°ä»¶ć§ć‚ć£ć¦ć‚‚ BatchOptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć›ć‚“ć€‚ 恟恠恗态ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®ćƒćƒ¼ć‚øćƒ§ćƒ³ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®å€¤ćÆ1å¢—åˆ†ć•ć‚Œć¾ć™ć€‚

@BatchUpdate(sqlFile = true, suppressOptimisticLockException = true)
int[] update(List<Employee> employees);

äø€ę„åˆ¶ē“„違反Ā¶

äø€ę„åˆ¶ē“„é•åćŒē™ŗē”Ÿć—ćŸå “合ćÆ态SQLćƒ•ć‚”ć‚¤ćƒ«ć®ä½æē”Øć®ęœ‰ē„”ć«é–¢äæ‚ćŖ恏 UniqueConstraintException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

ć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆĀ¶

@BatchUpdate 恮 queryTimeout 要ē“ ć«ć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆć®ē§’ę•°ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@BatchUpdate(queryTimeout = 10)
int[] update(List<Employee> employees);

恓恮čح定ćÆ态SQLćƒ•ć‚”ć‚¤ćƒ«ć®ä½æē”Øć®ęœ‰ē„”ć«é–¢äæ‚ćŖćé©ē”Øć•ć‚Œć¾ć™ć€‚ queryTimeout 要ē“ ć«å€¤ć‚’ęŒ‡å®šć—ćŖć„å “åˆć€ čح定ć‚Æćƒ©ć‚¹ć«ęŒ‡å®šć•ć‚ŒćŸć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆćŒä½æē”Øć•ć‚Œć¾ć™ć€‚

ćƒćƒƒćƒć‚µć‚¤ć‚ŗĀ¶

@BatchUpdate 恮 batchSize 要ē“ ć«ćƒćƒƒćƒć‚µć‚¤ć‚ŗć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@BatchUpdate(batchSize = 10)
int[] update(List<Employee> employees);

ć“ć®ęŒ‡å®šćÆ态SQLćƒ•ć‚”ć‚¤ćƒ«ć®ä½æē”Øć®ęœ‰ē„”ć«é–¢äæ‚ćŖćé©ē”Øć•ć‚Œć¾ć™ć€‚ batchSize 要ē“ ć«å€¤ć‚’ęŒ‡å®šć—ćŖć„å “åˆć€ čح定 ć‚Æćƒ©ć‚¹ć«ęŒ‡å®šć•ć‚ŒćŸćƒćƒƒćƒć‚µć‚¤ć‚ŗ恌ä½æē”Øć•ć‚Œć¾ć™ć€‚

SQL ć®ćƒ­ć‚°å‡ŗ力形式Ā¶

@BatchUpdate 恮 sqlLog 要ē“ ć« SQL ć®ćƒ­ć‚°å‡ŗåŠ›å½¢å¼ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@BatchUpdate(sqlLog = SqlLogType.RAW)
int[] update(List<Employee> employees);

SqlLogType.RAW ćÆćƒć‚¤ćƒ³ćƒ‰ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æļ¼ˆ?ļ¼‰ä»˜ćć® SQL 悒惭悰å‡ŗåŠ›ć™ć‚‹ć“ćØ悒č”Øć—ć¾ć™ć€‚

ćƒćƒƒćƒå‰Šé™¤Ā¶

ćƒćƒƒćƒå‰Šé™¤ć‚’č”Œć†ć«ćÆ态 @BatchDelete 悒Daoć®ćƒ”ć‚½ćƒƒćƒ‰ć«ę³Øé‡ˆć—ć¾ć™ć€‚

@Config(config = AppConfig.class)
public interface EmployeeDao {
    @BatchDelete
    int[] delete(List<Employee> employees);
    ...
}

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆ态DELETEꖇ恌č‡Ŗ動ē”Ÿęˆć•ć‚Œć¾ć™ć€‚ @BatchDelete 恮 sqlFile 恫 true 悒čØ­å®šć™ć‚‹ć“ćØć§ć€ä»»ę„ć®SQLćƒ•ć‚”ć‚¤ćƒ«ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć§ćć¾ć™ć€‚

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮要ē“ ć§ć‚ć‚‹ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ 恫ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ćŒęŒ‡å®šć•ć‚Œć¦ć„ć‚‹å “åˆć€ å‰Šé™¤ć®å®Ÿč”Œå‰ć«ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ć® preDelete ćƒ”ć‚½ćƒƒćƒ‰ćŒć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć”ćØć«å‘¼ć³å‡ŗć•ć‚Œć¾ć™ć€‚ ć¾ćŸć€å‰Šé™¤ć®å®Ÿč”Œå¾Œć«ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćƒŖć‚¹ćƒŠćƒ¼ć® postDelete ćƒ”ć‚½ćƒƒćƒ‰ćŒć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć”ćØć«å‘¼ć³å‡ŗć•ć‚Œć¾ć™ć€‚

ęˆ»ć‚Šå€¤Ā¶

ęˆ»ć‚Šå€¤ćÆå„ę›“ę–°å‡¦ē†ć®ę›“ꖰ件ꕰ悒č”Ø恙 int[] 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

SQL恮č‡Ŗ動ē”Ÿęˆć«ć‚ˆć‚‹ćƒćƒƒćƒå‰Šé™¤Ā¶

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ 悒要ē“ ćØ恙悋 java.lang.Iterable ć®ć‚µćƒ–ć‚æ悤惗恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ęŒ‡å®šć§ćć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ꕰćÆ1恤恧恙怂 å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚ ęˆ»ć‚Šå€¤ć®é…åˆ—ć®č¦ē“ ć®ę•°ćÆćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮 Iterable 恮要ē“ ć®ę•°ćØē­‰ć—恏ćŖć‚Šć¾ć™ć€‚ é…åˆ—ć®ćć‚Œćžć‚Œć®č¦ē“ ćŒę›“ę–°ć•ć‚ŒćŸä»¶ę•°ć‚’čæ”ć—ć¾ć™ć€‚

SQLč‡Ŗ動ē”Ÿęˆć«ćŠć‘ć‚‹ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćØę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”Ā¶

ę¬”ć®ę”ä»¶ć‚’ęŗ€ćŸć™å “åˆć«ć€ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ćŒč”Œć‚ć‚Œć¾ć™ć€‚

  • ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮java.lang.Iterableć®ć‚µćƒ–ć‚æć‚¤ćƒ—ć®č¦ē“ ć§ć‚ć‚‹ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ 恫@Version恌ę³Øé‡ˆć•ć‚ŒćŸćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒć‚ć‚‹
  • @BatchDelete恮ignoreVersion要ē“ ćŒfalse恧恂悋

ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ćŒęœ‰åŠ¹ć§ć‚ć‚Œć°ć€ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćÆč­˜åˆ„å­ćØćØć‚‚ć«å‰Šé™¤ę”ä»¶ć«å«ć¾ć‚Œć¾ć™ć€‚ ć“ć®å “åˆć€å‰Šé™¤ä»¶ę•°ćŒ0ä»¶ć§ć‚ć‚Œć°ć€ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ć®å¤±ę•—ć‚’ē¤ŗ恙 BatchOptimisticLockException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

ignoreVersionĀ¶

@BatchDelete 恮 ignoreVersion 要ē“ ćŒ true ć®å “åˆć€ ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćÆå‰Šé™¤ę”ä»¶ć«ćÆå«ć¾ć‚Œć¾ć›ć‚“ć€‚ å‰Šé™¤ä»¶ę•°ćŒ0ä»¶ć§ć‚ć£ć¦ć‚‚ BatchOptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć›ć‚“ć€‚

@BatchDelete(ignoreVersion = true)
int[] delete(List<Employee> employees);
suppressOptimisticLockExceptionĀ¶

@BatchDelete 恮 suppressOptimisticLockException 要ē“ ćŒ true ć®å “åˆć€ ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćÆå‰Šé™¤ę”ä»¶ć«å«ć¾ć‚Œć¾ć™ćŒć€ å‰Šé™¤ä»¶ę•°ćŒ0ä»¶ć§ć‚ć£ć¦ć‚‚ BatchOptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć›ć‚“ć€‚

@BatchDelete(suppressOptimisticLockException = true)
int[] delete(List<Employee> employees);

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ć‚ˆć‚‹ćƒćƒƒćƒå‰Šé™¤Ā¶

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ć‚ˆć‚‹ćƒćƒƒćƒå‰Šé™¤ć‚’č”Œć†ć«ćÆ态 @BatchDelete 恮 sqlFile 要ē“ ć« true 悒čØ­å®šć—ć€ ćƒ”ć‚½ćƒƒćƒ‰ć«åƾåæœć™ć‚‹SQLćƒ•ć‚”ć‚¤ćƒ«ć‚’ē”Øę„ć—ć¾ć™ć€‚

@BatchDelete(sqlFile = true)
int[] delete(List<Employee> employees);

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆä»»ę„ć®åž‹ć‚’č¦ē“ ćØ恙悋 java.lang.Iterable ć®ć‚µćƒ–ć‚æ悤惗恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ęŒ‡å®šć§ćć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ꕰćÆ1恤恧恙怂 å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚ ęˆ»ć‚Šå€¤ć®é…åˆ—ć®č¦ē“ ć®ę•°ćÆćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮 Iterable 恮要ē“ ć®ę•°ćØē­‰ć—恏ćŖć‚Šć¾ć™ć€‚ é…åˆ—ć®ćć‚Œćžć‚Œć®č¦ē“ ćŒę›“ę–°ć•ć‚ŒćŸä»¶ę•°ć‚’čæ”ć—ć¾ć™ć€‚

恟ćØ恈恰态äøŠčØ˜ć®ćƒ”ć‚½ćƒƒćƒ‰ć«åƾåæœć™ć‚‹SQLćÆę¬”ć®ć‚ˆć†ć«čؘčæ°ć—ć¾ć™ć€‚

delete from employee where name = /* employees.name */'hoge'

SQLćƒ•ć‚”ć‚¤ćƒ«äøŠć§ćÆć€ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åå‰ćÆ java.lang.Iterable ć®ć‚µćƒ–ć‚æć‚¤ćƒ—ć®č¦ē“ ć‚’ęŒ‡ć—ć¾ć™ć€‚

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ćŠć‘ć‚‹ćƒćƒ¼ć‚øćƒ§ćƒ³ē•Ŗ号ćØę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”Ā¶

ę¬”ć®ę”ä»¶ć‚’ęŗ€ćŸć™å “åˆć«ć€ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ćŒč”Œć‚ć‚Œć¾ć™ć€‚

恟恠恗态SQLćƒ•ć‚”ć‚¤ćƒ«ć«ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ē”Ø恮SQL悒čؘčæ°ć™ć‚‹ć®ćÆć€ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³é–‹ē™ŗč€…ć®č²¬ä»»ć§ć™ć€‚ 恟ćØ恈恰态äø‹čØ˜ć®SQLć®ć‚ˆć†ć«ć€WHEREå„ć§ćƒćƒ¼ć‚øćƒ§ćƒ³ć‚’ē•Ŗå·ć‚’ęŒ‡å®šć—ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

delete from EMPLOYEE where ID = /* employees.id */1 and VERSION = /* employees.version */1

恓恮SQLć®å‰Šé™¤ä»¶ę•°ćŒ0ä»¶ć¾ćŸćÆč¤‡ę•°ä»¶ć®å “åˆć€ ę„½č¦³ēš„ęŽ’ä»–åˆ¶å¾”ć®å¤±ę•—ć‚’ē¤ŗ恙 BatchOptimisticLockException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

ignoreVersionĀ¶

@BatchDelete 恮 ignoreVersion 要ē“ ćŒ true ć®å “åˆć€å‰Šé™¤ä»¶ę•°ćŒ0ä»¶ć¾ćŸćÆč¤‡ę•°ä»¶ć§ć‚ć£ć¦ć‚‚ BatchOptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć›ć‚“ć€‚

@BatchDelete(sqlFile = true, ignoreVersion = true)
int[] delete(List<Employee> employees);
suppressOptimisticLockExceptionĀ¶

@BatchDelete 恮 suppressOptimisticLockException 要ē“ ćŒ true ć®å “åˆć€å‰Šé™¤ä»¶ę•°ćŒ0ä»¶ć¾ćŸćÆč¤‡ę•°ä»¶ć§ć‚ć£ć¦ć‚‚ BatchOptimisticLockException ćÆć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć›ć‚“ć€‚

@BatchDelete(sqlFile = true, suppressOptimisticLockException = true)
int[] delete(List<Employee> employees);

ć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆĀ¶

@BatchDelete 恮 queryTimeout 要ē“ ć«ć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆć®ē§’ę•°ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@BatchDelete(queryTimeout = 10)
int[] delete(List<Employee> employees);

ć“ć®ęŒ‡å®šćÆ态SQLćƒ•ć‚”ć‚¤ćƒ«ć®ä½æē”Øć®ęœ‰ē„”ć«é–¢äæ‚ćŖćé©ē”Øć•ć‚Œć¾ć™ć€‚ queryTimeout 要ē“ ć«å€¤ć‚’ęŒ‡å®šć—ćŖć„å “åˆć€ čح定 ć«ęŒ‡å®šć•ć‚ŒćŸć‚Æć‚ØćƒŖć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆćŒä½æē”Øć•ć‚Œć¾ć™ć€‚

ćƒćƒƒćƒć‚µć‚¤ć‚ŗĀ¶

@BatchDelete 恮 batchSize 要ē“ ć«ćƒćƒƒćƒć‚µć‚¤ć‚ŗć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@BatchDelete(batchSize = 10)
int[] delete(List<Employee> employees);

恓恮čح定ćÆ态SQLćƒ•ć‚”ć‚¤ćƒ«ć®ä½æē”Øć®ęœ‰ē„”ć«é–¢äæ‚ćŖćé©ē”Øć•ć‚Œć¾ć™ć€‚ batchSize 要ē“ ć«å€¤ć‚’ęŒ‡å®šć—ćŖć„å “åˆć€ čح定 ć«ęŒ‡å®šć•ć‚ŒćŸćƒćƒƒćƒć‚µć‚¤ć‚ŗ恌ä½æē”Øć•ć‚Œć¾ć™ć€‚

SQL ć®ćƒ­ć‚°å‡ŗ力形式Ā¶

@BatchDelete 恮 sqlLog 要ē“ ć« SQL ć®ćƒ­ć‚°å‡ŗåŠ›å½¢å¼ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@BatchDelete(sqlLog = SqlLogType.RAW)
int[] delete(List<Employee> employees);

SqlLogType.RAW ćÆćƒć‚¤ćƒ³ćƒ‰ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æļ¼ˆ?ļ¼‰ä»˜ćć® SQL 悒惭悰å‡ŗåŠ›ć™ć‚‹ć“ćØ悒č”Øć—ć¾ć™ć€‚

ć‚¹ćƒˆć‚¢ćƒ‰ćƒ•ć‚”ćƒ³ć‚Æć‚·ćƒ§ćƒ³Ā¶

ć‚¹ćƒˆć‚¢ćƒ‰ćƒ•ć‚”ćƒ³ć‚Æć‚·ćƒ§ćƒ³ć‚’å‘¼ć³å‡ŗ恙恫ćÆ态 @Function 悒Daoć®ćƒ”ć‚½ćƒƒćƒ‰ć«ę³Øé‡ˆć—ć¾ć™ć€‚

@Config(config = AppConfig.class)
public interface EmployeeDao {
    @Function
    Integer execute(@In Integer id, @InOut Reference<BigDecimal> salary);
    ...
}

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫ćÆć€ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ēØ®åˆ„ć‚’ē¤ŗ恙 @In 态 @InOut 态 @Out 态 @ResultSet ć®ć„ćšć‚Œć‹ć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćŒåæ…é ˆć§ć™ć€‚ ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆč¤‡ę•°ęŒ‡å®šć§ćć¾ć™ć€‚

ęˆ»ć‚Šå€¤Ā¶

ęˆ»ć‚Šå€¤ćÆę¬”ć®ć„ćšć‚Œć‹ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

1件悒čæ”ć™å “合Ā¶
複ꕰ件悒čæ”ć™å “合Ā¶

ę¬”ć®ć„ćšć‚Œć‹ć‚’č¦ē“ ćØ恙悋 java.util.List

ćŸć ć—ć€č¤‡ę•°ä»¶ć‚’čæ”恛悋恮ćÆćƒ•ć‚”ćƒ³ć‚Æć‚·ćƒ§ćƒ³ćŒć‚«ćƒ¼ć‚½ćƒ«ć‚’å®Ÿč”ŒēµęžœćØ恗恦čæ”ć™å “åˆć®ćæ恧恙怂

ćƒ•ć‚”ćƒ³ć‚Æć‚·ćƒ§ćƒ³åĀ¶

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆćƒ”ć‚½ćƒƒćƒ‰åćŒćƒ•ć‚”ćƒ³ć‚Æć‚·ćƒ§ćƒ³åć«ćŖć‚Šć¾ć™ć€‚ @Function 恮 name 要ē“ ć«å€¤ć‚’ęŒ‡å®šć—ćŸå “合ćÆć€ćć®å€¤ćŒćƒ•ć‚”ćƒ³ć‚Æć‚·ćƒ§ćƒ³åć«ćŖć‚Šć¾ć™ć€‚

@Function(name = "calculateSalary")
void execute(@In Integer id, @InOut Reference<BigDecimal> salary);

@Function 恮 catalog 要ē“ ć‚„ schema 要ē“ ć«ć‚«ć‚æćƒ­ć‚°åć‚„ć‚¹ć‚­ćƒ¼ćƒžåć‚’ęŒ‡å®šć§ćć¾ć™ć€‚ 恓恮ćØććƒ•ć‚”ćƒ³ć‚Æć‚·ćƒ§ćƒ³ć®åå‰ćÆ catalog 要ē“ ć€ schema 要ē“ ć€ name 要ē“  ļ¼ˆęŒ‡å®šć•ć‚Œć¦ć„ćŖć‘ć‚Œć°ćƒ”ć‚½ćƒƒćƒ‰åļ¼‰ć‚’ćƒ”ćƒŖć‚Ŗćƒ‰ć§é€£ēµć—ćŸć‚‚ć®ć«ćŖć‚Šć¾ć™ć€‚

@Function(catlog = "CATALOG", schema ="SCHEMA", name = "calculateSalary")
void execute(@In Integer id, @InOut Reference<BigDecimal> salary);

ęˆ»ć‚Šå€¤ć®åž‹ćŒ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ 悄 ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ 悒要ē“ ćØ恙悋 java.util.List ć®å “åˆć«ćŠć„ć¦ć€ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć™ć¹ć¦ć«åÆ¾ć—ć¦ę¼ć‚ŒćŖ恏ēµęžœć‚»ćƒƒćƒˆć®ć‚«ćƒ©ćƒ ć‚’ćƒžćƒƒćƒ”ćƒ³ć‚°ć™ć‚‹ć“ćØ悒äæčØ¼ć—ćŸć„å “åˆćÆ态 @Function 恮 ensureResultMapping 要ē“ ć« true ć‚’ęŒ‡å®šć—ć¾ć™ć€‚

@Function(ensureResultMapping = true)
List<Employee> execute();

ēµęžœć‚»ćƒƒćƒˆć®ć‚«ćƒ©ćƒ ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć•ć‚ŒćŖć„ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒå­˜åœØć™ć‚‹å “åˆ ResultMappingException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æĀ¶

ć‚¹ćƒˆć‚¢ćƒ‰ćƒ•ć‚”ćƒ³ć‚Æć‚·ćƒ§ćƒ³ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćØDaoćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮äø¦ć³é †ćÆåˆć‚ć›ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

INćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æĀ¶

INćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆ态 @In ć‚’ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫ę³Øé‡ˆć—ć¦ē¤ŗć—ć¾ć™ć€‚ ęŒ‡å®šåÆčƒ½ćŖćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆ仄äø‹ć®é€šć‚Šć§ć™ć€‚

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćŒåŸŗęœ¬åž‹ć‚‚ć—ććÆćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć®å “åˆć€å¼•ę•°ć‚’ null ć«ć§ćć¾ć™ć€‚ ćć‚Œä»„å¤–ć®åž‹ć®å “åˆć€å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚

@Function
void execute(@In Integer id);

ę¬”ć®ć‚ˆć†ć«ä½æē”Øć—ć¾ć™ć€‚

EmployeeDao dao = new EmployeeDaoImpl();
dao.execute(1);
INOUTćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æĀ¶

INOUTćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆ态 @InOut ć‚’ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫ę³Øé‡ˆć—ć¦ē¤ŗć—ć¾ć™ć€‚ ę³Øé‡ˆć•ć‚Œć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆ org.seasar.doma.jdbc.Reference 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ Reference ć®åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć«ęŒ‡å®šć§ćć‚‹åž‹ćÆ仄äø‹ć®é€šć‚Šć§ć™ć€‚

å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚

@Function
void execute(@InOut Reference<BigDecimal> salary);

ę¬”ć®ć‚ˆć†ć«ä½æē”Øć—ć¾ć™ć€‚

EmployeeDao dao = new EmployeeDaoImpl();
BigDecimal in = new BigDecimal(100);
Reference<BigDecimal> ref = new Reference<BigDecimal>(in);
dao.execute(ref);
BigDecimal out = ref.get();
OUTćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æĀ¶

OUTćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆ态 @Out ć‚’ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫ę³Øé‡ˆć—ć¦ē¤ŗć—ć¾ć™ć€‚ ę³Øé‡ˆć•ć‚Œć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆ org.seasar.doma.jdbc.Reference 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ Reference ć®åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć«ęŒ‡å®šć§ćć‚‹åž‹ćÆ仄äø‹ć®é€šć‚Šć§ć™ć€‚

å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚

ćƒ”ć‚½ćƒƒćƒ‰ć®ęˆ»ć‚Šå€¤ć®åž‹ćŒ void ä»„å¤–ć®å “åˆć€ęˆ»ć‚Šå€¤ćÆOUTćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćØćŖć‚Šć¾ć™ć€‚

@Function
Integer execute(@Out Reference<BigDecimal> salary);

ę¬”ć®ć‚ˆć†ć«ä½æē”Øć—ć¾ć™ć€‚

EmployeeDao dao = new EmployeeDaoImpl();
Reference<BigDecimal> ref = new Reference<BigDecimal>();
Integer result = dao.execute(ref);
BigDecimal out = ref.get();
ć‚«ćƒ¼ć‚½ćƒ«ć®OUTćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ悂恗恏ćÆēµęžœć‚»ćƒƒćƒˆĀ¶

ć‚«ćƒ¼ć‚½ćƒ«ć®OUTćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ态悂恗恏ćÆć‚¹ćƒˆć‚¢ćƒ‰ćƒ•ć‚”ćƒ³ć‚Æć‚·ćƒ§ćƒ³ćŒčæ”恙ēµęžœć‚»ćƒƒćƒˆćÆ态 @ResultSet ć‚’ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫ę³Øé‡ˆć—ć¦ē¤ŗć—ć¾ć™ć€‚ ę³Øé‡ˆć•ć‚Œć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆ态仄äø‹ć®åž‹ć‚’要ē“ ćØ恙悋 java.util.List 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚

@Function
void execute(@ResultSet List<Employee> employee);

ę¬”ć®ć‚ˆć†ć«ä½æē”Øć—ć¾ć™ć€‚

EmployeeDao dao = new EmployeeDaoImpl();
List<Employee> employees = new ArrayList<Employee>();
dao.execute(employees);
for (Employee e : employees) {
    ...
}

@ResultSet 恌ę³Ø釈恕悌恟 java.util.List ć®åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恌 ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ 恧恂悊态恋恤态ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć™ć¹ć¦ć«åÆ¾ć—ć¦ ę¼ć‚ŒćŖ恏ēµęžœć‚»ćƒƒćƒˆć®ć‚«ćƒ©ćƒ ć‚’ćƒžćƒƒćƒ”ćƒ³ć‚°ć™ć‚‹ć“ćØ悒äæčØ¼ć—ćŸć„å “åˆćÆ态 @ResultSet 恮 ensureResultMapping 要ē“ ć« true ć‚’ęŒ‡å®šć—ć¾ć™ć€‚

@Function
void execute(@ResultSet(ensureResultMapping = true) List<Employee> employee);

ēµęžœć‚»ćƒƒćƒˆć®ć‚«ćƒ©ćƒ ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć•ć‚ŒćŖć„ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒå­˜åœØć™ć‚‹å “åˆ ResultMappingException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

ćƒžćƒƒćƒ—ć®ć‚­ćƒ¼ć®ćƒćƒ¼ćƒŸćƒ³ć‚°č¦ē“„Ā¶

ēµęžœć‚»ćƒƒćƒˆć‚’ java.util.Map<String, Object> ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć™ć‚‹å “åˆć€ @Function 恮 mapKeyNaming 要ē“ ć«ćƒžćƒƒćƒ—ć®ć‚­ćƒ¼ć®ćƒćƒ¼ćƒŸćƒ³ć‚°č¦ē“„ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Function(mapKeyNaming = MapKeyNamingType.CAMEL_CASE)
List<Map<String, Object>> execute(@In Integer id);

MapKeyNamingType.CAMEL_CASE ćÆć€ć‚«ćƒ©ćƒ åć‚’ć‚­ćƒ£ćƒ”ćƒ«ć‚±ćƒ¼ć‚¹ć«å¤‰ę›ć™ć‚‹ć“ćØ悒ē¤ŗć—ć¾ć™ć€‚ ćć®ć»ć‹ć«ć€ć‚«ćƒ©ćƒ åć‚’ć‚’å¤§ę–‡å­—ć‚„å°ę–‡å­—ć«å¤‰ę›ć™ć‚‹č¦ē“„ćŒć‚ć‚Šć¾ć™ć€‚

꜀ēµ‚ēš„ćŖå¤‰ę›ēµęžœćÆć€ć“ć“ć«ęŒ‡å®šć—ćŸå€¤ćØ čح定 ć«ęŒ‡å®šć•ć‚ŒćŸ MapKeyNaming ć®å®Ÿč£…ć«ć‚ˆć‚Šę±ŗć¾ć‚Šć¾ć™ć€‚

SQL ć®ćƒ­ć‚°å‡ŗ力形式Ā¶

@Function 恮 sqlLog 要ē“ ć« SQL ć®ćƒ­ć‚°å‡ŗåŠ›å½¢å¼ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Function(sqlLog = SqlLogType.RAW)
void execute(@In Integer id);

SqlLogType.RAW ćÆćƒć‚¤ćƒ³ćƒ‰ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æļ¼ˆ?ļ¼‰ä»˜ćć® SQL 悒惭悰å‡ŗåŠ›ć™ć‚‹ć“ćØ悒č”Øć—ć¾ć™ć€‚

ć‚¹ćƒˆć‚¢ćƒ‰ćƒ—ćƒ­ć‚·ćƒ¼ć‚øćƒ£ćƒ¼Ā¶

ć‚¹ćƒˆć‚¢ćƒ‰ćƒ—ćƒ­ć‚·ćƒ¼ć‚øćƒ£ćƒ¼ć‚’å‘¼ć³å‡ŗ恙恫ćÆ态 @Procedure 悒Daoć®ćƒ”ć‚½ćƒƒćƒ‰ć«ę³Øé‡ˆć—ć¾ć™ć€‚

@Config(config = AppConfig.class)
public interface EmployeeDao {
    @Procedure
    void execute(@In Integer id, @InOut Reference<BigDecimal> salary);
    ...
}

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫ćÆć€ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ēØ®åˆ„ć‚’ē¤ŗ恙 @In 态 @InOut 态 @Out 态 @ResultSet ć®ć„ćšć‚Œć‹ć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćŒåæ…é ˆć§ć™ć€‚ ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆč¤‡ę•°ęŒ‡å®šć§ćć¾ć™ć€‚

ęˆ»ć‚Šå€¤Ā¶

ęˆ»ć‚Šå€¤ćÆ void 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

ćƒ—ćƒ­ć‚·ćƒ¼ć‚øćƒ£ćƒ¼åĀ¶

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆćƒ”ć‚½ćƒƒćƒ‰åćŒćƒ—ćƒ­ć‚·ćƒ¼ć‚øćƒ£ćƒ¼åć«ćŖć‚Šć¾ć™ć€‚ @Procedure 恮 name 要ē“ ć«å€¤ć‚’ęŒ‡å®šć—ćŸå “合ćÆć€ćć®å€¤ćŒćƒ—ćƒ­ć‚·ćƒ¼ć‚øćƒ£ćƒ¼åć«ćŖć‚Šć¾ć™ć€‚

@Procedure(name = "calculateSalary")
void execute(@In Integer id, @InOut Reference<BigDecimal> salary);

@Procedure 恮 catalog 要ē“ ć‚„ schema 要ē“ ć«ć‚«ć‚æćƒ­ć‚°åć‚„ć‚¹ć‚­ćƒ¼ćƒžåć‚’ęŒ‡å®šć§ćć¾ć™ć€‚ 恓恮ćØććƒ—ćƒ­ć‚·ćƒ¼ć‚øćƒ£ćƒ¼ć®åå‰ćÆ catalog 要ē“ ć€ schema 要ē“ ć€ name 要ē“ ļ¼ˆęŒ‡å®šć•ć‚Œć¦ć„ćŖć‘ć‚Œć°ćƒ”ć‚½ćƒƒćƒ‰åļ¼‰ć‚’ćƒ”ćƒŖć‚Ŗćƒ‰ć§é€£ēµć—ćŸć‚‚ć®ć«ćŖć‚Šć¾ć™ć€‚

@Procedure(catlog = "CATALOG", schema ="SCHEMA", name = "calculateSalary")
void execute(@In Integer id, @InOut Reference<BigDecimal> salary);

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æĀ¶

ć‚¹ćƒˆć‚¢ćƒ‰ćƒ—ćƒ­ć‚·ćƒ¼ć‚øćƒ£ćƒ¼ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćØDaoćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮äø¦ć³é †ćÆåˆć‚ć›ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

INćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æĀ¶

INćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆ态 @In ć‚’ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫ę³Øé‡ˆć—ć¦ē¤ŗć—ć¾ć™ć€‚ ęŒ‡å®šåÆčƒ½ćŖćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆ仄äø‹ć®é€šć‚Šć§ć™ć€‚

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćŒåŸŗęœ¬åž‹ć‚‚ć—ććÆćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć®å “åˆć€å¼•ę•°ć‚’ null ć«ć§ćć¾ć™ć€‚ ćć‚Œä»„å¤–ć®åž‹ć®å “åˆć€å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚

@Procedure
void execute(@In Integer id);

ę¬”ć®ć‚ˆć†ć«ä½æē”Øć—ć¾ć™ć€‚

EmployeeDao dao = new EmployeeDaoImpl();
dao.execute(1);
INOUTćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æĀ¶

INOUTćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆ态 @InOut ć‚’ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫ę³Øé‡ˆć—ć¦ē¤ŗć—ć¾ć™ć€‚ ę³Øé‡ˆć•ć‚Œć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆ org.seasar.doma.jdbc.Reference 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ Reference ć®åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć«ęŒ‡å®šć§ćć‚‹åž‹ćÆ仄äø‹ć®é€šć‚Šć§ć™ć€‚

å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚

@Procedure
void execute(@InOut Reference<BigDecimal> salary);

ę¬”ć®ć‚ˆć†ć«ä½æē”Øć—ć¾ć™ć€‚

EmployeeDao dao = new EmployeeDaoImpl();
BigDecimal in = new BigDecimal(100);
Reference<BigDecimal> ref = new Reference<BigDecimal>(in);
dao.execute(ref);
BigDecimal out = ref.get();
OUTćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æĀ¶

OUTćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆ态 @Out ć‚’ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫ę³Øé‡ˆć—ć¦ē¤ŗć—ć¾ć™ć€‚ ę³Øé‡ˆć•ć‚Œć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆ org.seasar.doma.jdbc.Reference 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ Reference ć®åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć«ęŒ‡å®šć§ćć‚‹åž‹ćÆ仄äø‹ć®é€šć‚Šć§ć™ć€‚

å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚

@Procedure
void execute(@Out Reference<BigDecimal> salary);

ę¬”ć®ć‚ˆć†ć«ä½æē”Øć—ć¾ć™ć€‚

EmployeeDao dao = new EmployeeDaoImpl();
Reference<BigDecimal> ref = new Reference<BigDecimal>();
dao.execute(ref);
BigDecimal out = ref.get();
ć‚«ćƒ¼ć‚½ćƒ«ć®OUTćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ悂恗恏ćÆēµęžœć‚»ćƒƒćƒˆĀ¶

ć‚«ćƒ¼ć‚½ćƒ«ć®OUTćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ态悂恗恏ćÆć‚¹ćƒˆć‚¢ćƒ‰ćƒ—ćƒ­ć‚·ćƒ¼ć‚øćƒ£ćƒ¼ćŒčæ”恙ēµęžœć‚»ćƒƒćƒˆćÆ态 @ResultSet ć‚’ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫ę³Øé‡ˆć—ć¦ē¤ŗć—ć¾ć™ć€‚ ę³Øé‡ˆć•ć‚Œć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆ态仄äø‹ć®åž‹ć‚’要ē“ ćØ恙悋 java.util.List 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚

@Procedure
void execute(@ResultSet List<Employee> employees);

ę¬”ć®ć‚ˆć†ć«ä½æē”Øć—ć¾ć™ć€‚

EmployeeDao dao = new EmployeeDaoImpl();
List<Employee> employees = new ArrayList<Employee>();
dao.execute(employees);
for (Employee e : employees) {
    ...
}

@ResultSet 恌ę³Ø釈恕悌恟 java.util.List ć®åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恌 ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ 恧恂悊态恋恤态ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć™ć¹ć¦ć«åÆ¾ć—ć¦ ę¼ć‚ŒćŖ恏ēµęžœć‚»ćƒƒćƒˆć®ć‚«ćƒ©ćƒ ć‚’ćƒžćƒƒćƒ”ćƒ³ć‚°ć™ć‚‹ć“ćØ悒äæčØ¼ć—ćŸć„å “åˆćÆ态 @ResultSet 恮 ensureResultMapping 要ē“ ć« true ć‚’ęŒ‡å®šć—ć¾ć™ć€‚

@Procedure
void execute(@ResultSet(ensureResultMapping = true) List<Employee> employee);

ēµęžœć‚»ćƒƒćƒˆć®ć‚«ćƒ©ćƒ ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć•ć‚ŒćŖć„ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćŒå­˜åœØć™ć‚‹å “åˆ ResultMappingException ćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ć€‚

ćƒžćƒƒćƒ—ć®ć‚­ćƒ¼ć®ćƒćƒ¼ćƒŸćƒ³ć‚°č¦ē“„Ā¶

ēµęžœć‚»ćƒƒćƒˆć‚’ java.util.Map<String, Object> ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć™ć‚‹å “åˆć€ @Procedure 恮 mapKeyNaming 要ē“ ć«ćƒžćƒƒćƒ—ć®ć‚­ćƒ¼ć®ćƒćƒ¼ćƒŸćƒ³ć‚°č¦ē“„ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Procedure(mapKeyNaming = MapKeyNamingType.CAMEL_CASE)
void execute(@ResultSet List<Map<String, Object>> employees);

MapKeyNamingType.CAMEL_CASE ćÆć€ć‚«ćƒ©ćƒ åć‚’ć‚­ćƒ£ćƒ”ćƒ«ć‚±ćƒ¼ć‚¹ć«å¤‰ę›ć™ć‚‹ć“ćØ悒ē¤ŗć—ć¾ć™ć€‚ ćć®ć»ć‹ć«ć€ć‚«ćƒ©ćƒ åć‚’ć‚’å¤§ę–‡å­—ć‚„å°ę–‡å­—ć«å¤‰ę›ć™ć‚‹č¦ē“„ćŒć‚ć‚Šć¾ć™ć€‚

꜀ēµ‚ēš„ćŖå¤‰ę›ēµęžœćÆć€ć“ć“ć«ęŒ‡å®šć—ćŸå€¤ćØ čح定 ć«ęŒ‡å®šć•ć‚ŒćŸ MapKeyNaming ć®å®Ÿč£…ć«ć‚ˆć‚Šę±ŗć¾ć‚Šć¾ć™ć€‚

SQL ć®ćƒ­ć‚°å‡ŗ力形式Ā¶

@Procedure 恮 sqlLog 要ē“ ć« SQL ć®ćƒ­ć‚°å‡ŗåŠ›å½¢å¼ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Procedure(sqlLog = SqlLogType.RAW)
void execute(@In Integer id);

SqlLogType.RAW ćÆćƒć‚¤ćƒ³ćƒ‰ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æļ¼ˆ?ļ¼‰ä»˜ćć® SQL 悒惭悰å‡ŗåŠ›ć™ć‚‹ć“ćØ悒č”Øć—ć¾ć™ć€‚

ćƒ•ć‚”ć‚Æ惈ćƒŖĀ¶

java.sql.Connection ćŒęä¾›ć™ć‚‹ćƒ•ć‚”ć‚Æ惈ćƒŖćƒ”ć‚½ćƒƒćƒ‰ć‹ć‚‰ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’å–å¾—ć™ć‚‹ć«ćÆ态 Daoć®ćƒ”ć‚½ćƒƒćƒ‰ć«ę¬”ć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ę³Øé‡ˆć—ć¾ć™ć€‚

  • java.sql.Array悒ē”Ÿęˆć™ć‚‹ć«ćÆ态@ArrayFactory
  • java.sql.Blob悒ē”Ÿęˆć™ć‚‹ć«ćÆ态@BlobFactory
  • java.sql.Clob悒ē”Ÿęˆć™ć‚‹ć«ćÆ态@ClobFactory
  • java.sql.NClob悒ē”Ÿęˆć™ć‚‹ć«ćÆ态@NClobFactory
  • java.sql.SQLXML悒ē”Ÿęˆć™ć‚‹ć«ćÆ态@SQLXMLFactory

Array恮ē”ŸęˆĀ¶

ęˆ»ć‚Šå€¤ć®åž‹ćÆ java.sql.Array ć€ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆ1ć¤ć®é…åˆ—åž‹ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ å¼•ę•°ćÆ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚

@ArrayFactory 恮 typeName 要ē“ ć«ćÆćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć®åž‹åć‚’ęŒ‡å®šć—ć¾ć™ć€‚

@ArrayFactory(typeName = "integer")
Array createIntegerArray(Integer[] elements);

Blob恮ē”ŸęˆĀ¶

ęˆ»ć‚Šå€¤ć®åž‹ćÆ java.sql.Blob ć€ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ꕰćÆ0恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

@BlobFactory
Blob createBlob();

Clob恮ē”ŸęˆĀ¶

ęˆ»ć‚Šå€¤ć®åž‹ćÆ java.sql.Clob ć€ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ꕰćÆ0恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

@ClobFactory
Clob createClob();

NClob恮ē”ŸęˆĀ¶

ęˆ»ć‚Šå€¤ć®åž‹ćÆ java.sql.NClob ć€ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ꕰćÆ0恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

@NClobFactory
NClob createNClob();

SQLXML恮ē”ŸęˆĀ¶

ęˆ»ć‚Šå€¤ć®åž‹ćÆ java.sql.SQLXML ć€ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ꕰćÆ0恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

@SQLXMLFactory
SQLXML createSQLXML();

ć‚¹ć‚ÆćƒŖ惗惈Ā¶

SQLć‚¹ć‚ÆćƒŖćƒ—ćƒˆć®å®Ÿč”Œć‚’č”Œć†ć«ćÆ态 @Script 悒Daoć®ćƒ”ć‚½ćƒƒćƒ‰ć«ę³Øé‡ˆć—ć¾ć™ć€‚

@Config(config = AppConfig.class)
public interface EmployeeDao {
    @Script
    void createTable();
    ...
}

ćƒ”ć‚½ćƒƒćƒ‰ć®ęˆ»ć‚Šå€¤ć®åž‹ćÆ void 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ꕰćÆ0恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

ć¾ćŸć€ćƒ”ć‚½ćƒƒćƒ‰ć«åƾåæœć™ć‚‹ć‚¹ć‚ÆćƒŖćƒ—ćƒˆćƒ•ć‚”ć‚¤ćƒ«ćŒåæ…é ˆć§ć™ć€‚

ć‚¹ć‚ÆćƒŖćƒ—ćƒˆćƒ•ć‚”ć‚¤ćƒ«Ā¶

ć‚¹ć‚ÆćƒŖćƒ—ćƒˆćƒ•ć‚”ć‚¤ćƒ«ć§ćÆ态 Dialect ćŒęä¾›ć™ć‚‹RDBMSåć‚„åŒŗåˆ‡ć‚Šę–‡å­—ćŒä½æē”Øć•ć‚Œć¾ć™ć€‚

ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ Dialectć®åå‰ RDBMS名 åŒŗåˆ‡ć‚Šę–‡å­—
DB2 Db2Dialect db2 @
H2 Database Engine 1.2.126 H212126Dialect h2  
H2 Database H2Dialect h2  
HSQLDB HsqldbDialect hsqldb  
Microsoft SQL Server 2008 Mssql2008Dialect mssql GO
Microsoft SQL Server MssqlDialect mssql GO
MySQL MySqlDialect mysql /
Oracle Database OracleDialect oracle /
PostgreSQL PostgresDialect postgres $$
SQLite SqliteDialect sqlite  
配ē½®å “ꉀĀ¶

ć‚¹ć‚ÆćƒŖćƒ—ćƒˆćƒ•ć‚”ć‚¤ćƒ«ćÆć‚Æćƒ©ć‚¹ćƒ‘ć‚¹ćŒé€šć£ćŸ META-INF ćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖ仄äø‹ć«é…ē½®ć—ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

ćƒ•ć‚”ć‚¤ćƒ«åć®å½¢å¼Ā¶

ćƒ•ć‚”ć‚¤ćƒ«åćÆć€ę¬”ć®å½¢å¼ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

META-INF/Dao恮ć‚Æćƒ©ć‚¹ć®å®Œå…Øäæ®é£¾åć‚’ćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖć«å¤‰ę›ć—ćŸć‚‚ć®/Daoć®ćƒ”ć‚½ćƒƒćƒ‰å.script

ä¾‹ćˆć°ć€ Dao恮ć‚Æćƒ©ć‚¹ćŒ aaa.bbb.EmployeeDao ć§ćƒžćƒƒćƒ”ćƒ³ć‚°ć—ćŸć„ćƒ”ć‚½ćƒƒćƒ‰ćŒ createTable ć®å “åˆć€ćƒ‘ć‚¹åćÆę¬”ć®ć‚ˆć†ć«ćŖć‚Šć¾ć™ć€‚

META-INF/aaa/bbb/EmployeeDao/createTable.script

複ꕰ恮RDBMS恫åƾåæœć™ć‚‹åæ…č¦ćŒć‚ć‚Šē‰¹å®šć®RDBMS恧ćÆåˆ„ć®ć‚¹ć‚ÆćƒŖćƒ—ćƒˆćƒ•ć‚”ć‚¤ćƒ«ć‚’ä½æć„ćŸć„å “åˆć€ .script ć®å‰ć«ćƒć‚¤ćƒ•ćƒ³åŒŗåˆ‡ć‚Šć§RDBMSåć‚’å…„ć‚Œć‚‹ć“ćØ恧态 å„Ŗ先ēš„恫ä½æē”Øć™ć‚‹ćƒ•ć‚”ć‚¤ćƒ«ć‚’ęŒ‡ē¤ŗć§ćć¾ć™ć€‚ 恟ćØ恈恰态PostgreSQL専ē”Ø恮SQLćƒ•ć‚”ć‚¤ćƒ«ćÆę¬”ć®åå‰ć«ć—ć¾ć™ć€‚

META-INF/aaa/bbb/EmployeeDao/createTables-postgres.script

ć“ć®å “åˆć€PostgreSQL悒ä½æē”Øć—ć¦ć„ć‚‹å “åˆć«é™ć‚Šć€ META-INF/aaa/bbb/EmployeeDao/createTable.script 悈悊悂 META-INF/aaa/bbb/EmployeeDao/createTable-postgres.script 恌å„Ŗ先ēš„恫ä½æē”Øć•ć‚Œć¾ć™ć€‚

ć‚Øćƒ³ć‚³ćƒ¼ćƒ‡ć‚£ćƒ³ć‚°Ā¶

ć‚¹ć‚ÆćƒŖćƒ—ćƒˆćƒ•ć‚”ć‚¤ćƒ«ć®ć‚Øćƒ³ć‚³ćƒ¼ćƒ‡ć‚£ćƒ³ć‚°ćÆUTF-8恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

åŒŗåˆ‡ć‚Šę–‡å­—Ā¶

ć‚¹ć‚ÆćƒŖćƒ—ćƒˆćƒ•ć‚”ć‚¤ćƒ«ć®åŒŗåˆ‡ć‚Šę–‡å­—ć«ćÆ态 ć‚¹ćƒ†ćƒ¼ćƒˆćƒ”ćƒ³ćƒˆć®åŒŗåˆ‡ć‚Šę–‡å­—ćØ惖惭惃ć‚Æ恮åŒŗåˆ‡ć‚Šę–‡å­—ć®2ēØ®é”žćŒć‚ć‚Šć¾ć™ć€‚

ć‚¹ćƒ†ćƒ¼ćƒˆćƒ”ćƒ³ćƒˆć®åŒŗåˆ‡ć‚Šę–‡å­—ćÆć‚»ćƒŸć‚³ćƒ­ćƒ³ ; 恧恙怂

惖惭惃ć‚Æ恮åŒŗåˆ‡ć‚Šę–‡å­—ćÆ态 Dialect ćŒęä¾›ć™ć‚‹å€¤ćŒä½æē”Øć•ć‚Œć¾ć™ć€‚

惖惭惃ć‚Æ恮åŒŗåˆ‡ć‚Šę–‡å­—ćÆć€ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć® blockDelimiter 要ē“ ć§ę˜Žē¤ŗ恙悋恓ćØć‚‚ć§ćć¾ć™ć€‚ ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć§ęŒ‡å®šć—ćŸå “åˆć€ Dialect ć®å€¤ć‚ˆć‚Šć‚‚å„Ŗå…ˆć•ć‚Œć¾ć™ć€‚

@Script(blockDelimiter = "GO")
void createTable();
ć‚Øćƒ©ćƒ¼ē™ŗē”Ÿę™‚恮ē¶™ē¶šå®Ÿč”ŒĀ¶

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆć€ć‚¹ć‚ÆćƒŖ惗惈äø­ć®ć©ć‚Œć‹ć®SQLć®å®Ÿč”ŒćŒå¤±ę•—ć™ć‚Œć°ć€ 処ē†ćÆćć“ć§ę­¢ć¾ć‚Šć¾ć™ć€‚ ć—ć‹ć—ć€ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć® haltOnError 要ē“ ć« false ć‚’ęŒ‡å®šć™ć‚‹ć“ćØ恧态ć‚Øćƒ©ćƒ¼ē™ŗē”Ÿę™‚ć«å‡¦ē†ć‚’ē¶™ē¶šć•ć›ć‚‹ć“ćØćŒć§ćć¾ć™ć€‚

@Script(haltOnError = false)
void createTable();

čؘčæ°ä¾‹Ā¶

ć‚¹ć‚ÆćƒŖćƒ—ćƒˆćƒ•ć‚”ć‚¤ćƒ«ćÆę¬”ć®ć‚ˆć†ć«čؘčæ°ć§ćć¾ć™ć€‚ ć“ć®ä¾‹ćÆ态Oracle Databaseć«ęœ‰åŠ¹ćŖć‚¹ć‚ÆćƒŖ惗惈恧恙怂

/*
 * ćƒ†ćƒ¼ćƒ–ćƒ«å®šē¾©ļ¼ˆSQLć‚¹ćƒ†ćƒ¼ćƒˆćƒ”ćƒ³ćƒˆļ¼‰
 */
create table EMPLOYEE (
  ID numeric(5) primary key,  -- č­˜åˆ„å­
  NAME varchar2(20)           -- 名前
);

/*
 * ćƒ‡ćƒ¼ć‚æ恮čæ½åŠ ļ¼ˆSQLć‚¹ćƒ†ćƒ¼ćƒˆćƒ”ćƒ³ćƒˆļ¼‰
 */
insert into EMPLOYEE (ID, NAME) values (1, 'SMITH');

/*
 * ćƒ—ćƒ­ć‚·ćƒ¼ć‚øćƒ£ćƒ¼å®šē¾©ļ¼ˆSQL惖惭惃ć‚Æļ¼‰
 */
create or replace procedure proc
( cur out sys_refcursor,
  employeeid in numeric
) as
begin
  open cur for select * from employee where id > employeeid order by id;
end proc_resultset;
/

/*
 * ćƒ—ćƒ­ć‚·ćƒ¼ć‚øćƒ£ćƒ¼å®šē¾©2ļ¼ˆSQL惖惭惃ć‚Æļ¼‰
 */
create or replace procedure proc2
( cur out sys_refcursor,
  employeeid in numeric
) as
begin
  open cur for select * from employee where id > employeeid order by id;
end proc_resultset;
/

ć‚³ćƒ”ćƒ³ćƒˆćÆ1č”Œć‚³ćƒ”ćƒ³ćƒˆ -- ćØ惖惭惃ć‚Æć‚³ćƒ”ćƒ³ćƒˆ /* */ 恮2ēØ®é”žćŒä½æē”Øć§ćć¾ć™ć€‚ ć‚³ćƒ”ćƒ³ćƒˆćÆå–ć‚Šé™¤ć‹ć‚Œć¦ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ćøē™ŗč”Œć•ć‚Œć¾ć™ć€‚

1恤恮SQLć‚¹ćƒ†ćƒ¼ćƒˆćƒ”ćƒ³ćƒˆćÆč¤‡ę•°č”Œć«åˆ†ć‘ć¦čؘčæ°ć§ćć¾ć™ć€‚ ć‚¹ćƒ†ćƒ¼ćƒˆćƒ”ćƒ³ćƒˆćÆć‚»ćƒŸć‚³ćƒ­ćƒ³ ; 恧åŒŗåˆ‡ć‚‰ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ę”¹č”ŒćÆć‚¹ćƒ†ćƒ¼ćƒˆćƒ”ćƒ³ćƒˆć®åŒŗåˆ‡ć‚ŠćØćÆćæćŖć•ć‚Œć¾ć›ć‚“ć€‚

ć‚¹ćƒˆć‚¢ćƒ‰ćƒ—ćƒ­ć‚·ćƒ¼ć‚øćƒ£ćƒ¼ćŖć©ć®ćƒ–ćƒ­ćƒƒć‚Æ恮åŒŗåˆ‡ć‚ŠćÆ态 Dialect ć®ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®å€¤ć‹ć€ @Script 恮 blockDelimiter 要ē“ ć«ęŒ‡å®šć—ćŸå€¤ć‚’ä½æē”Ø恗恦ē¤ŗć›ć¾ć™ć€‚ ć“ć®ä¾‹ć§ćÆ态 OracleDialect ć®ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®åŒŗåˆ‡ć‚Šę–‡å­—ć§ć‚ć‚‹ć‚¹ćƒ©ćƒƒć‚·ćƒ„ / 悒ä½æē”Øć—ć¦ć„ć¾ć™ć€‚ 惖惭惃ć‚Æ恮 åŒŗåˆ‡ć‚Šę–‡å­—ćÆč”Œé ­ć«čؘčæ°ć—态 åŒŗåˆ‡ć‚Šę–‡å­—ć®å¾Œć‚ć«ćÆä½•ć‚‚čؘčæ°ć—ćŖć„ć‚ˆć†ć«ć—ć¦ćć ć•ć„ć€‚ ć¤ć¾ć‚Šć€åŒŗåˆ‡ć‚Šę–‡å­—ć ć‘ć®č”ŒćØ恗ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

SQL ć®ćƒ­ć‚°å‡ŗ力形式Ā¶

@Script 恮 sqlLog 要ē“ ć« SQL ć®ćƒ­ć‚°å‡ŗåŠ›å½¢å¼ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚

@Script(sqlLog = SqlLogType.RAW)
void createTable();

SqlLogType.RAW ćÆćƒć‚¤ćƒ³ćƒ‰ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æļ¼ˆ?ļ¼‰ä»˜ćć® SQL 悒惭悰å‡ŗåŠ›ć™ć‚‹ć“ćØ悒č”Øć—ć¾ć™ć€‚

SQLćƒ—ćƒ­ć‚»ćƒƒć‚µĀ¶

SQLćƒ†ćƒ³ćƒ—ćƒ¬ćƒ¼ćƒˆć§ēµ„ćæē«‹ć¦ć‚‰ć‚ŒćŸSQLć‚’ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć§ę‰±ć†ć«ćÆ态 @SqlProcessor 悒Daoć®ćƒ”ć‚½ćƒƒćƒ‰ć«ę³Øé‡ˆć—ć¾ć™ć€‚

@Config(config = AppConfig.class)
public interface EmployeeDao {
    @SqlProcessor
    <R> R process(Integer id, BiFunction<Config, PreparedSql, R> handler);
    ...
}

ćƒ”ć‚½ćƒƒćƒ‰ć«åƾåæœć™ć‚‹ SQL 恌åæ…é ˆć§ć™ć€‚

č­¦å‘Š

SQLćƒ—ćƒ­ć‚»ćƒƒć‚µć‚’ä½æć£ć¦SQL悒ēµ„ćæē«‹ć¦å®Ÿč”Œć™ć‚‹å “åˆć€ę½œåœØēš„恫ćÆåøø恫SQLć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć®ćƒŖć‚¹ć‚ÆćŒć‚ć‚Šć¾ć™ć€‚ ć¾ćšćÆ态他恮ć‚Æć‚ØćƒŖ悂恗恏ćÆć‚Æć‚ØćƒŖćƒ“ćƒ«ćƒ€ć‚’ä½æć†ę–¹ę³•ć‚’ę¤œčØŽć—ć¦ćć ć•ć„ć€‚ ć¾ćŸć€SQLćƒ—ćƒ­ć‚»ćƒƒć‚µć§ćÆäæ”é ¼ć§ććŖć„å€¤ć‚’SQL恮ēµ„ćæē«‹ć¦ć«ä½æ悏ćŖć„ć‚ˆć†ć«ę³Øę„ć—ć¦ćć ć•ć„ć€‚

ęˆ»ć‚Šå€¤Ā¶

ćƒ”ć‚½ćƒƒćƒ‰ć®ęˆ»ć‚Šå€¤ćÆä»»ę„ć®åž‹ć«ć§ćć¾ć™ć€‚ 恟恠恗态 BiFunction åž‹ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮3ē•Ŗē›®ć®åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćØåˆć‚ć›ć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚

ćŖćŠć€ęˆ»ć‚Šå€¤ć®åž‹ć‚’ void ć«ć™ć‚‹å “åˆć€ BiFunction åž‹ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮3ē•Ŗē›®ć®åž‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫ćÆ Void ć‚’ęŒ‡å®šć—ć¾ć™ć€‚

@SqlProcessor
void process(Integer id, BiFunction<Config, PreparedSql, Void> handler);

ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æĀ¶

BiFunction åž‹ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ悒1恤恮ćæå«ć‚ć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚ BiFunction åž‹ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆSQLćƒ†ćƒ³ćƒ—ćƒ¬ćƒ¼ćƒˆå‡¦ē†å¾Œć®SQLć‚’å‡¦ē†ć™ć‚‹ćŸć‚ć«ä½æć‚ć‚Œć¾ć™ć€‚

ćć®ä»–ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆSQLćƒ†ćƒ³ćƒ—ćƒ¬ćƒ¼ćƒˆć§å‚ē…§ć§ćć¾ć™ć€‚ åŸŗęœ¬ēš„恫ćÆ态 ꤜē“¢ ć®å•ć„åˆć‚ć›ę”ä»¶ć«ęŒ‡å®šć§ćć‚‹ć®ćØåŒć˜åž‹ć‚’ä½æē”Øć§ćć¾ć™ć€‚

利ē”Ø例Ā¶

ä¾‹ćˆć°ć€SQLćƒ†ćƒ³ćƒ—ćƒ¬ćƒ¼ćƒˆć§å‡¦ē†ć—ćŸSQLć‚’ć•ć‚‰ć«å¤‰å½¢ć—ē›“ęŽ„å®Ÿč”Œć™ć‚‹ć“ćØćŒć§ćć¾ć™ć€‚ļ¼ˆć“ć®ä¾‹ć§ćÆ例外処ē†ć‚’ēœē•„ć—ć¦ć„ć¾ć™ć€‚ļ¼‰

EmployeeDao dao = ...
dao.process(1, (config, preparedSql) -> {
  String sql = preparedSql.getRawSql();
  String anotherSql = createAnotherSql(sql);
  DataSource dataSource = config.getDataSource()
  Connection connection = dataSource.getConnection();
  PreparedStatement statement = connection.prepareStatement(anotherSql);
  return statement.execute();
});
select * from employee where id = /*^ id */0

ć‚Æć‚ØćƒŖćƒ“ćƒ«ćƒ€Ā¶

org.seasar.doma.jdbc.builder ćƒ‘ćƒƒć‚±ćƒ¼ć‚ø恧ćÆ态 ćƒ—ćƒ­ć‚°ćƒ©ćƒ ć§SQL悒ēµ„ćæē«‹ć¦ć‚‹ćŸć‚ć®ć‚Æć‚ØćƒŖćƒ“ćƒ«ćƒ€ć‚’ęä¾›ć—ć¦ć„ć¾ć™ć€‚

ä½•ć‚‰ć‹ć®ē†ē”±ć«ć‚ˆć‚Š ć‚Æć‚ØćƒŖ ć®åˆ©ē”ØćŒé›£ć—ć„å “åˆć«ć®ćæ态 ć‚Æć‚ØćƒŖćƒ“ćƒ«ćƒ€ć‚’åˆ©ē”Ø恙悋恓ćØ悒ęŽØå„Øć—ć¾ć™ć€‚ ć¾ćŸć€ć‚Æć‚ØćƒŖćƒ“ćƒ«ćƒ€ćÆ ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆćƒ”ć‚½ćƒƒćƒ‰ 恮äø­ć§ä½æē”Ø恙悋恓ćØ悒ęŽØå„Øć—ć¾ć™ć€‚

恩恮ć‚Æć‚ØćƒŖćƒ“ćƒ«ćƒ€ć‚‚ć€ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ćÆ Config åž‹ć®å¼•ę•°ć‚’ćØ悋 static ćŖ newInstance ćƒ”ć‚½ćƒƒćƒ‰ć§ē”Ÿęˆć§ćć¾ć™ć€‚ ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć«ćÆ态 sql ćƒ”ć‚½ćƒƒćƒ‰ć§SQLę–‡å­—åˆ—ć®ę–­ē‰‡ć‚’态 param ćƒ”ć‚½ćƒƒćƒ‰ćØ literal ćƒ”ć‚½ćƒƒćƒ‰ć§ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćØćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ悒ęø”ć›ć¾ć™ć€‚

param ćƒ”ć‚½ćƒƒćƒ‰ć§ęø”ć•ć‚ŒćŸćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆ PreparedStatement ć®ćƒć‚¤ćƒ³ćƒ‰å¤‰ę•°ćØć—ć¦ę‰±ć‚ć‚Œć¾ć™ć€‚

literal ćƒ”ć‚½ćƒƒćƒ‰ć§ęø”ć•ć‚ŒćŸćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆSQL恫ćƒŖćƒ†ćƒ©ćƒ«ćØć—ć¦åŸ‹ć‚č¾¼ć¾ć‚Œć¾ć™ć€‚ ć“ć®ćƒ”ć‚½ćƒƒćƒ‰ć§ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恌ęø”ć•ć‚ŒćŸå “åˆć€SQLć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³åƾē­–ćØ恗恦恮ć‚Øć‚¹ć‚±ćƒ¼ćƒ—å‡¦ē†ćÆå®Ÿę–½ć•ć‚Œć¾ć›ć‚“ć€‚ 恗恋恗态SQLć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć‚’é˜²ććŸć‚ć«ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®å€¤ć«ć‚·ćƒ³ć‚°ćƒ«ć‚Æć‚©ćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’å«ć‚ć‚‹ć“ćØćÆē¦ę­¢ć—ć¦ć„ć¾ć™ć€‚

ꤜē“¢ć«ćŠć„ć¦ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恮ćƒŖć‚¹ćƒˆć‚’ęø”ć™å “åˆćÆ params ćƒ”ć‚½ćƒƒćƒ‰ćØ literals ćƒ”ć‚½ćƒƒćƒ‰ć‚’åˆ©ē”Øć§ćć¾ć™ć€‚ ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆć‚«ćƒ³ćƒžć§é€£ēµć•ć‚ŒćŸSQLć«å¤‰ę›ć•ć‚Œć¾ć™ć€‚ 恓悌悉ćÆ态IN叄ćØäø€ē·’ć«åˆ©ē”Ø恕悌悋恓ćØć‚’ęƒ³å®šć•ć‚ŒćŸćƒ”ć‚½ćƒƒćƒ‰ć§ć™ć€‚

ꤜē“¢Ā¶

ꤜē“¢ć«ćÆ态 SelectBuilder ć‚Æćƒ©ć‚¹ć‚’ä½æē”Øć—ć¾ć™ć€‚

利ē”Ø例ćÆꬔ恮ćØ恊悊恧恙怂

SelectBuilder builder = SelectBuilder.newInstance(config);
builder.sql("select");
builder.sql("id").sql(",");
builder.sql("name").sql(",");
builder.sql("salary");
builder.sql("from Emp");
builder.sql("where");
builder.sql("job_type = ").literal(String.class, "fulltime");
builder.sql("and");
builder.sql("name like ").param(String.class, "S%");
builder.sql("and");
builder.sql("age in (").params(Integer.class, Arrays.asList(20, 30, 40)).sql(")");
List<Emp> employees = builder.getEntityResultList(Emp.class);

ēµ„ćæē«‹ć¦ćŸSQLć®ć„ćć¤ć‹ć®ę–¹ę³•ć§å–å¾—ć§ćć¾ć™ć€‚

1件取得Ā¶

  • getScalarSingleResult
  • getOptionalScalarSingleResult
  • getEntitySingleResult
  • getOptionalEntitySingleResult
  • getMapSingleResult
  • getOptionalMapSingleResult

č¤‡ę•°ä»¶å–å¾—Ā¶

  • getScalarResultList
  • getOptionalScalarResultList
  • getEntityResultList
  • getMapResultList

ć‚¤ćƒ†ćƒ¬ćƒ¼ćƒˆę¤œē“¢Ā¶

  • iterateAsScalar
  • iterateAsOptionalScalar
  • iterateAsEntity
  • iterateAsMap

ć‚¹ćƒˆćƒŖćƒ¼ćƒ ę¤œē“¢Ā¶

  • streamAsScalar
  • streamAsOptionalScalar
  • streamAsEntity
  • streamAsMap

ęŒæå…„Ā¶

ęŒæå…„ć«ćÆ态 InsertBuilder ć‚Æćƒ©ć‚¹ć‚’ä½æē”Øć—ć¾ć™ć€‚

利ē”Ø例ćÆꬔ恮ćØ恊悊恧恙怂

InsertBuilder builder = InsertBuilder.newInstance(config);
builder.sql("insert into Emp");
builder.sql("(name, salary)");
builder.sql("values (");
builder.param(String.class, "SMITH").sql(", ");
builder.param(BigDecimal.class, new BigDecimal(1000)).sql(")");
builder.execute();

ēµ„ćæē«‹ć¦ćŸSQLćÆ execute ćƒ”ć‚½ćƒƒćƒ‰ć§å®Ÿč”Œć§ćć¾ć™ć€‚

ꛓꖰĀ¶

ꛓꖰ恫ćÆ态 UpdateBuilder ć‚Æćƒ©ć‚¹ć‚’ä½æē”Øć—ć¾ć™ć€‚

利ē”Ø例ćÆꬔ恮ćØ恊悊恧恙怂

UpdateBuilder builder = UpdateBuilder.newInstance(config);
builder.sql("update Emp");
builder.sql("set");
builder.sql("name = ").param(String.class, "SMIHT").sql(",");
builder.sql("salary = ").param(BigDecimal.class, new BigDecimal("1000"));
builder.sql("where");
builder.sql("id = ").param(int.class, 10);
builder.execute();

ēµ„ćæē«‹ć¦ćŸSQLćÆ execute ćƒ”ć‚½ćƒƒćƒ‰ć§å®Ÿč”Œć§ćć¾ć™ć€‚

削除Ā¶

å‰Šé™¤ć«ćÆ态 DeleteBuilder ć‚Æćƒ©ć‚¹ć‚’ä½æē”Øć—ć¾ć™ć€‚

利ē”Ø例ćÆꬔ恮ćØ恊悊恧恙怂

DeleteBuilder builder = DeleteBuilder.newInstance(config);
builder.sql("delete from Emp");
builder.sql("where");
builder.sql("name = ").param(String.class, "SMITH");
builder.sql("and");
builder.sql("salary = ").param(BigDecimal.class, new BigDecimal(1000));
builder.execute();

ēµ„ćæē«‹ć¦ćŸSQLćÆ execute ćƒ”ć‚½ćƒƒćƒ‰ć§å®Ÿč”Œć§ćć¾ć™ć€‚

SQLĀ¶

SQL ćƒ†ćƒ³ćƒ—ćƒ¬ćƒ¼ćƒˆĀ¶

SQL ćÆ SQL ćƒ†ćƒ³ćƒ—ćƒ¬ćƒ¼ćƒˆć‚’ä½æē”Ø恗恦čؘčæ°ć—ć¾ć™ć€‚

SQL ćƒ†ćƒ³ćƒ—ćƒ¬ćƒ¼ćƒˆć®ę–‡ę³•ćÆ SQL ć®ćƒ–ćƒ­ćƒƒć‚Æć‚³ćƒ”ćƒ³ćƒˆ /* */ ć‚’ćƒ™ćƒ¼ć‚¹ć«ć—ćŸć‚‚ć®ć§ 恂悋恟悁1ć¤ć®ćƒ†ćƒ³ćƒ—ćƒ¬ćƒ¼ćƒˆćÆꬔ恮2ć¤ć®ę–¹ę³•ć§ä½æē”Øć§ćć¾ć™ć€‚

  • Doma ć§ćƒ†ćƒ³ćƒ—ćƒ¬ćƒ¼ćƒˆć®ę–‡ę³•ć‚’č§£é‡ˆć—å‹•ēš„恫SQL悒ēµ„ćæē«‹ć¦ć¦å®Ÿč”Œć™ć‚‹
  • SQL ć®ćƒ„ćƒ¼ćƒ«ć§ćƒ†ćƒ³ćƒ—ćƒ¬ćƒ¼ćƒˆć®ę–‡ę³•ćÆć‚³ćƒ”ćƒ³ćƒˆć‚¢ć‚¦ćƒˆć•ć‚ŒćŸć‚‚ć®ćØ恗恦 静ēš„ćŖ SQL ć‚’å®Ÿč”Œć™ć‚‹

恓恮ē‰¹å¾“ćÆ 2-way SQL ćØå‘¼ć°ć‚Œć‚‹ć“ćØćŒć‚ć‚Šć¾ć™ć€‚

SQL ćƒ†ćƒ³ćƒ—ćƒ¬ćƒ¼ćƒˆćÆćƒ•ć‚”ć‚¤ćƒ«ć«čؘčæ°ć—恦Daoć®ćƒ”ć‚½ćƒƒćƒ‰ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć™ć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚

恟ćØ恈恰态 SQL ćƒ•ć‚”ć‚¤ćƒ«ć«ćÆę¬”ć®ć‚ˆć†ćŖ SQL ćƒ†ćƒ³ćƒ—ćƒ¬ćƒ¼ćƒˆć‚’ę ¼ē“ć—ć¾ć™ć€‚

select * from employee where employee_id = /* employeeId */99

恓恓恧ćÆ态惖惭惃ć‚Æć‚³ćƒ”ćƒ³ćƒˆć§å›²ć¾ć‚ŒćŸ employeeId 恌Daoć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć®ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恫åƾåæœć—态 ē›“å¾Œć® 99 ćÆćƒ†ć‚¹ćƒˆē”Øć®ćƒ‡ćƒ¼ć‚æ恫ćŖć‚Šć¾ć™ć€‚ ćƒ†ć‚¹ćƒˆē”Øć®ćƒ‡ćƒ¼ć‚æćÆ态 Doma ć«č§£é‡ˆć•ć‚Œć¦å®Ÿč”Œć•ć‚Œć‚‹å “åˆć«ćÆä½æē”Øć•ć‚Œć¾ć›ć‚“ć€‚ SQL ć®ćƒ„ćƒ¼ćƒ«ć«ć‚ˆć‚‹é™ēš„ćŖå®Ÿč”Œę™‚ć«ć®ćæä½æē”Øć•ć‚Œć¾ć™ć€‚

åƾåæœć™ć‚‹Daoć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć®ćƒ”ć‚½ćƒƒćƒ‰ćÆꬔ恮ćØ恊悊恧恙怂

Employee selectById(employeeId);

ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³Ā¶

SQLćƒ•ć‚”ć‚¤ćƒ«ćØDaoć®ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒžćƒƒćƒ”ćƒ³ć‚°ćÆę¬”ć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć§ē¤ŗć—ć¾ć™ć€‚

  • @Select
  • @Insert(sqlFile = true)
  • @Update(sqlFile = true)
  • @Delete(sqlFile = true)
  • @BatchInsert(sqlFile = true)
  • @BatchUpdate(sqlFile = true)
  • @BatchDelete(sqlFile = true)

SQLćƒ•ć‚”ć‚¤ćƒ«Ā¶

ć‚Øćƒ³ć‚³ćƒ¼ćƒ‡ć‚£ćƒ³ć‚°Ā¶

SQLćƒ•ć‚”ć‚¤ćƒ«ć®ć‚Øćƒ³ć‚³ćƒ¼ćƒ‡ć‚£ćƒ³ć‚°ćÆUTF-8恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

配ē½®å “ꉀĀ¶

SQLćƒ•ć‚”ć‚¤ćƒ«ćÆć‚Æćƒ©ć‚¹ćƒ‘ć‚¹ćŒé€šć£ćŸ META-INF ćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖ仄äø‹ć«é…ē½®ć—ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

ćƒ•ć‚”ć‚¤ćƒ«åć®å½¢å¼Ā¶

ćƒ•ć‚”ć‚¤ćƒ«åćÆć€ę¬”ć®å½¢å¼ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

META-INF/Dao恮ć‚Æćƒ©ć‚¹ć®å®Œå…Øäæ®é£¾åć‚’ćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖć«å¤‰ę›ć—ćŸć‚‚ć®/Daoć®ćƒ”ć‚½ćƒƒćƒ‰å.sql

ä¾‹ćˆć°ć€ Dao恮ć‚Æćƒ©ć‚¹ćŒ aaa.bbb.EmployeeDao ć§ćƒžćƒƒćƒ”ćƒ³ć‚°ć—ćŸć„ćƒ”ć‚½ćƒƒćƒ‰ćŒ selectById ć®å “åˆć€ćƒ‘ć‚¹åćÆę¬”ć®ć‚ˆć†ć«ćŖć‚Šć¾ć™ć€‚

META-INF/aaa/bbb/EmployeeDao/selectById.sql

複ꕰ恮 RDBMS 悒ä½æē”Ø恙悋ē’°å¢ƒäø‹ć§ē‰¹å®šć® RDBMS 恧ćÆåˆ„ć® SQL ćƒ•ć‚”ć‚¤ćƒ«ć‚’ä½æć„ćŸć„å “åˆć€ ę‹”å¼µå­ .sql ć®å‰ć«ćƒć‚¤ćƒ•ćƒ³åŒŗåˆ‡ć‚Šć§ RDBMS åć‚’å…„ć‚Œć‚‹ć“ćØ恧态 å„Ŗ先ēš„恫ä½æē”Øć™ć‚‹ćƒ•ć‚”ć‚¤ćƒ«ć‚’ęŒ‡ē¤ŗć§ćć¾ć™ć€‚ 恟ćØ恈恰态PostgreSQL専ē”Ø恮SQLćƒ•ć‚”ć‚¤ćƒ«ćÆę¬”ć®åå‰ć«ć—ć¾ć™ć€‚

META-INF/aaa/bbb/EmployeeDao/selectById-postgres.sql

ć“ć®ä¾‹ć§ćÆPostgreSQL悒ä½æē”Øć—ć¦ć„ć‚‹å “åˆć«é™ć‚Šć€ META-INF/aaa/bbb/EmployeeDao/selectById.sql 悈悊悂 META-INF/aaa/bbb/EmployeeDao/selectById-postgres.sql 恌å„Ŗ先ēš„恫ä½æē”Øć•ć‚Œć¾ć™ć€‚

RDBMS 名ćÆ态 Dialect 恮 getName ćƒ”ć‚½ćƒƒćƒ‰ć®å€¤ćŒä½æē”Øć•ć‚Œć¾ć™ć€‚ 恂悉恋恘悁ē”Øꄏ恕悌恟 Dialect ć«ć¤ć„ć¦ćć‚Œćžć‚Œć® RDBMS åć‚’ä»„äø‹ć®č”Ø恫ē¤ŗć—ć¾ć™ć€‚

ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ Dialect RDBMS 名
DB2 Db2Dialect db2
H2 Database Engine 1.2.126 H212126Dialect h2
H2 Database H2Dialect h2
HSQLDB HsqldbDialect hsqldb
Microsoft SQL Server 2008 Mssql2008Dialect mssql
Microsoft SQL Server MssqlDialect mssql
MySQL MySqlDialect mysql
Oracle Database OracleDialect oracle
PostgreSQL PostgresDialect postgres
SQLite SqliteDialect sqlite

SQL ć‚³ćƒ”ćƒ³ćƒˆĀ¶

SQL ć‚³ćƒ”ćƒ³ćƒˆäø­ć«å¼ć‚’čؘčæ°ć™ć‚‹ć“ćØć§å€¤ć®ćƒć‚¤ćƒ³ćƒ‡ć‚£ćƒ³ć‚°ć‚„ę”ä»¶åˆ†å²ć‚’č”Œć„ć¾ć™ć€‚ Doma ć«č§£é‡ˆć•ć‚Œć‚‹SQLć‚³ćƒ”ćƒ³ćƒˆć‚’ å¼ć‚³ćƒ”ćƒ³ćƒˆ ćØå‘¼ć³ć¾ć™ć€‚

å¼ć‚³ćƒ”ćƒ³ćƒˆć«ćÆ仄äø‹ć®ć‚‚ć®ćŒć‚ć‚Šć¾ć™ć€‚

ćƒŽćƒ¼ćƒˆ

å¼ć‚³ćƒ”ćƒ³ćƒˆć«čؘčæ°ć§ćć‚‹å¼ć®ę–‡ę³•ć«ć¤ć„恦ćÆ 式č؀čŖž ć‚’å‚ē…§ć—ć¦ćć ć•ć„ć€‚

ćƒć‚¤ćƒ³ćƒ‰å¤‰ę•°ć‚³ćƒ”ćƒ³ćƒˆĀ¶

ćƒć‚¤ćƒ³ćƒ‰å¤‰ę•°ć‚’ē¤ŗć™å¼ć‚³ćƒ”ćƒ³ćƒˆć‚’ ćƒć‚¤ćƒ³ćƒ‰å¤‰ę•° ć‚³ćƒ”ćƒ³ćƒˆćØå‘¼ć³ć¾ć™ć€‚ ćƒć‚¤ćƒ³ćƒ‰å¤‰ę•°ćÆ态 java.sql.PreparedStatement 悒介恗恦SQL恫čØ­å®šć•ć‚Œć¾ć™ć€‚

ćƒć‚¤ćƒ³ćƒ‰å¤‰ę•°ćÆ /*ļ½ž*/ ćØ恄恆惖惭惃ć‚Æć‚³ćƒ”ćƒ³ćƒˆć§å›²ć‚“ć§ē¤ŗć—ć¾ć™ć€‚ ćƒć‚¤ćƒ³ćƒ‰å¤‰ę•°ć®åå‰ćÆDaoćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æåć«åƾåæœć—ć¾ć™ć€‚ åƾåæœć™ć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆ åŸŗęœ¬åž‹ 悂恗恏ćÆ ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ćƒć‚¤ćƒ³ćƒ‰å¤‰ę•°ć‚³ćƒ”ćƒ³ćƒˆć®ē›“å¾Œć«ćÆćƒ†ć‚¹ćƒˆē”Øćƒ‡ćƒ¼ć‚æć‚’ęŒ‡å®šć™ć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚ ćŸć ć—ć€ćƒ†ć‚¹ćƒˆē”Øćƒ‡ćƒ¼ć‚æćÆå®Ÿč”Œę™‚ć«ćÆä½æē”Øć•ć‚Œć¾ć›ć‚“ć€‚

åŸŗęœ¬åž‹ć‚‚ć—ććÆćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹åž‹ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æĀ¶

Dao ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć®ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恌 åŸŗęœ¬åž‹ 悂恗恏ćÆ ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ ć®å “åˆć€ ć“ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆ1ć¤ć®ćƒć‚¤ćƒ³ćƒ‰å¤‰ę•°ć‚’č”Øē¾ć§ćć¾ć™ć€‚ ćƒć‚¤ćƒ³ćƒ‰å¤‰ę•°ć‚³ćƒ”ćƒ³ćƒˆćÆćƒć‚¤ćƒ³ćƒ‰å¤‰ę•°ć‚’åŸ‹ć‚č¾¼ćæćŸć„å “ę‰€ć«čؘčæ°ć—态 ćƒć‚¤ćƒ³ćƒ‰å¤‰ę•°ć‚³ćƒ”ćƒ³ćƒˆć®ē›“å¾Œć«ćÆćƒ†ć‚¹ćƒˆē”Øćƒ‡ćƒ¼ć‚æć‚’ęŒ‡å®šć—ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ Dao ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć®ćƒ”ć‚½ćƒƒćƒ‰ćØåƾåæœć™ć‚‹ SQL ć®ä¾‹ćÆꬔ恮ćØ恊悊恧恙怂

Employee selectById(Integer employeeId);
select * from employee where employee_id = /* employeeId */99
Iterableåž‹ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æĀ¶

Dao ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć®ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恌 java.lang.Iterable ć®ć‚µćƒ–ć‚æć‚¤ćƒ—ć®å “åˆć€ ć“ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆ态 INå„å†…ć®č¤‡ę•°ć®ćƒć‚¤ćƒ³ćƒ‰å¤‰ę•°ć‚’č”Øē¾ć§ćć¾ć™ć€‚ 恟恠恗态 java.lang.Iterable ć®ć‚µćƒ–ć‚æć‚¤ćƒ—ć®å®Ÿåž‹å¼•ę•°ćÆ åŸŗęœ¬åž‹ 悂恗恏ćÆ ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ćƒć‚¤ćƒ³ćƒ‰å¤‰ę•°ć‚³ćƒ”ćƒ³ćƒˆćÆINć‚­ćƒ¼ćƒÆćƒ¼ćƒ‰ć®ē›“å¾Œć«ē½®ćć€ ćƒć‚¤ćƒ³ćƒ‰å¤‰ę•°ć‚³ćƒ”ćƒ³ćƒˆć®ē›“å¾Œć«ćÆę‹¬å¼§ć¤ćć§ćƒ†ć‚¹ćƒˆē”Øćƒ‡ćƒ¼ć‚æć‚’ęŒ‡å®šć—ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ Dao ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć®ćƒ”ć‚½ćƒƒćƒ‰ćØåƾåæœć™ć‚‹ SQL ć®ä¾‹ćÆꬔ恮ćØ恊悊恧恙怂

List<Employee> selectByIdList(List<Integer> employeeIdList);
select * from employee where employee_id in /* employeeIdList */(1,2,3)

Iterable 恌ē©ŗ恧恂悋ćØ恍态INå„ć®ę‹¬å¼§å†…ć®å€¤ćÆ null 恫ćŖć‚Šć¾ć™ć€‚

select * from employee where employee_id in (null)
ä»»ę„ć®åž‹ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æĀ¶

Dao ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć®ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æ恌 åŸŗęœ¬åž‹ 悂恗恏ćÆ ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ 恧ćŖć„å “åˆć€ ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćÆč¤‡ę•°ć®ćƒć‚¤ćƒ³ćƒ‰å¤‰ę•°ć‚³ćƒ”ćƒ³ćƒˆć«åƾåæœć—ć¾ć™ć€‚ ćƒć‚¤ćƒ³ćƒ‰å¤‰ę•°ć‚³ćƒ”ćƒ³ćƒˆć®äø­ć§ćÆ态惉惃惈 . 悒ä½æē”Øć—ä»»ę„ć®åž‹ć®ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć‚„ćƒ”ć‚½ćƒƒćƒ‰ć«ć‚¢ć‚Æć‚»ć‚¹ć§ćć¾ć™ć€‚ Dao ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć®ćƒ”ć‚½ćƒƒćƒ‰ćØåƾåæœć™ć‚‹ SQL ć®ä¾‹ćÆꬔ恮ćØ恊悊恧恙怂

EmployeeDto ć‚Æćƒ©ć‚¹ć«ćÆ态 employeeName ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć‚„ salary ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ćŒå­˜åœØ恙悋悂恮ćØć—ć¾ć™ć€‚

List<Employee> selectByNameAndSalary(EmployeeDto dto);
select * from employee
where
employee_name = /* dto.employeeName */'abc'
and
salary = /* dto.salary */1234

ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć«ć‚¢ć‚Æć‚»ć‚¹ć™ć‚‹ä»£ć‚ć‚Šć« public ćŖćƒ”ć‚½ćƒƒćƒ‰ć‚’å‘¼ć³å‡ŗ恙恓ćØ悂åÆčƒ½ć§ć™ć€‚

select * from employee
where
salary = /* dto.getTaxedSalary() */1234

ćƒŖćƒ†ćƒ©ćƒ«å¤‰ę•°ć‚³ćƒ”ćƒ³ćƒˆĀ¶

ćƒŖćƒ†ćƒ©ćƒ«å¤‰ę•°ć‚’ē¤ŗć™å¼ć‚³ćƒ”ćƒ³ćƒˆć‚’ ćƒŖćƒ†ćƒ©ćƒ«å¤‰ę•° ć‚³ćƒ”ćƒ³ćƒˆćØå‘¼ć³ć¾ć™ć€‚ ćƒŖćƒ†ćƒ©ćƒ«å¤‰ę•°ćÆ态 SQL恮ćƒŖćƒ†ćƒ©ćƒ«ć®å½¢å¼ć«å¤‰ę›ć•ć‚ŒćŸå¾Œć«SQLć«åŸ‹ć‚č¾¼ć¾ć‚Œć¾ć™ć€‚ ćƒŖćƒ†ćƒ©ćƒ«ć®å½¢å¼ć«å¤‰ę›ćØćÆć€ę–‡å­—åˆ—åž‹ć‚’ć‚·ćƒ³ć‚°ćƒ«ć‚Æć‚©ćƒ¼ćƒˆć§å›²ć‚€ćŖć©ć‚’ęŒ‡ć—ć¾ć™ć€‚ ć“ć®å¤‰ę›ć«ćÆSQLć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³åƾē­–ćØ恗恦恮ć‚Øć‚¹ć‚±ćƒ¼ćƒ—å‡¦ē†ćÆå«ć¾ć‚Œć¾ć›ć‚“ć€‚

SQL ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć‚’é˜²ććŸć‚ć€ćƒŖćƒ†ćƒ©ćƒ«å¤‰ę•°ć®å€¤ć«ć‚·ćƒ³ć‚°ćƒ«ć‚Æć‚©ćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’å«ć‚ć‚‹ć“ćØćÆē¦ę­¢ć—ć¦ć„ć¾ć™ć€‚

ćƒŖćƒ†ćƒ©ćƒ«å¤‰ę•°ćÆ /*^ļ½ž*/ ćØ恄恆惖惭惃ć‚Æć‚³ćƒ”ćƒ³ćƒˆć§å›²ć‚“ć§ē¤ŗć—ć¾ć™ć€‚ ćƒŖćƒ†ćƒ©ćƒ«å¤‰ę•°ć®åå‰ćÆDaoćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æåć«åƾåæœć—ć¾ć™ć€‚ åƾåæœć™ć‚‹ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć®åž‹ćÆ åŸŗęœ¬åž‹ 悂恗恏ćÆ ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ 恧ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ćƒŖćƒ†ćƒ©ćƒ«å¤‰ę•°ć‚³ćƒ”ćƒ³ćƒˆć®ē›“å¾Œć«ćÆćƒ†ć‚¹ćƒˆē”Øćƒ‡ćƒ¼ć‚æć‚’ęŒ‡å®šć™ć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚ ćŸć ć—ć€ćƒ†ć‚¹ćƒˆē”Øćƒ‡ćƒ¼ć‚æćÆå®Ÿč”Œę™‚ć«ćÆä½æē”Øć•ć‚Œć¾ć›ć‚“ć€‚

Dao ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć®ćƒ”ć‚½ćƒƒćƒ‰ćØåƾåæœć™ć‚‹ SQL ć®ä¾‹ćÆꬔ恮ćØ恊悊恧恙怂

Employee selectByCode(String code);
select * from employee where code = /*^ code */'test'

Dao ć®å‘¼ć³å‡ŗć—ä¾‹ćÆꬔ恮通悊恧恙怂

EmployeeDao dao = new EmployeeDaoImpl();
List<Employee> list = dao.selectByCode("abc");

ē™ŗč”Œć•ć‚Œć‚‹ SQL ćÆę¬”ć®ć‚ˆć†ć«ćŖć‚Šć¾ć™ć€‚

select * from employee where code = 'abc'

čØ˜ę³•ćŒē•°ćŖ悋恓ćØ悒除恑恰态ä½æć„ę–¹ćÆćƒć‚¤ćƒ³ćƒ‰å¤‰ę•°ć‚³ćƒ”ćƒ³ćƒˆćØåŒę§˜ć§ć™ć€‚

ćƒŽćƒ¼ćƒˆ

ćƒŖćƒ†ćƒ©ćƒ«å¤‰ę•°ć‚³ćƒ”ćƒ³ćƒˆćÆć€å®Ÿč”Œč؈ē”»ć‚’å›ŗå®šć™ć‚‹ćŖć©ć‚ćˆć¦ćƒć‚¤ćƒ³ćƒ‰å¤‰ę•°ć®ä½æē”Ø悒éæć‘ćŸć„å “åˆć«åˆ©ē”Øć§ćć¾ć™ć€‚

åŸ‹ć‚č¾¼ćæå¤‰ę•°ć‚³ćƒ”ćƒ³ćƒˆĀ¶

åŸ‹ć‚č¾¼ćæå¤‰ę•°ć‚’ē¤ŗć™å¼ć‚³ćƒ”ćƒ³ćƒˆć‚’ åŸ‹ć‚č¾¼ćæå¤‰ę•° ć‚³ćƒ”ćƒ³ćƒˆćØå‘¼ć³ć¾ć™ć€‚ åŸ‹ć‚č¾¼ćæå¤‰ę•°ć®å€¤ćÆ SQL 悒ēµ„ćæē«‹ć¦ć‚‹éš›ć« SQL 恮äø€éƒØćØ恗恦ē›“ęŽ„åŸ‹ć‚č¾¼ć¾ć‚Œć¾ć™ć€‚

SQL ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć‚’é˜²ććŸć‚ć€åŸ‹ć‚č¾¼ćæå¤‰ę•°ć®å€¤ć«ä»„äø‹ć®å€¤ć‚’å«ć‚ć‚‹ć“ćØćÆē¦ę­¢ć—ć¦ć„ć¾ć™ć€‚

  • ć‚·ćƒ³ć‚°ćƒ«ć‚Æć‚©ćƒ†ćƒ¼ć‚·ćƒ§ćƒ³
  • ć‚»ćƒŸć‚³ćƒ­ćƒ³
  • č”Œć‚³ćƒ”ćƒ³ćƒˆ
  • 惖惭惃ć‚Æć‚³ćƒ”ćƒ³ćƒˆ

åŸ‹ć‚č¾¼ćæå¤‰ę•°ćÆ /*#ļ½ž*/ ćØ恄恆惖惭惃ć‚Æć‚³ćƒ”ćƒ³ćƒˆć§ē¤ŗć—ć¾ć™ć€‚ åŸ‹ć‚č¾¼ćæå¤‰ę•°ć®åå‰ćÆ Dao ćƒ”ć‚½ćƒƒćƒ‰ć®ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æåć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć•ć‚Œć¾ć™ć€‚

Dao ć®ćƒ”ć‚½ćƒƒćƒ‰ćØåƾåæœć™ć‚‹ SQL ć®ä¾‹ćÆꬔ恮ćØ恊悊恧恙怂

List<Employee> selectAll(BigDecimal salary, String orderyBy);
select * from employee where salary > /* salary */100 /*# orderBy */

Dao ć®å‘¼ć³å‡ŗć—ä¾‹ćÆꬔ恮通悊恧恙怂

EmployeeDao dao = new EmployeeDaoImpl();
BigDecimal salary = new BigDecimal(1000);
String orderBy = "order by salary asc, employee_name";
List<Employee> list = dao.selectAll(salary, orderBy);

ē™ŗč”Œć•ć‚Œć‚‹ SQL ćÆę¬”ć®ć‚ˆć†ć«ćŖć‚Šć¾ć™ć€‚

select * from employee where salary > ? order by salary asc, employee_name

ćƒŽćƒ¼ćƒˆ

åŸ‹ć‚č¾¼ćæå¤‰ę•°ć‚³ćƒ”ćƒ³ćƒˆćÆ态 ORDER BY 叄ćŖ恩 SQL 恮äø€éƒØć‚’ćƒ—ćƒ­ć‚°ćƒ©ćƒ ć§ēµ„ćæē«‹ć¦ćŸć„å “åˆć«ä½æē”Øć§ćć¾ć™ć€‚

ę”ä»¶ć‚³ćƒ”ćƒ³ćƒˆĀ¶

ifćØendĀ¶

ę”ä»¶åˆ†å²ć‚’ē¤ŗć™å¼ć‚³ćƒ”ćƒ³ćƒˆć‚’ę”ä»¶ć‚³ćƒ”ćƒ³ćƒˆćØå‘¼ć³ć¾ć™ć€‚ ꧋ꖇćÆꬔ恮ćØ恊悊恧恙怂

/*%if ę”ä»¶å¼*/ ļ½ž /*%end*/

ę”ä»¶å¼ćÆēµęžœćŒ boolean 悂恗恏ćÆ java.lang.Boolean 型ćØč©•ä¾”ć•ć‚Œć‚‹å¼ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ä¾‹ć‚’ē¤ŗć—ć¾ć™ć€‚

select * from employee where
/*%if employeeId != null */
    employee_id = /* employeeId */99
/*%end*/

äøŠčØ˜ć® SQL ꖇćÆ employeeId 恌 null 恧ćŖć„å “åˆć€ ę¬”ć®ć‚ˆć†ćŖęŗ–å‚™ć•ć‚ŒćŸę–‡ć«å¤‰ę›ć•ć‚Œć¾ć™ć€‚

select * from employee where employee_id = ?

恓恮 SQL ꖇćÆ employeeId 恌 null ć®å “åˆć«ę¬”ć®ć‚ˆć†ćŖęŗ–å‚™ć•ć‚ŒćŸę–‡ć«å¤‰ę›ć•ć‚Œć¾ć™ć€‚

select * from employee

if ć®ę”ä»¶ćŒęˆć‚Šē«‹ćŸćŖć„å “åˆć« if ć®å¤–ć«ć‚ć‚‹ WHEREå„ćŒå‡ŗåŠ›ć•ć‚ŒćŖ恄恮ćÆ态 ę”ä»¶ć‚³ćƒ”ćƒ³ćƒˆć«ćŠć‘ć‚‹WHERE悄HAVING恮č‡Ŗ動除去 ę©Ÿčƒ½ćŒåƒć„ć¦ć„ć‚‹ćŸć‚ć§ć™ć€‚

ę”ä»¶ć‚³ćƒ”ćƒ³ćƒˆć«ćŠć‘ć‚‹WHERE悄HAVING恮č‡Ŗ動除去Ā¶

ę”ä»¶ć‚³ćƒ”ćƒ³ćƒˆć‚’ä½æē”Øć—ćŸå “åˆć€ę”ä»¶ć®å‰ć«ć‚ć‚‹ WHERE 悄 HAVING 恫恤恄恦č‡Ŗå‹•ć§å‡ŗåŠ›ć®č¦/äøč¦ć‚’åˆ¤å®šć—ć¾ć™ć€‚ 恟ćØćˆć°ć€ę¬”ć®ć‚ˆć†ćŖSQL恧 employeeId 恌 null ć®å “åˆć€

select * from employee where
/*%if employeeId != null */
    employee_id = /* employeeId */99
/*%end*/

/*%if ļ½ž*/ ć®å‰ć® where ćÆč‡Ŗå‹•ć§é™¤åŽ»ć•ć‚Œć€ę¬”ć®SQL恌ē”Ÿęˆć•ć‚Œć¾ć™ć€‚

select * from employee
ę”ä»¶ć‚³ćƒ”ćƒ³ćƒˆć«ćŠć‘ć‚‹AND悄OR恮č‡Ŗ動除去Ā¶

ę”ä»¶ć‚³ćƒ”ćƒ³ćƒˆć‚’ä½æē”Øć—ćŸå “åˆć€ę”ä»¶ć®å¾Œć‚ć«ć¤ć„ć AND 悄 OR 恫恤恄恦č‡Ŗå‹•ć§å‡ŗåŠ›ć®č¦/äøč¦ć‚’åˆ¤å®šć—ć¾ć™ć€‚ 恟ćØćˆć°ć€ę¬”ć®ć‚ˆć†ćŖSQL恧 employeeId 恌 null ć®å “åˆć€

select * from employee where
/*%if employeeId != null */
    employee_id = /* employeeId */99
/*%end*/
and employeeName like 's%'

/*%end*/ ć®å¾Œć‚ć® and ćÆč‡Ŗå‹•ć§é™¤åŽ»ć•ć‚Œć€ę¬”ć® SQL 恌ē”Ÿęˆć•ć‚Œć¾ć™ć€‚

select * from employee where employeeName like 's%'
elseifćØelseĀ¶

/*%if ę”ä»¶å¼*/ ćØ /*%end*/ 恮間恧ćÆ态 elseif 悄 else 悒č”Ø恙ꬔ恮꧋ꖇ悂ä½æē”Øć§ćć¾ć™ć€‚

  • /*%elseif ę”ä»¶å¼*/
  • /*%else*/

ä¾‹ć‚’ē¤ŗć—ć¾ć™ć€‚

select
  *
from
  employee
where
/*%if employeeId != null */
  employee_id = /* employeeId */9999
/*%elseif department_id != null */
  and
  department_id = /* departmentId */99
/*%else*/
  and
  department_id is null
/*%end*/

äøŠć® SQL ćÆ态 employeeId != null 恌ꈐē«‹ć™ć‚‹ćØćå®Ÿéš›ćÆꬔ恮 SQL ć«å¤‰ę›ć•ć‚Œć¾ć™ć€‚

select
  *
from
  employee
where
  employee_id = ?

employeeId == null && department_id != null 恌ꈐē«‹ć™ć‚‹ćØćć€å®Ÿéš›ćÆꬔ恮 SQL ć«å¤‰ę›ć•ć‚Œć¾ć™ć€‚ department_id 恮ē›“å‰ć® AND ćÆč‡Ŗå‹•ć§é™¤åŽ»ć•ć‚Œć‚‹ćŸć‚å‡ŗåŠ›ć•ć‚Œć¾ć›ć‚“ć€‚

select
  *
from
  employee
where
  department_id = ?

employeeId == null && department_id == null 恌ꈐē«‹ć™ć‚‹ćØćć€å®Ÿéš›ćÆꬔ恮 SQL ć«å¤‰ę›ć•ć‚Œć¾ć™ć€‚ department_id 恮ē›“å‰ć® AND ćÆč‡Ŗå‹•ć§é™¤åŽ»ć•ć‚Œć‚‹ćŸć‚å‡ŗåŠ›ć•ć‚Œć¾ć›ć‚“ć€‚

select
  *
from
  employee
where
  department_id is null
ćƒć‚¹ćƒˆć—ćŸę”ä»¶ć‚³ćƒ”ćƒ³ćƒˆĀ¶

ę”ä»¶ć‚³ćƒ”ćƒ³ćƒˆćÆćƒć‚¹ćƒˆć•ć›ć‚‹ć“ćØćŒć§ćć¾ć™ć€‚

select * from employee where
/*%if employeeId != null */
  employee_id = /* employeeId */99
  /*%if employeeName != null */
    and
    employee_name = /* employeeName */'hoge'
  /*%else*/
    and
    employee_name is null
  /*%end*/
/*%end*/
ę”ä»¶ć‚³ćƒ”ćƒ³ćƒˆć«ćŠć‘ć‚‹åˆ¶ē“„Ā¶

ę”ä»¶ć‚³ćƒ”ćƒ³ćƒˆć® if ćØ end ćÆSQLć®åŒć˜ēÆ€ć«å«ć¾ć‚ŒćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ēƀćØćÆ态 SELECTēÆ€ć€FROMēÆ€ć€WHEREēÆ€ć€GROUP BYēÆ€ć€HAVINGēÆ€ć€ORDER BYēƀćŖ恩恧恙怂 ę¬”ć®ä¾‹ć§ćÆ态 if 恌FROMēÆ€ć«ć‚ć‚Š end 恌WHEREēÆ€ć«ć‚ć‚‹ćŸć‚äøę­£ć§ć™ć€‚

select * from employee /*%if employeeId != null */
where employee_id = /* employeeId */99 /*%end*/

ć¾ćŸć€ if ćØ end ćÆåŒć˜ćƒ¬ćƒ™ćƒ«ć®ę–‡ć«å«ć¾ć‚ŒćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ę¬”ć®ä¾‹ć§ćÆ态 if ćŒę‹¬å¼§ć®å¤–ć«ć‚ć‚ŠendćŒę‹¬å¼§ć®å†…å“ć«ć‚ć‚‹ć®ć§äøę­£ć§ć™ć€‚

select * from employee
where employee_id in /*%if departmentId != null */(...  /*%end*/ ...)

ē¹°ć‚Ščæ”ć—ć‚³ćƒ”ćƒ³ćƒˆĀ¶

forćØendĀ¶

ē¹°ć‚Ščæ”恗悒ē¤ŗć™å¼ć‚³ćƒ”ćƒ³ćƒˆć‚’ē¹°ć‚Ščæ”ć—ć‚³ćƒ”ćƒ³ćƒˆćØå‘¼ć³ć¾ć™ć€‚ ꧋ꖇćÆꬔ恮ćØ恊悊恧恙怂

/*%for č­˜åˆ„å­ : 式*/ ļ½ž /*%end*/

č­˜åˆ„å­ćÆ态ē¹°ć‚Ščæ”ć•ć‚Œć‚‹č¦ē“ ć‚’ęŒ‡ć™å¤‰ę•°ć§ć™ć€‚ 式ćÆ java.lang.Iterable 型ćØć—ć¦č©•ä¾”ć•ć‚Œć‚‹å¼ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ä¾‹ć‚’ē¤ŗć—ć¾ć™ć€‚

select * from employee where
/*%for name : names */
employee_name like /* name */'hoge'
  /*%if name_has_next */
/*# "or" */
  /*%end */
/*%end*/

äøŠčØ˜ć® SQL ꖇćÆ态 names 恌3恤恮要ē“ ć‹ć‚‰ćŖ悋ćƒŖć‚¹ćƒˆć‚’č”Øć™å “åˆć€ę¬”ć®ć‚ˆć†ćŖęŗ–å‚™ć•ć‚ŒćŸę–‡ć«å¤‰ę›ć•ć‚Œć¾ć™ć€‚

select * from employee where
employee_name like ?
or
employee_name like ?
or
employee_name like ?
item_has_nextćØitem_indexĀ¶

/*%for č­˜åˆ„å­ : 式*/ 恋悉 /*%end*/ ć¾ć§ć®å†…å“ć§ćÆꬔ恮2恤恮ē‰¹åˆ„ćŖå¤‰ę•°ć‚’ä½æē”Øć§ćć¾ć™ć€‚

  • item_has_next
  • item_index

ęŽ„é ­č¾žć® item ćÆč­˜åˆ„å­ć‚’č”Øć—ć¾ć™ć€‚ć¤ć¾ć‚Šć€ for ć®č­˜åˆ„å­ćŒ name ć®å “åˆ ć“ć®å¤‰ę•°ćÆ恝悌恞悌 name_has_next ćØ name_index ćØćŖć‚Šć¾ć™ć€‚

item_has_next ćÆꬔ恮ē¹°ć‚Ščæ”恗要ē“ ćŒå­˜åœØ恙悋恋恩恆恋悒ē¤ŗ恙 boolean ć®å€¤ć§ć™ć€‚

item_index ćÆē¹°ć‚Ščæ”恗恮index悒č”Ø恙 int ć®å€¤ć§ć™ć€‚å€¤ćÆ0å§‹ć¾ć‚Šć§ć™ć€‚

ē¹°ć‚Ščæ”ć—ć‚³ćƒ”ćƒ³ćƒˆć«ćŠć‘ć‚‹WHERE悄HAVING恮č‡Ŗ動除去Ā¶

ē¹°ć‚Ščæ”ć—ć‚³ćƒ”ćƒ³ćƒˆć‚’ä½æē”Øć—ćŸå “åˆć€ć‚³ćƒ”ćƒ³ćƒˆć®å‰ć«ć‚ć‚‹ WHERE 悄 HAVING 恫恤恄恦č‡Ŗå‹•ć§å‡ŗåŠ›ć®č¦/äøč¦ć‚’åˆ¤å®šć—ć¾ć™ć€‚ 恟ćØćˆć°ć€ę¬”ć®ć‚ˆć†ćŖ SQL 恧 names 恮 size 恌 0 ć®å “åˆļ¼ˆē¹°ć‚Ščæ”ć—ćŒč”Œć‚ć‚ŒćŖć„å “åˆļ¼‰ć€

select * from employee where
/*%for name : names */
employee_name like /* name */'hoge'
  /*%if name_has_next */
/*# "or" */
  /*%end */
/*%end*/

/*%for ļ½ž*/ ć®å‰ć® where ćÆč‡Ŗå‹•ć§é™¤åŽ»ć•ć‚Œć€ę¬”ć® SQL 恌ē”Ÿęˆć•ć‚Œć¾ć™ć€‚

select * from employee
ē¹°ć‚Ščæ”ć—ć‚³ćƒ”ćƒ³ćƒˆć«ćŠć‘ć‚‹AND悄OR恮č‡Ŗ動除去Ā¶

ē¹°ć‚Ščæ”ć—ć‚³ćƒ”ćƒ³ćƒˆć‚’ä½æē”Øć—ćŸå “åˆć€ć‚³ćƒ”ćƒ³ćƒˆć®å¾Œć‚ć«ć¤ć„ć AND 悄 OR 恫恤恄恦č‡Ŗå‹•ć§å‡ŗåŠ›ć®č¦/äøč¦ć‚’åˆ¤å®šć—ć¾ć™ć€‚ 恟ćØćˆć°ć€ę¬”ć®ć‚ˆć†ćŖ SQL 恧 names 恮 size 恌 0 ć®å “åˆļ¼ˆē¹°ć‚Ščæ”ć—ćŒč”Œć‚ć‚ŒćŖć„å “åˆļ¼‰ć€

select * from employee where
/*%for name : names */
employee_name like /* name */'hoge'
  /*%if name_has_next */
/*# "or" */
  /*%end */
/*%end*/
or
salary > 1000

/*%end*/ ć®å¾Œć‚ć® or ćÆč‡Ŗå‹•ć§é™¤åŽ»ć•ć‚Œć€ę¬”ć®SQL恌ē”Ÿęˆć•ć‚Œć¾ć™ć€‚

select * from employee where salary > 1000
ē¹°ć‚Ščæ”ć—ć‚³ćƒ”ćƒ³ćƒˆć«ćŠć‘ć‚‹åˆ¶ē“„Ā¶

ē¹°ć‚Ščæ”ć—ć‚³ćƒ”ćƒ³ćƒˆć® for ćØ end ćÆ SQL ć®åŒć˜ēÆ€ć«å«ć¾ć‚ŒćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ēƀćØćÆ态SELECTēÆ€ć€FROMēÆ€ć€WHEREēÆ€ć€GROUP BYēÆ€ć€HAVINGēÆ€ć€ORDER BYēƀćŖ恩恧恙怂

ć¾ćŸć€ for ćØ end ćÆåŒć˜ćƒ¬ćƒ™ćƒ«ć®ę–‡ć«å«ć¾ć‚ŒćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ć¤ć¾ć‚Šć€ę‹¬å¼§ć®å¤–ć§ for ć€ę‹¬å¼§ć®å†…å“ć§ end ćØ恄恆čؘčæ°ćÆčŖć‚ć‚‰ć‚Œć¾ć›ć‚“怂

éøęŠžć‚«ćƒ©ćƒ ćƒŖć‚¹ćƒˆå±•é–‹ć‚³ćƒ”ćƒ³ćƒˆĀ¶

expandĀ¶

SELECTēÆ€ć®ć‚¢ć‚¹ć‚æćƒŖć‚¹ć‚Æ * 悒 ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ ć®å®šē¾©ć‚’ 参ē…§ć—恦č‡Ŗå‹•ć§ć‚«ćƒ©ćƒ ć®ćƒŖć‚¹ćƒˆć«å±•é–‹ć™ć‚‹å¼ć‚’éøęŠžć‚«ćƒ©ćƒ ćƒŖć‚¹ćƒˆå±•é–‹ć‚³ćƒ”ćƒ³ćƒˆćØå‘¼ć³ć¾ć™ć€‚ ꧋ꖇćÆꬔ恮ćØ恊悊恧恙怂

/*%expand ć‚Ø悤ćƒŖć‚¢ć‚¹*/

ć‚Ø悤ćƒŖć‚¢ć‚¹ćÆę–‡å­—åˆ—ćØć—ć¦č©•ä¾”ć•ć‚Œć‚‹å¼ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚ ć‚Ø悤ćƒŖć‚¢ć‚¹ćÆēœē•„åÆčƒ½ć§ć™ć€‚

ć“ć®ć‚³ćƒ”ćƒ³ćƒˆć®ē›“å¾Œć«ćÆć‚¢ć‚¹ć‚æćƒŖć‚¹ć‚Æ * 恌åæ…é ˆć§ć™ć€‚

ä¾‹ć‚’ē¤ŗć—ć¾ć™ć€‚

select /*%expand*/* from employee

äøŠčØ˜ć®SQLꖇ恮ēµęžœćŒę¬”ć®ć‚ˆć†ćŖ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć•ć‚Œć¦ć„ć‚‹ć‚‚ć®ćØć—ć¾ć™ć€‚

@Entity
public class Employee {
    Integer id;
    String name;
    Integer age;
}

恓恮ćØ恍态 SQL ćÆ仄äø‹ć®ć‚ˆć†ć«å¤‰ę›ć•ć‚Œć¾ć™ć€‚

select id, name, age from employee

SQL äøŠć§ćƒ†ćƒ¼ćƒ–ćƒ«ć«ć‚Ø悤ćƒŖć‚¢ć‚¹ć‚’ęŒ‡å®šć™ć‚‹å “åˆć€ éøęŠžć‚«ćƒ©ćƒ ćƒŖć‚¹ćƒˆå±•é–‹ć‚³ćƒ”ćƒ³ćƒˆć«ć‚‚åŒć˜ć‚Ø悤ćƒŖć‚¢ć‚¹ć‚’ęŒ‡å®šć—ć¦ćć ć•ć„ć€‚

select /*%expand "e" */* from employee e

恓恮ćØ恍态 SQL ćÆ仄äø‹ć®ć‚ˆć†ć«å¤‰ę›ć•ć‚Œć¾ć™ć€‚

select e.id, e.name, e.age from employee e

ę›“ę–°ć‚«ćƒ©ćƒ ćƒŖć‚¹ćƒˆē”Ÿęˆć‚³ćƒ”ćƒ³ćƒˆĀ¶

populateĀ¶

UPDATEꖇ恮SETēƀ 悒 ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ ć®å®šē¾©ć‚’ 参ē…§ć—恦č‡Ŗå‹•ć§ē”Ÿęˆć™ć‚‹å¼ć‚’ę›“ę–°ć‚«ćƒ©ćƒ ćƒŖć‚¹ćƒˆē”Ÿęˆć‚³ćƒ”ćƒ³ćƒˆćØå‘¼ć³ć¾ć™ć€‚ ꧋ꖇćÆꬔ恮ćØ恊悊恧恙怂

/*%populate*/

ä¾‹ć‚’ē¤ŗć—ć¾ć™ć€‚

update employee set /*%populate*/ id = id where age < 30

äøŠčØ˜ć®SQLꖇćøć®å…„åŠ›ćŒę¬”ć®ć‚ˆć†ćŖ ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć•ć‚Œć¦ć„ć‚‹ć‚‚ć®ćØć—ć¾ć™ć€‚

@Entity
public class Employee {
    Integer id;
    String name;
    Integer age;
}

恓恮ćØ恍态 SQL ćÆ仄äø‹ć®ć‚ˆć†ć«å¤‰ę›ć•ć‚Œć¾ć™ć€‚

update employee set id = ?, name = ?, age = ? where age < 30

ę›“ę–°ć‚«ćƒ©ćƒ ćƒŖć‚¹ćƒˆē”Ÿęˆć‚³ćƒ”ćƒ³ćƒˆćÆ态 /*%populate*/ 恋悉WHEREå„ć¾ć§ć‚’ć‚«ćƒ©ćƒ ćƒŖć‚¹ćƒˆć§ē½®ćę›ćˆć¾ć™ć€‚ ć¤ć¾ć‚Šć€å…ƒć®SQLć«ć‚ć£ćŸ id = id 恮čؘčæ°ćÆ꜀ēµ‚ēš„ćŖSQL恋悉ćÆå‰Šé™¤ć•ć‚Œć¾ć™ć€‚

通åøøć®ćƒ–ćƒ­ćƒƒć‚Æć‚³ćƒ”ćƒ³ćƒˆĀ¶

/* 恮ē›“å¾Œć«ē¶šć3ę–‡å­—ē›®ćŒJavać®č­˜åˆ„å­ć®å…ˆé ­ć§ä½æē”Ø恧恍ćŖć„ę–‡å­— ļ¼ˆćŸć ć—态ē©ŗē™½ćŠć‚ˆć³å¼ć§ē‰¹åˆ„ćŖę„å‘³ć‚’ć‚‚ć¤ %态#态 @态 "态 ' ćÆ除恏ļ¼‰ć®å “åˆć€ 恝悌ćÆ通åøøć®ćƒ–ćƒ­ćƒƒć‚Æć‚³ćƒ”ćƒ³ćƒˆć ćØćæćŖć•ć‚Œć¾ć™ć€‚

恟ćØćˆć°ć€ę¬”ć®ä¾‹ćÆć™ć¹ć¦é€šåøøć®ćƒ–ćƒ­ćƒƒć‚Æć‚³ćƒ”ćƒ³ćƒˆć§ć™ć€‚

/**ļ½ž*/
/*+ļ½ž*/
/*=ļ½ž*/
/*:ļ½ž*/
/*;ļ½ž*/
/*(ļ½ž*/
/*)ļ½ž*/
/*&ļ½ž*/

äø€ę–¹ć€ę¬”ć®ä¾‹ćÆć™ć¹ć¦å¼ć‚³ćƒ”ćƒ³ćƒˆć ćØćæćŖć•ć‚Œć¾ć™ć€‚

/* ļ½ž*/ ...--3ę–‡å­—ē›®ćŒē©ŗē™½ć§ć‚ć‚‹ćŸć‚å¼ć‚³ćƒ”ćƒ³ćƒˆć§ć™ć€‚
/*aļ½ž*/ ...--3ę–‡å­—ē›®ćŒJavać®č­˜åˆ„å­ć®å…ˆé ­ć§ä½æē”ØåÆčƒ½ćŖę–‡å­—ć§ć‚ć‚‹ćŸć‚å¼ć‚³ćƒ”ćƒ³ćƒˆć§ć™ć€‚
/*$ļ½ž*/ ...--3ę–‡å­—ē›®ćŒJavać®č­˜åˆ„å­ć®å…ˆé ­ć§ä½æē”ØåÆčƒ½ćŖę–‡å­—ć§ć‚ć‚‹ćŸć‚å¼ć‚³ćƒ”ćƒ³ćƒˆć§ć™ć€‚
/*%ļ½ž*/ ...--3ę–‡å­—ē›®ćŒę”ä»¶ć‚³ćƒ”ćƒ³ćƒˆć‚„ē¹°ć‚Ščæ”ć—ć‚³ćƒ”ćƒ³ćƒˆć®å§‹ć¾ć‚Šć‚’č”Ø恙怌%ć€ć§ć‚ć‚‹ćŸć‚å¼ć‚³ćƒ”ćƒ³ćƒˆć§ć™ć€‚
/*#ļ½ž*/ ...--3ę–‡å­—ē›®ćŒåŸ‹ć‚č¾¼ćæå¤‰ę•°ć‚³ćƒ”ćƒ³ćƒˆć‚’č”Ø恙怌#ć€ć§ć‚ć‚‹ćŸć‚å¼ć‚³ćƒ”ćƒ³ćƒˆć§ć™ć€‚
/*@ļ½ž*/ ...--3ę–‡å­—ē›®ćŒēµ„ćæč¾¼ćæé–¢ę•°ć‚‚ć—ććÆć‚Æćƒ©ć‚¹åć‚’č”Ø恙怌@ć€ć§ć‚ć‚‹ćŸć‚å¼ć‚³ćƒ”ćƒ³ćƒˆć§ć™ć€‚
/*"ļ½ž*/ ...--3ę–‡å­—ē›®ćŒę–‡å­—列ćƒŖćƒ†ćƒ©ćƒ«ć®å¼•ē”Øē¬¦ć‚’č”Ø恙怌"ć€ć§ć‚ć‚‹ćŸć‚å¼ć‚³ćƒ”ćƒ³ćƒˆć§ć™ć€‚
/*'ļ½ž*/ ...--3ę–‡å­—ē›®ćŒę–‡å­—ćƒŖćƒ†ćƒ©ćƒ«ć®å¼•ē”Øē¬¦ć‚’č”Ø恙怌'ć€ć§ć‚ć‚‹ćŸć‚å¼ć‚³ćƒ”ćƒ³ćƒˆć§ć™ć€‚

ćƒŽćƒ¼ćƒˆ

ē‰¹ć«ē†ē”±ćŒćŖć„å “åˆć€é€šåøøć®ćƒ–ćƒ­ćƒƒć‚Æć‚³ćƒ”ćƒ³ćƒˆć«ćÆ ęœ€åˆć®ć‚¢ć‚¹ć‚æćƒŖć‚¹ć‚Æ悒2恤重恭悋 /**ļ½ž*/ 悒ä½æē”Øć™ć‚‹ć®ćŒć‚ˆć„ć§ć—ć‚‡ć†ć€‚

通åøøć®č”Œć‚³ćƒ”ćƒ³ćƒˆĀ¶

-- ćÆ通åøøć®č”Œć‚³ćƒ”ćƒ³ćƒˆć ćØćæćŖć•ć‚Œć¾ć™ć€‚

Doma恧ćÆč”Œć‚³ćƒ”ćƒ³ćƒˆć‚’ē‰¹åˆ„ć«č§£é‡ˆć™ć‚‹ć“ćØćÆć‚ć‚Šć¾ć›ć‚“ć€‚

式č؀čŖžĀ¶

SQL äø­ć®å¼ć‚³ćƒ”ćƒ³ćƒˆć«ćÆē°”ꘓćŖå¼ć‚’čؘčæ°ć§ćć¾ć™ć€‚ ę–‡ę³•ćÆJavaćØ恻ćØć‚“ć©åŒć˜ć§ć™ć€‚ 恟恠恗态Java恧åÆčƒ½ćŖ恓ćØć™ć¹ć¦ćŒć§ćć‚‹ć‚ć‘ć§ćÆć‚ć‚Šć¾ć›ć‚“ć€‚

ćƒŽćƒ¼ćƒˆ

ē‰¹ć«å¤§ććŖ違恄ćÆ态 java.util.Optional ćŖ恩恮ć‚Ŗćƒ—ć‚·ćƒ§ćƒŠćƒ«ćŖåž‹ć®ę‰±ć„ę–¹ć«ć‚ć‚Šć¾ć™ć€‚ å¼ć®äø­ć§ćÆ态 Optional åž‹ć®å€¤ćÆåøøć«ćć®č¦ē“ ć®åž‹ć®å€¤ć«č‡Ŗå‹•å¤‰ę›ć•ć‚Œć¾ć™ć€‚ 恟ćØ恈恰态 Optional<String> åž‹ć®å€¤ćÆ String åž‹ć®å€¤ćØć—ć¦ę‰±ć‚ć‚Œć¾ć™ć€‚ ć—ćŸćŒć£ć¦ć€ Optional åž‹ć®ćƒ”ć‚½ćƒƒćƒ‰ć‚’å‘¼ć³å‡ŗ恗恟悊态 Optional åž‹ć‚’ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćØć™ć‚‹ćƒ”ć‚½ćƒƒćƒ‰ć®å‘¼ć³å‡ŗ恗ćÆć§ćć¾ć›ć‚“ć€‚

å€¤ć®å­˜åœØć®ęœ‰ē„”悒ē¢ŗčŖć™ć‚‹å “合ćÆ态 /*%if optional.isPresent() */ ćØ恙悋ę›æć‚ć‚Šć« /*%if optional != null */ ćØć—ć¦ćć ć•ć„ć€‚

java.util.OptionalInt 态 java.util.OptionalDouble 态 java.util.OptionalLong ć«ć¤ć„ć¦ć‚‚åŒę§˜ć§ć™ć€‚

ćƒŖćƒ†ćƒ©ćƒ«Ā¶

仄äø‹ć®ćƒŖćƒ†ćƒ©ćƒ«ćŒē”Øę„ć•ć‚Œć¦ć„ć¾ć™ć€‚

ćƒŖćƒ†ćƒ©ćƒ« 型
null void
true boolean
false boolean
10 int
10L long
0.123F float
0.123D double
0.123B java.math.BigDecimal
‘a’ char
“a” java.lang.String

ę•°å€¤ć®åž‹ćÆ态ćƒŖćƒ†ćƒ©ćƒ«ć®ęœ€å¾Œć« L 悄 F ćŖć©ć®ć‚µćƒ•ć‚£ćƒƒć‚Æć‚¹ć‚’ä»˜äøŽć—恦åŒŗåˆ„ć—ć¾ć™ć€‚ ć‚µćƒ•ć‚£ćƒƒć‚Æć‚¹ćÆå¤§ę–‡å­—ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

select * from employee where
/*%if employeeName != null && employeeName.length() > 10 */
    employee_name = /* employeeName */'smith'
/*%end*/

ęÆ”č¼ƒę¼”ē®—子Ā¶

仄äø‹ć®ęÆ”č¼ƒę¼”ē®—å­ć‚’ä½æē”Øć§ćć¾ć™ć€‚

ę¼”ē®—子 čŖ¬ę˜Ž
== ē­‰å€¤ę¼”ē®—子
!= äøē­‰å€¤ę¼”ē®—子
< 小ćŖć‚Šę¼”ē®—子
<= 小ćŖć‚Šć‚¤ć‚³ćƒ¼ćƒ«ę¼”ē®—子
> 大ćŖć‚Šę¼”ē®—子
>= 大ćŖć‚Šć‚¤ć‚³ćƒ¼ćƒ«ę¼”ē®—子

ęÆ”č¼ƒę¼”ē®—å­ć‚’åˆ©ē”Ø恙悋恫ćÆ态 č¢«ę¼”ē®—å­ćŒ java.lang.Comparable ć‚’å®Ÿč£…ć—ć¦ć„ć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚

< 态 <= 态 > 态 >= 恧ćÆć€č¢«ę¼”ē®—å­ćŒ null ć§ć‚ć£ć¦ćÆć„ć‘ć¾ć›ć‚“ć€‚

select * from employee where
/*%if employeeName.indexOf("s") > -1 */
    employee_name = /* employeeName */'smith'
/*%end*/

č«–ē†ę¼”ē®—子Ā¶

仄äø‹ć®č«–ē†ę¼”ē®—å­ć‚’ä½æē”Øć§ćć¾ć™ć€‚

ę¼”ē®—子 čŖ¬ę˜Ž
! č«–ē†å¦å®šę¼”ē®—子
&& č«–ē†ē©ę¼”ē®—子
|| č«–ē†å’Œę¼”ē®—子

ę‹¬å¼§ć‚’ä½æć£ć¦ć€ę¼”ē®—å­ćŒé©ē”Ø恕悌悋å„Ŗ先åŗ¦ć‚’åˆ¶å¾”ć§ćć¾ć™ć€‚

select * from employee where
/*%if (departmentId == null || managerId == null) and employee_name != null */
    employee_name = /* employeeName */'smith'
/*%end*/

ē®—č”“ę¼”ē®—子Ā¶

仄äø‹ć®ē®—č”“ę¼”ē®—å­ć‚’ä½æē”Øć§ćć¾ć™ć€‚

ę¼”ē®—子 čŖ¬ę˜Ž
+ 加ē®—ę¼”ē®—子
- ęø›ē®—ę¼”ē®—子
* 乗ē®—ę¼”ē®—子
/ 除ē®—ę¼”ē®—子
% å‰°ä½™ę¼”ē®—子

č¢«ę¼”ē®—子ćÆę•°å€¤åž‹ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

select * from employee where
    salary = /* salary + 1000 */0

連ēµę¼”ē®—子Ā¶

連ēµę¼”ē®—子 + 悒ä½æć£ć¦ę–‡å­—ć‚’é€£ēµć§ćć¾ć™ć€‚

č¢«ę¼”ē®—子ćÆę¬”ć®ć„ćšć‚Œć‹ć®åž‹ć§ćŖć‘ć‚Œć°ć„ć‘ć¾ć›ć‚“ć€‚

  • java.lang.String
  • java.lang.Character
  • char
select * from employee where
   employee_name like /* employeeName + "_" */'smith'

ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć®å‘¼ć³å‡ŗ恗Ā¶

惉惃惈 . 恧åŒŗåˆ‡ć£ć¦ćƒ”ć‚½ćƒƒćƒ‰åć‚’ęŒ‡å®šć™ć‚‹ć“ćØć§ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”ŒåÆčƒ½ć§ć™ć€‚ å®Ÿč”ŒåÆčƒ½ćŖćƒ”ć‚½ćƒƒćƒ‰ćÆåÆč¦–ę€§ćŒpublicćŖć‚‚ć®ć ć‘ć«é™ć‚‰ć‚Œć¾ć™ć€‚

select * from employee where
/*%if employeeName.startsWith("s") */
    employee_name = /* employeeName */'smith'
/*%end*/

å¼•ę•°ćŒćŖć„å “åˆćÆćƒ”ć‚½ćƒƒćƒ‰åć®å¾Œć‚ć« () ć‚’ęŒ‡å®šć—ć¾ć™ć€‚

select * from employee where
/*%if employeeName.length() > 10 */
    employee_name = /* employeeName */'smith'
/*%end*/

ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ćøć®ć‚¢ć‚Æć‚»ć‚¹Ā¶

惉惃惈 . 恧åŒŗåˆ‡ć£ć¦ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰åć‚’ęŒ‡å®šć™ć‚‹ć“ćØć§ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć«ć‚¢ć‚Æć‚»ć‚¹ć§ćć¾ć™ć€‚ åÆ視ꀧćÆprivateć§ć‚ć£ć¦ć‚‚ć‚¢ć‚Æć‚»ć‚¹åÆčƒ½ć§ć™ć€‚

select * from employee where
    employee_name = /* employee.employeeName */'smith'

staticćƒ”ć‚½ćƒƒćƒ‰ć®å‘¼ć³å‡ŗ恗Ā¶

@ ć§å›²ć¾ć‚ŒćŸć‚Æćƒ©ć‚¹ć®å®Œå…Øäæ®é£¾åć«ćƒ”ć‚½ćƒƒćƒ‰ć‚’ē¶šć‘悋恓ćØ恧staticćƒ”ć‚½ćƒƒćƒ‰ć‚’å®Ÿč”ŒåÆčƒ½ć§ć™ć€‚ å®Ÿč”ŒåÆčƒ½ćŖćƒ”ć‚½ćƒƒćƒ‰ćÆåÆč¦–ę€§ćŒpublicćŖć‚‚ć®ć ć‘ć«é™ć‚‰ć‚Œć¾ć™ć€‚

select * from employee where
/*%if @java.util.regex.Pattern@matches("^[a-z]*$", employeeName) */
    employee_name = /* employeeName */'smith'
/*%end*/

staticćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ćøć®ć‚¢ć‚Æć‚»ć‚¹Ā¶

@ ć§å›²ć¾ć‚ŒćŸć‚Æćƒ©ć‚¹ć®å®Œå…Øäæ®é£¾åć«ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć‚’ē¶šć‘悋恓ćØ恧staticćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć«ć‚¢ć‚Æć‚»ć‚¹ć§ćć¾ć™ć€‚ åÆ視ꀧćÆprivateć§ć‚ć£ć¦ć‚‚ć‚¢ć‚Æć‚»ć‚¹åÆčƒ½ć§ć™ć€‚

select * from employee where
/*%if employeeName.length() < @java.lang.Byte@MAX_VALUE */
  employee_name = /* employeeName */'smith'
/*%end*/

ēµ„ćæč¾¼ćæé–¢ę•°ć®ä½æē”ØĀ¶

ēµ„ćæč¾¼ćæé–¢ę•°ćÆ态äø»ć«ć€SQLć«ćƒć‚¤ćƒ³ćƒ‰ć™ć‚‹å‰ć«ćƒć‚¤ćƒ³ćƒ‰å¤‰ę•°ć®å€¤ć‚’å¤‰ę›“ć™ć‚‹ćŸć‚ć®ćƒ¦ćƒ¼ćƒ†ć‚£ćƒŖćƒ†ć‚£ć§ć™ć€‚

恟ćØ恈恰态LIKEå„ć§å‰ę–¹äø€č‡“ꤜē“¢ć‚’č”Œć†å “åˆć«ę¬”ć®ć‚ˆć†ć«čؘčæ°ć§ćć¾ć™ć€‚

select * from employee where
    employee_name like /* @prefix(employee.employeeName) */'smith' escape '$'

恓恓恧ćÆ态 @prefix(employee.employeeName) ćØć„ć†ć‚ˆć†ć«ć€ employee.employeeName 悒 @prefix é–¢ę•°ć«ęø”ć—ć¦ć„ć¾ć™ć€‚ @prefix é–¢ę•°ćÆć€ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć§å—ć‘å–ć‚‹ę–‡å­—åˆ—ć‚’å‰ę–¹äø€č‡“ꤜē“¢ē”Øć®ę–‡å­—åˆ—ć«å¤‰ę›ć—ć¾ć™ć€‚ ć¾ćŸć€ē‰¹åˆ„ćŖę„å‘³ć‚’ęŒć¤ę–‡å­—ć‚’ć‚Øć‚¹ć‚±ćƒ¼ćƒ—ć—ć¾ć™ć€‚ 恟ćØ恈恰 employee.employeeName ć®å€¤ćŒ ABC ć§ć‚ć‚‹å “åˆć€ 値ćÆ ABC% ć«å¤‰ę›ć•ć‚Œć¾ć™ć€‚ 悂恗态 employee.employeeName ć®å€¤ćŒ AB%C ćØć„ć†ć‚ˆć†ć« % ć‚’å«ć‚“ć§ć„ć‚‹å “åˆć€ % ćÆćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®ć‚Øć‚¹ć‚±ćƒ¼ćƒ—ć‚·ćƒ¼ć‚±ćƒ³ć‚¹ $ 恧ć‚Øć‚¹ć‚±ćƒ¼ćƒ—ć•ć‚Œć€å€¤ćÆ AB$%C% ć«å¤‰ę›ć•ć‚Œć¾ć™ć€‚

ä½æē”ØåÆčƒ½ćŖé–¢ę•°ć®ć‚·ć‚°ćƒćƒćƒ£ćÆ仄äø‹ć®ćØ恊悊恧恙怂

String @escape(String text, char escapeChar = ‘$’)
LIKEę¼”ē®—ć®ćŸć‚ć®ć‚Øć‚¹ć‚±ćƒ¼ćƒ—ć‚’č”Œć†ć“ćØ悒ē¤ŗć—ć¾ć™ć€‚ ęˆ»ć‚Šå€¤ćÆå…„åŠ›å€¤ć‚’ć‚Øć‚¹ć‚±ćƒ¼ćƒ—ć—ćŸę–‡å­—åˆ—ć§ć™ć€‚ escapeChar ćŒęŒ‡å®šć•ć‚ŒćŖć„å “åˆć€ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®ć‚Øć‚¹ć‚±ćƒ¼ćƒ—ę–‡å­— $ 恌ä½æē”Øć•ć‚Œć¾ć™ć€‚ å¼•ę•°ć« null 悒ęø”ć—ćŸå “åˆć€ null 悒čæ”ć—ć¾ć™ć€‚
String @prefix(String prefix, char escapeChar = ‘$’)
å‰ę–¹äø€č‡“ꤜē“¢ć‚’č”Œć†ć“ćØ悒ē¤ŗć—ć¾ć™ć€‚ ęˆ»ć‚Šå€¤ćÆå…„åŠ›å€¤ć‚’ć‚Øć‚¹ć‚±ćƒ¼ćƒ—ć—ćƒÆć‚¤ćƒ«ćƒ‰ć‚«ćƒ¼ćƒ‰ć‚’å¾Œć‚ć«ä»˜äøŽć—ćŸę–‡å­—åˆ—ć§ć™ć€‚ escapeChar ćŒęŒ‡å®šć•ć‚ŒćŖć„å “åˆć€ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®ć‚Øć‚¹ć‚±ćƒ¼ćƒ—ę–‡å­— $ 恌ä½æē”Øć•ć‚Œć¾ć™ć€‚ å¼•ę•°ć« null 悒ęø”ć—ćŸå “åˆć€ null 悒čæ”ć—ć¾ć™ć€‚
String @infix(String infix, char escapeChar = ‘$’)
äø­é–“äø€č‡“ꤜē“¢ć‚’č”Œć†ć“ćØ悒ē¤ŗć—ć¾ć™ć€‚ ęˆ»ć‚Šå€¤ćÆå…„åŠ›å€¤ć‚’ć‚Øć‚¹ć‚±ćƒ¼ćƒ—ć—ćƒÆć‚¤ćƒ«ćƒ‰ć‚«ćƒ¼ćƒ‰ć‚’å‰ćØå¾Œć‚ć«ä»˜äøŽć—ćŸę–‡å­—åˆ—ć§ć™ć€‚ escapeChar ćŒęŒ‡å®šć•ć‚ŒćŖć„å “åˆć€ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®ć‚Øć‚¹ć‚±ćƒ¼ćƒ—ę–‡å­— $ 恌ä½æē”Øć•ć‚Œć¾ć™ć€‚ å¼•ę•°ć« null 悒ęø”ć—ćŸå “åˆć€ null 悒čæ”ć—ć¾ć™ć€‚
String @suffix(String suffix, char escapeChar = ‘$’)
å¾Œę–¹äø€č‡“ꤜē“¢ć‚’č”Œć†ć“ćØ悒ē¤ŗć—ć¾ć™ć€‚ ęˆ»ć‚Šå€¤ćÆå…„åŠ›å€¤ć‚’ć‚Øć‚¹ć‚±ćƒ¼ćƒ—ć—ćƒÆć‚¤ćƒ«ćƒ‰ć‚«ćƒ¼ćƒ‰ć‚’å‰ć«ä»˜äøŽć—ćŸę–‡å­—åˆ—ć§ć™ć€‚ escapeChar ćŒęŒ‡å®šć•ć‚ŒćŖć„å “åˆć€ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®ć‚Øć‚¹ć‚±ćƒ¼ćƒ—ę–‡å­— $ 恌ä½æē”Øć•ć‚Œć¾ć™ć€‚ å¼•ę•°ć« null 悒ęø”ć—ćŸå “åˆć€ null 悒čæ”ć—ć¾ć™ć€‚
java.util.Date @roundDownTimePart(java.util.Date date)
ę™‚åˆ»éƒØåˆ†ć‚’åˆ‡ć‚ŠęØ恦悋恓ćØ悒ē¤ŗć—ć¾ć™ć€‚ ęˆ»ć‚Šå€¤ćÆę™‚åˆ»éƒØåˆ†ćŒåˆ‡ć‚ŠęØć¦ć‚‰ć‚ŒćŸę–°ć—ć„ę—„ä»˜ć§ć™ć€‚ å¼•ę•°ć« null 悒ęø”ć—ćŸå “åˆć€ null 悒čæ”ć—ć¾ć™ć€‚
java.sql.Date @roundDownTimePart(java.sql.Date date)
ę™‚åˆ»éƒØåˆ†ć‚’åˆ‡ć‚ŠęØ恦悋恓ćØ悒ē¤ŗć—ć¾ć™ć€‚ ęˆ»ć‚Šå€¤ćÆę™‚åˆ»éƒØåˆ†ćŒåˆ‡ć‚ŠęØć¦ć‚‰ć‚ŒćŸę–°ć—ć„ę—„ä»˜ć§ć™ć€‚ å¼•ę•°ć« null 悒ęø”ć—ćŸå “åˆć€ null 悒čæ”ć—ć¾ć™ć€‚
java.sql.Timestamp @roundDownTimePart(java.sql.Timestamp timestamp)
ę™‚åˆ»éƒØåˆ†ć‚’åˆ‡ć‚ŠęØ恦悋恓ćØ悒ē¤ŗć—ć¾ć™ć€‚ ęˆ»ć‚Šå€¤ćÆę™‚åˆ»éƒØåˆ†ćŒåˆ‡ć‚ŠęØć¦ć‚‰ć‚ŒćŸę–°ć—ć„ć‚æć‚¤ćƒ ć‚¹ć‚æćƒ³ćƒ—ć§ć™ć€‚ å¼•ę•°ć« null 悒ęø”ć—ćŸå “åˆć€ null 悒čæ”ć—ć¾ć™ć€‚
java.util.Date @roundUpTimePart(java.util.Date date)
ę™‚åˆ»éƒØåˆ†ć‚’åˆ‡ć‚ŠäøŠć’悋恓ćØ悒ē¤ŗć—ć¾ć™ć€‚ ęˆ»ć‚Šå€¤ćÆę™‚åˆ»éƒØåˆ†ćŒåˆ‡ć‚ŠäøŠć’ć‚‰ć‚ŒćŸę–°ć—ć„ę—„ä»˜ć§ć™ć€‚ å¼•ę•°ć« null 悒ęø”ć—ćŸå “åˆć€ null 悒čæ”ć—ć¾ć™ć€‚
java.sql.Date @roundUpTimePart(java.sql.Date date)
ę™‚åˆ»éƒØåˆ†ć‚’åˆ‡ć‚ŠäøŠć’悋恓ćØ悒ē¤ŗć—ć¾ć™ć€‚ ęˆ»ć‚Šå€¤ćÆę™‚åˆ»éƒØåˆ†ćŒåˆ‡ć‚ŠäøŠć’ć‚‰ć‚ŒćŸę–°ć—ć„ę—„ä»˜ć§ć™ć€‚ å¼•ę•°ć« null 悒ęø”ć—ćŸå “åˆć€ null 悒čæ”ć—ć¾ć™ć€‚
java.sql.Timestamp @roundUpTimePart(java.sql.Timestamp timestamp)
ę™‚åˆ»éƒØåˆ†ć‚’åˆ‡ć‚ŠäøŠć’悋恓ćØ悒ē¤ŗć—ć¾ć™ć€‚ ęˆ»ć‚Šå€¤ćÆę™‚åˆ»éƒØåˆ†ćŒåˆ‡ć‚ŠäøŠć’ć‚‰ć‚ŒćŸę–°ć—ć„ć‚æć‚¤ćƒ ć‚¹ć‚æćƒ³ćƒ—ć§ć™ć€‚ å¼•ę•°ć« null 悒ęø”ć—ćŸå “åˆć€ null 悒čæ”ć—ć¾ć™ć€‚
boolean @isEmpty(CharSequence charSequence)
ę–‡å­—ć‚·ćƒ¼ć‚±ćƒ³ć‚¹ćŒ null 态悂恗恏ćÆę–‡å­—ć‚·ćƒ¼ć‚±ćƒ³ć‚¹ć®é•·ć•ćŒ 0 ć®å “åˆ true 悒čæ”ć—ć¾ć™ć€‚
boolean @isNotEmpty(CharSequence charSequence)
ę–‡å­—ć‚·ćƒ¼ć‚±ćƒ³ć‚¹ćŒ null 恧ćŖć„ć€ć‹ć¤ę–‡å­—ć‚·ćƒ¼ć‚±ćƒ³ć‚¹ć®é•·ć•ćŒ 0 恧ćŖć„å “åˆ true 悒čæ”ć—ć¾ć™ć€‚
boolean @isBlank(CharSequence charSequence)
ę–‡å­—ć‚·ćƒ¼ć‚±ćƒ³ć‚¹ćŒ null 态悂恗恏ćÆę–‡å­—ć‚·ćƒ¼ć‚±ćƒ³ć‚¹ć®é•·ć•ćŒ 0 态 悂恗恏ćÆę–‡å­—ć‚·ćƒ¼ć‚±ćƒ³ć‚¹ćŒē©ŗē™½ć ć‘ć‹ć‚‰å½¢ęˆć•ć‚Œć‚‹å “合 true悒čæ”ć—ć¾ć™ć€‚
boolean @isNotBlank(CharSequence charSequence)
ę–‡å­—ć‚·ćƒ¼ć‚±ćƒ³ć‚¹ćŒ null 恧ćŖć„ć€ć‹ć¤ę–‡å­—ć‚·ćƒ¼ć‚±ćƒ³ć‚¹ć®é•·ć•ćŒ 0 恧ćŖ恄态 ć‹ć¤ę–‡å­—ć‚·ćƒ¼ć‚±ćƒ³ć‚¹ćŒē©ŗē™½ć ć‘ć§å½¢ęˆć•ć‚ŒćŖć„å “åˆ true 悒čæ”ć—ć¾ć™ć€‚

ć“ć‚Œć‚‰ć®é–¢ę•°ćÆ态 org.seasar.doma.expr.ExpressionFunctions ć®ćƒ”ć‚½ćƒƒćƒ‰ć«åƾåæœć—ć¦ć„ć¾ć™ć€‚

ć‚«ć‚¹ć‚æćƒ é–¢ę•°ć®ä½æē”ØĀ¶

é–¢ę•°ć‚’ē‹¬č‡Ŗć«å®šē¾©ć—ä½æē”Øć§ćć¾ć™ć€‚

ē‹¬č‡Ŗć«å®šē¾©ć—ćŸé–¢ę•°ļ¼ˆć‚«ć‚¹ć‚æćƒ é–¢ę•°ļ¼‰ć‚’ä½æē”Ø恙悋恫ćÆꬔ恮čØ­å®šćŒåæ…要恧恙怂

  • é–¢ę•°ćÆ态 org.seasar.doma.expr.ExpressionFunctions ć‚’å®Ÿč£…ć—ćŸć‚Æćƒ©ć‚¹ć®ćƒ”ć‚½ćƒƒćƒ‰ćØć—ć¦å®šē¾©ć™ć‚‹ć€‚
  • ćƒ”ć‚½ćƒƒćƒ‰ćÆpublicćŖć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ćØ恙悋怂
  • ä½œęˆć—ćŸć‚Æćƒ©ć‚¹ćÆ ę³Ø釈処ē† 恮ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć§ē™»éŒ²ć™ć‚‹ć€‚ ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć®ć‚­ćƒ¼ćÆ doma.expr.functions 恧恂悋怂
  • ä½œęˆć—ćŸć‚Æćƒ©ć‚¹ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’čح定ć‚Æćƒ©ć‚¹ć®RDBMSć®ę–¹čØ€ć§ä½æē”Ø恙悋 ļ¼ˆDomaćŒęä¾›ć™ć‚‹RDBMSć®ę–¹čØ€ć®å®Ÿč£…ćÆć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ恧 ExpressionFunctions ć‚’å—ć‘å–ć‚‹ć“ćØ恌åÆčƒ½ļ¼‰ć€‚

ć‚«ć‚¹ć‚æćƒ é–¢ę•°ć‚’å‘¼ć³å‡ŗ恙恫ćÆ态ēµ„ćæč¾¼ćæé–¢ę•°ćØåŒć˜ć‚ˆć†ć«é–¢ę•°åć®å…ˆé ­ć« @ ć‚’ć¤ć‘ć¾ć™ć€‚ 恟ćØ恈恰态 myfunc ćØć„ć†é–¢ę•°ć®å‘¼ć³å‡ŗ恗ćÆę¬”ć®ć‚ˆć†ć«čؘčæ°ć§ćć¾ć™ć€‚

select * from employee where
    employee_name = /* @myfunc(employee.employeeName) */'smith'

ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³Ā¶

DomaćÆć€ćƒ­ćƒ¼ć‚«ćƒ«ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ć‚’ć‚µćƒćƒ¼ćƒˆć—ć¾ć™ć€‚ ć“ć®ćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆć§ćÆć€ćƒ­ćƒ¼ć‚«ćƒ«ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ć®čØ­å®šę–¹ę³•ćØ利ē”Øę–¹ę³•ć«ć¤ć„ć¦čŖ¬ę˜Žć—ć¾ć™ć€‚

ć‚°ćƒ­ćƒ¼ćƒćƒ«ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ć‚’ä½æē”Øć—ćŸć„å “åˆćÆ态JTAļ¼ˆJava Transaction APIļ¼‰ ć®å®Ÿč£…ć‚’ć‚‚ć¤ćƒ•ćƒ¬ćƒ¼ćƒ ćƒÆćƒ¼ć‚Æć‚„ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć‚µćƒ¼ćƒćƒ¼ć®ę©Ÿčƒ½ć‚’åˆ©ē”Øć—ć¦ćć ć•ć„ć€‚

čح定Ā¶

ćƒ­ćƒ¼ć‚«ćƒ«ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ć‚’å®Ÿč”Œć™ć‚‹ć«ćÆę¬”ć®ę”ä»¶ć‚’ęŗ€ćŸć™åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚

  • Config 恮 getDataSource 恧 LocalTransactionDataSource 悒čæ”恙
  • äøŠčØ˜ć® LocalTransactionDataSource ć‚’ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æć§å—ć‘ć¦ LocalTransactionManager 悒ē”Ÿęˆć™ć‚‹
  • äøŠčØ˜ć® LocalTransactionManager 恮ē®”ē†äø‹ć§ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć‚¢ć‚Æć‚»ć‚¹ć‚’č”Œć†

LocalTransactionManager 恮ē”ŸęˆćØå–å¾—ę–¹ę³•ćÆć„ćć¤ć‹ć‚ć‚Šć¾ć™ćŒć€ęœ€ć‚‚å˜ē“”ćŖę–¹ę³•ćÆ态 Config ć®å®Ÿč£…ć‚Æćƒ©ć‚¹ć®ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ恧ē”Ÿęˆć— Config ć®å®Ÿč£…ć‚Æćƒ©ć‚¹ć‚’ć‚·ćƒ³ć‚°ćƒ«ćƒˆćƒ³ćØ恙悋恓ćØ恧恙怂

å®Ÿč£…ä¾‹ć§ć™ć€‚

@SingletonConfig
public class AppConfig implements Config {

    private static final AppConfig CONFIG = new AppConfig();

    private final Dialect dialect;

    private final LocalTransactionDataSource dataSource;

    private final TransactionManager transactionManager;

    private AppConfig() {
        dialect = new H2Dialect();
        dataSource = new LocalTransactionDataSource(
                "jdbc:h2:mem:tutorial;DB_CLOSE_DELAY=-1", "sa", null);
        transactionManager = new LocalTransactionManager(
                dataSource.getLocalTransaction(getJdbcLogger()));
    }

    @Override
    public Dialect getDialect() {
        return dialect;
    }

    @Override
    public DataSource getDataSource() {
        return dataSource;
    }

    @Override
    public TransactionManager getTransactionManager() {
        return transactionManager;
    }

    public static AppConfig singleton() {
        return CONFIG;
    }
}

ćƒŽćƒ¼ćƒˆ

ć‚Æćƒ©ć‚¹ć« @SingletonConfig ć‚’ęŒ‡å®šć™ć‚‹ć“ćØć§ć‚·ćƒ³ć‚°ćƒ«ćƒˆćƒ³ć§ć‚ć‚‹ć“ćØ悒č”Øć—ć¦ć„ć¾ć™

利ē”Ø例Ā¶

čح定 恧ē¤ŗ恗恟 AppConfig ć‚Æćƒ©ć‚¹ć‚’ä»„äø‹ć®ć‚ˆć†ć«Daoć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć«ę³Øé‡ˆć™ć‚‹ć‚‚ć®ćØć—ć¦ä¾‹ć‚’ē¤ŗć—ć¾ć™ć€‚

@Dao(config = AppConfig.class)
public interface EmployeeDao {
    ...
}

ä»„é™ć®ć‚³ćƒ¼ćƒ‰ä¾‹ć«ē™»å “恙悋 dao ćÆäøŠčؘć‚Æćƒ©ć‚¹ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć§ć™ć€‚

ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ć®é–‹å§‹ćØēµ‚äŗ†Ā¶

ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ćÆ TransactionManager 恮仄äø‹ć®ćƒ”ć‚½ćƒƒćƒ‰ć®ć„ćšć‚Œć‹ć‚’ä½æć£ć¦é–‹å§‹ć—ć¾ć™ć€‚

  • required
  • requiresNew
  • notSupported

ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³å†…ć§č”Œć†å‡¦ē†ćÆćƒ©ćƒ ćƒ€å¼ćØ恗恦ęø”ć—ć¾ć™ć€‚

TransactionManager tm = AppConfig.singleton().getTransactionManager();

tm.required(() -> {
    Employee employee = dao.selectById(1);
    employee.setName("hoge");
    employee.setJobType(JobType.PRESIDENT);
    dao.update(employee);
});

ćƒ©ćƒ ćƒ€å¼ćŒę­£åøø恫ēµ‚äŗ†ć™ć‚Œć°ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ćÆć‚³ćƒŸćƒƒćƒˆć•ć‚Œć¾ć™ć€‚ ćƒ©ćƒ ćƒ€å¼ćŒä¾‹å¤–ć‚’ć‚¹ćƒ­ćƒ¼ć—ćŸå “åˆćÆćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ćÆćƒ­ćƒ¼ćƒ«ćƒćƒƒć‚Æć•ć‚Œć¾ć™ć€‚

꘎ē¤ŗēš„ćŖćƒ­ćƒ¼ćƒ«ćƒćƒƒć‚ÆĀ¶

ä¾‹å¤–ć‚’ć‚¹ćƒ­ćƒ¼ć™ć‚‹ę–¹ę³•ä»„å¤–ć§ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ć‚’ćƒ­ćƒ¼ćƒ«ćƒćƒƒć‚Æ恙悋恫ćÆ setRollbackOnly ćƒ”ć‚½ćƒƒćƒ‰ć‚’å‘¼ć³å‡ŗć—ć¾ć™ć€‚

TransactionManager tm = AppConfig.singleton().getTransactionManager();

tm.required(() -> {
    Employee employee = dao.selectById(1);
    employee.setName("hoge");
    employee.setJobType(JobType.PRESIDENT);
    dao.update(employee);
    // ćƒ­ćƒ¼ćƒ«ćƒćƒƒć‚Æ恙悋悂恮ćØć—ć¦ćƒžćƒ¼ć‚Æ恙悋
    tm.setRollbackOnly();
});

ć‚»ćƒ¼ćƒ–ćƒć‚¤ćƒ³ćƒˆĀ¶

ć‚»ćƒ¼ćƒ–ćƒć‚¤ćƒ³ćƒˆć‚’ä½æē”Ø恙悋恓ćØć§ć€ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³äø­ć®ē‰¹å®šć®å¤‰ę›“ć‚’å–ć‚Šę¶ˆć™ć“ćØćŒć§ćć¾ć™ć€‚

TransactionManager tm = AppConfig.singleton().getTransactionManager();

tm.required(() -> {
    // ꤜē“¢ć—恦ꛓꖰ
    Employee employee = dao.selectById(1);
    employee.setName("hoge");
    dao.update(employee);

    // ć‚»ćƒ¼ćƒ–ćƒć‚¤ćƒ³ćƒˆć‚’ä½œęˆ
    tm.setSavepoint("beforeDelete");

    // 削除
    dao.delete(employee);

    // ć‚»ćƒ¼ćƒ–ćƒć‚¤ćƒ³ćƒˆćøęˆ»ć‚‹ļ¼ˆäøŠć§č”Œć£ćŸå‰Šé™¤ć‚’å–ć‚Šę¶ˆć™ļ¼‰
    tm.rollback("beforeDelete");
});

ę³Ø釈処ē†Ā¶

Pluggable Annotation Processing API ć‚’åˆ©ē”Ø恙悋ćØć€ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ć®č‡Ŗ動ē”Ÿęˆć‚„ę¤œčØ¼ć‚’ ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ę™‚ ć«č”Œć†ć“ćØćŒć§ćć¾ć™ć€‚

Doma恧ćÆ恓恮APIć‚’åˆ©ē”Ø恙悋恓ćØ恧 @Entity 悄 @Dao ćØčØ€ć£ćŸć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćŒę³Ø釈恕悌恟ć‚Æćƒ©ć‚¹ć‚„ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć‚’å‡¦ē†ć—态 åæ…要ćŖć‚Æćƒ©ć‚¹ć‚’č‡Ŗ動ē”Ÿęˆć—ć¾ć™ć€‚ ć¾ćŸć€ę³Ø釈恕悌恟ć‚Æćƒ©ć‚¹ć‚„ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć®ę¤œčØ¼ć‚’č”Œć„ć€Domać®č¦ē“„ć«å¾“ć£ć¦ć„ćŖć„ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ćŒć‚ć‚‹å “åˆćÆ ć‚Øćƒ©ćƒ¼ćƒ”ćƒƒć‚»ćƒ¼ć‚ø悒IDEļ¼ˆEclipsećŖ恩ļ¼‰ć®ć‚Øćƒ‡ć‚£ć‚æ悄javacć‚’å®Ÿč”Œć—ćŸć‚³ćƒ³ć‚½ćƒ¼ćƒ«äøŠć«č”Øē¤ŗć—ć¾ć™ć€‚

恓恓恧ćÆ态DomaćŒęä¾›ć™ć‚‹ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć®ēخ锞ćØć€ćƒ“ćƒ«ćƒ‰ćƒ„ćƒ¼ćƒ«ć”ćØ恮ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć®čØ­å®šę–¹ę³•ć‚’čŖ¬ę˜Žć—ć¾ć™ć€‚

ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³Ā¶

doma.dao.package
@Dao 恌ę³Øé‡ˆć•ć‚ŒćŸć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć®å®Ÿč£…ć‚Æćƒ©ć‚¹ćŒē”Ÿęˆć•ć‚Œć‚‹ćƒ‘ćƒƒć‚±ćƒ¼ć‚ø怂 ä½•ć‚‰ć‹ć®å€¤ć‚’ęŒ‡å®šć—ćŸå “åˆć€doma.dao.subpackageć®ęŒ‡å®šć‚ˆć‚Šć‚‚å„Ŗå…ˆć•ć‚Œć‚‹ć€‚ ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®å€¤ćÆ态 @Dao 恌ę³Øé‡ˆć•ć‚ŒćŸć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ćØåŒć˜ćƒ‘ćƒƒć‚±ćƒ¼ć‚ø怂
doma.dao.subpackage
@Dao 恌ę³Øé‡ˆć•ć‚ŒćŸć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć®å®Ÿč£…ć‚Æćƒ©ć‚¹ćŒē”Ÿęˆć•ć‚Œć‚‹ć‚µćƒ–ćƒ‘ćƒƒć‚±ćƒ¼ć‚ø怂 doma.dao.packageć«å€¤ć‚’ęŒ‡å®šć—ć¦ć„ćŖć„å “åˆć«ć®ćæęœ‰åŠ¹ć€‚ @Dao 恌ę³Øé‡ˆć•ć‚ŒćŸć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć®ćƒ‘ćƒƒć‚±ćƒ¼ć‚ø恌 example.dao ć§ć€ć“ć“ć«ęŒ‡å®šć—ćŸå€¤ćŒ impl ć®å “åˆć€ ē”Ÿęˆć•ć‚Œć‚‹ć‚Æćƒ©ć‚¹ć®ćƒ‘ćƒƒć‚±ćƒ¼ć‚øćÆ example.dao.impl ćØćŖ悋怂
doma.dao.suffix
@Dao 恌ę³Øé‡ˆć•ć‚ŒćŸć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć®å®Ÿč£…ć‚Æćƒ©ć‚¹ć®åå‰ć®ć‚µćƒ•ć‚£ćƒƒć‚Æć‚¹ć€‚ @Dao 恌ę³Øé‡ˆć•ć‚ŒćŸć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć®å˜ē“”åćŒ EmployeeDao ć§ć€ć“ć“ć«ęŒ‡å®šć—ćŸå€¤ćŒ Bean ć®å “åˆć€ ē”Ÿęˆć•ć‚Œć‚‹ć‚Æćƒ©ć‚¹ć®å˜ē“”名ćÆ EmployeeDaoBean ćØćŖ悋怂 ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®å€¤ćÆ Impl 怂
doma.debug
ę³Ø釈処ē†ć®ćƒ‡ćƒćƒƒć‚°ęƒ…å ±ć‚’ćƒ­ć‚°å‡ŗåŠ›ć™ć‚‹ć‹ć©ć†ć‹ć€‚ true ć®å “åˆć€ćƒ­ć‚°å‡ŗåŠ›ć‚’č”Œć†ć€‚ ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®å€¤ćÆ态 false 怂
doma.domain.converters
ä»»ę„ć®åž‹ćØåŸŗęœ¬åž‹ć‚’ē›øäŗ’å¤‰ę›ć™ć‚‹ DomainConverter ć®ćƒ—ćƒ­ćƒć‚¤ćƒ€ćØćŖ悋ć‚Æćƒ©ć‚¹ć®å®Œå…Øäæ®é£¾åć®ć‚«ćƒ³ćƒžåŒŗåˆ‡ć‚Šć€‚ ć‚Æćƒ©ć‚¹ćÆ org.seasar.doma.DomainConverters ć«ć‚ˆć£ć¦ę³Øé‡ˆć•ć‚Œć¦ć„ćŖ恄恑悌恰恄恑ćŖ恄怂
doma.entity.field.prefix
@Entity 恌ę³Ø釈恕悌恟ć‚Æćƒ©ć‚¹ć”ćØ恫ē”Ÿęˆć•ć‚Œć‚‹ć‚æ悤惗ć‚Æćƒ©ć‚¹ć§ä½æē”Ø恕悌悋怂 ć‚æ悤惗ć‚Æćƒ©ć‚¹ć®publicćŖćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰åć®ćƒ—ćƒ¬ćƒ•ć‚£ćƒƒć‚Æć‚¹ć€‚ none ć‚’ęŒ‡å®šć™ć‚‹ćØćƒ—ćƒ¬ćƒ•ć‚£ćƒƒć‚Æć‚¹ć‚’ä½æē”Ø恗ćŖ恄ćØć„ć†ę„å‘³ć«ćŖ悋怂 ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®å€¤ćÆ态 $ 怂
doma.expr.functions
å¼ć‚³ćƒ”ćƒ³ćƒˆć§åˆ©ē”ØåÆčƒ½ćŖé–¢ę•°ē¾¤ć‚’č”Ø恙ć‚Æćƒ©ć‚¹ć®å®Œå…Øäæ®é£¾åć€‚ org.seasar.doma.expr.ExpressionFunctions ć®ć‚µćƒ–ć‚æ悤惗恧ćŖ恑悌恰恄恑ćŖ恄怂 ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®å€¤ćÆ态 org.seasar.doma.expr.ExpressionFunctions 怂
doma.resources.dir
SQLćƒ•ć‚”ć‚¤ćƒ«ćŖ恩ćƒŖć‚½ćƒ¼ć‚¹ćƒ•ć‚”ć‚¤ćƒ«ć®å‡ŗåŠ›å…ˆćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖ怂 ēµ¶åÆ¾ćƒ‘ć‚¹ć§ęŒ‡å®šć™ć‚‹ć€‚ ęŒ‡å®šć—ćŖć„å “åˆćÆć‚Æćƒ©ć‚¹ćƒ•ć‚”ć‚¤ćƒ«ć®å‡ŗåŠ›å…ˆćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖ恌ä½æ悏悌悋怂
doma.sql.validation
SQLćƒ•ć‚”ć‚¤ćƒ«ć®å­˜åœØ惁悧惃ć‚ÆćØSQLć‚³ćƒ”ćƒ³ćƒˆć®ę–‡ę³•ćƒć‚§ćƒƒć‚Æć‚’č”Œć†å “åˆćÆ true 怂 č”Œć‚ćŖć„å “åˆćÆ false 怂 ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®å€¤ćÆ态 true 怂
doma.version.validation
ę³Ø釈処ē†ć«ć‚ˆć‚‹ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ē”Ÿęˆć§åˆ©ē”Ø恗恟Domać®ćƒćƒ¼ć‚øćƒ§ćƒ³ćØå®Ÿč”Œę™‚ć®Domać®ćƒćƒ¼ć‚øćƒ§ćƒ³ćŒåŒć˜ć§ć‚ć‚‹ć“ćØ悒 惁悧惃ć‚Æć™ć‚‹å “åˆćÆ true 怂 恗ćŖć„å “åˆćÆ false 怂 Domać®ć‚ć‚‹ćƒćƒ¼ć‚øćƒ§ćƒ³ć§ē”Ÿęˆć•ć‚ŒćŸć‚³ćƒ¼ćƒ‰ć‚’å«ć‚€ćƒ©ć‚¤ćƒ–ćƒ©ćƒŖć‚’ä½œęˆć™ć‚‹å “åˆć« false ć‚’ęŒ‡å®šć—ć¦ćƒ“ćƒ«ćƒ‰ć™ć‚‹ćØ态 ćć®ćƒ©ć‚¤ćƒ–ćƒ©ćƒŖć®å†åˆ©ē”Øę€§ćŒé«˜ć¾ć‚Šć¾ć™ć€‚ ćƒ©ć‚¤ćƒ–ćƒ©ćƒŖćŒä¾å­˜ć™ć‚‹Domać®ćƒćƒ¼ć‚øćƒ§ćƒ³ćØćÆē•°ćŖć‚‹ćƒćƒ¼ć‚øćƒ§ćƒ³ć®Domać§å®Ÿč”Œć§ćć‚‹ć‹ć‚‰ć§ć™ ļ¼ˆDomać®ćƒćƒ¼ć‚øćƒ§ćƒ³ć«äŗ’ę›ę€§ćŒć‚ć‚‹é™ć‚Šć«ćŠć„ć¦ļ¼‰ć€‚ ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®å€¤ćÆ态 true 怂
doma.config.path
ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć®čØ­å®šćƒ•ć‚”ć‚¤ćƒ«ć‚’ē½®ćå “ę‰€ć®ęŒ‡å®šć€‚ ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®å€¤ćÆ态 doma.compile.config怂

EclipseĀ¶

惗惭ć‚ø悧ć‚Æćƒˆć®ć€ŒProperties怍-怌Java Compiler怍-怌Annotation Processingć€ć®é …ē›®ć§ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć‚’ē™»éŒ²ć—ć¾ć™ć€‚

javacĀ¶

-Ać‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć«ć‚ˆć‚Šē™»éŒ²ć—ć¾ć™ć€‚ č©³ē“°ćÆjavacć®ćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆć‚’å‚ē…§ć—ć¦ćć ć•ć„ć€‚

GradleĀ¶

compileJava.options.compilerArgs ć«ęŒ‡å®šć—ć¾ć™ć€‚

compileJava.options.compilerArgs = ['-Adoma.dao.subpackage=impl', '-Adoma.dao.suffix=Impl']

čØ­å®šćƒ•ć‚”ć‚¤ćƒ«Ā¶

ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆ main/resources/doma.compile.config ćƒ•ć‚”ć‚¤ćƒ«ć«ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć‚’čؘčæ°ć—ć¦ćŠćć“ćØ恧态 ćƒ“ćƒ«ćƒ‰ćƒ„ćƒ¼ćƒ«ć”ćØ恮ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć®čØ­å®šć‚’åˆ©ē”Ø恙悋åæ…č¦ćŒćŖ恏ćŖć‚Šć¾ć™ć€‚ čؘčæ°å½¢å¼ćÆćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćƒ•ć‚”ć‚¤ćƒ«ćØåŒę§˜ć§ć™ć€‚ ćŖ恊态čØ­å®šćŒćƒćƒƒćƒ†ć‚£ćƒ³ć‚°ć—ćŸå “åˆć€ćƒ“ćƒ«ćƒ‰ćƒ„ćƒ¼ćƒ«ć”ćØ恮ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć®čØ­å®šćŒå„Ŗå…ˆć•ć‚Œć¾ć™ć€‚

ćƒ“ćƒ«ćƒ‰Ā¶

Maven Central RepositoryĀ¶

Doma 恮 jar ćƒ•ć‚”ć‚¤ćƒ«ćÆ Maven Central Repository ć‹ć‚‰å…„ę‰‹ć§ćć¾ć™ć€‚ GroupId ćØ ArtifactId ć®åē§°ćÆ仄äø‹ć®é€šć‚Šć§ć™ć€‚

GroupId:org.seasar.doma
ArtifactId:doma

Eclipse 悒ä½æć£ćŸćƒ“ćƒ«ćƒ‰Ā¶

Eclipse ć§ćƒ“ćƒ«ćƒ‰ć‚’č”Œć†éš›ć®ćƒć‚¤ćƒ³ćƒˆćÆ仄äø‹ć®é€šć‚Šć§ć™ć€‚

  • 惗惭ć‚ø悧ć‚Æ惈恮čØ­å®šć§ę³Ø釈処ē†ć‚’ęœ‰åŠ¹ć«ć™ć‚‹
  • Build Path ć«åŠ ćˆć¦ Factory Path 恫悂 Doma 恮 jar ćƒ•ć‚”ć‚¤ćƒ«ć‚’čØ­å®šć™ć‚‹

ćƒŽćƒ¼ćƒˆ

ę‰‹å‹•ć§čØ­å®šć™ć‚‹ć‚ˆć‚Šć‚‚ Gradle 恮 eclipse ć‚æć‚¹ć‚Æ恧č‡Ŗ動čØ­å®šć™ć‚‹ć“ćØ悒ęŽØå„Øć—ć¾ć™ć€‚ č©³ē“°ć«ć¤ć„恦ćÆ态 domaframework/simple-boilerplate ć«å«ć¾ć‚Œć‚‹ build.gradle ćØ eclipse.gradle ć‚’å‚ē…§ćć ć•ć„怂

ę³Ø釈処ē†ć®ęœ‰åŠ¹åŒ–Ā¶

ę³Ø釈処ē†ć‚’ęœ‰åŠ¹åŒ–ć™ć‚‹ć«ćÆć€ćƒ”ćƒ‹ćƒ„ćƒ¼ć‹ć‚‰ Project > Properties 悒éø悓恧ē”»é¢ć‚’é–‹ć å·¦ć®ćƒ”ćƒ¦ćƒ¼ć‹ć‚‰ Java Compiler > Annotation Processing 悒éøęŠžć—ć¾ć™ć€‚

ćć—ć¦ć€äø‹čØ˜ć«ē¤ŗ恙惁悧惃ć‚Æ惜惃ć‚Æć‚¹ć«ćƒć‚§ćƒƒć‚Æć‚’å…„ć‚Œć¾ć™ć€‚

_images/annotation-processing.png

Factory Path 恮čح定Ā¶

ę³Ø釈処ē†ć‚’ęœ‰åŠ¹åŒ–ć™ć‚‹ć«ćÆć€ćƒ”ćƒ‹ćƒ„ćƒ¼ć‹ć‚‰ Project > Properties 悒éø悓恧ē”»é¢ć‚’é–‹ć å·¦ć®ćƒ”ćƒ¦ćƒ¼ć‹ć‚‰ Java Compiler > Annotation Processing > Factory Path 悒éøęŠžć—ć¾ć™ć€‚

ćć—ć¦ć€äø‹čØ˜ć«ē¤ŗ恙惁悧惃ć‚Æ惜惃ć‚Æć‚¹ć«ćƒć‚§ćƒƒć‚Æć‚’å…„ć‚Œć€ ćƒ“ćƒ«ćƒ‰ćƒ‘ć‚¹ć§ęŒ‡å®šć—ć¦ć„ć‚‹ć®ćØåŒć˜ćƒćƒ¼ć‚øćƒ§ćƒ³ć® Doma 恮 jar 悒ē™»éŒ²ć—ć¾ć™ć€‚

_images/factory-path.png

Gradle 悒ä½æć£ćŸćƒ“ćƒ«ćƒ‰Ā¶

Gradle ć§ćƒ“ćƒ«ćƒ‰ć‚’č”Œć†éš›ć®ćƒć‚¤ćƒ³ćƒˆćÆ仄äø‹ć®ćØ恊悊恧恙怂

  • Javać‚Æćƒ©ć‚¹ćØSQLćƒ•ć‚”ć‚¤ćƒ«ć®å‡ŗåŠ›å…ˆćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖć‚’åŒć˜ć«ć™ć‚‹
  • ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć‚ˆć‚Šå‰ć«SQLćƒ•ć‚”ć‚¤ćƒ«ć‚’å‡ŗåŠ›å…ˆćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖć«ć‚³ćƒ”ćƒ¼ć™ć‚‹
  • 依存関äæ‚恮čØ­å®šć§domaćøć®ä¾å­˜ć‚’ęŒ‡å®šć™ć‚‹

ć‚µćƒ³ćƒ—ćƒ«ć®build.gradle恧恙怂

apply plugin: 'java'

// Javać‚Æćƒ©ć‚¹ćØSQLćƒ•ć‚”ć‚¤ćƒ«ć®å‡ŗåŠ›å…ˆćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖć‚’åŒć˜ć«ć™ć‚‹
processResources.destinationDir = compileJava.destinationDir
// ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć‚ˆć‚Šå‰ć«SQLćƒ•ć‚”ć‚¤ćƒ«ć‚’å‡ŗåŠ›å…ˆćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖć«ć‚³ćƒ”ćƒ¼ć™ć‚‹ćŸć‚ć«ä¾å­˜é–¢äæ‚ć‚’é€†č»¢ć™ć‚‹
compileJava.dependsOn processResources

repositories {
    mavenCentral()
    maven {url 'https://oss.sonatype.org/content/repositories/snapshots/'}
}

dependencies {
    compile "org.seasar.doma:doma:2.16.1"
}

ćƒŽćƒ¼ćƒˆ

ćƒŖ惝ć‚ø惈ćƒŖ恫恊恑悋 https://oss.sonatype.org/content/repositories/snapshots/ 恮čح定ćÆ Doma 恮 SNAPSHOT ć‚’å‚ē…§ć—ćŸć„å “åˆć«ć®ćæåæ…要恧恙怂

Doma 恮 SNAPSHOT ćÆ Travis-CI ć§ćƒ“ćƒ«ćƒ‰ćŒęˆåŠŸć•ć‚Œć‚‹ćŸć³ć«ä½œęˆć•ć‚ŒćƒŖ惝ć‚ø惈ćƒŖć«é…ē½®ć•ć‚Œć¾ć™ć€‚

Gradle 悒ä½æć£ćŸć‚ˆć‚Šč©³ē“°ćŖćƒ“ćƒ«ćƒ‰ć‚¹ć‚ÆćƒŖćƒ—ćƒˆć®ä¾‹ćØ恗恦态 domaframework/simple-boilerplate ć‚’å‚ē…§ć«ć—ć¦ćć ć•ć„ć€‚

Lombok ć‚µćƒćƒ¼ćƒˆĀ¶

Doma ćÆ Lombok ć®ćƒćƒ¼ć‚øćƒ§ćƒ³ 1.16.12 仄äøŠć‚’ć‚µćƒćƒ¼ćƒˆć—ć¦ć„ć¾ć™ć€‚

ćƒŽćƒ¼ćƒˆ

IDE ćØ恗恦 Eclipse ć‚’åˆ©ē”Øć™ć‚‹å “åˆćÆćƒćƒ¼ć‚øćƒ§ćƒ³ 4.5 仄äøŠć‚’ä½æć£ć¦ćć ć•ć„ć€‚ 4.5 ęœŖęŗ€ć§ćÆć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćƒ—ćƒ­ćƒƒć‚µć§å–å¾—ć•ć‚Œć‚‹ć‚Æćƒ©ć‚¹ć«å®šē¾©ć•ć‚ŒćŸćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ćŖ恩恮äø¦ć³ćŒć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ć«čØ˜č¼‰ć•ć‚Œć¦ć„ć‚‹é †åŗćØē•°ćŖ悊态 ę­£ć—ćå‹•ä½œć—ćŖ恄恟悁恧恙怂

Lombok ć‚µćƒćƒ¼ćƒˆć®ę¦‚č¦Ā¶

Lombok ćØ Doma ćÆå…±ć« JSR 269 ć§č¦å®šć•ć‚ŒćŸć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćƒ—ćƒ­ć‚»ćƒƒć‚µć‚’ęä¾›ć—ć¦ć„ć¾ć™ćŒć€ Lombok ćØ Doma ć‚’åŒę™‚ć«åˆ©ē”Øć™ć‚‹å “åˆćÆć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćƒ—ćƒ­ć‚»ćƒƒć‚µć®å‡¦ē†é †åŗćŒå•é”Œć«ćŖ悋恓ćØćŒć‚ć‚Šć¾ć™ć€‚ ä¾‹ćˆć°ć€ Lombok ć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćƒ—ćƒ­ć‚»ćƒƒć‚µćŒć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ悒ē”Ÿęˆć—态 Doma ć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćƒ—ćƒ­ć‚»ćƒƒć‚µćŒćć®ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ悒čŖ­ćæå–ć‚‹å “åˆćŖ恩恧恙怂 仮恫态Doma ć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćƒ—ćƒ­ć‚»ćƒƒć‚µćŒå…ˆć«å®Ÿč”Œć•ć‚Œć‚‹ćØå˜ć«ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æćŒå®šē¾©ć•ć‚Œć¦ć„ćŖ恄悂恮ćØć—ć¦å‹•ä½œć—ć€ ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć«å¤±ę•—ć—ć¾ć™ć€‚

ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćƒ—ćƒ­ć‚»ćƒƒć‚µć®å‡¦ē†é †åŗć‚’ęŒ‡å®šć§ćć‚Œć°ć“ć®å•é”ŒćÆč§£ę±ŗć™ć‚‹ć®ć§ć™ćŒć€ ꮋåæµćŖćŒć‚‰å‡¦ē†é †åŗćŒäæčØ¼ć•ć‚ŒćŖ恄恓ćØćŒä»•ę§˜ć«čØ˜č¼‰ć•ć‚Œć¦ćŠć‚Šć€å®Ÿéš›ć«å•é”Œč§£ę±ŗ恮仕ēµ„ćæćÆęä¾›ć•ć‚Œć¦ć„ć¾ć›ć‚“ć€‚

Doma 恧ćÆć€ć“ć®å•é”Œć«åƾåæœć™ć‚‹ćŸć‚ć«ć€Lombok ć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć®ęœ‰ē„”悒čŖč­˜ć—ć¦å‡¦ē†é †åŗć«ä¾å­˜ć«ć—ćŖ恄ęŒÆć‚‹čˆžć„ć‚’ć™ć‚‹ć‚ˆć†ć«ć—ć¦ć„ć¾ć™ć€‚ å…ˆć»ć©ć®ä¾‹ć§čØ€ćˆć°ć€ @lombok.Value ćŖć©ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ悒ē”Ÿęˆć™ć‚‹Lombokć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ćŒå­˜åœØć™ć‚‹å “åˆćÆ å®Ÿéš›ć«ćÆć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ悒čŖ­ćæå–ć‚‰ćŖćć¦ć‚‚ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æćŒå­˜åœØ恙悋悂恮ćØć—ć¦å‹•ä½œć™ć‚‹ćØ恄恆恓ćØ恧恙怂

Lombok 利ē”Øć®ćƒ™ć‚¹ćƒˆćƒ—ćƒ©ć‚Æćƒ†ć‚£ć‚¹Ā¶

Lombok ć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ē”Ø恄恟ć‚Æćƒ©ć‚¹ć®å®šē¾©ć«ć¤ć„恦ęŽØå„Øć™ć‚‹ę–¹ę³•ć‚’čØ˜č¼‰ć—ć¾ć™ć€‚

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹Ā¶

immutableļ¼ˆć‚¤ćƒŸćƒ„ćƒ¼ć‚æćƒ–ćƒ«ļ¼‰Ā¶

ć‚¤ćƒŸćƒ„ćƒ¼ć‚æćƒ–ćƒ«ćŖć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć‚’å®šē¾©ć™ć‚‹å “合ćÆäø‹čØ˜ć®ē‚¹ć«ę³Øę„ć—ć¾ć™ć€‚

  • @Entity 恮 immutable 要ē“ ć« true 悒čØ­å®šć™ć‚‹
  • @lombok.Value 悂恗恏ćÆ @lombok.AllArgsConstructor 悒ę³Ø釈恙悋
  • @lombok.AllArgsConstructor 悒éøć‚“ć å “åˆć€getter悒ē”Ÿęˆć™ć‚‹ćŸć‚ć«ćÆ @lombok.Getter 悒ę³Ø釈恙悋
@Entity(immutable = true)
@Value
public class Employee {
  @Id
  Integer id;
  String name;
  Age age;
}
@Entity(immutable = true)
@AllArgsConstructor
@Getter
public class Worker {
  @Id
  private final Integer id;
  private final String name;
  private final Age age;
}
mutableļ¼ˆćƒŸćƒ„ćƒ¼ć‚æćƒ–ćƒ«ļ¼‰Ā¶

ćƒŸćƒ„ćƒ¼ć‚æćƒ–ćƒ«ćŖć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć‚’å®šē¾©ć™ć‚‹å “合ćÆäø‹čØ˜ć®ē‚¹ć«ę³Øę„ć—ć¾ć™ć€‚

  • ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æć‚’å®šē¾©ć™ć‚‹ļ¼ˆćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ恮ē”Ÿęˆć‚’ęŠ‘åˆ¶ć—ćŖ恄ļ¼‰
  • getter/setter悒ē”Ÿęˆć™ć‚‹å “合ćÆ @lombok.Data 悂恗恏ćÆ @lombok.Getter / @lombok.Setter 悒ę³Ø釈恙悋
@Entity
@Data
public class Person {
  @Id
  private Integer id;
  private String name;
  private Age age;
}
@Entity
@Getter
@Setter
public class Businessman {
  @Id
  private Integer id;
  private String name;
  private Age age;
}

ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹Ā¶

ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć‚’å®šē¾©ć™ć‚‹å “合ćÆäø‹čØ˜ć®ē‚¹ć«ę³Øę„ć—ć¾ć™ć€‚

  • @lombok.Value 悒ę³Ø釈恙悋
  • ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ćÆ1ć¤ć ć‘å®šē¾©ć—名前ćÆ value 恫恙悋
@Domain(valueType = Integer.class)
@Value
public class Age {
  Integer value;
}

ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«ć‚Æćƒ©ć‚¹Ā¶

ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«ć‚Æćƒ©ć‚¹ć‚’å®šē¾©ć™ć‚‹å “合ćÆäø‹čØ˜ć®ē‚¹ć«ę³Øę„ć—ć¾ć™ć€‚

  • @lombok.Value 悂恗恏ćÆ @lombok.AllArgsConstructor 悒ę³Ø釈恙悋
  • @lombok.AllArgsConstructor 悒éøć‚“ć å “åˆć€getter悒ē”Ÿęˆć™ć‚‹ćŸć‚ć«ćÆ @lombok.Getter 悒ę³Ø釈恙悋
@Embeddable
@Value
public class Address {
  String street;
  String city;
}
@Embeddable
@AllArgsConstructor
@Getter
public class Location {
  private final String street;
  private final String city;
}

Kotlin ć‚µćƒćƒ¼ćƒˆĀ¶

Doma ćÆ Kotlin 1.1.2ć‚’å®Ÿéؓēš„ć«ć‚µćƒćƒ¼ćƒˆć—ć¦ć„ć¾ć™ć€‚

Kotlin利ē”Øć®ćƒ™ć‚¹ćƒˆćƒ—ćƒ©ć‚Æćƒ†ć‚£ć‚¹Ā¶

ć‚Æćƒ©ć‚¹ć®å®šē¾©ć‚„ćƒ“ćƒ«ćƒ‰ć«é–¢ć™ć‚‹äŗ‹ęŸ„恫恤恄恦ęŽØå„Øć™ć‚‹ę–¹ę³•ć‚’čØ˜č¼‰ć—ć¾ć™ć€‚

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹Ā¶

  • Data Classć§å®šē¾©ć™ć‚‹
  • ć‚¤ćƒŸćƒ„ćƒ¼ć‚æćƒ–ćƒ«ć§å®šē¾©ć™ć‚‹ļ¼ˆ @Entity 恮 immutable 要ē“ ć« true 悒čØ­å®šć™ć‚‹ļ¼‰
  • ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æćÆ1ć¤ć ć‘å®šē¾©ć™ć‚‹
  • ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æä»„å¤–ć§ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć‚’å®šē¾©ć—ćŖ恄
  • ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æć§å®šē¾©ć™ć‚‹ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć«ćÆ val 悒ä½æē”Ø恙悋
@Entity(immutable = true)
data class Person(
      @Id
      @GeneratedValue(strategy = org.seasar.doma.GenerationType.IDENTITY)
      val id: Int? = null,
      val name: Name,
      val address: Address)

ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹Ā¶

  • Data Classć§å®šē¾©ć™ć‚‹
  • ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æćÆ1ć¤ć ć‘å®šē¾©ć™ć‚‹
  • ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æć§å®šē¾©ć™ć‚‹ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®åå‰ćÆ value 恫恙悋
  • ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æć§å®šē¾©ć™ć‚‹ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć«ćÆ val 悒ä½æē”Ø恙悋
@Domain(valueType = String::class)
data class Name(val value: String)

ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«ć‚Æćƒ©ć‚¹Ā¶

  • Data Classć§å®šē¾©ć™ć‚‹
  • ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æćÆ1ć¤ć ć‘å®šē¾©ć™ć‚‹
  • ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æä»„å¤–ć§ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć‚’å®šē¾©ć—ćŖ恄
  • ć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æć§å®šē¾©ć™ć‚‹ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć«ćÆ val 悒ä½æē”Ø恙悋
@Embeddable
data class Address(val city: String, val street: String)

Daoć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹Ā¶

  • Kotlin恧ćÆćŖ恏Javać§å®šē¾©ć™ć‚‹
  • ę›“ę–°å‡¦ē†ć®ęˆ»ć‚Šå€¤ć®åž‹ćÆ org.seasar.doma.jdbc.Result 悄 org.seasar.doma.jdbc.BatchResult 悒ä½æ恆
@Dao(config = AppConfig.class)
public interface PersonDao {
  @Select
  Person selectById(Integer id);
  @Insert
  Result<Person> insert(Person person);
}
val dao: PersonDao = ...
val person = Person(name = Name("Jhon"), address = Address(city = "Tokyo", street = "Yaesu"))
val (newPerson, count) = dao.insert(person)

kaptć«ć‚ˆć‚‹ćƒ“ćƒ«ćƒ‰Ā¶

Kotlin恧čؘčæ°ć•ć‚ŒćŸć‚Æćƒ©ć‚¹ć‚„ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć«åÆ¾ć—ć¦ę³Ø釈処ē†ć‚’恙悋恫ćÆ kapt ć‚’å®Ÿč”Œć™ć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚ kaptćÆ実éؓēš„ćŖ位ē½®ä»˜ć‘ć«ć‚ć‚Šćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆćŒć‚ć‚Šć¾ć›ć‚“ć€‚ Gradleć§ćƒ“ćƒ«ćƒ‰ć™ć‚‹éš›ćÆ态ē¢ŗ実ćŖę³Ø釈処ē†ćŒč”Œć‚ć‚Œć‚‹ć‚ˆć†ć«åøø恫 clean build ć‚’å®Ÿč”Œć™ć‚‹ć“ćØ悒ęŽØå„Øć—ć¾ć™ć€‚

./gradlew clean build

Eclispeć‚’åˆ©ē”Øć™ć‚‹å “åˆčØ­å®šć‚’é©åˆ‡ć«č”Œćˆć°Java恮ę³Ø釈処ē†ćÆč‡Ŗå‹•ć§č”Œć‚ć‚Œć¾ć™ćŒć€kaptļ¼ˆKotlin恮ę³Ø釈処ē†ļ¼‰ćÆGradleć‚’å®Ÿč”Œć—ćŖć„é™ć‚Šč”Œć‚ć‚ŒćŖ恄恓ćØ恫ę³Øę„ć—ć¦ćć ć•ć„ć€‚

äø‹čؘćÆbuild.gradleć®ęŠœē²‹ć§ć™ć€‚ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ę™‚ć«SQLćƒ•ć‚”ć‚¤ćƒ«ć‚’å‚ē…§ć™ć‚‹ćŸć‚ć«äø‹čØ˜ć®čØ­å®šć«ē‰¹ć«ę³Øę„ć—ć¦ćć ć•ć„ć€‚

// ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć‚ˆć‚Šå‰ć«SQLćƒ•ć‚”ć‚¤ćƒ«ć‚’å‡ŗåŠ›å…ˆćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖć«ć‚³ćƒ”ćƒ¼ć™ć‚‹ćŸć‚ć«ä¾å­˜é–¢äæ‚ć‚’é€†č»¢ć™ć‚‹
compileJava.dependsOn processResources

// SQLćƒ•ć‚”ć‚¤ćƒ«ćŖ恩ćƒŖć‚½ćƒ¼ć‚¹ćƒ•ć‚”ć‚¤ćƒ«ć®å‡ŗåŠ›å…ˆćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖ悒kaptć«ä¼ćˆć‚‹
kapt {
    arguments {
        arg("doma.resources.dir", processResources.destinationDir)
    }
}

JavaćØKotlin恮귷åœØĀ¶

kapt恮äøē¢ŗ実ćŖęŒ™å‹•ć‚’éæ恑悋恟悁态Domać«é–¢ć™ć‚‹ć‚³ćƒ¼ćƒ‰ć®å…Ø恦悒Java恧ę›ø恏恓ćØćÆꤜčØŽć«å€¤ć—ć¾ć™ć€‚ Domać®åˆ©ē”Ø恫恊恄恦态JavaćØKotlin恮귷åœØćÆå•é”Œć‚ć‚Šć¾ć›ć‚“ć€‚

ć‚µćƒ³ćƒ—ćƒ«ćƒ—ćƒ­ć‚ø悧ć‚Æ惈Ā¶

ć‚µćƒ³ćƒ—ćƒ«ć‚³ćƒ¼ćƒ‰ć«ć¤ć„ć¦ćÆäø‹čØ˜ć®ćƒ—ćƒ­ć‚ø悧ć‚Æćƒˆć‚’å‚ē…§ćć ć•ć„怂

Developer DocumentationĀ¶

Doma 恮開ē™ŗĀ¶

ćƒŽćƒ¼ćƒˆ

ć“ć®ćƒšćƒ¼ć‚øćÆ Doma 恮開ē™ŗč€…ć«å‘ć‘ć¦ę›øć‹ć‚Œć¦ć„ć¾ć™ć€‚

ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰Ā¶

$ git clone https://github.com/domaframework/doma.git

ćƒ“ćƒ«ćƒ‰Ā¶

$ ./gradlew build

Maven ćƒ­ćƒ¼ć‚«ćƒ«ćƒŖ惝ć‚ø惈ćƒŖćøć®ć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«Ā¶

$ ./gradlew build install

ćƒŽćƒ¼ćƒˆ

ćƒ­ćƒ¼ć‚«ćƒ«ć§äæ®ę­£ć‚’åŠ ćˆćŸć‚³ćƒ¼ćƒ‰ć«åÆ¾ć—ć¦ ēµ±åˆćƒ†ć‚¹ćƒˆ ć‚’å®Ÿč”Œć™ć‚‹ć«ćÆ态 ćƒ­ćƒ¼ć‚«ćƒ«ć® Maven ćƒŖ惝ć‚ø惈ćƒŖ恫 Doma ęœ¬ä½“ć®ęˆęžœē‰©ć‚’äŗ‹å‰ć«ć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«ć—ć¦ćŠćåæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚

EclipseĀ¶

Eclipse 恮čØ­å®šćƒ•ć‚”ć‚¤ćƒ«ć‚’ē”Ÿęˆć§ćć¾ć™ć€‚

$ ./gradlew eclipse

Continuous IntegrationĀ¶

Continuous Integration ć®å®Ÿč”Œć«ćÆ Travis CI ć‚’åˆ©ē”Øć—ć¦ć„ć¾ć™ć€‚

ćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆĀ¶

ćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆć®ä½œęˆć«ćÆ Sphinx ć‚’åˆ©ē”Øć—ć¦ć„ć¾ć™ć€‚

ē’°å¢ƒę§‹ēƉĀ¶

$ cd docs
$ pip install -r requirements.txt

LiveReloadĀ¶

Google Chrome 恫 LiveReload ć‚’ć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«ć™ć‚‹ć“ćØ恧 ćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆć®äæ®ę­£ć‚’即åŗ§ć«ćƒ–ćƒ©ć‚¦ć‚¶ć§ē¢ŗčŖć§ćć¾ć™ć€‚

ć“ć®ę‹”å¼µę©Ÿčƒ½ć‚’ęœ‰åŠ¹ć«ć—ćŸäøŠć§ć‚µćƒ¼ćƒćƒ¼ć‚’čµ·å‹•ć—ć¾ć™ć€‚

$ python server.py

ꬔ恮 URL ć§ćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆć‚’ē¢ŗčŖć§ćć¾ć™ć€‚

ēµ±åˆćƒ†ć‚¹ćƒˆĀ¶

ćƒŽćƒ¼ćƒˆ

ć“ć®ćƒšćƒ¼ć‚øćÆ Doma 恮開ē™ŗč€…ć«å‘ć‘ć¦ę›øć‹ć‚Œć¦ć„ć¾ć™ć€‚

ēµ±åˆćƒ†ć‚¹ćƒˆć®ē›®ēš„ćÆ2恤恧恙怂

  • Eclipse 悄 javac 恮ę³Ø釈処ē†ć®ęŒ™å‹•ć‚’ćƒ†ć‚¹ćƒˆć™ć‚‹
  • ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ćøć®ć‚¢ć‚Æć‚»ć‚¹ć‚’ä¼“ć†ę©Ÿčƒ½ć‚’ćƒ†ć‚¹ćƒˆć™ć‚‹

ēµ±åˆćƒ†ć‚¹ćƒˆć§ćÆ RDBMS 悒ä½æć£ćŸćƒ†ć‚¹ćƒˆć‚’č”Œć„ć¾ć™ć€‚ ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ä½æē”Ø恙悋 RDBMS ćÆ H2 Database Engine 恧恙怂

ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰Ā¶

$ git clone https://github.com/domaframework/doma-it.git

ćƒ“ćƒ«ćƒ‰Ā¶

$ ./gradlew build

EclipseĀ¶

Eclipse 恮čØ­å®šćƒ•ć‚”ć‚¤ćƒ«ć‚’ē”Ÿęˆć§ćć¾ć™ć€‚

$ ./gradlew eclipse

ćƒ•ć‚”ć‚Æ惈ćƒŖćƒ‘ć‚¹ć®čØ­å®šć‚‚č”Œć‚ć‚Œć¾ć™ć€‚

Continuous IntegrationĀ¶

Travis CI ć‚’åˆ©ē”Øć—ć¦ć„ć¾ć™ć€‚

仄äø‹ć® RDBMS ć‚’åˆ©ē”Øć—ćŸćƒ†ć‚¹ćƒˆć‚’å®Ÿč”Œć—ć¦ć„ć¾ć™ć€‚

  • H2 Database Engine
  • HSQLDB
  • MySQL
  • PostgreSQL

About DomaĀ¶

ćƒŖćƒŖćƒ¼ć‚¹ćƒŽćƒ¼ćƒˆĀ¶

v2.16.1: 2017-05-14Ā¶

  • GH196 Kotlin 1.1.2 ć‚’å®Ÿéؓēš„ć«ć‚µćƒćƒ¼ćƒˆ
  • GH195 Oracle 12c ä»„é™ć§IDENTITY悒ä½æć£ćŸč­˜åˆ„å­ć®č‡Ŗ動ē”Ÿęˆć‚’ć‚µćƒćƒ¼ćƒˆ
  • GH194 SelectBuilder 恫 params ćƒ”ć‚½ćƒƒćƒ‰ćØ literals ćƒ”ć‚½ćƒƒćƒ‰ć‚’čæ½åŠ 

v2.16.0: 2017-02-19Ā¶

  • GH191 čØ­å®šćƒ•ć‚”ć‚¤ćƒ«ć‹ć‚‰ę³Ø釈処ē†ć®ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć‚’čŖ­ćæč¾¼ć‚ć‚‹ć‚ˆć†ć«

v2.15.0: 2017-02-05Ā¶

  • GH184 Long name serial sequence
  • GH187 Eclipse 4.6.2 恧ꤜå‡ŗ恕悌恟ćƒÆćƒ¼ćƒ‹ćƒ³ć‚°ć‚’äæ®ę­£
  • GH188 Dao ć«ćŠć„ć¦ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆćƒ”ć‚½ćƒƒćƒ‰ć®ćæćŒå®šē¾©ć•ć‚ŒćŸć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć‚’ē¶™ę‰æåÆčƒ½ć«å¤‰ę›“

v2.14.0: 2017-01-14Ā¶

  • GH183 BatchUpdateExecutor, BatchDeleteExecutor, MapBatchInsertBuilder 悒čæ½åŠ 
  • GH182 ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«ć‚Æćƒ©ć‚¹ć«ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć‚’å®šē¾©ć—ćŖć„å “åˆć«ē”Ÿęˆć•ć‚Œć‚‹ć‚³ćƒ¼ćƒ‰ćŒć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć‚Øćƒ©ćƒ¼ć«ćŖć£ć¦ć„ćŸć®ć‚’äæ®ę­£
  • GH181 SQLćƒ†ćƒ³ćƒ—ćƒ¬ćƒ¼ćƒˆć§ēµ„ćæē«‹ć¦ć‚‰ć‚ŒćŸSQLć‚’ę‰±ć†ćŸć‚ć® @SqlProcessor 悒čæ½åŠ 
  • GH180 Lombok ć‚’ć‚µćƒćƒ¼ćƒˆ
  • GH179 StandardExpressionFunctions#escape恌escapeChar悒ä½æē”Ø恗恦恄ćŖ恄
  • GH177 Kotlin 1.0.6åƾåæœ
  • GH176 BatchInsertExecutor悒čæ½åŠ 
  • GH175 ēµ„ćæč¾¼ćæé–¢ę•°ć® LocalDate, LocalDateTime åƾåæœ
  • GH174 Mapć‚’ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æćØ恗恦č‡Ŗå‹•ć§Insertꖇ悒ēµ„ćæē«‹ć¦ć‚‹MapInsertBuilder悒čæ½åŠ 

v2.13.0: 2016-11-13Ā¶

  • GH170 č­˜åˆ„å­ć‚’ćƒ—ćƒŖćƒŸćƒ†ć‚£ćƒ–åž‹ć«ć™ć‚‹å “åˆć®ę³Øꄏē‚¹ć‚’čØ˜č¼‰
  • GH167 Doma 2 恫恊恑悋äø»č¦ćŖå¤‰ę›“ē‚¹ć«čØ˜č¼‰ć•ć‚ŒćŸć‚Æćƒ©ć‚¹åć®é–“é•ć„ć‚’äæ®ę­£

v2.12.1: 2016-08-06Ā¶

  • GH165 ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć®ē¶™ę‰æ꧋造恌2ę®µéšŽć®å “åˆć«ē„”é™ćƒ«ćƒ¼ćƒ—ćŒē™ŗē”Ÿć™ć‚‹äøå…·åˆć‚’äæ®ę­£

v2.12.0: 2016-07-14Ā¶

  • GH161 SQLćƒ•ć‚”ć‚¤ćƒ«ć®ć‚­ćƒ£ćƒƒć‚·ćƒ„ć‚’å‰Šé™¤ć™ć‚‹ćŸć‚ć®ćƒ”ć‚½ćƒƒćƒ‰ć‚’čæ½åŠ 
  • GH160 ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«ć‚Æćƒ©ć‚¹ć‚’ćƒć‚¹ćƒˆć—ćŸåž‹ćØć—ć¦å®šē¾©ć™ć‚‹ć“ćØć‚’ć‚µćƒćƒ¼ćƒˆ
  • GH159 ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć‚’ćƒć‚¹ćƒˆć—ćŸåž‹ćØć—ć¦å®šē¾©ć™ć‚‹ć“ćØć‚’ć‚µćƒćƒ¼ćƒˆ
  • GH158 ćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆć®ć‚³ćƒ”ćƒ¼ćƒ©ć‚¤ćƒˆć®ę—„ä»˜ć‚’ę›“ę–°
  • GH156 SQLćƒ•ć‚”ć‚¤ćƒ«ć®å­˜åœØ惁悧惃ć‚Æć§ćƒ‘ć‚¹ć®å¤§ę–‡å­—å°ę–‡å­—ć‚’åŒŗåˆ„ć™ć‚‹ć‚ˆć†ć«äæ®ę­£
  • GH155 fix typo

v2.11.0: 2016-06-18Ā¶

  • GH153 ć‚Æć‚ØćƒŖćƒ“ćƒ«ćƒ€ć§ćƒŖćƒ†ćƒ©ćƒ«ć®åŸ‹ć‚č¾¼ćæć‚’ć‚µćƒćƒ¼ćƒˆ
  • GH151 ćƒŖćƒ†ćƒ©ćƒ«å¤‰ę•°ć‚³ćƒ”ćƒ³ćƒˆć®ē›“å¾Œć®ćƒ†ć‚¹ćƒˆē”ØćƒŖćƒ†ćƒ©ćƒ«ć«åÆ¾ć™ć‚‹ćƒć‚§ćƒƒć‚Æ悒äæ®ę­£
  • GH150 ćƒŖćƒ†ćƒ©ćƒ«å¤‰ę•°ć‚³ćƒ”ćƒ³ćƒˆć®ę©Ÿčƒ½ć‚’čæ½åŠ 

v2.10.0: 2016-05-28Ā¶

  • GH146 Embeddable ćŖć‚Ŗ惖ć‚ø悧ć‚Æ惈恌 null ć®å “åˆć«ę›“ę–°ē³»ć®å‡¦ē†ćŒå¤±ę•—恙悋äøå…·åˆć‚’äæ®ę­£
  • GH145 Kotlin ć®ć‚µćƒćƒ¼ćƒˆć«ć¤ć„ć¦ćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆć‚’čæ½åŠ 
  • GH142 ć‚Øćƒ³ćƒ™ćƒƒćƒ€ćƒ–ćƒ«ć‚Æćƒ©ć‚¹ć®ćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆć‚’čæ½åŠ 
  • GH141 ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ćŒē¶™ę‰æć‚’ć—ć¦ć„ć‚‹å “åˆć®č¦Ŗćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ćøć®ć‚¢ć‚Æć‚»ć‚¹ę–¹ę³•ć‚’ē°”ę˜“åŒ–
  • GH140 惗ćƒŖćƒŸćƒ†ć‚£ćƒ–åž‹ć®ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć«nullćŒć‚¢ć‚µć‚¤ćƒ³ć•ć‚Œć‚‹å “åˆć«ä¾‹å¤–ćŒē™ŗē”Ÿć—ć¦ć„ćŸäøå…·åˆć‚’ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆå€¤ćŒčØ­å®šć•ć‚Œć‚‹ć‚ˆć†ć«äæ®ę­£
  • GH139 @Embeddable ć‚’ć‚µćƒćƒ¼ćƒˆ
  • GH138 Kotlin ć§ć‚¤ćƒŸćƒ„ćƒ¼ć‚æćƒ–ćƒ«ćŖć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚’å®šē¾©ć™ć‚‹éš› @ParameterName 悒ä½æē”Ø恙悋åæ…č¦ę€§ć‚’é™¤åŽ»

v2.9.0: 2016-05-16Ā¶

  • GH136 ꛓꖰēµęžœć‚’č”Ø恙ć‚Æćƒ©ć‚¹ć§ Kotlin 恮 Destructuring Declarations 恫åƾåæœ
  • GH135 ę³Ø釈処ē†ć§å‡ŗåŠ›ć™ć‚‹ćƒ”ćƒƒć‚»ćƒ¼ć‚ø恫态ć‚Æćƒ©ć‚¹ć€ćƒ”ć‚½ćƒƒćƒ‰ć€ćƒ•ć‚£ćƒ¼ćƒ‰åćŖ恩å‡ŗåŠ›å…ƒć®ęƒ…å ±ć‚’čæ½åŠ 
  • GH134 @Dao 恫 Singleton ć‚’ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć§ęä¾›ć™ć‚‹ć‚æć‚¤ćƒ—ć® Config ć‚’ęŒ‡å®šć™ć‚‹ć“ćØć‚’ć‚µćƒćƒ¼ćƒˆ
  • GH133 kapt 1.0.1-2ć®å®Ÿéؓēš„ćŖć‚µćƒćƒ¼ćƒˆ
  • GH132 Switching remote URLs from SSH to HTTPS
  • GH131 ē„”åćƒ‘ćƒƒć‚±ćƒ¼ć‚øć«é…ē½®ć—ćŸć‚Æćƒ©ć‚¹ć®ę³Ø釈処ē†ć«å¤±ę•—恙悋äøå…·åˆć‚’äæ®ę­£
  • GH130 ćƒ†ć‚¹ćƒˆć‚³ćƒ¼ćƒ‰ć®ę”¹å–„

v2.8.0: 2016-04-16Ā¶

  • GH127 ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć‚’ćƒć‚¹ćƒˆć—ćŸåž‹ćØć—ć¦å®šē¾©ć™ć‚‹ć“ćØć‚’ć‚µćƒćƒ¼ćƒˆ

v2.7.0: 2016-02-27Ā¶

  • GH125 SelectBuilder ć®ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć® FetchType 悒 Lazy 恫čح定
  • GH124 é–“é•ć£ćŸč­¦å‘Šćƒ”ćƒƒć‚»ćƒ¼ć‚ø悒äæ®ę­£
  • GH122 ꤜē“¢ē”Øćƒ”ć‚½ćƒƒćƒ‰ć®ęˆ»ć‚Šå€¤ć®åž‹ć‚’ Stream ćØ恙悋恓ćØ悒čŖć‚ćŸ
  • GH121 include恮čŖ¬ę˜ŽćŒé–“é•ć£ć¦ć„ćŸć®ć‚’äæ®ę­£

v2.6.2: 2016-02-11Ā¶

  • GH118 SQLć‚³ćƒ”ćƒ³ćƒˆ ć‚«ćƒ©ćƒ ćƒŖć‚¹ćƒˆå±•é–‹ć‚³ćƒ”ćƒ³ćƒˆ ćƒŖćƒ³ć‚Æäæ®ę­£
  • GH117 ćƒŖćƒ³ć‚Æć«é–¢é€£ć—ćŸJavadocē”Ÿęˆć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć‚’čæ½åŠ ć—ć¾ć—ćŸ
  • GH116 ć‚Æć‚ØćƒŖćƒ“ćƒ«ćƒ€ć®getSql()ć®å‘¼ć³å‡ŗ恗恧ć‚Øćƒ©ćƒ¼ćŒē™ŗē”Ÿć—ćŖć„ć‚ˆć†ć«äæ®ę­£
  • GH115 Spring Boot DevTools恫åƾåæœ

v2.6.1: 2016-01-11Ā¶

  • GH111 Revert “ę³Ø釈処ē†ć§ē”Ÿęˆć•ć‚Œć‚‹ć‚³ćƒ¼ćƒ‰ćŒå†—é•·ćŖć‚ø悧惍ćƒŖć‚Æć‚¹ć‚’å«ć‚€å•é”Œć‚’äæ®ę­£”

v2.6.0: 2015-11-21Ā¶

  • GH107 ę³Ø釈処ē†ć§ē”Ÿęˆć•ć‚Œć‚‹ć‚³ćƒ¼ćƒ‰ćŒå†—é•·ćŖåž‹å¼•ę•°ć‚’å«ć‚€å•é”Œć‚’äæ®ę­£
  • GH105 Fix cause position in UniqueConstraintException’s constructor

v2.5.1: 2015-11-01Ā¶

  • GH102 UnknownColumnHandler 恮 handle() 悒ē©ŗå®Ÿč£…ć«ć™ć‚‹ćØ NullPointerException 恌ē™ŗē”Ÿć™ć‚‹å•é”Œć‚’äæ®ę­£

v2.5.0: 2015-10-10Ā¶

  • GH99 ćƒćƒƒćƒę›“ę–°ć«ćŠć„ć¦ćƒ‘ćƒ•ć‚©ćƒ¼ćƒžćƒ³ć‚¹ćŒę‚Ŗ恏ćŖć‚‹å•é”Œć‚’ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć®IDENTITY悒äŗ‹å‰ć«äŗˆē“„恙悋恓ćØć§č§£ę±ŗ

v2.4.1: 2015-09-12Ā¶

  • GH96 åŸ‹ć‚č¾¼ćæå¤‰ę•°ć‚³ćƒ”ćƒ³ćƒˆć®å±•é–‹å¾Œć«ć‚¹ćƒšćƒ¼ć‚¹ć‚’ęŒæå…„ć—ćŖ恄

v2.4.0: 2015-08-14Ā¶

  • GH93 JdbcMappingHint#getDomainClass() ćŒćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć‚’čæ”恕ćŖć„å•é”Œć‚’äæ®ę­£
  • GH89 PortableObjectType悒ć‚ø悧惍ćƒŖć‚Æć‚¹ć«ć—ć¦ć€Stringē­‰ć‚’valueTypećØć—ć¦ęŒ‡å®šć§ćć‚‹ć‚ˆć†ć«
  • GH88 JdbcLoggerć®ćƒ”ć‚½ćƒƒćƒ‰ć®typo悒äæ®ę­£ć€‚ Failuer -> Failure
  • GH87 StandardExpressionFunctionsć®ć‚µćƒ–ć‚Æćƒ©ć‚¹ć«publicćŖć‚³ćƒ³ć‚¹ćƒˆćƒ©ć‚Æć‚æ悒čæ½åŠ 
  • GH86 Version number spec is different from the document
  • GH84 populate 悒ä½æć£ćŸćƒ”ć‚½ćƒƒćƒ‰ć§ DOMA4122 恌å‡ŗć‚‹å•é”Œć‚’äæ®ę­£
  • GH81 ćƒŖć‚½ćƒ¼ć‚¹ćƒćƒ³ćƒ‰ćƒ«ćŒå–å¾—ć§ććŖć„å “åˆćÆćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć®ćƒŖć‚½ćƒ¼ć‚¹ćƒćƒ³ćƒ‰ćƒ«ć«ćƒ•ć‚©ćƒ¼ćƒ«ćƒćƒƒć‚Æ恙悋

v2.3.1: 2015-05-30Ā¶

  • GH79 SQLćƒ•ć‚”ć‚¤ćƒ«ć‚’ä½æć£ćŸę›“ę–°ćŒć‚¹ć‚­ćƒƒćƒ—ć•ć‚Œć‚‹å•é”Œć‚’äæ®ę­£

v2.3.0: 2015-05-23Ā¶

  • GH75 SQLćƒ•ć‚”ć‚¤ćƒ«ć§UPDATEꖇ恮SETå„ć‚’č‡Ŗ動ē”Ÿęˆ
  • GH74 PostgresDialect恧IDē”Ÿęˆć‚Øćƒ©ćƒ¼ćŒē™ŗē”Ÿć™ć‚‹å•é”Œć‚’äæ®ę­£

v2.2.0: 2015-03-28Ā¶

  • GH71 ć‚¤ćƒ³ć‚æćƒ¼ćƒ•ć‚§ćƒ¼ć‚¹ć«ć‚‚@Domain恧ę³Øé‡ˆć§ćć‚‹ć‚ˆć†ć«ć—ć¾ć—ćŸ
  • GH70 EntityListenerć®å–å¾—ćÆEntityListenerProviderć‚’ä»‹ć™ć‚‹ć‚ˆć†ć«ć—ć¾ć—ćŸ
  • GH67 SQL Server 恮 OPTION å„ćŒå­˜åœØ恙悋ćØćƒšćƒ¼ć‚øćƒ³ć‚°ćŒę­£ć—ćå®Ÿč”Œć•ć‚ŒćŖć„å•é”Œć‚’äæ®ę­£ć—ć¾ć—ćŸ
  • GH66 ćƒćƒ¼ćƒŸćƒ³ć‚°č¦ē“„恮適ē”Øć‚’ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ę™‚ć‹ć‚‰å®Ÿč”Œę™‚ć«å¤‰ę›“
  • GH64 ć‚¤ćƒŸćƒ„ćƒ¼ć‚æćƒ–ćƒ«ćŖć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®å–å¾—ć§NullPointerException 恌ē™ŗē”Ÿć™ć‚‹ćƒć‚°ć‚’äæ®ę­£ć—ć¾ć—ćŸ
  • GH61 SQL Server 2012 恋悉čæ½åŠ ć•ć‚ŒćŸ OFFSET-FETCH ć‚’ćƒšćƒ¼ć‚øćƒ³ć‚°å‡¦ē†ć«ä½æ恆
  • GH60 Mssql2008Dialect 恮 getName() 恌čæ”ć™å€¤ć‚’å¤‰ę›“ć—ć¾ć—ćŸ
  • GH59 Windowsē’°å¢ƒć§ćƒ†ć‚¹ćƒˆćŒå¤±ę•—ć™ć‚‹å•é”Œć‚’äæ®ę­£
  • GH58 StringUtil恮fromCamelCaseToSnakeCaseć§ć€ć‚«ćƒ©ćƒ åć«ę•°å­—ćŒå«ć¾ć‚Œć¦ć„ć‚‹å “åˆę„å›³ć—ć¦ć„ć‚‹ēµęžœć«ćŖ悉ćŖ恄

v2.1.0: 2014-12-30Ā¶

  • GH51 LocalTransactionManager#notSupported()ćŒę–°č¦ć®ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³ć‚’ä½œęˆć™ć‚‹äøå…·åˆć‚’äæ®ę­£ć—ć¾ć—ćŸ
  • GH50 SQLć‚³ćƒ”ćƒ³ćƒˆć‚’ä½æć£ć¦SQLć«č­˜åˆ„å­ć‚’čæ½čØ˜ć§ćć‚‹ć‚ˆć†ć«ć—ć¾ć—ćŸ
  • GH49 Gradleć®ćƒ—ćƒ­ć‚ø悧ć‚Æćƒˆć®åå‰ć‚’”doma”恫čØ­å®šć—ć¾ć—ćŸ
  • GH48 /*%expand ćØ */ ć®é–“ć®ć‚¹ćƒšćƒ¼ć‚¹ćÆaliasćØćæćŖ恕ćŖć„ć‚ˆć†ć«ć—ć¾ć—ćŸ

v2.0.1: 2014-08-06Ā¶

  • DomainConverter 恮ē¬¬2åž‹å¼•ę•°ć« byte[] ć‚’ęŒ‡å®šć™ć‚‹ćØę³Ø釈処ē†ć§ć‚³ćƒ³ćƒ‘ć‚¤ćƒ« ć‚Øćƒ©ćƒ¼ć«ćŖć‚‹å•é”Œć‚’äæ®ę­£ć—ć¾ć—ćŸ

v2.0.0: 2014-07-02Ā¶

  • UnitOfWork ć‚’å‰Šé™¤ć—ć¾ć—ćŸ

v2.0-beta-5: 2014-06-07Ā¶

  • List<Optional<Emp>> 悄 List<Optional<Map<String, Object>>> ć‚’ęˆ»ć‚Šå€¤ćØ恙悋 Dao ćƒ”ć‚½ćƒƒćƒ‰ćÆę³Ø釈処ē†ć§ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ć‚Øćƒ©ćƒ¼ć«ć—ć¾ć—ćŸ
  • Entity ę›“ę–°å¾Œć« OriginalStates ćøå¤‰ę›“ćŒåę˜ ć•ć‚ŒćŖć„å•é”Œć‚’äæ®ę­£ć—ć¾ć—ćŸ
  • ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®č­˜åˆ„å­ć®å€¤ćŒć™ć§ć«čØ­å®šć•ć‚Œć¦ć„ć‚‹å “åˆćÆč‡Ŗ動ē”Ÿęˆå‡¦ē†ć‚’å®Ÿč”Œć—ćŖć„ć‚ˆć†ć«ć—ć¾ć—ćŸ
  • ć‚«ćƒ©ćƒ ćƒŖć‚¹ćƒˆå±•é–‹ć‚³ćƒ”ćƒ³ćƒˆ 恧 DOMA4257 ć‚Øćƒ©ćƒ¼ć«ćŖć‚‹å•é”Œć‚’äæ®ę­£ć—ć¾ć—ćŸ
  • SQLć®ćƒ­ć‚°å‡ŗåŠ›ę–¹ę³•ć‚’ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć§åˆ¶å¾”ć§ćć‚‹ć‚ˆć†ć«ć—ć¾ć—ćŸ
  • Dao 恋悉å‡ŗåŠ›ć•ć‚Œć‚‹ćƒ­ć‚°ć®ćƒ”ćƒƒć‚»ćƒ¼ć‚øć‚’č©³ē“°åŒ–ć—ć¾ć—ćŸ
  • UtilLoggingJdbcLogger ć®ćƒ­ć‚¬ćƒ¼ć®åå‰ć‚’ć‚Æćƒ©ć‚¹ć®å®Œå…Øäæ®é£¾åć«å¤‰ę›“ć—ć¾ć—ćŸ
  • SQLå®Ÿč”Œę™‚ć«SQLćƒ•ć‚”ć‚¤ćƒ«ć®ćƒ‘ć‚¹ćŒćƒ­ć‚°ć«å‡ŗåŠ›ć•ć‚ŒćŖć„å•é”Œć‚’äæ®ę­£ć—ć¾ć—ćŸ

v2.0-beta-4: 2014-05-04Ā¶

  • Pluggable Annotation Processing API 恮 Visitor 悒 Java 8 ē”Ø恮悂恮ćøćƒćƒ¼ć‚øćƒ§ćƒ³ć‚¢ćƒƒćƒ—ć—ć¾ć—ćŸ
  • ē©ŗ恮 java.util.Iterable 悒 IN å„ć«ćƒć‚¤ćƒ³ćƒ‰ć™ć‚‹å “åˆćÆ SQL 恮 null ćØć—ć¦ę‰±ć†ć‚ˆć†ć«ć—ć¾ć—ćŸ
  • java.sql.SQLXML 恫åƾåæœć—ć¾ć—ćŸ
  • LocalTransaction ć§ęŒ‡å®šć—ćŸć‚»ćƒ¼ćƒ–ćƒć‚¤ćƒ³ćƒˆć€Œä»„é™ć€ć‚’å‰Šé™¤ć™ć¹ćē®‡ę‰€ć§ć€Œä»„å‰ć€ć‚’å‰Šé™¤ć—ć¦ć„ć‚‹äøå…·åˆć‚’äæ®ę­£ć—ć¾ć—ćŸ
  • LocalTransaction ć§ć‚»ćƒ¼ćƒ–ćƒć‚¤ćƒ³ćƒˆå‰Šé™¤ę™‚ć®ćƒ­ć‚°ćŒé–“é•ć£ć¦ć„ć‚‹äøå…·åˆć‚’äæ®ę­£ć—ć¾ć—ćŸ
  • Entity ć®ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®åž‹ć‚’ byte é…åˆ—ć«ć™ć‚‹ćØę³Ø釈処ē†ć«å¤±ę•—恙悋äøå…·åˆć‚’äæ®ę­£ć—ć¾ć—ćŸ

v2.0-beta-3: 2014-04-03Ā¶

  • ꤜē“¢ēµęžœć‚’ java.util.stream.Collector ć§å‡¦ē†ć§ćć‚‹ć‚ˆć†ć«ć—ć¾ć—ćŸć€‚
  • LocalTransactionManager 恋悉 TransactionManager ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć‚’ęŠ½å‡ŗć—ć¾ć—ćŸć€‚
  • Config ć§ęŒ‡å®šć—ćŸčØ­å®šćŒäø€éƒØē„”č¦–ć•ć‚Œć‚‹äøå…·åˆć‚’äæ®ę­£ć—ć¾ć—ćŸć€‚
  • ćƒžćƒƒćƒ—ć®ćƒćƒ¼ćƒŸćƒ³ć‚°č¦ē“„ć‚’äø€å¾‹åˆ¶å¾”ć™ć‚‹ćŸć‚ć®ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ MapKeyNaming 悒čæ½åŠ ć—ć¾ć—ćŸć€‚
  • java.time.LocalDate 态 java.time.LocalTime 态 java.time.LocalDateTime 悒åŸŗęœ¬åž‹ćØ恗恦ä½æē”Øć§ćć‚‹ć‚ˆć†ć«ć—ć¾ć—ćŸć€‚
  • JdbcLogger ć®å®Ÿč£…ć®å·®ć—ę›æćˆć‚’å®¹ę˜“ć«ć™ć‚‹ćŸć‚ć« AbstractJdbcLogger 悒čæ½åŠ ć—ć¾ć—ćŸć€‚
  • SelectStrategyType ć®åå‰ć‚’ SelectType ć«å¤‰ę›“ć—ć¾ć—ćŸć€‚

Doma 2 恫恊恑悋äø»č¦ćŖå¤‰ę›“ē‚¹Ā¶

Doma 1.36.0 ć‹ć‚‰ć®å¤‰ę›“ē‚¹ć®å†…态äø»ćŖ悂恮悒ē¤ŗć—ć¦ć„ć¾ć™ć€‚

å…Ø般Ā¶

  • Java 8 恫åƾåæœć—ć¾ć—ćŸć€‚Java 7 ä»„å‰ć§ćÆå‹•ä½œć—ć¾ć›ć‚“ć€‚
  • deprecated ćŖ API ćŒå‰Šé™¤ć•ć‚Œć¾ć—ćŸć€‚

čح定Ā¶

  • Config ć®å®Ÿč£…ć‚Æćƒ©ć‚¹ć‚’ć‚·ćƒ³ć‚°ćƒ«ćƒˆćƒ³ćØć—ć¦ę‰±ćˆć‚‹ć‚ˆć†ć« @SingletonConfig 恌čæ½åŠ ć•ć‚Œć¾ć—ćŸć€‚
  • ćƒˆćƒ©ćƒ³ć‚¶ć‚Æć‚·ćƒ§ćƒ³å‡¦ē†ć‚’ē°”ę˜“åŒ–ć™ć‚‹ćŸć‚ć« TransactionManager 恌čæ½åŠ ć•ć‚Œć¾ć—ćŸć€‚
  • ć‚Æć‚ØćƒŖć‚’ć‚«ć‚¹ć‚æ惞悤ć‚ŗåÆčƒ½ć«ć™ć‚‹ćŸć‚ć« QueryImplementors ćØ CommandImplementors 恌čæ½åŠ ć•ć‚Œć¾ć—ćŸć€‚
  • ēµęžœć‚»ćƒƒćƒˆć«ęœŖēŸ„ć®ć‚«ćƒ©ćƒ ćŒå«ć¾ć‚Œć¦ć„ćŸå “åˆć®ęŒ™å‹•ć‚’ć‚«ć‚¹ć‚æ惞悤ć‚ŗåÆčƒ½ć«ć™ć‚‹ćŸć‚ć« UnknownColumnHandler 恌čæ½åŠ ć•ć‚Œć¾ć—ćŸć€‚
  • ćƒžćƒƒćƒ—ć®ć‚­ćƒ¼ć®ćƒćƒ¼ćƒŸćƒ³ć‚°č¦ē“„ć‚’äø€å¾‹ć§č§£ę±ŗć§ćć‚‹ć‚ˆć†ć« MapKeyNaming 恌čæ½åŠ ć•ć‚Œć¾ć—ćŸć€‚
  • DomaAbstractConfig ćŒå‰Šé™¤ć•ć‚Œć¾ć—ćŸć€‚ 恓恮ć‚Æćƒ©ć‚¹ćŒęä¾›ć—ć¦ć„ćŸå®Ÿč£…ćÆ Config ć®ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆćƒ”ć‚½ćƒƒćƒ‰ć§ęä¾›ć•ć‚Œć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚
  • DefaultClassHelper ćŒå‰Šé™¤ć•ć‚Œć¾ć—ćŸć€‚ 恓恮ć‚Æćƒ©ć‚¹ćŒęä¾›ć—ć¦ć„ćŸå®Ÿč£…ćÆ ClassHelper ć®ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆćƒ”ć‚½ćƒƒćƒ‰ć§ęä¾›ć•ć‚Œć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚
  • NullRequiresNewController ćŒå‰Šé™¤ć•ć‚Œć¾ć—ćŸć€‚ 恓恮ć‚Æćƒ©ć‚¹ćŒęä¾›ć—ć¦ć„ćŸå®Ÿč£…ćÆ RequiresNewController ć®ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆćƒ”ć‚½ćƒƒćƒ‰ć§ęä¾›ć•ć‚Œć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚

åŸŗęœ¬åž‹Ā¶

  • Object åž‹ćŒåŸŗęœ¬åž‹ćØčŖč­˜ć•ć‚Œć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚
  • java.time.LocalDate åž‹ćŒåŸŗęœ¬åž‹ćØčŖč­˜ć•ć‚Œć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚
  • java.time.LocalTime åž‹ćŒåŸŗęœ¬åž‹ćØčŖč­˜ć•ć‚Œć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚
  • java.time.LocalDateTime åž‹ćŒåŸŗęœ¬åž‹ćØčŖč­˜ć•ć‚Œć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚

ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹Ā¶

  • @Domain 悒ä½æć£ć¦ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć‚’ä½œć£ćŸå “åˆć€ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆ null ć‚’å—ć‘å…„ć‚ŒćŖ恏ćŖć‚Šć¾ć—ćŸć€‚ null ć‚’å—ć‘å…„ć‚Œć‚‹ć«ćÆ @Domain 恮 acceptNull 要ē“ ć« true ć®ęŒ‡å®šćŒåæ…要恧恙怂

ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹Ā¶

  • 実éؓēš„ćŖę‰±ć„ć ć£ćŸć‚¤ćƒŸćƒ„ćƒ¼ć‚æćƒ–ćƒ«ćŖć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ćŒę­£å¼ć«ć‚µćƒćƒ¼ćƒˆć•ć‚Œć¾ć—ćŸć€‚
  • ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć«åŸŗęœ¬åž‹ć‚„ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć‚’č¦ē“ ćØ恙悋 java.util.Optional ć‚’å®šē¾©ć§ćć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚
  • ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć« java.util.OptionalInt ć‚’å®šē¾©ć§ćć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚
  • ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć« java.util.OptionalLong ć‚’å®šē¾©ć§ćć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚
  • ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć« java.util.OptionalDouble ć‚’å®šē¾©ć§ćć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚

Daoć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹Ā¶

  • ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚„ęˆ»ć‚Šå€¤ć®åž‹ć« java.util.Optional ć‚’å®šē¾©ć§ćć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚
  • ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚„ęˆ»ć‚Šå€¤ć®åž‹ć« java.util.OptionalInt ć‚’å®šē¾©ć§ćć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚
  • ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚„ęˆ»ć‚Šå€¤ć®åž‹ć« java.util.OptionalLong ć‚’å®šē¾©ć§ćć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚
  • ćƒ‘ćƒ©ćƒ”ćƒ¼ć‚æć‚„ęˆ»ć‚Šå€¤ć®åž‹ć« java.util.OptionalDouble ć‚’å®šē¾©ć§ćć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚
  • java.util.stream.Stream 悒ä½æć£ć¦ę¤œē“¢ēµęžœć‚’処ē†ć§ćć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚
  • java.util.stream.Collector 悒ä½æć£ć¦ę¤œē“¢ēµęžœć‚’処ē†ć§ćć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚
  • @Delegate ćŒå»ƒę­¢ć«ćŖć‚Šć€ä»£ć‚ć‚Šć«ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆćƒ”ć‚½ćƒƒćƒ‰ćŒä½æćˆć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚
  • IterationCallback 悒ä½æć£ćŸę¤œē“¢ćŒē¦ę­¢ć•ć‚Œć¾ć—ćŸć€‚ ä»£ć‚ć‚Šć« java.util.stream.Stream 悒ä½æć£ćŸę¤œē“¢ć‚’ć—ć¦ćć ć•ć„ć€‚

SQLć«é–¢ć™ć‚‹å¤‰ę›“Ā¶

  • ć‚«ćƒ©ćƒ ćƒŖć‚¹ćƒˆå±•é–‹ć‚³ćƒ”ćƒ³ćƒˆćŒå°Žå…„ć•ć‚Œć¾ć—ćŸć€‚

式č؀čŖžĀ¶

  • ēµ„ćæč¾¼ćæé–¢ę•° contain ć‚’å‰Šé™¤ć—ć¾ć—ćŸć€‚

ę³Ø釈処ē†Ā¶

  • ę³Ø釈処ē†ć®ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ć®åå‰ć« doma ćØć„ć†åå‰ē©ŗé–“ć‚’ä»˜äøŽć—ć¾ć—ćŸć€‚ Doma ä»„å¤–ć®ę³Ø釈処ē†ć®ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ćØć‚­ćƒ¼ćŒé‡č¤‡ć™ć‚‹ć“ćØ悒éæ恑悋恟悁恧恙怂

ćƒ“ćƒ«ćƒ‰Ā¶

  • Doma恮jar悒Mavenć®ć‚»ćƒ³ćƒˆćƒ©ćƒ«ćƒŖ惝ć‚ø惈ćƒŖć‹ć‚‰ęä¾›ć™ć‚‹ć‚ˆć†ć«ć—ć¾ć—ćŸć€‚

FAQĀ¶

ē›®ę¬”

äø€čˆ¬ēš„ćŖč³Ŗ問Ā¶

DomaćØćÆć©ć®ć‚ˆć†ćŖę„å‘³ć§ć™ć‹ļ¼ŸĀ¶

D omain O riented Database MA pping Framework 恮ē•„恧恙怂

ę³Ø釈処ē†ćØćÆćŖ悓恧恙恋ļ¼ŸĀ¶

Java 6 ć§å°Žå…„ć•ć‚ŒćŸ Pluggable Annotation Processing API ć‚’åˆ©ē”Øć—ćŸå‡¦ē†ć§ć€ ć‚³ćƒ³ćƒ‘ć‚¤ćƒ«ę™‚ć®ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ę¤œčØ¼ć‚„ć€ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ē”ŸęˆćŒåÆčƒ½ć§ć™ć€‚

Doma恧ćÆ态ę³Ø釈処ē†ć‚’ä½æē”Ø恗恦仄äø‹ć®ć“ćØć‚’å®Ÿē¾ć—ć¦ć„ć¾ć™ć€‚

  • ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć‚Æćƒ©ć‚¹ć‚„ćƒ‰ćƒ”ć‚¤ćƒ³ć‚Æćƒ©ć‚¹ć®ćƒ”ć‚æęƒ…å ±ć®ē”Ÿęˆ
  • Daoć®ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć‹ć‚‰å®Ÿč£…ć‚Æćƒ©ć‚¹ć®ē”Ÿęˆ
  • SQLćƒ•ć‚”ć‚¤ćƒ«ć®ćƒćƒŖćƒ‡ćƒ¼ć‚·ćƒ§ćƒ³

動作ē’°å¢ƒć«é–¢ć™ć‚‹č³Ŗ問Ā¶

ć©ć®ćƒćƒ¼ć‚øćƒ§ćƒ³ć®JREć‚’ć‚µćƒćƒ¼ćƒˆć—ć¦ć„ć¾ć™ć‹ļ¼ŸĀ¶

JER 8 仄äøŠć‚’ć‚µćƒćƒ¼ćƒˆć—ć¦ć„ć¾ć™ć€‚

Domać‚’å‹•ä½œć•ć›ć‚‹ć®ć«åæ…要ćŖćƒ©ć‚¤ćƒ–ćƒ©ćƒŖćÆä½•ć§ć™ć‹ļ¼ŸĀ¶

ä½•ć‚‚ć‚ć‚Šć¾ć›ć‚“ć€‚ DomaćÆJREä»„å¤–ć®ć©ć‚“ćŖćƒ©ć‚¤ćƒ–ćƒ©ćƒŖć«ć‚‚ä¾å­˜ć—ć¦ć„ć¾ć›ć‚“ć€‚

開ē™ŗē’°å¢ƒć«é–¢ć™ć‚‹č³Ŗ問Ā¶

ć©ć®ćƒćƒ¼ć‚øćƒ§ćƒ³ć®JDKć‚’ć‚µćƒćƒ¼ćƒˆć—ć¦ć„ć¾ć™ć‹ļ¼ŸĀ¶

JDK 8 仄äøŠć‚’ć‚µćƒćƒ¼ćƒˆć—ć¦ć„ć¾ć™ć€‚

Doma恮jar悒Eclipseć®ćƒ“ćƒ«ćƒ‰ćƒ‘ć‚¹ć«čØ­å®šć—ć¾ć—ćŸćŒę³Ø釈処ē†ćŒå®Ÿč”Œć•ć‚Œć¾ć›ć‚“怂Ā¶

Factory Path恫悂Doma恮jarćƒ•ć‚”ć‚¤ćƒ«ć‚’ē™»éŒ²ć—ć¦ćć ć•ć„ć€‚

Factory Path恮čح定ē”»é¢ćÆ态惗惭ć‚ø悧ć‚Æćƒˆć®ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£čح定ē”»é¢ć‹ć‚‰ć€ Java - Compiler - Annotation Processing - Factory Path ćØč¾æć‚Œć¾ć™ć€‚ Annotation ProcessingćØFactory Path恮ē”»é¢ć§ćÆ态 怌Enable project specific settingsć€ć®ćƒć‚§ćƒƒć‚Æ惜惃ć‚Æć‚¹ć‚’ćƒć‚§ćƒƒć‚Æć—ć¦ćć ć•ć„ć€‚

ę³Ø釈処ē†ć§ē”Ÿęˆć•ć‚ŒćŸć‚³ćƒ¼ćƒ‰ćÆ恩恓恫å‡ŗåŠ›ć•ć‚Œć¾ć™ć‹ļ¼ŸĀ¶

Eclipseć‚’åˆ©ē”Øć—ć¦ć„ć‚‹å “åˆć€ ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć§ćÆ惗惭ć‚ø悧ć‚Æ惈ē›“äø‹ć® .apt_generated ćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖ恫å‡ŗåŠ›ć•ć‚Œć¾ć™ć€‚

Eclipse悒ä½æē”Øć—ć¦ć„ć¾ć™ćŒć€.apt_generated ćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖ恌ćæć¤ć‹ć‚Šć¾ć›ć‚“ć€‚Ā¶

å˜ć«Package Explorerćƒ“ćƒ„ćƒ¼äøŠć« .apt_generated ćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖ恌č”Øē¤ŗć•ć‚Œć¦ć„ćŖć„ć ć‘ć‹ć‚‚ć—ć‚Œć¾ć›ć‚“ć€‚ .apt_generated ćÆć€åē§°ćŒ . ć§å§‹ć¾ć£ć¦ć„ć‚‹ćŸć‚ć«ć€ Package Explorerćƒ“ćƒ„ćƒ¼ć§č”Øē¤ŗåÆ¾č±”å¤–ć«ćŖć‚Šć¾ć™ć€‚ åƾåæœę–¹ę³•ćØ恗恦ćÆ仄äø‹ć®ć„ćšć‚Œć‹ć‚’éøęŠžć—ć¦ćć ć•ć„ć€‚

  • Nivigatorćƒ“ćƒ„ćƒ¼ć‹ć‚‰ .apt_generated ćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖ悒ē¢ŗčŖć™ć‚‹
  • Package Explorerćƒ“ćƒ„ćƒ¼ć®ćƒ•ć‚£ćƒ«ć‚æćƒŖćƒ³ć‚°ć®čØ­å®šć‚’å¤‰ę›“ć— .apt_generated ćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖ悒č”Øē¤ŗ恕恛悋
  • å‡ŗåŠ›å…ˆćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖć‚’å¤‰ę›“ć—åē§°ćŒ . ć§å§‹ć¾ć‚‰ćŖć„ć‚ˆć†ć«ć™ć‚‹

SQLćƒ•ć‚”ć‚¤ćƒ«ćŒč¦‹ć¤ć‹ć‚Šć¾ć›ć‚“ć€‚Ā¶

SQLćƒ•ć‚”ć‚¤ćƒ«ćŒå­˜åœØć™ć‚‹ć«ć‚‚é–¢ć‚ć‚‰ćšć€ę¬”ć®ć‚Øćƒ©ćƒ¼ćƒ”ćƒƒć‚»ćƒ¼ć‚ø恌å‡ŗåŠ›ć•ć‚Œć‚‹ć“ćØćŒć‚ć‚Šć¾ć™ć€‚

[DOMA4019] SQLćƒ•ć‚”ć‚¤ćƒ«[META-INF/../select.sql]恌ć‚Æćƒ©ć‚¹ćƒ‘ć‚¹ć‹ć‚‰č¦‹ć¤ć‹ć‚Šć¾ć›ć‚“ć§ć—ćŸ

SQLćƒ•ć‚”ć‚¤ćƒ«ćÆć‚Æćƒ©ć‚¹ć®å‡ŗåŠ›ćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖ恋悉ꤜē“¢ć•ć‚Œć¾ć™ć€‚ SQLćƒ•ć‚”ć‚¤ćƒ«ć®å‡ŗåŠ›ćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖćØć‚Æćƒ©ć‚¹ć®å‡ŗåŠ›ćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖćŒåŒć˜ć§ć‚ć‚‹ć“ćØ悒ē¢ŗčŖć—ć¦ćć ć•ć„ć€‚

Eclipseć®å “åˆć€ćƒ—ćƒ­ć‚ø悧ć‚Æćƒˆć®ćƒ—ćƒ­ćƒ‘ćƒ†ć‚£ć®ć€ŒJava Build Pathć€ć®čح定ē”»é¢ć§ć€ ć‚½ćƒ¼ć‚¹ćƒ•ć‚©ćƒ«ćƒ€ć”ćØ恫å‡ŗåŠ›å…ˆćƒ‡ć‚£ćƒ¬ć‚Æ惈ćƒŖć‚’å¤‰ę›“åÆčƒ½ć«ćŖć£ć¦ć„ć¾ć™ć€‚

DBć‚¢ć‚Æć‚»ć‚¹ćƒ©ć‚¤ćƒ–ćƒ©ćƒŖćØć—ć¦ć®ę©Ÿčƒ½ć«é–¢ć™ć‚‹č³Ŗ問Ā¶

SQL悒č‡Ŗ動ē”Ÿęˆć™ć‚‹ę©Ÿčƒ½ćÆć‚ć‚Šć¾ć™ć‹ļ¼ŸĀ¶

ćÆ恄怂

ꛓꖰē³»SQLć€ć‚¹ćƒˆć‚¢ćƒ‰ćƒ—ćƒ­ć‚·ćƒ¼ć‚øćƒ£ćƒ¼/ćƒ•ć‚”ćƒ³ć‚Æć‚·ćƒ§ćƒ³å‘¼ć³å‡ŗ恗恫恤恄恦ćÆSQL悒č‡Ŗå‹•ć§ē”Ÿęˆć§ćć¾ć™ć€‚ ꤜē“¢ē³»ć®SQL恫恤恄恦ćÆ态č‡Ŗ動ē”Ÿęˆę©Ÿčƒ½ćÆć‚ć‚Šć¾ć›ć‚“ćŒć€ćƒ•ć‚”ć‚¤ćƒ«ć«å¤–éƒØåŒ–ć—ćŸSQLć‚’å®Ÿč”Œć—ć€ ćć®ēµęžœć‚’Java恮ć‚Ŗ惖ć‚ø悧ć‚Æćƒˆć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć™ć‚‹ę©Ÿčƒ½ćŒć‚ć‚Šć¾ć™ć€‚

č©³ć—ććÆ ć‚Æć‚ØćƒŖ ć‚’å‚ē…§ć—ć¦ćć ć•ć„ć€‚

ę”ä»¶ćŒå‹•ēš„ć«å¤‰ć‚ć‚‹SQLćÆć©ć®ć‚ˆć†ć«å®Ÿč”Œć§ćć¾ć™ć‹ļ¼ŸĀ¶

SQLćƒ•ć‚”ć‚¤ćƒ«ć«ć€SQLć‚³ćƒ”ćƒ³ćƒˆć‚’ä½æć£ć¦ę”ä»¶ć‚’ęŒ‡å®šć§ćć¾ć™ć€‚ SQLć‚³ćƒ”ćƒ³ćƒˆćÆå®Ÿč”Œę™‚ć«č§£ęžć•ć‚Œć€ę”ä»¶ć«ć‚ˆć£ć¦ē•°ćŖ悋SQL恌ē”Ÿęˆć•ć‚Œć¾ć™ć€‚

č©³ć—ććÆ SQL ć‚’å‚ē…§ć—ć¦ćć ć•ć„ć€‚

1åƾ1 悄 1åƾn ćŖć©ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹äøŠć®ćƒŖćƒ¬ćƒ¼ć‚·ćƒ§ćƒ³ć‚·ćƒƒćƒ—ć‚’Javać‚Ŗ惖ć‚ø悧ć‚Æćƒˆć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć§ćć¾ć™ć‹ļ¼ŸĀ¶

ć„ć„ćˆć€ć§ćć¾ć›ć‚“ć€‚

Doma恧ćÆ态SQL恮ēµęžœć‚»ćƒƒćƒˆć®1č”Œć‚’ćć®ć¾ć¾1恤恮ć‚Øćƒ³ćƒ†ć‚£ćƒ†ć‚£ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć«ćƒžćƒƒćƒ”ćƒ³ć‚°ć—ć¾ć™ć€‚ ć“ć®ć»ć†ćŒć‚·ćƒ³ćƒ—ćƒ«ć§ć‚ć‹ć‚Šć‚„ć™ć„ćØč€ƒćˆć¦ć„ć‚‹ćŸć‚ć§ć™ć€‚

ć‚³ćƒć‚Æć‚·ćƒ§ćƒ³ćƒ—ćƒ¼ćƒŖćƒ³ć‚°ć®ę©Ÿčƒ½ćÆć‚ć‚Šć¾ć™ć‹ļ¼ŸĀ¶

恄恄恈态Doma恧ćÆęä¾›ć—ć¦ć„ć¾ć›ć‚“ć€‚

ć‚³ćƒć‚Æć‚·ćƒ§ćƒ³ćƒ—ćƒ¼ćƒŖćƒ³ć‚°ę©Ÿčƒ½ć‚’ć‚‚ć¤ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć‚µćƒ¼ćƒćƒ¼ć€ćƒ•ćƒ¬ćƒ¼ćƒ ćƒÆćƒ¼ć‚Æ态 ćƒ©ć‚¤ćƒ–ćƒ©ćƒŖē­‰ćØēµ„ćæåˆć‚ć›ć¦ä½æē”Øć—ć¦ćć ć•ć„ć€‚