001//@formatter:off
002/*
003 * Query Request - demonstrates ACTIVE OBJECT
004 * Code-Beispiel zum Buch Patterns Kompakt, Verlag Springer Vieweg
005 * Copyright 2014 Karl Eilebrecht
006 * 
007 * Licensed under the Apache License, Version 2.0 (the "License"):
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019//@formatter:on
020package de.calamanari.pk.activeobject;
021
022import java.util.List;
023import java.util.concurrent.Callable;
024import java.util.concurrent.FutureTask;
025
026import org.slf4j.Logger;
027import org.slf4j.LoggerFactory;
028
029/**
030 * Query Request - objectified request
031 * 
032 * @author <a href="mailto:Karl.Eilebrecht(a/t)calamanari.de">Karl Eilebrecht</a>
033 */
034public class QueryRequest extends FutureTask<List<String[]>> {
035
036    private static final Logger LOGGER = LoggerFactory.getLogger(QueryRequest.class);
037
038    /**
039     * first name filter, parameter of the initial call
040     */
041    private final String paramFirstName;
042
043    /**
044     * last name filter, parameter of the initial call
045     */
046    private final String paramLastName;
047
048    /**
049     * birthday filter, parameter of the initial call
050     */
051    private final String paramBirthday;
052
053    /**
054     * Creates an objectified request
055     * 
056     * @param engine query engine to be used
057     * @param paramFirstName person's first name to query for
058     * @param paramLastName person's last name to query for
059     * @param paramBirthday person's birthday to query for
060     */
061    public QueryRequest(final AbstractHistoryQueryEngine engine, final String paramFirstName, final String paramLastName, final String paramBirthday) {
062        super(new Callable<List<String[]>>() {
063
064            @Override
065            public List<String[]> call() throws Exception {
066                return engine.queryHistoryData(paramFirstName, paramLastName, paramBirthday);
067            }
068
069        });
070        this.paramFirstName = paramFirstName;
071        this.paramLastName = paramLastName;
072        this.paramBirthday = paramBirthday;
073        LOGGER.debug("{} created", this);
074    }
075
076    /**
077     * Returns the first name filter
078     * 
079     * @return first name to query for
080     */
081    public String getParamFirstName() {
082        return paramFirstName;
083    }
084
085    /**
086     * Returns the last name filter
087     * 
088     * @return last name to query for
089     */
090    public String getParamLastName() {
091        return paramLastName;
092    }
093
094    /**
095     * Returns the birthday filter
096     * 
097     * @return birthday to query for
098     */
099    public String getParamBirthday() {
100        return paramBirthday;
101    }
102
103    @Override
104    public void run() {
105        LOGGER.debug("{}.run() called for {}", this.getClass().getSimpleName(), this);
106        super.run();
107    }
108
109    @Override
110    public String toString() {
111        return this.getClass().getSimpleName() + "({paramFirstName=" + paramFirstName + ", paramLastName=" + paramLastName + ", paramBirthday=" + paramBirthday
112                + "})";
113    }
114
115}