Since we have fysically moved our database, our development machines
experience much long startup times for mmbase, around the order of 3min.
I did some investigation and found a nice little speedup which will reduce 
starting mmbase with 30 seconds. Not really groundbreaking but it helps!

mmbase/src/org/mmbase/storage/implementation/database/DatabaseStorageManager.java

this is the original code which gets called for each builder:

protected synchronized boolean exists(String tableName) 
  throws StorageException {
    try {
        getActiveConnection();
        DatabaseMetaData metaData = activeConnection.getMetaData();
        ResultSet res = metaData.getTables(null, null, tableName, null);
        try {
          boolean result = res.next();
          return result;
        } finally {
          res.close();
        }
    } catch (Exception e) {
        throw new StorageException(e.getMessage());
    } finally {
        releaseActiveConnection();
    }
}

I did some digging and found our that the jdbc-spec says that wildcards ('%') 
can be used to find out which tables are in the database. Well, you know where 
this will lead to, so this is the proposed code:
 
  static Set cache = null;

  protected synchronized boolean exists(String tableName) 
    throws StorageException {
    // cache
    if(cache == null) {
      try {
        cache = new HashSet();
        getActiveConnection();
        DatabaseMetaData metaData = activeConnection.getMetaData();
        ResultSet res = 
          metaData.getTables(null, null, 
factory.getMMBase().getBaseName()+"_%", null);
          try {
            while(res.next())
              cache.add(res.getString(3));
            } finally {
              res.close();
            }
          } catch(Exception e) {
            throw new StorageException(e.getMessage());
          } finally {
             releaseActiveConnection();
          }
        }
        return cache.contains(tableName);
    }

I post this because I dont know if the original maintainer didn't use this 
feature 
with a reason. 
_______________________________________________
Developers mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/developers

Reply via email to