Source Code Cross Referenced for BackupHelper.java in  » Database-Client » dbmjui » fr » aliacom » dbmjui » components » backup » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » dbmjui » fr.aliacom.dbmjui.components.backup 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on May 1, 2003
003:         *
004:         * Dbmjui is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU General Public License version 2 as
006:         * published by the Free Software Foundation.
007:         *  
008:         * Dbmjui is distributed in the hope that it will be useful,
009:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
010:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
011:         * General Public License for more details.
012:         *  
013:         * You should have received a copy of the GNU General Public
014:         * License along with dbmjui; see the file COPYING.  If not,
015:         * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
016:         * Boston, MA 02111-1307, USA.
017:         *
018:         */
019:        package fr.aliacom.dbmjui.components.backup;
020:
021:        import java.text.ParseException;
022:        import java.text.SimpleDateFormat;
023:        import java.util.ArrayList;
024:
025:        import org.apache.log4j.Logger;
026:
027:        import com.sap.dbtech.powertoys.DBM;
028:        import com.sap.dbtech.powertoys.DBMException;
029:        import com.sap.dbtech.rte.comm.RTEException;
030:
031:        import fr.aliacom.dbmjui.BackupHistory;
032:        import fr.aliacom.dbmjui.DbInstance;
033:        import fr.aliacom.dbmjui.beans.BackupMedium;
034:        import fr.aliacom.dbmjui.driver.IBackupHelper;
035:
036:        /**
037:         * @author tom
038:         *
039:         * (c) 2001, 2003 Thomas Cataldo
040:         */
041:        public class BackupHelper implements  IBackupHelper {
042:
043:            private SimpleDateFormat formatter;
044:            private Logger log;
045:
046:            public BackupHelper() {
047:                log = Logger.getLogger(BackupHelper.class);
048:                formatter = new SimpleDateFormat("yyyyMMddhhmmss");
049:            }
050:
051:            public ArrayList getMediumList(DbInstance dbi, int mediumType)
052:                    throws RTEException, DBMException {
053:                DBM dbm = dbi.getDbmConnection();
054:                String mediumList;
055:                try {
056:                    mediumList = dbm.cmd("medium_getall");
057:                } finally {
058:                    dbm.release();
059:                }
060:                return parseMediumList(mediumList, mediumType);
061:            }
062:
063:            /**
064:             * Creates a list of {@link BackupMedium} using the
065:             * output a the <code>medium_getall</code> dbm command
066:             * 
067:             * @param mediumList the output of <code>medium_getall</code> 
068:             * @return a list of {@link BackupMedium}
069:             */
070:            protected ArrayList parseMediumList(String mediumList,
071:                    int backupType) {
072:                ArrayList ret = new ArrayList();
073:                String lines[] = mediumList.split("\n");
074:                for (int i = 0; i < lines.length; i++) {
075:                    BackupMedium medium = parseLine(lines[i]);
076:                    if ((backupType & medium.getBackupType()) == medium
077:                            .getBackupType()) {
078:                        ret.add(medium);
079:                    }
080:                }
081:                return ret;
082:            }
083:
084:            /**
085:             * @param mediumLine
086:             * @return a backup medium
087:             */
088:            protected BackupMedium parseLine(String mediumLine) {
089:                String[] line = mediumLine.split("\t");
090:                BackupMedium bm = new BackupMedium();
091:                bm.setName(line[0]);
092:                bm.setLocation(line[1]);
093:                try {
094:                    bm.setDate(formatter.parse(line[9]));
095:                } catch (ParseException pe) {
096:                    pe.printStackTrace();
097:                }
098:
099:                // parse medium
100:                bm.setDeviceType(parseMediumType(line[2]));
101:
102:                // parse backup type
103:                bm.setBackupType(parseBackupType(line[3]));
104:
105:                bm.setMediumSize(Integer.parseInt(line[4].trim()));
106:                bm.setBlockSize(Integer.parseInt(line[5].trim()));
107:
108:                bm.setOverwritable(line[6].trim().equals("YES"));
109:                bm.setUseAutoloader(line[7].trim().equals("YES"));
110:                return bm;
111:            }
112:
113:            /**
114:             * @param mType
115:             * @return one of the medium type constants
116:             */
117:            protected int parseMediumType(String mType) {
118:                int mediumType = BackupMedium.TYPE_UNKNOWN;
119:                if (mType.equals("TAPE")) {
120:                    mediumType = BackupMedium.TYPE_TAPE;
121:                } else if (mType.equals("FILE")) {
122:                    mediumType = BackupMedium.TYPE_FILE;
123:                } else if (mType.equals("PIPE")) {
124:                    mediumType = BackupMedium.TYPE_PIPE;
125:                } else if (mType.equals("NO-REWIND")) {
126:                    mediumType = BackupMedium.TYPE_NO_REWIND;
127:                } else if (mType.equals("AUTOLOADER")) {
128:                    mediumType = BackupMedium.TYPE_AUTOLOADER;
129:                }
130:                return mediumType;
131:            }
132:
133:            /**
134:             * @param bType
135:             * @return one of the backup type constants
136:             */
137:            protected int parseBackupType(String bType) {
138:                int backupType = BackupMedium.BACKUP_TYPE_UNKNOWN;
139:                if (bType.equals("DATA")) {
140:                    backupType = BackupMedium.BACKUP_TYPE_DATA;
141:                } else if (bType.equals("PAGES")) {
142:                    backupType = BackupMedium.BACKUP_TYPE_PAGES;
143:                } else if (bType.equals("LOG")) {
144:                    backupType = BackupMedium.BACKUP_TYPE_LOG;
145:                } else if (bType.equals("AUTO")) {
146:                    backupType = BackupMedium.BACKUP_TYPE_AUTO;
147:                }
148:                return backupType;
149:            }
150:
151:            /**
152:             * Method getBackupHistory.
153:             * Will force a backup history reload.
154:             * @return BackupHistory
155:             */
156:            public BackupHistory getBackupHistory(DbInstance dbi) {
157:                BackupHistory history = new BackupHistory();
158:                try {
159:                    final String cmd = "backup_history_list -c " + "KEY,"
160:                            + "LABEL," + "ACTION," + "STAMP1," + "STAMP2,"
161:                            + "START," + "STOP," + "FIRSTLOG," + "LASTLOG,"
162:                            + "LOG," + "MEDIA," + "PAGES," + "VOLUMES," + "RC,"
163:                            + "ERROR";
164:                    log.debug(cmd);
165:                    DBM dbm = dbi.getPlainDbmConnection();
166:                    String ret = dbm.cmd(cmd);
167:                    dbm.release();
168:                    String[] backups = ret.split("\n");
169:                    for (int i = backups.length - 1; i > 0; i--) {
170:                        history.addBackup(backups[i]);
171:                    }
172:                } catch (Exception e) {
173:                    // ignore errors in history creation
174:                    // no history throws an exception
175:                    // I should create a BackupHistoryException for proper handling in log backup
176:                }
177:                return history;
178:            }
179:
180:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.