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

org.uqbar.commons.model.SearchByExample Maven / Gradle / Ivy

package org.uqbar.commons.model;

import java.util.List;

import org.uqbar.commons.utils.TransactionalAndObservable;

/**
 * Default implementation of a {@link Search}, delegating into a {@link Home} object and performing a search
 * by example.
 * 
 * @author npasserini
 * 
 * @param 
 */
@TransactionalAndObservable
public class SearchByExample extends Search {
	public static final String EXAMPLE = "example";

	private T example;
	private Home home;

	/**
	 * Straightforward constructor.
	 * 
	 * @param home The home into which we will delegate our searches.
	 */
	public SearchByExample(Home home) {
		super(home.getEntityType());
		this.home = home;

		init();
	}

	protected void init() {
		this.createExampleObject();
		this.search();
	}

	/**
	 * The object to serve as an example for the searches to be performed. Any properties set into this object
	 * will be used as a filter when the search method is invoked.
	 */
	public T getExample() {
		return this.example;
	}

	@Override
	public void clear() {
		this.createExampleObject();
	}

	protected void createExampleObject() {
		this.example = this.home.createExample();
	}

	@Override
	protected List doSearch() {
		return this.home.searchByExample(this.example);
	}

	@Override
	public void removeSelected() {
		this.home.delete(this.getSelected());
		this.search();
	}

	public void setExample(T example) {
		this.example = example;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy