KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > jdbc > DBUpgradeOp


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.jdbc;
21
22 import java.io.File JavaDoc;
23
24 import com.sslexplorer.boot.VersionInfo;
25
26 /**
27  * Represents a single SQL file to use to update a database to a specific
28  * version.
29  *
30  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
31  */

32 public class DBUpgradeOp implements Comparable JavaDoc {
33     private File JavaDoc file;
34     private VersionInfo.Version version;
35     private String JavaDoc name;
36     
37     DBUpgradeOp(File JavaDoc file) throws IllegalArgumentException JavaDoc {
38         this.file = file;
39         String JavaDoc n = file.getName();
40         int idx = n.indexOf('-');
41         if (idx == -1) {
42           throw new IllegalArgumentException JavaDoc("File name not in correct format.");
43         }
44         String JavaDoc ver = n.substring(0, idx);
45         version = new VersionInfo.Version(ver.replace('_', '.'));
46         name = n.substring(idx + 1);
47         if(!name.toLowerCase().endsWith(".sql")) {
48             throw new IllegalArgumentException JavaDoc("File name not in correct format.");
49         }
50         name = name.substring(0, name.length() - 3);
51     }
52     
53     /**
54      * Get the file to use for this upgrade
55      *
56      * @return upgrade file
57      */

58     public File JavaDoc getFile() {
59         return file;
60     }
61     
62     /**
63      * Get the version that this upgrade will take the database schema to
64      *
65      * @return version
66      */

67     public VersionInfo.Version getVersion() {
68         return version;
69     }
70     
71     /**
72      * Get the database name to upgrade
73      *
74      * @return database name to upgrade
75      */

76     public String JavaDoc getName() {
77         return name;
78     }
79     
80     /**
81      * Compare two upgrade operations based on the name and version.
82      *
83      * @param o other version
84      * @return comparison
85      */

86     public int compareTo(Object JavaDoc o) {
87         int i = getName().compareTo(((DBUpgradeOp)o).getName());
88         return i == 0 ? getVersion().compareTo((((DBUpgradeOp)o).getVersion())) : i;
89     }
90     
91 }
Popular Tags