All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.blazebit.persistence.impl.query.CustomSQLTypedQuery Maven / Gradle / Ivy
/*
* 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.impl.query;
import com.blazebit.persistence.impl.ParameterValueTransformer;
import com.blazebit.persistence.impl.ValuesParameterBinder;
import javax.persistence.FlushModeType;
import javax.persistence.LockModeType;
import javax.persistence.Parameter;
import javax.persistence.PersistenceException;
import javax.persistence.Query;
import javax.persistence.TemporalType;
import javax.persistence.TypedQuery;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @author Christian Beikov
* @since 1.2.0
*/
public class CustomSQLTypedQuery extends AbstractCustomQuery implements TypedQuery {
private final Query delegate;
public CustomSQLTypedQuery(QuerySpecification querySpecification, Query delegate, Map transformers, Map valuesParameters, Map valuesBinders) {
super(querySpecification, transformers, valuesParameters, valuesBinders);
this.delegate = delegate;
}
@Override
@SuppressWarnings("unchecked")
public List getResultList() {
bindParameters();
return querySpecification.createSelectPlan(firstResult, maxResults).getResultList();
}
@Override
@SuppressWarnings("unchecked")
public X getSingleResult() {
bindParameters();
return querySpecification.createSelectPlan(firstResult, maxResults).getSingleResult();
}
@Override
public int executeUpdate() {
throw new IllegalArgumentException("Can not call executeUpdate on a select query!");
}
@Override
public TypedQuery setHint(String hintName, Object value) {
// TODO: implement
throw new UnsupportedOperationException("Not yet implemented!");
}
@Override
public Map getHints() {
// TODO: implement
throw new UnsupportedOperationException("Not yet implemented!");
}
@Override
public TypedQuery setFlushMode(FlushModeType flushMode) {
delegate.setFlushMode(flushMode);
return this;
}
@Override
public FlushModeType getFlushMode() {
return delegate.getFlushMode();
}
@Override
public TypedQuery setLockMode(LockModeType lockMode) {
delegate.setLockMode(lockMode);
return this;
}
@Override
public LockModeType getLockMode() {
return delegate.getLockMode();
}
@Override
public T unwrap(Class cls) {
// TODO: This unperformant, I think we should introduce a hasParticiaptingQueries in QuerySpecification
if (querySpecification.getParticipatingQueries().size() > 1) {
throw new PersistenceException("Unsupported unwrap: " + cls.getName());
}
return delegate.unwrap(cls);
}
/* Covariant override */
@Override
public TypedQuery setMaxResults(int maxResults) {
super.setMaxResults(maxResults);
return this;
}
@Override
public TypedQuery setFirstResult(int startPosition) {
super.setFirstResult(startPosition);
return this;
}
@Override
public TypedQuery setParameter(Parameter param, T value) {
super.setParameter(param, value);
return this;
}
@Override
public TypedQuery setParameter(Parameter param, Calendar value, TemporalType temporalType) {
super.setParameter(param, value, temporalType);
return this;
}
@Override
public TypedQuery setParameter(Parameter param, Date value, TemporalType temporalType) {
super.setParameter(param, value, temporalType);
return this;
}
@Override
public TypedQuery setParameter(String name, Object value) {
super.setParameter(name, value);
return this;
}
@Override
public TypedQuery setParameter(String name, Calendar value, TemporalType temporalType) {
super.setParameter(name, value, temporalType);
return this;
}
@Override
public TypedQuery setParameter(String name, Date value, TemporalType temporalType) {
super.setParameter(name, value, temporalType);
return this;
}
@Override
public TypedQuery setParameter(int position, Object value) {
super.setParameter(position, value);
return this;
}
@Override
public TypedQuery setParameter(int position, Calendar value, TemporalType temporalType) {
super.setParameter(position, value, temporalType);
return this;
}
@Override
public TypedQuery setParameter(int position, Date value, TemporalType temporalType) {
super.setParameter(position, value, temporalType);
return this;
}
}