Exemplo n.º 1
0
  @Override
  protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot)
      throws DatabaseException {
    Database database = snapshot.getDatabase();
    String objectName = example.getName();
    Schema schema = example.getSchema();

    List<CachedRow> rs = null;
    try {
      JdbcDatabaseSnapshot.CachingDatabaseMetaData metaData =
          ((JdbcDatabaseSnapshot) snapshot).getMetaData();
      rs =
          metaData.getTables(
              ((AbstractJdbcDatabase) database).getJdbcCatalogName(schema),
              ((AbstractJdbcDatabase) database).getJdbcSchemaName(schema),
              database.correctObjectName(objectName, Table.class),
              new String[] {"TABLE"});

      Table table;
      if (rs.size() > 0) {
        table = readTable(rs.get(0), database);
      } else {
        return null;
      }

      return table;
    } catch (SQLException e) {
      throw new DatabaseException(e);
    }
  }
Exemplo n.º 2
0
  @Override
  public boolean isSystemObject(final DatabaseObject example) {
    if (example == null) {
      return false;
    }
    if (example.getSchema() != null
        && example.getSchema().getName() != null
        && example.getSchema().getName().equalsIgnoreCase("information_schema")) {
      return true;
    }
    if (example instanceof Table && getSystemTables().contains(example.getName())) {
      return true;
    }

    if (example instanceof View && getSystemViews().contains(example.getName())) {
      return true;
    }

    return false;
  }
Exemplo n.º 3
0
  @Override
  protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot)
      throws DatabaseException, InvalidExampleException {
    Database database = snapshot.getDatabase();
    Relation relation = ((Column) example).getRelation();
    if (((Column) example).getComputed() != null && ((Column) example).getComputed()) {
      return example;
    }
    Schema schema = relation.getSchema();

    List<CachedRow> columnMetadataRs = null;
    try {

      JdbcDatabaseSnapshot.CachingDatabaseMetaData databaseMetaData =
          ((JdbcDatabaseSnapshot) snapshot).getMetaData();

      columnMetadataRs =
          databaseMetaData.getColumns(
              ((AbstractJdbcDatabase) database).getJdbcCatalogName(schema),
              ((AbstractJdbcDatabase) database).getJdbcSchemaName(schema),
              relation.getName(),
              example.getName());

      if (columnMetadataRs.size() > 0) {
        CachedRow data = columnMetadataRs.get(0);
        Column column = readColumn(data, relation, database);

        if (column != null
            && database instanceof MSSQLDatabase
            && database.getDatabaseMajorVersion() >= 8) {
          String sql;
          if (database.getDatabaseMajorVersion() >= 9) {
            // SQL Server 2005 or later
            // https://technet.microsoft.com/en-us/library/ms177541.aspx
            sql =
                "SELECT CAST([ep].[value] AS [nvarchar](MAX)) AS [REMARKS] "
                    + "FROM [sys].[extended_properties] AS [ep] "
                    + "WHERE [ep].[class] = 1 "
                    + "AND [ep].[major_id] = OBJECT_ID(N'"
                    + database.escapeStringForDatabase(
                        database.escapeTableName(
                            schema.getCatalogName(), schema.getName(), relation.getName()))
                    + "') "
                    + "AND [ep].[minor_id] = COLUMNPROPERTY([ep].[major_id], N'"
                    + database.escapeStringForDatabase(column.getName())
                    + "', 'ColumnId') "
                    + "AND [ep].[name] = 'MS_Description'";
          } else {
            // SQL Server 2000
            // https://technet.microsoft.com/en-us/library/aa224810%28v=sql.80%29.aspx
            sql =
                "SELECT CAST([p].[value] AS [ntext]) AS [REMARKS] "
                    + "FROM [dbo].[sysproperties] AS [p] "
                    + "WHERE [p].[id] = OBJECT_ID(N'"
                    + database.escapeStringForDatabase(
                        database.escapeTableName(
                            schema.getCatalogName(), schema.getName(), relation.getName()))
                    + "') "
                    + "AND [p].[smallid] = COLUMNPROPERTY([p].[id], N'"
                    + database.escapeStringForDatabase(column.getName())
                    + "', 'ColumnId') "
                    + "AND [p].[type] = 4 "
                    + "AND [p].[name] = 'MS_Description'";
          }

          List<String> remarks =
              ExecutorService.getInstance()
                  .getExecutor(snapshot.getDatabase())
                  .queryForList(new RawSqlStatement(sql), String.class);
          if (remarks != null && remarks.size() > 0) {
            column.setRemarks(StringUtils.trimToNull(remarks.iterator().next()));
          }
        }

        return column;
      } else {
        return null;
      }
    } catch (Exception e) {
      throw new DatabaseException(e);
    }
  }
Exemplo n.º 4
0
  @Override
  public boolean isSystemObject(DatabaseObject example) {
    if (example == null) {
      return false;
    }

    if (this.isLiquibaseObject(example)) {
      return false;
    }

    if (example instanceof Schema) {
      if ("SYSTEM".equals(example.getName())
          || "SYS".equals(example.getName())
          || "CTXSYS".equals(example.getName())
          || "XDB".equals(example.getName())) {
        return true;
      }
      if ("SYSTEM".equals(example.getSchema().getCatalogName())
          || "SYS".equals(example.getSchema().getCatalogName())
          || "CTXSYS".equals(example.getSchema().getCatalogName())
          || "XDB".equals(example.getSchema().getCatalogName())) {
        return true;
      }
    } else if (isSystemObject(example.getSchema())) {
      return true;
    }
    if (example instanceof Catalog) {
      if (("SYSTEM".equals(example.getName())
          || "SYS".equals(example.getName())
          || "CTXSYS".equals(example.getName())
          || "XDB".equals(example.getName()))) {
        return true;
      }
    } else if (example.getName() != null) {
      if (example.getName().startsWith("BIN$")) { // oracle deleted table
        return true;
      } else if (example.getName().startsWith("AQ$")) { // oracle AQ tables
        return true;
      } else if (example.getName().startsWith("DR$")) { // oracle index tables
        return true;
      } else if (example.getName().startsWith("SYS_IOT_OVER")) { // oracle system table
        return true;
      } else if ((example.getName().startsWith("MDRT_") || example.getName().startsWith("MDRS_"))
          && example.getName().endsWith("$")) {
        // CORE-1768 - Oracle creates these for spatial indices and will remove them when the index
        // is removed.
        return true;
      } else if (example
          .getName()
          .startsWith(
              "MLOG$_")) { // Created by materliaized view logs for every table that is part of a
        // materialized view. Not available for DDL operations.
        return true;
      } else if (example
          .getName()
          .startsWith(
              "RUPD$_")) { // Created by materialized view log tables using primary keys. Not
        // available for DDL operations.
        return true;
      } else if (example.getName().startsWith("WM$_")) { // Workspace Manager backup tables.
        return true;
      } else if (example
          .getName()
          .equals(
              "CREATE$JAVA$LOB$TABLE")) { // This table contains the name of the Java object, the
        // date it was loaded, and has a BLOB column to store the
        // Java object.
        return true;
      } else if (example
          .getName()
          .equals("JAVA$CLASS$MD5$TABLE")) { // This is a hash table that tracks the loading of Java
        // objects into a schema.
        return true;
      }
    }

    return super.isSystemObject(example);
  }
Exemplo n.º 5
0
  @Override
  public boolean isSystemObject(DatabaseObject example) {
    if (example == null) {
      return false;
    }

    if (this.isLiquibaseObject(example)) {
      return false;
    }

    if (example instanceof Schema) {
      if ("SYSTEM".equals(example.getName())
          || "SYS".equals(example.getName())
          || "CTXSYS".equals(example.getName())
          || "XDB".equals(example.getName())) {
        return true;
      }
      if ("SYSTEM".equals(example.getSchema().getCatalogName())
          || "SYS".equals(example.getSchema().getCatalogName())
          || "CTXSYS".equals(example.getSchema().getCatalogName())
          || "XDB".equals(example.getSchema().getCatalogName())) {
        return true;
      }
    } else if (isSystemObject(example.getSchema())) {
      return true;
    }
    if (example instanceof Catalog) {
      if (("SYSTEM".equals(example.getName())
          || "SYS".equals(example.getName())
          || "CTXSYS".equals(example.getName())
          || "XDB".equals(example.getName()))) {
        return true;
      }
    } else if (example instanceof Table) {
      if (example.getName().startsWith("BIN$")) { // oracle deleted table
        return true;
      } else if (example.getName().startsWith("AQ$")) { // oracle AQ tables
        return true;
      } else if (example.getName().startsWith("DR$")) { // oracle index tables
        return true;
      } else if (example.getName().startsWith("SYS_IOT_OVER")) { // oracle system table
        return true;
      }
    }

    return super.isSystemObject(example);
  }