All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.data.simpledb.query.SimpleDbResultConverter Maven / Gradle / Ivy

Go to download

Provides a POJO centric model as per Spring Data interfaces to interact with Amazon SimpleDB, a non-relational datastore

There is a newer version: 1.0.1
Show newest version
package org.springframework.data.simpledb.query;

import org.springframework.data.simpledb.reflection.ReflectionUtils;

import java.util.*;

/**
 * This class convert the list of entities retrieved from db to the returned type needed by the query method
 */
public final class SimpleDbResultConverter {

	private SimpleDbResultConverter() {
		/* utility class */
	}

	public static List filterNamedAttributesAsList(List domainObjects, String attributeName) {
		List ret = new ArrayList();
		for(Object object : domainObjects) {
			ret.add(ReflectionUtils.callGetter(object, attributeName));
		}
		return ret;
	}

	public static Set filterNamedAttributesAsSet(List domainObjects, String attributeName) {
		Set ret = new LinkedHashSet();
		for(Object object : domainObjects) {
			ret.add(ReflectionUtils.callGetter(object, attributeName));
		}
		return ret;
	}

	public static List> toListOfListOfObject(List entityList, List requestedQueryFieldNames) {
		if(entityList.size() > 0) {
			List> rows = new ArrayList>();
			for(Object entity : entityList) {
				List cols = new ArrayList();
				for(String fieldName : requestedQueryFieldNames) {
					Object value = ReflectionUtils.callGetter(entity, fieldName);
					cols.add(value);
				}
				rows.add(cols);
			}
			return rows;
		} else {
			return Collections.emptyList();
		}
	}

}