Changeset 4030


Ignore:
Timestamp:
Dec 3, 2007, 1:29:48 PM (15 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #858: Display database name when starting initdb and updatedb scripts

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/Config.java

    r3719 r4030  
    9595  public static String getString(String key)
    9696  {
    97     assert isInitialised : "Config has not been initialised";
    9897    return getString(key, null);
    9998  }
     
    108107  public static String getString(String key, String defaultValue)
    109108  {
    110     assert isInitialised : "Config has not been initialised";
     109    if (!isInitialised) init();
    111110    String value = config.getProperty(key, defaultValue);
    112111    if (value != null) value = value.trim();
     
    122121  public static int getInt(String key)
    123122  {
    124     assert isInitialised : "Config has not been initialised";
    125123    return getInt(key, 0);
    126124  }
     
    136134  public static int getInt(String key, int defaultValue)
    137135  {
    138     assert isInitialised : "Config has not been initialised";
     136    if (!isInitialised) init();
    139137    int result = defaultValue;
    140138    String setting = config.getProperty(key);
     
    161159  public static long getLong(String key, long defaultValue)
    162160  {
    163     assert isInitialised : "Config has not been initialised";
     161    if (!isInitialised) init();
    164162    long result = defaultValue;
    165163    String setting = config.getProperty(key);
     
    186184  public static boolean getBoolean(String key)
    187185  {
    188     assert isInitialised : "Config has not been initialised";
     186    if (!isInitialised) init();
    189187    String setting = config.getProperty(key);
    190188    return (setting == null
     
    205203  public static String getCharset()
    206204  {
    207     return config.getProperty("defaultCharset", "ISO-8859-1");
     205    return getString("defaultCharset", "ISO-8859-1");
    208206  }
    209207
  • trunk/src/core/net/sf/basedb/core/Version.java

    r3675 r4030  
    4646  private static String maintenance;
    4747  private static int build;
     48 
     49  static
     50  {
     51    init();
     52  }
    4853 
    4954  /**
  • trunk/src/install/net/sf/basedb/install/InitDB.java

    r3917 r4030  
    2525package net.sf.basedb.install;
    2626
     27import java.sql.Driver;
    2728import java.util.Arrays;
    2829import java.util.List;
     30import java.util.Properties;
    2931
    3032import net.sf.basedb.core.Application;
     33import net.sf.basedb.core.Config;
    3134import net.sf.basedb.core.HibernateUtil;
    3235import net.sf.basedb.core.Install;
     36import net.sf.basedb.core.ProgressReporter;
    3337import net.sf.basedb.core.Update;
    3438import net.sf.basedb.util.ConsoleProgressReporter;
     
    6670        ChainedProgressReporter progress = new ChainedProgressReporter(new ConsoleProgressReporter());
    6771        progress.setRange(0, 30);
     72        showDbInfo(progress);
    6873        Install.createTables(update, progress);
    6974        progress.setRange(35, 70);
     
    7984      else if ("info".equals(cmd))
    8085      {
     86        showDbInfo(null);
    8187        Application.start(false);
    8288        HibernateUtil.dbIndexes(true, false, false, false);
     
    8692      {
    8793        boolean verbose = args.length >= 2 ? args[1].equals("-v") : false;
     94        showDbInfo(null);
    8895        Application.start(false);
    8996        HibernateUtil.dbIndexes(verbose, false, false, true);
     
    93100      {
    94101        boolean verbose = args.length >= 2 ? args[1].equals("-v") : false;
     102        showDbInfo(null);
    95103        Application.start(false);
    96104        HibernateUtil.dbIndexes(verbose, false, true, false);
     
    100108      {
    101109        List<String> opt = Arrays.asList(args);
     110        showDbInfo(null);
    102111        boolean verbose = opt.contains("-v");
    103112        boolean drop = opt.contains("-dropindexes");
     
    135144  }
    136145
     146  private static void showDbInfo(ProgressReporter progress)
     147  {
     148    final Properties properties = System.getProperties();
     149    final String jdbcDriver = Config.getString("db.driver");
     150    String driverVersion = "unknown version";
     151    try
     152    {
     153      final Driver driver = (Driver)Class.forName(jdbcDriver).newInstance();
     154      driverVersion = "version " + driver.getMajorVersion() + "." + driver.getMinorVersion();
     155    }
     156    catch (Throwable t)
     157    {}
     158   
     159    String message =
     160      "--System information-----------------------------\n" +
     161      "BASE     : " + Application.getMajorVersion() + "." +
     162        Application.getMinorVersion() + "." +
     163        Application.getMaintenanceVersion() + "\n" +
     164      "Database : " + Config.getString("db.url") + "\n" +
     165      "Dialect  : " + Config.getString("db.dialect") + "\n" +
     166      "JDBC     : " + jdbcDriver + "; " + driverVersion + "\n" +
     167      "Java     : " + properties.getProperty("java.runtime.name") + "; " +
     168        properties.getProperty("java.runtime.version") + "; " +
     169        properties.getProperty("java.vendor") + "\n" +
     170      "OS       : " + properties.getProperty("os.name") +"; " +
     171        properties.getProperty("os.arch") + "; " +
     172        properties.getProperty("os.version") +"\n" +
     173      "-------------------------------------------------";
     174    if (progress != null)
     175    {
     176      progress.display(0, message);
     177    }
     178    else
     179    {
     180      System.out.println(message);
     181    }
     182  }
     183 
    137184}
    138185
Note: See TracChangeset for help on using the changeset viewer.