You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2010/02/04 15:05:04 UTC
svn commit: r906484 - in /pivot/trunk:
core/src/org/apache/pivot/sql/ResultList.java
tools/src/org/apache/pivot/tools/json/JSONViewer.java
wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java
Author: gbrown
Date: Thu Feb 4 14:05:02 2010
New Revision: 906484
URL: http://svn.apache.org/viewvc?rev=906484&view=rev
Log:
Fix bug in WTKXSerializer when clearing namespace; update JSONViewer to sort map entries alphabetically; make null values optional in ResultSet (primarily to save bandwidth when using JSONSerializer).
Modified:
pivot/trunk/core/src/org/apache/pivot/sql/ResultList.java
pivot/trunk/tools/src/org/apache/pivot/tools/json/JSONViewer.java
pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java
Modified: pivot/trunk/core/src/org/apache/pivot/sql/ResultList.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/sql/ResultList.java?rev=906484&r1=906483&r2=906484&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/sql/ResultList.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/sql/ResultList.java Thu Feb 4 14:05:02 2010
@@ -171,8 +171,10 @@
value = null;
}
- String key = (field.key == null) ? field.columnName : field.key;
- current.put(key, value);
+ if (value != null || includeNullValues) {
+ String key = (field.key == null) ? field.columnName : field.key;
+ current.put(key, value);
+ }
}
} catch (SQLException exception) {
throw new RuntimeException(exception);
@@ -222,20 +224,29 @@
}
private ResultSet resultSet;
+ private boolean includeNullValues;
private ArrayList<Field> fields;
private ListListenerList<Map<String, Object>> listListeners =
new ListListenerList<Map<String,Object>>();
public ResultList(ResultSet resultSet, Field... fields) {
- this(resultSet, new ArrayList<Field>(fields));
+ this(resultSet, false, new ArrayList<Field>(fields));
+ }
+
+ public ResultList(ResultSet resultSet, boolean includeNullValues, Field... fields) {
+ this(resultSet, false, new ArrayList<Field>(fields));
}
public ResultList(ResultSet resultSet, Sequence<Field> fields) {
- this(resultSet, new ArrayList<Field>(fields));
+ this(resultSet, false, new ArrayList<Field>(fields));
+ }
+
+ public ResultList(ResultSet resultSet, boolean includeNullValues, Sequence<Field> fields) {
+ this(resultSet, false, new ArrayList<Field>(fields));
}
- private ResultList(ResultSet resultSet, ArrayList<Field> fields) {
+ private ResultList(ResultSet resultSet, boolean includeNullValues, ArrayList<Field> fields) {
if (resultSet == null) {
throw new IllegalArgumentException();
}
@@ -268,6 +279,7 @@
}
this.resultSet = resultSet;
+ this.includeNullValues = includeNullValues;
this.fields = fields;
}
Modified: pivot/trunk/tools/src/org/apache/pivot/tools/json/JSONViewer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/tools/src/org/apache/pivot/tools/json/JSONViewer.java?rev=906484&r1=906483&r2=906484&view=diff
==============================================================================
--- pivot/trunk/tools/src/org/apache/pivot/tools/json/JSONViewer.java (original)
+++ pivot/trunk/tools/src/org/apache/pivot/tools/json/JSONViewer.java Thu Feb 4 14:05:02 2010
@@ -20,6 +20,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.StringReader;
+import java.util.Comparator;
import org.apache.pivot.collections.List;
import org.apache.pivot.collections.Map;
@@ -170,6 +171,12 @@
if (value instanceof Map<?, ?>) {
TreeBranch treeBranch = new TreeBranch("{}");
+ treeBranch.setComparator(new Comparator<TreeNode>() {
+ @Override
+ public int compare(TreeNode treeNode1, TreeNode treeNode2) {
+ return treeNode1.getText().compareTo(treeNode2.getText());
+ }
+ });
Map<String, Object> map = (Map<String, Object>)value;
for (String key : map) {
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java?rev=906484&r1=906483&r2=906484&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java Thu Feb 4 14:05:02 2010
@@ -272,7 +272,6 @@
}
private Resources resources;
- private WTKXSerializer namespaceOwner;
private HashMap<String, Object> namedObjects;
private HashMap<String, WTKXSerializer> namedSerializers;
@@ -282,6 +281,7 @@
private URL location = null;
private Element element = null;
private Object root = null;
+ private boolean clearNamespaceOnRead = false;
private String language = DEFAULT_LANGUAGE;
@@ -316,18 +316,19 @@
this(resources, null);
}
- private WTKXSerializer(Resources resources, WTKXSerializer namespaceOwner) {
+ private WTKXSerializer(Resources resources, WTKXSerializer owner) {
this.resources = resources;
- this.namespaceOwner = namespaceOwner;
- if (namespaceOwner == null) {
+ if (owner == null) {
namedObjects = new HashMap<String, Object>();
namedSerializers = new HashMap<String, WTKXSerializer>();
} else {
- namedObjects = namespaceOwner.namedObjects;
- namedSerializers = namespaceOwner.namedSerializers;
+ namedObjects = owner.namedObjects;
+ namedSerializers = owner.namedSerializers;
}
+ this.clearNamespaceOnRead = (owner == null);
+
xmlInputFactory = XMLInputFactory.newInstance();
xmlInputFactory.setProperty("javax.xml.stream.isCoalescing", true);
@@ -406,7 +407,7 @@
}
// Reset the serializer
- if (namespaceOwner == null) {
+ if (clearNamespaceOnRead) {
namedObjects.clear();
namedSerializers.clear();
}
@@ -467,7 +468,8 @@
bindable.initialize(resources);
}
- // Clear the location
+ // Reset the serializer
+ clearNamespaceOnRead = true;
location = null;
return root;
@@ -1134,6 +1136,8 @@
previousValue = serializer.put(id, value);
}
+ clearNamespaceOnRead = false;
+
return previousValue;
}