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: */package org.apache.geronimo.console.databasemanager.wizard;
017:
018: import java.io.Serializable;
019: import java.util.ArrayList;
020: import java.util.List;
021: import org.apache.geronimo.converter.DatabaseConversionStatus;
022: import org.apache.geronimo.converter.AbstractDatabasePool;
023: import org.apache.geronimo.converter.JDBCPool;
024: import org.apache.geronimo.converter.XADatabasePool;
025:
026: /**
027: * Tracks the progress of a database pool import operation.
028: *
029: * @version $Rev: 476061 $ $Date: 2006-11-16 22:36:50 -0800 (Thu, 16 Nov 2006) $
030: */
031: public class ImportStatus implements Serializable {
032: private DatabaseConversionStatus original;
033: private int currentPool = -1;
034: private PoolProgress[] pools;
035:
036: public ImportStatus(DatabaseConversionStatus original) {
037: this .original = original;
038: List list = new ArrayList();
039: for (int i = 0; i < original.getNoTXPools().length; i++) {
040: JDBCPool pool = original.getNoTXPools()[i];
041: list.add(new PoolProgress(pool, PoolProgress.TYPE_NOTX));
042: }
043: for (int i = 0; i < original.getJdbcPools().length; i++) {
044: JDBCPool pool = original.getJdbcPools()[i];
045: list.add(new PoolProgress(pool, PoolProgress.TYPE_LOCAL));
046: }
047: for (int i = 0; i < original.getXaPools().length; i++) {
048: XADatabasePool pool = original.getXaPools()[i];
049: final PoolProgress progress = new PoolProgress(pool,
050: 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
057: .size()]);
058: }
059:
060: public boolean isFinished() {
061: for (int i = 0; i < pools.length; i++) {
062: PoolProgress pool = pools[i];
063: if (!pool.isFinished() && !pool.isSkipped()) {
064: return false;
065: }
066: }
067: return true;
068: }
069:
070: public void setCurrentPoolIndex(int currentPool) {
071: this .currentPool = currentPool;
072: getCurrentPool().setStarted(true);
073: }
074:
075: public DatabaseConversionStatus getOriginal() {
076: return original;
077: }
078:
079: public int getCurrentPoolIndex() {
080: return currentPool;
081: }
082:
083: public PoolProgress getCurrentPool() {
084: return currentPool > -1 ? pools[currentPool] : null;
085: }
086:
087: public PoolProgress[] getPools() {
088: return pools;
089: }
090:
091: public int getPendingCount() {
092: int count = 0;
093: for (int i = 0; i < pools.length; i++) {
094: PoolProgress pool = pools[i];
095: if (!pool.isSkipped() && !pool.isStarted()) {
096: ++count;
097: }
098: }
099: return count;
100: }
101:
102: public int getStartedCount() {
103: int count = 0;
104: for (int i = 0; i < pools.length; i++) {
105: PoolProgress pool = pools[i];
106: if (pool.isStarted() && !pool.isFinished()
107: && !pool.isSkipped()) {
108: ++count;
109: }
110: }
111: return count;
112: }
113:
114: public int getFinishedCount() {
115: int count = 0;
116: for (int i = 0; i < pools.length; i++) {
117: PoolProgress pool = pools[i];
118: if (!pool.isSkipped() && pool.isFinished()) {
119: ++count;
120: }
121: }
122: return count;
123: }
124:
125: public int getSkippedCount() {
126: int count = 0;
127: for (int i = 0; i < pools.length; i++) {
128: PoolProgress pool = pools[i];
129: if (pool.isSkipped()) {
130: ++count;
131: }
132: }
133: return count;
134: }
135:
136: public final static class PoolProgress implements Serializable {
137: public final static String TYPE_NOTX = "NoTX";
138: public final static String TYPE_LOCAL = "JDBC";
139: public final static String TYPE_XA = "XA";
140:
141: private AbstractDatabasePool pool;
142: private boolean started;
143: private boolean finished;
144: private boolean skipped;
145: private String type;
146: private String name; // Once in Geronimo
147: private String configurationName; // Once in Geronimo
148:
149: public PoolProgress(AbstractDatabasePool pool, String type) {
150: this .pool = pool;
151: this .type = type;
152: }
153:
154: public AbstractDatabasePool getPool() {
155: return pool;
156: }
157:
158: public boolean isStarted() {
159: return started;
160: }
161:
162: public void setStarted(boolean started) {
163: this .started = started;
164: }
165:
166: public boolean isFinished() {
167: return finished;
168: }
169:
170: public void setFinished(boolean finished) {
171: this .finished = finished;
172: }
173:
174: public boolean isSkipped() {
175: return skipped;
176: }
177:
178: public void setSkipped(boolean skipped) {
179: this .skipped = skipped;
180: }
181:
182: public String getType() {
183: return type;
184: }
185:
186: public String getName() {
187: return name;
188: }
189:
190: public void setName(String name) {
191: this .name = name;
192: }
193:
194: public String getConfigurationName() {
195: return configurationName;
196: }
197:
198: public void setConfigurationName(String configurationName) {
199: this .configurationName = configurationName;
200: }
201:
202: public String getStatus() {
203: return isSkipped() ? "Ignored"
204: : isFinished() ? "Deployed as " + name
205: : isStarted() ? "Started" : "Pending";
206: }
207: }
208: }
|