List of usage examples for org.apache.commons.beanutils PropertyUtils setSimpleProperty
public static void setSimpleProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Set the value of the specified simple property of the specified bean, with no type conversions.
For more details see PropertyUtilsBean
.
From source file:com.sqewd.open.dal.core.persistence.handlers.StringArrayConvertor.java
public void load(AbstractEntity entity, String field, Object data) throws Exception { StructAttributeReflect attr = ReflectionUtils.get().getAttribute(entity.getClass(), field); String sdata = (String) data; String[] spdata = sdata.split(_SPLIT_REGEX_); if (attr.Field.getType().isArray()) { Object arrdata = getArrayData(spdata, attr.Field); PropertyUtils.setSimpleProperty(entity, attr.Field.getName(), arrdata); } else// w w w. j av a 2s.c o m throw new Exception("Object field [" + attr.Field.getName() + "] is not an array."); }
From source file:net.orpiske.ssps.common.registry.MultiRsHandler.java
@Override protected SoftwareInventoryDto handleRow(ResultSet rs) throws SQLException { SoftwareInventoryDto dto = new SoftwareInventoryDto(); ResultSetMetaData meta = rs.getMetaData(); for (int i = 1; i <= meta.getColumnCount(); i++) { Object value = rs.getObject(i); String name = meta.getColumnName(i); try {/*from www . j a v a 2 s. c o m*/ /* * We convert the column name to a more appropriate and java like name * because some columns are usually named as some_thing whereas Java * properties are named someThing. This call does this conversion. */ String javaProperty = NameConverter.sqlToProperty(name); if (javaProperty.equals("version")) { Version version = Version.toVersion((String) value); PropertyUtils.setSimpleProperty(dto, javaProperty, version); } else { PropertyUtils.setSimpleProperty(dto, javaProperty, value); } } catch (Exception e) { throw new SQLException("Unable to set property " + name + " for bean" + dto.getClass(), e); } } return dto; }
From source file:net.orpiske.ssps.common.dependencies.cache.MultiRsHandler.java
@Override protected DependencyCacheDto handleRow(ResultSet rs) throws SQLException { DependencyCacheDto dto = new DependencyCacheDto(); ResultSetMetaData meta = rs.getMetaData(); for (int i = 1; i <= meta.getColumnCount(); i++) { Object value = rs.getObject(i); String name = meta.getColumnName(i); try {/*w ww . ja v a 2 s. com*/ /* * We convert the column name to a more appropriate and java like name * because some columns are usually named as some_thing whereas Java * properties are named someThing. This call does this conversion. */ String javaProperty = NameConverter.sqlToProperty(name); if (javaProperty.equals("version")) { Version version = Version.toVersion((String) value); PropertyUtils.setSimpleProperty(dto, javaProperty, version); } else { PropertyUtils.setSimpleProperty(dto, javaProperty, value); } } catch (Exception e) { throw new SQLException("Unable to set property " + name + " for bean" + dto.getClass(), e); } } return dto; }
From source file:net.orpiske.ssps.common.repository.search.cache.MultiRsHandler.java
@Override protected PackageInfo handleRow(ResultSet rs) throws SQLException { PackageInfo dto = new PackageInfo(); ResultSetMetaData meta = rs.getMetaData(); for (int i = 1; i <= meta.getColumnCount(); i++) { Object value = rs.getObject(i); String name = meta.getColumnName(i); try {/*from w ww. j av a 2s . c om*/ /* * We convert the column name to a more appropriate and java like name * because some columns are usually named as some_thing whereas Java * properties are named someThing. This call does this conversion. */ String javaProperty = NameConverter.sqlToProperty(name); if (javaProperty.equals("version")) { Version version = Version.toVersion((String) value); PropertyUtils.setSimpleProperty(dto, javaProperty, version); } else { PropertyUtils.setSimpleProperty(dto, javaProperty, value); } } catch (Exception e) { throw new SQLException("Unable to set property " + name + " for bean" + dto.getClass(), e); } } return dto; }
From source file:net.orpiske.ssps.common.registry.SoftwareInventoryRsHandler.java
@Override public SoftwareInventoryDto handle(ResultSet rs) throws SQLException { // No records to handle :O if (!rs.next()) { return null; }// w w w . j a v a 2s .co m ResultSetMetaData meta = rs.getMetaData(); for (int i = 1; i <= meta.getColumnCount(); i++) { Object value = rs.getObject(i); String name = meta.getColumnName(i); try { /* * We convert the column name to a more appropriate and java like name * because some columns are usually named as some_thing whereas Java * properties are named someThing. This call does this conversion. */ String javaProperty = NameConverter.sqlToProperty(name); if (javaProperty.equals("version")) { Version version = Version.toVersion((String) value); PropertyUtils.setSimpleProperty(dto, javaProperty, version); } else { PropertyUtils.setSimpleProperty(dto, javaProperty, value); } } catch (Exception e) { throw new SQLException("Unable to set property " + name + " for bean" + dto.getClass(), e); } } return dto; }
From source file:com.qrmedia.commons.persistence.hibernate.clone.property.SimplePropertyCloner.java
@Override protected <T> boolean cloneValue(Object source, Object target, String propertyName, Object propertyValue, HibernateEntityGraphCloner entityGraphCloner) throws IllegalArgumentException { // null properties are always be treated as simple if ((propertyValue == null) || propertyClassifier.isSimpleProperty(propertyValue.getClass())) { try {/*from www . j av a 2s. com*/ PropertyUtils.setSimpleProperty(target, propertyName, propertyValue); return true; } catch (Exception exception) { throw new IllegalArgumentException("Unable to set property '" + propertyName + "' on " + target + " due to " + exception.getClass().getSimpleName() + ": " + exception.getMessage()); } } // other properties can't be handled by this cloner return false; }
From source file:net.orpiske.ssps.common.repository.search.cache.PackageCacheRsHandler.java
@Override public PackageInfo handle(ResultSet rs) throws SQLException { // No records to handle :O if (!rs.next()) { return null; }/* w w w . j a v a 2 s . com*/ ResultSetMetaData meta = rs.getMetaData(); for (int i = 1; i <= meta.getColumnCount(); i++) { Object value = rs.getObject(i); String name = meta.getColumnName(i); try { /* * We convert the column name to a more appropriate and java like name * because some columns are usually named as some_thing whereas Java * properties are named someThing. This call does this conversion. */ String javaProperty = NameConverter.sqlToProperty(name); if (javaProperty.equals("version")) { Version version = Version.toVersion((String) value); PropertyUtils.setSimpleProperty(dto, javaProperty, version); } else { PropertyUtils.setSimpleProperty(dto, javaProperty, value); } } catch (Exception e) { throw new SQLException("Unable to set property " + name + " for bean" + dto.getClass(), e); } } return dto; }
From source file:net.orpiske.ssps.common.db.MultiRsHandler.java
@Override protected T handleRow(ResultSet rs) throws SQLException { T dto;/*from w ww. ja va 2 s . co m*/ try { dto = clazz.newInstance(); } catch (InstantiationException e1) { throw new SQLException("Unable to instantiate DTO class: " + e1.getMessage(), e1); } catch (IllegalAccessException e1) { throw new SQLException("Illegal to instantiate DTO class: " + e1.getMessage(), e1); } ResultSetMetaData meta = rs.getMetaData(); for (int i = 1; i <= meta.getColumnCount(); i++) { Object value = rs.getObject(i); String name = meta.getColumnName(i); try { /* * We convert the column name to a more appropriate and java like name * because some columns are usually named as some_thing whereas Java * properties are named someThing. This call does this conversion. */ String javaProperty = NameConverter.sqlToProperty(name); PropertyUtils.setSimpleProperty(dto, javaProperty, value); } catch (Exception e) { throw new SQLException("Unable to set property " + name + " for bean" + dto.getClass(), e); } } return dto; }
From source file:cn.sel.dvw.SimpleObjectRowMapper.java
@Override public T mapRow(ResultSet resultSet, int rowNum) throws SQLException { T rowObj;// w ww . j a va 2s . com try { rowObj = clazz.getConstructor().newInstance(); } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { e.printStackTrace(); throw new SQLException("Failed to instantiate the result object!", e); } Field[] fields = clazz.getFields(); for (Field field : fields) { MProperty annotation = field.getAnnotation(MProperty.class); String fieldName = field.getName(); String columnName = null; boolean useSetter = false; if (annotation != null) { columnName = annotation.db_col_name(); useSetter = annotation.useSetter(); } if (columnName == null || columnName.isEmpty()) { columnName = fieldName; } Object value = resultSet.getObject(columnName); if (value != null) { try { if (useSetter) { PropertyUtils.setSimpleProperty(rowObj, fieldName, value); } else { field.setAccessible(true); field.set(rowObj, value); } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { e.printStackTrace(); throw new SQLException(String.format("Failed to set value for property '%s'!", fieldName)); } } } return rowObj; }
From source file:eu.europa.ec.grow.espd.xml.common.importing.CriteriaToEspdDocumentPopulator.java
private void setCriterionValueOnEspdModel(EspdDocument espdDocument, CriterionType ublCriterion) { Optional<CcvCriterion> ccvCriterion = CriteriaList.findById(ublCriterion.getID().getValue()); if (!ccvCriterion.isPresent()) { return;// w w w. ja va 2 s . co m } try { PropertyUtils.setSimpleProperty(espdDocument, ccvCriterion.get().getEspdDocumentField(), criterionFactory.buildEspdCriterion(ccvCriterion.get(), ublCriterion)); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { log.error(e.getMessage(), e); } }