org.babyfish.jimmer.sql.ast.impl.Literals 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.ast.impl;
import org.babyfish.jimmer.meta.ImmutableProp;
import org.babyfish.jimmer.runtime.ImmutableSpi;
import org.babyfish.jimmer.sql.ast.*;
import org.babyfish.jimmer.sql.ast.impl.render.AbstractSqlBuilder;
import org.babyfish.jimmer.sql.ast.impl.render.BatchSqlBuilder;
import org.babyfish.jimmer.sql.ast.table.spi.PropExpressionImplementor;
import org.babyfish.jimmer.sql.runtime.ExecutionException;
import org.babyfish.jimmer.sql.runtime.JSqlClientImplementor;
import org.babyfish.jimmer.sql.runtime.ScalarProvider;
import org.babyfish.jimmer.sql.runtime.SqlBuilder;
import org.jetbrains.annotations.NotNull;
import java.util.*;
public class Literals {
private Literals() {}
public static StringExpression string(String value) {
return new Str(value);
}
public static > NumericExpression number(N value) {
return new Num<>(value);
}
public static > ComparableExpression comparable(T value) {
return new Cmp<>(value);
}
public static void bind(Expression> mayBeLiteral, Expression> expression) {
if (!(mayBeLiteral instanceof Any>)) {
return;
}
if (expression instanceof PropExpression>) {
((Any>)mayBeLiteral).setMatchedProp(((PropExpressionImplementor>)expression).getProp());
} else if (expression instanceof TupleExpressionImplementor>) {
TupleExpressionImplementor> tupleExpr = (TupleExpressionImplementor>) expression;
int size = tupleExpr.size();
ImmutableProp[] props = new ImmutableProp[size];
boolean hasProp = false;
for (int i = 0; i < size; i++) {
Selection> expr = tupleExpr.get(i);
if (expr instanceof PropExpression>) {
props[i] = ((PropExpressionImplementor>)expr).getProp();
hasProp = true;
}
}
if (hasProp) {
((Any>) mayBeLiteral).setMatchedProps(props);
}
}
}
@SuppressWarnings("unchecked")
public static Collection> convert(Collection> literals, Expression> expression, JSqlClientImplementor sqlClient) {
if (literals == null || literals.isEmpty()) {
return literals;
}
if (expression instanceof PropExpression>) {
ImmutableProp prop = ((PropExpressionImplementor>)expression).getProp();
ScalarProvider