(注:このブログはもう更新していません)この日記は私的なものであり所属会社の見解とは無関係です。 GitHub: takahashikzn

[クラウド帳票エンジンDocurain]

EclipseLinkがDBを自動判定する仕組み

EclipseLinkは、DBに応じた固有のSQLを生成することでパフォーマンスを稼ぐ機能を持っています (eclipselink.jdbc.native-sql)。


そして、設定ファイルに何も書かなくてもDB製品は自動判定されているのですが、そのあたりの処理は
org.eclipse.persistence.internal.sessions.DatabaseSessionImplクラスのsetOrDetectDatasource
で行われています。


このメソッドは更に
org.eclipse.persistence.internal.helper.DBPlatformHelper
へ処理を移譲しており、ここでやっと判定の具体的な処理が登場するわけです。


細かい話は端折りますが、当然ながら製品名の正規表現マッチングを行っているわけでして、その元ネタがこれ。DBPlatformHelperと同じパッケージのプロパティファイルの内容です。

(?i)oracle.*12=org.eclipse.persistence.platform.database.oracle.Oracle11Platform
(?i)oracle.*11=org.eclipse.persistence.platform.database.oracle.Oracle11Platform
(?i)oracle.*10=org.eclipse.persistence.platform.database.oracle.Oracle10Platform
(?i)oracle.*9=org.eclipse.persistence.platform.database.oracle.Oracle9Platform
(?i)oracle.*=org.eclipse.persistence.platform.database.oracle.OraclePlatform
SQL\ Anywhere.*=org.eclipse.persistence.platform.database.SQLAnywherePlatform
(?i)(sybase.*)|(adaptive\ server\ enterprise.*)|(SQL\ Server.*)=org.eclipse.persistence.platform.database.SybasePlatform
(?i)microsoft.*=org.eclipse.persistence.platform.database.SQLServerPlatform
#Use JavaDBPlatform as the platform for Derby
(?i).*derby.*=org.eclipse.persistence.platform.database.JavaDBPlatform
(?i).*db2.*=org.eclipse.persistence.platform.database.DB2Platform
(?i)pointbase.*=org.eclipse.persistence.platform.database.PointBasePlatform
(?i)mysql.*=org.eclipse.persistence.platform.database.MySQLPlatform
(?i)informix.*=org.eclipse.persistence.platform.database.InformixPlatform
(?i)postgresql.*=org.eclipse.persistence.platform.database.PostgreSQLPlatform
(?i)h2.*=org.eclipse.persistence.platform.database.H2Platform
(?i)hsql.*=org.eclipse.persistence.platform.database.HSQLPlatform
(?i)firebird.*=org.eclipse.persistence.platform.database.FirebirdPlatform
(?i).*symfoware.*=org.eclipse.persistence.platform.database.SymfowarePlatform
(?i)access.*=org.eclipse.persistence.platform.database.AccessPlatform
SAP\ DB.*=org.eclipse.persistence.platform.database.MaxDBPlatform
HDB.*=org.eclipse.persistence.platform.database.HANAPlatform


パッと見の感想としては、

  • Oracleが優遇されているのは、EclipseLinkが元はOracleの製品だったから?
  • MariaDBのエントリは無いが、MariaDBは自分のことをMySQLだと主張するのでMySQLにマッチ
    • DatabaseMetaData#getDatabaseProductNameMySQL1010.0.19-MariaDBのような文字列を返す
  • SAP向けDBに対する、微妙なやる気の無さ

MariaDBの判定はどーすんだ...?

将来的にMariaDB用の方言が実装された時、どうやって判定するんですかね。SHOW VARIABLES LIKE ...でも発行するんだろうか。