001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.geronimo.console.databasemanager.wizard; 018 019 import java.io.Serializable; 020 import java.util.ArrayList; 021 import java.util.List; 022 import org.apache.geronimo.converter.DatabaseConversionStatus; 023 import org.apache.geronimo.converter.AbstractDatabasePool; 024 import org.apache.geronimo.converter.JDBCPool; 025 import org.apache.geronimo.converter.XADatabasePool; 026 027 /** 028 * Tracks the progress of a database pool import operation. 029 * 030 * @version $Rev: 476061 $ $Date: 2006-11-17 01:36:50 -0500 (Fri, 17 Nov 2006) $ 031 */ 032 public class ImportStatus implements Serializable { 033 private DatabaseConversionStatus original; 034 private int currentPool = -1; 035 private PoolProgress[] pools; 036 037 public ImportStatus(DatabaseConversionStatus original) { 038 this.original = original; 039 List list = new ArrayList(); 040 for (int i = 0; i < original.getNoTXPools().length; i++) { 041 JDBCPool pool = original.getNoTXPools()[i]; 042 list.add(new PoolProgress(pool, PoolProgress.TYPE_NOTX)); 043 } 044 for (int i = 0; i < original.getJdbcPools().length; i++) { 045 JDBCPool pool = original.getJdbcPools()[i]; 046 list.add(new PoolProgress(pool, PoolProgress.TYPE_LOCAL)); 047 } 048 for (int i = 0; i < original.getXaPools().length; i++) { 049 XADatabasePool pool = original.getXaPools()[i]; 050 final PoolProgress progress = new PoolProgress(pool, PoolProgress.TYPE_XA); 051 if(pool.getXaDataSourceClass().indexOf("apache.derby") < 0) { 052 progress.setSkipped(true); 053 } 054 list.add(progress); 055 } 056 pools = (PoolProgress[]) list.toArray(new PoolProgress[list.size()]); 057 } 058 059 public boolean isFinished() { 060 for (int i = 0; i < pools.length; i++) { 061 PoolProgress pool = pools[i]; 062 if(!pool.isFinished() && !pool.isSkipped()) { 063 return false; 064 } 065 } 066 return true; 067 } 068 069 public void setCurrentPoolIndex(int currentPool) { 070 this.currentPool = currentPool; 071 getCurrentPool().setStarted(true); 072 } 073 074 public DatabaseConversionStatus getOriginal() { 075 return original; 076 } 077 078 public int getCurrentPoolIndex() { 079 return currentPool; 080 } 081 082 public PoolProgress getCurrentPool() { 083 return currentPool > -1 ? pools[currentPool] : null; 084 } 085 086 public PoolProgress[] getPools() { 087 return pools; 088 } 089 090 public int getPendingCount() { 091 int count = 0; 092 for (int i = 0; i < pools.length; i++) { 093 PoolProgress pool = pools[i]; 094 if(!pool.isSkipped() && !pool.isStarted()) { 095 ++count; 096 } 097 } 098 return count; 099 } 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 }