ashish shrivastava wrote:
I am OK with the complexity. I can not group sql task as there are
dependencies on other tasks.
please tell me how to achieve it.


ahh. when I said complexity, I meant "nobody in the ant team wants to write the code to do connection pooling as there is little perceived value in what is essentially a build tool of adding the stuff that enterprise java does for you"

Interestingly enough, the SmartFrog deployment tool doesnt do connection pooling either. There's two reasons for that.

The first is that its based on <sql>, though if you look at the source

-http://smartfrog.svn.sourceforge.net/viewvc/smartfrog/trunk/core/components/database/src/org/smartfrog/services/database/core/TransactionImpl.java?view=markup

you'll see that it dropped most of the logic to work out where to split lines, deal with comments properly, etc ,because the authors knew they raised most of the <sql> support calls. Instead you just declare your actions in a list

 /**
  * Create an events table with various attributes
  * this is an implicit test of multi-line SQL.
  */
 CreateEventsTable extends AdminCommand {
    sqlCommands [
    "DROP TABLE events",
    ##CREATE TABLE events (
      EVENT_ID varchar(64) not null,
      EVENT_NAME varchar(255) not null,
      EVENT_DATE timestamp not null,
      EVENT_VERSION integer,
      EVENT_LASTMODIFIED timestamp,
      EVENT_TEXT varchar(8192),
      primary key (EVENT_ID));
      #
    ];
    }


The second is that outside of doing high scalability load with hundreds of clients sharing a limited number of connections, connection pooling doesnt deliver much, and forces your code to implement all the concurrency/pooling logic to do pooling right, the stuff that hibernate, EJB and spring try and hide you from.

If all you are doing at deployment is issuing a sequence of commands like setting up a database with a few tables, you dont need pooling, really. all you need is to tempalte your operations then issue the commands as you see fit. Here is my ant code (product placement, from chapter 16 of Ant in Action, "deployment"), to set up the database:


  <target name="mysql-init" depends="ivy-resolve"
    xmlns:ext="http://antbook.org/d1/ext"; >
    <ivy:cachepath pathid="sql.classpath" conf="sql" />
    <property name="mysql.root.pass" value=""/>
    <property name="mysql.diary.pass" value="secret"/>
    <presetdef name="mysql-admin">
      <sql driver="com.mysql.jdbc.Driver"
        classpathref="sql.classpath"
        userid="root"
        password="${mysql.root.pass}"
        print="true"
        url="jdbc:mysql://localhost/mysql"
        expandProperties="true"/>
    </presetdef>
    <presetdef name="mysql">
      <mysql-admin
        userid="diary"
        password="${mysql.diary.pass}"
        url="jdbc:mysql://localhost/diary"/>
    </presetdef>
  </target>

  <target name="mysql-drop-db" depends="mysql-init"
    description="create the database and account">
    <mysql-admin onerror="continue">
      DROP DATABASE diary;
    </mysql-admin>
  </target>


  <target name="mysql-create-db" depends="mysql-init,mysql-drop-db"
    description="create the database and account">
    <mysql-admin>
      CREATE DATABASE diary;
      GRANT ALL PRIVILEGES ON diary.* TO 'diary'@'localhost';
      SET PASSWORD FOR 'diary'@'localhost' =
       PASSWORD('${mysql.diary.pass}');
    </mysql-admin>
  </target>

  <target name="mysql-create-events" depends="mysql-init"
      description="create the event table">
    <mysql>
      CREATE TABLE EVENTS (
      EVENT_ID varchar(64) not null,
      EVENT_NAME varchar(255) not null,
      EVENT_DATE timestamp not null,
      EVENT_VERSION integer,
      EVENT_LASTMODIFIED timestamp,
      EVENT_TEXT varchar(8192),
      primary key (EVENT_ID));
    </mysql>
  </target>

  <target name="mysql-list-events" depends="mysql-init"
    description="list all events in the system">
    <mysql>
      select * from EVENTS;
    </mysql>
  </target>

  <target name="mysql-drop-events" depends="mysql-init"
    description="delete the event table">
    <mysql>
      DROP TABLE EVENTS;
    </mysql>
  </target>


this works for me. The only place I'd see performance as an issue would be if I were trying to populate a 15GB file from inside Ant. The correct way to do that (for testing) is to do it in the persistence framework of your choice, then snapshot either the database files or the entire vmware/xen image for reuse.

-steve

Thanks
Ashish


On 1/11/07, Steve Loughran <[EMAIL PROTECTED]> wrote:

ashish shrivastava wrote:
> I am using ANT for deployment of my product.I need to run different
> SQL's at
> different stages of my deployment, so if i use ANT SQL task it will
> create a
> new DB connection each time.Is there any way i can share the DB
connection
> between different tasks.(may be putting the connection in Project class
> thru
> my custom SQL task....)?
>
> Thanks in Advance
> Ashish
>

No, its too complex to do connection pooling. Is it really that
expensive to set up the connection?

1. You can do a sequence of operations in one <sql> Tasks.
2 you can use <presetdef> to define a task with all your db bindings.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to