KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > backupTool > DbBackupEntry


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;
17
18 import java.io.File JavaDoc;
19
20 import org.outerj.daisy.backupTool.dbDump.DbDumper;
21
22 public class DbBackupEntry extends AbstractBackupEntry {
23     private DbDumper dbDumper;
24     private File JavaDoc tmpFile;
25
26    public DbBackupEntry(File JavaDoc backupFile, DbDumper dbDumper, BackupInstance buInstance) {
27        super(backupFile, buInstance);
28        String JavaDoc fileName = backupFile.getName();
29        fileName = fileName.substring(0, fileName.lastIndexOf(".")+1) + "sql";
30        tmpFile = new File JavaDoc(backupFile.getParentFile(), fileName );
31        this.dbDumper = dbDumper;
32    }
33
34     public void backupInit() throws Exception JavaDoc {
35         this.backupFile.createNewFile();
36         tmpFile.createNewFile();
37     }
38     
39     public void backup() throws Exception JavaDoc {
40         dbDumper.dump(tmpFile);
41     }
42
43     protected File JavaDoc getTempPath() {
44         return tmpFile;
45     }
46
47     public void restore() throws Exception JavaDoc {
48         tmpFile.createNewFile();
49         BackupHelper.unzipToFile(backupFile, tmpFile);
50         dbDumper.restore(tmpFile);
51         BackupHelper.deleteFile(tmpFile);
52     }
53
54     protected boolean isNothing() {
55         return false;
56     }
57 }
58
Popular Tags