org.babyfish.jimmer.sql.ScalarProviderUtils 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
The newest version!
package org.babyfish.jimmer.sql;
import org.babyfish.jimmer.sql.dialect.Dialect;
import org.babyfish.jimmer.sql.runtime.ScalarProvider;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ScalarProviderUtils {
@Nullable
public static Object toSql(
@NotNull T literal,
@NotNull ScalarProvider scalarProvider,
@NotNull Dialect dialect
) throws Exception {
Object sqlValue = scalarProvider.toSql(literal);
return scalarProvider.isJsonScalar() ? dialect.jsonToBaseValue((String) sqlValue) : sqlValue;
}
@NotNull
public static Class> getSqlType(
@NotNull ScalarProvider, ?> scalarProvider,
@NotNull Dialect dialect
) {
return scalarProvider.isJsonScalar() ? dialect.getJsonBaseType() : scalarProvider.getSqlType();
}
}