Java Code Examples for java.sql.DatabaseMetaData#getDatabaseMajorVersion()
The following examples show how to use
java.sql.DatabaseMetaData#getDatabaseMajorVersion() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DbEngineManager.java From aceql-http with GNU Lesser General Public License v2.1 | 6 votes |
/** * Returns true if Oracle Version is >= 12.1 (12.c) * * @param connection * @return true if Oracle Version is >= 12.1 (12.c) * @throws SQLException */ public static boolean isOracleVersionGtOrEq12c(Connection connection) throws SQLException { DatabaseMetaData databaseMetaData = connection.getMetaData(); int versionMajor = databaseMetaData.getDatabaseMajorVersion(); int versionMinnor = databaseMetaData.getDatabaseMinorVersion(); if (versionMajor < 12) { return false; } else if (versionMajor == 12) { if (versionMinnor >= 1) { return true; } else { return false; } } else { return true; } }
Example 2
Source File: DatabaseInformations.java From javamelody with Apache License 2.0 | 6 votes |
static Database getDatabaseForConnection(Connection connection) throws SQLException { final DatabaseMetaData metaData = connection.getMetaData(); final String databaseName = metaData.getDatabaseProductName(); final String url = metaData.getURL(); for (final Database database : Database.values()) { if (database.isRecognized(databaseName, url)) { if (database == MYSQL && metaData.getDatabaseMajorVersion() <= 4) { // si mysql et version 4 alors c'est MYSQL4 et non MYSQL return MYSQL4; } return database; } } throw new IllegalArgumentException( I18N.getFormattedString("type_base_de_donnees_inconnu", databaseName)); }
Example 3
Source File: AbstractDialect.java From bdf3 with Apache License 2.0 | 6 votes |
/** * 判断是否是支持的数据库类型 * @param connection 数据连接 * @param dbProductName 数据库名称 * @param dbMajorVersion 数据版本号 * @return 返回当前方言是否支持当前数据库 */ public boolean support(Connection connection,String dbProductName,String dbMajorVersion) { try { DatabaseMetaData databaseMetaData = connection.getMetaData(); String databaseProductName = databaseMetaData .getDatabaseProductName(); int databaseMajorVersion = databaseMetaData .getDatabaseMajorVersion(); boolean containsMysql = StringUtils.containsIgnoreCase( databaseProductName,dbProductName); if(StringUtils.isNotEmpty(dbMajorVersion)){ return containsMysql&&Integer.valueOf(dbMajorVersion)==databaseMajorVersion; } return containsMysql; } catch (SQLException e) { return false; } }
Example 4
Source File: DbImplMySql.java From jqm with Apache License 2.0 | 5 votes |
@Override public boolean compatibleWith(DatabaseMetaData product) throws SQLException { return (product.getDatabaseProductName().contains("MySQL") && ((product.getDatabaseMajorVersion() == 5 && product.getDatabaseMinorVersion() >= 6) || product.getDatabaseMajorVersion() > 5)) || (product.getDatabaseProductName().contains("MariaDB") && product.getDatabaseMajorVersion() >= 10); }
Example 5
Source File: DBInformation.java From cloud-spring-boot-sample with Apache License 2.0 | 5 votes |
public DBInformation(DatabaseMetaData metaData) throws SQLException { url = metaData.getURL(); dbName = metaData.getDatabaseProductName(); dbMajorVersion = metaData.getDatabaseMajorVersion(); dbMinorVersion = metaData.getDatabaseMinorVersion(); driverName = metaData.getDriverName(); driverVersion = metaData.getDriverVersion(); userName = metaData.getUserName(); }
Example 6
Source File: DatabaseStatusChecker.java From dubbox with Apache License 2.0 | 5 votes |
public Status check() { boolean ok; try { Connection connection = dataSource.getConnection(); try { DatabaseMetaData metaData = connection.getMetaData(); ResultSet resultSet = metaData.getTypeInfo(); try { ok = resultSet.next(); } finally { resultSet.close(); } if (message == null) { message = metaData.getURL() + " (" + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion() + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")"; } if (version == 0) { version = metaData.getDatabaseMajorVersion(); } } finally { connection.close(); } } catch (Throwable e) { logger.error(e.getMessage(), e); ok = false; } return new Status(! ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message); }
Example 7
Source File: DatabaseStatusChecker.java From dubbox with Apache License 2.0 | 5 votes |
public Status check() { boolean ok; try { Connection connection = dataSource.getConnection(); try { DatabaseMetaData metaData = connection.getMetaData(); ResultSet resultSet = metaData.getTypeInfo(); try { ok = resultSet.next(); } finally { resultSet.close(); } if (message == null) { message = metaData.getURL() + " (" + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion() + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")"; } if (version == 0) { version = metaData.getDatabaseMajorVersion(); } } finally { connection.close(); } } catch (Throwable e) { logger.error(e.getMessage(), e); ok = false; } return new Status(! ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message); }
Example 8
Source File: DatabaseStatusChecker.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public Status check() { boolean ok; try { Connection connection = dataSource.getConnection(); try { DatabaseMetaData metaData = connection.getMetaData(); ResultSet resultSet = metaData.getTypeInfo(); try { ok = resultSet.next(); } finally { resultSet.close(); } if (message == null) { message = metaData.getURL() + " (" + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion() + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")"; } if (version == 0) { version = metaData.getDatabaseMajorVersion(); } } finally { connection.close(); } } catch (Throwable e) { logger.error(e.getMessage(), e); ok = false; } return new Status(! ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message); }
Example 9
Source File: DatabaseStatusChecker.java From dubbox with Apache License 2.0 | 5 votes |
public Status check() { boolean ok; try { Connection connection = dataSource.getConnection(); try { DatabaseMetaData metaData = connection.getMetaData(); ResultSet resultSet = metaData.getTypeInfo(); try { ok = resultSet.next(); } finally { resultSet.close(); } if (message == null) { message = metaData.getURL() + " (" + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion() + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")"; } if (version == 0) { version = metaData.getDatabaseMajorVersion(); } } finally { connection.close(); } } catch (Throwable e) { logger.error(e.getMessage(), e); ok = false; } return new Status(! ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message); }
Example 10
Source File: DatabaseStatusChecker.java From dubbox with Apache License 2.0 | 5 votes |
public Status check() { boolean ok; try { Connection connection = dataSource.getConnection(); try { DatabaseMetaData metaData = connection.getMetaData(); ResultSet resultSet = metaData.getTypeInfo(); try { ok = resultSet.next(); } finally { resultSet.close(); } if (message == null) { message = metaData.getURL() + " (" + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion() + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")"; } if (version == 0) { version = metaData.getDatabaseMajorVersion(); } } finally { connection.close(); } } catch (Throwable e) { logger.error(e.getMessage(), e); ok = false; } return new Status(! ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message); }
Example 11
Source File: ScoreDialectResolver.java From score with Apache License 2.0 | 5 votes |
protected Dialect resolveDialectInternal(DatabaseMetaData metaData) throws SQLException { String databaseName = metaData.getDatabaseProductName(); int databaseMajorVersion = metaData.getDatabaseMajorVersion(); logger.info("Database name is: " + databaseName + " databaseMajorVersion is: " + databaseMajorVersion); if ( "MySQL".equals( databaseName ) ) { return new ScoreMySQLDialect(); } DatabaseMetaDataDialectResolutionInfoAdapter databaseMetaDataDialectResolutionInfoAdapter=new DatabaseMetaDataDialectResolutionInfoAdapter(metaData); return resolveDialect(databaseMetaDataDialectResolutionInfoAdapter); }
Example 12
Source File: DbImplMySql8.java From jqm with Apache License 2.0 | 5 votes |
@Override public boolean compatibleWith(DatabaseMetaData product) throws SQLException { return (product.getDatabaseProductName().contains("MySQL") && (product.getDatabaseMajorVersion() >= 8)) || (product.getDatabaseProductName().contains("MariaDB") && ((product.getDatabaseMajorVersion() == 10 && product.getDatabaseMinorVersion() >= 3) || (product.getDatabaseMajorVersion() > 10))); }
Example 13
Source File: DatabaseStatusChecker.java From dubbo3 with Apache License 2.0 | 5 votes |
public Status check() { boolean ok; try { Connection connection = dataSource.getConnection(); try { DatabaseMetaData metaData = connection.getMetaData(); ResultSet resultSet = metaData.getTypeInfo(); try { ok = resultSet.next(); } finally { resultSet.close(); } if (message == null) { message = metaData.getURL() + " (" + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion() + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")"; } if (version == 0) { version = metaData.getDatabaseMajorVersion(); } } finally { connection.close(); } } catch (Throwable e) { logger.error(e.getMessage(), e); ok = false; } return new Status(! ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message); }
Example 14
Source File: DatabaseMetaDataTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Test UDT-related metadata methods. * */ public void testUDTs() throws Exception { // // We only run this test if the database version is at least 10.4. // Otherwise we can't create a UDT. // DatabaseMetaData dmd = getDMD(); // GemStone changes BEGIN int databaseMajor = dmd.getDatabaseMajorVersion(); int databaseMinor = dmd.getDatabaseMinorVersion(); if (databaseMajor < 10 || databaseMinor < 4) { return; } /* (original code) Version dataVersion = getDataVersion( getConnection() ); if ( dataVersion.compareTo( new Version( 10, 6, 0, 0 ) ) < 0 ) { return; } */ // GemStone changes END createObjectsForUDTTests(); ResultSet rs = dmd.getUDTs(null,null,null,null); String[] columnNames = new String[] { "TYPE_CAT", "TYPE_SCHEM", "TYPE_NAME", "CLASS_NAME", "DATA_TYPE", "REMARKS", "BASE_TYPE"}; int[] columnTypes = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.LONGVARCHAR, Types.INTEGER, Types.VARCHAR, Types.SMALLINT }; boolean[] nullability = new boolean[] { true, true, false, false, false, true, true }; assertMetaDataResultSet(rs, columnNames, columnTypes, nullability); String[][] expectedRows = new String[][] { { null, "APP", "PRICE", "org.apache.derbyTesting.functionTests.tests.lang.Price", "2000", null, null }, }; JDBC.assertFullResultSet( rs, expectedRows ); // now try the test, specifying a specific type of UDT rs = dmd.getUDTs( null, null, null, new int[] { Types.JAVA_OBJECT } ); JDBC.assertFullResultSet( rs, expectedRows ); rs = dmd.getUDTs( null, null, null, new int[] { Types.DISTINCT, Types.JAVA_OBJECT } ); JDBC.assertFullResultSet( rs, expectedRows ); // no UDTs of these types rs = dmd.getUDTs( null, null, null, new int[] { Types.DISTINCT, Types.STRUCT } ); JDBC.assertEmpty(rs); // try explicit schema and type name rs = dmd.getUDTs( null, "APP", "PRICE", new int[] { Types.DISTINCT, Types.JAVA_OBJECT } ); JDBC.assertFullResultSet( rs, expectedRows ); rs = dmd.getUDTs( null, "AP%", "PRI%", new int[] { Types.DISTINCT, Types.JAVA_OBJECT } ); JDBC.assertFullResultSet( rs, expectedRows ); rs = dmd.getUDTs( null, "FOO", "PRICE", new int[] { Types.DISTINCT, Types.JAVA_OBJECT } ); JDBC.assertEmpty(rs); // now make sure that getColumns() returns the right data rs = dmd.getColumns( null, "APP", "ORDERS", null ); expectedRows = new String[][] { { "", "APP", "ORDERS", "TOTALPRICE", "2000", "\"APP\".\"PRICE\"", "-1", null, null, null, "1", "", null, null, null, null, "1", "YES", null, null, null, null, "NO" }, }; JDBC.assertFullResultSet( rs, expectedRows ); rs = dmd.getColumns( null, "APP", "ORDERS", null ); crossCheckGetColumnsAndResultSetMetaData( rs, false, 0 ); dropObjectsForUDTTests(); }
Example 15
Source File: SqlDialectFactoryImpl.java From Bats with Apache License 2.0 | 4 votes |
public SqlDialect create(DatabaseMetaData databaseMetaData) { String databaseProductName; int databaseMajorVersion; int databaseMinorVersion; String databaseVersion; try { databaseProductName = databaseMetaData.getDatabaseProductName(); databaseMajorVersion = databaseMetaData.getDatabaseMajorVersion(); databaseMinorVersion = databaseMetaData.getDatabaseMinorVersion(); databaseVersion = databaseMetaData.getDatabaseProductVersion(); } catch (SQLException e) { throw new RuntimeException("while detecting database product", e); } final String upperProductName = databaseProductName.toUpperCase(Locale.ROOT).trim(); final String quoteString = getIdentifierQuoteString(databaseMetaData); final NullCollation nullCollation = getNullCollation(databaseMetaData); final SqlDialect.Context c = SqlDialect.EMPTY_CONTEXT .withDatabaseProductName(databaseProductName) .withDatabaseMajorVersion(databaseMajorVersion) .withDatabaseMinorVersion(databaseMinorVersion) .withDatabaseVersion(databaseVersion) .withIdentifierQuoteString(quoteString) .withNullCollation(nullCollation); switch (upperProductName) { case "ACCESS": return new AccessSqlDialect(c); case "APACHE DERBY": return new DerbySqlDialect(c); case "DBMS:CLOUDSCAPE": return new DerbySqlDialect(c); case "HIVE": return new HiveSqlDialect(c); case "INGRES": return new IngresSqlDialect(c); case "INTERBASE": return new InterbaseSqlDialect(c); case "JETHRODATA": return new JethroDataSqlDialect( c.withJethroInfo(jethroCache.get(databaseMetaData))); case "LUCIDDB": return new LucidDbSqlDialect(c); case "ORACLE": return new OracleSqlDialect(c); case "PHOENIX": return new PhoenixSqlDialect(c); case "MYSQL (INFOBRIGHT)": return new InfobrightSqlDialect(c); case "MYSQL": return new MysqlSqlDialect(c); case "REDSHIFT": return new RedshiftSqlDialect(c); case "SPARK": return new SparkSqlDialect(c); } // Now the fuzzy matches. if (databaseProductName.startsWith("DB2")) { return new Db2SqlDialect(c); } else if (upperProductName.contains("FIREBIRD")) { return new FirebirdSqlDialect(c); } else if (databaseProductName.startsWith("Informix")) { return new InformixSqlDialect(c); } else if (upperProductName.contains("NETEZZA")) { return new NetezzaSqlDialect(c); } else if (upperProductName.contains("PARACCEL")) { return new ParaccelSqlDialect(c); } else if (databaseProductName.startsWith("HP Neoview")) { return new NeoviewSqlDialect(c); } else if (upperProductName.contains("POSTGRE")) { return new PostgresqlSqlDialect(c); } else if (upperProductName.contains("SQL SERVER")) { return new MssqlSqlDialect(c); } else if (upperProductName.contains("SYBASE")) { return new SybaseSqlDialect(c); } else if (upperProductName.contains("TERADATA")) { return new TeradataSqlDialect(c); } else if (upperProductName.contains("HSQL")) { return new HsqldbSqlDialect(c); } else if (upperProductName.contains("H2")) { return new H2SqlDialect(c); } else if (upperProductName.contains("VERTICA")) { return new VerticaSqlDialect(c); } else if (upperProductName.contains("SPARK")) { return new SparkSqlDialect(c); } else { return new AnsiSqlDialect(c); } }
Example 16
Source File: DatabaseMetaDataTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Test UDT-related metadata methods. * */ public void testUDTs() throws Exception { // // We only run this test if the database version is at least 10.4. // Otherwise we can't create a UDT. // DatabaseMetaData dmd = getDMD(); // GemStone changes BEGIN int databaseMajor = dmd.getDatabaseMajorVersion(); int databaseMinor = dmd.getDatabaseMinorVersion(); if (databaseMajor < 10 || databaseMinor < 4) { return; } /* (original code) Version dataVersion = getDataVersion( getConnection() ); if ( dataVersion.compareTo( new Version( 10, 6, 0, 0 ) ) < 0 ) { return; } */ // GemStone changes END createObjectsForUDTTests(); ResultSet rs = dmd.getUDTs(null,null,null,null); String[] columnNames = new String[] { "TYPE_CAT", "TYPE_SCHEM", "TYPE_NAME", "CLASS_NAME", "DATA_TYPE", "REMARKS", "BASE_TYPE"}; int[] columnTypes = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.LONGVARCHAR, Types.INTEGER, Types.VARCHAR, Types.SMALLINT }; boolean[] nullability = new boolean[] { true, true, false, false, false, true, true }; assertMetaDataResultSet(rs, columnNames, columnTypes, nullability); String[][] expectedRows = new String[][] { { null, "APP", "PRICE", "org.apache.derbyTesting.functionTests.tests.lang.Price", "2000", null, null }, }; JDBC.assertFullResultSet( rs, expectedRows ); // now try the test, specifying a specific type of UDT rs = dmd.getUDTs( null, null, null, new int[] { Types.JAVA_OBJECT } ); JDBC.assertFullResultSet( rs, expectedRows ); rs = dmd.getUDTs( null, null, null, new int[] { Types.DISTINCT, Types.JAVA_OBJECT } ); JDBC.assertFullResultSet( rs, expectedRows ); // no UDTs of these types rs = dmd.getUDTs( null, null, null, new int[] { Types.DISTINCT, Types.STRUCT } ); JDBC.assertEmpty(rs); // try explicit schema and type name rs = dmd.getUDTs( null, "APP", "PRICE", new int[] { Types.DISTINCT, Types.JAVA_OBJECT } ); JDBC.assertFullResultSet( rs, expectedRows ); rs = dmd.getUDTs( null, "AP%", "PRI%", new int[] { Types.DISTINCT, Types.JAVA_OBJECT } ); JDBC.assertFullResultSet( rs, expectedRows ); rs = dmd.getUDTs( null, "FOO", "PRICE", new int[] { Types.DISTINCT, Types.JAVA_OBJECT } ); JDBC.assertEmpty(rs); // now make sure that getColumns() returns the right data rs = dmd.getColumns( null, "APP", "ORDERS", null ); expectedRows = new String[][] { { "", "APP", "ORDERS", "TOTALPRICE", "2000", "\"APP\".\"PRICE\"", "-1", null, null, null, "1", "", null, null, null, null, "1", "YES", null, null, null, null, "NO" }, }; JDBC.assertFullResultSet( rs, expectedRows ); rs = dmd.getColumns( null, "APP", "ORDERS", null ); crossCheckGetColumnsAndResultSetMetaData( rs, false, 0 ); dropObjectsForUDTTests(); }
Example 17
Source File: DatabaseMetaDataTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Methods that describe the version of the * driver and database. */ public void testVersionInfo() throws SQLException { DatabaseMetaData dmd = getDMD(); int databaseMajor = dmd.getDatabaseMajorVersion(); int databaseMinor = dmd.getDatabaseMinorVersion(); int driverMajor = dmd.getDriverMajorVersion(); int driverMinor = dmd.getDriverMinorVersion(); String databaseVersion = dmd.getDatabaseProductVersion(); String driverVersion = dmd.getDriverVersion(); if (usingEmbedded()) { // Database *is* the driver. assertEquals("Embedded Major version ", databaseMajor, driverMajor); assertEquals("Embedded Minor version ", databaseMinor, driverMinor); assertEquals("Embedded version", databaseVersion, driverVersion); } assertEquals("GemFireXD", dmd.getDatabaseProductName()); String driverName = dmd.getDriverName(); if (usingEmbedded()) { assertEquals("GemFireXD Embedded JDBC Driver", driverName); } else if (usingDerbyNetClient()) { assertEquals("GemFireXD Network Client JDBC Driver", driverName); } int jdbcMajor = dmd.getJDBCMajorVersion(); int jdbcMinor = dmd.getJDBCMinorVersion(); int expectedJDBCMajor = -1; if (JDBC.vmSupportsJDBC4()) { expectedJDBCMajor = 4; } else if (JDBC.vmSupportsJDBC3()) { expectedJDBCMajor = 3; } else if (JDBC.vmSupportsJSR169()) { // Not sure what is the correct output for JSR 169 expectedJDBCMajor = -1; } if (expectedJDBCMajor != -1) { assertEquals("JDBC Major version", expectedJDBCMajor, jdbcMajor); assertEquals("JDBC Minor version", 0, jdbcMinor); } }
Example 18
Source File: OracleSchema.java From netbeans with Apache License 2.0 | 4 votes |
private Set<String> getRecycleBinObjects(DatabaseMetaData dmd, String... types) { String driverName = null; String driverVer = null; List<String> emptyList = Collections.emptyList(); Set<String> result = new HashSet<String>(); try { driverName = dmd.getDriverName(); driverVer = dmd.getDriverVersion(); int databaseMajorVersion = 0; try { databaseMajorVersion = dmd.getDatabaseMajorVersion(); } catch (UnsupportedOperationException use) { LOGGER.log(Level.FINEST, "getDatabaseMajorVersion() on " + dmd, use); } if (databaseMajorVersion < 10 || types == null) { return Collections.emptySet(); } Statement stmt = dmd.getConnection().createStatement(); ResultSet rs = null; try { rs = stmt.executeQuery("SELECT OBJECT_NAME, TYPE FROM SYS.DBA_RECYCLEBIN"); // NOI18N } catch (SQLException ex) { LOGGER.log(Level.FINE, ex.getMessage(), ex); // try both rs = stmt.executeQuery("SELECT OBJECT_NAME, TYPE FROM RECYCLEBIN"); // NOI18N } if (rs != null) { List<String> typesL = types == null ? emptyList : Arrays.asList(types); try { while (rs.next()) { String type = rs.getString("TYPE"); // NOI18N if (typesL.isEmpty() || typesL.contains(type)) { result.add(rs.getString("OBJECT_NAME")); // NOI18N } } } finally { rs.close(); } } stmt.close(); } catch (Exception e) { LOGGER.log(Level.INFO, "Error while analyzing the recycle bin. JDBC Driver: " + driverName + "(" + driverVer + ")", e); } return result; }
Example 19
Source File: SqlDialectFactoryImpl.java From Quicksql with MIT License | 4 votes |
public SqlDialect create(DatabaseMetaData databaseMetaData) { String databaseProductName; int databaseMajorVersion; int databaseMinorVersion; String databaseVersion; try { databaseProductName = databaseMetaData.getDatabaseProductName(); databaseMajorVersion = databaseMetaData.getDatabaseMajorVersion(); databaseMinorVersion = databaseMetaData.getDatabaseMinorVersion(); databaseVersion = databaseMetaData.getDatabaseProductVersion(); } catch (SQLException e) { throw new RuntimeException("while detecting database product", e); } final String upperProductName = databaseProductName.toUpperCase(Locale.ROOT).trim(); final String quoteString = getIdentifierQuoteString(databaseMetaData); final NullCollation nullCollation = getNullCollation(databaseMetaData); final Casing unquotedCasing = getCasing(databaseMetaData, false); final Casing quotedCasing = getCasing(databaseMetaData, true); final boolean caseSensitive = isCaseSensitive(databaseMetaData); final SqlDialect.Context c = SqlDialect.EMPTY_CONTEXT .withDatabaseProductName(databaseProductName) .withDatabaseMajorVersion(databaseMajorVersion) .withDatabaseMinorVersion(databaseMinorVersion) .withDatabaseVersion(databaseVersion) .withIdentifierQuoteString(quoteString) .withUnquotedCasing(unquotedCasing) .withQuotedCasing(quotedCasing) .withCaseSensitive(caseSensitive) .withNullCollation(nullCollation); switch (upperProductName) { case "ACCESS": return new AccessSqlDialect(c); case "APACHE DERBY": return new DerbySqlDialect(c); case "DBMS:CLOUDSCAPE": return new DerbySqlDialect(c); case "HIVE": return new HiveSqlDialect(c); case "INGRES": return new IngresSqlDialect(c); case "INTERBASE": return new InterbaseSqlDialect(c); case "JETHRODATA": return new JethroDataSqlDialect( c.withJethroInfo(jethroCache.get(databaseMetaData))); case "LUCIDDB": return new LucidDbSqlDialect(c); case "ORACLE": return new OracleSqlDialect(c); case "PHOENIX": return new PhoenixSqlDialect(c); case "MYSQL (INFOBRIGHT)": return new InfobrightSqlDialect(c); case "MYSQL": return new MysqlSqlDialect(c); case "REDSHIFT": return new RedshiftSqlDialect(c); case "SNOWFLAKE": return new SnowflakeSqlDialect(c); case "SPARK": return new SparkSqlDialect(c); } // Now the fuzzy matches. if (databaseProductName.startsWith("DB2")) { return new Db2SqlDialect(c); } else if (upperProductName.contains("FIREBIRD")) { return new FirebirdSqlDialect(c); } else if (databaseProductName.startsWith("Informix")) { return new InformixSqlDialect(c); } else if (upperProductName.contains("NETEZZA")) { return new NetezzaSqlDialect(c); } else if (upperProductName.contains("PARACCEL")) { return new ParaccelSqlDialect(c); } else if (databaseProductName.startsWith("HP Neoview")) { return new NeoviewSqlDialect(c); } else if (upperProductName.contains("POSTGRE")) { return new PostgresqlSqlDialect(c); } else if (upperProductName.contains("SQL SERVER")) { return new MssqlSqlDialect(c); } else if (upperProductName.contains("SYBASE")) { return new SybaseSqlDialect(c); } else if (upperProductName.contains("TERADATA")) { return new TeradataSqlDialect(c); } else if (upperProductName.contains("HSQL")) { return new HsqldbSqlDialect(c); } else if (upperProductName.contains("H2")) { return new H2SqlDialect(c); } else if (upperProductName.contains("VERTICA")) { return new VerticaSqlDialect(c); } else if (upperProductName.contains("SNOWFLAKE")) { return new SnowflakeSqlDialect(c); } else if (upperProductName.contains("SPARK")) { return new SparkSqlDialect(c); } else { return new AnsiSqlDialect(c); } }
Example 20
Source File: ScriptRunner.java From sis with Apache License 2.0 | 4 votes |
/** * Creates a new runner which will execute the statements using the given connection. * * <p>Some {@code maxRowsPerInsert} parameter values of interest:</p> * <ul> * <li>A value of 0 means to create only the schemas without inserting any data in them.</li> * <li>A value of 1 means to use one separated {@code INSERT INTO} statement for each row, which may be slow.</li> * <li>A value of 100 is a value which have been found empirically as giving good results.</li> * <li>A value of {@link Integer#MAX_VALUE} means to not perform any attempt to limit the number of rows in an * {@code INSERT INTO} statement. Note that this causes {@link StackOverflowError} in some JDBC driver.</li> * </ul> * * @param connection the connection to the database. * @param maxRowsPerInsert maximum number of rows per {@code "INSERT INTO"} statement. * @throws SQLException if an error occurred while creating a SQL statement. */ public ScriptRunner(final Connection connection, final int maxRowsPerInsert) throws SQLException { ArgumentChecks.ensureNonNull("connection", connection); ArgumentChecks.ensurePositive("maxRowsPerInsert", maxRowsPerInsert); final DatabaseMetaData metadata = connection.getMetaData(); this.maxRowsPerInsert = maxRowsPerInsert; this.dialect = Dialect.guess(metadata); this.identifierQuote = metadata.getIdentifierQuoteString(); this.isSchemaSupported = metadata.supportsSchemasInTableDefinitions() && metadata.supportsSchemasInDataManipulation(); this.isCatalogSupported = metadata.supportsCatalogsInTableDefinitions() && metadata.supportsCatalogsInDataManipulation(); this.statement = connection.createStatement(); switch (dialect) { default: { isEnumTypeSupported = false; isGrantOnSchemaSupported = false; isGrantOnTableSupported = false; isCreateLanguageRequired = false; isCommentSupported = false; break; } case POSTGRESQL: { final int version = metadata.getDatabaseMajorVersion(); isEnumTypeSupported = (version == 8) ? metadata.getDatabaseMinorVersion() >= 4 : version >= 8; isGrantOnSchemaSupported = true; isGrantOnTableSupported = true; isCreateLanguageRequired = (version < 9); isCommentSupported = true; break; } case HSQL: { isEnumTypeSupported = false; isGrantOnSchemaSupported = false; isGrantOnTableSupported = false; isCreateLanguageRequired = false; isCommentSupported = false; /* * HSQLDB stores tables in memory by default. For storing the tables on files, we have to * use "CREATE CACHED TABLE" statement, which is HSQL-specific. For avoiding SQL dialect, * the following statement change the default setting on current connection. * * Reference: http://hsqldb.org/doc/guide/dbproperties-chapt.html#dpc_db_props_url */ statement.execute("SET DATABASE DEFAULT TABLE TYPE CACHED"); break; } } /* * Now build the list of statements to skip, depending of which features are supported by the database. * WARNING: do not use capturing group here, because some subclasses (e.g. EPSGInstaller) will use their * own capturing groups. A non-capturing group is declared by "(?:A|B)" instead than a plain "(A|B)". */ if (!isEnumTypeSupported) { addStatementToSkip("CREATE\\s+(?:TYPE|CAST)\\s+.*"); } if (!isGrantOnSchemaSupported || !isGrantOnTableSupported) { addStatementToSkip("GRANT\\s+\\w+\\s+ON\\s+"); if (isGrantOnSchemaSupported) { regexOfStmtToSkip.append("TABLE"); } else if (isGrantOnTableSupported) { regexOfStmtToSkip.append("SCHEMA"); } else { regexOfStmtToSkip.append("(?:TABLE|SCHEMA)"); } regexOfStmtToSkip.append("\\s+.*"); } if (!isCommentSupported) { addStatementToSkip("COMMENT\\s+ON\\s+.*"); } }