Changeset 2209


Ignore:
Timestamp:
May 3, 2006, 11:40:05 AM (17 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #3: Update doesn't create indexes

Location:
trunk
Files:
15 added
8 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/build.xml

    r2205 r2209  
    55
    66    Copyright (C) 2005-2006
    7     Samuel Andersson, Jari Häkkinen, Nicklas Nordborg, Gregory Vincic
     7    Samuel Andersson, Jari Häkkinen, Nicklas Nordborg, Gregory Vincic
    88
    99    Files are copyright by their respective authors. The contributions
     
    249249      </fileset>
    250250    </copy>
    251     <chmod perm="a+x">
    252       <fileset dir="${test.build}">
    253         <include name="*.sh" />
    254       </fileset>
    255     </chmod>
     251    <chmod file="${test.build}/run.sh" perm="a+x"/>
    256252    <copy todir="${test.build}">
    257253      <fileset dir="${src}">
     
    555551      jarfile="${dist.bin}/BASE2Install.jar"
    556552    />
    557     <copy todir="${dist.bin}" file="${install.src}/initdb.sh" />
    558     <copy todir="${dist.bin}" file="${install.src}/includes" />
    559     <copy todir="${dist.bin}" file="${install.src}/initdb.bat" />
    560     <copy todir="${dist.bin}" file="${install.src}/updatedb.sh" />
    561     <copy todir="${dist.bin}" file="${install.src}/updatedb.bat" />
    562     <copy todir="${dist.bin}" file="${web.src}/helptexts.xml" />
    563     <chmod file="${dist.bin}/initdb.sh" perm="a+x"/>
    564     <chmod file="${dist.bin}/updatedb.sh" perm="a+x"/>
     553    <copy todir="${dist.bin}">
     554      <fileset dir="${install.src}" includes="*.sh,*.bat" />
     555      <fileset dir="${install.src}" includes="includes" />
     556      <fileset file="${web.src}/helptexts.xml" />
     557    </copy>
     558    <chmod dir="${dist.bin}" includes="*.sh" perm="a+x"/>
    565559  </target>
    566560  <target
  • trunk/src/core/net/sf/basedb/core/HibernateUtil.java

    r2207 r2209  
    3131import net.sf.basedb.core.data.ExtendableData;
    3232import net.sf.basedb.core.data.NewsData;
     33import net.sf.basedb.core.dbengine.DbEngine;
     34import net.sf.basedb.core.dbengine.EngineFactory;
     35import net.sf.basedb.core.dbengine.TableInfo;
     36import net.sf.basedb.core.dbengine.TableInfo.ColumnInfo;
     37import net.sf.basedb.core.dbengine.TableInfo.ForeignKeyInfo;
     38import net.sf.basedb.core.dbengine.TableInfo.IndexInfo;
    3339import net.sf.basedb.core.query.QueryType;
    3440import net.sf.basedb.util.XMLUtil;
    3541
     42import java.util.HashMap;
    3643import java.util.HashSet;
    3744import java.util.List;
    3845import java.util.Iterator;
    3946import java.util.Date;
     47import java.util.Map;
    4048import java.util.Set;
    4149import java.sql.Connection;
     
    6775import org.hibernate.EntityMode;
    6876import org.hibernate.exception.ConstraintViolationException;
    69 import org.hibernate.mapping.ForeignKey;
    7077import org.hibernate.mapping.PersistentClass;
    7178import org.hibernate.mapping.Table;
     
    7582import org.hibernate.mapping.Column;
    7683import org.hibernate.mapping.PrimaryKey;
    77 import org.hibernate.mapping.UniqueKey;
    7884import org.hibernate.cfg.Configuration;
    7985import org.hibernate.tool.hbm2ddl.SchemaExport;
     
    8187import org.hibernate.metadata.ClassMetadata;
    8288import org.hibernate.dialect.Dialect;
    83 import org.hibernate.dialect.Oracle9Dialect;
    8489import org.hibernate.engine.Mapping;
    8590
     
    121126  */
    122127  private static Dialect dialect = null;
     128 
     129  /**
     130    Our extra database specific sql generation that is not possible by
     131    the Hibernate dialect.
     132  */
     133  private static DbEngine dbEngine = null;
    123134
    124135  /**
     
    154165      sf = cfg.buildSessionFactory();
    155166      dialect = Dialect.getDialect(cfg.getProperties());
    156       useThetaJoin = dialect instanceof Oracle9Dialect;
     167      dbEngine = EngineFactory.createEngine(dialect);
     168      useThetaJoin = dbEngine.useThetaJoin();
    157169    }
    158170    catch (HibernateException ex)
     
    172184    cfg = null;
    173185    dialect = null;
     186    dbEngine = null;
    174187  }
    175188
     
    413426      if (update)
    414427      {
    415         // TODO - This will not create indexes, it must be done manually
     428        // Note! This doesn't create indexes correctly. Use dbIndexes method.
    416429        SchemaUpdate se = new SchemaUpdate(cfg);
    417430        se.execute(false, true);
     
    473486    }
    474487    return isEmpty;
    475   }
    476  
    477   private static Set<String> getIndexes(Table t, Set<String> uniqueColumns, Connection c)
    478   {
    479     Set<String> indexes = new HashSet<String>();
    480     try
    481     {
    482       DatabaseMetaData metaData = c.getMetaData();
    483       ResultSet result = metaData.getIndexInfo(t.getCatalog(), t.getSchema(), t.getName(), false, true);
    484       int columnCount = 0;
    485       String lastColumn = null;
    486       String lastName = null;
    487       while (result.next())
    488       {
    489         System.out.println("  IN-DB: " + result.getString(6) + "." + result.getString(9) + "(" + !result.getBoolean(4) + ")");
    490         String name = result.getString(6);
    491         String column = result.getString(9);
    492        
    493         if (uniqueColumns.contains(column))
    494         {
    495           if (lastColumn == null && lastName == null)
    496           {
    497             lastColumn = column;
    498             lastName = name;
    499             columnCount = 1;
    500           }
    501           else if (!lastName.equals(name))
    502           {
    503             if (columnCount > 1) indexes.add(lastName);
    504             lastName = name;
    505             lastColumn = column;
    506             columnCount = 1;
    507           }
    508           else
    509           {
    510             columnCount++;
    511           }
    512         }
    513         else
    514         {
    515           if (lastColumn != null && lastName != null && columnCount > 1)
    516           {
    517             indexes.add(lastName);
    518             lastColumn = null;
    519             lastName = null;
    520           }
    521           indexes.add(name);
    522         }
    523       }
    524      
    525       result = metaData.getPrimaryKeys(t.getCatalog(), t.getSchema(), t.getName());
    526       while (result.next())
    527       {
    528         System.out.println("  PK-DB: " + result.getString(6));
    529         indexes.remove(result.getString(6));
    530       }
    531      
    532       result = metaData.getImportedKeys(t.getCatalog(), t.getSchema(), t.getName());
    533       while (result.next())
    534       {
    535         System.out.println("  FK-DB: " + result.getString(12));
    536         indexes.remove(result.getString(12));
    537       }
    538     }
    539     catch (SQLException ex)
    540     {
    541       throw new BaseException(ex);
    542     }
    543    
    544     System.out.println("  REMAINING: " + indexes);
    545     return indexes;
    546488  }
    547489 
     
    15801522    primary keys and foreign keys as found in the Hibernate mapping
    15811523    information and in the current database.
     1524   
     1525    @param verbose If true, lots of information will be printed
     1526    @param silent If true, no information will be printed
     1527    @param dropIndexes If true, all indexes will be dropped
     1528    @param updateIndexes If true, indexes that doesn't already exist will be created
    15821529  */
    15831530  @SuppressWarnings("unchecked")
    1584   public static void showDatabaseInfo()
    1585   {
     1531  public static void dbIndexes(boolean verbose, boolean silent, boolean dropIndexes, boolean updateIndexes)
     1532  {
     1533    if (silent) verbose = false;
    15861534    Iterator<Table> tables = (Iterator<Table>)cfg.getTableMappings();
     1535    Session session = newSession();
     1536    Connection connection = session.connection();
     1537    DatabaseMetaData metaData = null;
     1538   
     1539    try
     1540    {
     1541      metaData = connection.getMetaData();
     1542    }
     1543    catch (SQLException ex)
     1544    {
     1545      throw new BaseException(ex);
     1546    }
    15871547   
    15881548    while (tables.hasNext())
    15891549    {
    15901550      Table table = tables.next();
    1591       System.out.println("TABLE: " + table.getName());
    1592       System.out.println("  Hibernate information");
    1593       System.out.println("  ---------------------");
    1594       System.out.println("    Catalog      : " + table.getCatalog());
    1595       System.out.println("    Schema       : " + table.getSchema());
     1551      if (!silent)
     1552      {
     1553        System.out.println("=================");
     1554        System.out.println("Table   : " + table.getName());
     1555      }
     1556      if (verbose)
     1557      {
     1558        System.out.println("Catalog : " + table.getCatalog());
     1559        System.out.println("Schema  : " + table.getSchema());
     1560      }
     1561
     1562      Map<Set<String>, String> indexedColumns = new HashMap<Set<String>, String>();
     1563      Map<Set<String>, String> uniqueColumns = new HashMap<Set<String>, String>();
    15961564     
    1597       Iterator<Column> columns = (Iterator<Column>)table.getColumnIterator();
    1598       while (columns.hasNext())
    1599       {
    1600         Column column = columns.next();
    1601         String name = column.getName();
    1602         String type = "";
    1603         try
     1565      String pkName = null;
     1566      Set<String> fkNames = new HashSet<String>();
     1567
     1568      if (verbose)
     1569      {
     1570        System.out.println("Database information");
     1571        System.out.println("--------------------");
     1572      }
     1573     
     1574      TableInfo tiDb = null;
     1575      try
     1576      {
     1577        tiDb = new TableInfo(table, metaData);
     1578      }
     1579      catch (SQLException ex)
     1580      {
     1581        throw new BaseException(ex);
     1582      }
     1583
     1584      if (verbose && tiDb != null)
     1585      {
     1586        // Write all columns
     1587        for (ColumnInfo ci : tiDb.getColumns())
    16041588        {
    1605           type = column.getSqlType(dialect, null);
    1606         }
    1607         catch (Exception ex)
    1608         {}
    1609         boolean isUnique = column.isUnique();
    1610         boolean isNullable = column.isNullable();
    1611         System.out.println("    Column       : " + name + " " + type +
    1612           (isNullable ? " NULL" : " NOT NULL") + (isUnique ? " UNIQUE" : ""));
    1613       }
    1614      
    1615       System.out.println("    Primary key : TODO");
    1616       System.out.println("    Foreign key : TODO");
    1617       System.out.println("    Index       : TODO");
    1618      
    1619       System.out.println("  Database information");
    1620       System.out.println("  --------------------");
    1621       System.out.println("    TODO");
    1622      
    1623     }
    1624    
    1625   }
    1626  
    1627  
    1628   public static void listTables()
    1629   {
    1630     Iterator<Table> ti = (Iterator<Table>)cfg.getTableMappings();
    1631     Dialect dialect = getDialect();
    1632     Session s = newSession();
    1633    
    1634     while (ti.hasNext())
    1635     {
    1636       Table t = ti.next();
    1637       System.out.println("TABLE: " +t.toString());
    1638       if (t.isPhysicalTable())
    1639       {
    1640         Set<String> uniqueColumns = new HashSet<String>();
    1641         Iterator<Column> ci = (Iterator<Column>)t.getColumnIterator();
    1642         while (ci.hasNext())
    1643         {
    1644           Column c = ci.next();
    1645           if (c.isUnique()) uniqueColumns.add(c.getName());
     1589          System.out.println("  Column       : " + ci);
    16461590        }
    16471591       
    1648         Set<String> indexes = getIndexes(t, uniqueColumns, s.connection());
    1649 
    1650         Iterator<Index> ii = (Iterator<Index>)t.getIndexIterator();
    1651         while (ii.hasNext())
     1592        // Write primary key
     1593        System.out.println("  Primary key  : " + tiDb.getPrimaryKey());
     1594     
     1595        // Write foreign keys
     1596        for (ForeignKeyInfo fk : tiDb.getForeignKeys())
    16521597        {
    1653           Index i = ii.next();
    1654           String name = t.getName() + "_" + i.getName();
    1655           System.out.println("  INDEX: "+i.toString());
    1656           /*
    1657           if (indexes.contains(i.getName()))
     1598          System.out.println("  Foreign key  : " + fk);
     1599        }
     1600     
     1601        // Write indexes and unique constraints
     1602        for (IndexInfo ii : tiDb.getIndexes())
     1603        {
     1604          if (ii.isUnique())
    16581605          {
    1659             System.out.println("  DROP-SQL: DROP INDEX " + i.getName());
    1660           }
    1661           */
    1662           if (!indexes.contains(name))
    1663           {
    1664             System.out.println("  CREATE-SQL: " +
    1665               Index.buildSqlCreateIndexString(dialect, name, t, i.getColumnIterator(), false, null, null));
     1606            System.out.println("  Unique       : " + ii);
    16661607          }
    16671608          else
    16681609          {
    1669             indexes.remove(name);
     1610            System.out.println("  Index        : " + ii);
     1611          }
     1612        }
     1613      }
     1614     
     1615      if (verbose)
     1616      {
     1617        System.out.println("Hibernate information");
     1618        System.out.println("---------------------");
     1619      }
     1620     
     1621      TableInfo tiHib = new TableInfo(table, dialect);
     1622     
     1623      if (verbose)
     1624      {
     1625        // Write all columns
     1626        for (ColumnInfo ci : tiHib.getColumns())
     1627        {
     1628          System.out.println("  Column       : " + ci);
     1629        }
     1630       
     1631        // Write primary key
     1632        System.out.println("  Primary key  : " + tiHib.getPrimaryKey());
     1633     
     1634        // Write foreign keys
     1635        for (ForeignKeyInfo fk : tiHib.getForeignKeys())
     1636        {
     1637          System.out.println("  Foreign key  : " + fk);
     1638        }
     1639      }
     1640
     1641      // Write indexes and unique constraints
     1642      for (IndexInfo ii : tiHib.getIndexes())
     1643      {
     1644        if (!silent)
     1645        {
     1646          if (ii.isUnique())
     1647          {
     1648            System.out.println("  Unique       : " + ii);
     1649          }
     1650          else
     1651          {
     1652            System.out.println("  Index        : " + ii);
     1653          }
     1654        }
     1655         
     1656        String dbName = tiDb.findIndexName(ii.getName(), ii.getColumns());
     1657        boolean exists = dbName != null;
     1658        boolean safeToDrop = exists && tiDb.safeToDrop(ii);
     1659
     1660        String dropSql = exists ?
     1661          dbEngine.getDropIndexSql(table.getName(), dbName, ii.isUnique()) : "";
     1662        String createSql =
     1663          dbEngine.getCreateIndexSql(table.getName(), table.getName() + "_" + ii.getName(),
     1664          ii.getColumns(), ii.isUnique());
     1665        boolean actionDrop = dropIndexes && exists && safeToDrop;
     1666        boolean actionCreate = updateIndexes && (actionDrop || !exists);
     1667       
     1668        if (!silent)
     1669        {
     1670          System.out.println("    Exists     : " + exists + (exists ? "(" + dbName + ")" : ""));
     1671          System.out.println("    Safe drop  : " + safeToDrop);
     1672          System.out.println("    DROP-SQL   : " + dropSql);
     1673          System.out.println("    CREATE-SQL : " + createSql);
     1674          System.out.println("    Actions    : " + (actionDrop ? "DROP " : "") +
     1675            (actionCreate ? "CREATE" : ""));
     1676        }
     1677        if (actionDrop || actionCreate)
     1678        {
     1679          Statement st = null;
     1680          try
     1681          {
     1682            st = connection.createStatement();
     1683            if (actionDrop)
     1684            {
     1685              log.info("Dropping index: + " + dropSql);
     1686              st.executeUpdate(dropSql);
     1687            }
     1688            if (actionCreate)
     1689            {
     1690              log.info("Creating index: + " + createSql);
     1691              st.executeUpdate(createSql);
     1692            }
     1693            connection.commit();
     1694            st.close();
     1695            st = null;
     1696          }
     1697          catch (SQLException ex)
     1698          {
     1699            log.error("Exception", ex);
     1700            throw new BaseException(ex);
     1701          }
     1702          finally
     1703          {
     1704            if (st != null)
     1705            {
     1706              try
     1707              {
     1708                st.close();
     1709              }
     1710              catch (Throwable t)
     1711              {
     1712                log.error("Exception", t);
     1713              }
     1714            }
    16701715          }
    16711716        }
    16721717       
    1673         Iterator<UniqueKey> ui = (Iterator<UniqueKey>)t.getUniqueKeyIterator();
    1674         while (ui.hasNext())
    1675         {
    1676           UniqueKey uk = ui.next();
    1677           String name = t.getName() + "_" + uk.getName();
    1678           System.out.println("  UNIQUEKEY: " + uk.toString());
    1679          
    1680           /*
    1681           if (indexes.contains(uk.getName()))
    1682           {
    1683             System.out.println("  DROP-SQL: DROP INDEX " + uk.getName());
    1684           }
    1685           */
    1686           if (!indexes.contains(name))
    1687           {
    1688             System.out.println("  CREATE-SQL: " +
    1689               Index.buildSqlCreateIndexString(dialect, name, t, uk.getColumnIterator(), true, null, null));
    1690           }
    1691           else
    1692           {
    1693             indexes.remove(name);
    1694           }
    1695         }
    1696        
    1697    
    1698         Iterator<ForeignKey> fi = (Iterator<ForeignKey>)t.getForeignKeyIterator();
    1699         while (fi.hasNext())
    1700         {
    1701           ForeignKey fk = fi.next();
    1702           System.out.println("  FOREIGNKEY: " + fk.toString());
    1703         }
    1704        
    1705         PrimaryKey pk = t.getPrimaryKey();
    1706         if (pk != null) System.out.println("  PRIMARYKEY: " + pk.getName());
    1707 
    1708         System.out.println("  DROP-SQL: DROP " + indexes);
    1709        
    1710       }
    1711     }
    1712    
    1713   }
    1714  
    1715   public static void listSql()
    1716   {
    1717     String[] sql = cfg.generateSchemaCreationScript(dialect);
    1718     for (String s : sql)
    1719     {
    1720       System.out.println(s);
    1721     }
    1722   }
    1723  
     1718      }
     1719     
     1720      if (!silent)
     1721      {
     1722        System.out.println("=================");
     1723        System.out.println("");
     1724      }
     1725    }
     1726  }
     1727 
     1728
    17241729}
    17251730
  • trunk/src/install/includes

    r1974 r2209  
    44# BioArray Software Environment (BASE) - http://base.thep.lu.se/
    55# Copyright (C) 2002-2004 Lao Saal, Carl Troein,
    6 # Johan Vallon-Christersson, Jari Hkinen, Nicklas Nordborg
     6# Johan Vallon-Christersson, Jari Häkkinen, Nicklas Nordborg
    77#
    88# This file is part of BASE.
  • trunk/src/install/initdb.bat

    r1974 r2209  
    22REM $Id: run.bat,v 1.6 2004/10/27 15:39:47 nicklas Exp $
    33REM
    4 REM BioArray Software Environment (BASE) - http://base.thep.lu.se/
    5 REM Copyright (C) 2002-2004 Lao Saal, Carl Troein,
    6 REM Johan Vallon-Christersson, Jari H�kkinen, Nicklas Nordborg
     4REM Copyright (C) 2006 Nicklas Nordborg
    75REM
    8 REM This file is part of BASE.
    9 REM
    10 REM BASE is free software; you can redistribute it and/or
    11 REM modify it under the terms of the GNU General Public License
    12 REM as published by the Free Software Foundation; either version 2
    13 REM of the License, or (at your option) any later version.
    14 REM
    15 REM BASE is distributed in the hope that it will be useful,
    16 REM but WITHOUT ANY WARRANTY; without even the implied warranty of
    17 REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    18 REM GNU General Public License for more details.
     6REM This file is part of BASE - BioArray Software Environment.
     7REM Available at http://base.thep.lu.se/
     8REM
     9REM BASE is free software; you can redistribute it and/or modify it
     10REM under the terms of the GNU General Public License as published by
     11REM the Free Software Foundation; either version 2 of the License, or
     12REM (at your option) any later version.
     13REM
     14REM BASE is distributed in the hope that it will be useful, but
     15REM WITHOUT ANY WARRANTY; without even the implied warranty of
     16REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     17REM General Public License for more details.
    1918REM
    2019REM You should have received a copy of the GNU General Public License
    2120REM along with this program; if not, write to the Free Software
    22 REM Foundation, Inc., 59 Temple Place - Suite 330,
    23 REM Boston, MA  02111-1307, USA.
     21REM Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
     22REM 02111-1307, USA.
    2423REM ----------------------------------------
    2524
    26 
    27 REM Set up the classpath
    28 SET WEBINF=../www/WEB-INF
    29 SET CP=.
    30 
    31 REM Base2 configuration
    32 SET CP=%CP%;%WEBINF%/classes
    33 
    34 REM Base2 core & installation
    35 SET CP=%CP%;BASE2Install.jar
    36 SET CP=%CP%;%WEBINF%/lib/BASE2Core.jar
    37 SET CP=%CP%;%WEBINF%/lib/BASE2Webclient.jar
    38 
    39 REM Hibernate
    40 SET CP=%CP%;%WEBINF%/lib/hibernate3.jar
    41 SET CP=%CP%;%WEBINF%/lib/cglib-2.1.3.jar
    42 SET CP=%CP%;%WEBINF%/lib/asm.jar
    43 SET CP=%CP%;%WEBINF%/lib/commons-collections-2.1.1.jar
    44 SET CP=%CP%;%WEBINF%/lib/commons-logging-1.0.4.jar
    45 SET CP=%CP%;%WEBINF%/lib/dom4j-1.6.1.jar
    46 SET CP=%CP%;%WEBINF%/lib/ehcache-1.1.jar
    47 SET CP=%CP%;%WEBINF%/lib/jta.jar
    48 SET CP=%CP%;%WEBINF%/lib/antlr-2.7.6rc1.jar
    49 
    50 REM Log4j (also used by Hibernate)
    51 SET CP=%CP%;%WEBINF%/lib/log4j-1.2.11.jar
    52 
    53 REM C3P0 Connection pool manager
    54 SET CP=%CP%;%WEBINF%/lib/c3p0-0.9.0.jar
    55 
    56 REM MySQL JDBC driver
    57 SET CP=%CP%;%WEBINF%/lib/mysql-connector-java-3.1.12-bin.jar
    58 
    59 REM Postgres JDBC driver
    60 SET CP=%CP%;%WEBINF%/lib/postgresql-8.0-313.jdbc3.jar
    61 
    62 REM Oracle JDBC driver (experimental)
    63 SET CP=%CP%;%WEBINF%/lib/ojdbc14.jar
    64 
    65 REM JDOM and Xerces XML parser
    66 SET CP=%CP%;%WEBINF%/lib/jdom.jar
    67 SET CP=%CP%;%WEBINF%/lib/jaxen-1.1-beta-7.jar
    68 SET CP=%CP%;%WEBINF%/lib/saxpath.jar
    69 SET CP=%CP%;%WEBINF%/lib/xerces-2.6.2.jar
    70 SET CP=%CP%;%WEBINF%/lib/xml-apis.jar
    71 
    72 REM Java Advanced Imaging
    73 SET CP=%CP%;%WEBINF%/lib/jai_codec.jar
    74 SET CP=%CP%;%WEBINF%/lib/jai_core.jar
    75 SET CP=%CP%;%WEBINF%/lib/mlibwrapper_jai.jar
    76 
    77 REM Java Math Expression Parser
    78 SET CP=%CP%;%WEBINF%/lib/jep-2.3.0.jar
    79 
    80 REM JFreeChart
    81 SET CP=%CP%:%WEBINF%/lib/jfreechart-1.0.0.jar
    82 SET CP=%CP%:%WEBINF%/lib/jcommon-1.0.0.jar
     25REM Set classpath
     26call set_classpath.bat
    8327
    8428REM Execute install class
    85 java -server -cp %CP% net.sf.basedb.install.InitDB %1 %2 %3 %4 %5 %6 %7 %8 %9
     29java -server -cp %CP% net.sf.basedb.install.InitDB install %1 %2 %3 %4 %5 %6 %7 %8 %9
  • trunk/src/install/initdb.sh

    r1974 r2209  
    2929
    3030# Execute install class
    31 java -server -cp $CP net.sf.basedb.install.InitDB $*
     31java -server -cp $CP net.sf.basedb.install.InitDB install $*
  • trunk/src/install/net/sf/basedb/install/InitDB.java

    r2142 r2209  
    2525package net.sf.basedb.install;
    2626
     27import net.sf.basedb.core.Application;
     28import net.sf.basedb.core.HibernateUtil;
    2729import net.sf.basedb.core.Install;
    2830import net.sf.basedb.core.Update;
     
    4446  public static void main(String[] args)
    4547  {
    46     if (args.length != 1 && args.length != 2)
    47     {
    48       showUsage();
    49       return;
    50     }
    51     String rootPassword = args.length == 2 ? args[1] : args[0];
    52     String rootLogin = "root";
    53     boolean update = args.length == 2 && "update".equals(args[0]);
     48    String cmd = args[0];
     49   
    5450    try
    5551    {
    56       ChainedProgressReporter progress = new ChainedProgressReporter(new ConsoleProgressReporter());
    57       progress.setRange(0, 30);
    58       Install.createTables(update, progress);
    59       progress.setRange(35, 70);
    60       Install.initDatabase(update, progress, rootLogin, rootPassword);
    61       progress.setRange(75, 90);
    62       Update.updateDatabase(progress, rootLogin, rootPassword);
    63       progress.setRange(95, 100);
    64       progress.display(0, "Installing web application...");
    65       Webclient.install("root", rootPassword, "", "");
    66       progress.display(100, "Web application installed successfully.\n");
     52      if ("install".equals(cmd) || "update".equals(cmd))
     53      {
     54        if (args.length != 2)
     55        {
     56          showUsage(cmd);
     57          return;
     58        }
     59        String rootPassword = args[1];
     60        String rootLogin = "root";
     61       
     62        boolean update = "update".equals(cmd);
     63        ChainedProgressReporter progress = new ChainedProgressReporter(new ConsoleProgressReporter());
     64        progress.setRange(0, 30);
     65        Install.createTables(update, progress);
     66        progress.setRange(35, 70);
     67        Install.initDatabase(update, progress, rootLogin, rootPassword);
     68        progress.setRange(75, 90);
     69        Update.updateDatabase(progress, rootLogin, rootPassword);
     70        progress.setRange(95, 100);
     71        progress.display(0, "Installing web application...");
     72        Webclient.install("root", rootPassword, "", "");
     73        progress.display(100, "Web application installed successfully.\n");
     74      }
     75      else if ("info".equals(cmd))
     76      {
     77        Application.start();
     78        HibernateUtil.dbIndexes(true, false, false, false);
     79        Application.stop();
     80      }
     81      else if ("updateindexes".equals(cmd))
     82      {
     83        boolean verbose = args.length >= 2 ? args[1].equals("-v") : false;
     84        Application.start();
     85        HibernateUtil.dbIndexes(verbose, false, false, true);
     86        Application.stop();
     87      }
     88      else if ("dropindexes".equals(cmd))
     89      {
     90        boolean verbose = args.length >= 2 ? args[1].equals("-v") : false;
     91        Application.start();
     92        HibernateUtil.dbIndexes(verbose, false, true, false);
     93        Application.stop();
     94      }
     95      else
     96      {
     97        System.out.println("Unknown command: " + cmd);
     98        System.out.println("Usage: InitDB cmd");
     99        System.out.println("       cmd: install | update | info | updateindexes | dropindexes");
     100      }
    67101    }
    68102    catch (Throwable t)
     
    73107  }
    74108
    75   private static void showUsage()
     109  private static void showUsage(String cmd)
    76110  {
    77     System.out.println("Usage: initdb <root password>");
    78     System.out.println("       root password: The password to give to the root user account");
     111    if ("install".equals(cmd) || "update".equals(cmd))
     112    {
     113      String script = "install".equals(cmd) ? "initdb.sh" : "updatedb.sh";
     114      System.out.println("Usage: "+script+" <root password>");
     115      System.out.println("       root password: The password to give to the root user account");
     116    }
     117   
    79118  }
    80119
  • trunk/src/install/updatedb.bat

    r1974 r2209  
    22REM $Id: run.bat,v 1.6 2004/10/27 15:39:47 nicklas Exp $
    33REM
    4 REM BioArray Software Environment (BASE) - http://base.thep.lu.se/
    5 REM Copyright (C) 2002-2004 Lao Saal, Carl Troein,
    6 REM Johan Vallon-Christersson, Jari H�kkinen, Nicklas Nordborg
     4REM Copyright (C) 2006 Nicklas Nordborg
    75REM
    8 REM This file is part of BASE.
    9 REM
    10 REM BASE is free software; you can redistribute it and/or
    11 REM modify it under the terms of the GNU General Public License
    12 REM as published by the Free Software Foundation; either version 2
    13 REM of the License, or (at your option) any later version.
    14 REM
    15 REM BASE is distributed in the hope that it will be useful,
    16 REM but WITHOUT ANY WARRANTY; without even the implied warranty of
    17 REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    18 REM GNU General Public License for more details.
     6REM This file is part of BASE - BioArray Software Environment.
     7REM Available at http://base.thep.lu.se/
     8REM
     9REM BASE is free software; you can redistribute it and/or modify it
     10REM under the terms of the GNU General Public License as published by
     11REM the Free Software Foundation; either version 2 of the License, or
     12REM (at your option) any later version.
     13REM
     14REM BASE is distributed in the hope that it will be useful, but
     15REM WITHOUT ANY WARRANTY; without even the implied warranty of
     16REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     17REM General Public License for more details.
    1918REM
    2019REM You should have received a copy of the GNU General Public License
    2120REM along with this program; if not, write to the Free Software
    22 REM Foundation, Inc., 59 Temple Place - Suite 330,
    23 REM Boston, MA  02111-1307, USA.
     21REM Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
     22REM 02111-1307, USA.
    2423REM ----------------------------------------
    2524
    26 
    27 REM Set up the classpath
    28 SET WEBINF=../www/WEB-INF
    29 SET CP=.
    30 
    31 REM Base2 configuration
    32 SET CP=%CP%;%WEBINF%/classes
    33 
    34 REM Base2 core & installation
    35 SET CP=%CP%;BASE2Install.jar
    36 SET CP=%CP%;%WEBINF%/lib/BASE2Core.jar
    37 SET CP=%CP%;%WEBINF%/lib/BASE2Webclient.jar
    38 
    39 REM Hibernate
    40 SET CP=%CP%;%WEBINF%/lib/hibernate3.jar
    41 SET CP=%CP%;%WEBINF%/lib/cglib-2.1.3.jar
    42 SET CP=%CP%;%WEBINF%/lib/asm.jar
    43 SET CP=%CP%;%WEBINF%/lib/commons-collections-2.1.1.jar
    44 SET CP=%CP%;%WEBINF%/lib/commons-logging-1.0.4.jar
    45 SET CP=%CP%;%WEBINF%/lib/dom4j-1.6.1.jar
    46 SET CP=%CP%;%WEBINF%/lib/ehcache-1.1.jar
    47 SET CP=%CP%;%WEBINF%/lib/jta.jar
    48 SET CP=%CP%;%WEBINF%/lib/antlr-2.7.6rc1.jar
    49 
    50 REM Log4j (also used by Hibernate)
    51 SET CP=%CP%;%WEBINF%/lib/log4j-1.2.11.jar
    52 
    53 REM C3P0 Connection pool manager
    54 SET CP=%CP%;%WEBINF%/lib/c3p0-0.9.0.jar
    55 
    56 REM MySQL JDBC driver
    57 SET CP=%CP%;%WEBINF%/lib/mysql-connector-java-3.1.12-bin.jar
    58 
    59 REM Postgres JDBC driver
    60 SET CP=%CP%;%WEBINF%/lib/postgresql-8.0-313.jdbc3.jar
    61 
    62 REM Oracle JDBC driver (experimental)
    63 SET CP=%CP%;%WEBINF%/lib/ojdbc14.jar
    64 
    65 REM JDOM and Xerces XML parser
    66 SET CP=%CP%;%WEBINF%/lib/jdom.jar
    67 SET CP=%CP%;%WEBINF%/lib/jaxen-1.1-beta-7.jar
    68 SET CP=%CP%;%WEBINF%/lib/saxpath.jar
    69 SET CP=%CP%;%WEBINF%/lib/xerces-2.6.2.jar
    70 SET CP=%CP%;%WEBINF%/lib/xml-apis.jar
    71 
    72 REM Java Advanced Imaging
    73 SET CP=%CP%;%WEBINF%/lib/jai_codec.jar
    74 SET CP=%CP%;%WEBINF%/lib/jai_core.jar
    75 SET CP=%CP%;%WEBINF%/lib/mlibwrapper_jai.jar
    76 
    77 REM Java Math Expression Parser
    78 SET CP=%CP%;%WEBINF%/lib/jep-2.3.0.jar
    79 
    80 REM JFreeChart
    81 SET CP=%CP%:%WEBINF%/lib/jfreechart-1.0.0.jar
    82 SET CP=%CP%:%WEBINF%/lib/jcommon-1.0.0.jar
     25REM Set classpath
     26call set_classpath.bat
    8327
    8428REM Execute install class
  • trunk/src/test/TestAll.java

    r2104 r2209  
    114114    results.put("TestContext", TestContext.test_all());
    115115    results.put("TestDbControl", TestDbControl.test_all());
    116 //    results.put("TestUpdate", TestUpdate.test_all());
    117 //    results.put("TestMisc", TestMisc.test_all());
    118116    results.put("TestNews", TestNews.test_all());
    119117    results.put("TestMessage", TestMessage.test_all());
    120118    results.put("TestXMLUtil", TestXMLUtil.test_all());
    121 //    results.put("TestFilter", TestFilter.test_all());
    122119    results.put("TestParameterType", TestParameterType.test_all());
    123120    results.put("TestJarClassLoader", TestJarClassLoader.test_all());
    124121    results.put("TestJep", TestJep.test_all());
     122    results.put("TestDbInfo", TestDbInfo.test_all());
    125123
    126124    // Plugins, jobs
  • trunk/src/test/TestDbInfo.java

    r2207 r2209  
    3030import net.sf.basedb.core.query.Restriction;
    3131
    32 public class TestDatabase
     32public class TestDbInfo
    3333{
    3434
     
    4444  static boolean test_all()
    4545  {
    46     write("++Testing database");
     46    write("++Testing dbinfo");
    4747
    48     HibernateUtil.showDatabaseInfo();
    49     /*
    50     HibernateUtil.listTables();
    51     HibernateUtil.listSql();
    52     */
     48    try
     49    {
     50      HibernateUtil.dbIndexes(!TestUtil.getSilent(), TestUtil.getSilent(), false, false);
     51    }
     52    catch (Throwable t)
     53    {
     54      t.printStackTrace();
     55      ok = false;
     56    }
    5357
    54     write("++Testing database "+(ok ? "OK" : "Failed")+"\n");
     58    write("++Testing dbinfo "+(ok ? "OK" : "Failed")+"\n");
    5559    return ok;
    5660  }
Note: See TracChangeset for help on using the changeset viewer.