1 /*
2 * PROJECT : DAR Runtime and Tools
3 * COPYRIGHT : Copyright (C) 1999-2004 tim.stephenson@enableit.org
4 * LICENSE : GNU LESSER GENERAL PUBLIC LICENSE
5 * Version 2.1, February 1999
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21 package org.enableit.db.ant;
22
23 import java.io.File;
24 import java.util.Vector;
25
26 import org.apache.log4j.Logger;
27 import org.apache.tools.ant.BuildException;
28 import org.apache.tools.ant.DirectoryScanner;
29 import org.apache.tools.ant.Project;
30 import org.apache.tools.ant.types.FileSet;
31 import org.enableit.db.DataLoader;
32
33
34 /***
35 * A task to invoke the DataLoader class for a FileSet.
36 */
37 public class DataLoaderTask extends AbstractDBTask {
38 /*
39 * Properties
40 */
41
42 /***
43 * The Log4J <code>Logger</code> doing the logging.
44 */
45 protected static Logger logger = Logger.getLogger(DataLoaderTask.class);
46
47 /***
48 * CVS info ABOUT this class and its current version
49 */
50 public static final String ABOUT = "$Id: DataLoaderTask.java,v 1.9 2004/03/19 19:19:48 tim Exp $";
51
52 /***
53 * The fileset.
54 */
55 protected Vector filesets = new Vector();
56
57 /*
58 * Constructors
59 */
60
61 /***
62 * Default Constructor
63 */
64 public DataLoaderTask() {
65 }
66
67 /*
68 * Methods
69 */
70
71 /***
72 * Adds a set of files (nested fileset attribute).
73 */
74 public void addFileset(FileSet set) {
75 filesets.addElement(set);
76 }
77
78 /***
79 * Performs the copy operation.
80 */
81 public void execute()
82 throws BuildException {
83 // Log the entry into the method.
84 logger.info("METHOD_ENTRY: execute");
85
86 try {
87 logger.info("Starting Data Loader ");
88 log("Starting Data Loader ", Project.MSG_INFO);
89 logger.debug("...Driver: " + driver);
90 log("...Driver: " + driver, Project.MSG_VERBOSE);
91 logger.debug("...URL: " + url);
92 log("...URL: " + url, Project.MSG_VERBOSE);
93 logger.debug("...Username: " + userid);
94 log("...Username: " + userid, Project.MSG_VERBOSE);
95 logger.debug("...Password: " + password);
96 log("...Password: " + password, Project.MSG_VERBOSE);
97
98 DataLoader dl = new DataLoader();
99
100 dl.setConnectionProperties(driver, url, userid, password);
101
102 // deal with the filesets
103 for (int i = 0; i < filesets.size(); i++) {
104 FileSet fs = (FileSet) filesets.elementAt(i);
105 DirectoryScanner ds = fs.getDirectoryScanner(project);
106 File fromDir = fs.getDir(project);
107
108 String[] srcFiles = ds.getIncludedFiles();
109
110 logger.warn("No of files found=" + srcFiles.length);
111 log("No of files found=" + srcFiles.length, Project.MSG_INFO);
112
113 for (int j = 0; j < srcFiles.length; j++) {
114 logger.warn("Loading file: " + srcFiles[j]);
115 log("Loading file: " + srcFiles[j], Project.MSG_INFO);
116 dl.setFile(new File(fromDir, srcFiles[j]));
117
118 long start = System.currentTimeMillis();
119
120 try {
121 dl.execute();
122 } catch (org.enableit.db.DBException e) {
123 log("Unable to load data from " + srcFiles[j]
124 + ", message is: " + e.getMessage(),
125 Project.MSG_INFO);
126 } finally {
127 logger.warn("Loading file: " + srcFiles[j]);
128 log("... " + (System.currentTimeMillis() - start)
129 + "(ms)", Project.MSG_INFO);
130 }
131 }
132 }
133 } catch (Exception e) {
134 logger.error(e);
135 throw new BuildException(e.getMessage());
136 }
137
138 logger.info("METHOD_EXIT: execute");
139 }
140 }
This page was automatically generated by Maven