vzornic / pg-jsonb Goto Github PK
View Code? Open in Web Editor NEWJava lib for for supporting jsonb PostgreSQL type.
License: MIT License
Java lib for for supporting jsonb PostgreSQL type.
License: MIT License
pgjsonb strongly depends on hibernate 5.6, but in hibernate 6.0, many classes no longer exist, do you have any plans to upgrade pgjsonb according to hibernate 6.0?
You have a great library, thank you so much for it. We try to use it in our Spring Boot App. But the current version on Spring Boot uses hibernate-core 5.4.12 that contains some not backward compatible changes.
The changes that you need to do in your library is something like:
package com.vzornic.pgjson.hibernate.criteria.attribute;
import com.vzornic.pgjson.postgresql.domain.jsonquery.implementation.JsonProperty;
import com.vzornic.pgjson.postgresql.domain.jsonquery.model.CastType;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.Type;
import java.io.Serializable;
import org.hibernate.metamodel.model.domain.internal.AbstractAttribute;
import org.hibernate.metamodel.model.domain.internal.AbstractManagedType;
import org.hibernate.metamodel.model.domain.internal.BasicTypeImpl;
import org.hibernate.metamodel.model.domain.spi.SimpleTypeDescriptor;
/**
* Singular json attribute implementation. Requires jsonPath and class type to work properly.
* The following types are supported: String, Integer, Long, Float, Double, Short, Boolean
*
* @param <X>
* @param <Y>
*/
public class SingularJSONAttributeImpl<X, Y> extends AbstractAttribute<X,Y> implements SingularAttribute<X, Y>, Serializable {
private final boolean isOptional;
private final Type<Y> attributeType;
private final JsonProperty jsonPath;
private final Class<Y> javaType;
public SingularJSONAttributeImpl(Attribute<X,Y> attribute, String jsonPath, Class<Y> type) {
super((AbstractManagedType) attribute.getDeclaringType(),attribute.getName(),
attribute.getPersistentAttributeType(),
new BasicTypeImpl<Y>(type, Type.PersistenceType.BASIC), attribute.getJavaMember());
this.isOptional = true;
this.attributeType = new BasicTypeImpl<Y>(type, Type.PersistenceType.BASIC);
this.jsonPath = new JsonProperty(getName(), jsonPath).hql();
this.javaType = type;
if (!String.class.isAssignableFrom(getJavaType())) {
if (Float.class.isAssignableFrom(getJavaType())) {
this.jsonPath.cast(CastType.NUMERIC);
} else if (Double.class.isAssignableFrom(getJavaType())) {
this.jsonPath.cast(CastType.DOUBLE_PRECISION);
} else if (Long.class.isAssignableFrom(getJavaType())) {
this.jsonPath.cast(CastType.BIGINT);
} else if (Integer.class.isAssignableFrom(getJavaType())) {
this.jsonPath.cast(CastType.INTEGER);
} else if (Boolean.class.isAssignableFrom(getJavaType())) {
this.jsonPath.cast(CastType.BOOLEAN);
} else if (Short.class.isAssignableFrom(getJavaType())) {
this.jsonPath.cast(CastType.SMALLINT);
} else {
throw new RuntimeException();//TODO
}
}
}
/**
* JSON attribute cannot be identifier
*
* @return false
*/
@Override
public boolean isId() {
return false;
}
/**
* JSON attribute cannot be version
*
* @return false
*/
@Override
public boolean isVersion() {
return false;
}
@Override
public boolean isOptional() {
return isOptional;
}
@Override
public Type<Y> getType() {
return attributeType;
}
@Override
public Class<Y> getJavaType() {
return null;
}
/**
* JSON attribute cannot be association
*
* @return false
*/
@Override
public boolean isAssociation() {
return false;
}
@Override
public boolean isCollection() {
return false;
}
@Override
public BindableType getBindableType() {
return BindableType.SINGULAR_ATTRIBUTE;
}
@Override
public Class<Y> getBindableJavaType() {
return attributeType.getJavaType();
}
public String getFullPath() {
return jsonPath.toSqlString();
}
public String getFullPath(String alias) {
return jsonPath.alias(alias).toSqlString();
}
@Override
public SimpleTypeDescriptor<?> getKeyGraphType() {
return null;
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.