You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2007/01/23 22:47:49 UTC

svn commit: r499144 - in /portals/jetspeed-2/trunk: ./ ant-tasks/ ant-tasks/src/java/org/apache/jetspeed/anttasks/ maven-plugin/

Author: taylor
Date: Tue Jan 23 13:47:48 2007
New Revision: 499144

URL: http://svn.apache.org/viewvc?view=rev&rev=499144
Log:
Problem:

Only one instance of Derby is allowed to be loaded per instance of the Java Virtual Machine (JVM) 
and only a single Derby instance is allowed to access any given database at a time. 
When the Derby instance connects to a database, a lock is created that helps to enforce these rules. 
The only way to remove that lock is to explicitly tear down Derby’s connection to the database. 
While SQL Ant Task is fully capable of launching the Derby embedded database and executing SQL statements against it, 
it is not capable of handling the appropriate Derby shutdown tasks that are required to use Derby properly.

Hence the Derby database used in an ant <SQL> task remains looked until that process terminates – 
any other connection request – whether from a forked or embedded JAVA process – is rejected.

Solution:

While not the best solution from a performance perspective, the easiest and most reliable is to establish the SQL task from 
within a separate (JAVA) process, which -when forked- will upon completion terminate the database and bring it down 
correctly (i.e. remove the lock).

contribution from Hajo Birthelmer

Added:
    portals/jetspeed-2/trunk/ant-tasks/project.xml
    portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/ExecuteJavaSQL.java
    portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/ExecuteSQL.java
    portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StartDatabase.java
    portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StartDerby.java
    portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StopDatabase.java
    portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StopDerby.java
Modified:
    portals/jetspeed-2/trunk/.classpath
    portals/jetspeed-2/trunk/ant-tasks/pom.xml
    portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/antlib.xml
    portals/jetspeed-2/trunk/core-build.xml
    portals/jetspeed-2/trunk/full-portal.xml
    portals/jetspeed-2/trunk/maven-plugin/plugin.jelly

Modified: portals/jetspeed-2/trunk/.classpath
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/.classpath?view=diff&rev=499144&r1=499143&r2=499144
==============================================================================
--- portals/jetspeed-2/trunk/.classpath (original)
+++ portals/jetspeed-2/trunk/.classpath Tue Jan 23 13:47:48 2007
@@ -103,7 +103,7 @@
 	<classpathentry kind="var" path="MAVEN_REPO/org.springframework/jars/spring-mock-2.0.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/org.springframework/jars/spring-portlet-2.0.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/org.springframework/jars/spring-webmvc-2.0.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/springmodules/jars/spring-modules-ojb-0.6.jar"/>	
+	<classpathentry kind="var" path="MAVEN_REPO/springmodules/jars/spring-modules-ojb-0.6.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/commons-fileupload/jars/commons-fileupload-1.0.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/org.apache.portals.bridges/jars/portals-bridges-common-1.0.1-dev.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/org.apache.portals.bridges/jars/portals-bridges-frameworks-1.0.1-dev.jar"/>
@@ -118,5 +118,6 @@
 	<classpathentry kind="var" path="MAVEN_REPO/ddlutils/jars/ddlutils-1.0-RC1-PATCHED.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/commons-beanutils/jars/commons-beanutils-1.6.1.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/commons-betwixt/jars/commons-betwixt-20061115.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/ant/jars/ant-1.6.5.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>

Modified: portals/jetspeed-2/trunk/ant-tasks/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/ant-tasks/pom.xml?view=diff&rev=499144&r1=499143&r2=499144
==============================================================================
--- portals/jetspeed-2/trunk/ant-tasks/pom.xml (original)
+++ portals/jetspeed-2/trunk/ant-tasks/pom.xml Tue Jan 23 13:47:48 2007
@@ -49,6 +49,7 @@
             <groupId>ant</groupId>
             <artifactId>ant</artifactId>
             <scope>provided</scope>
+            <version>1.6.5</version>
         </dependency>
 
     </dependencies>

Added: portals/jetspeed-2/trunk/ant-tasks/project.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/ant-tasks/project.xml?view=auto&rev=499144
==============================================================================
--- portals/jetspeed-2/trunk/ant-tasks/project.xml (added)
+++ portals/jetspeed-2/trunk/ant-tasks/project.xml Tue Jan 23 13:47:48 2007
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Copyright 2004 The Apache Software Foundation
+    
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+    
+    http://www.apache.org/licenses/LICENSE-2.0
+    
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+    
+    $Id: project.xml 355198 2005-12-08 20:44:03Z rogerrut $
+-->
+<project>
+    <extend>${basedir}/../core-build.xml</extend>
+    <pomVersion>3</pomVersion>
+    <artifactId>ant-tasks</artifactId>
+    <name>Jetspeed-2 Ant Tasks</name>
+
+    <package>org.apache.jetspeed</package>
+    <description>Ant Tasks Required for the Jetspeed-2 Product Build.</description>
+    <shortDescription>Ant Tasks Required for the Jetspeed-2 Product Build.</shortDescription>
+
+    <repository>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/portals/jetspeed-2/trunk/ant-tasks</connection>
+        <developerConnection>
+            scm:svn:https://svn.apache.org/repos/asf/portals/jetspeed-2/trunk/ant-tasks
+        </developerConnection>
+        <url>http://svn.apache.org/viewcvs.cgi/portals/jetspeed-2/trunk/ant-tasks/</url>
+    </repository>
+  	    <dependency>
+	      <id>ant</id>
+	      <version>1.6.5</version>
+	      <properties>
+	         <war.bundle>true</war.bundle>
+	      </properties>          
+	    </dependency>
+
+</project>

Added: portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/ExecuteJavaSQL.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/ExecuteJavaSQL.java?view=auto&rev=499144
==============================================================================
--- portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/ExecuteJavaSQL.java (added)
+++ portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/ExecuteJavaSQL.java Tue Jan 23 13:47:48 2007
@@ -0,0 +1,135 @@
+/**
+ * 
+ */
+package org.apache.jetspeed.anttasks;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Target;
+import org.apache.tools.ant.taskdefs.SQLExec;
+import java.util.StringTokenizer;
+import java.io.File;
+
+/**
+ * @author hajo
+ * 
+ */
+public class ExecuteJavaSQL
+{
+
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args)
+	{
+	    final class TEMPSQL extends SQLExec {
+	        public TEMPSQL() 
+	        {
+		 	    setProject(new Project());
+			    getProject().init();
+			    super.setTaskType("sql");
+			    super.setTaskName("sql");
+			    super.target = new Target();
+	        }	
+	    }
+
+	    boolean autocommit = true;
+	    String driver = null;
+	    String url = null;
+	    String userid = null;
+	    String password = null;
+	    String source = null;
+	    String onError = null;
+	    
+	    
+	    
+       if (args == null)
+            throw new IllegalArgumentException("ExecuteSQL needs to know what to do - no arguments provided!!! ");
+
+        
+        // Parse all the command-line arguments
+        for (int n = 0; n < args.length; n++)
+        {
+        	String argument = args[n].toLowerCase().trim();
+        	
+			if (argument.startsWith("driver="))	           
+			{
+				driver = args[n].substring("driver=".length());
+			}
+			else
+				if (argument.startsWith("url="))
+				{
+					url = args[n].substring("url=".length());
+				}
+				else
+					if (argument.startsWith("userid="))
+					{
+						userid = args[n].substring("userid=".length());
+					}
+					else
+						if (argument.startsWith("password="))
+						{
+							password = args[n].substring("password=".length());
+						}
+						else
+							if (argument.startsWith("src=")) 	       
+							{
+								source = args[n].substring("src=".length());
+							}
+							else
+								if (argument.startsWith("autocommit="))
+								{
+									String s = args[n].substring("src=".length());
+									try
+									{
+										autocommit = Boolean.parseBoolean(s);
+									}
+									catch (Exception e)
+									{
+										e.printStackTrace();
+									}
+								}
+								else
+									if (argument.startsWith("onerror="))
+									{
+										onError = args[n].substring("onerror=".length());
+									}
+								    else
+							            {
+							                throw new IllegalArgumentException("Unknown argument: "
+							                        + args[n]);
+							            }
+        }
+		TEMPSQL sql = new TEMPSQL();
+		
+		sql.setAutocommit(autocommit);
+		sql.setDriver(driver);
+		sql.setUrl(url);
+		sql.setUserid(userid);
+		sql.setPassword(password);
+		File sqlFile = null;
+		try
+		{
+			sqlFile = new File(source); 
+		}
+		catch (Exception e)
+		{
+			 throw new IllegalArgumentException("File parameter " + source + " invalid : " + e.getLocalizedMessage());
+		}
+		sql.setSrc(sqlFile);
+		try
+		{
+			SQLExec.OnError errorHandling = new SQLExec.OnError();
+			errorHandling.setValue(onError);
+			sql.setOnerror(errorHandling);
+		}
+		catch (Exception e)
+		{
+			 throw new IllegalArgumentException("Error handling parameter " + onError + " invalid : " + e.getLocalizedMessage());
+		}
+			
+
+		
+		sql.execute();
+
+	}
+}

Added: portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/ExecuteSQL.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/ExecuteSQL.java?view=auto&rev=499144
==============================================================================
--- portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/ExecuteSQL.java (added)
+++ portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/ExecuteSQL.java Tue Jan 23 13:47:48 2007
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.anttasks;
+
+
+import java.sql.DriverManager;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.SQLExec;
+import java.util.Properties;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Target;
+import org.apache.tools.ant.taskdefs.SQLExec;;
+
+public class ExecuteSQL extends SQLExec
+{  
+
+  
+	public  void execute() throws BuildException 
+	{
+		
+	
+		try
+		{
+			System.out.println("Executing SQL statement");
+			super.execute();
+		}
+		catch (Exception e)
+		{
+			throw new BuildException(e, getLocation());
+		}
+		finally
+		{
+			if (StartDerby.getConnection(getProject()) != null)
+			{
+				try
+				{
+					if (!(StartDerby.getConnection(getProject()).isClosed()))
+						StartDerby.getConnection(getProject()).close();
+				}
+				catch (Exception e1)
+				{
+					// just a safetyguard
+				}
+				StartDerby.setConnection(getProject(),null);
+			}
+		}
+	}
+		
+
+  /**
+     * Creates a new Connection as using the driver, url, userid and password
+     * specified.
+     *
+     * The calling method is responsible for closing the connection.
+     *
+     * @return Connection the newly created connection.
+     * @throws BuildException if the UserId/Password/Url is not set or there
+     * is no suitable driver or the driver fails to load.
+     */
+  protected Connection getConnection() throws BuildException 
+  {
+	 	if (StartDerby.getDriver(getProject()) == null)
+	 		throw new BuildException("Derby driver not established!", getLocation());		
+  	// reuse excisting connection:
+  	if (StartDerby.getConnection(getProject())!= null)
+  	{
+  		System.out.println("Connection already established");
+  		return StartDerby.getConnection(getProject());
+  	}
+  	// do almost the same as in the orignial JDBC tasks:
+  	
+        if (getUrl() == null) {
+            throw new BuildException("Url attribute must be set!", getLocation());
+        }
+        try {
+
+            log("connecting to " + getUrl(), Project.MSG_VERBOSE);
+            Properties info = new Properties();
+            if (getUserId() != null)
+            	info.put("user", getUserId());
+            if (getPassword() != null)
+            	info.put("password", getPassword());
+            
+            Connection conn = StartDerby.getDriver(getProject()).connect(getUrl(), info);
+            if (conn == null) {
+                // Driver doesn't understand the URL
+                throw new SQLException("No suitable Driver for " + getUrl());
+            }
+
+            conn.setAutoCommit(isAutocommit());
+      		System.out.println("Connection to " + getUrl() + " established");
+      		StartDerby.setConnection(getProject(),conn);
+            return conn;
+        } catch (SQLException e) {
+            throw new BuildException(e, getLocation());
+        }
+
+    }
+  
+  
+}

Added: portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StartDatabase.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StartDatabase.java?view=auto&rev=499144
==============================================================================
--- portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StartDatabase.java (added)
+++ portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StartDatabase.java Tue Jan 23 13:47:48 2007
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.anttasks;
+
+import java.sql.DriverManager;
+import java.util.ArrayList;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.JDBCTask;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+import java.util.Properties;
+import org.apache.tools.ant.Project;
+
+public class StartDatabase
+  extends JDBCTask  {
+
+  
+  
+  
+  public void execute() 
+    throws BuildException 
+    {
+	    if (StartDerby.getDriver(getProject()) == null)
+	    	 throw new BuildException("Derby driver not established!", getLocation());
+	  	// reuse excisting connection:
+	  	if (StartDerby.getConnection(getProject()) != null)
+	  	{
+			System.out.println("Connection already established");
+			return;
+	  	}
+	  	// do almost the same as in the orignial JDBC tasks:
+	  	
+	        if (getUrl() == null) {
+	            throw new BuildException("Url attribute must be set!", getLocation());
+	        }
+	        try {
+
+	            log("connecting to " + getUrl(), Project.MSG_VERBOSE);
+	            Properties info = new Properties();
+	            if (getUserId() != null)
+	            	info.put("user", getUserId());
+	            if (getPassword() != null)
+	            	info.put("password", getPassword());
+	            
+	            Connection conn = StartDerby.getDriver(getProject()).connect(getUrl(), info);
+	            if (conn == null) {
+	                // Driver doesn't understand the URL
+	                throw new SQLException("No suitable Driver for " +  getUrl());
+	            }
+
+	            conn.setAutoCommit(isAutocommit());
+	            StartDerby.setConnection(getProject(),conn);
+	            System.out.println("Derby connected to " + getUrl());
+	            return;
+	        } catch (SQLException e) {
+	            throw new BuildException(e, getLocation());
+	        }
+ }
+  
+}

Added: portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StartDerby.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StartDerby.java?view=auto&rev=499144
==============================================================================
--- portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StartDerby.java (added)
+++ portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StartDerby.java Tue Jan 23 13:47:48 2007
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.anttasks;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import java.sql.DriverManager;
+import java.sql.Driver;
+import java.sql.Connection;
+import org.apache.tools.ant.Project;
+import java.util.Hashtable;
+
+
+public class StartDerby 
+  extends Task {
+ 
+//	public static Driver DERBY_DRIVER = null;
+//	public static Connection  DERBY_CONNECTION = null;
+
+  public void execute() 
+    throws BuildException {
+      try {
+  	   	if (StartDerby.getDriver(getProject()) != null)
+       	{
+        		System.out.println("Derby Driver has ALREADY BEEN ESTABLISHED!");
+        		return;
+       	}
+  	  StartDerby.setDriver(getProject(),(java.sql.Driver)(Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance()));
+        System.out.println("Derby Driver 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);
+      }
+  }
+  
+  public static void setDriver(Project project, Driver d)
+  {
+	  try
+	  {
+		  if (d != null)
+		  {
+			  project.addReference("DRIVER",d);
+			  System.out.println("Driver reference in Project set ");
+		  }
+		  else
+		  {
+			  Hashtable h = project.getReferences();
+			  h.remove("DRIVER");
+			  System.out.println("Driver reference in Project removed ");
+		  }
+	  }
+	  catch (Exception e)
+	  {
+		  System.out.println("Could't SET Driver reference in Project : " + e.getLocalizedMessage());
+		  
+	  }
+  }
+  public static Driver getDriver(Project project)
+  {
+	  try
+	  {
+		  Object o = project.getReference("DRIVER");
+		  if (o != null)
+			  return (Driver)o;
+		  else return null;
+	  }
+	  catch (Exception e)
+	  {
+		  System.out.println("Could't get Driver reference in Project : " + e.getLocalizedMessage());
+		  return null;
+	  }
+  }
+  
+  public static void setConnection(Project project, Connection d)
+  {
+	  try
+	  {
+		  if (d != null)
+		  {
+			  project.addReference("Connection",d);
+			  System.out.println("Connection reference in Project set ");
+		  }
+		  else
+		  {
+			  Hashtable h = project.getReferences();
+			  h.remove("Connection");
+			  System.out.println("Connection reference in Project removed ");
+		  }
+	  }
+	  catch (Exception e)
+	  {
+		  System.out.println("Could't SET Connection reference in Project : " + e.getLocalizedMessage());
+		  
+	  }
+  }
+  public static Connection getConnection(Project project)
+  {
+	  try
+	  {
+		  Object o = project.getReference("Connection");
+		  if (o != null)
+			  return (Connection)o;
+		  else return null;
+	  }
+	  catch (Exception e)
+	  {
+		  System.out.println("Could't get Connection reference in Project : " + e.getLocalizedMessage());
+		  return null;
+	  }
+  }
+}

Added: portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StopDatabase.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StopDatabase.java?view=auto&rev=499144
==============================================================================
--- portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StopDatabase.java (added)
+++ portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StopDatabase.java Tue Jan 23 13:47:48 2007
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.anttasks;
+
+import java.sql.DriverManager;
+import java.util.ArrayList;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+
+
+public class StopDatabase
+  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 {
+  	if (StartDerby.getDriver(getProject()) == null)
+	{
+		System.out.println("Derby Driver has NOT BEEN ESTABLISHED!");
+		return ; // already closed;
+	}
+	if (StartDerby.getConnection(getProject()) != null)
+	{
+		try
+		{
+			StartDerby.getConnection(getProject()).close();
+			System.out.println("Derby Connection successfully closed!");
+		}
+		catch (SQLException e)
+		{
+			throw new BuildException(e, getLocation());
+		}
+		StartDerby.setConnection(getProject(),null);
+		
+	}
+	else
+		System.out.println("Derby Connection has already been closed!");
+ }
+  
+}

Added: portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StopDerby.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StopDerby.java?view=auto&rev=499144
==============================================================================
--- portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StopDerby.java (added)
+++ portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/StopDerby.java Tue Jan 23 13:47:48 2007
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.anttasks;
+
+import java.sql.DriverManager;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+import java.util.Properties;
+import java.util.Properties;
+import org.apache.tools.ant.Project;
+
+
+public class StopDerby 
+  extends Task {
+  
+
+  public void execute() 
+    throws BuildException 
+    {
+	  	if (StartDerby.getDriver(getProject()) == null)
+		{
+			System.out.println("Derby Driver has NOT BEEN ESTABLISHED!");
+			return ; // already closed;
+		}
+		if (StartDerby.getConnection(getProject()) != null)
+		{
+			try
+			{
+				StartDerby.getConnection(getProject()).close();
+				System.out.println("Derby Connection successfully closed!");
+			}
+			catch (SQLException e)
+			{
+				throw new BuildException(e, getLocation());
+			}
+			StartDerby.setConnection(getProject(),null);
+			
+		}
+		else
+    		System.out.println("Derby Connection has already been closed!");
+    	
+//    	getConnection("jdbc:derby:;shutdown=true");
+        Properties info = new Properties();
+      	info.put("shutdown",Boolean.TRUE);
+        System.out.println("Derby Driver sutting down!");
+        try
+        {
+        	StartDerby.getDriver(getProject()).connect("jdbc:derby:",info);
+    	} catch (Exception e) 
+    	{
+    		System.out.println("Derby has been shutdown!");
+        }
+
+    	StartDerby.setDriver(getProject(),null);
+        System.out.println("Derby Driver has been shutdown!");
+     }
+  
+}

Modified: portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/antlib.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/antlib.xml?view=diff&rev=499144&r1=499143&r2=499144
==============================================================================
--- portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/antlib.xml (original)
+++ portals/jetspeed-2/trunk/ant-tasks/src/java/org/apache/jetspeed/anttasks/antlib.xml Tue Jan 23 13:47:48 2007
@@ -16,4 +16,8 @@
 -->
 <antlib>
     <typedef name="archetypedescriptor" classname="org.apache.jetspeed.anttasks.ArchetypeDescriptor"/>
+    <typedef name="startderby" classname="org.apache.jetspeed.anttasks.StartDerby"/>
+    <typedef name="stopDatabase" classname="org.apache.jetspeed.anttasks.StopDatabase"/>
+    <typedef name="stopDerby" classname="org.apache.jetspeed.anttasks.StopDerby"/>
+    <typedef name="executeSQL" classname="org.apache.jetspeed.anttasks.ExecuteSQL"/>
 </antlib>

Modified: portals/jetspeed-2/trunk/core-build.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/core-build.xml?view=diff&rev=499144&r1=499143&r2=499144
==============================================================================
--- portals/jetspeed-2/trunk/core-build.xml (original)
+++ portals/jetspeed-2/trunk/core-build.xml Tue Jan 23 13:47:48 2007
@@ -372,5 +372,14 @@
 	         <war.bundle>true</war.bundle>
 	      </properties>          
 	    </dependency>
+	    <dependency>
+	      <id>ant</id>
+	      <version>1.6.5</version>
+	      <properties>
+	         <war.bundle>true</war.bundle>
+	      </properties>          
+	    </dependency>
+    
+	 
 	  </dependencies>     
 </project>

Modified: portals/jetspeed-2/trunk/full-portal.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/full-portal.xml?view=diff&rev=499144&r1=499143&r2=499144
==============================================================================
--- portals/jetspeed-2/trunk/full-portal.xml (original)
+++ portals/jetspeed-2/trunk/full-portal.xml Tue Jan 23 13:47:48 2007
@@ -35,5 +35,13 @@
         <type>plugin</type>
         <properties/>
     </dependency>
+    	          <dependency>
+	      <id>org.apache.portals.jetspeed-2:ant-tasks</id>
+    	  <version>${jetspeed.version}</version>
+      		<properties>
+        		 <war.bundle>true</war.bundle>
+		    </properties>                    
+        </dependency>
+	
 	</dependencies>
 </project>

Modified: portals/jetspeed-2/trunk/maven-plugin/plugin.jelly
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/maven-plugin/plugin.jelly?view=diff&rev=499144&r1=499143&r2=499144
==============================================================================
--- portals/jetspeed-2/trunk/maven-plugin/plugin.jelly (original)
+++ portals/jetspeed-2/trunk/maven-plugin/plugin.jelly Tue Jan 23 13:47:48 2007
@@ -869,6 +869,17 @@
   </goal>
     
   <goal name="j2:_db.execute">
+  
+   	<j:set var="useAntSQL" value = "true"/>
+    <!-- For Derby we need special handling to avoid locking of the database by the main ant process --> 
+  
+	<j:if test="${dbase == 'derby'}">
+	    <attainGoal name="j2:_db.executeDerby"/>
+	    <j:set var="useAntSQL" value = "false"/>
+     </j:if>
+	
+	<j:if test="${useAntSQL}">
+  
     <!-- Ugly hack (or sound fix) setting the parentScope to an empty String because
          with maven project inheritance the size of this property is killing
          performance when the sql task is trying to interpose property values.
@@ -904,6 +915,27 @@
         <pathelement path="${plugin.getDependencyPath('hsqldb')}"/>
       </classpath>
     </sql>
+     </j:if> 
+  </goal>
+    
+  <goal name="j2:_db.executeDerby">
+	<echo> executeDerby </echo>
+  
+     <java classname="org.apache.jetspeed.anttasks.ExecuteJavaSQL" fork="yes">
+      <classpath>
+    	<path refid="maven.dependency.classpath"/>
+        <pathelement path="${maven.build.dest}"/>
+        <pathelement path="${plugin.getDependencyPath('org.apache.derby:derby')}"/>
+        <pathelement path="${org.apache.jetspeed.jdbc.drivers.path}"/>
+      </classpath>
+      <arg line="driver=${org.apache.jetspeed.database.driver} 
+      url=${org.apache.jetspeed.database.url}
+      userid=${org.apache.jetspeed.database.user} 
+      password=${org.apache.jetspeed.database.password} 
+      src=&quot;${database.arg.script}&quot; autocommit=true
+      onerror=${database.arg.onerror}"/>
+    </java>
+ 
   </goal>
     
   <goal name="j2:_db.test.properties">



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org