Home » geronimo-2.2-source-release » org.apache.geronimo.console.databasemanager.wizard » [javadoc | source]

    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   package org.apache.geronimo.console.databasemanager.wizard;
   18   
   19   import java.io.Serializable;
   20   import java.util.ArrayList;
   21   import java.util.List;
   22   import org.apache.geronimo.converter.DatabaseConversionStatus;
   23   import org.apache.geronimo.converter.AbstractDatabasePool;
   24   import org.apache.geronimo.converter.JDBCPool;
   25   import org.apache.geronimo.converter.XADatabasePool;
   26   
   27   /**
   28    * Tracks the progress of a database pool import operation.
   29    *
   30    * @version $Rev: 476061 $ $Date: 2006-11-16 22:36:50 -0800 (Thu, 16 Nov 2006) $
   31    */
   32   public class ImportStatus implements Serializable {
   33       private DatabaseConversionStatus original;
   34       private int currentPool = -1;
   35       private PoolProgress[] pools;
   36   
   37       public ImportStatus(DatabaseConversionStatus original) {
   38           this.original = original;
   39           List list = new ArrayList();
   40           for (int i = 0; i < original.getNoTXPools().length; i++) {
   41               JDBCPool pool = original.getNoTXPools()[i];
   42               list.add(new PoolProgress(pool, PoolProgress.TYPE_NOTX));
   43           }
   44           for (int i = 0; i < original.getJdbcPools().length; i++) {
   45               JDBCPool pool = original.getJdbcPools()[i];
   46               list.add(new PoolProgress(pool, PoolProgress.TYPE_LOCAL));
   47           }
   48           for (int i = 0; i < original.getXaPools().length; i++) {
   49               XADatabasePool pool = original.getXaPools()[i];
   50               final PoolProgress progress = new PoolProgress(pool, PoolProgress.TYPE_XA);
   51               if(pool.getXaDataSourceClass().indexOf("apache.derby") < 0) {
   52                   progress.setSkipped(true);
   53               }
   54               list.add(progress);
   55           }
   56           pools = (PoolProgress[]) list.toArray(new PoolProgress[list.size()]);
   57       }
   58   
   59       public boolean isFinished() {
   60           for (int i = 0; i < pools.length; i++) {
   61               PoolProgress pool = pools[i];
   62               if(!pool.isFinished() && !pool.isSkipped()) {
   63                   return false;
   64               }
   65           }
   66           return true;
   67       }
   68   
   69       public void setCurrentPoolIndex(int currentPool) {
   70           this.currentPool = currentPool;
   71           getCurrentPool().setStarted(true);
   72       }
   73   
   74       public DatabaseConversionStatus getOriginal() {
   75           return original;
   76       }
   77   
   78       public int getCurrentPoolIndex() {
   79           return currentPool;
   80       }
   81   
   82       public PoolProgress getCurrentPool() {
   83           return currentPool > -1 ? pools[currentPool] : null;
   84       }
   85   
   86       public PoolProgress[] getPools() {
   87           return pools;
   88       }
   89   
   90       public int getPendingCount() {
   91           int count = 0;
   92           for (int i = 0; i < pools.length; i++) {
   93               PoolProgress pool = pools[i];
   94               if(!pool.isSkipped() && !pool.isStarted()) {
   95                   ++count;
   96               }
   97           }
   98           return count;
   99       }
  100   
  101       public int getStartedCount() {
  102           int count = 0;
  103           for (int i = 0; i < pools.length; i++) {
  104               PoolProgress pool = pools[i];
  105               if(pool.isStarted() && !pool.isFinished() && !pool.isSkipped()) {
  106                   ++count;
  107               }
  108           }
  109           return count;
  110       }
  111   
  112       public int getFinishedCount() {
  113           int count = 0;
  114           for (int i = 0; i < pools.length; i++) {
  115               PoolProgress pool = pools[i];
  116               if(!pool.isSkipped() && pool.isFinished()) {
  117                   ++count;
  118               }
  119           }
  120           return count;
  121       }
  122   
  123       public int getSkippedCount() {
  124           int count = 0;
  125           for (int i = 0; i < pools.length; i++) {
  126               PoolProgress pool = pools[i];
  127               if(pool.isSkipped()) {
  128                   ++count;
  129               }
  130           }
  131           return count;
  132       }
  133   
  134       public final static class PoolProgress implements Serializable {
  135           public final static String TYPE_NOTX = "NoTX";
  136           public final static String TYPE_LOCAL = "JDBC";
  137           public final static String TYPE_XA = "XA";
  138   
  139           private AbstractDatabasePool pool;
  140           private boolean started;
  141           private boolean finished;
  142           private boolean skipped;
  143           private String type;
  144           private String name; // Once in Geronimo
  145           private String configurationName; // Once in Geronimo
  146   
  147           public PoolProgress(AbstractDatabasePool pool, String type) {
  148               this.pool = pool;
  149               this.type = type;
  150           }
  151   
  152           public AbstractDatabasePool getPool() {
  153               return pool;
  154           }
  155   
  156           public boolean isStarted() {
  157               return started;
  158           }
  159   
  160           public void setStarted(boolean started) {
  161               this.started = started;
  162           }
  163   
  164           public boolean isFinished() {
  165               return finished;
  166           }
  167   
  168           public void setFinished(boolean finished) {
  169               this.finished = finished;
  170           }
  171   
  172           public boolean isSkipped() {
  173               return skipped;
  174           }
  175   
  176           public void setSkipped(boolean skipped) {
  177               this.skipped = skipped;
  178           }
  179   
  180           public String getType() {
  181               return type;
  182           }
  183   
  184           public String getName() {
  185               return name;
  186           }
  187   
  188           public void setName(String name) {
  189               this.name = name;
  190           }
  191   
  192           public String getConfigurationName() {
  193               return configurationName;
  194           }
  195   
  196           public void setConfigurationName(String configurationName) {
  197               this.configurationName = configurationName;
  198           }
  199   
  200           public String getStatus() {
  201               return isSkipped() ? "Ignored" : isFinished() ? "Deployed as "+name : isStarted() ? "Started" : "Pending";
  202           }
  203       }
  204   }

Home » geronimo-2.2-source-release » org.apache.geronimo.console.databasemanager.wizard » [javadoc | source]