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

de.tsl2.nano.service.util.finder.Expression Maven / Gradle / Ivy

Go to download

TSL2 JEE Service Access (Generic Services for Entity Access, JEE File-System-Connector, Generic Featuring, Job-Scheduling, BeanContainer, Batch, Comfortable Bean Query Definitions, JAAS, Authentification, Authorization, )

The newest version!
package de.tsl2.nano.service.util.finder;

import java.util.Arrays;
import java.util.Collection;

/**
 * additional query finder. use that, if the standard finders don't match your constraints.
 * 
 * @param  result bean type
 * @author Thomas Schneider, Thomas Schneider
 * @version $Revision$
 */
public class Expression extends AbstractFinder {
    /** serialVersionUID */
    private static final long serialVersionUID = -6987663981295488159L;

    String expression;
//    boolean asSubSelect = false;

    /**
     * constructor
     * 
     * @param queryString
     * @param asSubSelect
     * @param args
     * @param relationsToLoad
     */
    public Expression(String queryString, boolean asSubSelect, Object[] args, Class... relationsToLoad) {
        this(null, queryString, asSubSelect, args, relationsToLoad);
    }

    /**
     * constructor
     * 
     * @param resultType
     * @param queryString
     * @param asSubSelect
     * @param args
     * @param relationsToLoad
     */
    public Expression(Class resultType,
            String queryString,
            boolean asSubSelect,
            Object[] args,
            Class... relationsToLoad) {
        super(resultType, relationsToLoad);
        expression = queryString;
//        this.asSubSelect = asSubSelect;
        if (args != null) {
            par = Arrays.asList(args);
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    StringBuffer createQuery(StringBuffer currentQuery,
            Collection parameter,
            Collection> lazyRelations) {
        currentQuery.append("\n" + getConnector(currentQuery) + " (" + expression + ")");
        return currentQuery;
    }
}