/** * Set the list of dynamic properties supported by this DynaClass. * * @param properties List of dynamic properties to be supported */ protected void setProperties(final DynaProperty[] properties) { this.properties = properties; propertiesMap.clear(); for (DynaProperty propertie : properties) { propertiesMap.put(propertie.getName(), propertie); } }
/** * Set the list of dynamic properties supported by this DynaClass. * * @param properties List of dynamic properties to be supported */ protected void setProperties(final DynaProperty[] properties) { this.properties = properties; propertiesMap.clear(); for (DynaProperty propertie : properties) { propertiesMap.put(propertie.getName(), propertie); } }
/** * <p>Introspect the metadata associated with our result set, and populate * the <code>properties</code> and <code>propertiesMap</code> instance * variables.</p> * * @param resultSet The <code>resultSet</code> whose metadata is to * be introspected * * @throws SQLException if an error is encountered processing the * result set metadata */ protected void introspect(final ResultSet resultSet) throws SQLException { // Accumulate an ordered list of DynaProperties final ArrayList<DynaProperty> list = new ArrayList<DynaProperty>(); final ResultSetMetaData metadata = resultSet.getMetaData(); final int n = metadata.getColumnCount(); for (int i = 1; i <= n; i++) { // JDBC is one-relative! final DynaProperty dynaProperty = createDynaProperty(metadata, i); if (dynaProperty != null) { list.add(dynaProperty); } } // Convert this list into the internal data structures we need properties = list.toArray(new DynaProperty[list.size()]); for (DynaProperty propertie : properties) { propertiesMap.put(propertie.getName(), propertie); } }
/** * <p>Introspect the metadata associated with our result set, and populate * the <code>properties</code> and <code>propertiesMap</code> instance * variables.</p> * * @param resultSet The <code>resultSet</code> whose metadata is to * be introspected * * @throws SQLException if an error is encountered processing the * result set metadata */ protected void introspect(final ResultSet resultSet) throws SQLException { // Accumulate an ordered list of DynaProperties final ArrayList<DynaProperty> list = new ArrayList<DynaProperty>(); final ResultSetMetaData metadata = resultSet.getMetaData(); final int n = metadata.getColumnCount(); for (int i = 1; i <= n; i++) { // JDBC is one-relative! final DynaProperty dynaProperty = createDynaProperty(metadata, i); if (dynaProperty != null) { list.add(dynaProperty); } } // Convert this list into the internal data structures we need properties = list.toArray(new DynaProperty[list.size()]); for (DynaProperty propertie : properties) { propertiesMap.put(propertie.getName(), propertie); } }
/** * Add a new dynamic property. * * @param property Property the new dynamic property to add. * * @throws IllegalArgumentException if name is null */ protected void add(final DynaProperty property) { add(property.getName(), property.getType()); }
/** * Add a new dynamic property. * * @param property Property the new dynamic property to add. * * @throws IllegalArgumentException if name is null * @throws IllegalStateException if this DynaClass is currently * restricted, so no new properties can be added */ protected void add(final DynaProperty property) { if (property.getName() == null) { throw new IllegalArgumentException("Property name is missing."); } if (isRestricted()) { throw new IllegalStateException("DynaClass is currently restricted. No new properties can be added."); } // Check if property already exists if (propertiesMap.get(property.getName()) != null) { return; } // Create a new property array with the specified property final DynaProperty[] oldProperties = getDynaProperties(); final DynaProperty[] newProperties = new DynaProperty[oldProperties.length+1]; System.arraycopy(oldProperties, 0, newProperties, 0, oldProperties.length); newProperties[oldProperties.length] = property; // Update the properties setProperties(newProperties); }
/** * Add a new dynamic property. * * @param property Property the new dynamic property to add. * * @throws IllegalArgumentException if name is null */ protected void add(final DynaProperty property) { add(property.getName(), property.getType()); }
/** * Add a new dynamic property. * * @param property Property the new dynamic property to add. * * @throws IllegalArgumentException if name is null * @throws IllegalStateException if this DynaClass is currently * restricted, so no new properties can be added */ protected void add(final DynaProperty property) { if (property.getName() == null) { throw new IllegalArgumentException("Property name is missing."); } if (isRestricted()) { throw new IllegalStateException("DynaClass is currently restricted. No new properties can be added."); } // Check if property already exists if (propertiesMap.get(property.getName()) != null) { return; } // Create a new property array with the specified property final DynaProperty[] oldProperties = getDynaProperties(); final DynaProperty[] newProperties = new DynaProperty[oldProperties.length+1]; System.arraycopy(oldProperties, 0, newProperties, 0, oldProperties.length); newProperties[oldProperties.length] = property; // Update the properties setProperties(newProperties); }
/** * Returns the set of property values in the * decorated {@link DynaBean}. * * @return Unmodifiable collection of values. */ public Collection<Object> values() { final DynaProperty[] properties = getDynaProperties(); final List<Object> values = new ArrayList<Object>(properties.length); for (DynaProperty propertie : properties) { final String key = propertie.getName(); final Object value = getDynaBean().get(key); values.add(value); } return Collections.unmodifiableList(values); }
/** * Returns the set of property values in the * decorated {@link DynaBean}. * * @return Unmodifiable collection of values. */ public Collection<Object> values() { final DynaProperty[] properties = getDynaProperties(); final List<Object> values = new ArrayList<Object>(properties.length); for (DynaProperty propertie : properties) { final String key = propertie.getName(); final Object value = getDynaBean().get(key); values.add(value); } return Collections.unmodifiableList(values); }
/** * <p>Returns the Set of the property/value mappings * in the decorated {@link DynaBean}.</p> * * <p>Each element in the Set is a <code>Map.Entry</code> * type.</p> * * @return An unmodifiable set of the DynaBean * property name/value pairs */ public Set<Map.Entry<K, Object>> entrySet() { final DynaProperty[] properties = getDynaProperties(); final Set<Map.Entry<K, Object>> set = new HashSet<Map.Entry<K, Object>>(properties.length); for (DynaProperty propertie : properties) { final K key = convertKey(propertie.getName()); final Object value = getDynaBean().get(propertie.getName()); set.add(new MapEntry<K>(key, value)); } return Collections.unmodifiableSet(set); }
/** * <p>Returns the Set of the property/value mappings * in the decorated {@link DynaBean}.</p> * * <p>Each element in the Set is a <code>Map.Entry</code> * type.</p> * * @return An unmodifiable set of the DynaBean * property name/value pairs */ public Set<Map.Entry<K, Object>> entrySet() { final DynaProperty[] properties = getDynaProperties(); final Set<Map.Entry<K, Object>> set = new HashSet<Map.Entry<K, Object>>(properties.length); for (DynaProperty propertie : properties) { final K key = convertKey(propertie.getName()); final Object value = getDynaBean().get(propertie.getName()); set.add(new MapEntry<K>(key, value)); } return Collections.unmodifiableSet(set); }
/** * <p>Copy the column values for each row in the specified * <code>ResultSet</code> into a newly created {@link DynaBean}, and add * this bean to the list of {@link DynaBean}s that will later by * returned by a call to <code>getRows()</code>.</p> * * @param resultSet The <code>ResultSet</code> whose data is to be * copied * * @throws SQLException if an error is encountered copying the data */ protected void copy(final ResultSet resultSet) throws SQLException { int cnt = 0; while (resultSet.next() && (limit < 0 || cnt++ < limit) ) { final DynaBean bean = createDynaBean(); for (DynaProperty propertie : properties) { final String name = propertie.getName(); final Object value = getObject(resultSet, name); bean.set(name, value); } rows.add(bean); } }
/** * <p>Copy the column values for each row in the specified * <code>ResultSet</code> into a newly created {@link DynaBean}, and add * this bean to the list of {@link DynaBean}s that will later by * returned by a call to <code>getRows()</code>.</p> * * @param resultSet The <code>ResultSet</code> whose data is to be * copied * * @throws SQLException if an error is encountered copying the data */ protected void copy(final ResultSet resultSet) throws SQLException { int cnt = 0; while (resultSet.next() && (limit < 0 || cnt++ < limit) ) { final DynaBean bean = createDynaBean(); for (DynaProperty propertie : properties) { final String name = propertie.getName(); final Object value = getObject(resultSet, name); bean.set(name, value); } rows.add(bean); } }
int j = 0; for (int i = 0; i < oldProperties.length; i++) { if (!(name.equals(oldProperties[i].getName()))) { newProperties[j] = oldProperties[i]; j++;
/** * Indicates whether the decorated {@link DynaBean} contains * a specified value. * * @param value The value to check for. * @return <code>true</code> if one of the the {@link DynaBean}'s * properties contains the specified value, otherwise * <code>false</code>. */ public boolean containsValue(final Object value) { final DynaProperty[] properties = getDynaProperties(); for (DynaProperty propertie : properties) { final String key = propertie.getName(); final Object prop = getDynaBean().get(key); if (value == null) { if (prop == null) { return true; } } else { if (value.equals(prop)) { return true; } } } return false; }
/** * Indicates whether the decorated {@link DynaBean} contains * a specified value. * * @param value The value to check for. * @return <code>true</code> if one of the the {@link DynaBean}'s * properties contains the specified value, otherwise * <code>false</code>. */ public boolean containsValue(final Object value) { final DynaProperty[] properties = getDynaProperties(); for (DynaProperty propertie : properties) { final String key = propertie.getName(); final Object prop = getDynaBean().get(key); if (value == null) { if (prop == null) { return true; } } else { if (value.equals(prop)) { return true; } } } return false; }
/** * <p>Returns the Set of the property * names in the decorated {@link DynaBean}.</p> * * <p><b>N.B.</b>For {@link DynaBean}s whose associated {@link DynaClass} * is a {@link MutableDynaClass} a new Set is created every * time, otherwise the Set is created only once and cached.</p> * * @return An unmodifiable set of the {@link DynaBean}s * property names. */ public Set<K> keySet() { if (keySet != null) { return keySet; } // Create a Set of the keys final DynaProperty[] properties = getDynaProperties(); Set<K> set = new HashSet<K>(properties.length); for (DynaProperty propertie : properties) { set.add(convertKey(propertie.getName())); } set = Collections.unmodifiableSet(set); // Cache the keySet if Not a MutableDynaClass final DynaClass dynaClass = getDynaBean().getDynaClass(); if (!(dynaClass instanceof MutableDynaClass)) { keySet = set; } return set; }
/** * <p>Returns the Set of the property * names in the decorated {@link DynaBean}.</p> * * <p><b>N.B.</b>For {@link DynaBean}s whose associated {@link DynaClass} * is a {@link MutableDynaClass} a new Set is created every * time, otherwise the Set is created only once and cached.</p> * * @return An unmodifiable set of the {@link DynaBean}s * property names. */ public Set<K> keySet() { if (keySet != null) { return keySet; } // Create a Set of the keys final DynaProperty[] properties = getDynaProperties(); Set<K> set = new HashSet<K>(properties.length); for (DynaProperty propertie : properties) { set.add(convertKey(propertie.getName())); } set = Collections.unmodifiableSet(set); // Cache the keySet if Not a MutableDynaClass final DynaClass dynaClass = getDynaBean().getDynaClass(); if (!(dynaClass instanceof MutableDynaClass)) { keySet = set; } return set; }