[hg] main-silver: #223735: Problem was with foreign key used on ...

  • From: Martin Kozeny < >
  • To: , ,
  • Subject: [hg] main-silver: #223735: Problem was with foreign key used on ...
  • Date: Tue, 08 Jan 2013 09:58:40 -0800

changeset 4edeca848040 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/4edeca848040
description:
        #223735: Problem was with foreign key used on customer's zip code. 
Bug was fixed by replacing of setting hard-coded zip code with selected zip 
code from database.

diffstat:

 
apisupport.crudsample/crud-sample-application/CustomerDBAccessLibrary/nbproject/genfiles.properties
                                          |    4 +-
 
apisupport.crudsample/crud-sample-application/CustomerEditor/nbproject/genfiles.properties
                                                   |    4 +-
 
apisupport.crudsample/crud-sample-application/CustomerEditor/src/org/netbeans/modules/customereditor/EditorTopComponent.java
                 |    6 +-
 apisupport.crudsample/crud-sample-application/nbproject/build-impl.xml       
                                                                |    5 +-
 apisupport.crudsample/crud-sample-application/nbproject/genfiles.properties  
                                                                |    9 +-
 apisupport.crudsample/crud-sample-application/nbproject/platform.xml         
                                                                |   34 +++
 maven.samples/samples_src/MavenCRUDSample/crudsample/eclipselink.xml         
                                                                |    1 -
 maven.samples/samples_src/MavenCRUDSample/crudsample/pom.xml                 
                                                                |    1 -
 
maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/java/org/netbeans/modules/crudsampleapplication/dbaccess/MicroMarket.java
      |  108 ++++++++++
 
maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/java/org/netbeans/modules/crudsampleapplication/editor/EditorTopComponent.java
 |    6 +-
 
maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/resources/META-INF/eclipselink.xml
                                             |    1 +
 
maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/resources/META-INF/persistence.xml
                                             |    1 +
 
maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/resources/META-INF/toplink.xml
                                                 |    1 +
 maven.samples/samples_src/MavenCRUDSample/crudsample/toplink.xml             
                                                                |    1 -
 14 files changed, 166 insertions(+), 16 deletions(-)

diffs (331 lines):

diff --git 
a/apisupport.crudsample/crud-sample-application/CustomerDBAccessLibrary/nbproject/genfiles.properties
 
b/apisupport.crudsample/crud-sample-application/CustomerDBAccessLibrary/nbproject/genfiles.properties
--- 
a/apisupport.crudsample/crud-sample-application/CustomerDBAccessLibrary/nbproject/genfiles.properties
+++ 
b/apisupport.crudsample/crud-sample-application/CustomerDBAccessLibrary/nbproject/genfiles.properties
@@ -3,6 +3,6 @@
 build.xml.stylesheet.CRC32=79c3b980@1.34
 # This file is used by a NetBeans-based IDE to track changes in generated 
files such as build-impl.xml.
 # Do not edit this file. You may delete it but then the IDE will never 
regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=552cb7b3
+nbproject/build-impl.xml.data.CRC32=517d2575
 nbproject/build-impl.xml.script.CRC32=345d302b
-nbproject/build-impl.xml.stylesheet.CRC32=261c4bef@1.38
+nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.56
diff --git 
a/apisupport.crudsample/crud-sample-application/CustomerEditor/nbproject/genfiles.properties
 
b/apisupport.crudsample/crud-sample-application/CustomerEditor/nbproject/genfiles.properties
--- 
a/apisupport.crudsample/crud-sample-application/CustomerEditor/nbproject/genfiles.properties
+++ 
b/apisupport.crudsample/crud-sample-application/CustomerEditor/nbproject/genfiles.properties
@@ -1,8 +1,8 @@
 build.xml.data.CRC32=2bb71dcb
 build.xml.script.CRC32=0633455b
-build.xml.stylesheet.CRC32=79c3b980@1.42
+build.xml.stylesheet.CRC32=a56c6a5b@2.56
 # This file is used by a NetBeans-based IDE to track changes in generated 
files such as build-impl.xml.
 # Do not edit this file. You may delete it but then the IDE will never 
regenerate such files for you.
 nbproject/build-impl.xml.data.CRC32=2bb71dcb
 nbproject/build-impl.xml.script.CRC32=8f46581e
-nbproject/build-impl.xml.stylesheet.CRC32=261c4bef@1.42
+nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.56
diff --git 
a/apisupport.crudsample/crud-sample-application/CustomerEditor/src/org/netbeans/modules/customereditor/EditorTopComponent.java
 
b/apisupport.crudsample/crud-sample-application/CustomerEditor/src/org/netbeans/modules/customereditor/EditorTopComponent.java
--- 
a/apisupport.crudsample/crud-sample-application/CustomerEditor/src/org/netbeans/modules/customereditor/EditorTopComponent.java
+++ 
b/apisupport.crudsample/crud-sample-application/CustomerEditor/src/org/netbeans/modules/customereditor/EditorTopComponent.java
@@ -341,18 +341,20 @@
                 fire(false);
                 EntityManager entityManager = 
Persistence.createEntityManagerFactory("CustomerDBAccessPU").createEntityManager();
                 entityManager.getTransaction().begin();
-                if (customer.getCustomerId() != null) {
+                if (customer!=null && customer.getCustomerId() != null) {
                     Customer c = entityManager.find(Customer.class, 
customer.getCustomerId());
                     c.setName(jTextField1.getText());
                     c.setCity(jTextField2.getText());
                     entityManager.getTransaction().commit();
                 } else {
                     Query query = entityManager.createQuery("SELECT 
MAX(c.customerId) FROM Customer c");
+                    Query zipCodeQuery = entityManager.createQuery("SELECT 
m.zipCode FROM MicroMarket m").setMaxResults(1);
                     Integer newId = (Integer) query.getSingleResult() + 1;
+                    customer = new Customer();
                     customer.setCustomerId(newId);
                     customer.setName(jTextField1.getText());
                     customer.setCity(jTextField2.getText());
-                    customer.setZip("12345");
+                    customer.setZip((String)zipCodeQuery.getSingleResult());
                     
customer.setDiscountCode(entityManager.find(DiscountCode.class, 'H'));
                     entityManager.persist(customer);
                     entityManager.getTransaction().commit();
diff --git 
a/apisupport.crudsample/crud-sample-application/nbproject/build-impl.xml 
b/apisupport.crudsample/crud-sample-application/nbproject/build-impl.xml
--- a/apisupport.crudsample/crud-sample-application/nbproject/build-impl.xml
+++ b/apisupport.crudsample/crud-sample-application/nbproject/build-impl.xml
@@ -38,10 +38,11 @@
             </not>
         </condition>
     </fail>
-    <fail message="Cannot find NetBeans build harness. 
${line.separator}Check that nbplatform.${nbplatform.active}.netbeans.dest.dir 
and nbplatform.${nbplatform.active}.harness.dir are defined. 
${line.separator}On a developer machine these are normally defined in 
${user.properties.file}=${netbeans.user}/build.properties 
${line.separator}but for automated builds you should pass these properties to 
Ant explicitly.">
+    <ant antfile="nbproject/platform.xml"/>
+    <fail message="Cannot find NetBeans build harness. 
${line.separator}Check that nbplatform.${nbplatform.active}.netbeans.dest.dir 
and nbplatform.${nbplatform.active}.harness.dir are defined. 
${line.separator}On a developer machine these are normally defined in 
${user.properties.file}=${netbeans.user}/build.properties 
${line.separator}but for automated builds you should pass these properties to 
Ant explicitly. ${line.separator}You may instead download the harness and 
platform: -Dbootstrap.url=.../tasks.jar 
-Dautoupdate.catalog.url=.../updates.xml">
         <condition>
             <not>
-                <available type="dir" file="${harness.dir}"/>
+                <available file="${harness.dir}/suite.xml"/>
             </not>
         </condition>
     </fail>
diff --git 
a/apisupport.crudsample/crud-sample-application/nbproject/genfiles.properties 
b/apisupport.crudsample/crud-sample-application/nbproject/genfiles.properties
--- 
a/apisupport.crudsample/crud-sample-application/nbproject/genfiles.properties
+++ 
b/apisupport.crudsample/crud-sample-application/nbproject/genfiles.properties
@@ -1,8 +1,11 @@
 build.xml.data.CRC32=356ef93f
 build.xml.script.CRC32=5024f1d0
-build.xml.stylesheet.CRC32=531c622b@1.33
+build.xml.stylesheet.CRC32=eaf9f76a@2.56
 # This file is used by a NetBeans-based IDE to track changes in generated 
files such as build-impl.xml.
 # Do not edit this file. You may delete it but then the IDE will never 
regenerate such files for you.
 nbproject/build-impl.xml.data.CRC32=356ef93f
-nbproject/build-impl.xml.script.CRC32=a4bfd33a
-nbproject/build-impl.xml.stylesheet.CRC32=56de960a@1.37
+nbproject/build-impl.xml.script.CRC32=24977a9b
+nbproject/build-impl.xml.stylesheet.CRC32=0f381476@2.56
+nbproject/platform.xml.data.CRC32=356ef93f
+nbproject/platform.xml.script.CRC32=db9e1f43
+nbproject/platform.xml.stylesheet.CRC32=df8ac4dd@2.56
diff --git 
a/apisupport.crudsample/crud-sample-application/nbproject/platform.xml 
b/apisupport.crudsample/crud-sample-application/nbproject/platform.xml
new file mode 100644
--- /dev/null
+++ b/apisupport.crudsample/crud-sample-application/nbproject/platform.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="platform" default="download" basedir="..">
+    <condition property="download.required">
+        <and>
+            <not>
+                <available file="${harness.dir}/suite.xml"/>
+            </not>
+            <isset property="bootstrap.url"/>
+            <isset property="autoupdate.catalog.url"/>
+        </and>
+    </condition>
+    <target name="download" if="download.required">
+        <mkdir dir="${harness.dir}"/>
+        <pathconvert pathsep="|" property="download.clusters">
+            <mapper type="flatten"/>
+            <path path="${cluster.path}"/>
+        </pathconvert>
+        <property name="disabled.modules" value=""/>
+        <pathconvert property="module.includes" pathsep="">
+            <mapper type="glob" from="${basedir}${file.separator}*" 
to="(?!\Q*\E)"/>
+            <path>
+                <filelist files="${disabled.modules}" dir="."/>
+            </path>
+        </pathconvert>
+        <echo message="Downloading clusters ${download.clusters}"/>
+        <property name="tasks.jar" location="${java.io.tmpdir}/tasks.jar"/>
+        <get src="${bootstrap.url}" dest="${tasks.jar}" usetimestamp="true" 
verbose="true"/>
+        <taskdef name="autoupdate" 
classname="org.netbeans.nbbuild.AutoUpdate" classpath="${tasks.jar}"/>
+        <autoupdate installdir="${nbplatform.active.dir}" 
updatecenter="${autoupdate.catalog.url}">
+            <modules includes="${module.includes}.*" 
clusters="${download.clusters}"/>
+            <modules 
includes="org[.]netbeans[.]modules[.]apisupport[.]harness" 
clusters="harness"/>
+        </autoupdate>
+    </target>
+</project>
diff --git 
a/maven.samples/samples_src/MavenCRUDSample/crudsample/eclipselink.xml 
b/maven.samples/samples_src/MavenCRUDSample/crudsample/eclipselink.xml
--- a/maven.samples/samples_src/MavenCRUDSample/crudsample/eclipselink.xml
+++ b/maven.samples/samples_src/MavenCRUDSample/crudsample/eclipselink.xml
@@ -25,7 +25,6 @@
       <groupId>org.apache.derby</groupId>
       <artifactId>derbyclient</artifactId>
       <version>10.5.3.0_1</version>
-      <scope>runtime</scope>
     </dependency>
     <dependency>
       <groupId>org.netbeans.api</groupId>
diff --git a/maven.samples/samples_src/MavenCRUDSample/crudsample/pom.xml 
b/maven.samples/samples_src/MavenCRUDSample/crudsample/pom.xml
--- a/maven.samples/samples_src/MavenCRUDSample/crudsample/pom.xml
+++ b/maven.samples/samples_src/MavenCRUDSample/crudsample/pom.xml
@@ -26,7 +26,6 @@
       <groupId>org.apache.derby</groupId>
       <artifactId>derbyclient</artifactId>
       <version>10.5.3.0_1</version>
-      <scope>runtime</scope>
     </dependency>
     <dependency>
       <groupId>org.netbeans.api</groupId>
diff --git 
a/maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/java/org/netbeans/modules/crudsampleapplication/dbaccess/MicroMarket.java
 
b/maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/java/org/netbeans/modules/crudsampleapplication/dbaccess/MicroMarket.java
new file mode 100644
--- /dev/null
+++ 
b/maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/java/org/netbeans/modules/crudsampleapplication/dbaccess/MicroMarket.java
@@ -0,0 +1,108 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.netbeans.modules.crudsampleapplication.dbaccess;
+
+import java.io.Serializable;
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ *
+ * @author mkozeny
+ */
+@Entity
+@Table(name = "MICRO_MARKET")
+@XmlRootElement
+@NamedQueries({
+    @NamedQuery(name = "MicroMarket.findAll", query = "SELECT m FROM 
MicroMarket m"),
+    @NamedQuery(name = "MicroMarket.findByZipCode", query = "SELECT m FROM 
MicroMarket m WHERE m.zipCode = :zipCode"),
+    @NamedQuery(name = "MicroMarket.findByRadius", query = "SELECT m FROM 
MicroMarket m WHERE m.radius = :radius"),
+    @NamedQuery(name = "MicroMarket.findByAreaLength", query = "SELECT m 
FROM MicroMarket m WHERE m.areaLength = :areaLength"),
+    @NamedQuery(name = "MicroMarket.findByAreaWidth", query = "SELECT m FROM 
MicroMarket m WHERE m.areaWidth = :areaWidth")})
+public class MicroMarket implements Serializable {
+    private static final long serialVersionUID = 1L;
+    @Id
+    @Basic(optional = false)
+    @Column(name = "ZIP_CODE")
+    private String zipCode;
+    // @Max(value=?)  @Min(value=?)//if you know range of your decimal 
fields consider using these annotations to enforce field validation
+    @Column(name = "RADIUS")
+    private Double radius;
+    @Column(name = "AREA_LENGTH")
+    private Double areaLength;
+    @Column(name = "AREA_WIDTH")
+    private Double areaWidth;
+
+    public MicroMarket() {
+    }
+
+    public MicroMarket(String zipCode) {
+        this.zipCode = zipCode;
+    }
+
+    public String getZipCode() {
+        return zipCode;
+    }
+
+    public void setZipCode(String zipCode) {
+        this.zipCode = zipCode;
+    }
+
+    public Double getRadius() {
+        return radius;
+    }
+
+    public void setRadius(Double radius) {
+        this.radius = radius;
+    }
+
+    public Double getAreaLength() {
+        return areaLength;
+    }
+
+    public void setAreaLength(Double areaLength) {
+        this.areaLength = areaLength;
+    }
+
+    public Double getAreaWidth() {
+        return areaWidth;
+    }
+
+    public void setAreaWidth(Double areaWidth) {
+        this.areaWidth = areaWidth;
+    }
+
+    @Override
+    public int hashCode() {
+        int hash = 0;
+        hash += (zipCode != null ? zipCode.hashCode() : 0);
+        return hash;
+    }
+
+    @Override
+    public boolean equals(Object object) {
+        // TODO: Warning - this method won't work in the case the id fields 
are not set
+        if (!(object instanceof MicroMarket)) {
+            return false;
+        }
+        MicroMarket other = (MicroMarket) object;
+        if ((this.zipCode == null && other.zipCode != null) || (this.zipCode 
!= null && !this.zipCode.equals(other.zipCode))) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return 
"org.netbeans.modules.crudsampleapplication.dbaccess.MicroMarket[ zipCode=" + 
zipCode + " ]";
+    }
+    
+}
diff --git 
a/maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/java/org/netbeans/modules/crudsampleapplication/editor/EditorTopComponent.java
 
b/maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/java/org/netbeans/modules/crudsampleapplication/editor/EditorTopComponent.java
--- 
a/maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/java/org/netbeans/modules/crudsampleapplication/editor/EditorTopComponent.java
+++ 
b/maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/java/org/netbeans/modules/crudsampleapplication/editor/EditorTopComponent.java
@@ -341,18 +341,20 @@
                 fire(false);
                 EntityManager entityManager = 
Persistence.createEntityManagerFactory("CustomerDBAccessPU").createEntityManager();
                 entityManager.getTransaction().begin();
-                if (customer.getCustomerId() != null) {
+                if (customer!=null && customer.getCustomerId() != null) {
                     Customer c = entityManager.find(Customer.class, 
customer.getCustomerId());
                     c.setName(jTextField1.getText());
                     c.setCity(jTextField2.getText());
                     entityManager.getTransaction().commit();
                 } else {
                     Query query = entityManager.createQuery("SELECT 
MAX(c.customerId) FROM Customer c");
+                    Query zipCodeQuery = entityManager.createQuery("SELECT 
m.zipCode FROM MicroMarket m").setMaxResults(1);
                     Integer newId = (Integer) query.getSingleResult() + 1;
+                    customer = new Customer();
                     customer.setCustomerId(newId);
                     customer.setName(jTextField1.getText());
                     customer.setCity(jTextField2.getText());
-                    customer.setZip("12345");
+                    customer.setZip((String)zipCodeQuery.getSingleResult());
                     
customer.setDiscountCode(entityManager.find(DiscountCode.class, 'H'));
                     entityManager.persist(customer);
                     entityManager.getTransaction().commit();
diff --git 
a/maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/resources/META-INF/eclipselink.xml
 
b/maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/resources/META-INF/eclipselink.xml
--- 
a/maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/resources/META-INF/eclipselink.xml
+++ 
b/maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/resources/META-INF/eclipselink.xml
@@ -4,6 +4,7 @@
     <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
     
<class>org.netbeans.modules.crudsampleapplication.dbaccess.Customer</class>
     
<class>org.netbeans.modules.crudsampleapplication.dbaccess.DiscountCode</class>
+    
<class>org.netbeans.modules.crudsampleapplication.dbaccess.MicroMarket</class>
     <properties>
       <property name="javax.persistence.jdbc.url" 
value="jdbc:derby://localhost:1527/sample"/>
       <property name="javax.persistence.jdbc.password" value="app"/>
diff --git 
a/maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/resources/META-INF/persistence.xml
 
b/maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/resources/META-INF/persistence.xml
--- 
a/maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/resources/META-INF/persistence.xml
+++ 
b/maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/resources/META-INF/persistence.xml
@@ -4,6 +4,7 @@
     <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
     
<class>org.netbeans.modules.crudsampleapplication.dbaccess.Customer</class>
     
<class>org.netbeans.modules.crudsampleapplication.dbaccess.DiscountCode</class>
+    
<class>org.netbeans.modules.crudsampleapplication.dbaccess.MicroMarket</class>
     <properties>
       <property name="javax.persistence.jdbc.url" 
value="jdbc:derby://localhost:1527/sample"/>
       <property name="javax.persistence.jdbc.password" value="app"/>
diff --git 
a/maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/resources/META-INF/toplink.xml
 
b/maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/resources/META-INF/toplink.xml
--- 
a/maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/resources/META-INF/toplink.xml
+++ 
b/maven.samples/samples_src/MavenCRUDSample/crudsample/src/main/resources/META-INF/toplink.xml
@@ -4,6 +4,7 @@
     <provider>oracle.toplink.essentials.PersistenceProvider</provider>
     
<class>org.netbeans.modules.crudsampleapplication.dbaccess.Customer</class>
     
<class>org.netbeans.modules.crudsampleapplication.dbaccess.DiscountCode</class>
+    
<class>org.netbeans.modules.crudsampleapplication.dbaccess.MicroMarket</class>
     <properties>
       <property name="toplink.jdbc.user" value="app"/>
       <property name="toplink.jdbc.password" value="app"/>
diff --git a/maven.samples/samples_src/MavenCRUDSample/crudsample/toplink.xml 
b/maven.samples/samples_src/MavenCRUDSample/crudsample/toplink.xml
--- a/maven.samples/samples_src/MavenCRUDSample/crudsample/toplink.xml
+++ b/maven.samples/samples_src/MavenCRUDSample/crudsample/toplink.xml
@@ -25,7 +25,6 @@
       <groupId>org.apache.derby</groupId>
       <artifactId>derbyclient</artifactId>
       <version>10.5.3.0_1</version>
-      <scope>runtime</scope>
     </dependency>
     <dependency>
       <groupId>org.netbeans.api</groupId>

[hg] main-silver: #223735: Problem was with foreign key used on ...

Martin Kozeny 01/08/2013

<Possible follow-up(s)>

[hg] main-silver: #223735: Problem was with foreign key used on ...

Martin Kozeny 01/08/2013

Project Features

About this Project

APIsupport was started in November 2009, is owned by Antonin Nebuzelsky, and has 43 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close