From bb937f36342618164196ab21230576a349dea445 Mon Sep 17 00:00:00 2001 From: Fay Wang Date: Thu, 20 Nov 2008 18:16:46 +0000 Subject: [PATCH] OPENJPA-742: add get lineNumber/ColumnNumber to SourceTracker git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@719314 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/jdbc/meta/ClassMappingInfo.java | 20 ++++++++++++++++ .../openjpa/jdbc/meta/QueryResultMapping.java | 18 ++++++++++++++ .../apache/openjpa/jdbc/schema/Sequence.java | 18 ++++++++++++++ .../org/apache/openjpa/jdbc/schema/Table.java | 18 ++++++++++++++ .../openjpa/jdbc/schema/XMLSchemaParser.java | 13 ++++++++++ .../apache/openjpa/meta/ClassMetaData.java | 19 +++++++++++++++ .../openjpa/meta/NonPersistentMetaData.java | 19 +++++++++++++++ .../apache/openjpa/meta/QueryMetaData.java | 19 +++++++++++++++ .../apache/openjpa/meta/SequenceMetaData.java | 18 ++++++++++++++ .../openjpa/lib/meta/SourceTracker.java | 11 +++++++++ .../jdbc/XMLPersistenceMappingParser.java | 14 +++++++++-- ...notationPersistenceMetaDataSerializer.java | 16 +++++++++++++ .../persistence/PersistenceUnitInfoImpl.java | 8 +++++++ .../XMLPersistenceMetaDataParser.java | 24 ++++++++++++++++++- .../XMLPersistenceMetaDataSerializer.java | 16 +++++++++++++ 15 files changed, 248 insertions(+), 3 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java index d743c0a26..204a5bdbf 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java @@ -67,6 +67,9 @@ public class ClassMappingInfo private File _file = null; private int _srcType = SRC_OTHER; private String[] _comments = null; + private int _lineNum = 0; + private int _colNum = 0; + // Unique constraints indexed by primary or secondary table name private Map> _uniques; @@ -471,4 +474,21 @@ public class ClassMappingInfo public void setComments(String[] comments) { _comments = comments; } + + public int getLineNumber() { + return _lineNum; + } + + public void setLineNumber(int lineNum) { + _lineNum = lineNum; + } + + public int getColNumber() { + return _colNum; + } + + public void setColNumber(int colNum) { + _colNum = colNum; + } + } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/QueryResultMapping.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/QueryResultMapping.java index 3c07fc2fb..b724ae693 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/QueryResultMapping.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/QueryResultMapping.java @@ -57,6 +57,8 @@ public class QueryResultMapping private File _file = null; private Object _scope = null; private int _srcType = SRC_OTHER; + private int _lineNum = 0; + private int _colNum = 0; private int _mode = MODE_QUERY; private Class _class = null; private int _idx = 0; @@ -224,6 +226,22 @@ public class QueryResultMapping public String getResourceName() { return (_class == null) ? _name : _class.getName() + ":" + _name; } + + public int getLineNumber() { + return _lineNum; + } + + public void setLineNumber(int lineNum) { + _lineNum = lineNum; + } + + public int getColNumber() { + return _colNum; + } + + public void setColNumber(int colNum) { + _colNum = colNum; + } /** * A persistence-capable result. diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Sequence.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Sequence.java index 33caa9fa6..cde443b99 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Sequence.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Sequence.java @@ -38,6 +38,8 @@ public class Sequence private int _initial = 1; private int _increment = 1; private int _cache = 0; + private int _lineNum = 0; + private int _colNum = 0; // keep track of source private File _source = null; @@ -206,4 +208,20 @@ public class Sequence public String toString() { return getFullName(); } + + public int getLineNumber() { + return _lineNum; + } + + public void setLineNumber(int lineNum) { + _lineNum = lineNum; + } + + public int getColNumber() { + return _colNum; + } + + public void setColNumber(int colNum) { + _colNum = colNum; + } } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java index e30d0f648..1f834b960 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java @@ -61,6 +61,8 @@ public class Table private Index[] _idxs = null; private Unique[] _unqs = null; private String _comment = null; + private int _lineNum = 0; + private int _colNum = 0; /** * Default constructor. @@ -718,4 +720,20 @@ public class Table public void setComment(String comment) { _comment = comment; } + + public int getLineNumber() { + return _lineNum; + } + + public void setLineNumber(int lineNum) { + _lineNum = lineNum; + } + + public int getColNumber() { + return _colNum; + } + + public void setColNumber(int colNum) { + _colNum = colNum; + } } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/XMLSchemaParser.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/XMLSchemaParser.java index 03ce539d1..c2d293215 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/XMLSchemaParser.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/XMLSchemaParser.java @@ -26,6 +26,7 @@ import java.util.Iterator; import java.util.LinkedList; import org.xml.sax.Attributes; +import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.jdbc.sql.DBDictionary; @@ -34,6 +35,8 @@ import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.Localizer.Message; import org.apache.openjpa.util.UserException; +import serp.util.Numbers; + /** * Custom SAX parser used to parse {@link Schema} objects. The parser * will place all parsed schemas into the current {@link SchemaGroup}, set @@ -404,6 +407,11 @@ public class XMLSchemaParser private void startSequence(Attributes attrs) { Sequence seq = _schema.addSequence(attrs.getValue("name")); + Locator locator = getLocation().getLocator(); + if (locator != null) { + seq.setLineNumber(Numbers.valueOf(locator.getLineNumber())); + seq.setColNumber(Numbers.valueOf(locator.getColumnNumber())); + } seq.setSource(getSourceFile(), seq.SRC_XML); try { String val = attrs.getValue("initial-value"); @@ -423,6 +431,11 @@ public class XMLSchemaParser private void startTable(Attributes attrs) { _table = _schema.addTable(attrs.getValue("name")); _table.setSource(getSourceFile(), _table.SRC_XML); + Locator locator = getLocation().getLocator(); + if (locator != null) { + _table.setLineNumber(Numbers.valueOf(locator.getLineNumber())); + _table.setColNumber(Numbers.valueOf(locator.getColumnNumber())); + } } private void endTable() { diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java index a3123e849..a8ae0cbc1 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java @@ -135,6 +135,8 @@ public class ClassMetaData private final LifecycleMetaData _lifeMeta = new LifecycleMetaData(this); private File _srcFile = null; private int _srcType = SRC_OTHER; + private int _lineNum = 0; + private int _colNum = 0; private String[] _comments = null; private int _listIndex = -1; private int _srcMode = MODE_META | MODE_MAPPING; @@ -2173,6 +2175,23 @@ public class ClassMetaData public String getResourceName() { return _type.getName(); } + + public int getLineNumber() { + return _lineNum; + } + + public void setLineNumber(int lineNum) { + _lineNum = lineNum; + } + + public int getColNumber() { + return _colNum; + } + + public void setColNumber(int colNum) { + _colNum = colNum; + } + /** * The source mode this metadata has been loaded under. diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NonPersistentMetaData.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NonPersistentMetaData.java index 0de3089c9..81ff89e96 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NonPersistentMetaData.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NonPersistentMetaData.java @@ -40,6 +40,9 @@ public class NonPersistentMetaData private final int _type; private File _srcFile = null; + private int _lineNum = 0; + private int _colNum = 0; + private int _srcType = SRC_OTHER; private String[] _comments = null; private int _listIndex = -1; @@ -105,6 +108,22 @@ public class NonPersistentMetaData _srcType = srcType; } + public int getLineNumber() { + return _lineNum; + } + + public void setLineNumber(int lineNum) { + _lineNum = lineNum; + } + + public int getColNumber() { + return _colNum; + } + + public void setColNumber(int colNum) { + _colNum = colNum; + } + public String getResourceName() { return _class.getName(); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/QueryMetaData.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/QueryMetaData.java index ae2702946..948f144cb 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/QueryMetaData.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/QueryMetaData.java @@ -56,6 +56,9 @@ public class QueryMetaData private List _hintKeys; private List _hintVals; private String _resultSetMappingName; + private int _lineNum; + private int _colNum; + /** * Construct with the given name. */ @@ -274,4 +277,20 @@ public class QueryMetaData public String getResourceName() { return (_class == null) ? _name : _class.getName () + ":" + _name; } + + public int getLineNumber() { + return _lineNum; + } + + public void setLineNumber(int lineNum) { + _lineNum = lineNum; + } + + public int getColNumber() { + return _colNum; + } + + public void setColNumber(int colNum) { + _colNum = colNum; + } } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/SequenceMetaData.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/SequenceMetaData.java index 3b19d306c..1daf9cc78 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/SequenceMetaData.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/SequenceMetaData.java @@ -80,6 +80,8 @@ public class SequenceMetaData private File _source = null; private Object _scope = null; private int _srcType = SRC_OTHER; + private int _lineNum = 0; + private int _colNum = 0; private String[] _comments = null; private String _sequence = null; private int _increment = -1; @@ -129,6 +131,22 @@ public class SequenceMetaData _srcType = srcType; } + public int getLineNumber() { + return _lineNum; + } + + public void setLineNumber(int lineNum) { + _lineNum = lineNum; + } + + public int getColNumber() { + return _colNum; + } + + public void setColNumber(int colNum) { + _colNum = colNum; + } + public String getResourceName() { return _name; } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/SourceTracker.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/SourceTracker.java index 9e838fca7..be7a2c5e4 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/SourceTracker.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/SourceTracker.java @@ -53,4 +53,15 @@ public interface SourceTracker { * class, this would return the name of the class. */ public String getResourceName(); + + /** + * Return the line number of the file at which this instance was parsed. + */ + public int getLineNumber(); + + /** + * Return the column number in the line of the file at which this + * instance was parsed. + */ + public int getColNumber(); } diff --git a/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java b/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java index a63b407f1..14d4829e3 100644 --- a/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java +++ b/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java @@ -33,6 +33,7 @@ import javax.persistence.TemporalType; import org.apache.commons.lang.StringUtils; import org.xml.sax.Attributes; +import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.jdbc.meta.ClassMapping; @@ -61,7 +62,7 @@ import org.apache.openjpa.persistence.XMLPersistenceMetaDataParser; import org.apache.openjpa.util.InternalException; import static org.apache.openjpa.persistence.jdbc.MappingTag.*; - +import serp.util.Numbers; /** * Custom SAX parser used by the system to parse persistence mapping files. * @@ -414,6 +415,11 @@ public class XMLPersistenceMappingParser Object scope = (cur instanceof ClassMetaData) ? ((ClassMetaData) cur).getDescribedType() : null; seq.setSource(getSourceFile(), scope, seq.SRC_XML); + Locator locator = getLocation().getLocator(); + if (locator != null) { + seq.setLineNumber(Numbers.valueOf(locator.getLineNumber())); + seq.setColNumber(Numbers.valueOf(locator.getColumnNumber())); + } pushElement(seq); return true; } @@ -829,7 +835,11 @@ public class XMLPersistenceMappingParser Object scope = (cur instanceof ClassMetaData) ? ((ClassMetaData) cur).getDescribedType() : null; result.setSource(getSourceFile(), scope, result.SRC_XML); - + Locator locator = getLocation().getLocator(); + if (locator != null) { + result.setLineNumber(Numbers.valueOf(locator.getLineNumber())); + result.setColNumber(Numbers.valueOf(locator.getColumnNumber())); + } pushElement(result); return true; } diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataSerializer.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataSerializer.java index 3aa6cb273..b07336c64 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataSerializer.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataSerializer.java @@ -1277,6 +1277,14 @@ public class AnnotationPersistenceMetaDataSerializer return _seqs[0].getResourceName(); } + public int getLineNumber() { + return _seqs[0].getLineNumber(); + } + + public int getColNumber() { + return _seqs[0].getColNumber(); + } + public int compareTo(ClassSeqs other) { if (other == this) return 0; @@ -1346,6 +1354,14 @@ public class AnnotationPersistenceMetaDataSerializer return _queries[0].getResourceName(); } + public int getLineNumber() { + return _queries[0].getLineNumber(); + } + + public int getColNumber() { + return _queries[0].getColNumber(); + } + public int compareTo(ClassQueries other) { if (other == this) return 0; diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java index 06625ae39..7f00be55c 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java @@ -471,6 +471,14 @@ public class PersistenceUnitInfoImpl public int getSourceType() { return SRC_XML; } + + public int getLineNumber() { + return 0; + } + + public int getColNumber() { + return 0; + } public String getResourceName() { return "PersistenceUnitInfo:" + _name; diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java index d7721adb4..455586e5d 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java @@ -36,6 +36,7 @@ import static javax.persistence.CascadeType.*; import org.apache.commons.lang.StringUtils; import org.xml.sax.Attributes; +import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.apache.openjpa.conf.OpenJPAConfiguration; import org.apache.openjpa.enhance.PersistenceCapable; @@ -67,6 +68,8 @@ import static org.apache.openjpa.persistence.MetaDataTag.*; import static org.apache.openjpa.persistence.PersistenceStrategy.*; import org.apache.openjpa.util.ImplHelper; +import serp.util.Numbers; + /** * Custom SAX parser used by the system to quickly parse persistence i * metadata files. @@ -790,6 +793,11 @@ public class XMLPersistenceMetaDataParser if (isMetaDataMode()) { meta.setSource(getSourceFile(), meta.SRC_XML); meta.setSourceMode(MODE_META, true); + Locator locator = getLocation().getLocator(); + if (locator != null) { + meta.setLineNumber(Numbers.valueOf(locator.getLineNumber())); + meta.setColNumber(Numbers.valueOf(locator.getColumnNumber())); + } meta.setListingIndex(_clsPos); String name = attrs.getValue("name"); if (!StringUtils.isEmpty(name)) @@ -912,6 +920,11 @@ public class XMLPersistenceMetaDataParser Object scope = (cur instanceof ClassMetaData) ? ((ClassMetaData) cur).getDescribedType() : null; meta.setSource(getSourceFile(), scope, meta.SRC_XML); + Locator locator = getLocation().getLocator(); + if (locator != null) { + meta.setLineNumber(Numbers.valueOf(locator.getLineNumber())); + meta.setColNumber(Numbers.valueOf(locator.getColumnNumber())); + } return true; } @@ -1421,7 +1434,11 @@ public class XMLPersistenceMetaDataParser meta.setDefiningType(_cls); meta.setQueryString(attrs.getValue("query")); meta.setLanguage(JPQLParser.LANG_JPQL); - + Locator locator = getLocation().getLocator(); + if (locator != null) { + meta.setLineNumber(Numbers.valueOf(locator.getLineNumber())); + meta.setColNumber(Numbers.valueOf(locator.getColumnNumber())); + } Object cur = currentElement(); Object scope = (cur instanceof ClassMetaData) ? ((ClassMetaData) cur).getDescribedType() : null; @@ -1504,6 +1521,11 @@ public class XMLPersistenceMetaDataParser Object scope = (cur instanceof ClassMetaData) ? ((ClassMetaData) cur).getDescribedType() : null; meta.setSource(getSourceFile(), scope, meta.SRC_XML); + Locator locator = getLocation().getLocator(); + if (locator != null) { + meta.setLineNumber(Numbers.valueOf(locator.getLineNumber())); + meta.setColNumber(Numbers.valueOf(locator.getColumnNumber())); + } if (isMetaDataMode()) meta.setSourceMode(MODE_META); else if (isMappingMode()) diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataSerializer.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataSerializer.java index 7291c706e..c76f1f6af 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataSerializer.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataSerializer.java @@ -1229,6 +1229,14 @@ public class XMLPersistenceMetaDataSerializer return _seqs[0].getResourceName(); } + public int getLineNumber() { + return _seqs[0].getLineNumber(); + } + + public int getColNumber() { + return _seqs[0].getColNumber(); + } + public int compareTo(ClassSeqs other) { if (other == this) return 0; @@ -1298,6 +1306,14 @@ public class XMLPersistenceMetaDataSerializer return _queries[0].getResourceName(); } + public int getLineNumber() { + return _queries[0].getLineNumber(); + } + + public int getColNumber() { + return _queries[0].getColNumber(); + } + public int compareTo(ClassQueries other) { if (other == this) return 0;