OPENJPA-2768 fix XMLStore xml handling

the SAXParser handler didn't properly distinguish between 'extent' and 'element'
This commit is contained in:
Mark Struberg 2019-01-10 13:25:38 +01:00
parent 08acaa4f55
commit c1d9fd3c62
3 changed files with 81 additions and 89 deletions

View File

@ -357,8 +357,8 @@ public class XMLFileHandler {
private void startElement(String qName, Attributes attrs) private void startElement(String qName, Attributes attrs)
throws Exception { throws Exception {
switch (qName.charAt(0)) {
case 'o': // object if ("object".equals(qName)) { // object
// get the metadata for the type we're reading // get the metadata for the type we're reading
String type = attrs.getValue("class"); String type = attrs.getValue("class");
ClassMetaData meta = _conf.getMetaDataRepositoryInstance(). ClassMetaData meta = _conf.getMetaDataRepositoryInstance().
@ -376,14 +376,12 @@ public class XMLFileHandler {
// for this instance, and set the version // for this instance, and set the version
_object = new ObjectData(oid, meta); _object = new ObjectData(oid, meta);
_object.setVersion(new Long(attrs.getValue("version"))); _object.setVersion(new Long(attrs.getValue("version")));
break; }
else if ("field".equals(qName)) { // field
case 'f': // field
// start parsing a field element: for container types, // start parsing a field element: for container types,
// initialize the container; for other types, initialize a // initialize the container; for other types, initialize a
// buffer // buffer
_fmd = _fmd = _object.getMetaData().getField(attrs.getValue("name"));
_object.getMetaData().getField(attrs.getValue("name"));
switch (_fmd.getTypeCode()) { switch (_fmd.getTypeCode()) {
case JavaTypes.COLLECTION: case JavaTypes.COLLECTION:
case JavaTypes.ARRAY: case JavaTypes.ARRAY:
@ -395,14 +393,13 @@ public class XMLFileHandler {
default: default:
_buf = new StringBuffer(); _buf = new StringBuffer();
} }
break; }
else if ("element".equals(qName) ||
"key".equals(qName) ||
"value".equals(qName) ) { // field
case 'e': // element
case 'k': // key
case 'v': // value
// initialize a buffer for the element value // initialize a buffer for the element value
_buf = new StringBuffer(); _buf = new StringBuffer();
break;
} }
} }
@ -423,12 +420,11 @@ public class XMLFileHandler {
private void endElement(String qName) private void endElement(String qName)
throws Exception { throws Exception {
Object val; Object val;
switch (qName.charAt(0)) { if ("object".equals(qName)) {
case 'o': // object
// add the object to our results // add the object to our results
_extent.add(_object); _extent.add(_object);
}
case 'f': // field else if ("field".equals(qName)) {
switch (_fmd.getTypeCode()) { switch (_fmd.getTypeCode()) {
case JavaTypes.COLLECTION: case JavaTypes.COLLECTION:
case JavaTypes.ARRAY: case JavaTypes.ARRAY:
@ -444,28 +440,24 @@ public class XMLFileHandler {
// set the field value into the object being parsed // set the field value into the object being parsed
_object.setField(_fmd.getIndex(), _fieldVal); _object.setField(_fmd.getIndex(), _fieldVal);
break; }
else if ("element".equals(qName)) {
case 'e': // element
// cache element value // cache element value
val = fromXMLString(_fmd.getElement().getTypeCode(), val = fromXMLString(_fmd.getElement().getTypeCode(),
_fmd.getElement().getTypeMetaData(), _buf.toString()); _fmd.getElement().getTypeMetaData(), _buf.toString());
((Collection) _fieldVal).add(val); ((Collection) _fieldVal).add(val);
break; }
else if ("key".equals(qName)) {
case 'k': // key
// cache key value // cache key value
_keyVal = fromXMLString(_fmd.getKey().getTypeCode(), _keyVal = fromXMLString(_fmd.getKey().getTypeCode(),
_fmd.getKey().getTypeMetaData(), _buf.toString()); _fmd.getKey().getTypeMetaData(), _buf.toString());
break; }
else if ("value".equals(qName)) {
case 'v': // value
// create value and put cached key and value into map // create value and put cached key and value into map
val = fromXMLString(_fmd.getElement().getTypeCode(), val = fromXMLString(_fmd.getElement().getTypeCode(),
_fmd.getElement().getTypeMetaData(), _buf.toString()); _fmd.getElement().getTypeMetaData(), _buf.toString());
Map map = (Map) _fieldVal; Map map = (Map) _fieldVal;
map.put(_keyVal, val); map.put(_keyVal, val);
break;
} }
// don't cache text between elements // don't cache text between elements

View File

@ -118,8 +118,8 @@ public class XMLStore {
* @param updates {@link ObjectData} instances to insert or update * @param updates {@link ObjectData} instances to insert or update
* @param deletes {@link ObjectData} instances to delete * @param deletes {@link ObjectData} instances to delete
*/ */
public synchronized void endTransaction(Collection updates, public synchronized void endTransaction(Collection<ObjectData> updates,
Collection deletes) { Collection<ObjectData> deletes) {
// track dirty types // track dirty types
Set dirty = new HashSet(); Set dirty = new HashSet();
try { try {

View File

@ -51,8 +51,8 @@ public class XMLStoreManager
private XMLStore _store; private XMLStore _store;
// changed data within the current transaction // changed data within the current transaction
private Collection _updates; private Collection<ObjectData> _updates;
private Collection _deletes; private Collection<ObjectData> _deletes;
@Override @Override
protected Collection getUnsupportedOptions() { protected Collection getUnsupportedOptions() {
@ -201,8 +201,8 @@ public class XMLStoreManager
} }
@Override @Override
protected Collection flush(Collection pNew, Collection pNewUpdated, protected Collection flush(Collection<OpenJPAStateManager> pNew, Collection<OpenJPAStateManager> pNewUpdated,
Collection pNewFlushedDeleted, Collection pDirty, Collection pDeleted) { Collection<OpenJPAStateManager> pNewFlushedDeleted, Collection<OpenJPAStateManager> pDirty, Collection<OpenJPAStateManager> pDeleted) {
// we don't support incremental flushing, so pNewUpdated and // we don't support incremental flushing, so pNewUpdated and
// pNewFlushedDeleted should be empty; we ignore them here // pNewFlushedDeleted should be empty; we ignore them here
@ -210,8 +210,8 @@ public class XMLStoreManager
Collection exceps = new LinkedList(); Collection exceps = new LinkedList();
// convert instances to ObjectDatas // convert instances to ObjectDatas
_updates = new ArrayList(pNew.size() + pDirty.size()); _updates = new ArrayList<>(pNew.size() + pDirty.size());
_deletes = new ArrayList(pDeleted.size()); _deletes = new ArrayList<>(pDeleted.size());
// convert additions // convert additions
for (Iterator itr = pNew.iterator(); itr.hasNext();) { for (Iterator itr = pNew.iterator(); itr.hasNext();) {