ããŒã¿ããŒã¹ãæäœããã¢ããªã±ãŒã·ã§ã³ã§ã¯ãåœç¶ãã¯ãšãªå®è¡ã®çµæã®æ£ç¢ºæ§ãæ€èšŒãããã¹ããå¿ èŠã§ãã ããŸããŸãªçµã¿èŸŒã¿ããŒã¿ããŒã¹ãå©ãã«ãªããŸãã ãã®èšäºã§ã¯ããŠããããã¹ããHSQLDBããPostgreSQLã«ã©ã®ããã«è»¢éãããã«ã€ããŠèª¬æããŸãããªããããéå§ããã®ããã©ã®ãããªå°é£ã«ééããäœãåŸãããã®ãã説æããŸãã
ãã¹ãã§sqlã¯ãšãªã®ç¶æ
ã確èªããå¿
èŠãããå Žåãããããçµã¿èŸŒã¿ããŒã¿ããŒã¹ã䜿çšãããšäŸ¿å©ã§ãã ããŒã¿ããŒã¹ã¯ããã¹ãã®éå§æã«äœæãããæåŸã«åé€ãããŸãããããã£ãŠããã®ã©ã€ããµã€ã¯ã«ã¯ãå®è¡ãããããã»ã¹ã«ãã£ãŠå¶éãããŸãïŒãã®ãããããŒã¿ããŒã¹ã¯åã蟌ã¿ãšåŒã°ããŸã-ã€ãŸãããã¹ãããã»ã¹ã«çµã¿èŸŒãŸããŸãïŒã ãã®ãããªããŒã¿ããŒã¹ã®å©ç¹ã¯ãéããããã¹ãããŒã¿ã»ããã§äœæ¥ã§ããããšã§ããããã¯ãäžè¬ã«ããã¹ããµãŒããŒäžã§ãããŒã¿éããã倧å¹
ã«å°ãªãã§ãã ããã«ãããŒã¿ããŒã¹ã®äœæãããŒãã«ãžã®å
¥åãããã³ã€ã³ãã©ã¹ãã©ã¯ãã£å
šäœã®åé€ã¯ãããã°ã©ããŒã«å¯ŸããŠå®å
šã«ééçã§ãïŒãã¹ããµãŒããŒãäžããŠæ§æããå¿
èŠã¯ãªããããŒã¿ã®é¢é£æ§ãèæ
®ããå¿
èŠããããŸãããããã¯ãéçºã®é床ã«ããã©ã¹ã®åœ±é¿ãäžããŸãã
åœç€Ÿã¯ãããŸã§ããŠããããã¹ãã«HSQLDBã䜿çšããŠããŸããã ãããŠããã¹ãŠãããŸããããŸãããPostgreSQLã¯æ¬çªç°å¢ã«ããããã¹ãã¯prodã§èµ·ãã£ãŠããããšãå®å
šã«åæ ããŠããªãããšãå€æããŸããã äžéšã®æ©èœã¯ãã¹ãããã«æ®ãå¿
èŠããããŸãããããšãã°ããŠã£ã³ããŠé¢æ°ã䜿çšãããªã¯ãšã¹ãã¯ãã¹ãã§ããŸããã§ããã ããã€ãã®ãã¹ãã§ã¯ãéåžžã«æŽç·ŽãããæŸèæãäœæããå¿
èŠããããŸãããé®®æãªäŸã¯ãã«ã¹ã¿ã é
åã¿ã€ããPostgreSQLããã³HSQLDBã®SQLã«ãããã³ã°ããããŸããŸãªå®è£
ã§ãïŒããã«ã€ããŠã¯åŸã§è©³ãã説æããŸãïŒã ãŸãã exists
åé¡ã®ããå®è£
ã«ééããŸãã-çç±ããªããHSQLDBã®è
žã®ã©ããã§NPE
ãããã¹ããèœã¡ãå ŽåããããŸããã
ãã¹ãããŒã¿ããŒã¹ãšããŠPostgreSQLã䜿çšããã°ããããã®åé¡ã¯ãã¹ãŠåé¿ã§ããã¯ãã§ãã çŸåšãåã蟌ã¿PostgreSQLã«ã¯ã yandex-qatoolsã®postgresqlåã蟌ã¿ã©ã€ãã©ãªãšOpenTableã§å°å
¥ãããotj-pg-embeddedã® 2ã€ã®å®è£
ããããŸãã äž¡æ¹ã®ãããžã§ã¯ãã¯ããªããžããªã§ã®å®æçãªã³ãããããæãããªããã«ãéåžžã«æŽ»çºã«éçºãããŠããã䜿çšã䟿å©ã§ããã©ã€ãã©ãªã¯ãMavenãªããžããªããããŠã³ããŒãã§ããWindowsããµããŒãããŠããŸããããã¯ãäžéšã®éçºè
ããã®OSãéžæããäŒæ¥ã§éèŠã§ã æåŸã«ãããã€ãã®çç±ã§otj-pg-embeddedã§åæ¢ããããšã«ããŸããã
- ãŸããOpenTableã©ã€ãã©ãªã®æ¹ãã¯ããã«é«éã§ããããšãå€æããŸãããããŠã³ããŒãããããã£ã¹ããªãã¥ãŒã·ã§ã³ã®èµ·åæéã¯çŽ2ç§ã§ãããyandex-qatoolsã¯7.5ç§ä»¥å ã«èµ·åããŸã-ã»ãŒ4åé ãã§ãïŒ èµ·åãããã³ã«é åžããã±ãŒãžã解åããã®ã«ãããæéã®ã»ãšãã©ããWindowsãã·ã³ã§ã¯éå§æéãæ°åã«å¢å ããããšãå€æããŸããã
- 次ã«ãå€ãããŒãžã§ã³ãŸãã¯æ¡åŒµæ©èœä»ãã®ã«ã¹ã¿ã ã¢ã»ã³ããªã䜿çšããå¿ èŠãããå Žåã¯ãPostgreSQLã®ããŒãžã§ã³ãåã«çœ®ãæããã ãã§ååã§ãã ããã©ã«ãã§ã¯ãotj-pg-embedded 0.7.1ã«ã¯PostgreSQL 9.5ãä»å±ããŠããŸãïŒããŒãžã§ã³0.8.0ã§ã¯ãçŸåšã®ããŒãžã§ã³ã¯PostgreSQL 9.6ã§ãïŒã åæã«ãyandex-qatoolsã«ã«ã¹ã¿ã ã¢ã»ã³ããªãé 眮ããæ¹æ³ã¯å®å šã«ã¯æ確ã§ã¯ãããŸããã
- otj-pg-embeddedã¯ããªãå€ããããžã§ã¯ãã§ãïŒæåã®ã³ãããã¯2012幎2æã§ããïŒãã¡ã³ãããŒã¯githubãžã®ãªã¯ãšã¹ãã«è¿ éã«å¯Ÿå¿ããŸãã
- Yandex-qatoolsã«ã¯ããå€ãã®æ§æãªãã·ã§ã³ããããŸãããotj-pg-embeddedã¯ç解ããããå°ããªã©ã€ãã©ãªã§ãããååãªæ§æãªãã·ã§ã³ãæäŸããŸãã
- OpenTableã©ã€ãã©ãªã§ã¯ãããŒã¿ããŒã¹ã€ã³ã¹ã¿ã³ã¹ãã1è¡ã§ãå®è¡ã§ããŸããããã¯éåžžã«äŸ¿å©ã§çŽæçã§ãã ããã«ãããŒãžã§ã³0.8.0ã§ã¯ãèµ·åæã«PostgreSQLãå®è¡ãããŠããèšå®ã瀺ãããªãæçãªãã°ã衚瀺ãããŸãã
ãã®ãããã©ã€ãã©ãªã決å®ãã決å®çãªãžã§ã¹ãã£ãŒãè¡ãããã¹ãŠã®hsqläŸåé¢ä¿ãotj-pg-embeddedã«çœ®ãæããŠããã¹ããå®è¡ããŸãã...
æåã®çæ
DATE
SQLã¿ã€ãã®åŠçæ¹æ³ãç°ãªã
ãŸããSQLã¿ã€ãDate
ïŒ Timestamp
ã§ã¯ãªãDate
ïŒã§ã¯æ©èœãããã¹ãã倱æããããšãå€æããŸããã ããšãã°ãç¹å®ã®åºæºã§å±¥æŽæžãæ€çŽ¢ããå Žåãã¯ãšãªã¯ãå€æŽæ¥ãæå®ãããæ¥ä»ããåŸã®å±¥æŽæžããã¹ãŠè¿ããŸãã
return sessionFactory.getCurrentSession().createQuery( "FROM ResumeViewHistory " + "WHERE resumeId=:resumeId AND date IN " + " (SELECT max(date) FROM ResumeViewHistory " + " WHERE resumeId=:resumeId AND date>:date)") .setInteger("resumeId", resumeId) .setDate("date", from) .list();
ãã¹ãã§ã¯ãçŸåšã®æ¥ä»ã§å±¥æŽæžãäœæãããäœæãããæ¥ä»ããå°ãå€ãæ¥ä»ã®å±¥æŽæžããªãããšã確èªãããŸããã
assertTrue(resumeViewHistoryDao.findByResumeLastView( resume.getResumeId(), new DateTime().plusMinutes(1).toDate()) .isEmpty());
ãã®ãã¹ãã¯ãåæ§ã®ãã§ãã¯ãè¡ãä»ã®ãã¹ãŠã®ãã¹ããšåæ§ã«ã AssertionError
ã§PostgreSQLã«èœã¡ãŸããã åé¡ã¯ãæ¥ä»ãšæå»ãHSQLDBã§æ¯èŒãããããã1åã®å·®ãéèŠã§ãããšèŠãªãããããšã§ãã ãŸããPostgreSQLã§ã¯ãæå»ããŒãã«ãªã»ãããããŠæ¥ä»ã«ãªããã¯ãšãªã¯åãæ¥ã«äœæããããããå±¥æŽæžèªäœãå®å
šã«èŠã€ãããŸããïŒ
ãããã£ãŠãã»ãšãã©æåã¯ãç¹å®ã®æ¡ä»¶äžã§ç¹å®ã®åäœãæ³å®ããŠããã¹ããsqlã¯ãšãªããã§ãã¯ãããã®åäœã¯HSQLDBã§æ©èœããPostgreSQLã§ã¯æ©èœããªãã£ããšããç¶æ³ã«çŽé¢ããŸããã ã€ãŸããå®éã«ã¯ããã®ãã¹ãã¯åœ¹ã«ç«ããªãã®ã§ããªã¯ãšã¹ãã®æäœã«é¢ããæ
å ±ãæäŸããªãã£ãããã圹ã«ç«ããªãã£ãã ãã§ãªããæ害ã§ãããããŸããïŒéçºè
ã¯ããã¹ãã³ãŒããèªãã§ã1ååŸã«äœæããããªããžã§ã¯ãã®ç©ºã®çµæã®ãã§ãã¯ãããããšã確èªãã setTimestamp()
ã¡ãœãããDAO
ã¬ãã«ã§äœ¿çšãããŠãããšèãããšã setDate()
衚瀺ãããã®ã¯éåžžã«é©ãã§ãããã
LIKE + CTE
次ã®åé¡ã¯ã LIKE
æŒç®åã«ãã£ãŠäžè¬çãªããŒãã«åŒãšäžç·ã«ã¹ããŒãããŸããã CTEïŒå
±éããŒãã«åŒïŒã¯ãããè€éãªã¯ãšãªã§äœ¿çšããäžæããŒãã«ãå®çŸ©ããåŒã§ãã ãããã®äžæããŒãã«ã¯ãçŸåšã®ã¯ãšãªã«å¯ŸããŠã®ã¿äœæãããŸããããã¯ãäœããã®åœ¢åŒã§ããŒã¿ãçæçã«è¡šç€ºããã®ã«äŸ¿å©ã§ãã ããšãã°ãCTEã䜿çšããEmployer
ïŒéçšäž»ã圌ã¯ã¯ã©ã€ã¢ã³ãïŒ-äžå€®ãšã³ãã£ãã£ã®1ã€ã¯ããã£ãŒã«ãã®ã»ãããæžãããããç¹åãããªããžã§ã¯ããšããŠè¡šãããšãã§ããŸãã
éè€ãã顧客ãã€ãŸããç»é²ã¢ãã¬ã¹ãWebãµã€ãã®URLãªã©ãããã€ãã®æ¹æ³ã§äžèŽããäŒç€ŸãèŠã€ããå¿
èŠããããšããŸãã ãšããããäŒç€ŸïŒãŸãã¯ãã®äžéšïŒã®ååãäžèŽãããã©ããã®ãã§ãã¯ããããŸããããã§ã¯ã LIKE
æŒç®åãç»å ŽãLIKE
ã
WITH clients(name) AS (VALUES âŠ) SELECT employer.employer_id AS employerId, employer.name AS employerName FROM employer AS employer JOIN clients AS clients ON employer.name LIKE '%' || clients.name || '%'
ãããã£ãŠã次ã®é¡§å®¢ãªã¹ãã®å ŽåïŒ
- ã¢ãªã¹
- ãã
- ããããã³ã¿ãŒ
- ã客æ§
- ã¢ãªã¹ã»ã¯ãŒããŒ
- ããã»ããŒãªãŒ
ã¯ãšãªã®çµæã¯ã WITH
ã¹ããŒãã¡ã³ãã«çœ®æããããã®ã«ãã£ãŠå€§ããç°ãªããŸãïŒè¡šãåç
§ïŒã
PostgreSQLã¯åžžã«äºæž¬å¯èœãªçµæãââåºããHSQLDBã«ã¯ãçµåããå¿ èŠãããäžæããŒãã«ã«è€æ°ã®å€ãå«ãŸãããã¹ãŠã®å Žåã«åé¡ãããããã§ãã çµæãšããŠãããŒãã«ãããããããã«ãPostgreSQLãšHSQLDBã¯ââäžæããŒãã«ã®è€æ°ã®å€ã«å¯ŸããŠç°ãªãåå¿ã瀺ãããã¹ãã§ã¯å°æ°ã®ã¯ã©ã€ã¢ã³ãã®ã¿ããã§ãã¯ãããããããã¹ãã®åæããŒã¿ãä¿®æ£ããå¿ èŠããããŸããã
誀ã£ãSQLã«å¯Ÿããç°ãªãåå¿
ããŒã¿ã¢ãã«ã«ã¯ãSQLã³ãŒããæ ŒçŽãããªããžã§ã¯ããããããªããžã§ã¯ããç¹å®ã®æ¡ä»¶ã«é©ããŠãããã©ããã確èªããããã«å®è¡ãããŸãã åœç¶ãäžæ£ãªsqlã³ãŒããçºçããå Žåã®ã·ã¹ãã ã®åäœã確èªãããã®ã§ã察å¿ãããã¹ãããããŸããäžæ£ãªsqlããªããžã§ã¯ãã«æž¡ãããsqlãå®è¡ããã¡ãœãããåŒã³åºãããŸãã
SELECT user_id FROM user111 WHERE employer_id = :employerId
ãã¡ããã user111
ããŒãã«user111
ååšuser111
ãŸãã-ããã¯user
ããŒãã«ã®èª€ã£ãæžã蟌ã¿ã§ãã ç¡å¹ãªsqlãRuntimeException
ãšã RuntimeException
ããªããžã§ã¯ãã¯ä»¥éã®ããã»ã¹ããé€å€ãããŸãã ãã¹ãã§ãã¹ããããã®ã¯ããã®åäœã§ãã å®éãHSQLDBã§å®è¡ãããšã SQLException
ãšã©ãŒïŒ Exception
ããç¶æ¿ïŒã§ã³ãŒããã¯ã©ãã·ã¥ãããã®åŸJDBCException
ïŒ RuntimeException
ããç¶æ¿ïŒã«å€æããããã®äŸå€ã¯ãµãŒãã¹ã¡ãœããã§åŠçãããçµæãããã§ãã¯ãããŠãããªããžã§ã¯ããåé€ãããè¿œå ã®æäœãæ£åžžã«å®è¡ãããŸããåŠçããããªããžã§ã¯ã-ãããŠãã¹ãã¯æ£ããå®äºããŸããã
PostgreSQLãã¹ããå®è¡ãããšããšã©ãŒã¯ãŸã ãã£ããããã JDBCException
ã«å€æãããŠããã«éä¿¡ãããäžæ£ãªãªããžã§ã¯ãã¯åŠçããé€å€ããããã¹ãŠãæ£åžžã«ãªããŸãããã¯ãšãªã§ãã®çš®ã®ãšã©ãŒãçºçãããšããäºå®ã«ããã次ã®ã¢ã¯ã·ã§ã³ãäžæãããŸãã-ããªãã¡ãååšããªãããŒãã«ã«ã¢ã¯ã»ã¹ããããšãããšãPostgreSQLã¯ãã©ã³ã¶ã¯ã·ã§ã³ãäžæ¢ããæ®ãã®ã¯ãšãªã¯åŠçãããªããªããæçµçã«ãã¹ããæ£ããå®äºããªããªããŸããã
䞊ã¹æ¿ãã®åé¡
ããã§ã¯ã2ã€ã®ã¯ã©ã¹ã®åé¡ãåºå¥ã§ããŸãã 1ã€ç®ã¯ããã¹ãã³ãŒãå
ãšãªã¯ãšã¹ãã®çµæãšããŠã®ãšã³ãã£ãã£ã®é åºã®äžäžèŽã§ãã ããšãã°ããã¹ãã«ã¯è€æ°ã®ã€ã³ã¹ã¿ã³ã¹ã®ãªã¹ããããããããã¯ããŒã¿ããŒã¹ã«äœæããããªã¹ããšããŠã¢ã³ããŒããããŸãã ãã®ãããHSQLDBã§ã¯ããªããžã§ã¯ããããŒã¿ããŒã¹ããããŒããããé åºã¯åžžã«å
ã®ãªã¹ãã®é åºãšäžèŽããŠããŸããã PostgreSQLã§ã¯ãåæ§ã®ãã¶ã€ã³ã䜿çšããããã¹ãŠã®ãã¹ããããé åºãäžèŽããªãã£ãããããœãŒã¹ããã³çµæãªã¹ãã®æ瀺çãªäžŠã¹æ¿ãã䜿çšããããèŠçŽ ã®é åºãèæ
®ããã«ãªã¹ããæ¯èŒããå¿
èŠããããŸããïŒ arrayContainingInAnyOrder
ã arrayContainingInAnyOrder
ã¡ãœããã䜿çšãããšéåžžã«äŸ¿å©ã§ãïŒ Hamcrestãã¬ãŒã ã¯ãŒã¯ã®äžèŽïŒã
2çªç®ã®åé¡ã¯ããæ·±å»ã§ããããšãå€æããŸãããããŒã¿ããŒã¹ã¬ãã«ã§ã®äžŠã¹æ¿ãïŒ ORDER BY
ïŒã䜿çšããäžéšã®ãã¹ããæ©èœããªããªããŸããã ããã«ãç°ãªãç°å¢ã§å®è¡ãããšãœãŒãã®åäœãç°ãªããŸããããã€ãã®ç©ºå®€ã®ååã眮ãæããåŸããã¹ãã¯Linuxã§æ£åžžã«åäœãå§ããŸããããMacOSããã³Windowsã§å®è¡ãããšåäœããŸããã§ããã
åœç¶ãPostgreSQLã®ãã±ãŒã«èšå®ãã€ãŸãããŒã¿ããŒã¹å
ã®è¡ã®ãœãŒããæ
åœãããã±ãŒã«-LC_COLLATEã«çãããããŸããã ãã®èšå®ã¯ãããŒã¿ããŒã¹ã®äœææã«æå®ããããšã³ã³ãŒãã£ã³ã°ã«äŸåããŸããïŒ createdb
ãŸãã¯initdb
ã§ããŒã¿ããŒã¹ãåæåãããšãã«ãã®ãã©ã¡ãŒã¿ãŒãæ瀺çã«æå®ããªãå ŽåãPostgreSQLã¯ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ããå€ãååŸããŸãïŒãšããã§ãããŒã¿ããŒã¹ã®åæååŸã«å€æŽããããšã¯ã§ããŸããïŒã ãœãŒãèŠåã¯éåžžã«ç°ãªãå ŽåããããŸããããšãã°ãã¹ããŒã¹ãå«ãããã©ãããèæ
®ããããå°æåãŸãã¯å€§æåã®åªå
é äœã決å®ãããããŸãã
ãããã£ãŠãçµæããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã«äŸåãããã¹ããã€ãŸãããªããç²æ«ãªç¶æ³ã«ãªããŸããã PostgreSQLã§æäŸãããæšæºã®äžŠã¹æ¿ãLC_COLLATE=C
ã䜿çšããŠãOSã«äŸåããªãã«ãŒã«ã«åŸã£ãŠäžŠã¹æ¿ããèš±å¯ããèšå®ã䜿çšã§ããŸãããOpenTableã®embedded-pgå®è£
ã«ã¯initdb
ãã©ã¡ãŒã¿ãæž¡ãæ¹æ³ããªãããããã®ãªãã·ã§ã³ã¯æ©èœããŸããinitdb
ã çŸåšã®å®è£
ã§ã¯ãããŒã¿ããŒã¹ã®èµ·åæã«ãµãŒããŒæ§æãå€æŽã§ããŸããã collate
èšå®ãèšå®ã§ããªããããåé¡ãã¹ãã¯äžæçã«@Ignore
éä¿¡ãã@Ignore
ã ã¡ãªã¿ã«ãOpenTableã®ã¡ã³ãããŒã¯ãã®æ©èœã®å¿
èŠæ§ãèªèããŠãããããç°¡åãªè°è«ã®åŸãããŸããŸãªãã±ãŒã«èšå®ã§ããŒã¿ããŒã¹ãåæåããæ©èœãè¿œå ããPRãäœæããŸããã ãªãªãŒã¹ã¯ãŸãã§ãããembedded-pgã®æ¬¡ã®ããŒãžã§ã³ã§ãã®åé¡ã解決ãããããšãé¡ã£ãŠããŸãã
ã«ã¹ã¿ã ã¿ã€ããããã³ã°ã®åé¡
ãåç¥ã®ããã«ãHibernateã§ã¯ãããŒã¿ããŒã¹ã«ãé
åãã¿ã€ãã®ãã£ãŒã«ããæ ŒçŽããããã«ã UserType
ã€ã³ã¿ãŒãã§ã€ã¹ãå®è£
ãããŠãŒã¶ãŒã¿ã€ããèšè¿°ããå¿
èŠããããŸãã ããŒã¿ããŒã¹å
ã®åã®SQLåã決å®ããsqlTypes()
ã sqlTypes()
ã sqlTypes()
ãªã©ã®å¿
èŠãªã¡ãœãããå®è£
ãããŠãŒã¶ãŒã¯ã©ã¹ã瀺ã@Type
ã¢ãããŒã·ã§ã³ããšã³ãã£ãã£ã¯ã©ã¹ã®ãã£ãŒã«ã宣èšã«è¿œå ããïŒãŸãã¯ãããæå®ããnullSafeSet()
ã ãã§ååã§ãããããã³ã°ãã¡ã€ã«ã«å
¥åããŸãïŒã
ç§ãã¡ã®ãããžã§ã¯ãã§ã¯ãæåã«java.sql.Array
ã䜿çšããŠé
ååã®ãªããžã§ã¯ãã®èªã¿åããšæžã蟌ã¿ãè¡ããŸãããããã¯å®çšŒåç°å¢ã®PostgreSQLãšé£æºããŠæ£åžžã«åäœããŸãã ãã ãããã®æ¹æ³ã§ã¯HSQLDBã§ãããã³ã°ãæ©èœãããé
åãå«ããšã³ãã£ãã£ããã¹ãããå¿
èŠããã£ãããããŠãŒã¶ãŒã¿ã€ãã®å®è£
ããããã«å€æŽããŸããã nullSafeSet()
ã¯nullSafeSet()
ããã³nullSafeGet()
nullSafeSet()
å®è£
ãçŽæ¥nullSafeSet()
åäœããPostgreSQLArrayStrategy
ã³ãŒããããã©ã«ãã§äœ¿çšããããã¹ãäžã«ç¹å¥ãªæŠç¥HsqldbArrayStrategy
ãŠãŒã¶ãŒã¿ã€ãã«æž¡ãããŸããã java.sql.Blob
ãã¹ããPostgreSQLã«ç¿»èš³ããåŸãHSQLDBã«é¢é£ãããã¹ãŠã®ãã®ãç°¡åã«åé€ã§ãããããã³ã°èªäœãæ©èœããããšãåçŽã«æã¿ãŸãããããã¡ããããã»ã©ç°¡åã§ã¯ãããŸããã§ããã å®çšŒåç°å¢ã§ã¯ãjavaã¿ã€ãã«å¯Ÿå¿ããsqlã¿ã€ããååŸããããã«ã AbstractJdbcConnection
ã¯ã©ã¹ã䜿çšãããŸããããã«ãããè¿œå èšå®ãªãã§é
åã¿ã€ããæ£ãã解決ãããŸãã æ®å¿µãªããããã¹ãã®å Žåããã®ã¢ãããŒãã¯éäžã§ããæ©èœããŸããã§ããããã¹ããçŽæ¥å®è¡ãããå Žåã«ã®ã¿connection
䜿çšãããŸããã åæã«ããã¹ãããŒã¿ããŒã¹ãäœæãããšããORMã¢ãã«ãè¡šãã¡ã¿ããŒã¿ãåæåããããšã SessionFactory
ã®äœæäžã«ã¿ã€ãã決å®ããå¥ã®ã¡ã«ããºã ãæ©èœããŸããã€ãŸãããããã®ãããã³ã°ãçºçããŸãã ãã®ã¡ã«ããºã ã§ã¯ãæ¹èšã®èª¬æã§é
åã®ã¿ã€ããæ瀺çã«ç€ºãå¿
èŠããããŸããããããªããšãHibernateã¯åçŽã«ãé
åãã¿ã€ãã®ãã£ãŒã«ããæã€ããŒãã«ãäœæã§ããŸããã§ããã
org.hibernate.MappingException: No Dialect mapping for JDBC type: 2003
åé¡ã¯ã2ã€ã®é
åïŒ String
ãšInteger
ïŒãããããã®æ¹æ³ã§æ¥ç¶ã§ããã®ã¯1ã€ã®ã¿ã€ãã ãã§ãããããæ¹èšãã¡ã€ã«ã®é
åã«sqlã¿ã€ããæå®ã§ããªãããšã§ãã
registerColumnType(Types.ARRAY, "integer[$l]");
åé¿çãæ¢ãå¿
èŠããããŸãããããšãã°ããŠãŒã¶ãŒã¿ã€ãããšã«ãé
åã¿ã€ãèå¥åãäœæãããŸãããããšãã°ãæååé
åã¯ã¿ã€ã200301
ã«é¢é£ä»ããããæŽæ°ã®é
åã¯ã¿ã€ã200301
ã«é¢é£ä»ããã200302
ã ãã®èå¥åã¯sqlTypes()
ã¡ãœããã§è¿ãããŸããïŒ
public class EnumArrayUserTypeString extends EnumArrayUserType { public static final int VARCHAR_ARRAY_SQL_TYPE = 200301; @Override public int[] sqlTypes() { return new int[] {VARCHAR_ARRAY_SQL_TYPE}; } //... }
次ã«ãã¿ã€ããæ¹èšã«ç»é²ãããŸããã
public class HHPostgreSQLDialect extends PostgreSQL9Dialect { public HHPostgreSQLDialect() { registerColumnType(EnumArrayUserTypeString.VARCHAR_ARRAY_SQL_TYPE, "varchar[$l]"); registerColumnType(EnumArrayUserTypeInteger.INT_ARRAY_SQL_TYPE, "integer[$l]"); } // ... }
ãããã®æäœã®åŸãHibernateã¯æçµçã«æºè¶³ããåé¡ãªãå¿ èŠãªããŒãã«ãäœæããŸããã
ããã©ãŒãã³ã¹ã®åé¡
ãŸã第äžã«ãæãé£ãã質åïŒãã¹ãã®ããã©ãŒãã³ã¹ã¯ã©ããªããŸãããïŒ çµå±ãHSQLDBã¯ââã¡ã¢ãªã«çŽæ¥é
眮ãããembedded-pgã¯çµã¿èŸŒã¿ã§ãããå®éã«ã¯æ¬æ ŒçãªããŒã¿ããŒã¹ã§ãããæåã¯å€§éã®ãã¡ã€ã«ãäœæããŸãã
æåã®çµæã¯ããªãæ鬱ã§ãã.SSDãæèŒãããã·ã³ã§ã¯ãã¢ãžã¥ãŒã«å
ã®ãã¹ãŠã®ãã¹ããå®è¡ãããšé床ã25ã30ïŒ
äœäžããSATAãæèŒããå€ããã·ã³ã§ã¯ãã¹ãŠãããã«æªåããŸããïŒ40ïŒ
ã«äœäžïŒã ãã¹ããè€æ°ã®ã¹ã¬ããã§å®è¡ãããå Žåãç¶æ³ã¯èããæ¹åãããŸããã
mvn clean test -T C1
-ããããç¹ã«ä»¥åã«ãã«ãã¹ã¬ããã¢ãŒãã§ãã¹ããå®è¡ããããšããã人ã«ãšã£ãŠã¯ãããã§ãåã³ã¯ãããŸããã§ããã
è€æ°ã®ã¢ãžã¥ãŒã«ã§æ§æããããããžã§ã¯ãããã¹ããããšãçããããã°ã«æ°ä»ããŸããïŒsurefireãå¥ã®ã¢ãžã¥ãŒã«ã®ãã¹ããéå§ãããšããã«ãæ°ããããŒã¿ããŒã¹ã€ã³ã¹ã¿ã³ã¹ãèµ·åããã次ã®ãã¹ãŠãå®è¡ããŸãïŒããŒã¿ã¹ããŒãã®äœæããã¹ãããŒã¿ã䜿çšããããŒãã«ã®äœæ-äžè¬çã«ãå€ãã®é«äŸ¡ãªI / Oæäœã ããã¯å¥åŠã«èŠããŸããã·ã³ã°ã«ãã³ã®ææè
ãããŒã¿ããŒã¹ã€ã³ã¹ã¿ã³ã¹ã®äœæãæ
åœããã€ã³ã¹ã¿ã³ã¹ãä¿åããããã®volatileãã£ãŒã«ãããåä¿¡ã¡ãœããã®ããã¯ãããã«ãã§ãã¯ãããªã©ããã¹ãŠã®ã«ãŒã«ã«åŸã£ãŠèšè¿°ãããŠããããã§ãã maven-surefire-pluginãå
¥ã£ããšãããã®ã·ã³ã°ã«ãã³ãã·ã³ã°ã«ãã³ã§ã¯ãªãããšãå€æãããšããç§ãã¡ã¯é©ããŸããïŒ
ããã©ã«ãã§ã¯ãå¥ã®ã¢ãžã¥ãŒã«ããã¹ããããšããsurefireã¯æ°ããJVMããã»ã¹ãäœæããŸãã ãã®ããã»ã¹ã§ã¯ãã¢ãžã¥ãŒã«ã«é¢é£ãããã¹ãŠã®ãã¹ããå®è¡ãããŸãã ãã¹ããå®äºãããšãsurefireã¯æ°ããJVMã§å®è¡ããã次ã®ã¢ãžã¥ãŒã«ã«é²ã¿ãŸãã ãã®åäœã¯forkCount
ãã©ã¡ãŒã¿ãŒã«ãã£ãŠå¶åŸ¡ãããŸãããã®ãã©ã¡ãŒã¿ãŒã®ããã©ã«ãã¯1ïŒã¢ãžã¥ãŒã«ããšã«1ã€ã®æ°ããJVMïŒã§ãã ãã®ãã©ã¡ãŒã¿ãŒã0ã«èšå®ãããšããã¹ãŠã®ã¢ãžã¥ãŒã«ãåãJVMã§å®è¡ãããŸãã
forkCount=1
ã䜿çšãããšãåã¢ãžã¥ãŒã«ã®éå§æã«æ°ããPostgreSQLã€ã³ã¹ã¿ã³ã¹ãåãåãããšãæããã«ãªããŸããã 次ã«ããã¹ãŠã®ãã¹ãã«1ã€ã®JVMã䜿çšããããšã決å®ããŸãããããã®å Žåã次ã®ã¢ãžã¥ãŒã«ãèµ·åãããã³ã«ã€ã³ã¹ã¿ã³ã¹ãäœæãããããšãããããŸããïŒ ãã®çç±ã¯ããããforkCount=0
å Žåã«forkCount=0
ã«ãã£ãŠäœ¿çšãããåé¢ã¯ã©ã¹ããŒããŒã§ããã ã·ã¹ãã ã¯ã©ã¹ããŒããŒã䜿çšããæ瀺çãªæç€ºïŒ useSystemClassloader=true
ïŒã«ããããããããã®å Žåãsurefireã¯åé¢ã«åãæ¿ãããŸãïŒã¡ãªã¿ã«ããã°ã§ãããå ±åããããã¥ã¡ã³ãã¯ãã®åäœã«çŠç¹ãåœãŠãŠããŸã-Maven Surefireã§ã®ã¯ã©ã¹ã®èªã¿èŸŒã¿ãšåå²ãåç
§ããŠãã ããïŒã ãããã£ãŠãã¢ãžã¥ãŒã«ããšã«åå¥ã®ã¯ã©ã¹ããŒããŒãäœæããããã¹ãŠã®ã¯ã©ã¹ãå床ãªããŒããããããã«å¿ããŠããŒã¿ããŒã¹ã€ã³ã¹ã¿ã³ã¹ãåç
§ããŠã·ã³ã°ã«ãã³ã€ã³ã¹ã¿ã³ã¹ãåäœæãããŸãã ãããã£ãŠãåé¡ã¯ç¢ºå®ãªãã¡ã€ã¢ã®å
éšã¡ã«ããºã ã«ãããã®ã§ãããä¿®æ£å¯èœãªããã©ãŒãã³ã¹ã®åŽé¢ã«çŠç¹ãåãããããšã«ããŸããã
RAMå ã®äžæãã¡ã€ã«
æåã«ãembedded-pgãæäœäžã«äœæããäžæãã¡ã€ã«ããã£ã¹ã¯ããã¡ã¢ãªã«è»¢éããããšãã€ãŸããRAM FSãšããŠããŠã³ããããããŒãã£ã·ã§ã³ã«é
眮ããããšã«ããŸããã ãã®ã¢ãããŒãã¯ãå°ãªããšãäœéãã£ã¹ã¯ãæèŒãããã·ã³ã§ç¶æ³ãæ¹åãããšæ³å®ãããŠããŸãããç¹ã«ããã®æç¹ã§å¥ã®DBMSã§ããApache Cassandraã®äœæ¥ãé«éåããããã®ãã¹ãã§æ¢ã«äœ¿çšãããŠããããããã€ãŒã«ãåçºæããå¿
èŠã¯ãªããã³ãŒãããããã«æ¡åŒµããŠçµ±äžããã ãã§ããã å¯äžã®ãããããïŒ tmpfsãã¡ã€ã«ã·ã¹ãã ããµããŒãããLinuxã®ã¿ã«çŠç¹ãåœãŠãå€ãã³ãŒãã Macã«ãtmpfsã®é¡äŒŒç©ããããŸãããLinuxãšã¯ç°ãªããMacOSã«ã¯/dev/shm
ã/run
on Linuxãªã©ã®ããã©ã«ããã¡ã€ã«ã·ã¹ãã ã§äœæãããããŒãã£ã·ã§ã³ã¯ãããŸããã äœæã¯éåžžã«ç°¡åã§ãããéçºè
ã®ã¢ã¯ã·ã§ã³ãå¿
èŠã§ãããããã¹ãŠãééçã«æ©èœããããšãæã¿ãŸããã Windows : , ( , ), RAM FS â â , , , RamDisk, PostgreSQL. , , , , ( 5%), .
, , : HSQLDB, in-memory database â , , PostgreSQL â jdbc url ! , Connection
, , , ? c3p0 â , HSQLDB. , , .
PostgreSQL
PostgreSQL:
-
autovacuum
; - (
preparedThreshold=X
) â 1 4; - , ,
shared_buffers
effective_cache_size
( , ). , , â , RAM, .
?
HSQLDB PostgreSQL, , . , , , â , , , .
, : - , , . - â , maven-surefire-plugin PostgreSQL. : , , - - .
UPD: , yandex-qatools " «»" â â . Lanwen !