View Javadoc
1 /*** 2 * Redistribution and use of this software and associated documentation 3 * ("Software"), with or without modification, are permitted provided 4 * that the following conditions are met: 5 * 6 * 1. Redistributions of source code must retain copyright 7 * statements and notices. Redistributions must also contain a 8 * copy of this document. 9 * 10 * 2. Redistributions in binary form must reproduce the 11 * above copyright notice, this list of conditions and the 12 * following disclaimer in the documentation and/or other 13 * materials provided with the distribution. 14 * 15 * 3. The name "Exolab" must not be used to endorse or promote 16 * products derived from this Software without prior written 17 * permission of Exoffice Technologies. For written permission, 18 * please contact info@exolab.org. 19 * 20 * 4. Products derived from this Software may not be called "Exolab" 21 * nor may "Exolab" appear in their names without prior written 22 * permission of Exoffice Technologies. Exolab is a registered 23 * trademark of Exoffice Technologies. 24 * 25 * 5. Due credit should be given to the Exolab Project 26 * (http://www.exolab.org/). 27 * 28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS 29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 39 * OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * Copyright 2002 (C) Exoffice Technologies Inc. All Rights Reserved. 42 * 43 * $Id: Importer.java,v 1.4 2001/11/20 20:56:28 tima Exp $ 44 */ 45 46 package org.exolab.jms.tools.migration; 47 48 import java.io.IOException; 49 import java.sql.Connection; 50 import java.sql.SQLException; 51 52 import org.apache.commons.logging.Log; 53 import org.apache.commons.logging.LogFactory; 54 import org.apache.log4j.xml.DOMConfigurator; 55 56 import org.exolab.jms.config.Configuration; 57 import org.exolab.jms.config.ConfigurationFileException; 58 import org.exolab.jms.config.ConfigurationManager; 59 import org.exolab.jms.config.FileDoesNotExistException; 60 import org.exolab.jms.config.RdbmsDatabaseConfiguration; 61 import org.exolab.jms.persistence.DatabaseService; 62 import org.exolab.jms.persistence.PersistenceException; 63 import org.exolab.jms.util.CommandLine; 64 65 66 public class Importer { 67 68 private Connection _connection = null; 69 70 /*** 71 * The logger 72 */ 73 private static final Log _log = LogFactory.getLog(Importer.class); 74 75 76 public Importer(String path) throws IOException, PersistenceException { 77 78 if (path == null) { 79 throw new IllegalArgumentException("Argument 'path' is null"); 80 } 81 82 Configuration config = ConfigurationManager.getConfig(); 83 RdbmsDatabaseConfiguration rdbms = 84 config.getDatabaseConfiguration().getRdbmsDatabaseConfiguration(); 85 if (rdbms == null) { 86 throw new IOException("OpenJMS is not configured to use JDBC"); 87 } 88 89 _connection = DatabaseService.getConnection(); 90 91 } 92 93 public void apply() throws IOException { 94 // apply(new DestinationExporter(_input), 95 // new DestinationImporter(_connection)); 96 97 // apply(new MessageExporter(_input), 98 // new MessageImporter(_connection)); 99 100 // apply(new ConsumerExporter(_input), 101 // new ConsumerImporter(_connection)); 102 103 try { 104 _connection.close(); 105 } catch (SQLException exception) { 106 throw new IOException(exception.getMessage()); 107 } 108 } 109 110 // private void apply(Export source, Import target) throws IOException { 111 // Iterator iterator = source.exportCollection(); 112 // target.importCollection(iterator); 113 // } 114 115 public static void main(String[] args) { 116 CommandLine commands = new CommandLine(args); 117 118 String config = commands.value("config"); 119 String input = commands.value("import"); 120 if (config == null || input == null) { 121 usage(); 122 System.exit(1); 123 } else { 124 try { 125 init(config); 126 127 Importer importer = new Importer(input); 128 importer.apply(); 129 } catch (Exception exception) { 130 _log.error("Failed to import data", exception); 131 System.exit(1); 132 } 133 } 134 } 135 136 private static void init(String path) 137 throws ConfigurationFileException, FileDoesNotExistException, 138 PersistenceException { 139 140 // initialise the system-wide configuration 141 ConfigurationManager.setConfig(path); 142 Configuration config = ConfigurationManager.getConfig(); 143 144 // initialise log4j 145 DOMConfigurator.configure(config.getLoggerConfiguration().getFile()); 146 147 // initialise the database. 148 // NOTE: DatabaseService.start() is not invoked, as it can 149 // remove expired messages. 150 DatabaseService.instance(); 151 } 152 153 /*** 154 * Displays usage information for this tool when invoked from the 155 * command line 156 */ 157 private static void usage() { 158 System.err.println( 159 "usage: " + Importer.class.getName() + " <arguments> [options]\n" + 160 "arguments:\n" + 161 " -config <path> specifies the path to an OpenJMS " + 162 "configuration file\n" + 163 " -import <path> specifies the path to import data from\n"); 164 } 165 166 } //-- Importer

This page was automatically generated by Maven