List of usage examples for org.apache.commons.beanutils DynaBean get
public Object get(String name);
From source file:org.apache.ddlutils.platform.PlatformImplBase.java
/** * Returns all identity properties whose value were defined by the database and which * now need to be read back from the DB. * /*from w w w.ja v a2s . c om*/ * @param model The database model * @param dynaClass The dyna class * @param bean The bean * @return The columns */ private Column[] getRelevantIdentityColumns(Database model, SqlDynaClass dynaClass, final DynaBean bean) { SqlDynaProperty[] properties = dynaClass.getSqlDynaProperties(); Collection relevantProperties = CollectionUtils.select(Arrays.asList(properties), new Predicate() { public boolean evaluate(Object input) { SqlDynaProperty prop = (SqlDynaProperty) input; // we only want those identity columns that were really specified by the DB // if the platform allows specification of values for identity columns // in INSERT/UPDATE statements, then we need to filter the corresponding // columns out return prop.getColumn().isAutoIncrement() && (!isIdentityOverrideOn() || !getPlatformInfo().isIdentityOverrideAllowed() || (bean.get(prop.getName()) == null)); } }); Column[] columns = new Column[relevantProperties.size()]; int idx = 0; for (Iterator propIt = relevantProperties.iterator(); propIt.hasNext(); idx++) { columns[idx] = ((SqlDynaProperty) propIt.next()).getColumn(); } return columns; }
From source file:org.apache.ddlutils.platform.PlatformImplBase.java
/** * Derives the column values for the given dyna properties from the dyna bean. * // w ww. j av a2 s . c o m * @param properties The properties * @param bean The bean * @return The values indexed by the column names */ protected HashMap toColumnValues(SqlDynaProperty[] properties, DynaBean bean) { HashMap result = new HashMap(); for (int idx = 0; idx < properties.length; idx++) { result.put(properties[idx].getName(), bean == null ? null : bean.get(properties[idx].getName())); } return result; }
From source file:org.apache.ddlutils.platform.PlatformImplBase.java
/** * Sets a parameter of the prepared statement based on the type of the column of the property. * //from w w w . j av a 2 s .c o m * @param statement The statement * @param sqlIndex The index of the parameter to set in the statement * @param dynaBean The bean of which to take the value * @param property The property of the bean, which also defines the corresponding column */ protected void setObject(PreparedStatement statement, int sqlIndex, DynaBean dynaBean, SqlDynaProperty property) throws SQLException { int typeCode = property.getColumn().getTypeCode(); Object value = dynaBean.get(property.getName()); setStatementParameterValue(statement, sqlIndex, typeCode, value); }
From source file:org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform.java
/** * {@inheritDoc}//from w w w . j av a2s . c o m */ protected void setObject(PreparedStatement statement, int sqlIndex, DynaBean dynaBean, SqlDynaProperty property) throws SQLException { int typeCode = property.getColumn().getTypeCode(); Object value = dynaBean.get(property.getName()); // PostgreSQL doesn't like setNull for BYTEA columns if (value == null) { switch (typeCode) { case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: case Types.BLOB: statement.setBytes(sqlIndex, null); break; default: statement.setNull(sqlIndex, typeCode); break; } } else { super.setObject(statement, sqlIndex, dynaBean, property); } }
From source file:org.apache.ddlutils.TestAgainstLiveDatabaseBase.java
/** * Determines the value of the bean's property that has the given name. Depending on the * case-setting of the current builder, the case of teh name is considered or not. * //from w w w . j a v a2 s . c o m * @param bean The bean * @param propName The name of the property * @return The value */ protected Object getPropertyValue(DynaBean bean, String propName) { if (getPlatform().isDelimitedIdentifierModeOn()) { return bean.get(propName); } else { DynaProperty[] props = bean.getDynaClass().getDynaProperties(); for (int idx = 0; idx < props.length; idx++) { if (propName.equalsIgnoreCase(props[idx].getName())) { return bean.get(props[idx].getName()); } } throw new IllegalArgumentException("The bean has no property with the name " + propName); } }
From source file:org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDynaBeanImpl.java
public Object get(Object anObject) throws MetadataException { if (anObject == null) return null; if (anObject instanceof DynaBean) { DynaBean dynaBean = (DynaBean) anObject; try {/*ww w . j a v a2s .c o m*/ return dynaBean.get(getName()); } catch (Throwable t) { String msg = dynaBean.getClass().getName(); logGetProblem(anObject, msg); throw new PersistenceBrokerException(t); } } else { String msg = "the object is not a DynaBean"; logGetProblem(anObject, msg); throw new PersistenceBrokerException(msg); } }
From source file:org.ejbca.ui.cli.FieldEditor.java
/** gets a field value from a bean * /*w ww .ja v a 2 s . co m*/ * @param field the field to get * @param obj the bran to get the value from * @return the value */ public Object getBeanValue(final String field, final Object obj) { final DynaBean moddb = new WrapDynaBean(obj); final Object gotValue = moddb.get(field); logger.info(field + " returned value '" + gotValue + "'."); return gotValue; }
From source file:org.examproject.task.core.Facade.java
private DynaBean getParam() { // get the content object of the current. Object o = contentList.remove(0); // set the object to map. DynaBean param = (DynaBean) paramBeanFactory.create(); Map<String, Object> values = (Map<String, Object>) param.get("values"); values.put("content", o); return param; }
From source file:org.examproject.task.service.HogeClosure.java
@Override public void execute(Object o) { LOG.debug("called."); try {//from w ww. j ava2 s . c om // the argument object is dynabean object. DynaBean state = (DynaBean) o; // get the value map from the param object. DynaBean param = (DynaBean) state.get("param"); Map<String, HogeDto> values = (Map<String, HogeDto>) param.get("values"); // get the content object. HogeDto content = (HogeDto) values.get("content"); if (content == null) { LOG.warn("content is null."); return; } // mock task.. LOG.debug("waitTime: " + content.getWaitTime().toString()); Thread.sleep(Long.parseLong(content.getWaitTime())); LOG.debug(content.getName() + " ok."); } catch (Exception e) { LOG.error("error: " + e.getMessage()); throw new RuntimeException(e); } }
From source file:org.jaffa.qm.finder.apis.ExcelExportService.java
/** * Formats the input object based on the layout specified in the ColumnModel. *///from w ww . j a va 2 s . c o m private static String format(Object value, DynaBean columnModel) { try { String layout = (String) columnModel.get("layout"); if ("[hh:mm]".equals(layout)) return decimal2hmm(value); } catch (Exception e) { } return value != null ? value.toString() : ""; }