Package org.hibernate.tool.hbm2ddl

Examples of org.hibernate.tool.hbm2ddl.SchemaUpdateScript


      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );
        if ( tableInfo == null ) {
          scripts.add( new SchemaUpdateScript( table.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
        else {
          Iterator<String> subiter = table.sqlAlterStrings( dialect, mapping, tableInfo, tableCatalog,
              tableSchema );
          while ( subiter.hasNext() ) {
            scripts.add( new SchemaUpdateScript( subiter.next(), false ) );
          }
        }

        Iterator<String> comments = table.sqlCommentStrings( dialect, defaultCatalog, defaultSchema );
        while ( comments.hasNext() ) {
          scripts.add( new SchemaUpdateScript( comments.next(), false ) );
        }

      }
    }

    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      String tableSchema = ( table.getSchema() == null ) ? defaultSchema : table.getSchema();
      String tableCatalog = ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog();
      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );

        if (! constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.SKIP )) {
          Iterator uniqueIter = table.getUniqueKeyIterator();
          while ( uniqueIter.hasNext() ) {
            final UniqueKey uniqueKey = (UniqueKey) uniqueIter.next();
            // Skip if index already exists. Most of the time, this
            // won't work since most Dialects use Constraints. However,
            // keep it for the few that do use Indexes.
            if ( tableInfo != null && StringHelper.isNotEmpty( uniqueKey.getName() ) ) {
              final IndexMetadata meta = tableInfo.getIndexMetadata( uniqueKey.getName() );
              if ( meta != null ) {
                continue;
              }
            }
            String constraintString = uniqueKey.sqlCreateString( dialect, mapping, tableCatalog, tableSchema );
            if ( constraintString != null && !constraintString.isEmpty() )
              if ( constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY ) ) {
                String constraintDropString = uniqueKey.sqlDropString( dialect, tableCatalog, tableCatalog );
                scripts.add( new SchemaUpdateScript( constraintDropString, true) );
              }
              scripts.add( new SchemaUpdateScript( constraintString, true) );
          }
        }

        Iterator subIter = table.getIndexIterator();
        while ( subIter.hasNext() ) {
          final Index index = (Index) subIter.next();
          // Skip if index already exists
          if ( tableInfo != null && StringHelper.isNotEmpty( index.getName() ) ) {
            final IndexMetadata meta = tableInfo.getIndexMetadata( index.getName() );
            if ( meta != null ) {
              continue;
            }
          }
          scripts.add( new SchemaUpdateScript( index.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
      }
    }

    // Foreign keys must be created *after* unique keys for numerous DBs.  See HH-8390.
    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      String tableSchema = ( table.getSchema() == null ) ? defaultSchema : table.getSchema();
      String tableCatalog = ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog();
      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );

        if ( dialect.hasAlterTable() ) {
          Iterator subIter = table.getForeignKeyIterator();
          while ( subIter.hasNext() ) {
            ForeignKey fk = (ForeignKey) subIter.next();
            if ( fk.isPhysicalConstraint() ) {
              boolean create = tableInfo == null || ( tableInfo.getForeignKeyMetadata( fk ) == null && (
              // Icky workaround for MySQL bug:
                  !( dialect instanceof MySQLDialect ) || tableInfo.getIndexMetadata( fk.getName() ) == null ) );
              if ( create ) {
                scripts.add( new SchemaUpdateScript( fk.sqlCreateString( dialect, mapping,
                    tableCatalog, tableSchema ), false ) );
              }
            }
          }
        }
View Full Code Here


      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );
        if ( tableInfo == null ) {
          scripts.add( new SchemaUpdateScript( table.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
        else {
          Iterator<String> subiter = table.sqlAlterStrings( dialect, mapping, tableInfo, tableCatalog,
              tableSchema );
          while ( subiter.hasNext() ) {
            scripts.add( new SchemaUpdateScript( subiter.next(), false ) );
          }
        }

        Iterator<String> comments = table.sqlCommentStrings( dialect, defaultCatalog, defaultSchema );
        while ( comments.hasNext() ) {
          scripts.add( new SchemaUpdateScript( comments.next(), false ) );
        }

      }
    }

    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      String tableSchema = ( table.getSchema() == null ) ? defaultSchema : table.getSchema();
      String tableCatalog = ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog();
      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );

        if (! constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.SKIP )) {
          Iterator uniqueIter = table.getUniqueKeyIterator();
          while ( uniqueIter.hasNext() ) {
            final UniqueKey uniqueKey = (UniqueKey) uniqueIter.next();
            // Skip if index already exists. Most of the time, this
            // won't work since most Dialects use Constraints. However,
            // keep it for the few that do use Indexes.
            if ( tableInfo != null && StringHelper.isNotEmpty( uniqueKey.getName() ) ) {
              final IndexMetadata meta = tableInfo.getIndexMetadata( uniqueKey.getName() );
              if ( meta != null ) {
                continue;
              }
            }
            String constraintString = uniqueKey.sqlCreateString( dialect, mapping, tableCatalog, tableSchema );
            if ( constraintString != null && !constraintString.isEmpty() )
              if ( constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY ) ) {
                String constraintDropString = uniqueKey.sqlDropString( dialect, tableCatalog, tableSchema );
                scripts.add( new SchemaUpdateScript( constraintDropString, true) );
              }
              scripts.add( new SchemaUpdateScript( constraintString, true) );
          }
        }

        Iterator subIter = table.getIndexIterator();
        while ( subIter.hasNext() ) {
          final Index index = (Index) subIter.next();
          // Skip if index already exists
          if ( tableInfo != null && StringHelper.isNotEmpty( index.getName() ) ) {
            final IndexMetadata meta = tableInfo.getIndexMetadata( index.getName() );
            if ( meta != null ) {
              continue;
            }
          }
          scripts.add( new SchemaUpdateScript( index.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
      }
    }

    // Foreign keys must be created *after* unique keys for numerous DBs.  See HH-8390.
    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      String tableSchema = ( table.getSchema() == null ) ? defaultSchema : table.getSchema();
      String tableCatalog = ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog();
      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );

        if ( dialect.hasAlterTable() ) {
          Iterator subIter = table.getForeignKeyIterator();
          while ( subIter.hasNext() ) {
            ForeignKey fk = (ForeignKey) subIter.next();
            if ( fk.isPhysicalConstraint() ) {
              boolean create = tableInfo == null || ( tableInfo.getForeignKeyMetadata( fk ) == null && (
              // Icky workaround for MySQL bug:
                  !( dialect instanceof MySQLDialect ) || tableInfo.getIndexMetadata( fk.getName() ) == null ) );
              if ( create ) {
                scripts.add( new SchemaUpdateScript( fk.sqlCreateString( dialect, mapping,
                    tableCatalog, tableSchema ), false ) );
              }
            }
          }
        }
View Full Code Here

      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );
        if ( tableInfo == null ) {
          scripts.add( new SchemaUpdateScript( table.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
        else {
          Iterator<String> subiter = table.sqlAlterStrings( dialect, mapping, tableInfo, tableCatalog,
              tableSchema );
          while ( subiter.hasNext() ) {
            scripts.add( new SchemaUpdateScript( subiter.next(), false ) );
          }
        }

        Iterator<String> comments = table.sqlCommentStrings( dialect, defaultCatalog, defaultSchema );
        while ( comments.hasNext() ) {
          scripts.add( new SchemaUpdateScript( comments.next(), false ) );
        }

      }
    }

    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      String tableSchema = ( table.getSchema() == null ) ? defaultSchema : table.getSchema();
      String tableCatalog = ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog();
      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );

        if (! constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.SKIP )) {
          Iterator uniqueIter = table.getUniqueKeyIterator();
          while ( uniqueIter.hasNext() ) {
            final UniqueKey uniqueKey = (UniqueKey) uniqueIter.next();
            // Skip if index already exists. Most of the time, this
            // won't work since most Dialects use Constraints. However,
            // keep it for the few that do use Indexes.
            if ( tableInfo != null && StringHelper.isNotEmpty( uniqueKey.getName() ) ) {
              final IndexMetadata meta = tableInfo.getIndexMetadata( uniqueKey.getName() );
              if ( meta != null ) {
                continue;
              }
            }
            String constraintString = uniqueKey.sqlCreateString( dialect, mapping, tableCatalog, tableSchema );
            if ( constraintString != null && !constraintString.isEmpty() )
              if ( constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY ) ) {
                String constraintDropString = uniqueKey.sqlDropString( dialect, tableCatalog, tableSchema );
                scripts.add( new SchemaUpdateScript( constraintDropString, true) );
              }
              scripts.add( new SchemaUpdateScript( constraintString, true) );
          }
        }

        Iterator subIter = table.getIndexIterator();
        while ( subIter.hasNext() ) {
          final Index index = (Index) subIter.next();
          // Skip if index already exists
          if ( tableInfo != null && StringHelper.isNotEmpty( index.getName() ) ) {
            final IndexMetadata meta = tableInfo.getIndexMetadata( index.getName() );
            if ( meta != null ) {
              continue;
            }
          }
          scripts.add( new SchemaUpdateScript( index.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
      }
    }

    // Foreign keys must be created *after* unique keys for numerous DBs.  See HH-8390.
    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      String tableSchema = ( table.getSchema() == null ) ? defaultSchema : table.getSchema();
      String tableCatalog = ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog();
      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );

        if ( dialect.hasAlterTable() ) {
          Iterator subIter = table.getForeignKeyIterator();
          while ( subIter.hasNext() ) {
            ForeignKey fk = (ForeignKey) subIter.next();
            if ( fk.isPhysicalConstraint() ) {
              boolean create = tableInfo == null || ( tableInfo.getForeignKeyMetadata( fk ) == null && (
              // Icky workaround for MySQL bug:
                  !( dialect instanceof MySQLDialect ) || tableInfo.getIndexMetadata( fk.getName() ) == null ) );
              if ( create ) {
                scripts.add( new SchemaUpdateScript( fk.sqlCreateString( dialect, mapping,
                    tableCatalog, tableSchema ), false ) );
              }
            }
          }
        }
View Full Code Here

      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );
        if ( tableInfo == null ) {
          scripts.add( new SchemaUpdateScript( table.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
        else {
          Iterator<String> subiter = table.sqlAlterStrings( dialect, mapping, tableInfo, tableCatalog,
              tableSchema );
          while ( subiter.hasNext() ) {
            scripts.add( new SchemaUpdateScript( subiter.next(), false ) );
          }
        }

        Iterator<String> comments = table.sqlCommentStrings( dialect, defaultCatalog, defaultSchema );
        while ( comments.hasNext() ) {
          scripts.add( new SchemaUpdateScript( comments.next(), false ) );
        }

      }
    }

    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      String tableSchema = ( table.getSchema() == null ) ? defaultSchema : table.getSchema();
      String tableCatalog = ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog();
      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );

        if (! constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.SKIP )) {
          Iterator uniqueIter = table.getUniqueKeyIterator();
          while ( uniqueIter.hasNext() ) {
            final UniqueKey uniqueKey = (UniqueKey) uniqueIter.next();
            // Skip if index already exists. Most of the time, this
            // won't work since most Dialects use Constraints. However,
            // keep it for the few that do use Indexes.
            if ( tableInfo != null && StringHelper.isNotEmpty( uniqueKey.getName() ) ) {
              final IndexMetadata meta = tableInfo.getIndexMetadata( uniqueKey.getName() );
              if ( meta != null ) {
                continue;
              }
            }
            String constraintString = uniqueKey.sqlCreateString( dialect, mapping, tableCatalog, tableSchema );
            if ( constraintString != null && !constraintString.isEmpty() )
              if ( constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY ) ) {
                String constraintDropString = uniqueKey.sqlDropString( dialect, tableCatalog, tableSchema );
                scripts.add( new SchemaUpdateScript( constraintDropString, true) );
              }
              scripts.add( new SchemaUpdateScript( constraintString, true) );
          }
        }

        Iterator subIter = table.getIndexIterator();
        while ( subIter.hasNext() ) {
          final Index index = (Index) subIter.next();
          // Skip if index already exists
          if ( tableInfo != null && StringHelper.isNotEmpty( index.getName() ) ) {
            final IndexMetadata meta = tableInfo.getIndexMetadata( index.getName() );
            if ( meta != null ) {
              continue;
            }
          }
          scripts.add( new SchemaUpdateScript( index.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
      }
    }

    // Foreign keys must be created *after* unique keys for numerous DBs.  See HH-8390.
    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      String tableSchema = ( table.getSchema() == null ) ? defaultSchema : table.getSchema();
      String tableCatalog = ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog();
      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );

        if ( dialect.hasAlterTable() ) {
          Iterator subIter = table.getForeignKeyIterator();
          while ( subIter.hasNext() ) {
            ForeignKey fk = (ForeignKey) subIter.next();
            if ( fk.isPhysicalConstraint() ) {
              boolean create = tableInfo == null || ( tableInfo.getForeignKeyMetadata( fk ) == null && (
              // Icky workaround for MySQL bug:
                  !( dialect instanceof MySQLDialect ) || tableInfo.getIndexMetadata( fk.getName() ) == null ) );
              if ( create ) {
                scripts.add( new SchemaUpdateScript( fk.sqlCreateString( dialect, mapping,
                    tableCatalog, tableSchema ), false ) );
              }
            }
          }
        }
View Full Code Here

      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );
        if ( tableInfo == null ) {
          scripts.add( new SchemaUpdateScript( table.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
        else {
          Iterator<String> subiter = table.sqlAlterStrings( dialect, mapping, tableInfo, tableCatalog,
              tableSchema );
          while ( subiter.hasNext() ) {
            scripts.add( new SchemaUpdateScript( subiter.next(), false ) );
          }
        }

        Iterator<String> comments = table.sqlCommentStrings( dialect, defaultCatalog, defaultSchema );
        while ( comments.hasNext() ) {
          scripts.add( new SchemaUpdateScript( comments.next(), false ) );
        }

      }
    }

    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      String tableSchema = ( table.getSchema() == null ) ? defaultSchema : table.getSchema();
      String tableCatalog = ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog();
      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );

        if (! constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.SKIP )) {
          Iterator uniqueIter = table.getUniqueKeyIterator();
          while ( uniqueIter.hasNext() ) {
            final UniqueKey uniqueKey = (UniqueKey) uniqueIter.next();
            // Skip if index already exists. Most of the time, this
            // won't work since most Dialects use Constraints. However,
            // keep it for the few that do use Indexes.
            if ( tableInfo != null && StringHelper.isNotEmpty( uniqueKey.getName() ) ) {
              final IndexMetadata meta = tableInfo.getIndexMetadata( uniqueKey.getName() );
              if ( meta != null ) {
                continue;
              }
            }
            String constraintString = uniqueKey.sqlCreateString( dialect, mapping, tableCatalog, tableSchema );
            if ( constraintString != null && !constraintString.isEmpty() )
              if ( constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY ) ) {
                String constraintDropString = uniqueKey.sqlDropString( dialect, tableCatalog, tableCatalog );
                scripts.add( new SchemaUpdateScript( constraintDropString, true) );
              }
              scripts.add( new SchemaUpdateScript( constraintString, true) );
          }
        }

        if ( dialect.hasAlterTable() ) {
          Iterator subIter = table.getForeignKeyIterator();
          while ( subIter.hasNext() ) {
            ForeignKey fk = (ForeignKey) subIter.next();
            if ( fk.isPhysicalConstraint() ) {
              boolean create = tableInfo == null || ( tableInfo.getForeignKeyMetadata( fk ) == null && (
              // Icky workaround for MySQL bug:
                  !( dialect instanceof MySQLDialect ) || tableInfo.getIndexMetadata( fk.getName() ) == null ) );
              if ( create ) {
                scripts.add( new SchemaUpdateScript( fk.sqlCreateString( dialect, mapping,
                    tableCatalog, tableSchema ), false ) );
              }
            }
          }
        }

        Iterator subIter = table.getIndexIterator();
        while ( subIter.hasNext() ) {
          final Index index = (Index) subIter.next();
          // Skip if index already exists
          if ( tableInfo != null && StringHelper.isNotEmpty( index.getName() ) ) {
            final IndexMetadata meta = tableInfo.getIndexMetadata( index.getName() );
            if ( meta != null ) {
              continue;
            }
          }
          scripts.add( new SchemaUpdateScript( index.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
      }
    }
View Full Code Here

      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );
        if ( tableInfo == null ) {
          scripts.add( new SchemaUpdateScript( table.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
        else {
          Iterator<String> subiter = table.sqlAlterStrings( dialect, mapping, tableInfo, tableCatalog,
              tableSchema );
          while ( subiter.hasNext() ) {
            scripts.add( new SchemaUpdateScript( subiter.next(), false ) );
          }
        }

        Iterator<String> comments = table.sqlCommentStrings( dialect, defaultCatalog, defaultSchema );
        while ( comments.hasNext() ) {
          scripts.add( new SchemaUpdateScript( comments.next(), false ) );
        }

      }
    }

    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      String tableSchema = ( table.getSchema() == null ) ? defaultSchema : table.getSchema();
      String tableCatalog = ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog();
      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );

        if (! constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.SKIP )) {
          Iterator uniqueIter = table.getUniqueKeyIterator();
          while ( uniqueIter.hasNext() ) {
            final UniqueKey uniqueKey = (UniqueKey) uniqueIter.next();
            // Skip if index already exists. Most of the time, this
            // won't work since most Dialects use Constraints. However,
            // keep it for the few that do use Indexes.
            if ( tableInfo != null && StringHelper.isNotEmpty( uniqueKey.getName() ) ) {
              final IndexMetadata meta = tableInfo.getIndexMetadata( uniqueKey.getName() );
              if ( meta != null ) {
                continue;
              }
            }
            String constraintString = uniqueKey.sqlCreateString( dialect, mapping, tableCatalog, tableSchema );
            if ( constraintString != null && !constraintString.isEmpty() )
              if ( constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY ) ) {
                String constraintDropString = uniqueKey.sqlDropString( dialect, tableCatalog, tableSchema );
                scripts.add( new SchemaUpdateScript( constraintDropString, true) );
              }
              scripts.add( new SchemaUpdateScript( constraintString, true) );
          }
        }

        Iterator subIter = table.getIndexIterator();
        while ( subIter.hasNext() ) {
          final Index index = (Index) subIter.next();
          // Skip if index already exists
          if ( tableInfo != null && StringHelper.isNotEmpty( index.getName() ) ) {
            final IndexMetadata meta = tableInfo.getIndexMetadata( index.getName() );
            if ( meta != null ) {
              continue;
            }
          }
          scripts.add( new SchemaUpdateScript( index.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
      }
    }

    // Foreign keys must be created *after* unique keys for numerous DBs.  See HH-8390.
    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      String tableSchema = ( table.getSchema() == null ) ? defaultSchema : table.getSchema();
      String tableCatalog = ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog();
      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );

        if ( dialect.hasAlterTable() ) {
          Iterator subIter = table.getForeignKeyIterator();
          while ( subIter.hasNext() ) {
            ForeignKey fk = (ForeignKey) subIter.next();
            if ( fk.isPhysicalConstraint() ) {
              boolean create = tableInfo == null || ( tableInfo.getForeignKeyMetadata( fk ) == null && (
              // Icky workaround for MySQL bug:
                  !( dialect instanceof MySQLDialect ) || tableInfo.getIndexMetadata( fk.getName() ) == null ) );
              if ( create ) {
                scripts.add( new SchemaUpdateScript( fk.sqlCreateString( dialect, mapping,
                    tableCatalog, tableSchema ), false ) );
              }
            }
          }
        }
View Full Code Here

      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );
        if ( tableInfo == null ) {
          scripts.add( new SchemaUpdateScript( table.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
        else {
          Iterator<String> subiter = table.sqlAlterStrings( dialect, mapping, tableInfo, tableCatalog,
              tableSchema );
          while ( subiter.hasNext() ) {
            scripts.add( new SchemaUpdateScript( subiter.next(), false ) );
          }
        }

        Iterator<String> comments = table.sqlCommentStrings( dialect, defaultCatalog, defaultSchema );
        while ( comments.hasNext() ) {
          scripts.add( new SchemaUpdateScript( comments.next(), false ) );
        }

      }
    }

    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      String tableSchema = ( table.getSchema() == null ) ? defaultSchema : table.getSchema();
      String tableCatalog = ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog();
      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );

        if (! constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.SKIP )) {
          Iterator uniqueIter = table.getUniqueKeyIterator();
          while ( uniqueIter.hasNext() ) {
            final UniqueKey uniqueKey = (UniqueKey) uniqueIter.next();
            // Skip if index already exists. Most of the time, this
            // won't work since most Dialects use Constraints. However,
            // keep it for the few that do use Indexes.
            if ( tableInfo != null && StringHelper.isNotEmpty( uniqueKey.getName() ) ) {
              final IndexMetadata meta = tableInfo.getIndexMetadata( uniqueKey.getName() );
              if ( meta != null ) {
                continue;
              }
            }
            String constraintString = uniqueKey.sqlCreateString( dialect, mapping, tableCatalog, tableSchema );
            if ( constraintString != null && !constraintString.isEmpty() )
              if ( constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY ) ) {
                String constraintDropString = uniqueKey.sqlDropString( dialect, tableCatalog, tableSchema );
                scripts.add( new SchemaUpdateScript( constraintDropString, true) );
              }
              scripts.add( new SchemaUpdateScript( constraintString, true) );
          }
        }

        Iterator subIter = table.getIndexIterator();
        while ( subIter.hasNext() ) {
          final Index index = (Index) subIter.next();
          // Skip if index already exists
          if ( tableInfo != null && StringHelper.isNotEmpty( index.getName() ) ) {
            final IndexMetadata meta = tableInfo.getIndexMetadata( index.getName() );
            if ( meta != null ) {
              continue;
            }
          }
          scripts.add( new SchemaUpdateScript( index.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
      }
    }

    // Foreign keys must be created *after* unique keys for numerous DBs.  See HH-8390.
    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      String tableSchema = ( table.getSchema() == null ) ? defaultSchema : table.getSchema();
      String tableCatalog = ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog();
      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );

        if ( dialect.hasAlterTable() ) {
          Iterator subIter = table.getForeignKeyIterator();
          while ( subIter.hasNext() ) {
            ForeignKey fk = (ForeignKey) subIter.next();
            if ( fk.isPhysicalConstraint() ) {
              boolean create = tableInfo == null || ( tableInfo.getForeignKeyMetadata( fk ) == null && (
              // Icky workaround for MySQL bug:
                  !( dialect instanceof MySQLDialect ) || tableInfo.getIndexMetadata( fk.getName() ) == null ) );
              if ( create ) {
                scripts.add( new SchemaUpdateScript( fk.sqlCreateString( dialect, mapping,
                    tableCatalog, tableSchema ), false ) );
              }
            }
          }
        }
View Full Code Here

      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );
        if ( tableInfo == null ) {
          scripts.add( new SchemaUpdateScript( table.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
        else {
          Iterator<String> subiter = table.sqlAlterStrings( dialect, mapping, tableInfo, tableCatalog,
              tableSchema );
          while ( subiter.hasNext() ) {
            scripts.add( new SchemaUpdateScript( subiter.next(), false ) );
          }
        }

        Iterator<String> comments = table.sqlCommentStrings( dialect, defaultCatalog, defaultSchema );
        while ( comments.hasNext() ) {
          scripts.add( new SchemaUpdateScript( comments.next(), false ) );
        }

      }
    }

    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      String tableSchema = ( table.getSchema() == null ) ? defaultSchema : table.getSchema();
      String tableCatalog = ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog();
      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );

        if (! constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.SKIP )) {
          Iterator uniqueIter = table.getUniqueKeyIterator();
          while ( uniqueIter.hasNext() ) {
            final UniqueKey uniqueKey = (UniqueKey) uniqueIter.next();
            // Skip if index already exists. Most of the time, this
            // won't work since most Dialects use Constraints. However,
            // keep it for the few that do use Indexes.
            if ( tableInfo != null && StringHelper.isNotEmpty( uniqueKey.getName() ) ) {
              final IndexMetadata meta = tableInfo.getIndexMetadata( uniqueKey.getName() );
              if ( meta != null ) {
                continue;
              }
            }
            String constraintString = uniqueKey.sqlCreateString( dialect, mapping, tableCatalog, tableSchema );
            if ( constraintString != null && !constraintString.isEmpty() )
              if ( constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY ) ) {
                String constraintDropString = uniqueKey.sqlDropString( dialect, tableCatalog, tableSchema );
                scripts.add( new SchemaUpdateScript( constraintDropString, true) );
              }
              scripts.add( new SchemaUpdateScript( constraintString, true) );
          }
        }

        Iterator subIter = table.getIndexIterator();
        while ( subIter.hasNext() ) {
          final Index index = (Index) subIter.next();
          // Skip if index already exists
          if ( tableInfo != null && StringHelper.isNotEmpty( index.getName() ) ) {
            final IndexMetadata meta = tableInfo.getIndexMetadata( index.getName() );
            if ( meta != null ) {
              continue;
            }
          }
          scripts.add( new SchemaUpdateScript( index.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
      }
    }

    // Foreign keys must be created *after* unique keys for numerous DBs.  See HH-8390.
    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      String tableSchema = ( table.getSchema() == null ) ? defaultSchema : table.getSchema();
      String tableCatalog = ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog();
      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );

        if ( dialect.hasAlterTable() ) {
          Iterator subIter = table.getForeignKeyIterator();
          while ( subIter.hasNext() ) {
            ForeignKey fk = (ForeignKey) subIter.next();
            if ( fk.isPhysicalConstraint() ) {
              boolean create = tableInfo == null || ( tableInfo.getForeignKeyMetadata( fk ) == null && (
              // Icky workaround for MySQL bug:
                  !( dialect instanceof MySQLDialect ) || tableInfo.getIndexMetadata( fk.getName() ) == null ) );
              if ( create ) {
                scripts.add( new SchemaUpdateScript( fk.sqlCreateString( dialect, mapping,
                    tableCatalog, tableSchema ), false ) );
              }
            }
          }
        }
View Full Code Here

      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );
        if ( tableInfo == null ) {
          scripts.add( new SchemaUpdateScript( table.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
        else {
          Iterator<String> subiter = table.sqlAlterStrings( dialect, mapping, tableInfo, tableCatalog,
              tableSchema );
          while ( subiter.hasNext() ) {
            scripts.add( new SchemaUpdateScript( subiter.next(), false ) );
          }
        }

        Iterator<String> comments = table.sqlCommentStrings( dialect, defaultCatalog, defaultSchema );
        while ( comments.hasNext() ) {
          scripts.add( new SchemaUpdateScript( comments.next(), false ) );
        }

      }
    }

    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      String tableSchema = ( table.getSchema() == null ) ? defaultSchema : table.getSchema();
      String tableCatalog = ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog();
      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );

        if (! constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.SKIP )) {
          Iterator uniqueIter = table.getUniqueKeyIterator();
          while ( uniqueIter.hasNext() ) {
            final UniqueKey uniqueKey = (UniqueKey) uniqueIter.next();
            // Skip if index already exists. Most of the time, this
            // won't work since most Dialects use Constraints. However,
            // keep it for the few that do use Indexes.
            if ( tableInfo != null && StringHelper.isNotEmpty( uniqueKey.getName() ) ) {
              final IndexMetadata meta = tableInfo.getIndexMetadata( uniqueKey.getName() );
              if ( meta != null ) {
                continue;
              }
            }
            String constraintString = uniqueKey.sqlCreateString( dialect, mapping, tableCatalog, tableSchema );
            if ( constraintString != null && !constraintString.isEmpty() )
              if ( constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY ) ) {
                String constraintDropString = uniqueKey.sqlDropString( dialect, tableCatalog, tableCatalog );
                scripts.add( new SchemaUpdateScript( constraintDropString, true) );
              }
              scripts.add( new SchemaUpdateScript( constraintString, true) );
          }
        }

        if ( dialect.hasAlterTable() ) {
          Iterator subIter = table.getForeignKeyIterator();
          while ( subIter.hasNext() ) {
            ForeignKey fk = (ForeignKey) subIter.next();
            if ( fk.isPhysicalConstraint() ) {
              boolean create = tableInfo == null || ( tableInfo.getForeignKeyMetadata( fk ) == null && (
              // Icky workaround for MySQL bug:
                  !( dialect instanceof MySQLDialect ) || tableInfo.getIndexMetadata( fk.getName() ) == null ) );
              if ( create ) {
                scripts.add( new SchemaUpdateScript( fk.sqlCreateString( dialect, mapping,
                    tableCatalog, tableSchema ), false ) );
              }
            }
          }
        }

        Iterator subIter = table.getIndexIterator();
        while ( subIter.hasNext() ) {
          final Index index = (Index) subIter.next();
          // Skip if index already exists
          if ( tableInfo != null && StringHelper.isNotEmpty( index.getName() ) ) {
            final IndexMetadata meta = tableInfo.getIndexMetadata( index.getName() );
            if ( meta != null ) {
              continue;
            }
          }
          scripts.add( new SchemaUpdateScript( index.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
      }
    }
View Full Code Here

      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );
        if ( tableInfo == null ) {
          scripts.add( new SchemaUpdateScript( table.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
        else {
          Iterator<String> subiter = table.sqlAlterStrings( dialect, mapping, tableInfo, tableCatalog,
              tableSchema );
          while ( subiter.hasNext() ) {
            scripts.add( new SchemaUpdateScript( subiter.next(), false ) );
          }
        }

        Iterator<String> comments = table.sqlCommentStrings( dialect, defaultCatalog, defaultSchema );
        while ( comments.hasNext() ) {
          scripts.add( new SchemaUpdateScript( comments.next(), false ) );
        }

      }
    }

    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      String tableSchema = ( table.getSchema() == null ) ? defaultSchema : table.getSchema();
      String tableCatalog = ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog();
      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );

        if (! constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.SKIP )) {
          Iterator uniqueIter = table.getUniqueKeyIterator();
          while ( uniqueIter.hasNext() ) {
            final UniqueKey uniqueKey = (UniqueKey) uniqueIter.next();
            // Skip if index already exists. Most of the time, this
            // won't work since most Dialects use Constraints. However,
            // keep it for the few that do use Indexes.
            if ( tableInfo != null && StringHelper.isNotEmpty( uniqueKey.getName() ) ) {
              final IndexMetadata meta = tableInfo.getIndexMetadata( uniqueKey.getName() );
              if ( meta != null ) {
                continue;
              }
            }
            String constraintString = uniqueKey.sqlCreateString( dialect, mapping, tableCatalog, tableSchema );
            if ( constraintString != null && !constraintString.isEmpty() )
              if ( constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY ) ) {
                String constraintDropString = uniqueKey.sqlDropString( dialect, tableCatalog, tableSchema );
                scripts.add( new SchemaUpdateScript( constraintDropString, true) );
              }
              scripts.add( new SchemaUpdateScript( constraintString, true) );
          }
        }

        Iterator subIter = table.getIndexIterator();
        while ( subIter.hasNext() ) {
          final Index index = (Index) subIter.next();
          // Skip if index already exists
          if ( tableInfo != null && StringHelper.isNotEmpty( index.getName() ) ) {
            final IndexMetadata meta = tableInfo.getIndexMetadata( index.getName() );
            if ( meta != null ) {
              continue;
            }
          }
          scripts.add( new SchemaUpdateScript( index.sqlCreateString( dialect, mapping, tableCatalog,
              tableSchema ), false ) );
        }
      }
    }

    // Foreign keys must be created *after* unique keys for numerous DBs.  See HH-8390.
    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      String tableSchema = ( table.getSchema() == null ) ? defaultSchema : table.getSchema();
      String tableCatalog = ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog();
      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), tableSchema,
            tableCatalog, table.isQuoted() );

        if ( dialect.hasAlterTable() ) {
          Iterator subIter = table.getForeignKeyIterator();
          while ( subIter.hasNext() ) {
            ForeignKey fk = (ForeignKey) subIter.next();
            if ( fk.isPhysicalConstraint() ) {
              boolean create = tableInfo == null || ( tableInfo.getForeignKeyMetadata( fk ) == null && (
              // Icky workaround for MySQL bug:
                  !( dialect instanceof MySQLDialect ) || tableInfo.getIndexMetadata( fk.getName() ) == null ) );
              if ( create ) {
                scripts.add( new SchemaUpdateScript( fk.sqlCreateString( dialect, mapping,
                    tableCatalog, tableSchema ), false ) );
              }
            }
          }
        }
View Full Code Here

TOP

Related Classes of org.hibernate.tool.hbm2ddl.SchemaUpdateScript

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.