Changeset 6667


Ignore:
Timestamp:
Dec 18, 2014, 1:14:15 PM (8 years ago)
Author:
Nicklas Nordborg
Message:

References #1742: Upgrade to Hibernate 4.x

Fixes the first two issues:

  • MySQLEngine now fixes the SQL commands to a syntax that is accepted by MySQL.
  • Failure to execute a script that is isQuiet()==true results in a log entry and not an error
Location:
branches/3.4-stable/src/core/net/sf/basedb/core
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.4-stable/src/core/net/sf/basedb/core/HibernateUtil.java

    r6651 r6667  
    641641    }
    642642   
    643     if (mode.requireEmptyDatabase())
    644     {
    645       if (!isEmptyDatabase())
    646       {
    647         throw new BaseException("Database already has tables.");
    648       }
     643    boolean emptyDatabase = isEmptyDatabase();
     644    if (mode.requireEmptyDatabase() && !emptyDatabase)
     645    {
     646      throw new BaseException("Database already has tables.");
     647    }
     648    else if (!mode.requireEmptyDatabase() && emptyDatabase)
     649    {
     650      throw new BaseException("Database is empty");
    649651    }
    650652
     
    701703                {
    702704                  isEmpty = false;
    703                   log.error("Table '"+t.getName()+"' already exists; install aborted");
     705                  log.debug("Table '"+t.getName()+"' already exists");
     706                }
     707                else
     708                {
     709                  log.debug("Table '"+t.getName()+"' doesn't exists");
    704710                }
    705711                tables.close();
  • branches/3.4-stable/src/core/net/sf/basedb/core/dbengine/MySQLEngine.java

    r6630 r6667  
    2727import java.util.regex.Pattern;
    2828
     29import net.sf.basedb.core.hibernate.SchemaGenerator;
     30
     31import org.hibernate.dialect.Dialect;
    2932import org.hibernate.mapping.PersistentClass;
    3033
     
    211214
    212215  /**
     216    Fix "alter table ... drop constraint ..." statements that are generated
     217    incorrectly by Hibernate.
     218    @since 3.4
     219  */
     220  @Override
     221  public String inspectSchemaGenerationSQL(String sql, Dialect dialect,
     222      SchemaGenerator.Mode mode)
     223  {
     224    sql = super.inspectSchemaGenerationSQL(sql, dialect, mode);
     225    if (sql != null && sql.startsWith("alter table") && sql.contains("drop constraint"))
     226    {
     227      sql = sql.replace("drop constraint", "drop index");
     228    }
     229    return sql;
     230  }
     231
     232 
     233  /**
    213234    Return true.
    214235  */
  • branches/3.4-stable/src/core/net/sf/basedb/core/hibernate/SchemaGenerator.java

    r6468 r6667  
    120120      int numDone = 0;
    121121      int interval = Math.max(1, numStatements / 30);
     122     
    122123      for (SchemaUpdateScript script : allSql)
    123124      {
     
    131132          }
    132133          log.debug("Executing: " + actualSql);
    133           stmt.executeUpdate(actualSql);
    134           //System.out.println(actualSql);
     134          try
     135          {
     136            stmt.executeUpdate(actualSql);
     137          }
     138          catch (SQLException | RuntimeException ex)
     139          {
     140            if (script.isQuiet())
     141            {
     142              log.info("Ignoring quiet SQL: "+ actualSql, ex);
     143            }
     144            else
     145            {
     146              throw ex;
     147            }
     148          }
    135149          if (progress != null)
    136150          {
     
    153167      }
    154168    }
    155     catch (SQLException ex)
     169    catch (SQLException | RuntimeException ex)
    156170    {
    157171      log.error("Schema update failed", ex);
Note: See TracChangeset for help on using the changeset viewer.