openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject [openjpa] 01/03: OPENJPA-2768 fix XMLStore xml handling
Date Thu, 10 Jan 2019 12:31:25 GMT
This is an automated email from the ASF dual-hosted git repository.

struberg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openjpa.git

commit c1d9fd3c62ab40a893749ac3338b3ed20ddd6567
Author: Mark Struberg <struberg@apache.org>
AuthorDate: Thu Jan 10 13:25:38 2019 +0100

    OPENJPA-2768 fix XMLStore xml handling
    
    the SAXParser handler didn't properly distinguish between 'extent' and 'element'
---
 .../apache/openjpa/xmlstore/XMLFileHandler.java    | 150 ++++++++++-----------
 .../java/org/apache/openjpa/xmlstore/XMLStore.java |   8 +-
 .../apache/openjpa/xmlstore/XMLStoreManager.java   |  12 +-
 3 files changed, 81 insertions(+), 89 deletions(-)

diff --git a/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLFileHandler.java
b/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLFileHandler.java
index 16713f6..d8b1384 100644
--- a/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLFileHandler.java
+++ b/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLFileHandler.java
@@ -357,52 +357,49 @@ public class XMLFileHandler {
 
         private void startElement(String qName, Attributes attrs)
             throws Exception {
-            switch (qName.charAt(0)) {
-                case 'o': // object
-                    // get the metadata for the type we're reading
-                    String type = attrs.getValue("class");
-                    ClassMetaData meta = _conf.getMetaDataRepositoryInstance().
+
+            if ("object".equals(qName)) { // object
+                // get the metadata for the type we're reading
+                String type = attrs.getValue("class");
+                ClassMetaData meta = _conf.getMetaDataRepositoryInstance().
                         getMetaData(classForName(type), null, true);
 
-                    // construct the oid object
-                    Object oid;
-                    if (meta.getIdentityType() == ClassMetaData.ID_DATASTORE)
-                        oid = new Id(attrs.getValue("oid"), _conf, null);
-                    else
-                        oid = PCRegistry.newObjectId(meta.getDescribedType(),
+                // construct the oid object
+                Object oid;
+                if (meta.getIdentityType() == ClassMetaData.ID_DATASTORE)
+                    oid = new Id(attrs.getValue("oid"), _conf, null);
+                else
+                    oid = PCRegistry.newObjectId(meta.getDescribedType(),
                             attrs.getValue("oid"));
 
-                    // create an ObjectData that will contain the information
-                    // for this instance, and set the version
-                    _object = new ObjectData(oid, meta);
-                    _object.setVersion(new Long(attrs.getValue("version")));
-                    break;
-
-                case 'f': // field
-                    // start parsing a field element: for container types,
-                    // initialize the container; for other types, initialize a
-                    // buffer
-                    _fmd =
-                        _object.getMetaData().getField(attrs.getValue("name"));
-                    switch (_fmd.getTypeCode()) {
-                        case JavaTypes.COLLECTION:
-                        case JavaTypes.ARRAY:
-                            _fieldVal = new ArrayList();
-                            break;
-                        case JavaTypes.MAP:
-                            _fieldVal = new HashMap();
-                            break;
-                        default:
-                            _buf = new StringBuffer();
-                    }
-                    break;
+                // create an ObjectData that will contain the information
+                // for this instance, and set the version
+                _object = new ObjectData(oid, meta);
+                _object.setVersion(new Long(attrs.getValue("version")));
+            }
+            else if ("field".equals(qName)) { // field
+                // start parsing a field element: for container types,
+                // initialize the container; for other types, initialize a
+                // buffer
+                _fmd = _object.getMetaData().getField(attrs.getValue("name"));
+                switch (_fmd.getTypeCode()) {
+                    case JavaTypes.COLLECTION:
+                    case JavaTypes.ARRAY:
+                        _fieldVal = new ArrayList();
+                        break;
+                    case JavaTypes.MAP:
+                        _fieldVal = new HashMap();
+                        break;
+                    default:
+                        _buf = new StringBuffer();
+                }
+            }
+            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
                     _buf = new StringBuffer();
-                    break;
             }
         }
 
@@ -411,7 +408,7 @@ public class XMLFileHandler {
             throws SAXException {
             try {
                 endElement(qName);
-            } catch (RuntimeException re) {
+                } catch (RuntimeException re) {
                 throw re;
             } catch (SAXException se) {
                 throw se;
@@ -423,49 +420,44 @@ public class XMLFileHandler {
         private void endElement(String qName)
             throws Exception {
             Object val;
-            switch (qName.charAt(0)) {
-                case 'o': // object
-                    // add the object to our results
-                    _extent.add(_object);
-
-                case 'f': // field
-                    switch (_fmd.getTypeCode()) {
-                        case JavaTypes.COLLECTION:
-                        case JavaTypes.ARRAY:
-                        case JavaTypes.MAP:
-                            // field value already constructed
-                            break;
-                        default:
-                            // construct the field value from text within the
-                            // element
-                            _fieldVal = fromXMLString(_fmd.getTypeCode(),
+            if ("object".equals(qName)) {
+                // add the object to our results
+                _extent.add(_object);
+            }
+            else if ("field".equals(qName)) {
+                switch (_fmd.getTypeCode()) {
+                    case JavaTypes.COLLECTION:
+                    case JavaTypes.ARRAY:
+                    case JavaTypes.MAP:
+                        // field value already constructed
+                        break;
+                    default:
+                        // construct the field value from text within the
+                        // element
+                        _fieldVal = fromXMLString(_fmd.getTypeCode(),
                                 _fmd.getTypeMetaData(), _buf.toString());
-                    }
-
-                    // set the field value into the object being parsed
-                    _object.setField(_fmd.getIndex(), _fieldVal);
-                    break;
+                }
 
-                case 'e': // element
-                    // cache element value
-                    val = fromXMLString(_fmd.getElement().getTypeCode(),
+                // set the field value into the object being parsed
+                _object.setField(_fmd.getIndex(), _fieldVal);
+            }
+            else if ("element".equals(qName)) {
+                // cache element value
+                val = fromXMLString(_fmd.getElement().getTypeCode(),
                         _fmd.getElement().getTypeMetaData(), _buf.toString());
-                    ((Collection) _fieldVal).add(val);
-                    break;
-
-                case 'k': // key
-                    // cache key value
-                    _keyVal = fromXMLString(_fmd.getKey().getTypeCode(),
+                ((Collection) _fieldVal).add(val);
+            }
+            else if ("key".equals(qName)) {
+                // cache key value
+                _keyVal = fromXMLString(_fmd.getKey().getTypeCode(),
                         _fmd.getKey().getTypeMetaData(), _buf.toString());
-                    break;
-
-                case 'v': // value
-                    // create value and put cached key and value into map
-                    val = fromXMLString(_fmd.getElement().getTypeCode(),
-                        _fmd.getElement().getTypeMetaData(), _buf.toString());
-                    Map map = (Map) _fieldVal;
-                    map.put(_keyVal, val);
-                    break;
+            }
+            else if ("value".equals(qName)) {
+                // create value and put cached key and value into map
+                val = fromXMLString(_fmd.getElement().getTypeCode(),
+                    _fmd.getElement().getTypeMetaData(), _buf.toString());
+                Map map = (Map) _fieldVal;
+                map.put(_keyVal, val);
             }
 
             // don't cache text between elements
diff --git a/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLStore.java b/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLStore.java
index bd1873c..7cc330f 100644
--- a/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLStore.java
+++ b/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLStore.java
@@ -118,8 +118,8 @@ public class XMLStore {
      * @param updates {@link ObjectData} instances to insert or update
      * @param deletes {@link ObjectData} instances to delete
      */
-    public synchronized void endTransaction(Collection updates,
-        Collection deletes) {
+    public synchronized void endTransaction(Collection<ObjectData> updates,
+                                            Collection<ObjectData> deletes) {
         // track dirty types
         Set dirty = new HashSet();
         try {
@@ -154,6 +154,6 @@ public class XMLStore {
             // unlock store
             notify();
             _locked = false;
-		}
-	}
+        }
+    }
 }
diff --git a/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLStoreManager.java
b/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLStoreManager.java
index be9603e..5562c98 100644
--- a/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLStoreManager.java
+++ b/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLStoreManager.java
@@ -51,8 +51,8 @@ public class XMLStoreManager
     private XMLStore _store;
 
     // changed data within the current transaction
-    private Collection _updates;
-    private Collection _deletes;
+    private Collection<ObjectData> _updates;
+    private Collection<ObjectData> _deletes;
 
     @Override
     protected Collection getUnsupportedOptions() {
@@ -201,8 +201,8 @@ public class XMLStoreManager
     }
 
     @Override
-    protected Collection flush(Collection pNew, Collection pNewUpdated,
-        Collection pNewFlushedDeleted, Collection pDirty, Collection pDeleted) {
+    protected Collection flush(Collection<OpenJPAStateManager> pNew, Collection<OpenJPAStateManager>
pNewUpdated,
+        Collection<OpenJPAStateManager> pNewFlushedDeleted, Collection<OpenJPAStateManager>
pDirty, Collection<OpenJPAStateManager> pDeleted) {
         // we don't support incremental flushing, so pNewUpdated and
         // pNewFlushedDeleted should be empty; we ignore them here
 
@@ -210,8 +210,8 @@ public class XMLStoreManager
         Collection exceps = new LinkedList();
 
         // convert instances to ObjectDatas
-        _updates = new ArrayList(pNew.size() + pDirty.size());
-        _deletes = new ArrayList(pDeleted.size());
+        _updates = new ArrayList<>(pNew.size() + pDirty.size());
+        _deletes = new ArrayList<>(pDeleted.size());
 
         // convert additions
         for (Iterator itr = pNew.iterator(); itr.hasNext();) {


Mime
View raw message