public ActionPropertyConfig createActionPropertyConfig( BeanDesc beanDesc, PropertyDesc propertyDesc) { String fieldName = propertyDesc.getPropertyName() + EXPORT_SUFFIX; if (!beanDesc.hasField(fieldName)) { return new ActionPropertyConfigImpl(); } if (!ConstantAnnotationUtil.isConstantAnnotationStringField(beanDesc.getField(fieldName))) { return new ActionPropertyConfigImpl(); } String value = (String) beanDesc.getFieldValue(fieldName, null); return new ActionPropertyConfigImpl(value); }
/** * JavaBeansの値をマップにコピーします。 * * @param src ソース * @param dest あて先 */ public static void copyProperties(Object src, Map dest) { if (src == null || dest == null) { return; } final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(src.getClass()); final int size = beanDesc.getPropertyDescSize(); for (int i = 0; i < size; ++i) { final PropertyDesc pd = beanDesc.getPropertyDesc(i); if (pd.isReadable() && pd.isWritable()) { final Object value = pd.getValue(src); dest.put(pd.getPropertyName(), value); } } }
/** * JavaBeansの値からマップを作成します。 * * @param src ソース * @param prefix プレフィックス * @return JavaBeansの値を持つマップ */ public static Map createProperties(Object src, String prefix) { Map map = new HashMap(); if (src == null) { return map; } final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(src.getClass()); final int size = beanDesc.getPropertyDescSize(); for (int i = 0; i < size; ++i) { final PropertyDesc pd = beanDesc.getPropertyDesc(i); if (pd.isReadable()) { if (prefix == null) { final Object value = pd.getValue(src); String name = pd.getPropertyName().replace('$', '.'); map.put(name, value); } else if (pd.getPropertyName().startsWith(prefix)) { final Object value = pd.getValue(src); String name = pd.getPropertyName().substring(prefix.length()).replace('$', '.'); map.put(name, value); } } } return map; }
/** * JavaBeansの値をJavaBeansにコピーします。 * * @param src ソース * @param dest あて先 * @param includeNull <code>null</code>を含めるかどうか */ public static void copyProperties( final Object src, final Object dest, final boolean includeNull) { final BeanDesc srcBeanDesc = BeanDescFactory.getBeanDesc(src.getClass()); final BeanDesc destBeanDesc = BeanDescFactory.getBeanDesc(dest.getClass()); final int propertyDescSize = destBeanDesc.getPropertyDescSize(); for (int i = 0; i < propertyDescSize; i++) { final PropertyDesc destPropertyDesc = destBeanDesc.getPropertyDesc(i); final String propertyName = destPropertyDesc.getPropertyName(); if (srcBeanDesc.hasPropertyDesc(propertyName)) { final PropertyDesc srcPropertyDesc = srcBeanDesc.getPropertyDesc(propertyName); if (destPropertyDesc.isWritable() && srcPropertyDesc.isReadable()) { final Object value = srcPropertyDesc.getValue(src); if (includeNull || value != null) { destPropertyDesc.setValue(dest, srcPropertyDesc.getValue(src)); } } } } }
/** * パラメータを準備します。 * * @param parameter パラメータ */ protected void prepareParameter(T parameter) { sqlContext = new SqlContextImpl(); if (parameter != null) { Class<?> clazz = parameter.getClass(); if (ValueTypes.isSimpleType(clazz) || TemporalParameter.class == clazz || LobParameter.class == clazz) { sqlContext.addArg("$1", parameter, clazz); } else if (parameter instanceof Map) { @SuppressWarnings("unchecked") Map<Object, Object> paramMap = (Map<Object, Object>) parameter; Set<Entry<Object, Object>> entrySet = paramMap.entrySet(); for (Map.Entry<Object, Object> entry : entrySet) { Object value = entry.getValue(); Object key = entry.getKey(); if (key == null || !(key instanceof CharSequence)) { continue; } String name = ((CharSequence) key).toString(); sqlContext.addArg(name, value, (value == null ? String.class : value.getClass())); } } else { BeanDesc beanDesc = BeanDescFactory.getBeanDesc(clazz); for (int i = 0; i < beanDesc.getPropertyDescSize(); i++) { PropertyDesc pd = beanDesc.getPropertyDesc(i); if (!pd.isReadable()) { continue; } Object value = Parameter.wrapIfNecessary(pd, pd.getValue(parameter)); sqlContext.addArg(pd.getPropertyName(), value, pd.getPropertyType()); } } } node.accept(sqlContext); Object[] vars = sqlContext.getBindVariables(); Class<?>[] types = sqlContext.getBindVariableTypes(); int size = vars.length; for (int i = 0; i < size; i++) { addParam(vars[i], types[i]); } }