KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > controller > backup > AbstractPostgreSQLBackuper


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2005 Emic Networks
4  * Contact: c-jdbc@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2.1 of the License, or any later
9  * version.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19  *
20  * Initial developer(s): Emmanuel Cecchet.
21  * Contributor(s): Dylan Hansen.
22  */

23
24 package org.objectweb.cjdbc.controller.backup;
25
26 import java.io.File JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.StringTokenizer JavaDoc;
29
30 import org.objectweb.cjdbc.common.exceptions.BackupException;
31 import org.objectweb.cjdbc.common.log.Trace;
32
33 /**
34  * This abstract class provides base methods for PostgreSQL backupers.
35  *
36  * @author <a HREF="mailto:dhansen@h2st.com">Dylan Hansen</a>
37  * @version 1.1
38  */

39 public abstract class AbstractPostgreSQLBackuper implements Backuper
40 {
41   // Logger
42
static Trace logger = Trace.getLogger(AbstractPostgreSQLBackuper.class
43                                     .getName());
44
45   // HashMap containing options passed to Backuper
46
protected HashMap JavaDoc optionsMap = new HashMap JavaDoc();
47
48   // String representation of the options
49
protected String JavaDoc optionsString = null;
50
51   /**
52    * Creates a new <code>AbstractPostgreSQLBackuper</code> object
53    *
54    * @author Dylan Hansen
55    */

56   public AbstractPostgreSQLBackuper()
57   {
58   }
59
60   /**
61    * @see org.objectweb.cjdbc.controller.backup.Backuper#getOptions()
62    * @author Dylan Hansen
63    */

64   public String JavaDoc getOptions()
65   {
66     return optionsString;
67   }
68   
69   /**
70    * @see org.objectweb.cjdbc.controller.backup.Backuper#setOptions(java.lang.String)
71    * @author Dylan Hansen
72    */

73   public void setOptions(String JavaDoc options)
74   {
75     if (options != null)
76     {
77       StringTokenizer JavaDoc strTok = new StringTokenizer JavaDoc(options, ",");
78       String JavaDoc option = null;
79       String JavaDoc name = null;
80       String JavaDoc value = null;
81
82       // Parse the string of options, add them to the HashMap
83
while (strTok.hasMoreTokens())
84       {
85         option = strTok.nextToken();
86         name = option.substring(0, option.indexOf("="));
87         value = option.substring(option.indexOf("=") + 1, option.length());
88         optionsMap.put(name, value);
89       }
90  
91       optionsString = options;
92     }
93   }
94
95   /**
96    * @see org.objectweb.cjdbc.controller.backup.Backuper#deleteDump(java.lang.String,
97    * java.lang.String)
98    */

99   public void deleteDump(String JavaDoc path, String JavaDoc dumpName) throws BackupException
100   {
101     File JavaDoc toRemove = new File JavaDoc(getDumpPhysicalPath(path, dumpName));
102     if (logger.isDebugEnabled())
103       logger.debug("Deleting compressed dump " + toRemove);
104     toRemove.delete();
105   }
106
107   /**
108    * Get the dump physical path from its logical name
109    *
110    * @param path the path where the dump is stored
111    * @param dumpName dump logical name
112    * @return path to dump file
113    */

114   protected String JavaDoc getDumpPhysicalPath(String JavaDoc path, String JavaDoc dumpName)
115   {
116     String JavaDoc fullPath = null;
117
118     if (path.endsWith(File.separator))
119       fullPath = path + dumpName;
120     else
121       fullPath = path + File.separator + dumpName;
122
123     return fullPath;
124   }
125
126   /**
127    * Get the host of a given PostgreSQL connection string
128    *
129    * @param url The full PostgreSQL URL
130    * @return Host of the URL
131    * @author Dylan Hansen
132    */

133   protected String JavaDoc getHostFromURL(String JavaDoc url)
134   {
135     // Strip 'jdbc:postgresql://'
136
// 18 = "jdbc:postgresql://".length()
137
return url.substring(18, url.lastIndexOf(":"));
138   }
139
140   /**
141    * Get the port of a given PostgreSQL connection string
142    *
143    * @param url The full PostgreSQL URL
144    * @return Port of the URL
145    * @author Dylan Hansen
146    */

147   protected String JavaDoc getPortFromURL(String JavaDoc url)
148   {
149     // Get port number after the last ":" but before the last "/"
150
return url.substring(url.lastIndexOf(":") + 1, url.lastIndexOf("/"));
151   }
152
153   /**
154    * Get the database name of a given PostgreSQL connection string
155    *
156    * @param url The full PostgreSQL URL
157    * @return Name of the database
158    * @author Dylan Hansen
159    */

160   protected String JavaDoc getDatabaseNameFromURL(String JavaDoc url)
161   {
162     String JavaDoc dbName = null;
163
164     // If the url has parameters, there will be a "?"
165
if (url.indexOf("?") > -1)
166       // There are parameters, ignore them
167
dbName = url.substring(url.lastIndexOf("/") + 1, url.lastIndexOf("?"));
168     else
169       dbName = url.substring(url.lastIndexOf("/") + 1, url.length());
170
171     return dbName;
172   }
173
174   /**
175    * @see org.objectweb.cjdbc.controller.backup.Backuper#fetchDump(org.objectweb.cjdbc.controller.backup.DumpTransferInfo,
176    * java.lang.String, java.lang.String)
177    */

178   public void fetchDump(DumpTransferInfo dumpTransferInfo, String JavaDoc path,
179       String JavaDoc dumpName) throws BackupException
180   {
181     // TODO: Auto-generated method stub
182
// getBackupManager().fetchDump(this, backuperServerAddress, sessionKey,
183
// path, dumpName);
184
}
185
186   /**
187    * @see org.objectweb.cjdbc.controller.backup.Backuper#setupServer()
188    */

189   public DumpTransferInfo setupServer()
190   {
191     // TODO Auto-generated method stub
192
return null;
193   }
194
195   /**
196    * @see org.objectweb.cjdbc.controller.backup.Backuper#getBackupManager()
197    */

198   public BackupManager getBackupManager()
199   {
200     // TODO: Auto-generated method stub
201
return null;
202     // return BackupManager.TheOneAndOnlyBackupManager;
203
}
204 }
205
Popular Tags