List of usage examples for java.sql DatabaseMetaData getDatabaseProductVersion
String getDatabaseProductVersion() throws SQLException;
From source file:org.kawanfw.test.api.client.DatabaseMetaDataTest.java
public void test(Connection connection) throws Exception { MessageDisplayer.initClassDisplay(this.getClass().getSimpleName()); DatabaseMetaData databaseMetaData = connection.getMetaData(); // Test that getMetaData() will return value from cache databaseMetaData = connection.getMetaData(); if (connection instanceof RemoteConnection) { MessageDisplayer.display("Java Version : " + System.getProperty("java.version")); MessageDisplayer.display("AceQL Version: " + ((RemoteConnection) connection).getVersion()); MessageDisplayer.display("AceQL Url : " + ((RemoteConnection) connection).getUrl()); MessageDisplayer.display(""); }/* w w w . j ava 2 s.co m*/ if (connection instanceof RemoteConnection) { MessageDisplayer.display("((RemoteConnection)connection).clone();"); Connection connection2 = ((RemoteConnection) connection).clone(); @SuppressWarnings("unused") DatabaseMetaData databaseMetaData2 = connection2.getMetaData(); connection2.close(); } MessageDisplayer.display("General info (no Assert done):"); MessageDisplayer.display("connection.getCatalog() : " + connection.getCatalog()); MessageDisplayer.display( "databaseMetaData.getDatabaseProductName() : " + databaseMetaData.getDatabaseProductName()); MessageDisplayer.display( "databaseMetaData.getDatabaseProductVersion(): " + databaseMetaData.getDatabaseProductVersion()); MessageDisplayer.display( "databaseMetaData.getDatabaseMajorVersion() : " + databaseMetaData.getDatabaseMajorVersion()); MessageDisplayer.display( "databaseMetaData.getDatabaseMinorVersion() : " + databaseMetaData.getDatabaseMinorVersion()); MessageDisplayer.display( "databaseMetaData.allProceduresAreCallable() : " + databaseMetaData.allProceduresAreCallable()); // SystemOutHandle.display(DatabaseMetaData.bestRowSession); MessageDisplayer.display(""); // SystemOutHandle.display(databaseMetaData.autoCommitFailureClosesAllResultSets()); MessageDisplayer.display("databaseMetaData.getCatalogTerm(): " + databaseMetaData.getCatalogTerm()); try { MessageDisplayer.display( "databaseMetaData.supportsStoredProcedures(): " + databaseMetaData.supportsStoredProcedures()); MessageDisplayer.display("databaseMetaData.supportsStoredFunctionsUsingCallSyntax(): " + databaseMetaData.supportsStoredFunctionsUsingCallSyntax()); } catch (Throwable e) { MessageDisplayer.display(e.toString()); } MessageDisplayer.display("connection.getAutoCommit(): " + connection.getAutoCommit()); MessageDisplayer.display("databaseMetaData.getDefaultTransactionIsolation() : " + databaseMetaData.getDefaultTransactionIsolation()); MessageDisplayer .display("databaseMetaData.supportsTransactionIsolationLevel(TRANSACTION_READ_UNCOMMITTED): " + databaseMetaData .supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED)); MessageDisplayer.display("databaseMetaData.supportsTransactionIsolationLevel(TRANSACTION_READ_COMMITTED): " + databaseMetaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_COMMITTED)); MessageDisplayer.display("databaseMetaData.supportsTransactionIsolationLevel(TRANSACTION_REPEATABLE_READ): " + databaseMetaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_REPEATABLE_READ)); MessageDisplayer.display("databaseMetaData.supportsTransactionIsolationLevel(TRANSACTION_SERIALIZABLE): " + databaseMetaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE)); MessageDisplayer .display("databaseMetaData.supportsBatchUpdates() : " + databaseMetaData.supportsBatchUpdates()); MessageDisplayer .display("databaseMetaData.supportsSavepoints() : " + databaseMetaData.supportsSavepoints()); MessageDisplayer.display( "databaseMetaData.supportsGetGeneratedKeys(): " + databaseMetaData.supportsGetGeneratedKeys()); if (!new SqlUtil(connection).isTeradata() && !new SqlUtil(connection).isInformix()) { Assert.assertEquals(true, databaseMetaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_COMMITTED)); } Assert.assertEquals("databaseMetaData.supportsBatchUpdates()", true, databaseMetaData.supportsBatchUpdates()); if (!new SqlUtil(connection).isSQLAnywhere() && !new SqlUtil(connection).isAccess()) { Assert.assertEquals("databaseMetaData.supportsGetGeneratedKeys()", true, databaseMetaData.supportsGetGeneratedKeys()); } // Informix does not support savepoints SqlUtil sqlUtil = new SqlUtil(connection); if (!sqlUtil.isInformix() && !sqlUtil.isTeradata() && !new SqlUtil(connection).isAccess()) { Assert.assertEquals(true, databaseMetaData.supportsSavepoints()); } MessageDisplayer.display(""); String catalog = null; String schema = null; String table = "customer"; // Table name must be uppercase for Oracle & DB2, lowercase for MySQL // and PostgreSQL if (new SqlUtil(connection).isOracle() || new SqlUtil(connection).isHSQLDB() || new SqlUtil(connection).isDB2()) { table = table.toUpperCase(); } ResultSet rs = null; if (!new SqlUtil(connection).isAccess()) { rs = databaseMetaData.getPrimaryKeys(catalog, schema, table); printResultSet(rs); boolean rsNext = false; while (rs.next()) { rsNext = true; String keyColumnName = rs.getString("COLUMN_NAME"); MessageDisplayer.display("Primary Key is: " + keyColumnName + " for Table: " + table); Assert.assertEquals("customer_id", keyColumnName.toLowerCase()); } if (!new SqlUtil(connection).isH2()) { Assert.assertEquals(true, rsNext); } rs.close(); } // boolean returnNow = true; // if (returnNow) return; String[] types = { "TABLE", "VIEW" }; rs = databaseMetaData.getTables(null, null, null, types); Set<String> tablesSet = new HashSet<String>(); Set<String> ourTables = new HashSet<String>(); ourTables.add("banned_usernames"); ourTables.add("customer"); ourTables.add("customer_auto"); ourTables.add("orderlog"); ourTables.add("user_login"); MessageDisplayer.display(""); while (rs.next()) { table = rs.getString("TABLE_NAME"); if (ourTables.contains(table.toLowerCase())) { MessageDisplayer.display("Table: " + table); } tablesSet.add(table.toLowerCase()); } // printResultSet(rs); testTable("banned_usernames", tablesSet); testTable("customer", tablesSet); testTable("orderlog", tablesSet); testTable("user_login", tablesSet); rs.close(); }
From source file:de.innovationgate.webgate.api.jdbc.custom.JDBCSource.java
public ContentSourceSpecs init(WGDatabase db, String path) throws WGInvalidDatabaseException { Map creationOptions = db.getCreationOptions(); // Try to get shared connection pool from server boolean useSharedPool = WGUtils.getBooleanMapValue(db.getCreationOptions(), WGDatabase.COPTION_SHAREDPOOL, true);// www . ja v a 2 s. c om if (useSharedPool && db.getCreationOptions().containsKey(Database.OPTION_PATH) && db.getServer() instanceof SharedPoolJDBCDatabaseServer) { SharedPoolJDBCDatabaseServer poolServer = (SharedPoolJDBCDatabaseServer) db.getServer(); if (poolServer.isPoolAvailable(new CSVersion(0, 0))) { try { _connProvider = poolServer.createPoolConnectionProvider( (String) db.getCreationOptions().get(Database.OPTION_PATH)); WGFactory.getLogger() .info("Database '" + db.getDbReference() + "' uses the shared connection pool of database server '" + db.getServer().getTitle(Locale.getDefault()) + "'"); } catch (WGInvalidDatabaseException e) { throw e; } catch (Exception e) { throw new WGInvalidDatabaseException("Exception connecting to shared database server pool", e); } } } // Create regular pool if (_connProvider == null) { // Default JDBC props Properties props = new Properties(); props.put("autocommit", "true"); // Gather configured JDBC props Iterator optsIt = creationOptions.keySet().iterator(); while (optsIt.hasNext()) { String option = (String) optsIt.next(); if (option.startsWith(("jdbc."))) { props.put(option.substring(5), creationOptions.get(option)); } } // Set login props if (db.getMasterLoginName() != null && !db.getMasterLoginName().equals("")) { props.put("user", db.getMasterLoginName()); if (db.getMasterLoginPassword() != null) { props.put("password", db.getMasterLoginPassword()); } } // Set dbkey property so we see DBCP metrics via JMX props.put("dbcp.dbkey", db.getDbReference()); // Build JDBC Connection Creator try { _connProvider = new JDBCConnectionProvider(path, (String) db.getCreationOptions().get(COPTION_DRIVER), props, true); } catch (JDBCConnectionException e3) { throw new WGInvalidDatabaseException("Exception setting up JDBC connection", e3); } } // Gather other options try { if (creationOptions.containsKey("ResultSetType")) { _resultSetType = Integer.parseInt((String) creationOptions.get("ResultSetType")); } } catch (NumberFormatException e2) { throw new WGInvalidDatabaseException( "Cannot parse db option 'ResultSetType' as integer: " + _resultSetType); } // Gather meta data try { Connection connection = getConnection(); if (connection == null) { throw new WGInvalidDatabaseException("Unable to get connection"); } DatabaseMetaData dbMeta = connection.getMetaData(); ResultSet resultSet = dbMeta.getTables(null, null, null, new String[] { "TABLE", "VIEW", "GLOBAL TEMPORARY", "LOCAL TEMPORARY" }); startResultSet(resultSet); while (resultSet.next()) { TableName tableName = new TableName(resultSet); ResultSet keyResultSet = dbMeta.getPrimaryKeys(tableName.getCatalog(), tableName.getSchema(), tableName.getName()); List keyColumns = new ArrayList(); startResultSet(keyResultSet); while (keyResultSet.next()) { keyColumns.add(keyResultSet.getString("COLUMN_NAME").toLowerCase()); } if (keyColumns.size() > 0) { _tables.put(tableName.getCompleteName().toLowerCase(), keyColumns); } keyResultSet.close(); } resultSet.close(); _server = dbMeta.getDatabaseProductName() + " Version " + dbMeta.getDatabaseProductVersion(); _title = _server; } catch (SQLException e) { throw new WGInvalidDatabaseException( "SQL Error building connection to path " + path + ": " + e.getMessage()); } // Last changed update process int refreshSeconds = 60; if (creationOptions.containsKey(COPTION_REFRESH)) { try { refreshSeconds = Integer.parseInt((String) creationOptions.get(COPTION_REFRESH)); } catch (NumberFormatException e1) { Logger.getLogger(LOGGER_NAME).error("Cannot parse option " + COPTION_REFRESH + " as integer: " + creationOptions.get(COPTION_REFRESH)); } } // Gather specs ContentSourceSpecs specs = new ContentSourceSpecs(); specs.setBrowseable(true); specs.setWritable(true); specs.setCalculatesKeys(true); specs.setMaintainsLastChanged(false); specs.setLowerCaseItems(true); specs.setServePropertiesAsMetas(false); specs.setContentReadProtected(false); return specs; }
From source file:org.springframework.jdbc.core.metadata.GenericTableMetaDataProvider.java
@Override public void initializeWithMetaData(DatabaseMetaData databaseMetaData) throws SQLException { try {/*from www. ja v a 2s .co m*/ if (databaseMetaData.supportsGetGeneratedKeys()) { logger.debug("GetGeneratedKeys is supported"); setGetGeneratedKeysSupported(true); } else { logger.debug("GetGeneratedKeys is not supported"); setGetGeneratedKeysSupported(false); } } catch (SQLException ex) { if (logger.isWarnEnabled()) { logger.warn("Error retrieving 'DatabaseMetaData.getGeneratedKeys': " + ex.getMessage()); } } try { String databaseProductName = databaseMetaData.getDatabaseProductName(); if (this.productsNotSupportingGeneratedKeysColumnNameArray.contains(databaseProductName)) { if (logger.isDebugEnabled()) { logger.debug("GeneratedKeysColumnNameArray is not supported for " + databaseProductName); } setGeneratedKeysColumnNameArraySupported(false); } else { if (isGetGeneratedKeysSupported()) { if (logger.isDebugEnabled()) { logger.debug("GeneratedKeysColumnNameArray is supported for " + databaseProductName); } setGeneratedKeysColumnNameArraySupported(true); } else { setGeneratedKeysColumnNameArraySupported(false); } } } catch (SQLException ex) { if (logger.isWarnEnabled()) { logger.warn("Error retrieving 'DatabaseMetaData.getDatabaseProductName': " + ex.getMessage()); } } try { this.databaseVersion = databaseMetaData.getDatabaseProductVersion(); } catch (SQLException ex) { if (logger.isWarnEnabled()) { logger.warn("Error retrieving 'DatabaseMetaData.getDatabaseProductVersion': " + ex.getMessage()); } } try { setStoresUpperCaseIdentifiers(databaseMetaData.storesUpperCaseIdentifiers()); } catch (SQLException ex) { if (logger.isWarnEnabled()) { logger.warn("Error retrieving 'DatabaseMetaData.storesUpperCaseIdentifiers': " + ex.getMessage()); } } try { setStoresLowerCaseIdentifiers(databaseMetaData.storesLowerCaseIdentifiers()); } catch (SQLException ex) { if (logger.isWarnEnabled()) { logger.warn("Error retrieving 'DatabaseMetaData.storesLowerCaseIdentifiers': " + ex.getMessage()); } } }
From source file:org.metis.pull.WdsResourceBean.java
/** * Called by Spring after all of this bean's properties have been set. *///from w ww .j ava 2 s . com public void afterPropertiesSet() throws Exception { // log info for the jdbc driver being used // this will also attempt to open connection // with jdbc driver try { Connection con = getDataSource().getConnection(); if (con != null) { DatabaseMetaData dbmd = con.getMetaData(); setDbConnectionAcquired(true); if (dbmd != null) { setDriverName(dbmd.getDriverName().trim().toLowerCase()); isOracle = (getDriverName() != null && getDriverName().indexOf(ORACLE_STR) >= 0) ? true : false; LOG.info(getBeanName() + ":Is Oracle JDBC Driver = " + isOracle); LOG.info(getBeanName() + ":JDBC Driver name = " + getDriverName()); LOG.info(getBeanName() + ":JDBC Driver version = " + dbmd.getDriverVersion().trim()); LOG.info(getBeanName() + ":JDBC Driver product name = " + dbmd.getDatabaseProductName().trim()); LOG.info(getBeanName() + ":JDBC Driver database product version = " + dbmd.getDatabaseProductVersion().trim()); con.close(); } else { LOG.info(getBeanName() + ": Unable to get JDBC driver meta data"); } } else { LOG.info(getBeanName() + ": Unable to get JDBC connection"); } } catch (SQLException exc) { LOG.error(getBeanName() + ": got this exception when trying to " + "get driver meta data: " + exc.toString()); LOG.error(getBeanName() + ": exception stack trace follows:"); dumpStackTrace(exc.getStackTrace()); LOG.error(getBeanName() + ": Caused by " + exc.getCause().toString()); LOG.error(getBeanName() + ": causing exception stack trace follows:"); dumpStackTrace(exc.getCause().getStackTrace()); } // bean must be assigned a JDBC DataSource if (getDataSource() == null) { throw new Exception( getBeanName() + ".afterPropertiesSet: this bean has not been " + "assigned a JDBC DataSource"); } // do some validation if (getSqls4Get() == null && getSqls4Put() == null && getSqls4Post() == null && getSqls4Delete() == null) { throw new Exception("At least one of the WdsResourceBean's http methods has " + "not been assigned a SQL statement"); } // create and validate the different SQL statements if (getSqls4Get() != null) { sqlStmnts4Get = new ArrayList<SqlStmnt>(); for (String sql : getSqls4Get()) { SqlStmnt stmt = getSQLStmnt(this, sql, getJdbcTemplate()); if (stmt.isEqual(sqlStmnts4Get)) { throw new Exception("Injected SQL statements for GET are not distinct"); } sqlStmnts4Get.add(stmt); } if (LOG.isDebugEnabled()) { for (SqlStmnt sqlstmnt : sqlStmnts4Get) { LOG.debug(getBeanName() + ": SQL for GET = " + sqlstmnt.getOriginal()); LOG.debug(getBeanName() + ": Parameterized SQL for GET = " + sqlstmnt.getPrepared()); } } allowedMethodsRsp += "GET "; } if (getSqls4Put() != null) { sqlStmnts4Put = new ArrayList<SqlStmnt>(); for (String sql : getSqls4Put()) { SqlStmnt stmt = getSQLStmnt(this, sql, getJdbcTemplate()); if (stmt.isEqual(sqlStmnts4Put)) { throw new Exception("Injected SQL statements for PUT are not distinct"); } sqlStmnts4Put.add(stmt); } if (LOG.isDebugEnabled()) { for (SqlStmnt sqlstmnt : sqlStmnts4Put) { LOG.debug(getBeanName() + ": SQL for PUT = " + sqlstmnt.getOriginal()); LOG.debug(getBeanName() + ": Parameterized SQL for PUT = " + sqlstmnt.getPrepared()); } } allowedMethodsRsp += "PUT "; } if (getSqls4Post() != null) { sqlStmnts4Post = new ArrayList<SqlStmnt>(); for (String sql : getSqls4Post()) { SqlStmnt stmt = getSQLStmnt(this, sql, getJdbcTemplate()); if (stmt.isEqual(sqlStmnts4Post)) { throw new Exception("Injected SQL statements for POST are not distinct"); } sqlStmnts4Post.add(stmt); } if (LOG.isDebugEnabled()) { for (SqlStmnt sqlstmnt : sqlStmnts4Post) { LOG.debug(getBeanName() + ": SQL for POST = " + sqlstmnt.getOriginal()); LOG.debug(getBeanName() + ": Parameterized SQL for POST = " + sqlstmnt.getPrepared()); } } allowedMethodsRsp += "POST "; } if (getSqls4Delete() != null) { sqlStmnts4Delete = new ArrayList<SqlStmnt>(); for (String sql : getSqls4Delete()) { SqlStmnt stmt = getSQLStmnt(this, sql, getJdbcTemplate()); if (stmt.isEqual(sqlStmnts4Delete)) { throw new Exception("Injected SQL statements for DELETE are not distinct"); } sqlStmnts4Delete.add(stmt); } if (LOG.isDebugEnabled()) { for (SqlStmnt sqlstmnt : sqlStmnts4Delete) { LOG.debug(getBeanName() + ": SQL for DELETE = " + sqlstmnt.getOriginal()); LOG.debug(getBeanName() + ": Parameterized SQL for DELETE = " + sqlstmnt.getPrepared()); } } allowedMethodsRsp += "DELETE"; } LOG.debug(getBeanName() + ": allowedMethodsRsp string = " + allowedMethodsRsp); // tell our parent what methods this RDB will support setSupportedMethods(allowedMethodsRsp.split(SPACE_CHR_STR)); if (LOG.isDebugEnabled() && getAllowedAgents() != null) { if (!getAllowedAgents().isEmpty()) { LOG.debug(getBeanName() + ": agents allowed = " + getAllowedAgents()); } else { LOG.debug(getBeanName() + ": agents not allowed = " + getNotAllowedAgents()); } } }
From source file:org.apache.ddlutils.TestSummaryCreatorTask.java
/** * Adds the data from the test jdbc propertis file to the document. * // w w w.ja v a 2 s . c om * @param element The element to add the relevant database properties to * @param jdbcPropertiesFile The path of the properties file */ protected void addTargetDatabaseInfo(Element element, String jdbcPropertiesFile) throws IOException, BuildException { if (jdbcPropertiesFile == null) { return; } Properties props = readProperties(jdbcPropertiesFile); Connection conn = null; DatabaseMetaData metaData = null; try { String dataSourceClass = props.getProperty( TestAgainstLiveDatabaseBase.DATASOURCE_PROPERTY_PREFIX + "class", BasicDataSource.class.getName()); DataSource dataSource = (DataSource) Class.forName(dataSourceClass).newInstance(); for (Iterator it = props.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); String propName = (String) entry.getKey(); if (propName.startsWith(TestAgainstLiveDatabaseBase.DATASOURCE_PROPERTY_PREFIX) && !propName.equals(TestAgainstLiveDatabaseBase.DATASOURCE_PROPERTY_PREFIX + "class")) { BeanUtils.setProperty(dataSource, propName.substring(TestAgainstLiveDatabaseBase.DATASOURCE_PROPERTY_PREFIX.length()), entry.getValue()); } } String platformName = props.getProperty(TestAgainstLiveDatabaseBase.DDLUTILS_PLATFORM_PROPERTY); if (platformName == null) { platformName = new PlatformUtils().determineDatabaseType(dataSource); if (platformName == null) { throw new BuildException( "Could not determine platform from datasource, please specify it in the jdbc.properties via the ddlutils.platform property"); } } element.addAttribute("platform", platformName); element.addAttribute("dataSourceClass", dataSourceClass); conn = dataSource.getConnection(); metaData = conn.getMetaData(); try { element.addAttribute("dbProductName", metaData.getDatabaseProductName()); } catch (Throwable ex) { // we ignore it } try { element.addAttribute("dbProductVersion", metaData.getDatabaseProductVersion()); } catch (Throwable ex) { // we ignore it } try { int databaseMajorVersion = metaData.getDatabaseMajorVersion(); int databaseMinorVersion = metaData.getDatabaseMinorVersion(); element.addAttribute("dbVersion", databaseMajorVersion + "." + databaseMinorVersion); } catch (Throwable ex) { // we ignore it } try { element.addAttribute("driverName", metaData.getDriverName()); } catch (Throwable ex) { // we ignore it } try { element.addAttribute("driverVersion", metaData.getDriverVersion()); } catch (Throwable ex) { // we ignore it } try { int jdbcMajorVersion = metaData.getJDBCMajorVersion(); int jdbcMinorVersion = metaData.getJDBCMinorVersion(); element.addAttribute("jdbcVersion", jdbcMajorVersion + "." + jdbcMinorVersion); } catch (Throwable ex) { // we ignore it } } catch (Exception ex) { throw new BuildException(ex); } finally { if (conn != null) { try { conn.close(); } catch (SQLException ex) { // we ignore it } } } }
From source file:org.apache.hive.jdbc.TestJdbcDriver2.java
@Test public void testDatabaseMetaData() throws SQLException { DatabaseMetaData meta = con.getMetaData(); assertEquals("Apache Hive", meta.getDatabaseProductName()); assertEquals(HiveVersionInfo.getVersion(), meta.getDatabaseProductVersion()); assertEquals(System.getProperty("hive.version"), meta.getDatabaseProductVersion()); assertTrue("verifying hive version pattern. got " + meta.getDatabaseProductVersion(), Pattern.matches("\\d+\\.\\d+\\.\\d+.*", meta.getDatabaseProductVersion())); assertEquals(DatabaseMetaData.sqlStateSQL99, meta.getSQLStateType()); assertFalse(meta.supportsCatalogsInTableDefinitions()); assertTrue(meta.supportsSchemasInTableDefinitions()); assertTrue(meta.supportsSchemasInDataManipulation()); assertFalse(meta.supportsMultipleResultSets()); assertFalse(meta.supportsStoredProcedures()); assertTrue(meta.supportsAlterTableWithAddColumn()); //-1 indicates malformed version. assertTrue(meta.getDatabaseMajorVersion() > -1); assertTrue(meta.getDatabaseMinorVersion() > -1); }
From source file:mondrian.test.loader.MondrianFoodMartLoader.java
/** * Load output from the input, optionally creating tables, * populating tables and creating indexes *//* www . ja v a2s .c o m*/ private void load() throws Exception { if (!StringUtils.isBlank(jdbcDrivers)) { RolapUtil.loadDrivers(jdbcDrivers); } if (userName == null) { connection = DriverManager.getConnection(jdbcURL); } else { connection = DriverManager.getConnection(jdbcURL, userName, password); } if (jdbcInput) { if (inputUserName == null) { inputConnection = DriverManager.getConnection(inputJdbcURL); } else { inputConnection = DriverManager.getConnection(inputJdbcURL, inputUserName, inputPassword); } } final DatabaseMetaData metaData = connection.getMetaData(); String productName = metaData.getDatabaseProductName(); String version = metaData.getDatabaseProductVersion(); LOGGER.info("Output connection is " + productName + ", version: " + version); dialect = DialectManager.createDialect(null, connection); LOGGER.info( "Mondrian Dialect is " + dialect + ", detected database product: " + dialect.getDatabaseProduct()); if (dialect.getDatabaseProduct() == Dialect.DatabaseProduct.INFOBRIGHT && indexes) { System.out.println("Infobright engine detected: ignoring indexes"); indexes = false; } if (outputBatchSize == -1) { // No explicit batch size was set by user, so assign a good // default now if (dialect.getDatabaseProduct() == Dialect.DatabaseProduct.LUCIDDB) { // LucidDB column-store writes perform better with large batches outputBatchSize = 1000; } else { outputBatchSize = 50; } } if (dialect.getDatabaseProduct() == Dialect.DatabaseProduct.LUCIDDB) { // LucidDB doesn't support CREATE UNIQUE INDEX, but it // does support standard UNIQUE constraints generateUniqueConstraints = true; } try { final Condition<String> tableFilter; if (include != null || exclude != null) { tableFilter = new Condition<String>() { public boolean test(String tableName) { if (include != null) { if (!include.matcher(tableName).matches()) { return false; } } if (exclude != null) { if (!exclude.matcher(tableName).matches()) { return true; } } // Table name matched the inclusion criterion // (or everything was included) // and did not match the exclusion criterion // (or nothing was excluded), // therefore is included. return true; } }; } else { tableFilter = new Condition<String>() { public boolean test(String s) { return true; } }; } if (generateUniqueConstraints) { // Initialize tableConstraints createIndexes(false, false, tableFilter); } // This also initializes tableMetadataToLoad createTables(tableFilter); if (data) { if (!populationQueries) { if (jdbcInput) { loadDataFromJdbcInput(tableFilter, pauseMillis, outputBatchSize); } else { loadDataFromFile(tableFilter, pauseMillis, outputBatchSize); } } // Index the base tables before running queries to populate // the summary tables. if (indexes) { createIndexes(true, false, tableFilter); } loadFromSqlInserts(); } else { // Create indexes without loading data. if (indexes) { createIndexes(true, false, tableFilter); } } if (indexes && aggregates) { createIndexes(false, true, tableFilter); } if (analyze) { analyzeTables(); } } finally { if (connection != null) { connection.close(); connection = null; } if (inputConnection != null) { inputConnection.close(); inputConnection = null; } if (fileOutput != null) { fileOutput.close(); fileOutput = null; } } }
From source file:swp.bibjsf.persistence.Data.java
/** * Returns the lower-case names of all tables in the database. * * @return list of lower-case names of all tables in the database * @throws SQLException/*from w ww. j a v a2s . com*/ * falls ein Fehler beim Zugriff auf die Datenbank auftritt */ private List<String> getTableNames() throws SQLException { logger.debug("get table names"); DatabaseMetaData dbMeta; List<String> result = new ArrayList<String>(); Connection dbConnection = dataSource.getConnection(); try { dbMeta = dbConnection.getMetaData(); logger.debug("URL of database " + dbMeta.getURL()); logger.debug("database version: major=" + dbMeta.getDatabaseMajorVersion() + " minor=" + dbMeta.getDatabaseMinorVersion() + " product_version=" + dbMeta.getDatabaseProductVersion() + " product_name=" + dbMeta.getDatabaseProductName()); ResultSet rs = dbMeta.getTables(null, null, null, new String[] { "TABLE" }); try { while (rs.next()) { String theTableName = rs.getString("TABLE_NAME"); result.add(theTableName.toLowerCase()); } } finally { rs.close(); } return result; } finally { try { dbConnection.close(); } catch (SQLException e) { logger.debug("error while trying to close the database connection."); // ignore, nothing to be done here anyway } } }
From source file:jef.database.DbMetaData.java
/** * ???/*from w w w. j av a 2 s. c om*/ * * @return ? * @throws SQLException */ public String getDatabaseVersion() throws SQLException { Connection conn = getConnection(false); DatabaseMetaData databaseMetaData = conn.getMetaData(); String version = databaseMetaData.getDatabaseProductVersion(); releaseConnection(conn); return version; }