Bug 14512 - Allow creating database connection similar to <path>, <database> condition
Summary: Allow creating database connection similar to <path>, <database> condition
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: unspecified
Hardware: Other other
: P3 enhancement with 2 votes (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2002-11-13 16:47 UTC by thierry lach
Modified: 2012-01-12 15:24 UTC (History)
0 users



Attachments
Patch as described. (13.43 KB, patch)
2002-11-13 16:48 UTC, thierry lach
Details | Diff
Java source file - place in org/apache/tools/ant/types (14.03 KB, text/plain)
2002-11-13 16:50 UTC, thierry lach
Details
Java source file - place in org/apache/tools/ant/taskdefs/condition (10.27 KB, text/plain)
2002-11-13 16:51 UTC, thierry lach
Details

Note You need to log in before you can comment on or make changes to this bug.
Description thierry lach 2002-11-13 16:47:49 UTC
The attached patches allow creating a <connection> within the build file and 
referencing it from the <sql> task rather than having to define all of the 
connection information each time.

Also, it adds a <database> condition that can be used to query the database for 
the existence of a schema, a catalog, a table or view within a schema/catalog, 
or a column/index on a table.

There are three attachments.  One is a patch file, the other two are new 
sources.
Comment 1 thierry lach 2002-11-13 16:48:39 UTC
Created attachment 3824 [details]
Patch as described.
Comment 2 thierry lach 2002-11-13 16:50:22 UTC
Created attachment 3825 [details]
Java source file - place in org/apache/tools/ant/types
Comment 3 thierry lach 2002-11-13 16:51:17 UTC
Created attachment 3826 [details]
Java source file - place in org/apache/tools/ant/taskdefs/condition
Comment 4 thierry lach 2002-11-13 16:59:38 UTC
Here is an example build file (based upon the one I used to test this) that 
demonstrates some of the syntax.  Note:  I ran ant with -debug to see what 
properties were set as a result of the conditions, so there is no explicit use 
of the "xxxxx.is.present" property values.  (Their use is left as an exercise 
to the reader ;-)

<?xml version="2.0"?>
<project default="main" basedir=".">

  <path id="classes12">
    <pathelement location="c:/software/jdbc/classes12.jar"/>
  </path>

  <!-- Make sure the connection works properly with a classpath -->
  <connection id="connection1"
              driver="oracle.jdbc.driver.OracleDriver"
              url="jdbc:oracle:thin:@localhost:1521:ORCL"
	      userid="lacht"
	      password="none_of_your_business"
	      classpath="c:/software/jdbc/classes12.jar"/>

  <!-- Make sure the connection works properly with a classpathref -->
  <connection id="connection2"
              driver="oracle.jdbc.driver.OracleDriver"
              url="jdbc:oracle:thin:@localhost:1521:ORCL"
	      userid="lacht"
	      password="none_of_your_business"
	      classpathref="classes12"/>

  <target name="main">

    <!-- Make sure it still works the old way -->
    <sql
              driver="oracle.jdbc.driver.OracleDriver"
              url="jdbc:oracle:thin:@localhost:1521:ORCL"
	      userid="lacht"
	      password="none_of_your_business"
	      classpathref="classes12">
        <transaction>
	    select * from dual
	</transaction>
    </sql>

    <!-- The same thing with a connectionref -->
    <sql connectionref="connection1">
        <transaction>
	    select * from dual
	</transaction>
    </sql>

    <condition property="schema.is.present">
        <database connectionref="connection2"
	          type="schema"
		  name="LACHT"/>
    </condition>

    <condition property="table.is.present">
        <database connectionref="connection2"
	          catalog=""
	          type="table"
		  schema="LACHT"
		  name="TURBINE_USER"/>
    </condition>

    <condition property="column.is.present">
        <or>
          <database connectionref="connection1"
	            catalog=""
	            type="column"
		    schema="LACHT"
		    table="TURBINE_USER"
		    name="OBJECT_DATA"/>
          <database connectionref="connection2"
	            catalog=""
	            type="column"
		    schema="LACHT"
		    table="TURBINE_USER"
		    name="OBJECTDATA"/>
        </or>
    </condition>

  </target>

</project>