cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmen...@apache.org
Subject svn commit: r764350 - /cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
Date Mon, 13 Apr 2009 02:04:33 GMT
Author: kmenard
Date: Mon Apr 13 02:04:32 2009
New Revision: 764350

URL: http://svn.apache.org/viewvc?rev=764350&view=rev
Log:
CAY-1029: maven2 plugin to reverse engineer database

Configure overwriting existing entities and added update delete rules feature.

Modified:
    cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java

Modified: cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java?rev=764350&r1=764349&r2=764350&view=diff
==============================================================================
--- cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
(original)
+++ cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
Mon Apr 13 02:04:32 2009
@@ -12,6 +12,7 @@
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.util.Util;
+import org.apache.cayenne.util.DeleteRuleUpdater;
 import org.apache.cayenne.conn.DriverDataSource;
 import org.apache.cayenne.CayenneException;
 import org.apache.commons.logging.Log;
@@ -20,6 +21,8 @@
 import java.io.File;
 import java.io.PrintWriter;
 import java.sql.Driver;
+import java.util.List;
+import java.util.ArrayList;
 
 /**
  * Maven mojo to reverse engineer datamap from DB.
@@ -40,6 +43,15 @@
 	private String map;
 
     /**
+     * Indicates whether existing DB and object entities should be overwritten.
+     * This is an all-or-nothing setting.  If you need finer granularity, please
+     * use the Cayenne Modeler.
+     *
+     * @parameter expression="${cdbimport.overwriteExisting}" default-value="true"
+     */
+    private boolean overwriteExisting;
+
+    /**
      * DB schema to use for DB importing.
      *
      * @parameter expression="${cdbimport.schemaName}"
@@ -112,10 +124,18 @@
      */
     private String password;
 
-
+    /**
+     * Maven logger.
+     */
     private Log logger;
+
+    /**
+     * The DataMap file to use for importing.
+     */
     private File mapFile;
 
+    private List<ObjEntity> addedObjEntities = new ArrayList<ObjEntity>();
+
     public void execute() throws MojoExecutionException, MojoFailureException {
 
         logger = new MavenLogger(this);
@@ -139,6 +159,10 @@
             final DataMap dataMap = mapFile.exists() ? loadDataMap() : new DataMap();
             loader.loadDataMapFromDB(schemaName, tablePattern, dataMap);
 
+            for (ObjEntity addedObjEntity : addedObjEntities) {
+                    DeleteRuleUpdater.updateObjEntity(addedObjEntity);
+                }
+
             if (importProcedures) {
                 loader.loadProceduresFromDB(schemaName, procedurePattern, dataMap);
             }
@@ -165,7 +189,7 @@
     final class LoaderDelegate implements DbLoaderDelegate {
 
         public boolean overwriteDbEntity(final DbEntity ent) throws CayenneException {
-            return true;
+            return overwriteExisting;
         }
 
         public void dbEntityAdded(final DbEntity ent) {
@@ -180,6 +204,7 @@
 
         public void objEntityAdded(final ObjEntity ent) {
             logger.info("Added obj entity: " + ent.getName());
+            addedObjEntities.add(ent);
             ent.getDataMap().addObjEntity(ent);
         }
 



Mime
View raw message