|
本帖最后由 linxin@msn.com 于 2014-3-22 16:21 编辑
BIZAPI 中的 DatabaseProduct 实现有点囧。
paramConnection.getMetaData().getDatabaseProductName() 被反复调用, 使用MYSQL 数据库的好悲剧,需要调用10多次才能返回。- public enum DatabaseProduct
- {
- ORACLE, MSSQL, HSQLDB, SYBASE, DB2, KINGBASE, DEFAULT, MYSQL;
-
- private static Logger logger = Logger.getLogger(DatabaseProduct.class);
-
- private DatabaseProduct() {}
-
- public static DatabaseProduct getProduct(Connection paramConnection)
- throws SQLException
- {
- Utils.check(Utils.isNotNull(paramConnection), CommonMessages.class, "JUSTEP050006", "conn");
- if (logger.isDebugEnabled())
- {
- logger.debug("Connection product name:" + paramConnection.getMetaData().getDatabaseProductName());
- logger.debug("Connection product version:" + paramConnection.getMetaData().getDatabaseProductVersion());
- }
- if ((paramConnection.getMetaData().getDatabaseProductName().equals("Oracle")) || (paramConnection.getMetaData().getDatabaseProductName().equals("OSRDB"))) {
- return ORACLE;
- }
- if (paramConnection.getMetaData().getDatabaseProductName().equals("Microsoft SQL Server")) {
- return MSSQL;
- }
- if (paramConnection.getMetaData().getDatabaseProductName().equals("sql server")) {
- return SYBASE;
- }
- if ((paramConnection.getMetaData().getDatabaseProductName().equals("ASE")) || (paramConnection.getMetaData().getDatabaseProductName().equals("Adaptive Server Enterprise"))) {
- return SYBASE;
- }
- if (paramConnection.getMetaData().getDatabaseProductName().startsWith("DB2")) {
- return DB2;
- }
- if (paramConnection.getMetaData().getDatabaseProductName().equals("HSQL Database Engine")) {
- return HSQLDB;
- }
- if (paramConnection.getMetaData().getDatabaseProductName().equals("KingbaseES")) {
- return KINGBASE;
- }
- if (paramConnection.getMetaData().getDatabaseProductName().equals("MySQL")) {
- return MYSQL;
- }
- throw KSQLException.create("JUSTEP150030", new Object[] { paramConnection.getMetaData().getDatabaseProductName() });
- }
- }
复制代码 |
|