List of usage examples for java.sql DatabaseMetaData getDatabaseProductName
String getDatabaseProductName() throws SQLException;
From source file:org.springframework.jdbc.core.JdbcTemplateTests.java
public void testInterruptibleBatchUpdateWithBaseClassAndNoBatchSupport() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final int[] ids = new int[] { 100, 200 }; final int[] rowsAffected = new int[] { 1, 2 }; MockControl ctrlPreparedStatement = MockControl.createControl(PreparedStatement.class); PreparedStatement mockPreparedStatement = (PreparedStatement) ctrlPreparedStatement.getMock(); mockPreparedStatement.getConnection(); ctrlPreparedStatement.setReturnValue(mockConnection); mockPreparedStatement.setInt(1, ids[0]); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.executeUpdate(); ctrlPreparedStatement.setReturnValue(rowsAffected[0]); mockPreparedStatement.setInt(1, ids[1]); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.executeUpdate(); ctrlPreparedStatement.setReturnValue(rowsAffected[1]); if (debugEnabled) { mockPreparedStatement.getWarnings(); ctrlPreparedStatement.setReturnValue(null); }/* w w w . j a v a 2 s . c om*/ mockPreparedStatement.close(); ctrlPreparedStatement.setVoidCallable(); MockControl ctrlDatabaseMetaData = MockControl.createControl(DatabaseMetaData.class); DatabaseMetaData mockDatabaseMetaData = (DatabaseMetaData) ctrlDatabaseMetaData.getMock(); mockDatabaseMetaData.getDatabaseProductName(); ctrlDatabaseMetaData.setReturnValue("MySQL"); mockDatabaseMetaData.supportsBatchUpdates(); ctrlDatabaseMetaData.setReturnValue(false); mockConnection.prepareStatement(sql); ctrlConnection.setReturnValue(mockPreparedStatement); mockConnection.getMetaData(); ctrlConnection.setReturnValue(mockDatabaseMetaData, 2); ctrlPreparedStatement.replay(); ctrlDatabaseMetaData.replay(); replay(); BatchPreparedStatementSetter setter = new AbstractInterruptibleBatchPreparedStatementSetter() { protected boolean setValuesIfAvailable(PreparedStatement ps, int i) throws SQLException { if (i < ids.length) { ps.setInt(1, ids[i]); return true; } else { return false; } } }; JdbcTemplate template = new JdbcTemplate(mockDataSource, false); int[] actualRowsAffected = template.batchUpdate(sql, setter); assertTrue("executed 2 updates", actualRowsAffected.length == 2); assertEquals(rowsAffected[0], actualRowsAffected[0]); assertEquals(rowsAffected[1], actualRowsAffected[1]); ctrlPreparedStatement.verify(); ctrlDatabaseMetaData.verify(); }
From source file:org.springframework.jdbc.core.JdbcTemplateTests.java
public void testBatchUpdateWithPreparedStatement() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final int[] ids = new int[] { 100, 200 }; final int[] rowsAffected = new int[] { 1, 2 }; MockControl ctrlPreparedStatement = MockControl.createControl(PreparedStatement.class); PreparedStatement mockPreparedStatement = (PreparedStatement) ctrlPreparedStatement.getMock(); mockPreparedStatement.getConnection(); ctrlPreparedStatement.setReturnValue(mockConnection); mockPreparedStatement.setInt(1, ids[0]); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.addBatch();/*from w w w .jav a 2s. com*/ ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.setInt(1, ids[1]); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.addBatch(); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.executeBatch(); ctrlPreparedStatement.setReturnValue(rowsAffected); if (debugEnabled) { mockPreparedStatement.getWarnings(); ctrlPreparedStatement.setReturnValue(null); } mockPreparedStatement.close(); ctrlPreparedStatement.setVoidCallable(); MockControl ctrlDatabaseMetaData = MockControl.createControl(DatabaseMetaData.class); DatabaseMetaData mockDatabaseMetaData = (DatabaseMetaData) ctrlDatabaseMetaData.getMock(); mockDatabaseMetaData.getDatabaseProductName(); ctrlDatabaseMetaData.setReturnValue("MySQL"); mockDatabaseMetaData.supportsBatchUpdates(); ctrlDatabaseMetaData.setReturnValue(true); mockConnection.prepareStatement(sql); ctrlConnection.setReturnValue(mockPreparedStatement); mockConnection.getMetaData(); ctrlConnection.setReturnValue(mockDatabaseMetaData, 2); ctrlPreparedStatement.replay(); ctrlDatabaseMetaData.replay(); replay(); BatchPreparedStatementSetter setter = new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setInt(1, ids[i]); } public int getBatchSize() { return ids.length; } }; JdbcTemplate template = new JdbcTemplate(mockDataSource, false); int[] actualRowsAffected = template.batchUpdate(sql, setter); assertTrue("executed 2 updates", actualRowsAffected.length == 2); assertEquals(rowsAffected[0], actualRowsAffected[0]); assertEquals(rowsAffected[1], actualRowsAffected[1]); ctrlPreparedStatement.verify(); ctrlDatabaseMetaData.verify(); }
From source file:org.springframework.jdbc.core.JdbcTemplateTests.java
public void testBatchUpdateFails() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final int[] ids = new int[] { 100, 200 }; SQLException sex = new SQLException(); MockControl ctrlPreparedStatement = MockControl.createControl(PreparedStatement.class); PreparedStatement mockPreparedStatement = (PreparedStatement) ctrlPreparedStatement.getMock(); mockPreparedStatement.getConnection(); ctrlPreparedStatement.setReturnValue(mockConnection); mockPreparedStatement.setInt(1, ids[0]); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.addBatch();/*from w w w.j av a 2 s . c o m*/ ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.setInt(1, ids[1]); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.addBatch(); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.executeBatch(); ctrlPreparedStatement.setThrowable(sex); mockPreparedStatement.close(); ctrlPreparedStatement.setVoidCallable(); MockControl ctrlDatabaseMetaData = MockControl.createControl(DatabaseMetaData.class); DatabaseMetaData mockDatabaseMetaData = (DatabaseMetaData) ctrlDatabaseMetaData.getMock(); mockDatabaseMetaData.getDatabaseProductName(); ctrlDatabaseMetaData.setReturnValue("MySQL"); mockDatabaseMetaData.supportsBatchUpdates(); ctrlDatabaseMetaData.setReturnValue(true); ctrlConnection.reset(); mockConnection.prepareStatement(sql); ctrlConnection.setReturnValue(mockPreparedStatement); mockConnection.getMetaData(); ctrlConnection.setReturnValue(mockDatabaseMetaData, 2); mockConnection.close(); ctrlConnection.setVoidCallable(2); ctrlPreparedStatement.replay(); ctrlDatabaseMetaData.replay(); replay(); BatchPreparedStatementSetter setter = new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setInt(1, ids[i]); } public int getBatchSize() { return ids.length; } }; try { JdbcTemplate template = new JdbcTemplate(mockDataSource); template.batchUpdate(sql, setter); fail("Should have failed because of SQLException in bulk update"); } catch (DataAccessException ex) { assertTrue("Root cause is SQLException", ex.getCause() == sex); } ctrlPreparedStatement.verify(); ctrlDatabaseMetaData.verify(); }
From source file:org.springframework.jdbc.core.JdbcTemplateTests.java
public void testInterruptibleBatchUpdateWithBaseClass() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final int[] ids = new int[] { 100, 200 }; final int[] rowsAffected = new int[] { 1, 2 }; MockControl ctrlPreparedStatement = MockControl.createControl(PreparedStatement.class); PreparedStatement mockPreparedStatement = (PreparedStatement) ctrlPreparedStatement.getMock(); mockPreparedStatement.getConnection(); ctrlPreparedStatement.setReturnValue(mockConnection); mockPreparedStatement.setInt(1, ids[0]); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.addBatch();/*w w w . ja v a 2 s . c om*/ ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.setInt(1, ids[1]); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.addBatch(); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.executeBatch(); ctrlPreparedStatement.setReturnValue(rowsAffected); if (debugEnabled) { mockPreparedStatement.getWarnings(); ctrlPreparedStatement.setReturnValue(null); } mockPreparedStatement.close(); ctrlPreparedStatement.setVoidCallable(); MockControl ctrlDatabaseMetaData = MockControl.createControl(DatabaseMetaData.class); DatabaseMetaData mockDatabaseMetaData = (DatabaseMetaData) ctrlDatabaseMetaData.getMock(); mockDatabaseMetaData.getDatabaseProductName(); ctrlDatabaseMetaData.setReturnValue("MySQL"); mockDatabaseMetaData.supportsBatchUpdates(); ctrlDatabaseMetaData.setReturnValue(true); mockConnection.prepareStatement(sql); ctrlConnection.setReturnValue(mockPreparedStatement); mockConnection.getMetaData(); ctrlConnection.setReturnValue(mockDatabaseMetaData, 2); ctrlPreparedStatement.replay(); ctrlDatabaseMetaData.replay(); replay(); BatchPreparedStatementSetter setter = new AbstractInterruptibleBatchPreparedStatementSetter() { protected boolean setValuesIfAvailable(PreparedStatement ps, int i) throws SQLException { if (i < ids.length) { ps.setInt(1, ids[i]); return true; } else { return false; } } }; JdbcTemplate template = new JdbcTemplate(mockDataSource, false); int[] actualRowsAffected = template.batchUpdate(sql, setter); assertTrue("executed 2 updates", actualRowsAffected.length == 2); assertEquals(rowsAffected[0], actualRowsAffected[0]); assertEquals(rowsAffected[1], actualRowsAffected[1]); ctrlPreparedStatement.verify(); ctrlDatabaseMetaData.verify(); }
From source file:org.springframework.jdbc.core.JdbcTemplateTests.java
public void testInterruptibleBatchUpdate() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final int[] ids = new int[] { 100, 200 }; final int[] rowsAffected = new int[] { 1, 2 }; MockControl ctrlPreparedStatement = MockControl.createControl(PreparedStatement.class); PreparedStatement mockPreparedStatement = (PreparedStatement) ctrlPreparedStatement.getMock(); mockPreparedStatement.getConnection(); ctrlPreparedStatement.setReturnValue(mockConnection); mockPreparedStatement.setInt(1, ids[0]); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.addBatch();//from w w w .ja v a 2s . c o m ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.setInt(1, ids[1]); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.addBatch(); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.executeBatch(); ctrlPreparedStatement.setReturnValue(rowsAffected); if (debugEnabled) { mockPreparedStatement.getWarnings(); ctrlPreparedStatement.setReturnValue(null); } mockPreparedStatement.close(); ctrlPreparedStatement.setVoidCallable(); MockControl ctrlDatabaseMetaData = MockControl.createControl(DatabaseMetaData.class); DatabaseMetaData mockDatabaseMetaData = (DatabaseMetaData) ctrlDatabaseMetaData.getMock(); mockDatabaseMetaData.getDatabaseProductName(); ctrlDatabaseMetaData.setReturnValue("MySQL"); mockDatabaseMetaData.supportsBatchUpdates(); ctrlDatabaseMetaData.setReturnValue(true); mockConnection.prepareStatement(sql); ctrlConnection.setReturnValue(mockPreparedStatement); mockConnection.getMetaData(); ctrlConnection.setReturnValue(mockDatabaseMetaData, 2); ctrlPreparedStatement.replay(); ctrlDatabaseMetaData.replay(); replay(); BatchPreparedStatementSetter setter = new InterruptibleBatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { if (i < ids.length) { ps.setInt(1, ids[i]); } } public int getBatchSize() { return 1000; } public boolean isBatchExhausted(int i) { return (i >= ids.length); } }; JdbcTemplate template = new JdbcTemplate(mockDataSource, false); int[] actualRowsAffected = template.batchUpdate(sql, setter); assertTrue("executed 2 updates", actualRowsAffected.length == 2); assertEquals(rowsAffected[0], actualRowsAffected[0]); assertEquals(rowsAffected[1], actualRowsAffected[1]); ctrlPreparedStatement.verify(); ctrlDatabaseMetaData.verify(); }
From source file:org.metis.pull.WdsResourceBean.java
/** * Called by Spring after all of this bean's properties have been set. *//*from w w w . j a va2 s . c om*/ 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 . java2s. 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:com.ccl.jersey.codegen.SimpleMetaDataExporter.java
/** * Export the tables based on the given database metadata * * @param md/*from ww w . j a v a 2s . co m*/ * @param stmt * @throws SQLException */ public void export(DatabaseMetaData md, Statement stmt) throws SQLException { if (basePackageName == null) { basePackageName = module.getPackageName(); } module.bind(SQLCodegenModule.PACKAGE_NAME, basePackageName + ".query"); String beanPackageName = basePackageName + ".entity"; module.bind(SQLCodegenModule.BEAN_PACKAGE_NAME, beanPackageName); if (spatial) { SpatialSupport.addSupport(module); } typeMappings = module.get(TypeMappings.class); queryTypeFactory = module.get(QueryTypeFactory.class); metaDataSerializer = module.get(Serializer.class); beanSerializer = module.get(Serializer.class, SQLCodegenModule.BEAN_SERIALIZER); namingStrategy = module.get(NamingStrategy.class); configuration = module.get(Configuration.class); SQLTemplates templates = sqlTemplatesRegistry.getTemplates(md); if (templates != null) { configuration.setTemplates(templates); } else { logger.info("Found no specific dialect for " + md.getDatabaseProductName()); } if (beanSerializer == null) { keyDataFactory = new KeyDataFactory(namingStrategy, module.getPackageName(), module.getPrefix(), module.getSuffix(), schemaToPackage); } else { keyDataFactory = new KeyDataFactory(namingStrategy, beanPackageName, module.getBeanPrefix(), module.getBeanSuffix(), schemaToPackage); } String[] typesArray = null; if (tableTypesToExport != null && !tableTypesToExport.isEmpty()) { List<String> types = new ArrayList<String>(); for (String tableType : tableTypesToExport.split(",")) { types.add(tableType.trim()); } typesArray = types.toArray(new String[types.size()]); } else if (!exportAll) { List<String> types = new ArrayList<String>(2); if (exportTables) { types.add("TABLE"); } if (exportViews) { types.add("VIEW"); } typesArray = types.toArray(new String[types.size()]); } Map<String, String> modules = new HashMap<String, String>(); if (tableNamePattern != null && tableNamePattern.contains(",")) { for (String table : tableNamePattern.split(",")) { ResultSet tables = md.getTables(null, schemaPattern, null, typesArray); try { while (tables.next()) { String tableName = normalize(tables.getString("TABLE_NAME")); if (tableName.matches(table)) { addModule(stmt, modules, tableName); handleTable(md, tables, stmt); } } } finally { tables.close(); } } } else { ResultSet tables = md.getTables(null, schemaPattern, null, typesArray); try { while (tables.next()) { String tableName = normalize(tables.getString("TABLE_NAME")); if (null == tableNamePattern || tableName.matches(tableNamePattern)) { addModule(stmt, modules, tableName); handleTable(md, tables, stmt); } } } finally { tables.close(); } } stmt.close(); }
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); }