Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2233 - in development/laboratory/spells/derbyant: . src src/main src/main/com src/main/com/ibm src/main/com/ibm/developerworks src/main/com/ibm/developerworks/derby src/main/com/ibm/developerworks/derby/ant

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: peter AT neubauer.se
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r2233 - in development/laboratory/spells/derbyant: . src src/main src/main/com src/main/com/ibm src/main/com/ibm/developerworks src/main/com/ibm/developerworks/derby src/main/com/ibm/developerworks/derby/ant
  • Date: Wed, 06 Apr 2005 16:05:24 -0400

Author: peter AT neubauer.se
Date: Wed Apr 6 16:05:22 2005
New Revision: 2233

Added:
development/laboratory/spells/derbyant/
development/laboratory/spells/derbyant/.classpath
development/laboratory/spells/derbyant/.project
development/laboratory/spells/derbyant/build.xml
development/laboratory/spells/derbyant/example-build.xml
development/laboratory/spells/derbyant/index.xml
development/laboratory/spells/derbyant/src/
development/laboratory/spells/derbyant/src/main/
development/laboratory/spells/derbyant/src/main/com/
development/laboratory/spells/derbyant/src/main/com/ibm/
development/laboratory/spells/derbyant/src/main/com/ibm/developerworks/

development/laboratory/spells/derbyant/src/main/com/ibm/developerworks/derby/

development/laboratory/spells/derbyant/src/main/com/ibm/developerworks/derby/ant/

development/laboratory/spells/derbyant/src/main/com/ibm/developerworks/derby/ant/DBLookTask.java

development/laboratory/spells/derbyant/src/main/com/ibm/developerworks/derby/ant/StartDerbyTask.java

development/laboratory/spells/derbyant/src/main/com/ibm/developerworks/derby/ant/StopDatabaseTask.java

development/laboratory/spells/derbyant/src/main/com/ibm/developerworks/derby/ant/StopDerbyTask.java
Log:
first version of some ant tasks for derby database management, copied from
IBM Alphaworks


Added: development/laboratory/spells/derbyant/.classpath
==============================================================================
--- (empty file)
+++ development/laboratory/spells/derbyant/.classpath Wed Apr 6 16:05:22
2005
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER">
+ <attributes>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="lib" path="ant/lib/ant.jar">
+ <attributes>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="lib"
path="C:/Environment/derby/lib/derbytools.jar">
+ <attributes>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="lib" path="C:/Environment/derby/lib/derby.jar">
+ <attributes>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="lib"
path="C:/Environment/derby/lib/derbynet.jar">
+ <attributes>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="src" path="src/main">
+ <attributes>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="output" path="bin"/>
+</classpath>

Added: development/laboratory/spells/derbyant/.project
==============================================================================
--- (empty file)
+++ development/laboratory/spells/derbyant/.project Wed Apr 6 16:05:22
2005
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>DerbyAntTasks</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+ <linkedResources>
+ <link>
+ <name>ant</name>
+ <type>2</type>
+ <location>C:/Environment/apache-ant-1.6.2</location>
+ </link>
+ </linkedResources>
+</projectDescription>

Added: development/laboratory/spells/derbyant/build.xml
==============================================================================
--- (empty file)
+++ development/laboratory/spells/derbyant/build.xml Wed Apr 6 16:05:22
2005
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<project name="dpml-derbyant" default="install" basedir="."
+ xmlns:transit="antlib:net.dpml.transit">
+
+ <transit:import uri="artifact:template:dpml/magic/standard"/>
+
+</project>
+

Added: development/laboratory/spells/derbyant/example-build.xml
==============================================================================
--- (empty file)
+++ development/laboratory/spells/derbyant/example-build.xml Wed Apr 6
16:05:22 2005
@@ -0,0 +1,63 @@
+<project name="demo" default="demo">
+
+<!-- Define the Derby Ant Tasks -->
+ <taskdef
+ name="startDerby"
+ classname="com.ibm.developerworks.derby.ant.StartDerbyTask" />
+ <taskdef
+ name="stopDerby"
+ classname="com.ibm.developerworks.derby.ant.StopDerbyTask" />
+ <taskdef
+ name="stopDatabase"
+ classname="com.ibm.developerworks.derby.ant.StopDatabaseTask" />
+ <taskdef
+ name="ddlExport"
+ classname="com.ibm.developerworks.derby.ant.DBLookTask" />
+
+ <target name="demo">
+ <property name="DBURL" value="jdbc:derby:my/test;create=true" />
+ <property name="DRIVER" value="org.apache.derby.jdbc.EmbeddedDriver" />
+ <property name="USERID" value="" />
+ <property name="PASSWORD" value="" />
+ <property name="TEST" value="testing" />
+
+ <startDerby />
+
+ <!-- This is the default Ant sql task -->
+ <sql driver="${DRIVER}"
+ url="${DBURL}"
+ userid="${USERID}"
+ password="${PASSWORD}"
+ autocommit="yes"
+ onerror="continue"
+ caching="yes">
+ DROP TABLE TEST;
+ CREATE TABLE TEST (pkey int not null generated always as
+ identity (start with 1, increment by 1), firstfield char(10),
+ secondfield int);
+ INSERT INTO TEST (firstfield, secondfield) VALUES ('${TEST}', 10);
+ SELECT * FROM TEST;
+ </sql>
+
+ <!-- The SQL Command will leave the Derby database is a started state.
+ To protect the integrity of the database, we should explicitly
+ stop the database -->
+ <stopDatabase url="${DBURL}" />
+
+ <!-- Use the dblook tool to generate DDL for the tables -->
+ <ddlExport url="${DBURL}" dest="tables.sql" verbose="yes" />
+
+ <!-- Package the DB up for read-only distribution -->
+ <jar destfile="db.jar" >
+ <fileset dir=".">
+ <include name="my/**/*" />
+ </fileset>
+ </jar>
+
+ <!-- Shutdown Derby properly. This should be done every time,
+ but only when you're absolutely done using Derby -->
+ <stopDerby />
+
+ </target>
+
+</project>

Added: development/laboratory/spells/derbyant/index.xml
==============================================================================
--- (empty file)
+++ development/laboratory/spells/derbyant/index.xml Wed Apr 6 16:05:22
2005
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<index>
+ <resource>
+ <info>
+ <group>derby</group>
+ <name>derby</name>
+ <version>10.0.2.1</version>
+ <type>jar</type>
+ </info>
+ </resource>
+ <resource>
+ <info>
+ <group>derby</group>
+ <name>derbynet</name>
+ <version>10.0.2.1</version>
+ <type>jar</type>
+ </info>
+ </resource>
+<resource>
+ <info>
+ <group>derby</group>
+ <name>derbytools</name>
+ <version>10.0.2.1</version>
+ <type>jar</type>
+ </info>
+ </resource>
+
+ <resource>
+ <info>
+ <group>ant</group>
+ <name>ant</name>
+ <version>1.6.2</version>
+ <type>jar</type>
+ </info>
+ </resource>
+
+ <project basedir=".">
+ <info>
+ <group>dpml/derbyant</group>
+ <name>dpml-derbyant</name>
+ <version>1.0.0</version>
+ <status>SNAPSHOT</status>
+ </info>
+ <dependencies>
+ <include key="ant"/>
+ <include key="derby"/>
+ <include key="derbynet"/>
+ <include key="derbytools"/>
+ </dependencies>
+ </project>
+
+</index>
\ No newline at end of file

Added:
development/laboratory/spells/derbyant/src/main/com/ibm/developerworks/derby/ant/DBLookTask.java
==============================================================================
--- (empty file)
+++
development/laboratory/spells/derbyant/src/main/com/ibm/developerworks/derby/ant/DBLookTask.java
Wed Apr 6 16:05:22 2005
@@ -0,0 +1,114 @@
+package com.ibm.developerworks.derby.ant;
+
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+import java.util.Vector;
+import org.apache.derby.tools.dblook;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+
+public class DBLookTask
+ extends Task {
+
+ private String url; // -d
+ private String dest; // -o
+ private String schema; // -z
+ private Vector tables; // -t
+ private boolean append; // -append
+ private boolean verbose; // -verbose
+ private boolean noview; // -noview
+
+ public boolean isAppend() {
+ return append;
+ }
+ public void setAppend(boolean append) {
+ this.append = append;
+ }
+ public String getDest() {
+ return dest;
+ }
+ public void setDest(String dest) {
+ this.dest = dest;
+ }
+ public boolean isNoview() {
+ return noview;
+ }
+ public void setNoview(boolean noview) {
+ this.noview = noview;
+ }
+ public String getSchema() {
+ return schema;
+ }
+ public void setSchema(String schema) {
+ this.schema = schema;
+ }
+
+ public void setTables(String tables) {
+ if (this.tables == null)
+ this.tables = new Vector();
+ StringTokenizer st = new StringTokenizer(tables, " ");
+ while (st.hasMoreTokens()) {
+ this.tables.add(st.nextToken());
+ }
+ }
+
+ public String getTables() {
+ StringBuffer buf = new StringBuffer();
+ if (tables != null) {
+ for (int n = 0; n < tables.size(); n++) {
+ buf.append(tables.get(n) + " ");
+ }
+ }
+ return buf.toString();
+ }
+
+ public String getUrl() {
+ return url;
+ }
+ public void setUrl(String url) {
+ this.url = url;
+ }
+ public boolean isVerbose() {
+ return verbose;
+ }
+ public void setVerbose(boolean verbose) {
+ this.verbose = verbose;
+ }
+
+ public void execute()
+ throws BuildException {
+ ArrayList args = new ArrayList();
+ args.add("-d");
+ args.add(url);
+
+ if (dest != null) {
+ args.add("-o");
+ args.add(dest);
+ }
+
+ if (schema != null) {
+ args.add("-z");
+ args.add(schema);
+ }
+
+ if (tables != null) {
+ args.add("-t");
+ for (int n = 0; n < tables.size(); n++) {
+ args.add(tables.get(n));
+ }
+ }
+
+ if (append)
+ args.add("-append");
+
+ if (verbose)
+ args.add("-verbose");
+
+ if (noview)
+ args.add("-noview");
+
+ String[] argsarray = new String[args.size()];
+ argsarray = (String[])args.toArray(argsarray);
+ dblook.main(argsarray);
+ }
+}

Added:
development/laboratory/spells/derbyant/src/main/com/ibm/developerworks/derby/ant/StartDerbyTask.java
==============================================================================
--- (empty file)
+++
development/laboratory/spells/derbyant/src/main/com/ibm/developerworks/derby/ant/StartDerbyTask.java
Wed Apr 6 16:05:22 2005
@@ -0,0 +1,22 @@
+package com.ibm.developerworks.derby.ant;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+
+public class StartDerbyTask
+ extends Task {
+
+ public void execute()
+ throws BuildException {
+ try {
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
+ System.out.println("Derby has been started!");
+ } catch (Exception e) {
+ System.out.println(
+ "Derby could not start. This is most likely " +
+ "due to missing Derby JAR files. Please check your classpath" +
+ "and try again.");
+ throw new BuildException(e);
+ }
+ }
+}

Added:
development/laboratory/spells/derbyant/src/main/com/ibm/developerworks/derby/ant/StopDatabaseTask.java
==============================================================================
--- (empty file)
+++
development/laboratory/spells/derbyant/src/main/com/ibm/developerworks/derby/ant/StopDatabaseTask.java
Wed Apr 6 16:05:22 2005
@@ -0,0 +1,32 @@
+package com.ibm.developerworks.derby.ant;
+
+import java.sql.DriverManager;
+import java.util.ArrayList;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+
+public class StopDatabaseTask
+ extends Task {
+
+ private ArrayList subTasks;
+
+ private String url;
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public void execute()
+ throws BuildException {
+ try {
+ DriverManager.getConnection(url + ";shutdown=true");
+ } catch (Exception e){
+ System.out.println("Database has been shutdown");
+ }
+ }
+
+}

Added:
development/laboratory/spells/derbyant/src/main/com/ibm/developerworks/derby/ant/StopDerbyTask.java
==============================================================================
--- (empty file)
+++
development/laboratory/spells/derbyant/src/main/com/ibm/developerworks/derby/ant/StopDerbyTask.java
Wed Apr 6 16:05:22 2005
@@ -0,0 +1,18 @@
+package com.ibm.developerworks.derby.ant;
+
+import java.sql.DriverManager;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+
+public class StopDerbyTask
+ extends Task {
+
+ public void execute()
+ throws BuildException {
+ try {
+ DriverManager.getConnection("jdbc:derby:;shutdown=true");
+ } catch (Exception e) {
+ System.out.println("Derby has been shutdown!");
+ }
+ }
+}



  • svn commit: r2233 - in development/laboratory/spells/derbyant: . src src/main src/main/com src/main/com/ibm src/main/com/ibm/developerworks src/main/com/ibm/developerworks/derby src/main/com/ibm/developerworks/derby/ant, peter, 04/06/2005

Archive powered by MHonArc 2.6.24.

Top of Page