org.omnifaces.persistence.service.SubqueryRoot Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of omnipersistence Show documentation
Show all versions of omnipersistence Show documentation
Utilities for JPA, JDBC and DataSources
The newest version!
/*
* Copyright 2021 OmniFaces
*
* 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
*
* https://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 org.omnifaces.persistence.service;
import jakarta.persistence.criteria.Fetch;
import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.JoinType;
import jakarta.persistence.criteria.Root;
import jakarta.persistence.metamodel.CollectionAttribute;
import jakarta.persistence.metamodel.ListAttribute;
import jakarta.persistence.metamodel.MapAttribute;
import jakarta.persistence.metamodel.PluralAttribute;
import jakarta.persistence.metamodel.SetAttribute;
import jakarta.persistence.metamodel.SingularAttribute;
/**
* Fetch joins are not supported in subqueries, so delegate to normal joins.
*
* @see JoinFetchAdapter
*/
class SubqueryRoot extends RootWrapper {
public SubqueryRoot(Root wrapped) {
super(wrapped);
}
@Override
@SuppressWarnings({ "hiding" })
public Fetch fetch(String attributeName) {
return new JoinFetchAdapter<>(join(attributeName));
}
@Override
@SuppressWarnings({ "hiding" })
public Fetch fetch(String attributeName, JoinType joinType) {
return new JoinFetchAdapter<>(join(attributeName, joinType));
}
@Override
public Fetch fetch(SingularAttribute super X, Y> attribute) {
return new JoinFetchAdapter<>(join(attribute));
}
@Override
public Fetch fetch(SingularAttribute super X, Y> attribute, JoinType joinType) {
return new JoinFetchAdapter<>(join(attribute, joinType));
}
@Override
@SuppressWarnings("unchecked")
public Fetch fetch(PluralAttribute super X, ?, Y> attribute) {
Join join;
if (attribute instanceof ListAttribute) {
join = join((ListAttribute) attribute);
}
else if (attribute instanceof SetAttribute) {
join = join((SetAttribute) attribute);
}
else if (attribute instanceof MapAttribute) {
join = join((MapAttribute) attribute);
}
else if (attribute instanceof CollectionAttribute) {
join = join((CollectionAttribute) attribute);
}
else {
throw new UnsupportedOperationException();
}
return new JoinFetchAdapter<>(join);
}
@Override
@SuppressWarnings("unchecked")
public Fetch fetch(PluralAttribute super X, ?, Y> attribute, JoinType joinType) {
Join join;
if (attribute instanceof ListAttribute) {
join = join((ListAttribute) attribute, joinType);
}
else if (attribute instanceof SetAttribute) {
join = join((SetAttribute) attribute, joinType);
}
else if (attribute instanceof MapAttribute) {
join = join((MapAttribute) attribute, joinType);
}
else if (attribute instanceof CollectionAttribute) {
join = join((CollectionAttribute) attribute, joinType);
}
else {
throw new UnsupportedOperationException();
}
return new JoinFetchAdapter<>(join);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy