Changeset 4032


Ignore:
Timestamp:
Dec 4, 2007, 1:16:24 PM (15 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #850: SQL for checking schema version in BASE 1 should be externalized

Location:
trunk/src/clients/migrate/net/sf/basedb/clients/migrate
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/migrate/net/sf/basedb/clients/migrate/Manager.java

    r3679 r4032  
    2929import net.sf.basedb.core.Application;
    3030
     31import java.sql.PreparedStatement;
    3132import java.text.SimpleDateFormat;
    3233import java.util.Date;
     34import java.util.Map;
    3335
    3436/**
     
    4850  private SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
    4951
     52  /**
     53  PreparedStatements
     54   */
     55  private Map<String, PreparedStatement> preparedStatements = null;
     56
     57  public void setPreparedStatements(
     58      Map<String, PreparedStatement> preparedStatements)
     59  {
     60    this.preparedStatements = preparedStatements;
     61  }
     62
     63  public Map<String, PreparedStatement> getPreparedStatements()
     64  {
     65    return preparedStatements;
     66  }
     67 
     68  /**
     69  @param statement SQL statement to prepare selected from configured
     70         queryStatementsFile in migrate.properties.
     71   */
     72  protected PreparedStatement prepareStatementFromFile(String statement)
     73  {
     74    PreparedStatement ps = preparedStatements.get(statement);
     75    if (ps == null)
     76    {
     77      log.error("Statement '" + statement + "' is null");
     78      stop();
     79    }
     80    return ps;
     81  }
     82 
    5083  /**
    5184  Prints date without linebreak.
  • trunk/src/clients/migrate/net/sf/basedb/clients/migrate/Migrater.java

    r3824 r4032  
    4545import java.util.HashMap;
    4646import java.util.HashSet;
     47import java.util.Map;
    4748import java.util.Properties;
    4849import java.util.Set;
     
    9293  PreparedStatements
    9394   */
    94   private HashMap<String, PreparedStatement> preparedStatements = new HashMap<String, PreparedStatement>();
     95  //private HashMap<String, PreparedStatement> preparedStatements = new HashMap<String, PreparedStatement>();
    9596 
    9697  /**
     
    317318        else
    318319        {
    319           transfer.setPreparedStatements(preparedStatements);       
     320          transfer.setPreparedStatements(getPreparedStatements());       
    320321          transfer.setup(
    321322              FROM, TO, sessionControl, BASE2, migrateProperties);
     
    449450    String regexp = "^\\/\\*\\s+(\\w+)\\s+\\*\\/$";
    450451    Pattern pattern = Pattern.compile(regexp);
     452    Map<String, PreparedStatement> preparedStatements =
     453      new HashMap<String, PreparedStatement>();
    451454    try
    452455    {
     
    511514      stop();
    512515    }
     516    setPreparedStatements(preparedStatements);
    513517  }
    514518 
     
    528532    {
    529533      log.info("Verifying schema version of BASE1");
    530       PreparedStatement ps = FROM.prepareStatement("SELECT baseVersion, schemaVersion, lastChanged FROM SchemaVersion");
    531       ResultSet rs = ps.executeQuery();    
     534      PreparedStatement ps = prepareStatementFromFile("verifySchemaVersion");
     535      ResultSet rs = ps.executeQuery();
    532536      rs.next();
    533537      String schemaVersion = rs.getString(2);
     
    591595    migrater.configure();
    592596    migrater.connect();
     597    migrater.prepareStatementsFromFile();
    593598    migrater.verifySchemaVersion();
    594     migrater.prepareStatementsFromFile();
    595599    log.info("Migration initialisation DONE");
    596600    if (resumeMigration)
  • trunk/src/clients/migrate/net/sf/basedb/clients/migrate/Transfer.java

    r3725 r4032  
    109109  protected boolean QUICK_TRANSFER = false;
    110110  protected boolean LOCAL_MYSQL_TRANSFER = false;
    111   /**
    112   PreparedStatements
    113    */
    114   private HashMap<String, PreparedStatement> preparedStatements = null;
    115111 
    116112  /**
     
    175171      e.printStackTrace();
    176172    }
    177   }
    178 
    179   public void setPreparedStatements(
    180       HashMap<String, PreparedStatement> preparedStatements)
    181   {
    182     this.preparedStatements = preparedStatements;
    183   }
    184 
    185   /**
    186   @param statement SQL statement to prepare selected from configured
    187          queryStatementsFile in migrate.properties.
    188    */
    189   protected PreparedStatement prepareStatementFromFile(String statement)
    190   {
    191     PreparedStatement ps = preparedStatements.get(statement);
    192     if (ps == null)
    193     {
    194       log.error("Statement '" + statement + "' is null");
    195       stop();
    196     }
    197     return ps;
    198173  }
    199174
Note: See TracChangeset for help on using the changeset viewer.