cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dkazimirc...@apache.org
Subject svn commit: r1178712 - in /cayenne/main/trunk/framework: cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java cayenne-tools/src/main/resources/templates/v1_2/superclass.vm
Date Tue, 04 Oct 2011 07:57:41 GMT
Author: dkazimirchyk
Date: Tue Oct  4 07:57:40 2011
New Revision: 1178712

URL: http://svn.apache.org/viewvc?rev=1178712&view=rev
Log:
CAY-1622 Generated classes shouldn't produce serialVersionUID compiler warning

added getSerialVersionUID method to ObjEntity and updated Velocity template

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
    cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/superclass.vm

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java?rev=1178712&r1=1178711&r2=1178712&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
Tue Oct  4 07:57:40 2011
@@ -19,6 +19,9 @@
 
 package org.apache.cayenne.map;
 
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.security.MessageDigest;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -1250,5 +1253,42 @@ public class ObjEntity extends Entity im
     public void setExcludingSuperclassListeners(boolean excludingSuperclassListeners) {
         this.excludingSuperclassListeners = excludingSuperclassListeners;
     }
+    
+    /**
+     * Returns unique id for this ObjEntity.
+     * 
+     * @since 3.1
+     */
+    public long getSerialVersionUID() throws Exception {
+        ByteArrayOutputStream bout = new ByteArrayOutputStream();
+        DataOutputStream dout = new DataOutputStream(bout);
+            
+        dout.writeUTF(getClassName());
+        
+        if (getSuperClassName() != null) {
+            dout.writeUTF(getSuperClassName());
+        }
+  
+        for (ObjAttribute attr : getAttributes()) {
+            dout.writeUTF(attr.getName());
+            dout.writeUTF(attr.getType());
+        }
+        
+        for (ObjRelationship rel : getRelationships()) {
+            dout.writeUTF(rel.getName());
+            dout.writeUTF(rel.getCollectionType() != null 
+                    ? rel.getCollectionType() : "to-one");
+        }
+
+        dout.flush();
+
+        MessageDigest md = MessageDigest.getInstance("SHA");
+        byte[] hashBytes = md.digest(bout.toByteArray());
+        long hash = 0;
+        for (int i = Math.min(hashBytes.length, 8) - 1; i >= 0; i--) {
+            hash = (hash << 8) | (hashBytes[i] & 0xFF);
+        }
+        return hash;
+    }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/superclass.vm
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/superclass.vm?rev=1178712&r1=1178711&r2=1178712&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/superclass.vm
(original)
+++ cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/superclass.vm
Tue Oct  4 07:57:40 2011
@@ -54,6 +54,9 @@ ${importUtils.generate()}
  */
 public abstract class ${superClassName} extends ${baseClassName} {
 
+## SerialVersionUID
+    private static final long serialVersionUID = ${object.SerialVersionUID}L;
+
 ## Create property names
 #foreach( $attr in ${object.DeclaredAttributes} )
     public static final String ${stringUtils.capitalizedAsConstant($attr.Name)}_PROPERTY
= "${attr.Name}";



Mime
View raw message