openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r1133546 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence/src/main/java/org/apache/openjpa/persistence/
Date Wed, 08 Jun 2011 20:19:04 GMT
Author: mikedd
Date: Wed Jun  8 20:19:03 2011
New Revision: 1133546

URL: http://svn.apache.org/viewvc?rev=1133546&view=rev
Log:
OPENJPA-2010: Check line number and source file before logging duplicate meta data warning

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataTool.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/QueryMetaData.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java?rev=1133546&r1=1133545&r2=1133546&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
Wed Jun  8 20:19:03 2011
@@ -529,11 +529,12 @@ public class MappingTool
             if (_mappingWriter != null) {
                 output = new HashMap<File, String>();
                 File tmp = new File("openjpatmp");
-                for (int i = 0; i < mappings.length; i++)
-                    mappings[i].setSource(tmp, SourceTracker.SRC_OTHER);
-                for (int i = 0; i < queries.length; i++)
-                    queries[i].setSource(tmp, queries[i].getSourceScope(),
-                        SourceTracker.SRC_OTHER);
+                for (int i = 0; i < mappings.length; i++) {
+                    mappings[i].setSource(tmp, SourceTracker.SRC_OTHER, "openjpatmp");
+                }
+                for (int i = 0; i < queries.length; i++) {
+                    queries[i].setSource(tmp, queries[i].getSourceScope(), SourceTracker.SRC_OTHER,
"openjpatmp");
+                }
                 for (int i = 0; i < seqs.length; i++)
                     seqs[i].setSource(tmp, seqs[i].getSourceScope(),
                         SourceTracker.SRC_OTHER);
@@ -708,7 +709,7 @@ public class MappingTool
                 && fmds[i].getDeclaredType() != Object.class)
                 fmds[i].setDeclaredTypeCode(JavaTypes.PC);
         }
-        meta.setSource(_file, meta.getSourceType());
+        meta.setSource(_file, meta.getSourceType(), _file == null ? "": _file.getPath() );
         meta.setResolve(MODE_META, true);
     }
 

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java?rev=1133546&r1=1133545&r2=1133546&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
Wed Jun  8 20:19:03 2011
@@ -381,10 +381,11 @@ public abstract class AbstractCFMetaData
             if (queries[i].getSourceMode() == MODE_QUERY
                 || (mode & queries[i].getSourceMode()) == 0)
                 continue;
-            if (queries[i].getSourceFile() == null)
-                queries[i].setSource(defaultSourceFile(queries[i],
-                    clsNames), queries[i].getSourceScope(),
-                    queries[i].getSourceType());
+            if (queries[i].getSourceFile() == null) {
+                File defaultFile = defaultSourceFile(queries[i], clsNames);
+                queries[i].setSource(defaultFile, queries[i].getSourceScope(), queries[i].getSourceType(),
+                    defaultFile == null ? "" : defaultFile.getPath());
+            }
             if ((AccessController.doPrivileged(
                 J2DoPrivHelper.existsAction(queries[i].getSourceFile())))
                 .booleanValue()) {
@@ -423,9 +424,11 @@ public abstract class AbstractCFMetaData
         for (int i = 0; i < queries.length; i++) {
             if (queries[i].getSourceMode() != MODE_QUERY)
                 continue;
-            if (queries[i].getSourceFile() == null)
-                queries[i].setSource(defaultSourceFile(queries[i], clsNames),
-                    queries[i].getSourceScope(), queries[i].getSourceType());
+            if (queries[i].getSourceFile() == null) {
+                File defaultFile = defaultSourceFile(queries[i], clsNames);
+                queries[i].setSource(defaultFile, queries[i].getSourceScope(), queries[i].getSourceType(),
+                    defaultFile == null ? "" : defaultFile.getPath());
+            }
             if ((AccessController.doPrivileged(
                 J2DoPrivHelper.existsAction(queries[i].getSourceFile())))
                 .booleanValue()) {
@@ -522,7 +525,8 @@ public abstract class AbstractCFMetaData
      * Set the current source file of the given metadata.
      */
     protected void setSourceFile(ClassMetaData meta, File sourceFile) {
-        meta.setSource(sourceFile, meta.getSourceType());
+        meta.setSource(sourceFile, meta.getSourceType(), sourceFile != null ? 
+            sourceFile.getPath() : "");
     }
 
     /**

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java?rev=1133546&r1=1133545&r2=1133546&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
Wed Jun  8 20:19:03 2011
@@ -145,6 +145,7 @@ public class ClassMetaData
     private final ValueMetaData _owner;
     private final LifecycleMetaData _lifeMeta = new LifecycleMetaData(this);
     private File _srcFile = null;
+    private String _srcName = null;
     private int _srcType = SRC_OTHER;
     private int _lineNum = 0;  
     private int _colNum = 0;  
@@ -2403,9 +2404,10 @@ public class ClassMetaData
         return _srcType;
     }
 
-    public void setSource(File file, int srcType) {
+    public void setSource(File file, int srcType, String srcName) {
         _srcFile = file;
         _srcType = srcType;
+        _srcName = srcName;
     }
 
     public String getResourceName() {
@@ -2757,5 +2759,9 @@ public class ClassMetaData
             return _cacheEnabled;
         return getPCSuperclassMetaData() != null ?  getPCSuperclassMetaData().getCacheEnabled()
: null; 
     }
+    
+    public String getSourceName(){
+        return _srcName; 
+    }
 }
 

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataTool.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataTool.java?rev=1133546&r1=1133545&r2=1133546&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataTool.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataTool.java Wed
Jun  8 20:19:03 2011
@@ -175,7 +175,7 @@ public class MetaDataTool
                 && fmds[i].getDeclaredType() != Object.class)
                 fmds[i].setDeclaredTypeCode(JavaTypes.PC);
         }
-        meta.setSource(_file, meta.getSourceType());
+        meta.setSource(_file, meta.getSourceType(), _file == null ? "" : _file.getPath());
         _flush = true;
     }
 
@@ -205,7 +205,7 @@ public class MetaDataTool
                 output = new HashMap();
                 File tmp = new File("openjpatmp");
                 for (int i = 0; i < metas.length; i++)
-                    metas[i].setSource(tmp, metas[i].getSourceType());
+                    metas[i].setSource(tmp, metas[i].getSourceType(), tmp.getPath());
             }
             if (!mdf.store(metas, new QueryMetaData[0],
                 new SequenceMetaData[0], MODE_META, output))

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/QueryMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/QueryMetaData.java?rev=1133546&r1=1133545&r2=1133546&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/QueryMetaData.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/QueryMetaData.java
Wed Jun  8 20:19:03 2011
@@ -57,7 +57,8 @@ public class QueryMetaData
     private List _hintVals;
     private String _resultSetMappingName;
     private int _lineNum;  
-    private int _colNum;  
+    private int _colNum;
+    private String _srcName; 
 
     /**
      * Construct with the given name.
@@ -268,10 +269,11 @@ public class QueryMetaData
         return _srcType;
     }
 
-    public void setSource(File file, Object scope, int srcType) {
+    public void setSource(File file, Object scope, int srcType, String srcName) {
         _file = file;
         _scope = scope;
         _srcType = srcType;
+        _srcName = srcName;
     }
 
     public String getResourceName() {
@@ -293,4 +295,8 @@ public class QueryMetaData
     public void setColNumber(int colNum) {
         _colNum = colNum;
     }
+    
+    public String getSourceName() {
+        return _srcName;
+    }
 }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java?rev=1133546&r1=1133545&r2=1133546&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
Wed Jun  8 20:19:03 2011
@@ -733,12 +733,18 @@ public class AnnotationPersistenceMetaDa
      */
     private ClassMetaData getMetaData() {
         ClassMetaData meta = getRepository().getCachedMetaData(_cls);
-        if (meta != null &&
-            ((isMetaDataMode() && (meta.getSourceMode() & MODE_META) != 0) ||
-                (isMappingMode() &&
-                    (meta.getSourceMode() & MODE_MAPPING) != 0))) {
-            if (_log.isWarnEnabled())
+        if (meta != null
+            && ((isMetaDataMode() 
+                && (meta.getSourceMode() & MODE_META) != 0) 
+                || (isMappingMode() && (meta.getSourceMode() & MODE_MAPPING)
!= 0) ) ) {
+            if (_log.isWarnEnabled()) {
                 _log.warn(_loc.get("dup-metadata", _cls.getName()));
+            }
+            if(_log.isTraceEnabled()) { 
+                _log.trace(String.format(
+                    "MetaData originally obtained from file: %s under mode :%d with scope
%s, and type :%d",
+                    meta.getSourceName(), meta.getSourceMode(), meta.getSourceScope(), meta.getSourceType()));
+            }
             return null;
         }
 
@@ -746,7 +752,8 @@ public class AnnotationPersistenceMetaDa
             meta = getRepository().addMetaData(_cls, getAccessCode(_cls));
             meta.setEnvClassLoader(_envLoader);
             meta.setSourceMode(MODE_NONE);
-            meta.setSource(getSourceFile(), SourceTracker.SRC_ANNOTATIONS);
+            meta.setSource(getSourceFile(), SourceTracker.SRC_ANNOTATIONS, getSourceFile()
== null ? ""
+                : getSourceFile().getPath());
         }
         return meta;
     }
@@ -1825,7 +1832,7 @@ public class AnnotationPersistenceMetaDa
             }
 
             meta.setSource(getSourceFile(), (el instanceof Class) ? el : null,
-                SourceTracker.SRC_ANNOTATIONS);
+                SourceTracker.SRC_ANNOTATIONS, getSourceFile() == null ? "" : getSourceFile().getPath());
             if (isMetaDataMode())
                 meta.setSourceMode(MODE_META);
             else if (isMappingMode())
@@ -1902,7 +1909,7 @@ public class AnnotationPersistenceMetaDa
                 meta.addHint(hint.name(), hint.value());
 
             meta.setSource(getSourceFile(), (el instanceof Class) ? el : null,
-                SourceTracker.SRC_ANNOTATIONS);
+                SourceTracker.SRC_ANNOTATIONS, getSourceFile() == null ? "" : getSourceFile().getPath());
             if (isMetaDataMode())
                 meta.setSourceMode(MODE_META);
             else if (isMappingMode())

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java?rev=1133546&r1=1133545&r2=1133546&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
Wed Jun  8 20:19:03 2011
@@ -879,12 +879,20 @@ public class XMLPersistenceMetaDataParse
             && ((isMetaDataMode() && (meta.getSourceMode() & MODE_META)
!= 0)
             || (isMappingMode() && (meta.getSourceMode() & MODE_MAPPING) != 0)))
         {
-            if (log.isWarnEnabled())
-                log.warn(_loc.get("dup-metadata", _cls, getSourceName()));
+            if(isDuplicateClass(meta)) { 
+                if (log.isWarnEnabled()) {
+                    log.warn(_loc.get("dup-metadata", _cls, getSourceName()));
+                }
+                if(log.isTraceEnabled()) { 
+                    log.trace(String.format(
+                        "MetaData originally obtained from source: %s under mode: %d with
scope: %s, and type: %d",
+                        meta.getSourceName(), meta.getSourceMode(), meta.getSourceScope(),
meta.getSourceType()));
+                }
+            }
             _cls = null;
             return false;
         }
-
+        
         int access = AccessCode.UNKNOWN;
         if (meta == null) {
             int accessCode = toAccessType(attrs.getValue("access"));
@@ -904,17 +912,20 @@ public class XMLPersistenceMetaDataParse
             meta.setSourceMode(MODE_NONE);
 
             // parse annotations first so XML overrides them
-            if (_parser != null)
+            if (_parser != null) {
                 _parser.parse(_cls);
+            }
         }
         access = meta.getAccessType();
 
         boolean mappedSuper = "mapped-superclass".equals(elem);
         boolean embeddable = "embeddable".equals(elem);
+
         if (isMetaDataMode()) {
-            meta.setSource(getSourceFile(), SourceTracker.SRC_XML);
-            meta.setSourceMode(MODE_META, true);
             Locator locator = getLocation().getLocator();
+            meta.setSource(getSourceFile(), SourceTracker.SRC_XML, locator != null ? locator.getSystemId()
: "" );
+            meta.setSourceMode(MODE_META, true);
+        
             if (locator != null) {
                 meta.setLineNumber(locator.getLineNumber());
                 meta.setColNumber(locator.getColumnNumber());
@@ -1705,7 +1716,7 @@ public class XMLPersistenceMetaDataParse
         Object cur = currentElement();
         Object scope = (cur instanceof ClassMetaData)
             ? ((ClassMetaData) cur).getDescribedType() : null;
-        meta.setSource(getSourceFile(), scope, SourceTracker.SRC_XML);
+        meta.setSource(getSourceFile(), scope, SourceTracker.SRC_XML, locator == null ? ""
: locator.getSystemId());
         if (isMetaDataMode())
             meta.setSourceMode(MODE_META);
         else if (isMappingMode())
@@ -1788,8 +1799,9 @@ public class XMLPersistenceMetaDataParse
             log.trace(_loc.get("parse-native-query", name));
 
         QueryMetaData meta = getRepository().getCachedQueryMetaData(null, name);
-        if (meta != null && log.isWarnEnabled())
+        if (meta != null && isDuplicateQuery(meta) ) {
             log.warn(_loc.get("override-query", name, currentLocation()));
+        }
 
         meta = getRepository().addQueryMetaData(null, name);
         meta.setDefiningType(_cls);
@@ -1809,10 +1821,9 @@ public class XMLPersistenceMetaDataParse
             meta.setResultSetMappingName(val);
 
         Object cur = currentElement();
-        Object scope = (cur instanceof ClassMetaData)
-            ? ((ClassMetaData) cur).getDescribedType() : null;
-        meta.setSource(getSourceFile(), scope, SourceTracker.SRC_XML);
+        Object scope = (cur instanceof ClassMetaData) ? ((ClassMetaData) cur).getDescribedType()
: null;
         Locator locator = getLocation().getLocator();
+        meta.setSource(getSourceFile(), scope, SourceTracker.SRC_XML, locator == null ? ""
: locator.getSystemId());
         if (locator != null) {
             meta.setLineNumber(locator.getLineNumber());
             meta.setColNumber(locator.getColumnNumber());
@@ -2190,4 +2201,47 @@ public class XMLPersistenceMetaDataParse
     protected String normalizeCatalogName(String catName) {
         return catName;
     }
+
+    /**
+     * Determines whether the ClassMetaData has been resolved more than once. Compares the
current sourceName and
+     * linenumber to the ones used to originally resolve the metadata.
+     * 
+     * @param meta The ClassMetaData to inspect.
+     * @return true if the source was has already been resolved from a different location.
Otherwise return false
+     */
+    protected boolean isDuplicateClass(ClassMetaData meta) {
+        if (!StringUtils.equals(getSourceName(), meta.getSourceName())) {
+            return true;
+        }
+
+        if (getLineNum() != meta.getLineNumber()) {
+            return true;
+        }
+        return false;
+    }
+    
+    /**
+     * Determines whether the QueryMetaData has been resolved more than once.
+     * @param meta QueryMetaData that has already been resolved. 
+     * @return true if the QueryMetaData was defined in a different place - e.g. another
line in orm.xml.
+     */
+    protected boolean isDuplicateQuery(QueryMetaData meta) { 
+        if(! StringUtils.equals(getSourceName(), meta.getSourceName())) {
+            return true;
+        }
+        if(getLineNum() != meta.getLineNumber()) { 
+            return true;
+        }
+        return false; 
+            
+    }
+    
+    private int getLineNum() { 
+        int lineNum = 0;
+        Locator loc = getLocation().getLocator();
+        if(loc != null ) {
+            lineNum = loc.getLineNumber();
+        }
+        return lineNum;
+    }
 }



Mime
View raw message