org.babyfish.jimmer.sql.runtime.MicroServiceExporter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jimmer-sql Show documentation
Show all versions of jimmer-sql Show documentation
A revolutionary ORM framework for both java and kotlin
package org.babyfish.jimmer.sql.runtime;
import org.babyfish.jimmer.meta.ImmutableProp;
import org.babyfish.jimmer.meta.ImmutableType;
import org.babyfish.jimmer.runtime.ImmutableSpi;
import org.babyfish.jimmer.sql.Entities;
import org.babyfish.jimmer.sql.JSqlClient;
import org.babyfish.jimmer.sql.ast.Expression;
import org.babyfish.jimmer.sql.ast.impl.EntitiesImpl;
import org.babyfish.jimmer.sql.ast.impl.query.FilterLevel;
import org.babyfish.jimmer.sql.ast.impl.query.MutableRootQueryImpl;
import org.babyfish.jimmer.sql.ast.table.Table;
import org.babyfish.jimmer.sql.ast.tuple.Tuple2;
import org.babyfish.jimmer.sql.fetcher.Fetcher;
import org.babyfish.jimmer.sql.fetcher.impl.FetcherImplementor;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
public class MicroServiceExporter {
private final JSqlClientImplementor sqlClient;
public MicroServiceExporter(JSqlClient sqlClient) {
this.sqlClient = (JSqlClientImplementor) Objects.requireNonNull(sqlClient, "sqlClient cannot be null");
}
@SuppressWarnings("unchecked")
public List findByIds(
Collection> ids,
Fetcher> fetcher
) {
ImmutableType fetchedType = fetcher.getImmutableType();
JSqlClient client =
sqlClient.getFilters().getFilter(fetchedType) == null ?
sqlClient :
sqlClient.caches(cfg -> cfg.disable(fetchedType));
Entities entities = ((EntitiesImpl) client.getEntities()).forExporter();
return entities.findByIds((Fetcher) fetcher, ids);
}
@SuppressWarnings("unchecked")
public List> findByAssociatedIds(
ImmutableProp prop,
Collection> targetIds,
Fetcher> fetcher
) {
ImmutableType fetchedType = fetcher.getImmutableType();
if (prop.getDeclaringType() != fetchedType) {
throw new IllegalArgumentException(
"The root entity type of fetcher is \"" +
fetchedType +
"\" is not declaring type of \"" +
prop +
"\""
);
}
MutableRootQueryImpl> query =
new MutableRootQueryImpl<>(
sqlClient,
prop.getDeclaringType(),
ExecutionPurpose.EXPORT,
FilterLevel.DEFAULT
);
Expression