/* * (non-Javadoc) * * @see org.seasar.extension.jdbc.ResultSetHandler#handle(java.sql.ResultSet) */ @SuppressWarnings("unchecked") public Object handle(ResultSet rs) throws SQLException { // Set<String(columnName)> final Set columnNames = createColumnNames(rs.getMetaData()); // Map<String(columnName), PropertyType> Map propertyCache = null; // [DAO-118] (2007/08/26) // Map<String(relationNoSuffix), Map<String(columnName), PropertyType>> Map relationPropertyCache = null; // [DAO-118] (2007/08/25) final int relSize = getBeanMetaData().getRelationPropertyTypeSize(); final RelationRowCache relRowCache = new RelationRowCache(relSize); int count = 0; while (rs.next()) { // Lazy initialization because if the result is zero, the cache is // unused. if (propertyCache == null) { propertyCache = createPropertyCache(columnNames); } if (relationPropertyCache == null) { relationPropertyCache = createRelationPropertyCache(columnNames); } // Create row instance of base table by row property cache. final Object row = createRow(rs, propertyCache); for (int i = 0; i < relSize; ++i) { RelationPropertyType rpt = getBeanMetaData().getRelationPropertyType(i); if (rpt == null) { continue; } Object relationRow = null; Map relKeyValues = new HashMap(); // TODO 1レコード目でnullが返るなら、2レコード目以降は不要では? RelationKey relKey = createRelationKey(rs, rpt, columnNames, relKeyValues); if (relKey != null) { relationRow = relRowCache.getRelationRow(i, relKey); if (relationRow == null) { relationRow = createRelationRow(rs, rpt, columnNames, relKeyValues, relationPropertyCache); relRowCache.addRelationRow(i, relKey, relationRow); } } if (relationRow != null) { PropertyDesc pd = rpt.getPropertyDesc(); pd.setValue(row, relationRow); postCreateRow(relationRow); } } postCreateRow(row); count++; if (!fetchHandler.execute(row)) { break; } } return Integer.valueOf(count); }
/** * 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 dest あて先 */ public static void copyProperties(Map src, Object dest) { if (src == null || dest == null) { return; } BeanDesc beanDesc = BeanDescFactory.getBeanDesc(dest.getClass()); for (Iterator i = src.keySet().iterator(); i.hasNext(); ) { String key = (String) i.next(); if (!beanDesc.hasPropertyDesc(key)) { continue; } PropertyDesc pd = beanDesc.getPropertyDesc(key); if (pd.isWritable()) { pd.setValue(dest, src.get(key)); } } }
@Override protected int getOrder(PropertyDesc propDesc) { Method method = propDesc.getWriteMethod(); ValidateOrder order = method.getAnnotation(ValidateOrder.class); if (order == null) { return super.getOrder(propDesc); } return order.value(); }
/** * パラメータを準備します。 * * @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]); } }
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); }
public ActionPropertyConfig createActionPropertyConfig( BeanDesc beanDesc, PropertyDesc propertyDesc) { Method readMehod = propertyDesc.getReadMethod(); ExportToSession toSession = (ExportToSession) Annotations.getAnnotation(ExportToSession.class, readMehod); if (toSession != null) { return new ActionPropertyConfigImpl(Constants.SESSION); } Export export = (Export) Annotations.getAnnotation(Export.class, readMehod); if (export != null) { return new ActionPropertyConfigImpl(export.value()); } return super.createActionPropertyConfig(beanDesc, propertyDesc); }
/** * 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)); } } } } }
/** * 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; }
protected void addAutoUpdateWhereBindVariables( List<Object> varList, List<ValueType> varValueTypeList, Object bean) { BeanMetaData bmd = getBeanMetaData(); for (int i = 0; i < bmd.getPrimaryKeySize(); ++i) { PropertyType pt = bmd.getPropertyTypeByColumnName(bmd.getPrimaryKey(i)); PropertyDesc pd = pt.getPropertyDesc(); varList.add(pd.getValue(bean)); varValueTypeList.add(pt.getValueType()); } if (bmd.hasVersionNoPropertyType()) { PropertyType pt = bmd.getVersionNoPropertyType(); PropertyDesc pd = pt.getPropertyDesc(); varList.add(pd.getValue(bean)); varValueTypeList.add(pt.getValueType()); } if (bmd.hasTimestampPropertyType()) { PropertyType pt = bmd.getTimestampPropertyType(); PropertyDesc pd = pt.getPropertyDesc(); varList.add(pd.getValue(bean)); varValueTypeList.add(pt.getValueType()); } }
public Object getValue() { Object value = super.getValue(); if (value instanceof SelectItem[] || value instanceof SelectItem) { return value; } List list = new ArrayList(); boolean nullLabelSet = false; if (nullLabelRequired) { SelectItem si = new SelectItem(); si.setValue(""); final FacesContext context = getFacesContext(); FacesMessage mes = FacesMessageUtil.getMessage(context, NULL_LABEL_MESSAGE_CODE, null); si.setLabel(mes.getSummary()); list.add(si); nullLabelSet = true; } if (value != null && value.getClass().isArray()) { value = Arrays.asList((Object[]) value); } if (value instanceof Collection) { final Collection valueCollection = (Collection) value; if (!nullLabelSet && valueCollection.size() == 0) { list.add(BLANK_SELECT_ITEM); } else { for (Iterator it = valueCollection.iterator(); it.hasNext(); ) { Object item = it.next(); if (item instanceof SelectItem) { list.add(item); } else if (item instanceof Map) { Map map = (Map) item; SelectItem si = new SelectItem(); Object itemValueValue = map.get(itemValue); if (itemValueValue != null) { si.setValue(itemValueValue); } Object itemLabelValue = map.get(itemLabel); if (itemLabelValue == null) { itemLabelValue = itemValueValue; } if (itemLabelValue != null) { si.setLabel(itemLabelValue.toString()); } list.add(si); } else { SelectItem si = new SelectItem(); BeanDesc bd = BeanDescFactory.getBeanDesc(item.getClass()); PropertyDesc pd = bd.getPropertyDesc(itemValue); Object itemValueValue = (pd.isReadable()) ? pd.getValue(item) : null; if (itemValueValue != null) { si.setValue(itemValueValue); } Object itemLabelValue = null; if (bd.hasPropertyDesc(itemLabel)) { pd = bd.getPropertyDesc(itemLabel); itemLabelValue = (pd.isReadable()) ? pd.getValue(item) : null; } if (itemLabelValue == null) { itemLabelValue = itemValueValue; } if (itemLabelValue != null) { si.setLabel(itemLabelValue.toString()); } list.add(si); } } } } else if (value instanceof Map) { final Map map = (Map) value; if (!nullLabelSet && map.size() == 0) { list.add(BLANK_SELECT_ITEM); } else { for (Iterator it = map.keySet().iterator(); it.hasNext(); ) { Object key = it.next(); Object val = map.get(key); SelectItem si = new SelectItem(); if (key != null) { si.setLabel(key.toString()); } if (val != null) { si.setValue(val); } list.add(si); } } } else { if (!nullLabelSet && value == null) { list.add(BLANK_SELECT_ITEM); } } return list; }
protected void updateVersionNoIfNeed(Object bean) { if (getVersionNo() != null) { PropertyDesc pd = getBeanMetaData().getVersionNoPropertyType().getPropertyDesc(); pd.setValue(bean, getVersionNo()); } }
protected void updateTimestampIfNeed(Object bean) { if (getTimestamp() != null) { PropertyDesc pd = getBeanMetaData().getTimestampPropertyType().getPropertyDesc(); pd.setValue(bean, getTimestamp()); } }