예제 #1
0
  /** 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();
    }
  }
 public ResultSet getUDTs(
     String catalog, String schemaPattern, String typeNamePattern, int[] types)
     throws SQLException {
   _conn.checkOpen();
   try {
     return DelegatingResultSet.wrapResultSet(
         _conn, _meta.getUDTs(catalog, schemaPattern, typeNamePattern, types));
   } catch (SQLException e) {
     handleException(e);
     throw new AssertionError();
   }
 }
예제 #3
0
 @Test
 public void columnOrderOfgetUDTs() throws SQLException {
   ResultSet rs = meta.getUDTs(null, null, null, null);
   assertFalse(rs.next());
   ResultSetMetaData rsmeta = rs.getMetaData();
   assertEquals(rsmeta.getColumnCount(), 7);
   assertEquals(rsmeta.getColumnName(1), "TYPE_CAT");
   assertEquals(rsmeta.getColumnName(2), "TYPE_SCHEM");
   assertEquals(rsmeta.getColumnName(3), "TYPE_NAME");
   assertEquals(rsmeta.getColumnName(4), "CLASS_NAME");
   assertEquals(rsmeta.getColumnName(5), "DATA_TYPE");
   assertEquals(rsmeta.getColumnName(6), "REMARKS");
   assertEquals(rsmeta.getColumnName(7), "BASE_TYPE");
 }
예제 #4
0
 @Test
 public void testUDTs() throws Exception {
   TestMMDatabaseMetaData.compareResultSet(
       dbMetadata.getUDTs(VDB, null, "%", null)); // $NON-NLS-1$ //$NON-NLS-2$
 }
예제 #5
0
  protected boolean checkExistence(Connection conn, DatabaseObjectType type, String... params)
      throws SQLException {
    boolean result = false;
    DatabaseMetaData metadata = null;
    PreparedStatement pstmt = null;
    BaseSchema baseSchema = catalogStore.getSchema();

    if (params == null || params.length < 1) {
      throw new IllegalArgumentException("checkExistence function needs at least one argument.");
    }

    switch (type) {
      case DATA:
        metadata = conn.getMetaData();
        ResultSet data =
            metadata.getUDTs(
                null,
                baseSchema.getSchemaName() != null && !baseSchema.getSchemaName().isEmpty()
                    ? baseSchema.getSchemaName().toUpperCase()
                    : null,
                params[0].toUpperCase(),
                null);
        result = data.next();
        CatalogUtil.closeQuietly(data);
        break;
      case FUNCTION:
        metadata = conn.getMetaData();
        ResultSet functions =
            metadata.getFunctions(
                null,
                baseSchema.getSchemaName() != null && !baseSchema.getSchemaName().isEmpty()
                    ? baseSchema.getSchemaName().toUpperCase()
                    : null,
                params[0].toUpperCase());
        result = functions.next();
        CatalogUtil.closeQuietly(functions);
        break;
      case INDEX:
        if (params.length != 2) {
          throw new IllegalArgumentException(
              "Finding index object is needed two strings, table name and index name");
        }

        pstmt = getExistQuery(conn, type);
        if (pstmt != null) {
          result = checkExistenceByQuery(pstmt, baseSchema, params);
        } else {
          metadata = conn.getMetaData();
          ResultSet indexes =
              metadata.getIndexInfo(
                  null,
                  baseSchema.getSchemaName() != null && !baseSchema.getSchemaName().isEmpty()
                      ? baseSchema.getSchemaName().toUpperCase()
                      : null,
                  params[0].toUpperCase(),
                  false,
                  true);
          while (indexes.next()) {
            if (indexes.getString("INDEX_NAME").equals(params[1].toUpperCase())) {
              result = true;
              break;
            }
          }
          CatalogUtil.closeQuietly(indexes);
        }
        break;
      case TABLE:
        pstmt = getExistQuery(conn, type);
        if (pstmt != null) {
          result = checkExistenceByQuery(pstmt, baseSchema, params);
        } else {
          metadata = conn.getMetaData();
          ResultSet tables =
              metadata.getTables(
                  null,
                  baseSchema.getSchemaName() != null && !baseSchema.getSchemaName().isEmpty()
                      ? baseSchema.getSchemaName().toUpperCase()
                      : null,
                  params[0].toUpperCase(),
                  new String[] {"TABLE"});
          result = tables.next();
          CatalogUtil.closeQuietly(tables);
        }
        break;
      case DOMAIN:
      case OPERATOR:
      case RULE:
      case SEQUENCE:
      case TRIGGER:
      case VIEW:
        pstmt = getExistQuery(conn, type);

        if (pstmt == null) {
          throw new TajoInternalError(
              "Finding "
                  + type
                  + " type of database object is not supported on this database system.");
        }

        result = checkExistenceByQuery(pstmt, baseSchema, params);
        break;
    }

    return result;
  }
 public ResultSet getUDTs(
     String catalog, String schemaPattern, String typeNamePattern, int[] types)
     throws SQLException {
   return throwExceptionDelegate.getUDTs(catalog, schemaPattern, typeNamePattern, types);
 }