Search in sources :

Example 6 with DatabaseMetaData

use of java.sql.DatabaseMetaData in project hive by apache.

the class TestJdbcDriver2 method testImportedKeys.

/**
   * test getImportedKeys()
   * @throws SQLException
   */
@Test
public void testImportedKeys() throws SQLException {
    DatabaseMetaData dbmd = con.getMetaData();
    assertNotNull(dbmd);
    // currently getImportedKeys always returns an empty resultset for Hive
    ResultSet res = dbmd.getImportedKeys(null, null, null);
    ResultSetMetaData md = res.getMetaData();
    assertEquals(md.getColumnCount(), 14);
    assertFalse(res.next());
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData) Test(org.junit.Test)

Example 7 with DatabaseMetaData

use of java.sql.DatabaseMetaData in project hive by apache.

the class TestJdbcDriver2 method testProcCols.

/**
   * test getProcedureColumns()
   * @throws SQLException
   */
@Test
public void testProcCols() throws SQLException {
    DatabaseMetaData dbmd = con.getMetaData();
    assertNotNull(dbmd);
    // currently getProcedureColumns always returns an empty resultset for Hive
    ResultSet res = dbmd.getProcedureColumns(null, null, null, null);
    ResultSetMetaData md = res.getMetaData();
    assertEquals(md.getColumnCount(), 20);
    assertFalse(res.next());
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData) Test(org.junit.Test)

Example 8 with DatabaseMetaData

use of java.sql.DatabaseMetaData in project hive by apache.

the class cbo_rp_TestJdbcDriver2 method testDatabaseMetaData.

@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);
}
Also used : DatabaseMetaData(java.sql.DatabaseMetaData) Test(org.junit.Test)

Example 9 with DatabaseMetaData

use of java.sql.DatabaseMetaData in project zeppelin by apache.

the class SqlCompleter method getSqlKeywordsCompletions.

public static Set<String> getSqlKeywordsCompletions(Connection connection) throws IOException, SQLException {
    // Add the default SQL completions
    String keywords = new BufferedReader(new InputStreamReader(SqlCompleter.class.getResourceAsStream("/ansi.sql.keywords"))).readLine();
    Set<String> completions = new TreeSet<>();
    if (null != connection) {
        DatabaseMetaData metaData = connection.getMetaData();
        // Add the driver specific SQL completions
        String driverSpecificKeywords = "/" + metaData.getDriverName().replace(" ", "-").toLowerCase() + "-sql.keywords";
        logger.info("JDBC DriverName:" + driverSpecificKeywords);
        try {
            if (SqlCompleter.class.getResource(driverSpecificKeywords) != null) {
                String driverKeywords = new BufferedReader(new InputStreamReader(SqlCompleter.class.getResourceAsStream(driverSpecificKeywords))).readLine();
                keywords += "," + driverKeywords.toUpperCase();
            }
        } catch (Exception e) {
            logger.debug("fail to get driver specific SQL completions for " + driverSpecificKeywords + " : " + e, e);
        }
        // Add the keywords from the current JDBC connection
        try {
            keywords += "," + metaData.getSQLKeywords();
        } catch (Exception e) {
            logger.debug("fail to get SQL key words from database metadata: " + e, e);
        }
        try {
            keywords += "," + metaData.getStringFunctions();
        } catch (Exception e) {
            logger.debug("fail to get string function names from database metadata: " + e, e);
        }
        try {
            keywords += "," + metaData.getNumericFunctions();
        } catch (Exception e) {
            logger.debug("fail to get numeric function names from database metadata: " + e, e);
        }
        try {
            keywords += "," + metaData.getSystemFunctions();
        } catch (Exception e) {
            logger.debug("fail to get system function names from database metadata: " + e, e);
        }
        try {
            keywords += "," + metaData.getTimeDateFunctions();
        } catch (Exception e) {
            logger.debug("fail to get time date function names from database metadata: " + e, e);
        }
        // Set all keywords to lower-case versions
        keywords = keywords.toLowerCase();
    }
    StringTokenizer tok = new StringTokenizer(keywords, ", ");
    while (tok.hasMoreTokens()) {
        completions.add(tok.nextToken());
    }
    return completions;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) DatabaseMetaData(java.sql.DatabaseMetaData) IOException(java.io.IOException) SQLException(java.sql.SQLException)

Example 10 with DatabaseMetaData

use of java.sql.DatabaseMetaData in project sharding-jdbc by dangdangdotcom.

the class ShardingDataSourceFactoryTest method createShardingRule.

private ShardingRule createShardingRule() throws SQLException {
    DataSource dataSource = mock(DataSource.class);
    Connection connection = mock(Connection.class);
    DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
    when(dataSource.getConnection()).thenReturn(connection);
    when(connection.getMetaData()).thenReturn(databaseMetaData);
    when(databaseMetaData.getDatabaseProductName()).thenReturn("H2");
    Map<String, DataSource> dataSourceMap = new HashMap<>(1);
    dataSourceMap.put("ds", dataSource);
    DataSourceRule dataSourceRule = new DataSourceRule(dataSourceMap);
    TableRule tableRule = TableRule.builder("logicTable").actualTables(Arrays.asList("table_0", "table_1", "table_2")).dataSourceRule(dataSourceRule).build();
    return ShardingRule.builder().dataSourceRule(dataSourceRule).tableRules(Collections.singletonList(tableRule)).build();
}
Also used : TableRule(com.dangdang.ddframe.rdb.sharding.api.rule.TableRule) HashMap(java.util.HashMap) DataSourceRule(com.dangdang.ddframe.rdb.sharding.api.rule.DataSourceRule) Connection(java.sql.Connection) DatabaseMetaData(java.sql.DatabaseMetaData) DataSource(javax.sql.DataSource)

Aggregations

DatabaseMetaData (java.sql.DatabaseMetaData)299 ResultSet (java.sql.ResultSet)176 Connection (java.sql.Connection)139 SQLException (java.sql.SQLException)116 Test (org.junit.Test)81 ResultSetMetaData (java.sql.ResultSetMetaData)41 Statement (java.sql.Statement)36 ArrayList (java.util.ArrayList)33 PreparedStatement (java.sql.PreparedStatement)29 Properties (java.util.Properties)24 PhoenixDatabaseMetaData (org.apache.phoenix.jdbc.PhoenixDatabaseMetaData)16 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)15 IOException (java.io.IOException)14 HashMap (java.util.HashMap)11 DataSource (javax.sql.DataSource)9 HashSet (java.util.HashSet)8 List (java.util.List)8 Savepoint (java.sql.Savepoint)6 GargoyleException (com.kyj.fx.voeditor.visual.exceptions.GargoyleException)5 TreeSet (java.util.TreeSet)5