portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1079014 - in /portals/jetspeed-2/portal/trunk: ./ maven/jetspeed-db-maven-plugin/ maven/jetspeed-db-maven-plugin/src/main/java/org/apache/ddlutils/ maven/jetspeed-db-maven-plugin/src/main/java/org/apache/ddlutils/platform/ maven/jetspeed-d...
Date Mon, 07 Mar 2011 23:05:12 GMT
Author: ate
Date: Mon Mar  7 23:05:12 2011
New Revision: 1079014

URL: http://svn.apache.org/viewvc?rev=1079014&view=rev
Log:
JS2-1245: Update some external artifact dependencies to more recent and general available
versions
See: https://issues.apache.org/jira/browse/JS2-1245
- Replace the ddlutils svn r551445 build artifact patched with http://issues.apache.org/jira/browse/DDLUTILS-75#action_12521579
with a CGLIB runtime instrumented ddlutils-1.0.jar instead.
  ddlutils trunk (1.1-SNAPSHOT) does have DDLUTILS-75 fixed, however it is long time in coming
to a release of that.
  Instead, this alternative runtime "patch" does the same trick based on the ddlutils-1.0
release, and should be good until ddltuils eventually might come out with a newer version.

Added:
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/ddlutils/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/ddlutils/platform/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/ddlutils/platform/EnhancedSqlBuilder.java
  (with props)
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/db/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/db/ddlutils/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/db/ddlutils/io/
Modified:
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/pom.xml
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DDLGeneratorMojo.java
    portals/jetspeed-2/portal/trunk/pom.xml

Modified: portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/pom.xml?rev=1079014&r1=1079013&r2=1079014&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/pom.xml (original)
+++ portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/pom.xml Mon Mar  7 23:05:12
2011
@@ -58,6 +58,12 @@
       <groupId>org.apache.ddlutils</groupId>
       <artifactId>ddlutils</artifactId>
     </dependency>
+    <dependency>
+      <groupId>cglib</groupId>
+      <artifactId>cglib</artifactId>
+      <version>${cglib.version}</version>
+    </dependency>
+    
     <!-- Commons Digester (ddlutils->betwixt-digester) requires JCL -->
     <dependency>
       <groupId>org.slf4j</groupId>

Added: portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/ddlutils/platform/EnhancedSqlBuilder.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/ddlutils/platform/EnhancedSqlBuilder.java?rev=1079014&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/ddlutils/platform/EnhancedSqlBuilder.java
(added)
+++ portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/ddlutils/platform/EnhancedSqlBuilder.java
Mon Mar  7 23:05:12 2011
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.ddlutils.platform;
+
+import java.io.IOException;
+import java.sql.DatabaseMetaData;
+
+import net.sf.cglib.proxy.Enhancer;
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.MethodProxy;
+
+import org.apache.ddlutils.Platform;
+import org.apache.ddlutils.model.Database;
+import org.apache.ddlutils.model.ForeignKey;
+import org.apache.ddlutils.model.Table;
+import org.apache.ddlutils.platform.CreationParameters;
+import org.apache.ddlutils.platform.SqlBuilder;
+
+/**
+ * SqlBuilder enhanced through cglib modifying ddlutils 1.0 behavior at runtime for 
+ * https://issues.apache.org/jira/browse/DDLUTILS-75 which is fixed in ddlutils 1.1 but hasn't
been released yet.
+ * 
+ * @version $Id$
+ */
+public class EnhancedSqlBuilder extends SqlBuilder
+{
+	private SqlBuilder internal;
+	
+	private class SqlBuilderEnhancer implements MethodInterceptor
+	{
+	    public Object intercept(Object obj, java.lang.reflect.Method method, Object[] args,
MethodProxy proxy) throws Throwable 
+	    {
+	    	if (method.getName().equals("writeEmbeddedForeignKeysStmt"))
+	    	{
+	    		EnhancedSqlBuilder.this.writeEmbeddedForeignKeysStmt((Database)args[0], (Table)args[1]);
+	    		return null;
+	    	}
+	    	else if (method.getName().equals("writeExternalForeignKeyCreateStmt"))
+	    	{
+	    		EnhancedSqlBuilder.this.writeExternalForeignKeyCreateStmt((Database)args[0], (Table)args[1],
(ForeignKey)args[2]);
+	    		return null;
+	    	}
+	    	else
+	    	{	    		
+	    		return proxy.invokeSuper(obj, args);
+	    	}
+		}
+	}
+	
+	public EnhancedSqlBuilder(SqlBuilder sqlBuilder)
+	{
+		super(null);
+		Enhancer e = new Enhancer();
+		e.setSuperclass(sqlBuilder.getClass());
+		e.setCallback(new SqlBuilderEnhancer());
+		internal = (SqlBuilder)e.create(new Class[]{Platform.class}, new Object[]{sqlBuilder.getPlatform()});
+		internal.setIndent(sqlBuilder.getIndent());
+		internal.setValueLocale(sqlBuilder.getValueLocale());
+		internal.setWriter(sqlBuilder.getWriter());
+	}
+	
+	public void createTables(Database database, CreationParameters params,
+			boolean dropTables) throws IOException 
+	{
+		internal.createTables(database, params, dropTables);
+	}
+
+	/**
+     * {@inheritDoc}
+     */
+    protected String getOnDeleteClauseForCode(int deleteRuleCode)
+    {
+    	String platform = internal.getPlatform().getName();
+    	
+    	if (	platform.equals("Firebird") || 
+    			platform.equals("SapDB") ||
+    			platform.equals("PostgreSql") ||
+    			platform.equals("Derby") ||
+    			platform.startsWith("MySQL") ||
+    			platform.startsWith("DB2"))
+    	{
+            switch (deleteRuleCode)
+            {
+                case DatabaseMetaData.importedKeyCascade:
+                    return "ON DELETE CASCADE";
+                case DatabaseMetaData.importedKeyRestrict:
+                    return "ON DELETE RESTRICT";
+                case DatabaseMetaData.importedKeySetNull:
+                    return "ON DELETE SET NULL";
+                default:
+                    return ""; // No action case
+            }
+    	}
+    	else if (platform.startsWith("HsqlDb") || platform.startsWith("Oracle"))
+    	{
+            switch (deleteRuleCode)
+            {
+                case DatabaseMetaData.importedKeyCascade:
+                    return "ON DELETE CASCADE";
+                case DatabaseMetaData.importedKeyRestrict:
+                    return ""; // not supported
+                case DatabaseMetaData.importedKeySetNull:
+                    return "ON DELETE SET NULL";
+                default:
+                    return ""; // No action case
+            }
+    	}
+    	else if (platform.equals("MsSql"))
+    	{
+            switch (deleteRuleCode)
+            {
+                case DatabaseMetaData.importedKeyCascade:
+                    return "ON DELETE CASCADE";
+                case DatabaseMetaData.importedKeyRestrict:
+                    return ""; // not supported
+                case DatabaseMetaData.importedKeySetNull:
+                    return "ON DELETE SET NULL";
+                default:
+                    return "ON DELETE NO ACTION"; // No action case
+            }
+    	}
+    	return "";
+    }
+    
+    /**
+     * Writes the foreign key constraints inside a create table () clause.
+     * 
+     * @param database The database model
+     * @param table    The table
+     */
+    protected void writeEmbeddedForeignKeysStmt(Database database, Table table) throws IOException
+    {
+        for (int idx = 0; idx < table.getForeignKeyCount(); idx++)
+        {
+            ForeignKey key = table.getForeignKey(idx);
+
+            if (key.getForeignTableName() == null)
+            {
+                internal._log.warn("Foreign key table is null for key " + key);
+            }
+            else
+            {
+            	internal.printStartOfEmbeddedStatement();
+                if (internal.getPlatformInfo().isEmbeddedForeignKeysNamed())
+                {
+                	internal.print("CONSTRAINT ");
+                	internal.printIdentifier(internal.getForeignKeyName(table, key));
+                	internal.print(" ");
+                }
+                internal.print("FOREIGN KEY (");
+                internal.writeLocalReferences(key);
+                internal.print(") REFERENCES ");
+                internal.printIdentifier(internal.getTableName(database.findTable(key.getForeignTableName())));
+                internal.print(" (");
+                internal.writeForeignReferences(key);
+                internal.print(")");
+                
+                String onDeleteClause = getOnDeleteClauseForCode(((org.apache.jetspeed.maven.plugins.db.ddlutils.model.ForeignKey)key).getDeleteRuleCode());
+                if (onDeleteClause.trim().length() > 0)
+                {
+                	internal.print(' ' + onDeleteClause);
+                }
+            }
+        }
+    }
+
+    /**
+     * Writes a single foreign key constraint using a alter table statement.
+     * 
+     * @param database The database model
+     * @param table    The table 
+     * @param key      The foreign key
+     */
+    protected void writeExternalForeignKeyCreateStmt(Database database, Table table, ForeignKey
key) throws IOException
+    {
+        if (key.getForeignTableName() == null)
+        {
+        	internal._log.warn("Foreign key table is null for key " + key);
+        }
+        else
+        {
+        	internal.writeTableAlterStmt(table);
+
+        	String platform = internal.getPlatform().getName();
+        	
+        	if (platform.equals("SapDB") || platform.equals("MaxDB"))
+        	{
+        		internal.print(" ADD FOREIGN KEY ");
+        		internal.printIdentifier(internal.getForeignKeyName(table, key));
+        		internal.print(" (");
+        	}
+        	else
+        	{
+            	internal.print("ADD CONSTRAINT ");
+            	internal.printIdentifier(internal.getForeignKeyName(table, key));
+            	internal.print(" FOREIGN KEY (");
+        	}
+        	
+        	internal.writeLocalReferences(key);
+        	internal.print(") REFERENCES ");
+        	internal.printIdentifier(internal.getTableName(database.findTable(key.getForeignTableName())));
+        	internal.print(" (");
+        	internal.writeForeignReferences(key);
+        	internal.print(")");
+            String onDeleteClause = getOnDeleteClauseForCode(((org.apache.jetspeed.maven.plugins.db.ddlutils.model.ForeignKey)key).getDeleteRuleCode());
+            if (onDeleteClause.trim().length() > 0)
+            {
+            	internal.print(' ' + onDeleteClause);
+            }
+            internal.printEndOfStatement();
+        }
+    }
+}

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/ddlutils/platform/EnhancedSqlBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/ddlutils/platform/EnhancedSqlBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/ddlutils/platform/EnhancedSqlBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DDLGeneratorMojo.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DDLGeneratorMojo.java?rev=1079014&r1=1079013&r2=1079014&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DDLGeneratorMojo.java
(original)
+++ portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DDLGeneratorMojo.java
Mon Mar  7 23:05:12 2011
@@ -23,12 +23,14 @@ import java.io.StringWriter;
 
 import org.apache.ddlutils.Platform;
 import org.apache.ddlutils.PlatformFactory;
-import org.apache.ddlutils.io.DatabaseIO;
 import org.apache.ddlutils.model.Database;
 import org.apache.ddlutils.model.Table;
 import org.apache.ddlutils.platform.CreationParameters;
+import org.apache.ddlutils.platform.EnhancedSqlBuilder;
+import org.apache.ddlutils.platform.SqlBuilder;
 import org.apache.ddlutils.platform.oracle.Oracle8Platform;
 import org.apache.ddlutils.task.TableSpecificParameter;
+import org.apache.jetspeed.maven.plugins.db.ddlutils.io.DatabaseIO;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -147,11 +149,14 @@ public class DDLGeneratorMojo extends Ab
                     {
                         StringWriter stringWriter = new StringWriter();
                         platform.getSqlBuilder().setWriter(stringWriter);
-                        platform.getSqlBuilder().createTables(model, params, false);
+                        // use cglib enhanced wrapper for SqlBuilder to allow overriding
ddlutils 1.0 behavior at runtime for 
+                        // https://issues.apache.org/jira/browse/DDLUTILS-75 which is fixed
in ddlutils 1.1 but hasn't been released yet.
+                        SqlBuilder sqlBuilder = new EnhancedSqlBuilder(platform.getSqlBuilder());
+                        sqlBuilder.createTables(model, params, false);
                         int createSchemaLength = stringWriter.getBuffer().length();
                         writeOutput(new File(outputDir,"create-schema.sql"),stringWriter.toString());
                         stringWriter.getBuffer().setLength(0);
-                        platform.getSqlBuilder().createTables(model, params, true);
+                        sqlBuilder.createTables(model, params, true);
                         stringWriter.getBuffer().setLength(stringWriter.getBuffer().length()-createSchemaLength);
                         writeOutput(new File(outputDir,"drop-schema.sql"), stringWriter.toString());
                     }
@@ -233,7 +238,7 @@ public class DDLGeneratorMojo extends Ab
 
     protected Database readModel(File[] files) throws MojoExecutionException
     {
-        DatabaseIO reader = new DatabaseIO();
+    	DatabaseIO reader = new DatabaseIO();
         Database   model  = null;
 
         reader.setValidateXml(validateXml);

Modified: portals/jetspeed-2/portal/trunk/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/pom.xml?rev=1079014&r1=1079013&r2=1079014&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/pom.xml (original)
+++ portals/jetspeed-2/portal/trunk/pom.xml Mon Mar  7 23:05:12 2011
@@ -249,8 +249,7 @@
     <commons-lang.version>2.4</commons-lang.version>
     <slf4j.version>1.5.6</slf4j.version>
     <commons-pool.version>1.3</commons-pool.version>
-    <!-- ddlutils svn r551445 with patch applied from http://issues.apache.org/jira/browse/DDLUTILS-75#action_12521579
-->
-    <ddlutils.version>r551445-patched-75</ddlutils.version>
+    <ddlutils.version>1.0</ddlutils.version>
     <directory.version>1.5.5</directory.version>
     <dom4j.version>1.6.1</dom4j.version>
     <ehcache.version>1.7.2</ehcache.version>



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


Mime
View raw message