Ejemplo 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);
    }
  }
  public boolean isSameObject(
      DatabaseObject object1, DatabaseObject object2, Database accordingTo) {
    if (object1 == null && object2 == null) {
      return true;
    }
    if (object1 == null || object2 == null) {
      return false;
    }

    UUID snapshotId1 = object1.getSnapshotId();
    UUID snapshotId2 = object2.getSnapshotId();
    if (snapshotId1 != null && snapshotId2 != null) {
      if (snapshotId1.equals(snapshotId2)) {
        return true;
      }
    }

    boolean aHashMatches = false;

    List<String> hash1 = Arrays.asList(hash(object1, accordingTo));
    List<String> hash2 = Arrays.asList(hash(object2, accordingTo));
    for (String hash : hash1) {
      if (hash2.contains(hash)) {
        aHashMatches = true;
        break;
      }
    }

    if (!aHashMatches) {
      return false;
    }

    return createComparatorChain(object1.getClass(), accordingTo)
        .isSameObject(object1, object2, accordingTo);
  }
Ejemplo n.º 3
0
 public void addDatabaseObject(DatabaseObject databaseObject) {
   if (databaseObject == null) {
     return;
   }
   Set<DatabaseObject> objects = this.getObjects().get(databaseObject.getClass());
   if (objects == null) {
     objects = new HashSet<DatabaseObject>();
     this.getObjects().put(databaseObject.getClass(), objects);
   }
   objects.add(databaseObject);
 }
 public ObjectDifferences findDifferences(
     DatabaseObject object1,
     DatabaseObject object2,
     Database accordingTo,
     CompareControl compareControl) {
   return createComparatorChain(object1.getClass(), accordingTo)
       .findDifferences(object1, object2, accordingTo, compareControl, new HashSet<String>());
 }
Ejemplo n.º 5
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;
  }
  public String[] hash(DatabaseObject databaseObject, Database accordingTo) {
    String[] hash = null;
    if (databaseObject != null) {
      hash =
          createComparatorChain(databaseObject.getClass(), accordingTo)
              .hash(databaseObject, accordingTo);
    }

    if (hash == null) {
      hash = new String[] {"null"};
    }

    for (int i = 0; i < hash.length; i++) {
      if (StringUtils.trimToNull(hash[i]) == null) {
        hash[i] = "null";
      }
    }
    return hash;
  }
Ejemplo n.º 7
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);
    }
  }
Ejemplo n.º 8
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);
  }
Ejemplo n.º 9
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);
  }