Giter Site home page Giter Site logo

pg-jsonb's People

Contributors

vzornic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

pg-jsonb's Issues

Will pgjsonb be upgraded?

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?

Upgrade to hibernate-core 5.4.12.Final

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;
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.