Ejemplo n.º 1
0
  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;
  }
Ejemplo n.º 2
0
 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);
   }
 }
Ejemplo n.º 3
0
 public String[] getDropSql() {
   if (dropSql == null) {
     dropSql = configuration.generateDropSchemaScript(dialect);
   }
   return dropSql;
 }
Ejemplo n.º 4
0
 public String[] getCreateSql() {
   if (createSql == null) {
     createSql = configuration.generateSchemaCreationScript(dialect);
   }
   return createSql;
 }