/** * Determines the type of a {@code DynaProperty}. Here a special treatment * is needed for mapped properties. * * @param dynaProperty the property descriptor * @param value the value object to be set for this property * @return the type of this property */ private static Class<?> dynaPropertyType(final DynaProperty dynaProperty, final Object value) { if (!dynaProperty.isMapped()) { return dynaProperty.getType(); } return (value == null) ? String.class : value.getClass(); } }
/** * Determines the type of a {@code DynaProperty}. Here a special treatment * is needed for mapped properties. * * @param dynaProperty the property descriptor * @param value the value object to be set for this property * @return the type of this property */ private static Class<?> dynaPropertyType(final DynaProperty dynaProperty, final Object value) { if (!dynaProperty.isMapped()) { return dynaProperty.getType(); } return (value == null) ? String.class : value.getClass(); } }
/** * Set the value of a simple property with the specified name. * * @param name Name of the property whose value is to be set * @param value Value to which this property is to be set * * @throws ConversionException if the specified value cannot be * converted to the type required for this property * @throws IllegalArgumentException if there is no property * of the specified name * @throws NullPointerException if an attempt is made to set a * primitive property to null */ public void set(final String name, final Object value) { final DynaProperty descriptor = getDynaProperty(name); if (value == null) { if (descriptor.getType().isPrimitive()) { throw new NullPointerException ("Primitive value for '" + name + "'"); } } else if (!isAssignable(descriptor.getType(), value.getClass())) { throw new ConversionException ("Cannot assign value of type '" + value.getClass().getName() + "' to property '" + name + "' of type '" + descriptor.getType().getName() + "'"); } values.put(name, value); }
/** * Set the value of a simple property with the specified name. * * @param name Name of the property whose value is to be set * @param value Value to which this property is to be set * * @throws ConversionException if the specified value cannot be * converted to the type required for this property * @throws IllegalArgumentException if there is no property * of the specified name * @throws NullPointerException if an attempt is made to set a * primitive property to null */ public void set(final String name, final Object value) { final DynaProperty descriptor = getDynaProperty(name); if (value == null) { if (descriptor.getType().isPrimitive()) { throw new NullPointerException ("Primitive value for '" + name + "'"); } } else if (!isAssignable(descriptor.getType(), value.getClass())) { throw new ConversionException ("Cannot assign value of type '" + value.getClass().getName() + "' to property '" + name + "' of type '" + descriptor.getType().getName() + "'"); } values.put(name, value); }
/** * 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 */ protected void add(final DynaProperty property) { add(property.getName(), property.getType()); }
final Class<?> type = getDynaProperty(name).getType(); if (!type.isPrimitive()) { return (value);
/** * Get a column value from a {@link ResultSet} for the specified name. * * @param resultSet The result set * @param name The property name * @return The value * @throws SQLException if an error occurs */ protected Object getObject(final ResultSet resultSet, final String name) throws SQLException { final DynaProperty property = getDynaProperty(name); if (property == null) { throw new IllegalArgumentException("Invalid name '" + name + "'"); } final String columnName = getColumnName(name); final Class<?> type = property.getType(); // java.sql.Date if (type.equals(Date.class)) { return resultSet.getDate(columnName); } // java.sql.Timestamp if (type.equals(Timestamp.class)) { return resultSet.getTimestamp(columnName); } // java.sql.Time if (type.equals(Time.class)) { return resultSet.getTime(columnName); } return resultSet.getObject(columnName); }
/** * Get a column value from a {@link ResultSet} for the specified name. * * @param resultSet The result set * @param name The property name * @return The value * @throws SQLException if an error occurs */ protected Object getObject(final ResultSet resultSet, final String name) throws SQLException { final DynaProperty property = getDynaProperty(name); if (property == null) { throw new IllegalArgumentException("Invalid name '" + name + "'"); } final String columnName = getColumnName(name); final Class<?> type = property.getType(); // java.sql.Date if (type.equals(Date.class)) { return resultSet.getDate(columnName); } // java.sql.Timestamp if (type.equals(Timestamp.class)) { return resultSet.getTimestamp(columnName); } // java.sql.Time if (type.equals(Time.class)) { return resultSet.getTime(columnName); } return resultSet.getObject(columnName); }
final Class<?> type = getDynaProperty(name).getType(); if (!type.isPrimitive()) { return (value);
if (descriptor.getType().isPrimitive()) { throw new NullPointerException ("Primitive value for '" + name + "'"); } else if (!isAssignable(descriptor.getType(), value.getClass())) { throw new ConversionException ("Cannot assign value of type '" + value.getClass().getName() + "' to property '" + name + "' of type '" + descriptor.getType().getName() + "'");
if (descriptor.getType().isPrimitive()) { throw new NullPointerException ("Primitive value for '" + name + "'"); } else if (!isAssignable(descriptor.getType(), value.getClass())) { throw new ConversionException ("Cannot assign value of type '" + value.getClass().getName() + "' to property '" + name + "' of type '" + descriptor.getType().getName() + "'");
/** * <p>Return the value of a simple property with the specified name.</p> * * <p><strong>N.B.</strong> Returns <code>null</code> if there is no property * of the specified name.</p> * * @param name Name of the property whose value is to be retrieved. * @return The property's value * @throws IllegalArgumentException if no property name is specified */ public Object get(final String name) { if (name == null) { throw new IllegalArgumentException("No property name specified"); } // Value found Object value = values.get(name); if (value != null) { return value; } // Property doesn't exist if (!isDynaProperty(name)) { return null; } // Property doesn't exist value = createProperty(name, dynaClass.getDynaProperty(name).getType()); if (value != null) { set(name, value); } return value; }
/** * <p>Return the value of a simple property with the specified name.</p> * * <p><strong>N.B.</strong> Returns <code>null</code> if there is no property * of the specified name.</p> * * @param name Name of the property whose value is to be retrieved. * @return The property's value * @throws IllegalArgumentException if no property name is specified */ public Object get(final String name) { if (name == null) { throw new IllegalArgumentException("No property name specified"); } // Value found Object value = values.get(name); if (value != null) { return value; } // Property doesn't exist if (!isDynaProperty(name)) { return null; } // Property doesn't exist value = createProperty(name, dynaClass.getDynaProperty(name).getType()); if (value != null) { set(name, value); } return value; }
throw new IllegalArgumentException ("Non-mapped property for '" + name + "(" + key + ")' " + dynaClass.getDynaProperty(name).getType().getName());
throw new IllegalArgumentException ("Non-indexed property for '" + name + "[" + index + "]'" + dynaClass.getDynaProperty(name).getType().getName());
throw new IllegalArgumentException ("Non-mapped property for '" + name + "(" + key + ")' " + dynaClass.getDynaProperty(name).getType().getName());
throw new IllegalArgumentException ("Non-mapped property for '" + name + "(" + key + ")'" + dynaClass.getDynaProperty(name).getType().getName());
throw new IllegalArgumentException ("Non-mapped property for '" + name + "(" + key + ")'" + dynaClass.getDynaProperty(name).getType().getName());
return null; // Skip this property setter type = dynaProperty.getType();