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.icthh.xm.commons.migration.db.jsonb.JsonbExpression Maven / Gradle / Ivy
package com.icthh.xm.commons.migration.db.jsonb;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Root;
import org.hibernate.type.descriptor.jdbc.JsonJdbcType;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;
import static com.icthh.xm.commons.migration.db.jsonb.CustomDialect.JSON_QUERY;
import static com.icthh.xm.commons.migration.db.jsonb.CustomPostgreSQLDialect.TO_JSON_B;
import static com.icthh.xm.commons.migration.db.jsonb.CustomPostgreSQLDialect.TO_JSON_B_TEXT;
@Component
@ConditionalOnExpression("'${spring.datasource.url}'.startsWith('jdbc:postgresql:')")
public class JsonbExpression implements CustomExpression {
@Override
public Expression jsonQuery(CriteriaBuilder cb, Root> root, String column, String jsonPath) {
return jsonQuery(cb, root, column, jsonPath, JsonJdbcType.class);
}
@Override
public Expression jsonQuery(CriteriaBuilder cb, Root> root, String column, String jsonPath, Class type) {
return cb.function(JSON_QUERY, type, root.get(column), cb.literal(jsonPath));
}
@Override
public Expression> toExpression(CriteriaBuilder cb, Object object) {
return toJsonB(cb, object);
}
@Override
public Expression> toJsonB(CriteriaBuilder cb, Object object) {
return toJsonB(cb, object, JsonJdbcType.class);
}
@Override
public Expression toJsonB(CriteriaBuilder cb, Object object, Class type) {
return toJsonB(cb, cb.literal(object), type);
}
@Override
public Expression toJsonB(CriteriaBuilder cb, Expression> expression) {
return toJsonB(cb, expression, JsonJdbcType.class);
}
@Override
public Expression toJsonB(CriteriaBuilder cb, Expression> expression, Class type) {
return cb.function(TO_JSON_B, type, expression);
}
@Override
public Expression> toJsonbText(CriteriaBuilder cb, Object object) {
return toJsonbText(cb, object, JsonJdbcType.class);
}
@Override
public Expression toJsonbText(CriteriaBuilder cb, Object object, Class type) {
return toJsonbText(cb, cb.literal(object), type);
}
@Override
public Expression toJsonbText(CriteriaBuilder cb, Expression> expression) {
return toJsonbText(cb, expression, JsonJdbcType.class);
}
@Override
public Expression toJsonbText(CriteriaBuilder cb, Expression> expression, Class type) {
return cb.function(TO_JSON_B_TEXT, type, expression);
}
}