Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions api/src/org/labkey/api/data/BeanObjectFactory.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,7 +39,6 @@
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

Expand All@@ -51,10 +50,9 @@ public class BeanObjectFactory<K> implements ObjectFactory<K> // implements Resu
private Class<K> _class;

// for performance pre-calculate readable/writeable properties
protected HashMap<String,PropertyDescriptor> _writeableProperties = null;
protected HashSet<String> _writeableProperties = null;
protected HashSet<String> _readableProperties = null;


protected BeanObjectFactory()
{
}
Expand All@@ -63,7 +61,7 @@ protected BeanObjectFactory()
public BeanObjectFactory(Class<K> clss)
{
_class = clss;
_writeableProperties = new HashMap<>();
_writeableProperties = new HashSet<>();
_readableProperties = new HashSet<>();

K bean;
Expand All@@ -77,7 +75,7 @@ public BeanObjectFactory(Class<K> clss)
}

PropertyDescriptor[] origDescriptors = PropertyUtils.getPropertyDescriptors(bean);
_writeableProperties = new HashMap<>(origDescriptors.length * 2);
_writeableProperties = new HashSet<>(origDescriptors.length * 2);
_readableProperties = new HashSet<>(origDescriptors.length * 2);

for (PropertyDescriptor origDescriptor : origDescriptors)
Expand All@@ -95,7 +93,7 @@ public BeanObjectFactory(Class<K> clss)
}
}
if (PropertyUtils.isWriteable(bean, name))
_writeableProperties.put(name,origDescriptor);
_writeableProperties.add(name);
}
}

Expand DownExpand Up@@ -135,10 +133,8 @@ public K fromMap(K bean, Map<String, ?> m)
if (!(m instanceof CaseInsensitiveHashMap))
m = new CaseInsensitiveHashMap<>(m);

for (var entry : _writeableProperties.entrySet())
for (var prop : _writeableProperties)
{
String prop = entry.getKey();

// If the map contains the key, assuming that we should use the map's value, even if it's null.
// Otherwise, don't set a value on the bean.
if (m.containsKey(prop))
Expand DownExpand Up@@ -249,7 +245,7 @@ public ArrayList<K> handleArrayList(ResultSet rs) throws SQLException
ResultSetMetaData md = rs.getMetaData();
int count = md.getColumnCount();
CaseInsensitiveHashMap<String> propMap = new CaseInsensitiveHashMap<>(count * 2);
for (String prop : _writeableProperties.keySet())
for (String prop : _writeableProperties)
propMap.put(prop, prop);

String[] properties = new String[count + 1];
Expand Down