KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > backupTool > dbDump > AbstractDbDumper


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.backupTool.dbDump;
17
18 import java.io.InputStream JavaDoc;
19 import java.io.OutputStream JavaDoc;
20
21 import org.outerj.daisy.backupTool.BackupHelper;
22
23 public abstract class AbstractDbDumper implements DbDumper {
24
25     protected String JavaDoc dbName;
26
27     protected String JavaDoc host;
28     
29     protected Integer JavaDoc port;
30
31     protected String JavaDoc password;
32
33     protected String JavaDoc username;
34     
35     public AbstractDbDumper (String JavaDoc dbName, String JavaDoc host, Integer JavaDoc port, String JavaDoc password, String JavaDoc username) {
36         this.dbName = dbName;
37         this.host = host;
38         this.port = port;
39         this.password = password;
40         this.username = username;
41     }
42
43     protected static void handleRuntimeProcess(Process JavaDoc process, InputStream JavaDoc is,
44             OutputStream JavaDoc os) throws Exception JavaDoc {
45         InputStream JavaDoc pris = process.getInputStream();
46         InputStream JavaDoc pres = process.getErrorStream();
47         OutputStream JavaDoc pros = process.getOutputStream();
48         Thread JavaDoc writeToProcess = null;
49         Thread JavaDoc readFromProcess = null;
50         Thread JavaDoc readErrors;
51         try {
52             if (is != null) {
53                 writeToProcess = new Thread JavaDoc(
54                         new BackupHelper.RunnableStreamCopy(is, pros));
55                 writeToProcess.start();
56             }
57             if (os != null) {
58                 readFromProcess = new Thread JavaDoc(
59                         new BackupHelper.RunnableStreamCopy(pris, os));
60                 readFromProcess.start();
61             }
62             readErrors = new Thread JavaDoc(new BackupHelper.RunnableStreamCopy(pres,
63                     System.err));
64             readErrors.start();
65
66             if (writeToProcess != null)
67                 writeToProcess.join();
68             pros.close();
69
70             if (readFromProcess != null)
71                 readFromProcess.join();
72             pris.close();
73
74             readErrors.join();
75             pres.close();
76
77             if (process.waitFor() != 0)
78                 throw new RuntimeException JavaDoc(process + " ran with errors.");
79         } finally {
80             pris.close();
81             pres.close();
82             pros.close();
83         }
84     }
85
86     public String JavaDoc getDbName() {
87         return dbName;
88     }
89
90     public void setDbName(String JavaDoc dbName) {
91         this.dbName = dbName;
92     }
93
94     public String JavaDoc getHost() {
95         return host;
96     }
97
98     public void setHost(String JavaDoc host) {
99         this.host = host;
100     }
101
102     public String JavaDoc getPassword() {
103         return password;
104     }
105
106     public void setPassword(String JavaDoc password) {
107         this.password = password;
108     }
109
110     public String JavaDoc getUsername() {
111         return username;
112     }
113
114     public void setUsername(String JavaDoc username) {
115         this.username = username;
116     }
117
118 }
Popular Tags