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

com.mysema.query.support.SimpleProjectableAdapter Maven / Gradle / Ivy

There is a newer version: 3.7.4
Show newest version
/*
 * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team)
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mysema.query.support;

import java.util.List;

import com.mysema.commons.lang.CloseableIterator;
import com.mysema.query.Projectable;
import com.mysema.query.QueryModifiers;
import com.mysema.query.SearchResults;
import com.mysema.query.SimpleProjectable;
import com.mysema.query.SimpleQuery;
import com.mysema.query.types.Expression;
import com.mysema.query.types.OrderSpecifier;
import com.mysema.query.types.ParamExpression;
import com.mysema.query.types.Predicate;

/**
 * SimpleQueryAdapter is an adapter implementation for the {@link SimpleQuery} and 
 * {@link SimpleProjectable} interfaces
 *
 * @author tiwe
 *
 * @param  type of entity
 */
public class SimpleProjectableAdapter implements SimpleQuery>, SimpleProjectable {

    private final Projectable projectable;

    private final Expression projection;

    private final SimpleQuery query;

    @SuppressWarnings("BC_UNCONFIRMED_CAST")
    public  & Projectable> SimpleProjectableAdapter(Q query, Expression projection) {
        // NOTE : this is a correct cast which is not handled properly by FindBugs
        this(query, query, projection);
    }

    public SimpleProjectableAdapter(SimpleQuery query, Projectable projectable, Expression projection) {
        this.query = query;
        this.projectable = projectable;
        this.projection = projection;
    }

    @Override
    public boolean exists() {
        return projectable.exists();
    }

    @Override
    public boolean notExists() {
        return projectable.notExists();
    }

    @Override
    public long count() {
        return projectable.count();
    }

    @Override
    public SimpleProjectableAdapter distinct() {
        query.distinct();
        return this;
    }

    @Override
    public SimpleProjectableAdapter limit(long limit) {
        query.limit(limit);
        return this;
    }

    @Override
    public CloseableIterator iterate() {
        return projectable.iterate(projection);
    }

    @Override
    public List list() {
        return projectable.list(projection);
    }

    @Override
    public SearchResults listResults() {
        return projectable.listResults(projection);
    }

    @Override
    public SimpleProjectableAdapter offset(long offset) {
        query.offset(offset);
        return this;
    }

    @Override
    public SimpleProjectableAdapter orderBy(OrderSpecifier... o) {
        query.orderBy(o);
        return this;
    }

    @Override
    public SimpleProjectableAdapter restrict(QueryModifiers modifiers) {
        query.restrict(modifiers);
        return this;
    }

    @Override
    public 

SimpleProjectableAdapter set(ParamExpression

param, P value) { query.set(param, value); return this; } @Override public String toString() { return query.toString(); } @Override public T singleResult() { return projectable.singleResult(projection); } @Override public T uniqueResult() { return projectable.uniqueResult(projection); } @Override public SimpleProjectableAdapter where(Predicate... e) { query.where(e); return this; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy