@Override public long execute() { int rv = 0; for (T match : query.fetch()) { BeanMap beanMap = new BeanMap(match); for (Map.Entry<Path<?>,Object> entry : paths.entrySet()) { // TODO : support deep updates as well String propertyName = entry.getKey().getMetadata().getName(); beanMap.put(propertyName, entry.getValue()); } rv++; } return rv; }
newMap.setBean(newBean); } catch (Exception exception) { throw new CloneNotSupportedException("Unable to set bean in the cloned bean map: " + exception); while (readableKeys.hasNext()) { String key = readableKeys.next(); if (getWriteMethod(key) != null) { newMap.put(key, get(key));
/** * Sets the value. * * @param value the new value for the entry * @return the old value for the entry */ @Override public Object setValue(Object value) { String key = getKey(); Object oldValue = owner.get(key); owner.put(key, value); Object newValue = owner.get(key); this.value = newValue; return oldValue; }
/** * Puts all of the writable properties from the given BeanMap into this * BeanMap. Read-only and Write-only properties will be ignored. * * @param map the BeanMap whose properties to put */ public void putAllWriteable(BeanMap map) { Iterator<String> readableKeys = map.readMethods.keySet().iterator(); while (readableKeys.hasNext()) { String key = readableKeys.next(); if (getWriteMethod(key) != null) { this.put(key, map.get(key)); } } }
/** * Sets the bean property with the given name to the given value. * * @param name the name of the property to set * @param value the value to set that property to * @return the previous value of that property */ @Override public Object put(String name, Object value) { if (bean != null) { Object oldValue = get(name); Method method = getWriteMethod(name); if (method == null) { throw new IllegalArgumentException("The bean of type: " + bean.getClass().getName() + " has no property called: " + name); } try { Object[] arguments = createWriteMethodArguments(method, value); method.invoke(bean, arguments); Object newValue = get(name); firePropertyChange(name, oldValue, newValue); } catch (InvocationTargetException e) { throw new IllegalArgumentException(e.getMessage()); } catch (IllegalAccessException e) { throw new IllegalArgumentException(e.getMessage()); } return oldValue; } return null; }
@SuppressWarnings("unchecked") private <T> BooleanBuilder getByExample(T entity) { PathBuilder<T> entityPath = new PathBuilder<T>((Class<T>) entity.getClass(), "entity"); BooleanBuilder conditions = new BooleanBuilder(); Map<String, Object> beanMap = new BeanMap(entity); for (Map.Entry<String, Object> entry : beanMap.entrySet()) { if (!entry.getKey().equals("class")) { if (entry.getValue() != null) { conditions.and(entityPath.get(entry.getKey()).eq(entry.getValue())); } } } return conditions; }
@Override public Object next() { Object key = iter.next(); return get(key); }
private void initialise() { if (getBean() == null) { return; } Class<?> beanClass = getBean().getClass(); try { //BeanInfo beanInfo = Introspector.getBeanInfo( bean, null ); BeanInfo beanInfo = Introspector.getBeanInfo(beanClass); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); if (propertyDescriptors != null) { for (int i = 0; i < propertyDescriptors.length; i++) { PropertyDescriptor propertyDescriptor = propertyDescriptors[i]; if (propertyDescriptor != null) { String name = propertyDescriptor.getName(); Method readMethod = propertyDescriptor.getReadMethod(); Method writeMethod = propertyDescriptor.getWriteMethod(); Class<?> aType = propertyDescriptor.getPropertyType(); if (readMethod != null) { readMethods.put(name, readMethod); } if (writeMethods != null) { writeMethods.put(name, writeMethod); } types.put(name, aType); } } } } catch (IntrospectionException e) { } }
List<BeanMap> beanMaps = getItSomehow(); List<Map<String, String>> maps = new ArrayList<Map<String, String>>(); for (BeanMap beanMap : beanMaps) { Map<String, String> map = new HashMap<String, String>(); for (Object o : beanMap.entrySet()) { // It's not parameterized :( Map.Entry<String, Object> entry = (Map.Entry<String, Object>) o; String key = entry.getKey(); Object value = entry.getValue(); map.put(key, value != null ? String.valueOf(value) : null); } maps.add(map); } // ...
@Test public void containsKeyString() { assertTrue(beanMap.containsKey("id")); }
@Test public void clone_() throws CloneNotSupportedException { assertEquals(beanMap, beanMap.clone()); }
/** * Puts all of the writable properties from the given BeanMap into this * BeanMap. Read-only and Write-only properties will be ignored. * * @param map the BeanMap whose properties to put */ public void putAllWriteable(BeanMap map) { Iterator<String> readableKeys = map.readMethods.keySet().iterator(); while (readableKeys.hasNext()) { String key = readableKeys.next(); if (getWriteMethod(key) != null) { this.put(key, map.get(key)); } } }