public String[] getCleanSql() {
    if (cleanSql == null) {
      // loop over all foreign key constraints
      List dropForeignKeysSql = new ArrayList();
      List createForeignKeysSql = new ArrayList();
      Iterator iter = configuration.getTableMappings();
      while (iter.hasNext()) {
        Table table = (Table) iter.next();
        if (table.isPhysicalTable()) {
          Iterator subIter = table.getForeignKeyIterator();
          while (subIter.hasNext()) {
            ForeignKey fk = (ForeignKey) subIter.next();
            if (fk.isPhysicalConstraint()) {
              // collect the drop key constraint
              dropForeignKeysSql.add(
                  fk.sqlDropString(
                      dialect,
                      properties.getProperty(Environment.DEFAULT_CATALOG),
                      properties.getProperty(Environment.DEFAULT_SCHEMA)));
              createForeignKeysSql.add(
                  fk.sqlCreateString(
                      dialect,
                      mapping,
                      properties.getProperty(Environment.DEFAULT_CATALOG),
                      properties.getProperty(Environment.DEFAULT_SCHEMA)));
            }
          }
        }
      }

      List deleteSql = new ArrayList();
      iter = configuration.getTableMappings();
      while (iter.hasNext()) {
        Table table = (Table) iter.next();
        deleteSql.add("delete from " + table.getName());
      }

      List cleanSqlList = new ArrayList();
      cleanSqlList.addAll(dropForeignKeysSql);
      cleanSqlList.addAll(deleteSql);
      cleanSqlList.addAll(createForeignKeysSql);

      cleanSql = (String[]) cleanSqlList.toArray(new String[cleanSqlList.size()]);
    }
    return cleanSql;
  }
 public IdentitySchema(Configuration configuration) {
   this.configuration = configuration;
   this.properties = configuration.getProperties();
   this.dialect = Dialect.getDialect(properties);
   try {
     // get the mapping field via reflection :-(
     Field mappingField = Configuration.class.getDeclaredField("mapping");
     mappingField.setAccessible(true);
     this.mapping = (Mapping) mappingField.get(configuration);
   } catch (Exception e) {
     throw new RuntimeException("couldn't get the hibernate mapping", e);
   }
 }
 public String[] getDropSql() {
   if (dropSql == null) {
     dropSql = configuration.generateDropSchemaScript(dialect);
   }
   return dropSql;
 }
 public String[] getCreateSql() {
   if (createSql == null) {
     createSql = configuration.generateSchemaCreationScript(dialect);
   }
   return createSql;
 }