Java Code Examples for java.sql.DatabaseMetaData#getTableTypes()

The following examples show how to use java.sql.DatabaseMetaData#getTableTypes() . 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: DatabaseMetaDataTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Test getTableTypes()
 */
public void testTableTypes() throws SQLException
{
    DatabaseMetaData dmd = getDMD();

    ResultSet rs = dmd.getTableTypes();
    assertMetaDataResultSet(rs,
            new String[] {
            "TABLE_TYPE"
           },
           new int[] {
            Types.VARCHAR
           }
    , null
          );

    JDBC.assertFullResultSet(rs, new String[][]
      {
        {"SYNONYM"},{"SYSTEM TABLE"},{"TABLE"},{"VIEW"},
      }, true);
    rs.close();
}
 
Example 2
Source File: DatabaseMetaDataIT.java    From snowflake-jdbc with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetTableTypes() throws Throwable
{
  try (Connection connection = getConnection())
  {
    DatabaseMetaData metaData = connection.getMetaData();
    ResultSet resultSet = metaData.getTableTypes();
    Set<String> types = new HashSet<>();
    while (resultSet.next())
    {
      types.add(resultSet.getString(1));
    }
    assertEquals(2, types.size());
    assertTrue(types.contains("TABLE"));
    assertTrue(types.contains("VIEW"));
  }
}
 
Example 3
Source File: DatabaseMetaDataTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Test getTableTypes()
 */
public void testTableTypes() throws SQLException
{
    DatabaseMetaData dmd = getDMD();

    ResultSet rs = dmd.getTableTypes();
    assertMetaDataResultSet(rs,
            new String[] {
            "TABLE_TYPE"
           },
           new int[] {
            Types.VARCHAR
           }
    , null
          );

    JDBC.assertFullResultSet(rs, new String[][]
      {
        {"SYNONYM"},{"SYSTEM TABLE"},{"TABLE"},{"VIEW"},
      }, true);
    rs.close();
}
 
Example 4
Source File: ConnectionTest.java    From tddl5 with Apache License 2.0 6 votes vote down vote up
/**
 * MetaData
 * 
 * @author jianghang
 * @since 5.0.2
 */
@Test
public void testDatabaseMetaData() throws Exception {
    DatabaseMetaData metaData = tddlConnection.getMetaData();
    ResultSet rs = metaData.getTableTypes();
    printResult(rs);

    rs = metaData.getTables("andor_mysql_group_atom",
        "andor_mysql_group_atom",
        "mysql_ibatis_type",
        new String[] { "TABLE" });
    printResult(rs);

    rs = metaData.getColumns("andor_mysql_group_atom", "andor_mysql_group_atom", "mysql_ibatis_type", "%");
    printResult(rs);
}
 
Example 5
Source File: JdbcThinMetadataSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testGetTableTypes() throws Exception {
    try (Connection conn = DriverManager.getConnection(URL)) {
        DatabaseMetaData meta = conn.getMetaData();

        ResultSet rs = meta.getTableTypes();

        assertTrue(rs.next());

        assertEquals("TABLE", rs.getString("TABLE_TYPE"));

        assertTrue(rs.next());

        assertEquals("VIEW", rs.getString("TABLE_TYPE"));
    }
}
 
Example 6
Source File: JdbcMetadataSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testGetTableTypes() throws Exception {
    try (Connection conn = DriverManager.getConnection(BASE_URL)) {
        DatabaseMetaData meta = conn.getMetaData();

        ResultSet rs = meta.getTableTypes();

        assertTrue(rs.next());

        assertEquals("TABLE", rs.getString("TABLE_TYPE"));

        assertTrue(rs.next());

        assertEquals("VIEW", rs.getString("TABLE_TYPE"));
    }
}
 
Example 7
Source File: JDBCSourceOrSink.java    From components with Apache License 2.0 6 votes vote down vote up
private Set<String> getAvailableTableTypes(DatabaseMetaData dbMetaData) throws SQLException {
    Set<String> availableTableTypes = new HashSet<String>();
    List<String> neededTableTypes = Arrays.asList("TABLE", "VIEW", "SYNONYM");

    try (ResultSet rsTableTypes = dbMetaData.getTableTypes()) {
        while (rsTableTypes.next()) {
            String currentTableType = rsTableTypes.getString("TABLE_TYPE");
            if (currentTableType == null) {
                currentTableType = "";
            }
            currentTableType = currentTableType.trim();
            if ("BASE TABLE".equalsIgnoreCase(currentTableType)) {
                currentTableType = "TABLE";
            }
            if (neededTableTypes.contains(currentTableType)) {
                availableTableTypes.add(currentTableType);
            }
        }
    }

    return availableTableTypes;
}
 
Example 8
Source File: QueryDatabaseMetaDataIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testTableTypes() throws SQLException {
    try (Connection conn = DriverManager.getConnection(getUrl())) {
        DatabaseMetaData dbmd = conn.getMetaData();
        ResultSet rs = dbmd.getTableTypes();
        assertTrue(rs.next());
        assertEquals("INDEX", rs.getString(1));
        assertTrue(rs.next());
        assertEquals("SEQUENCE", rs.getString(1));
        assertTrue(rs.next());
        assertEquals("SYSTEM TABLE", rs.getString(1));
        assertTrue(rs.next());
        assertEquals("TABLE", rs.getString(1));
        assertTrue(rs.next());
        assertEquals("VIEW", rs.getString(1));
        assertFalse(rs.next());
    }
}
 
Example 9
Source File: AceQLMetaData.java    From aceql-http with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
    * Returns the table types for the Connection
    *
    * @return the table types for the Connection
    * @throws SQLException it any SQL Exception occurs
    */
   public List<String> getTableTypes() throws SQLException {
DatabaseMetaData databaseMetaData = connection.getMetaData();
ResultSet rs = databaseMetaData.getTableTypes();
List<String> tableTypes = new ArrayList<>();
while (rs.next()) {
    tableTypes.add(rs.getString(1));
}
return tableTypes;
   }
 
Example 10
Source File: MetaDataJavaPrinter.java    From aceql-http with GNU Lesser General Public License v2.1 5 votes vote down vote up
public List<String> getTableTypes() throws SQLException {
DatabaseMetaData databaseMetaData = connection.getMetaData();
ResultSet rs = databaseMetaData.getTableTypes();
List<String> tableTypes = new ArrayList<>();
while (rs.next()) {
    tableTypes.add(rs.getString(1));
}
return tableTypes;
   }
 
Example 11
Source File: MetaResultSetTest.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
@Test public void testGetTableTypes() throws SQLException {
  DatabaseMetaData metadata = getDatabaseMetadata();
  try (ResultSet rs = metadata.getTableTypes()) {
    ResultSetMetaData rsMeta = rs.getMetaData();

    assertEquals(1, rsMeta.getColumnCount());
    assertColumn(rsMeta, 1, "TABLE_TYPE", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
  }
}
 
Example 12
Source File: Database.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the "TABLE" and "VIEW" keywords for table type, with unsupported keywords omitted.
 */
private static String[] getTableTypes(final DatabaseMetaData metadata) throws SQLException {
    final Set<String> types = new HashSet<>(4);
    try (ResultSet reflect = metadata.getTableTypes()) {
        while (reflect.next()) {
            final String type = reflect.getString(Reflection.TABLE_TYPE);
            if ("TABLE".equalsIgnoreCase(type) || "VIEW".equalsIgnoreCase(type)) {
                types.add(type);
            }
        }
    }
    return types.toArray(new String[types.size()]);
}
 
Example 13
Source File: CassandraConnectionTest.java    From cassandra-jdbc-driver with Apache License 2.0 4 votes vote down vote up
@Test(groups = {"unit", "server"})
public void testGetMetaData() {
    try {
        DatabaseMetaData metaData = conn.getMetaData();
        assertNotNull(metaData);
        assertEquals("KEYSPACE", metaData.getSchemaTerm());

        ResultSet rs = metaData.getTableTypes();
        assertTrue(rs instanceof DummyCassandraResultSet);
        assertEquals(extractColumnNames(CassandraUtils.TABLE_TYPE_COLUMNS),
                CassandraUtils.getColumnNames(rs));
        assertEquals(CassandraUtils.TABLE_TYPE_DATA[0],
                CassandraUtils.getAllData(rs)[0]);
        rs.close();

        rs = metaData.getSchemas();
        assertTrue(rs instanceof DummyCassandraResultSet);
        assertEquals(extractColumnNames(CassandraUtils.SCHEMA_COLUMNS),
                CassandraUtils.getColumnNames(rs));
        Logger.debug(CassandraUtils.getAllData(rs));
        rs.close();

        rs = metaData.getTables(null, "system", "peers", null);
        assertTrue(rs instanceof DummyCassandraResultSet);
        assertEquals(extractColumnNames(CassandraUtils.TABLE_COLUMNS),
                CassandraUtils.getColumnNames(rs));
        Logger.debug(CassandraUtils.getAllData(rs));
        rs.close();

        rs = metaData.getColumns(null, "system", "peers", null);
        assertTrue(rs instanceof DummyCassandraResultSet);
        assertEquals(extractColumnNames(CassandraUtils.COLUMN_COLUMNS),
                CassandraUtils.getColumnNames(rs));
        Logger.debug(CassandraUtils.getAllData(rs));
        rs.close();

        rs = metaData.getIndexInfo(null, "system", "peers", false, true);
        assertTrue(rs instanceof DummyCassandraResultSet);
        assertEquals(extractColumnNames(CassandraUtils.INDEX_COLUMNS),
                CassandraUtils.getColumnNames(rs));
        Logger.debug(CassandraUtils.getAllData(rs));
        rs.close();

        rs = metaData.getPrimaryKeys(null, "system", "peers");
        assertTrue(rs instanceof DummyCassandraResultSet);
        assertEquals(extractColumnNames(CassandraUtils.PK_COLUMNS),
                CassandraUtils.getColumnNames(rs));
        Logger.debug(CassandraUtils.getAllData(rs));
        rs.close();

        rs = metaData.getUDTs(null, "system", "%", null);
        assertTrue(rs instanceof DummyCassandraResultSet);
        assertEquals(extractColumnNames(CassandraUtils.UDT_COLUMNS),
                CassandraUtils.getColumnNames(rs));
        Logger.debug(CassandraUtils.getAllData(rs));
        rs.close();

        rs = metaData.getColumns(null, "system", "IndexInfo", null);
        assertTrue(rs instanceof DummyCassandraResultSet);
        assertEquals(extractColumnNames(CassandraUtils.COLUMN_COLUMNS),
                CassandraUtils.getColumnNames(rs));
        Logger.debug(CassandraUtils.getAllData(rs));
        rs.close();
    } catch (SQLException e) {
        e.printStackTrace();
        fail("Error occurred during testing: " + e.getMessage());
    }
}