public DialectPostgreSQL( DatabaseMetaData metadata, BinaryManager binaryManager, RepositoryDescriptor repositoryDescriptor) throws StorageException { super(metadata, binaryManager, repositoryDescriptor); fulltextAnalyzer = repositoryDescriptor == null ? null : repositoryDescriptor.fulltextAnalyzer == null ? DEFAULT_FULLTEXT_ANALYZER : repositoryDescriptor.fulltextAnalyzer; pathOptimizationsEnabled = repositoryDescriptor == null ? false : repositoryDescriptor.pathOptimizationsEnabled; int major, minor; try { major = metadata.getDatabaseMajorVersion(); minor = metadata.getDatabaseMinorVersion(); } catch (SQLException e) { throw new StorageException(e); } supportsWith = major > 8 || (major == 8 && minor >= 4); usersSeparator = repositoryDescriptor == null ? null : repositoryDescriptor.usersSeparatorKey == null ? DEFAULT_USERS_SEPARATOR : repositoryDescriptor.usersSeparatorKey; try { compatibilityFulltextTable = getCompatibilityFulltextTable(metadata); } catch (SQLException e) { throw new StorageException(e); } }
private void populateMetaData(DataSource dataSource) { Connection connection = null; try { try { connection = dataSource.getConnection(); DatabaseMetaData metaData = connection.getMetaData(); CommonParameters.set( CommonParameters.DATABASE_PRODUCT_NAME, metaData.getDatabaseProductName()); CommonParameters.set( CommonParameters.DATABASE_PRODUCT_VERSION, metaData.getDatabaseProductVersion()); CommonParameters.set( CommonParameters.DATABASE_MINOR_VERSION, metaData.getDatabaseMinorVersion() + EMPTY); CommonParameters.set( CommonParameters.DATABASE_MAJOR_VERSION, metaData.getDatabaseMajorVersion() + EMPTY); CommonParameters.set(CommonParameters.DATABASE_DRIVER_NAME, metaData.getDriverName()); CommonParameters.set( CommonParameters.DATABASE_DRIVER_MINOR_VERSION, metaData.getDriverMinorVersion() + EMPTY); CommonParameters.set( CommonParameters.DATABASE_DRIVER_MAJOR_VERSION, metaData.getDriverMajorVersion() + EMPTY); CommonParameters.set( CommonParameters.DATABASE_CONNECTION_CLASS_NAME, connection.getClass().getCanonicalName()); } finally { if (connection != null) { connection.close(); } } } catch (SQLException e) { logger.error(e.getMessage(), e); } }
/** Returns the PostgreSQL version */ public Version getPostgreSQLVersion(Connection conn) throws SQLException { if (pgsqlVersion == null) { DatabaseMetaData md = conn.getMetaData(); pgsqlVersion = new Version( String.format("%d.%d", md.getDatabaseMajorVersion(), md.getDatabaseMinorVersion())); } return pgsqlVersion; }
public int getDatabaseMinorVersion() throws SQLException { { try { return _meta.getDatabaseMinorVersion(); } catch (SQLException e) { handleException(e); return 0; } } }
public DialectPostgreSQL(DatabaseMetaData metadata, RepositoryDescriptor repositoryDescriptor) { super(metadata, repositoryDescriptor); fulltextAnalyzer = repositoryDescriptor == null ? null : repositoryDescriptor.fulltextAnalyzer == null ? DEFAULT_FULLTEXT_ANALYZER : repositoryDescriptor.fulltextAnalyzer; pathOptimizationsEnabled = repositoryDescriptor == null ? false : repositoryDescriptor.getPathOptimizationsEnabled(); int major, minor; try { major = metadata.getDatabaseMajorVersion(); minor = metadata.getDatabaseMinorVersion(); } catch (SQLException e) { throw new NuxeoException(e); } supportsWith = major > 8 || (major == 8 && minor >= 4); if ((major == 9 && minor >= 1) || (major > 9)) { unloggedKeyword = UNLOGGED_KEYWORD; } else { unloggedKeyword = ""; } usersSeparator = repositoryDescriptor == null ? null : repositoryDescriptor.usersSeparatorKey == null ? DEFAULT_USERS_SEPARATOR : repositoryDescriptor.usersSeparatorKey; String idt = repositoryDescriptor == null ? null : repositoryDescriptor.idType; if (idt == null || "".equals(idt) || "varchar".equalsIgnoreCase(idt)) { idType = DialectIdType.VARCHAR; } else if ("uuid".equalsIgnoreCase(idt)) { idType = DialectIdType.UUID; } else if (idt.toLowerCase().startsWith("sequence")) { idType = DialectIdType.SEQUENCE; if (idt.toLowerCase().startsWith("sequence:")) { String[] split = idt.split(":"); idSequenceName = split[1]; } else { idSequenceName = "hierarchy_seq"; } } else { throw new NuxeoException("Unknown id type: '" + idt + "'"); } try { compatibilityFulltextTable = getCompatibilityFulltextTable(metadata); } catch (SQLException e) { throw new NuxeoException(e); } }
public DatabaseInfo(DatabaseMetaData metaData) throws SQLException { try { this.productName = metaData.getDatabaseProductName(); this.productVersion = metaData.getDatabaseProductVersion(); this.minorVersion = metaData.getDatabaseMinorVersion(); this.majorVersion = metaData.getDatabaseMajorVersion(); } catch (Error e) { if (logger.isErrorEnabled()) { logger.error( (format( "JDBC Driver %s version is not applicable for Migrator, use latest version of the driver", metaData.getDriverVersion()))); } System.exit(DRIVER_ERROR); } }
/** Initializes DatabaseFactory. */ public static synchronized void init() { if (dataSource != null) { return; } DatabaseConfig.load(); try { DatabaseConfig.DATABASE_DRIVER.newInstance(); } catch (Exception e) { log.fatal("Error obtaining DB driver", e); throw new Error("DB Driver doesnt exist!"); } connectionPool = new GenericObjectPool(); if (DatabaseConfig.DATABASE_CONNECTIONS_MIN > DatabaseConfig.DATABASE_CONNECTIONS_MAX) { log.error( "Please check your database configuration. Minimum amount of connections is > maximum"); DatabaseConfig.DATABASE_CONNECTIONS_MAX = DatabaseConfig.DATABASE_CONNECTIONS_MIN; } connectionPool.setMaxIdle(DatabaseConfig.DATABASE_CONNECTIONS_MIN); connectionPool.setMaxActive(DatabaseConfig.DATABASE_CONNECTIONS_MAX); /* test if connection is still valid before returning */ connectionPool.setTestOnBorrow(true); try { dataSource = setupDataSource(); Connection c = getConnection(); DatabaseMetaData dmd = c.getMetaData(); databaseName = dmd.getDatabaseProductName(); databaseMajorVersion = dmd.getDatabaseMajorVersion(); databaseMinorVersion = dmd.getDatabaseMinorVersion(); c.close(); } catch (Exception e) { log.fatal("Error with connection string: " + DatabaseConfig.DATABASE_URL, e); throw new Error("DatabaseFactory not initialized!"); } log.info("Successfully connected to database"); }
@Override protected Dialect resolveDialectInternal(DatabaseMetaData metaData) throws SQLException { String databaseName = metaData.getDatabaseProductName(); int databaseMajorVersion = metaData.getDatabaseMajorVersion(); if ("CUBRID".equalsIgnoreCase(databaseName)) { return new CUBRIDDialect(); } if ("HSQL Database Engine".equals(databaseName)) { return new HSQLDialect(); } if ("H2".equals(databaseName)) { return new H2Dialect(); } if ("MySQL".equals(databaseName)) { return new MySQLDialect(); } if ("PostgreSQL".equals(databaseName)) { final int databaseMinorVersion = metaData.getDatabaseMinorVersion(); if (databaseMajorVersion >= 8 && databaseMinorVersion >= 2) { return new PostgreSQL82Dialect(); } return new PostgreSQL81Dialect(); } if ("Apache Derby".equals(databaseName)) { final int databaseMinorVersion = metaData.getDatabaseMinorVersion(); if (databaseMajorVersion > 10 || (databaseMajorVersion == 10 && databaseMinorVersion >= 7)) { return new DerbyTenSevenDialect(); } else if (databaseMajorVersion == 10 && databaseMinorVersion == 6) { return new DerbyTenSixDialect(); } else if (databaseMajorVersion == 10 && databaseMinorVersion == 5) { return new DerbyTenFiveDialect(); } else { return new DerbyDialect(); } } if ("ingres".equalsIgnoreCase(databaseName)) { switch (databaseMajorVersion) { case 9: int databaseMinorVersion = metaData.getDatabaseMinorVersion(); if (databaseMinorVersion > 2) { return new Ingres9Dialect(); } return new IngresDialect(); case 10: return new Ingres10Dialect(); default: LOG.unknownIngresVersion(databaseMajorVersion); } return new IngresDialect(); } if (databaseName.startsWith("Microsoft SQL Server")) { switch (databaseMajorVersion) { case 8: return new SQLServerDialect(); case 9: return new SQLServer2005Dialect(); case 10: return new SQLServer2008Dialect(); default: LOG.unknownSqlServerVersion(databaseMajorVersion); } return new SQLServerDialect(); } if ("Sybase SQL Server".equals(databaseName) || "Adaptive Server Enterprise".equals(databaseName)) { return new SybaseASE15Dialect(); } if (databaseName.startsWith("Adaptive Server Anywhere")) { return new SybaseAnywhereDialect(); } if ("Informix Dynamic Server".equals(databaseName)) { return new InformixDialect(); } if (databaseName.equals("DB2 UDB for AS/400")) { return new DB2400Dialect(); } if (databaseName.startsWith("DB2/")) { return new DB2Dialect(); } if ("Oracle".equals(databaseName)) { switch (databaseMajorVersion) { case 11: return new Oracle10gDialect(); case 10: return new Oracle10gDialect(); case 9: return new Oracle9iDialect(); case 8: return new Oracle8iDialect(); default: LOG.unknownOracleVersion(databaseMajorVersion); } } return null; }
public JSONObject execute( HttpServletRequest request, HttpServletResponse response, EntityManager em, EntityTransaction et) throws Exception { DatabaseNode dn = (DatabaseNode) IDManager.get().get(id); JSONObject results = new JSONObject(); JSONArray meta = new JSONArray(); JSONArray data = new JSONArray(); String[] strs = {"Property", "Value"}; for (int i = 0; i < strs.length; i++) { meta.put(strs[i]); } SQLDatabaseMetaData metaData = dn.getConn().getSQLMetaData(); DatabaseMetaData jdbcmetadata = metaData.getJDBCMetaData(); JSONArray record = new JSONArray(); record.put("Database Product Name"); try { record.put(metaData.getDatabaseProductName()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Database Product Version"); try { record.put(metaData.getDatabaseProductVersion()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Driver Major Version"); try { record.put(jdbcmetadata.getDriverMajorVersion()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Driver Minor Version"); try { record.put(jdbcmetadata.getDriverMinorVersion()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Driver Name"); try { record.put(metaData.getDriverName()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Driver Version"); try { record.put(jdbcmetadata.getDriverVersion()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Username"); try { record.put(metaData.getUserName()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("URL"); try { record.put(jdbcmetadata.getURL()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); // record=new JSONArray(); // record.put("Auto Commit"); // try{ // record.put(dn.getConn().getAutoCommit()); // // }catch(Throwable e){record.put("Unsupported");} // data.put(record); record = new JSONArray(); record.put("All Procedures Are Callable"); try { record.put(jdbcmetadata.allProceduresAreCallable()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("All Tables Are Selectable"); try { record.put(jdbcmetadata.allTablesAreSelectable()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Nulls are sorted High"); try { record.put(jdbcmetadata.nullsAreSortedHigh()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Nulls are sorted Low"); try { record.put(jdbcmetadata.nullsAreSortedLow()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Nulls are sorted at Start"); try { record.put(jdbcmetadata.nullsAreSortedAtStart()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Nulls are sorted at End"); try { record.put(jdbcmetadata.nullsAreSortedAtEnd()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Is Read Only"); try { record.put(jdbcmetadata.isReadOnly()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Result Set Holdability"); try { record.put(jdbcmetadata.getResultSetHoldability()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Uses Local Files"); try { record.put(jdbcmetadata.usesLocalFiles()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Uses Local File per Table"); try { record.put(jdbcmetadata.usesLocalFilePerTable()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Mixed Case Identifiers"); try { record.put(jdbcmetadata.supportsMixedCaseIdentifiers()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Stores Upper Case Identifiers"); try { record.put(jdbcmetadata.storesUpperCaseIdentifiers()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Stores Lower Case Identifiers"); try { record.put(jdbcmetadata.storesLowerCaseIdentifiers()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Stores Mixed Case Identifiers"); try { record.put(jdbcmetadata.storesMixedCaseIdentifiers()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Mixed Case Quoted Identifiers"); try { record.put(jdbcmetadata.supportsMixedCaseQuotedIdentifiers()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Stores Upper Case Quoted Identifiers"); try { record.put(jdbcmetadata.storesUpperCaseQuotedIdentifiers()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Stores Lower Case Quoted Identifiers"); try { record.put(jdbcmetadata.storesLowerCaseQuotedIdentifiers()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Stores Mixed Case Quoted Identifiers"); try { record.put(jdbcmetadata.storesMixedCaseQuotedIdentifiers()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Identifier Quote"); try { record.put(jdbcmetadata.getIdentifierQuoteString()); } catch (Throwable e) { } data.put(record); record = new JSONArray(); record.put("Search String Escape"); try { record.put(jdbcmetadata.getSearchStringEscape()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Extra Name Characters"); try { record.put(jdbcmetadata.getExtraNameCharacters()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Alter Table With Add Column"); try { record.put(jdbcmetadata.supportsAlterTableWithAddColumn()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Alter Table With Drop Column"); try { record.put(jdbcmetadata.supportsAlterTableWithDropColumn()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Column Aliasing"); try { record.put(jdbcmetadata.supportsColumnAliasing()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Null Plus Non Null Is Null"); try { record.put(jdbcmetadata.nullPlusNonNullIsNull()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Convert"); try { record.put(jdbcmetadata.supportsConvert()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Table Correlation Names"); try { record.put(jdbcmetadata.supportsTableCorrelationNames()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Expressions in Order By"); try { record.put(jdbcmetadata.supportsExpressionsInOrderBy()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Order By Unrelated"); try { record.put(jdbcmetadata.supportsOrderByUnrelated()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Group By"); try { record.put(jdbcmetadata.supportsGroupBy()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Group By Unrelated"); try { record.put(jdbcmetadata.supportsGroupByUnrelated()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Group By Beyond Select"); try { record.put(jdbcmetadata.supportsGroupByBeyondSelect()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Like Escape Clause"); try { record.put(jdbcmetadata.supportsLikeEscapeClause()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Multiple Result Sets"); try { record.put(jdbcmetadata.supportsMultipleResultSets()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Multiple Open Results"); try { record.put(jdbcmetadata.supportsMultipleOpenResults()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Multiple Transactions"); try { record.put(jdbcmetadata.supportsMultipleTransactions()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Non Nullable Columns"); try { record.put(jdbcmetadata.supportsNonNullableColumns()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Minimum SQL Grammar"); try { record.put(jdbcmetadata.supportsMinimumSQLGrammar()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Core SQL Grammar"); try { record.put(jdbcmetadata.supportsCoreSQLGrammar()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Extended SQL Grammar"); try { record.put(jdbcmetadata.supportsExtendedSQLGrammar()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports ANSI92 Entry Level SQL"); try { record.put(jdbcmetadata.supportsANSI92EntryLevelSQL()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports ANSI92 Intermediate SQL"); try { record.put(jdbcmetadata.supportsANSI92IntermediateSQL()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports ANSI92 Full SQL"); try { record.put(jdbcmetadata.supportsANSI92FullSQL()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Integrity Enhancement Facility"); try { record.put(jdbcmetadata.supportsIntegrityEnhancementFacility()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Outer Joins"); try { record.put(jdbcmetadata.supportsOuterJoins()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Full Outer Joins"); try { record.put(jdbcmetadata.supportsFullOuterJoins()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Limited Outer Joins"); try { record.put(jdbcmetadata.supportsLimitedOuterJoins()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Schema Term"); try { record.put(jdbcmetadata.getSchemaTerm()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Procedure Term"); try { record.put(jdbcmetadata.getProcedureTerm()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Catalog Term"); try { record.put(jdbcmetadata.getCatalogTerm()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Is Catalog at Start"); try { record.put(jdbcmetadata.isCatalogAtStart()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Catalog Separator"); try { record.put(jdbcmetadata.getCatalogSeparator()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Schemas In Data Manipulation"); try { record.put(jdbcmetadata.supportsSchemasInDataManipulation()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Schemas In Procedure Calls"); try { record.put(jdbcmetadata.supportsSchemasInProcedureCalls()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Schemas In Table Definitions"); try { record.put(jdbcmetadata.supportsSchemasInTableDefinitions()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Schemas In Index Definitions"); try { record.put(jdbcmetadata.supportsSchemasInIndexDefinitions()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Schemas In Privilege Definitions"); try { record.put(jdbcmetadata.supportsSchemasInPrivilegeDefinitions()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Catalogs In Data Manipulation"); try { record.put(jdbcmetadata.supportsCatalogsInDataManipulation()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Catalogs In Procedure Calls"); try { record.put(jdbcmetadata.supportsCatalogsInProcedureCalls()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Catalogs In Table Definitions"); try { record.put(jdbcmetadata.supportsCatalogsInTableDefinitions()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Catalogs In Index Definitions"); try { record.put(jdbcmetadata.supportsCatalogsInIndexDefinitions()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Catalogs In Privilege Definitions"); try { record.put(jdbcmetadata.supportsCatalogsInPrivilegeDefinitions()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Positioned Delete"); try { record.put(jdbcmetadata.supportsPositionedDelete()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Positioned Update"); try { record.put(jdbcmetadata.supportsPositionedUpdate()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Select For Update"); try { record.put(jdbcmetadata.supportsSelectForUpdate()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Stored Procedures"); try { record.put(jdbcmetadata.supportsStoredProcedures()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Subqueries In Comparisons"); try { record.put(jdbcmetadata.supportsSubqueriesInComparisons()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Subqueries In Exists"); try { record.put(jdbcmetadata.supportsSubqueriesInExists()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Subqueries in IN Statements"); try { record.put(jdbcmetadata.supportsSubqueriesInIns()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Correlated Subqueries"); try { record.put(jdbcmetadata.supportsCorrelatedSubqueries()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Union"); try { record.put(jdbcmetadata.supportsUnion()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Union All"); try { record.put(jdbcmetadata.supportsUnionAll()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Open Cursors Across Commit"); try { record.put(jdbcmetadata.supportsOpenCursorsAcrossCommit()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Open Cursors Across Rollback"); try { record.put(jdbcmetadata.supportsOpenCursorsAcrossRollback()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Open Statements Across Commit"); try { record.put(jdbcmetadata.supportsOpenStatementsAcrossCommit()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Open Statements Across Rollback"); try { record.put(jdbcmetadata.supportsOpenStatementsAcrossRollback()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Binary Literal Length"); try { record.put(jdbcmetadata.getMaxBinaryLiteralLength()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Char Literal Length"); try { record.put(jdbcmetadata.getMaxCharLiteralLength()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Column Name Length"); try { record.put(jdbcmetadata.getMaxColumnNameLength()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Columns In Group By"); try { record.put(jdbcmetadata.getMaxColumnsInGroupBy()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Columns In Index"); try { record.put(jdbcmetadata.getMaxColumnsInIndex()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Columns In Order By"); try { record.put(jdbcmetadata.getMaxColumnsInOrderBy()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Columns In Select"); try { record.put(jdbcmetadata.getMaxColumnsInSelect()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Columns In Table"); try { record.put(jdbcmetadata.getMaxColumnsInTable()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Connections"); try { record.put(jdbcmetadata.getMaxConnections()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Cursor Name Length"); try { record.put(jdbcmetadata.getMaxCursorNameLength()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Index Length"); try { record.put(jdbcmetadata.getMaxIndexLength()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Schema Name Length"); try { record.put(jdbcmetadata.getMaxSchemaNameLength()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Procedure Name Length"); try { record.put(jdbcmetadata.getMaxProcedureNameLength()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Catalog Name Length"); try { record.put(jdbcmetadata.getMaxCatalogNameLength()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Row Size"); try { record.put(jdbcmetadata.getMaxRowSize()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Row Size Include Blobs"); try { record.put(jdbcmetadata.doesMaxRowSizeIncludeBlobs()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Statement Length"); try { record.put(jdbcmetadata.getMaxStatementLength()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Statements"); try { record.put(jdbcmetadata.getMaxStatements()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Table Name Length"); try { record.put(jdbcmetadata.getMaxTableNameLength()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max Tables In Select"); try { record.put(jdbcmetadata.getMaxTablesInSelect()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Max User Name Length"); try { record.put(jdbcmetadata.getMaxUserNameLength()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Default Transaction Isolation"); try { int isol = jdbcmetadata.getDefaultTransactionIsolation(); String is = null; switch (isol) { case java.sql.Connection.TRANSACTION_NONE: { is = "TRANSACTION_NONE"; break; } case java.sql.Connection.TRANSACTION_READ_COMMITTED: { is = "TRANSACTION_READ_COMMITTED"; break; } case java.sql.Connection.TRANSACTION_READ_UNCOMMITTED: { is = "TRANSACTION_READ_UNCOMMITTED"; break; } case java.sql.Connection.TRANSACTION_REPEATABLE_READ: { is = "TRANSACTION_REPEATABLE_READ"; break; } case java.sql.Connection.TRANSACTION_SERIALIZABLE: { is = "TRANSACTION_SERIALIZABLE"; break; } default: { is = ""; break; } } record.put(is); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Transactions"); try { record.put(jdbcmetadata.supportsTransactions()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Data Definition and Data Manipulation Transactions"); try { record.put(jdbcmetadata.supportsDataDefinitionAndDataManipulationTransactions()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Different Table Correlation Names"); try { record.put(jdbcmetadata.supportsDifferentTableCorrelationNames()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Data Manipulation Transactions Only"); try { record.put(jdbcmetadata.supportsDataManipulationTransactionsOnly()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Data Definition Causes Transaction Commit"); try { record.put(jdbcmetadata.dataDefinitionCausesTransactionCommit()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Data Definition Ignored in Transactions"); try { record.put(jdbcmetadata.dataDefinitionIgnoredInTransactions()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Batch Updates"); try { record.put(jdbcmetadata.supportsBatchUpdates()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Savepoints"); try { record.put(jdbcmetadata.supportsSavepoints()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Named Parameters"); try { record.put(jdbcmetadata.supportsNamedParameters()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Get Generated Keys"); try { record.put(jdbcmetadata.supportsGetGeneratedKeys()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Database Major Version"); try { record.put(jdbcmetadata.getDatabaseMajorVersion()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Database Minor Version"); try { record.put(jdbcmetadata.getDatabaseMinorVersion()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("JDBC Minor Version"); try { record.put(jdbcmetadata.getJDBCMinorVersion()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("JDBC Major Version"); try { record.put(jdbcmetadata.getJDBCMajorVersion()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("SQL State Type"); try { int sqlStateType = jdbcmetadata.getSQLStateType(); String is = null; switch (sqlStateType) { case DatabaseMetaData.sqlStateXOpen: { is = "sqlStateXOpen"; break; } case DatabaseMetaData.sqlStateSQL: { is = "sqlStateSQL"; break; } default: is = ""; } record.put(is); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Locators Update Copy"); try { record.put(jdbcmetadata.locatorsUpdateCopy()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Statement Pooling"); try { record.put(jdbcmetadata.supportsStatementPooling()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("SQL Keywords"); try { record.put(jdbcmetadata.getSQLKeywords()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Numeric Functions"); try { record.put(jdbcmetadata.getNumericFunctions()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("String Functions"); try { record.put(jdbcmetadata.getStringFunctions()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("System Functions"); try { record.put(jdbcmetadata.getSystemFunctions()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Time and Date Functions"); try { record.put(jdbcmetadata.getTimeDateFunctions()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Auto Commit Failure Closes All ResultSets"); try { record.put(jdbcmetadata.autoCommitFailureClosesAllResultSets()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Stored Functions Using Call Syntax"); try { record.put(jdbcmetadata.supportsStoredFunctionsUsingCallSyntax()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Supports Subqueries in Quantified Expressions"); try { record.put(jdbcmetadata.supportsSubqueriesInQuantifieds()); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("Client Info Properties"); try { ResultSet rs = jdbcmetadata.getClientInfoProperties(); while (rs.next()) { rs.getString("NAME"); } rs.close(); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); record = new JSONArray(); record.put("ROWID Lifetime"); try { RowIdLifetime rid = jdbcmetadata.getRowIdLifetime(); if (rid.equals(RowIdLifetime.ROWID_UNSUPPORTED)) record.put("ROWID_UNSUPPORTED"); else if (rid.equals(RowIdLifetime.ROWID_VALID_FOREVER)) record.put("ROWID_VALID_FOREVER"); else if (rid.equals(RowIdLifetime.ROWID_VALID_OTHER)) record.put("ROWID_VALID_OTHER"); else if (rid.equals(RowIdLifetime.ROWID_VALID_SESSION)) record.put("ROWID_VALID_SESSION"); else if (rid.equals(RowIdLifetime.ROWID_VALID_TRANSACTION)) record.put("ROWID_VALID_TRANSACTION"); else record.put(""); } catch (Throwable e) { record.put("Unsupported"); } data.put(record); results.put("meta", meta); results.put("data", data); return results; }
public void testMetaData() { String ddl0 = "DROP TABLE ADDRESSBOOK IF EXISTS; DROP TABLE ADDRESSBOOK_CATEGORY IF EXISTS; DROP TABLE USER IF EXISTS;"; String ddl1 = "CREATE TABLE USER(USER_ID INTEGER NOT NULL PRIMARY KEY,LOGIN_ID VARCHAR(128) NOT NULL,USER_NAME VARCHAR(254) DEFAULT ' ' NOT NULL,CREATE_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,UPDATE_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,LAST_ACCESS_DATE TIMESTAMP,CONSTRAINT IXUQ_LOGIN_ID0 UNIQUE(LOGIN_ID))"; String ddl2 = "CREATE TABLE ADDRESSBOOK_CATEGORY(USER_ID INTEGER NOT NULL,CATEGORY_ID INTEGER DEFAULT 0 NOT NULL,CATEGORY_NAME VARCHAR(60) DEFAULT '' NOT NULL,CONSTRAINT SYS_PK_ADDRESSBOOK_CATEGORY PRIMARY KEY(USER_ID,CATEGORY_ID),CONSTRAINT FK_ADRBKCAT1 FOREIGN KEY(USER_ID) REFERENCES USER(USER_ID) ON DELETE CASCADE)"; String ddl3 = "CREATE TABLE ADDRESSBOOK(USER_ID INTEGER NOT NULL,ADDRESSBOOK_ID INTEGER NOT NULL,CATEGORY_ID INTEGER DEFAULT 0 NOT NULL,FIRST VARCHAR(64) DEFAULT '' NOT NULL,LAST VARCHAR(64) DEFAULT '' NOT NULL,NOTE VARCHAR(128) DEFAULT '' NOT NULL,CONSTRAINT SYS_PK_ADDRESSBOOK PRIMARY KEY(USER_ID,ADDRESSBOOK_ID),CONSTRAINT FK_ADRBOOK1 FOREIGN KEY(USER_ID,CATEGORY_ID) REFERENCES ADDRESSBOOK_CATEGORY(USER_ID,CATEGORY_ID) ON DELETE CASCADE)"; String result1 = "1"; String result2 = "2"; String result3 = "3"; String result4 = "4"; String result5 = "5"; try { stmnt.execute(ddl0); stmnt.execute(ddl1); stmnt.execute(ddl2); stmnt.execute(ddl3); DatabaseMetaData md = connection.getMetaData(); { System.out.println("Testing DatabaseMetaData methods"); System.out.println(md.getDatabaseMajorVersion()); System.out.println(md.getDatabaseMinorVersion()); System.out.println(md.getDatabaseProductName()); System.out.println(md.getDatabaseProductVersion()); System.out.println(md.getDefaultTransactionIsolation()); System.out.println(md.getDriverMajorVersion()); System.out.println(md.getDriverMinorVersion()); System.out.println(md.getDriverName()); System.out.println(md.getDriverVersion()); System.out.println(md.getExtraNameCharacters()); System.out.println(md.getIdentifierQuoteString()); System.out.println(md.getJDBCMajorVersion()); System.out.println(md.getJDBCMinorVersion()); System.out.println(md.getMaxBinaryLiteralLength()); System.out.println(md.getMaxCatalogNameLength()); System.out.println(md.getMaxColumnsInGroupBy()); System.out.println(md.getMaxColumnsInIndex()); System.out.println(md.getMaxColumnsInOrderBy()); System.out.println(md.getMaxColumnsInSelect()); System.out.println(md.getMaxColumnsInTable()); System.out.println(md.getMaxConnections()); System.out.println(md.getMaxCursorNameLength()); System.out.println(md.getMaxIndexLength()); System.out.println(md.getMaxProcedureNameLength()); System.out.println(md.getMaxRowSize()); System.out.println(md.getMaxSchemaNameLength()); System.out.println(md.getMaxStatementLength()); System.out.println(md.getMaxStatements()); System.out.println(md.getMaxTableNameLength()); System.out.println(md.getMaxUserNameLength()); System.out.println(md.getNumericFunctions()); System.out.println(md.getProcedureTerm()); System.out.println(md.getResultSetHoldability()); System.out.println(md.getSchemaTerm()); System.out.println(md.getSearchStringEscape()); System.out.println("Testing DatabaseMetaData.getSQLKeywords()"); System.out.println(md.getSQLKeywords()); System.out.println(md.getSQLStateType()); System.out.println("Testing DatabaseMetaData.getStringFunctions()"); System.out.println(md.getStringFunctions()); System.out.println("Testing DatabaseMetaData.getSystemFunctions()"); System.out.println(md.getSystemFunctions()); System.out.println("Testing DatabaseMetaData.getTimeDateFunctions()"); System.out.println(md.getTimeDateFunctions()); System.out.println(md.getURL()); System.out.println(md.getUserName()); System.out.println(DatabaseMetaData.importedKeyCascade); System.out.println(md.isCatalogAtStart()); System.out.println(md.isReadOnly()); ResultSet rs; rs = md.getPrimaryKeys(null, null, "USER"); ResultSetMetaData rsmd = rs.getMetaData(); String result0 = ""; for (; rs.next(); ) { for (int i = 0; i < rsmd.getColumnCount(); i++) { result0 += rs.getString(i + 1) + ":"; } result0 += "\n"; } rs.close(); System.out.println(result0); } { ResultSet rs; rs = md.getBestRowIdentifier(null, null, "USER", 0, true); ResultSetMetaData rsmd = rs.getMetaData(); String result0 = ""; for (; rs.next(); ) { for (int i = 0; i < rsmd.getColumnCount(); i++) { result0 += rs.getString(i + 1) + ":"; } result0 += "\n"; } rs.close(); System.out.println(result0); } { ResultSet rs = md.getImportedKeys(null, null, "ADDRESSBOOK"); ResultSetMetaData rsmd = rs.getMetaData(); result1 = ""; for (; rs.next(); ) { for (int i = 0; i < rsmd.getColumnCount(); i++) { result1 += rs.getString(i + 1) + ":"; } result1 += "\n"; } rs.close(); System.out.println(result1); } { ResultSet rs = md.getCrossReference(null, null, "ADDRESSBOOK_CATEGORY", null, null, "ADDRESSBOOK"); ResultSetMetaData rsmd = rs.getMetaData(); result2 = ""; for (; rs.next(); ) { for (int i = 0; i < rsmd.getColumnCount(); i++) { result2 += rs.getString(i + 1) + ":"; } result2 += "\n"; } rs.close(); System.out.println(result2); } { ResultSet rs = md.getExportedKeys(null, null, "USER"); ResultSetMetaData rsmd = rs.getMetaData(); result3 = ""; for (; rs.next(); ) { for (int i = 0; i < rsmd.getColumnCount(); i++) { result3 += rs.getString(i + 1) + ":"; } result3 += "\n"; } rs.close(); System.out.println(result3); } { ResultSet rs = md.getCrossReference(null, null, "USER", null, null, "ADDRESSBOOK_CATEGORY"); ResultSetMetaData rsmd = rs.getMetaData(); result4 = ""; for (; rs.next(); ) { for (int i = 0; i < rsmd.getColumnCount(); i++) { result4 += rs.getString(i + 1) + ":"; } result4 += "\n"; } rs.close(); System.out.println(result4); } { stmnt.execute("DROP TABLE T IF EXISTS;"); stmnt.execute("CREATE TABLE T (I IDENTITY, A CHAR(20), B CHAR(20));"); stmnt.execute("INSERT INTO T VALUES (NULL, 'get_column_name', '" + getColumnName + "');"); ResultSet rs = stmnt.executeQuery("SELECT I, A, B, A \"aliasA\", B \"aliasB\", 1 FROM T;"); ResultSetMetaData rsmd = rs.getMetaData(); result5 = ""; for (; rs.next(); ) { for (int i = 0; i < rsmd.getColumnCount(); i++) { result5 += rsmd.getColumnName(i + 1) + ":" + rs.getString(i + 1) + ":"; } result5 += "\n"; } rs.close(); rs = stmnt.executeQuery("SELECT I, A, B, A \"aliasA\", B \"aliasB\", 1 FROM T;"); rsmd = rs.getMetaData(); for (; rs.next(); ) { for (int i = 0; i < rsmd.getColumnCount(); i++) { result5 += rsmd.getColumnLabel(i + 1) + ":" + rs.getString(i + 1) + ":"; } result5 += "\n"; } System.out.println(result5); System.out.println("first column identity: " + rsmd.isAutoIncrement(1)); rsmd.isCaseSensitive(1); rsmd.isCurrency(1); rsmd.isDefinitelyWritable(1); rsmd.isNullable(1); rsmd.isReadOnly(1); rsmd.isSearchable(1); rsmd.isSigned(1); rsmd.isWritable(1); rs.close(); // test identity with PreparedStatement pstmnt = connection.prepareStatement("INSERT INTO T VALUES (?,?,?)"); pstmnt.setString(1, null); pstmnt.setString(2, "test"); pstmnt.setString(3, "test2"); pstmnt.executeUpdate(); pstmnt = connection.prepareStatement("call identity()"); ResultSet rsi = pstmnt.executeQuery(); rsi.next(); int identity = rsi.getInt(1); System.out.println("call identity(): " + identity); rsi.close(); } } catch (SQLException e) { fail(e.getMessage()); } System.out.println("testMetaData complete"); // assert equality of exported and imported with xref assertEquals(result1, result2); assertEquals(result3, result4); }
public int getDatabaseMinorVersion() throws SQLException { return throwExceptionDelegate.getDatabaseMinorVersion(); }
/** * Detect databse dialect using JDBC metadata. Based on code of * http://svn.jboss.org/repos/hibernate/core/trunk/core/src/main/java/org/hibernate/ * dialect/resolver/StandardDialectResolver.java * * @param metaData {@link DatabaseMetaData} * @return String * @throws SQLException if error occurs */ public static String detect(final DatabaseMetaData metaData) throws SQLException { final String databaseName = SecurityHelper.doPrivilegedSQLExceptionAction( new PrivilegedExceptionAction<String>() { public String run() throws Exception { return metaData.getDatabaseProductName(); } }); if ("HSQL Database Engine".equals(databaseName)) { return DialectConstants.DB_DIALECT_HSQLDB; } if ("H2".equals(databaseName)) { return DialectConstants.DB_DIALECT_H2; } if ("MySQL".equals(databaseName)) { return DialectConstants.DB_DIALECT_MYSQL; } if ("PostgreSQL".equals(databaseName)) { int majorVersion = metaData.getDatabaseMajorVersion(); int minorVersion = metaData.getDatabaseMinorVersion(); return (majorVersion > 9 || (majorVersion == 9 && minorVersion >= 1)) ? DialectConstants.DB_DIALECT_PGSQL_SCS : DialectConstants.DB_DIALECT_PGSQL; } if ("Apache Derby".equals(databaseName)) { return DialectConstants.DB_DIALECT_DERBY; } if ("ingres".equalsIgnoreCase(databaseName)) { return DialectConstants.DB_DIALECT_INGRES; } if (databaseName.startsWith("Microsoft SQL Server")) { return DialectConstants.DB_DIALECT_MSSQL; } if ("Sybase SQL Server".equals(databaseName) || "Adaptive Server Enterprise".equals(databaseName)) { return DialectConstants.DB_DIALECT_SYBASE; } if (databaseName.startsWith("Adaptive Server Anywhere")) { return DialectConstants.DB_DIALECT_SYBASE; } if (databaseName.startsWith("DB2/")) { return detectDB2Dialect(metaData); } if ("Oracle".equals(databaseName)) { return DialectConstants.DB_DIALECT_ORACLE; } return DialectConstants.DB_DIALECT_GENERIC; }
/** Detects DB2 dialect. */ private static String detectDB2Dialect(final DatabaseMetaData metaData) throws SQLException { if (LOG.isDebugEnabled()) { LOG.debug( "DB Major version = " + metaData.getDatabaseMajorVersion() + ", DB Minor version = " + metaData.getDatabaseMinorVersion() + ", DB Product version = " + metaData.getDatabaseProductVersion()); } int majorVersion = metaData.getDatabaseMajorVersion(); int minorVersion = metaData.getDatabaseMinorVersion(); if (majorVersion < 9) { if (LOG.isDebugEnabled()) { LOG.debug( "The dialect " + DialectConstants.DB_DIALECT_DB2V8 + " will be used as the major version is lower than 9."); } return DialectConstants.DB_DIALECT_DB2V8; } else if (majorVersion > 9) { if (LOG.isDebugEnabled()) { LOG.debug( "The dialect " + DialectConstants.DB_DIALECT_DB2_MYS + " will be used as the major version is greater than 9."); } return DialectConstants.DB_DIALECT_DB2_MYS; } else if (majorVersion == 9 && minorVersion > 7) { if (LOG.isDebugEnabled()) { LOG.debug( "The dialect " + DialectConstants.DB_DIALECT_DB2_MYS + " will be used as the major version is 9 and the minor version is greater than 7."); } return DialectConstants.DB_DIALECT_DB2_MYS; } else if (majorVersion == 9 && minorVersion == 7) { try { int maintenanceVersion = getDB2MaintenanceVersion(metaData); if (maintenanceVersion >= 2) { if (LOG.isDebugEnabled()) { LOG.debug( "The dialect " + DialectConstants.DB_DIALECT_DB2_MYS + " will be used as the major version is 9, the minor version is 7 and the maintenance version" + " is greater or equals to 2, knowing that the extracted value is " + maintenanceVersion + "."); } return DialectConstants.DB_DIALECT_DB2_MYS; } else { if (LOG.isDebugEnabled()) { LOG.debug( "The dialect " + DialectConstants.DB_DIALECT_DB2 + " will be used as the major version is 9, the minor version is 7 and the maintenance version" + " is lower than 2, knowing that the extracted value is " + maintenanceVersion + "."); } return DialectConstants.DB_DIALECT_DB2; } } catch (SQLException e) { LOG.error("Error checking product version.", e); if (LOG.isDebugEnabled()) { LOG.debug( "The dialect " + DialectConstants.DB_DIALECT_DB2 + " will be used as the major version is 9, the minor version is 7 and" + " determination the maintenance version failed"); } return DialectConstants.DB_DIALECT_DB2; } } else { if (LOG.isDebugEnabled()) { LOG.debug( "The dialect " + DialectConstants.DB_DIALECT_DB2 + " will be used as the major version is 9 and the minor version is lower than 7"); } return DialectConstants.DB_DIALECT_DB2; } }