ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chun Ji" <...@pro-unlimited.com>
Subject RE: SQL task and resource collections ...
Date Wed, 27 Feb 2008 00:05:34 GMT

How about you create a new sql file that calls the rest of your Sqls , and just here is your
simple ant target: 
 <sql
    driver="org.database.jdbcDriver"
    url="jdbc:database-url"
    userid="sa"
    password="pass"
    src="xxx.sql"/>

That is how my code works. 


-c 


-----Original Message-----
From: John Shott [mailto:shott@stanford.edu]
Sent: Tuesday, February 26, 2008 1:32 PM
To: Ant Users List
Subject: Re: SQL task and resource collections ...


Steve:

Thanks for your informative response and your suspicion that I may have 
a problem with the size() of my fileset.

Since I can't seem to find a simple method of trying to test the size of 
my fileset, in advance of my call of the sql task, I've now tried to 
modify my target to first create a fileset, then created a property 
based on a pathcovert of that fileset, and then tried to run the sql 
task based on a test of that property.  While this looks a little ugly 
and kludgey, it was the only way (I thought) to make sure that I was 
guaranteed to not run the sql task if the fileset was empty.

My current target that includes the sql task now looks like:

<!-- build.xml snippet starts here -->

  <target name="loadStoredProcedures">
    <basename property="this.user" file="${this.dir}"/>
    <echo message="Loading stored procedures from ${this.dir}."/>
    <fileset dir="${this.dir}" id="this.fileset">
      <include name="*.sql"/>
      <modified>
        <param name="cache.cachefile" value="config/.sql${sfx}.properties"/>
      </modified>
    </fileset>
    <!-- The following path convert is a trick to simply set a property -->
    <!-- named ${new.files} only if there are any files to be processed -->
    <!-- in refid="this.fileset". -->
    <pathconvert property="new.files" refid="this.fileset"
      setonempty="false" targetos="unix"/>
    <if> <isset property="new.files"/>
      <then>
        <echo message="Property new.files is set to ${new.files}."/>
        <sql driver="${jdbc_driver_class}" url="${jdbc_url}"
          userid="${this.user}" password="${coral.db.password}"
          keepformat="true" delimiter="/" escapeprocessing="false" 
print="true"
          onerror="continue">
          <fileset refid="this.fileset"/>
          <classpath>
            <pathelement location="${build.dir}/ext/${jdbc.jar}"/>
          </classpath>
        </sql>
     </then>
   </if>
  </target>

<!-- build.xml snippet ends here -->

I still believe that I am still seeing a failure during the sql task and 
have included what I believe to be the relevant results of the call 'ant 
-debug loadStoredProcedures 2>&1 | tee sql_debug.log'

Apache Ant version 1.7.0 compiled on December 13 2006
Buildfile: build.xml
Adding reference: ant.PropertyHelper
Detected Java version: 1.5 in: /usr/java/jdk1.5.0_14/jre
Detected OS: Linux
Finding class net.sf.antcontrib.logic.IfTask
Loaded from /opencoral/ext/ant/ant-contrib-0.6.jar 
net/sf/antcontrib/logic/IfTask
.class
Class org.apache.tools.ant.taskdefs.condition.ConditionBase loaded from 
parent lo
ader (parentFirst)
Class net.sf.antcontrib.logic.IfTask loaded from ant loader (parentFirst)
Finding class net.sf.antcontrib.logic.IfTask$ElseIf
Loaded from /opencoral/ext/ant/ant-contrib-0.6.jar 
net/sf/antcontrib/logic/IfTask
$ElseIf.class
Class net.sf.antcontrib.logic.IfTask$ElseIf loaded from ant loader 
(parentFirst)
 +Datatype if net.sf.antcontrib.logic.IfTask

loadStoredProcedures:
Setting project property: this.user -> accmgr
     [echo] Loading stored procedures from 
/opencoral/build-rhel4/sql/storedProce
dures/accmgr.
Adding reference: this.fileset
fileset: Setup scanner in dir 
/opencoral/build-rhel4/sql/storedProcedures/accmgr
with patternSet{ includes: [*.sql] excludes: [] }
[pathconvert] Set property new.files = 
/opencoral/build-rhel4/sql/storedProcedure
s/accmgr/accounting_summary_source.sql:/opencoral/build-rhel4/sql/storedProcedure
s/accmgr/load_rates_source.sql:/opencoral/build-rhel4/sql/storedProcedures/accmgr
/raw_accounting_source.sql:/opencoral/build-rhel4/sql/storedProcedures/accmgr/usa
ge_summary_source.sql
Setting project property: new.files -> 
/opencoral/build-rhel4/sql/storedProcedure
s/accmgr/accounting_summary_source.sql:/opencoral/build-rhel4/sql/storedProcedure
s/accmgr/load_rates_source.sql:/opencoral/build-rhel4/sql/storedProcedures/accmgr
/raw_accounting_source.sql:/opencoral/build-rhel4/sql/storedProcedures/accmgr/usa
ge_summary_source.sql
     [echo] Property new.files is set to 
/opencoral/build-rhel4/sql/storedProcedu
res/accmgr/accounting_summary_source.sql:/opencoral/build-rhel4/sql/storedProcedu
res/accmgr/load_rates_source.sql:/opencoral/build-rhel4/sql/storedProcedures/accm
gr/raw_accounting_source.sql:/opencoral/build-rhel4/sql/storedProcedures/accmgr/u
sage_summary_source.sql.
fileset: Setup scanner in dir 
/opencoral/build-rhel4/sql/storedProcedures/accmgr
with patternSet{ includes: [*.sql] excludes: [] }
  [antcall] Exiting /opencoral/build.xml.

BUILD FAILED
/opencoral/build.xml:1571: The following error occurred while executing 
this line
:
/opencoral/build.xml:1594: Source file or resource collection, 
transactions or sq
l statement must be set!
        at 
org.apache.tools.ant.ProjectHelper.addLocationToBuildException(Project
Helper.java:541)
        at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:418)
        at 
org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:105)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.j
ava:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess
orImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java
:105)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at 
org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:62)
        at net.sf.antcontrib.logic.ForEach.executeSequential(Unknown Source)
        at net.sf.antcontrib.logic.ForEach.execute(Unknown Source)
        at 
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess
orImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java
:105)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at org.apache.tools.ant.Target.performTasks(Target.java:385)
        at 
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
        at 
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExec
utor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
        at org.apache.tools.ant.Main.runBuild(Main.java:698)
        at org.apache.tools.ant.Main.startAnt(Main.java:199)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: /opencoral/build.xml:1594: Source file or resource 
collection, transac
tions or sql statement must be set!
        at org.apache.tools.ant.taskdefs.SQLExec.execute(SQLExec.java:390)
        at 
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess
orImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java
:105)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at 
org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:62)
        at net.sf.antcontrib.logic.IfTask.execute(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.j
ava:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess
orImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java
:105)
        at org.apache.tools.ant.TaskAdapter.execute(TaskAdapter.java:134)
        at 
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess
orImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java
:105)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at org.apache.tools.ant.Target.performTasks(Target.java:385)
        at 
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
        at 
org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleC
heckExecutor.java:38)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
        at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:416)
        ... 26 more
--- Nested Exception ---
/opencoral/build.xml:1594: Source file or resource collection, 
transactions or sq
l statement must be set!
        at org.apache.tools.ant.taskdefs.SQLExec.execute(SQLExec.java:390)
        at 
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess
orImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java
:105)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at 
org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:62)
        at net.sf.antcontrib.logic.IfTask.execute(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.j
ava:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess
orImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java
:105)
        at org.apache.tools.ant.TaskAdapter.execute(TaskAdapter.java:134)
        at 
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess
orImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java
:105)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at org.apache.tools.ant.Target.performTasks(Target.java:385)
        at 
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
        at 
org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleC
heckExecutor.java:38)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
        at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:416)
        at 
org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:105)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.j
ava:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess
orImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java
:105)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at 
org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:62)
        at net.sf.antcontrib.logic.ForEach.executeSequential(Unknown Source)
        at net.sf.antcontrib.logic.ForEach.execute(Unknown Source)
        at 
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess
orImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java
:105)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at org.apache.tools.ant.Target.performTasks(Target.java:385)
        at 
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
        at 
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExec
utor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
        at org.apache.tools.ant.Main.runBuild(Main.java:698)
        at org.apache.tools.ant.Main.startAnt(Main.java:199)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

Total time: 5 seconds

So, it looks, based on my pathcovert ${new.files} property that it 
thinks that the fileset should contain 4 files.  But, I still seem to be 
generating an error when I try to load that fileset as a "refid" fileset.

Any insights or further tests .... or cleaner ways of testing for a 
non-empty fileset .... would be greatly appreciated.

Thanks,

John




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message