You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2001/08/01 17:26:22 UTC
cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs SQLExec.java
bodewig 01/08/01 08:26:22
Modified: src/main/org/apache/tools/ant/taskdefs SQLExec.java
Log:
Add nested <fileset> to <sql>
Submitted by: Tim Stephenson <ti...@sybase.com>
Revision Changes Path
1.21 +36 -7 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
Index: SQLExec.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/SQLExec.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- SQLExec.java 2001/07/10 14:55:40 1.20
+++ SQLExec.java 2001/08/01 15:26:22 1.21
@@ -71,7 +71,8 @@
* Comments may be created with REM -- or //.
*
* @author <a href="mailto:jeff@custommonkey.org">Jeff Martin</a>
- * @author <A href="gholam@xtra.co.nz">Michael McCallum</A>
+ * @author <A href="mailto:gholam@xtra.co.nz">Michael McCallum</A>
+ * @author <A href="mailto:tim.stephenson@sybase.com">Tim Stephenson</A>
*/
public class SQLExec extends Task {
@@ -90,6 +91,8 @@
private AntClassLoader loader;
+ private Vector filesets = new Vector();
+
/**
* Database connection
*/
@@ -224,12 +227,20 @@
}
/**
+ * Adds a set of files (nested fileset attribute).
+ */
+ public void addFileset(FileSet set) {
+ filesets.addElement(set);
+ }
+
+
+ /**
* Set the sql command to execute
*/
public Transaction createTransaction() {
- Transaction t = new Transaction();
- transactions.addElement(t);
- return t;
+ Transaction t = new Transaction();
+ transactions.addElement(t);
+ return t;
}
/**
@@ -269,6 +280,9 @@
/**
* Set the statement delimiter.
+ *
+ * <p>For example, set this to "go" and delimitertype to "ROW" for
+ * Sybase ASE or MS SQL Server.</p>
*/
public void setDelimiter(String delimiter) {
this.delimiter = delimiter;
@@ -332,11 +346,26 @@
public void execute() throws BuildException {
sqlCommand = sqlCommand.trim();
- if (srcFile == null && sqlCommand.length() == 0) {
+ if (srcFile == null && sqlCommand.length()==0 && filesets.isEmpty()) {
if (transactions.size() == 0) {
- throw new BuildException("Source file, transactions or sql statement must be set!", location);
+ throw new BuildException("Source file or fileset, transactions or sql statement must be set!", location);
}
- } else {
+ } else {
+ // deal with the filesets
+ for (int i=0; i<filesets.size(); i++) {
+ FileSet fs = (FileSet) filesets.elementAt(i);
+ DirectoryScanner ds = fs.getDirectoryScanner(project);
+ File srcDir = fs.getDir(project);
+
+ String[] srcFiles = ds.getIncludedFiles();
+
+ // Make a transaction for each file
+ for ( int j=0 ; j<srcFiles.length ; j++ ) {
+ Transaction t = createTransaction();
+ t.setSrc(new File(srcDir, srcFiles[j]));
+ }
+ }
+
// Make a transaction group for the outer command
Transaction t = createTransaction();
t.setSrc(srcFile);