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
This commit is contained in:
Fay Wang 2008-11-20 18:16:46 +00:00
parent 031f525d4f
commit bb937f3634
15 changed files with 248 additions and 3 deletions

View File

@ -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<String,List<Unique>> _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;
}
}

View File

@ -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;
@ -225,6 +227,22 @@ public class QueryResultMapping
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.
*/

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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() {

View File

@ -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;
@ -2174,6 +2176,23 @@ public class ClassMetaData
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.
*/

View File

@ -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();
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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;

View File

@ -472,6 +472,14 @@ public class PersistenceUnitInfoImpl
return SRC_XML;
}
public int getLineNumber() {
return 0;
}
public int getColNumber() {
return 0;
}
public String getResourceName() {
return "PersistenceUnitInfo:" + _name;
}

View File

@ -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())

View File

@ -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;