cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1407473 - in /cayenne/main/trunk/framework/cayenne-tools: ./ src/main/java/org/apache/cayenne/tools/ src/test/java/org/apache/cayenne/tools/
Date Fri, 09 Nov 2012 14:40:17 GMT
Author: aadamchik
Date: Fri Nov  9 14:40:16 2012
New Revision: 1407473

URL: http://svn.apache.org/viewvc?rev=1407473&view=rev
Log:
CAY-1758 cdbimport improvements: Default adapter (if none specified) must be AutoAdapter,
not JdbcAdapter

switching the ant tasks

Modified:
    cayenne/main/trunk/framework/cayenne-tools/pom.xml
    cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/CayenneTask.java
    cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java
    cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java
    cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbGeneratorTaskTest.java

Modified: cayenne/main/trunk/framework/cayenne-tools/pom.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/pom.xml?rev=1407473&r1=1407472&r2=1407473&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/pom.xml (original)
+++ cayenne/main/trunk/framework/cayenne-tools/pom.xml Fri Nov  9 14:40:16 2012
@@ -1,150 +1,149 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
-	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.   
--->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
-    <parent>
-        <artifactId>cayenne-parent</artifactId>
-        <groupId>org.apache.cayenne</groupId>
-        <version>3.2M1-SNAPSHOT</version>
+<!-- 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. -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+	<parent>
+		<artifactId>cayenne-parent</artifactId>
+		<groupId>org.apache.cayenne</groupId>
+		<version>3.2M1-SNAPSHOT</version>
 		<relativePath>../../pom.xml</relativePath>
-    </parent>
+	</parent>
 
-    <modelVersion>4.0.0</modelVersion>
+	<modelVersion>4.0.0</modelVersion>
 
-    <artifactId>cayenne-tools</artifactId>
-    <packaging>jar</packaging>
-    <name>Cayenne Tools</name>
-    <dependencies>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-        </dependency>
-        
-        <dependency>
+	<artifactId>cayenne-tools</artifactId>
+	<packaging>jar</packaging>
+	<name>Cayenne Tools</name>
+	<dependencies>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+		</dependency>
+
+		<dependency>
 			<groupId>org.apache.cayenne.build-tools</groupId>
 			<artifactId>cayenne-test-utilities</artifactId>
 			<version>${project.version}</version>
 			<scope>test</scope>
 		</dependency>
 
-        <dependency>
-            <groupId>ant</groupId>
-            <artifactId>ant</artifactId>
-        </dependency>
-
-        <dependency>
-            <groupId>commons-collections</groupId>
-            <artifactId>commons-collections</artifactId>
-        </dependency>
-
-        <dependency>
-            <groupId>commons-logging</groupId>
-            <artifactId>commons-logging</artifactId>
-        </dependency>
-
-        <dependency>
-            <groupId>commons-dbcp</groupId>
-            <artifactId>commons-dbcp</artifactId>
-            <scope>compile</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>commons-pool</groupId>
-            <artifactId>commons-pool</artifactId>
-            <scope>compile</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.velocity</groupId>
-            <artifactId>velocity</artifactId>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.cayenne.unpublished</groupId>
-            <artifactId>cayenne-legal-unpublished</artifactId>
-            <version>${project.version}</version>
-            <scope>provided</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.cayenne.unpublished</groupId>
-            <artifactId>cayenne-jdk1.5-unpublished</artifactId>
-            <version>${project.version}</version>
-            <scope>provided</scope>
-        </dependency>
-        
-        <dependency>
-            <groupId>org.apache.cayenne</groupId>
-            <artifactId>cayenne-project</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-
-        <dependency>
-            <groupId>foundrylogic.vpp</groupId>
-            <artifactId>vpp</artifactId>
-        </dependency>
-
-        <dependency>
-            <groupId>net.java.dev.inflector</groupId>
-            <artifactId>inflector</artifactId>
-        </dependency>
-
-    </dependencies>
-
-    <build>
-        <plugins>
-            <plugin>
-                <artifactId>maven-remote-resources-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>process</goal>
-                        </goals>
-                        <phase>process-resources</phase>
-                        <configuration>
-                            <outputDirectory>
-                                ${project.build.directory}/classes
-                            </outputDirectory>
-                            <resourceBundles>
-                                <resourceBundle>
-                                    org.apache.cayenne.unpublished:cayenne-legal-unpublished:${project.version}
-                                </resourceBundle>
-                            </resourceBundles>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-            <plugin>
-                <artifactId>maven-source-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <id>bundle-source-jar</id>
-                        <phase>package</phase>
-                        <goals>
-                            <goal>jar</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
+		<dependency>
+			<groupId>org.mockito</groupId>
+			<artifactId>mockito-all</artifactId>
+			<scope>test</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>ant</groupId>
+			<artifactId>ant</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>commons-collections</groupId>
+			<artifactId>commons-collections</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>commons-logging</groupId>
+			<artifactId>commons-logging</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>commons-dbcp</groupId>
+			<artifactId>commons-dbcp</artifactId>
+			<scope>compile</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>commons-pool</groupId>
+			<artifactId>commons-pool</artifactId>
+			<scope>compile</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>org.apache.velocity</groupId>
+			<artifactId>velocity</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.apache.cayenne.unpublished</groupId>
+			<artifactId>cayenne-legal-unpublished</artifactId>
+			<version>${project.version}</version>
+			<scope>provided</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>org.apache.cayenne.unpublished</groupId>
+			<artifactId>cayenne-jdk1.5-unpublished</artifactId>
+			<version>${project.version}</version>
+			<scope>provided</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>org.apache.cayenne</groupId>
+			<artifactId>cayenne-project</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+
+		<dependency>
+			<groupId>foundrylogic.vpp</groupId>
+			<artifactId>vpp</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>net.java.dev.inflector</groupId>
+			<artifactId>inflector</artifactId>
+		</dependency>
+
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<artifactId>maven-remote-resources-plugin</artifactId>
+				<executions>
+					<execution>
+						<goals>
+							<goal>process</goal>
+						</goals>
+						<phase>process-resources</phase>
+						<configuration>
+							<outputDirectory>
+								${project.build.directory}/classes
+							</outputDirectory>
+							<resourceBundles>
+								<resourceBundle>
+									org.apache.cayenne.unpublished:cayenne-legal-unpublished:${project.version}
+								</resourceBundle>
+							</resourceBundles>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<artifactId>maven-source-plugin</artifactId>
+				<executions>
+					<execution>
+						<id>bundle-source-jar</id>
+						<phase>package</phase>
+						<goals>
+							<goal>jar</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
 
-    </build>
+	</build>
 </project>
\ No newline at end of file

Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/CayenneTask.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/CayenneTask.java?rev=1407473&r1=1407472&r2=1407473&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/CayenneTask.java
(original)
+++ cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/CayenneTask.java
Fri Nov  9 14:40:16 2012
@@ -21,9 +21,12 @@ package org.apache.cayenne.tools;
 
 import java.io.File;
 
+import javax.sql.DataSource;
+
+import org.apache.cayenne.configuration.DataNodeDescriptor;
 import org.apache.cayenne.configuration.ToolModule;
+import org.apache.cayenne.configuration.server.DbAdapterFactory;
 import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.di.AdhocObjectFactory;
 import org.apache.cayenne.di.DIBootstrap;
 import org.apache.cayenne.di.Injector;
 import org.apache.cayenne.map.DataMap;
@@ -42,7 +45,7 @@ import org.xml.sax.InputSource;
 public abstract class CayenneTask extends Task {
     protected Path classpath;
 
-    protected DbAdapter adapter;
+    protected String adapter;
     protected File map;
     protected String driver;
     protected String url;
@@ -100,13 +103,7 @@ public abstract class CayenneTask extend
      *            The db adapter to set.
      */
     public void setAdapter(String adapter) {
-        if (adapter != null) {
-            Injector injector = DIBootstrap.createInjector(new ToolModule());
-            AdhocObjectFactory objectFactory = injector
-                    .getInstance(AdhocObjectFactory.class);
-
-            this.adapter = objectFactory.newInstance(DbAdapter.class, adapter);
-        }
+        this.adapter = adapter;
     }
 
     /**
@@ -131,9 +128,6 @@ public abstract class CayenneTask extend
 
     /**
      * Sets the username used to connect to the database server.
-     * 
-     * @param username
-     *            The username to set.
      */
     public void setUserName(String username) {
         this.userName = username;
@@ -154,4 +148,20 @@ public abstract class CayenneTask extend
         InputSource in = new InputSource(map.getCanonicalPath());
         return new MapLoader().loadDataMap(in);
     }
+    
+    protected Injector getInjector() {
+        return DIBootstrap.createInjector(new ToolModule());
+    }
+
+    protected DbAdapter getAdapter(Injector injector, DataSource dataSource)
+            throws Exception {
+
+        DbAdapterFactory adapterFactory = injector
+                .getInstance(DbAdapterFactory.class);
+
+        DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor();
+        nodeDescriptor.setAdapterType(adapter);
+
+        return adapterFactory.createAdapter(nodeDescriptor, dataSource);
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java?rev=1407473&r1=1407472&r2=1407473&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java
(original)
+++ cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java
Fri Nov  9 14:40:16 2012
@@ -26,8 +26,6 @@ import org.apache.cayenne.access.DbGener
 import org.apache.cayenne.configuration.ToolModule;
 import org.apache.cayenne.conn.DriverDataSource;
 import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dba.JdbcAdapter;
-import org.apache.cayenne.di.AdhocObjectFactory;
 import org.apache.cayenne.di.DIBootstrap;
 import org.apache.cayenne.di.Injector;
 import org.apache.cayenne.log.NoopJdbcEventLogger;
@@ -38,8 +36,8 @@ import org.apache.tools.ant.BuildExcepti
 import org.apache.tools.ant.Project;
 
 /**
- * An Ant Task that is a frontend to Cayenne DbGenerator allowing schema generation from
- * DataMap using Ant.
+ * An Ant Task that is a frontend to Cayenne DbGenerator allowing schema
+ * generation from DataMap using Ant.
  * 
  * @since 1.2
  */
@@ -58,29 +56,14 @@ public class DbGeneratorTask extends Cay
     public void execute() {
 
         Injector injector = DIBootstrap.createInjector(new ToolModule());
-        AdhocObjectFactory objectFactory = injector.getInstance(AdhocObjectFactory.class);
-
-        // prepare defaults
-        if (adapter == null) {
-            adapter = objectFactory.newInstance(
-                    DbAdapter.class,
-                    JdbcAdapter.class.getName());
-        }
 
         log(String.format(
                 "connection settings - [driver: %s, url: %s, username: %s]",
-                driver,
-                url,
-                userName), Project.MSG_VERBOSE);
-
-        log(
-                String.format(
-                        "generator options - [dropTables: %s, dropPK: %s, createTables: %s,
createPK: %s, createFK: %s]",
-                        dropTables,
-                        dropPK,
-                        createTables,
-                        createPK,
-                        createFK),
+                driver, url, userName), Project.MSG_VERBOSE);
+
+        log(String.format(
+                "generator options - [dropTables: %s, dropPK: %s, createTables: %s, createPK:
%s, createFK: %s]",
+                dropTables, dropPK, createTables, createPK, createFK),
                 Project.MSG_VERBOSE);
 
         validateAttributes();
@@ -93,11 +76,15 @@ public class DbGeneratorTask extends Cay
 
             // Load the data map and run the db generator.
             DataMap dataMap = loadDataMap();
-            DbGenerator generator = new DbGenerator(
-                    adapter,
-                    dataMap,
-                    Collections.<DbEntity> emptyList(),
-                    null,
+
+            // load driver taking custom CLASSPATH into account...
+            DriverDataSource dataSource = new DriverDataSource((Driver) Class
+                    .forName(driver).newInstance(), url, userName, password);
+
+            DbAdapter adapter = getAdapter(injector, dataSource);
+
+            DbGenerator generator = new DbGenerator(adapter, dataMap,
+                    Collections.<DbEntity> emptyList(), null,
                     NoopJdbcEventLogger.getInstance());
             generator.setShouldCreateFKConstraints(createFK);
             generator.setShouldCreatePKSupport(createPK);
@@ -105,13 +92,8 @@ public class DbGeneratorTask extends Cay
             generator.setShouldDropPKSupport(dropPK);
             generator.setShouldDropTables(dropTables);
 
-            // load driver taking custom CLASSPATH into account...
-            DriverDataSource dataSource = new DriverDataSource((Driver) Class.forName(
-                    driver).newInstance(), url, userName, password);
-
             generator.runGenerator(dataSource);
-        }
-        catch (Exception ex) {
+        } catch (Exception ex) {
             Throwable th = Util.unwindException(ex);
 
             String message = "Error generating database";
@@ -122,15 +104,14 @@ public class DbGeneratorTask extends Cay
 
             log(message, Project.MSG_ERR);
             throw new BuildException(message, th);
-        }
-        finally {
+        } finally {
             Thread.currentThread().setContextClassLoader(loader);
         }
     }
 
     /**
-     * Validates atttributes that are not related to internal DefaultClassGenerator.
-     * Throws BuildException if attributes are invalid.
+     * Validates atttributes that are not related to internal
+     * DefaultClassGenerator. Throws BuildException if attributes are invalid.
      */
     protected void validateAttributes() throws BuildException {
         StringBuilder error = new StringBuilder("");

Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java?rev=1407473&r1=1407472&r2=1407473&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java
(original)
+++ cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java
Fri Nov  9 14:40:16 2012
@@ -26,6 +26,8 @@ import org.apache.cayenne.CayenneExcepti
 import org.apache.cayenne.access.AbstractDbLoaderDelegate;
 import org.apache.cayenne.access.DbLoader;
 import org.apache.cayenne.conn.DriverDataSource;
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.di.Injector;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.ObjEntity;
@@ -76,6 +78,9 @@ public class DbImporterTask extends Caye
             DriverDataSource dataSource = new DriverDataSource((Driver) Class
                     .forName(driver).newInstance(), url, userName, password);
 
+            Injector injector = getInjector();
+            DbAdapter adapter = getAdapter(injector, dataSource);
+
             // Load the data map and run the db importer.
             final LoaderDelegate loaderDelegate = new LoaderDelegate();
             final DbLoader loader = new DbLoader(dataSource.getConnection(),
@@ -101,7 +106,8 @@ public class DbImporterTask extends Caye
             }
 
             if (importProcedures) {
-                loader.loadProcedures(dataMap, catalog, schema, procedurePattern);
+                loader.loadProcedures(dataMap, catalog, schema,
+                        procedurePattern);
             }
 
             // Write the new DataMap out to disk.

Modified: cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbGeneratorTaskTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbGeneratorTaskTest.java?rev=1407473&r1=1407472&r2=1407473&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbGeneratorTaskTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbGeneratorTaskTest.java
Fri Nov  9 14:40:16 2012
@@ -19,9 +19,18 @@
 
 package org.apache.cayenne.tools;
 
+import static org.mockito.Mockito.mock;
+
+import javax.sql.DataSource;
+
 import junit.framework.TestCase;
 
+import org.apache.cayenne.configuration.ToolModule;
+import org.apache.cayenne.dba.AutoAdapter;
+import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.sqlserver.SQLServerAdapter;
+import org.apache.cayenne.di.DIBootstrap;
+import org.apache.cayenne.di.Injector;
 
 public class DbGeneratorTaskTest extends TestCase {
 
@@ -38,9 +47,19 @@ public class DbGeneratorTaskTest extends
     }
 
     public void testSetAdapter() throws Exception {
+        DataSource ds = mock(DataSource.class);
+        Injector injector = DIBootstrap.createInjector(new ToolModule());
+
         DbGeneratorTask task = new DbGeneratorTask();
+        
+        DbAdapter autoAdapter = task.getAdapter(injector, ds);
+        assertTrue(autoAdapter instanceof AutoAdapter);
+        
+        
         task.setAdapter(SQLServerAdapter.class.getName());
-        assertTrue(task.adapter instanceof SQLServerAdapter);
+
+        DbAdapter sqlServerAdapter = task.getAdapter(injector, ds);
+        assertTrue(sqlServerAdapter instanceof SQLServerAdapter);
     }
 
     public void testSetUrl() throws Exception {



Mime
View raw message