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

com.blazebit.persistence.criteria.impl.expression.AbstractExpression Maven / Gradle / Ivy

There is a newer version: 1.6.11
Show newest version
/*
 * Copyright 2014 - 2020 Blazebit.
 *
 * 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.blazebit.persistence.criteria.impl.expression;

import com.blazebit.persistence.criteria.BlazeExpression;
import com.blazebit.persistence.criteria.impl.BlazeCriteriaBuilderImpl;
import com.blazebit.persistence.criteria.impl.expression.function.CastFunction;

import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collection;

/**
 * @author Christian Beikov
 * @since 1.2.0
 */
public abstract class AbstractExpression extends AbstractSelection implements BlazeExpression {

    private static final long serialVersionUID = 1L;

    public AbstractExpression(BlazeCriteriaBuilderImpl criteriaBuilder, Class javaType) {
        super(criteriaBuilder, javaType);
    }

    @Override
    @SuppressWarnings({"unchecked"})
    public  BlazeExpression as(Class type) {
        return type.equals(getJavaType()) ? (BlazeExpression) this : new CastFunction(criteriaBuilder, type, this);
    }

    @Override
    public Predicate isNull() {
        return criteriaBuilder.isNull(this);
    }

    @Override
    public Predicate isNotNull() {
        return criteriaBuilder.isNotNull(this);
    }

    @Override
    public Predicate in(Object... values) {
        return criteriaBuilder.in(this, values);
    }

    @Override
    @SuppressWarnings({"unchecked"})
    public Predicate in(Expression... values) {
        return criteriaBuilder.in(this, (Expression[]) values);
    }

    @Override
    @SuppressWarnings({"unchecked"})
    public Predicate in(Collection values) {
        return criteriaBuilder.in(this, (Collection) values);
    }

    @Override
    @SuppressWarnings("unchecked")
    public Predicate in(Expression> values) {
        return criteriaBuilder.in(this, values);
    }

    @SuppressWarnings({"unchecked"})
    public BlazeExpression asLong() {
        setJavaType(Long.class);
        return (BlazeExpression) this;
    }

    @SuppressWarnings({"unchecked"})
    public BlazeExpression asInteger() {
        setJavaType(Integer.class);
        return (BlazeExpression) this;
    }

    @SuppressWarnings({"unchecked"})
    public BlazeExpression asFloat() {
        setJavaType(Float.class);
        return (BlazeExpression) this;
    }

    @SuppressWarnings({"unchecked"})
    public BlazeExpression asDouble() {
        setJavaType(Double.class);
        return (BlazeExpression) this;
    }

    @SuppressWarnings({"unchecked"})
    public BlazeExpression asBigDecimal() {
        setJavaType(BigDecimal.class);
        return (BlazeExpression) this;
    }

    @SuppressWarnings({"unchecked"})
    public BlazeExpression asBigInteger() {
        setJavaType(BigInteger.class);
        return (BlazeExpression) this;
    }

    @SuppressWarnings({"unchecked"})
    public BlazeExpression asString() {
        setJavaType(String.class);
        return (BlazeExpression) this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy