repeated executions of the cdbimport results in duplicate object definitions in 
the map file when overwriteExisting=true
------------------------------------------------------------------------------------------------------------------------

                 Key: CAY-1443
                 URL: https://issues.apache.org/jira/browse/CAY-1443
             Project: Cayenne
          Issue Type: Bug
    Affects Versions: 3.0
         Environment: cayenne 3.0
            Reporter: Paul Sprague



There are some problems with repeated executions of the cdbimport goal.

1. we end up with duplicate object definitions in the map file
2. the defaultPackage isn't used in the object definitions the 1st time the map 
file is created

Note that the overwriteExisting property is set to true so to me the entire map 
file should be rebuilt from scratch. This isn't what happens in the maven 
plugin through, the existing map file is instead read in. Changing this 
behavior will ensure the files content doesn't influence subsequent executions 
of the cdbimport goal. However this doesn't fix the case where the 
overwriteExisting property is set to false.

<execution>
    <id>cdbimport</id>
    <configuration>
        <map>${project.build.sourceDirectory}/../resources/**.map.xml</map>
        <overwriteExisting>true</overwriteExisting>
        <schemaName>**</schemaName>
        <tablePattern>T_TIME_ZONE</tablePattern>
        <adapter>org.apache.cayenne.dba.oracle.OracleAdapter</adapter>
        <importProcedures>false</importProcedures>
        <procedurePattern>%</procedurePattern>
        <meaningfulPk>false</meaningfulPk>
        <driver>oracle.jdbc.driver.OracleDriver</driver>
        <url>jdbc:oracle:thin:@**:1521:**</url>
        <username>**</username>
        <password>**</password>
        <defaultPackage>com.test</defaultPackage>
    </configuration>
    <goals>
        <goal>cdbimport</goal>
    </goals>
</execution>

1st execution:

<?xml version="1.0" encoding="utf-8"?>
<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap";
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap 
http://cayenne.apache.org/schema/3.0/modelMap.xsd";
  project-version="3.0.0.1">

        <!-- NOTE: that I have change my local maven plugin to allow 
DataMap.setDefaultPackage to be set through the cdbimport goal -->
        <property name="defaultPackage" value="com.test"/>
        
        <db-entity name="T_TIME_ZONE" schema="**">
                <db-attribute name="JAVA_CODE" type="VARCHAR" 
isMandatory="true" length="50"/>
                <db-attribute name="TIME_ZONE_ID" type="INTEGER" 
isPrimaryKey="true" isMandatory="true" length="22"/>
        </db-entity>
        
        <!-- NOTE: className is wrong? it doesn't contain the package -->
        <obj-entity name="TTimeZone" className="TTimeZone" 
dbEntityName="T_TIME_ZONE">
                <obj-attribute name="javaCode" type="java.lang.String" 
db-attribute-path="JAVA_CODE"/>
        </obj-entity>
</data-map>


2nd execution:

<?xml version="1.0" encoding="utf-8"?>
<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap";
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap 
http://cayenne.apache.org/schema/3.0/modelMap.xsd";
  project-version="3.0.0.1">
        <property name="defaultPackage" value="com.test"/>
        <db-entity name="T_TIME_ZONE" schema="**">
                <db-attribute name="JAVA_CODE" type="VARCHAR" 
isMandatory="true" length="50"/>
                <db-attribute name="TIME_ZONE_ID" type="INTEGER" 
isPrimaryKey="true" isMandatory="true" length="22"/>
        </db-entity>
        
        <!-- NOTE: still doesn't have package -->
        <obj-entity name="TTimeZone" className="TTimeZone">
                <obj-attribute name="javaCode" type="java.lang.String"/>
        </obj-entity>
        
        <!-- ERROR? this one has the default package but this definition 
shouldn't even exist -->
        <obj-entity name="TTimeZone1" className="com.test.TTimeZone1" 
dbEntityName="T_TIME_ZONE">
                <obj-attribute name="javaCode" type="java.lang.String" 
db-attribute-path="JAVA_CODE"/>
        </obj-entity>
</data-map>

================================================================================
================================================================================

Setting overwriteExisting to false

1st execution:

<?xml version="1.0" encoding="utf-8"?>
<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap";
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap 
http://cayenne.apache.org/schema/3.0/modelMap.xsd";
  project-version="3.0.0.1">
        <property name="defaultPackage" value="com.test"/>
        <db-entity name="T_TIME_ZONE" schema="**">
                <db-attribute name="JAVA_CODE" type="VARCHAR" 
isMandatory="true" length="50"/>
                <db-attribute name="TIME_ZONE_ID" type="INTEGER" 
isPrimaryKey="true" isMandatory="true" length="22"/>
        </db-entity>
        <obj-entity name="TTimeZone" className="TTimeZone" 
dbEntityName="T_TIME_ZONE">
                <obj-attribute name="javaCode" type="java.lang.String" 
db-attribute-path="JAVA_CODE"/>
        </obj-entity>
</data-map>

2nd execution:

<?xml version="1.0" encoding="utf-8"?>
<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap";
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap 
http://cayenne.apache.org/schema/3.0/modelMap.xsd";
  project-version="3.0.0.1">
        <property name="defaultPackage" value="com.test"/>
        <db-entity name="T_TIME_ZONE" schema="**">
                <db-attribute name="JAVA_CODE" type="VARCHAR" 
isMandatory="true" length="50"/>
                <db-attribute name="TIME_ZONE_ID" type="INTEGER" 
isPrimaryKey="true" isMandatory="true" length="22"/>
        </db-entity>
        <obj-entity name="TTimeZone" className="TTimeZone" 
dbEntityName="T_TIME_ZONE">
                <obj-attribute name="javaCode" type="java.lang.String" 
db-attribute-path="JAVA_CODE"/>
        </obj-entity>
</data-map>

================================================================================
================================================================================

Changed DbImporterMojo.java:211 so it doesn't load the map file when we are 
overwriting.

final DataMap dataMap = mapFile.exists() && !overwriteExisting ? loadDataMap() 
: new DataMap();

Setting overwriteExisting back to true; appears to fix the duplicate object 
definitions.


1st execution:

<?xml version="1.0" encoding="utf-8"?>
<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap";
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap 
http://cayenne.apache.org/schema/3.0/modelMap.xsd";
  project-version="3.0.0.1">
        <property name="defaultPackage" value="com.test"/>
        <db-entity name="T_TIME_ZONE" schema="**">
                <db-attribute name="JAVA_CODE" type="VARCHAR" 
isMandatory="true" length="50"/>
                <db-attribute name="TIME_ZONE_ID" type="INTEGER" 
isPrimaryKey="true" isMandatory="true" length="22"/>
        </db-entity>
        <obj-entity name="TTimeZone" className="TTimeZone" 
dbEntityName="T_TIME_ZONE">
                <obj-attribute name="javaCode" type="java.lang.String" 
db-attribute-path="JAVA_CODE"/>
        </obj-entity>
</data-map>

2nd execution:

<?xml version="1.0" encoding="utf-8"?>
<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap";
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap 
http://cayenne.apache.org/schema/3.0/modelMap.xsd";
  project-version="3.0.0.1">
        <property name="defaultPackage" value="com.test"/>
        <db-entity name="T_TIME_ZONE" schema="**">
                <db-attribute name="JAVA_CODE" type="VARCHAR" 
isMandatory="true" length="50"/>
                <db-attribute name="TIME_ZONE_ID" type="INTEGER" 
isPrimaryKey="true" isMandatory="true" length="22"/>
        </db-entity>
        <obj-entity name="TTimeZone" className="TTimeZone" 
dbEntityName="T_TIME_ZONE">
                <obj-attribute name="javaCode" type="java.lang.String" 
db-attribute-path="JAVA_CODE"/>
        </obj-entity>
</data-map>




-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to