Java Code Examples for java.sql.DatabaseMetaData#getUDTs()
The following examples show how to use
java.sql.DatabaseMetaData#getUDTs() .
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: DatabaseMetaDataIT.java From snowflake-jdbc with Apache License 2.0 | 6 votes |
@Test public void testOtherEmptyTables() throws Throwable { try (Connection connection = getConnection()) { DatabaseMetaData metaData = connection.getMetaData(); ResultSet resultSet; // index is not supported. resultSet = metaData.getIndexInfo(null, null, null, true, true); assertEquals(0, getSizeOfResultSet(resultSet)); // UDT is not supported. resultSet = metaData.getUDTs(null, null, null, new int[]{}); assertEquals(0, getSizeOfResultSet(resultSet)); } }
Example 2
Source File: Show.java From jsqsh with Apache License 2.0 | 6 votes |
private ResultSet doUser(Session session, Connection con, Options options) throws SQLException { if (options.arguments.size() < 2 || options.arguments.size() > 3 || !options.arguments.get(1).equalsIgnoreCase("types")) { session.err.println("Use: \\show user types [[[catalog.]schema-pattern.]type-pattern]"); return null; } SQLConnectionContext ctx = (SQLConnectionContext) session.getConnectionContext(); SQLObjectName name = (options.arguments.size() == 3) ? new SQLObjectName(ctx, options.arguments.get(2)) : new SQLObjectName(ctx, "%"); DatabaseMetaData meta = con.getMetaData(); return meta.getUDTs( (options.catalog != null ? options.catalog : name.getCatalog()), (options.schemaPattern != null ? options.schemaPattern : name.getSchema()), (options.tablePattern != null ? options.tablePattern : name.getName()), null); }
Example 3
Source File: TestDatabaseMetaData.java From evosql with Apache License 2.0 | 5 votes |
/** * Basic test of DatabaseMetaData functions that access system tables */ public void testTwo() throws Exception { Connection conn = newConnection(); int updateCount; try { TestUtil.testScript(conn, "testrun/hsqldb/TestSelf.txt"); DatabaseMetaData dbmeta = conn.getMetaData(); dbmeta.allProceduresAreCallable(); dbmeta.getBestRowIdentifier(null, null, "T_1", DatabaseMetaData.bestRowTransaction, true); dbmeta.getCatalogs(); dbmeta.getColumnPrivileges(null, "PUBLIC", "T_1", "%"); dbmeta.getColumns("PUBLIC", "PUBLIC", "T_1", "%"); dbmeta.getCrossReference(null, null, "T_1", null, null, "T_1"); dbmeta.getExportedKeys(null, null, "T_1"); dbmeta.getFunctionColumns(null, "%", "%", "%"); dbmeta.getFunctions(null, "%", "%"); dbmeta.getImportedKeys("PUBLIC", "PUBLIC", "T_1"); dbmeta.getIndexInfo("PUBLIC", "PUBLIC", "T1", true, true); dbmeta.getPrimaryKeys("PUBLIC", "PUBLIC", "T_1"); dbmeta.getProcedureColumns(null, null, "%", "%"); dbmeta.getProcedures("PUBLIC", "%", "%"); dbmeta.getSchemas(null, "#"); dbmeta.getTablePrivileges(null, "%", "%"); dbmeta.getUDTs(null, "%", "%", new int[]{ Types.DISTINCT }); } catch (Exception e) { assertTrue("unable to prepare or execute DDL", false); } finally { conn.close(); } }
Example 4
Source File: MetaResultSetTest.java From calcite-avatica with Apache License 2.0 | 5 votes |
@Test public void testGetUDTs() throws SQLException { DatabaseMetaData metadata = getDatabaseMetadata(); try (ResultSet rs = metadata.getUDTs(null, null, null, null)) { ResultSetMetaData rsMeta = rs.getMetaData(); assertEquals(7, rsMeta.getColumnCount()); assertColumn(rsMeta, 1, "TYPE_CAT", Types.VARCHAR, DatabaseMetaData.columnNullable); assertColumn(rsMeta, 2, "TYPE_SCHEM", Types.VARCHAR, DatabaseMetaData.columnNullable); assertColumn(rsMeta, 3, "TYPE_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls); assertColumn(rsMeta, 4, "CLASS_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls); assertColumn(rsMeta, 5, "DATA_TYPE", Types.INTEGER, DatabaseMetaData.columnNoNulls); assertColumn(rsMeta, 6, "REMARKS", Types.VARCHAR, DatabaseMetaData.columnNullable); assertColumn(rsMeta, 7, "BASE_TYPE", Types.SMALLINT, DatabaseMetaData.columnNullable); } }
Example 5
Source File: ColumnInfo.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private String getUDTClassName( DatabaseMetaData dmd, String sqlTypeName ) throws SQLException { String className = null; try { // special case for system defined types if ( sqlTypeName.charAt( 0 ) != '"' ) { return sqlTypeName; } String[] nameParts = IdUtil.parseMultiPartSQLIdentifier( sqlTypeName ); String schemaName = nameParts[ 0 ]; String unqualifiedName = nameParts[ 1 ]; ResultSet rs = dmd.getUDTs( null, schemaName, unqualifiedName, new int[] { java.sql.Types.JAVA_OBJECT } ); if ( rs.next() ) { className = rs.getString( 4 ); } rs.close(); } catch (Exception e) { throw LoadError.unexpectedError( e ); } if ( className == null ) { className = "???"; } return className; }
Example 6
Source File: ColumnInfo.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private String getUDTClassName( DatabaseMetaData dmd, String sqlTypeName ) throws SQLException { String className = null; try { // special case for system defined types if ( sqlTypeName.charAt( 0 ) != '"' ) { return sqlTypeName; } String[] nameParts = IdUtil.parseMultiPartSQLIdentifier( sqlTypeName ); String schemaName = nameParts[ 0 ]; String unqualifiedName = nameParts[ 1 ]; ResultSet rs = dmd.getUDTs( null, schemaName, unqualifiedName, new int[] { java.sql.Types.JAVA_OBJECT } ); if ( rs.next() ) { className = rs.getString( 4 ); } rs.close(); } catch (Exception e) { throw LoadError.unexpectedError( e ); } if ( className == null ) { className = "???"; } return className; }
Example 7
Source File: ColumnInfo.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
private String getUDTClassName( DatabaseMetaData dmd, String sqlTypeName ) throws SQLException { String className = null; try { // special case for system defined types if ( sqlTypeName.charAt( 0 ) != '"' ) { return sqlTypeName; } String[] nameParts = IdUtil.parseMultiPartSQLIdentifier( sqlTypeName ); String schemaName = nameParts[ 0 ]; String unqualifiedName = nameParts[ 1 ]; ResultSet rs = dmd.getUDTs( null, schemaName, unqualifiedName, new int[] { java.sql.Types.JAVA_OBJECT } ); if ( rs.next() ) { className = rs.getString( 4 ); } rs.close(); } catch (Exception e) { throw LoadError.unexpectedError( e ); } if ( className == null ) { className = "???"; } return className; }
Example 8
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 9
Source File: CassandraConnectionTest.java From cassandra-jdbc-driver with Apache License 2.0 | 4 votes |
@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()); } }
Example 10
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(); }