Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove GSON dependency, move test/ to src/integration-test #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Remove GSON dependency, move test/ to src/integration-test
  • Loading branch information
abcfy2 committed Jun 6, 2018
commit 60e43fa6568edd9f6c9712f3a58252cc535d069b
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -75,11 +75,10 @@ dependencies {
profile 'org.grails.profiles:web-plugin'
provided 'org.grails:grails-plugin-services'
provided 'org.grails:grails-plugin-domain-class'
provided 'org.postgresql:postgresql:42.2.2'
testCompile 'org.grails:grails-plugin-testing'
testCompile 'org.grails:grails-gorm-testing-support'

provided 'org.postgresql:postgresql:42.2.2'

// plugins
provided 'org.grails.plugins:hibernate5'

@@ -88,7 +87,6 @@ dependencies {
provided("org.hibernate:hibernate-ehcache:$hibernateVersion") {
exclude group: 'net.sf.ehcache', module: 'ehcache'
}
compile 'com.google.code.gson:gson:2.8.4'
}

task wrapper(type: Wrapper) {
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package net.kaleidos.hibernate.json

import grails.gorm.transactions.Rollback
import grails.testing.mixin.integration.Integration
import spock.lang.Specification
import spock.lang.Unroll
import test.json.TestMapJson

@Integration
@Rollback
class PgJsonPathsIntegrationSpec extends Specification {

def pgJsonTestSearchService

@Unroll
void 'Test equals finding nested values (json)'() {
void 'Test equals finding nested values (json): a'() {
setup:
new TestMapJson(data: [name: 'Iván', lastName: 'López', nested: [a: 1, b: 2]]).save(flush: true)
new TestMapJson(data: [name: 'Alonso', lastName: 'Torres', nested: [a: 2, b: 3]]).save(flush: true)
@@ -30,7 +34,7 @@ class PgJsonPathsIntegrationSpec extends Specification {
}

@Unroll
void 'Test equals finding nested values (json)'() {
void 'Test equals finding nested values (json): b'() {
setup:
new TestMapJson(data: [name: 'Iván', lastName: 'López', nested: [a: 1, b: 2]]).save(flush: true)
new TestMapJson(data: [name: 'Alonso', lastName: 'Torres', nested: [a: 2, b: 3]]).save(flush: true)
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package net.kaleidos.hibernate.json

import grails.gorm.transactions.Rollback
import grails.testing.mixin.integration.Integration
import spock.lang.Specification
import spock.lang.Unroll
import test.json.TestMapJson

@Integration
@Rollback
class PgJsonValuesIntegrationSpec extends Specification {

def pgJsonTestSearchService
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package net.kaleidos.hibernate.json

import grails.gorm.transactions.Rollback
import grails.testing.mixin.integration.Integration
import spock.lang.Specification
import spock.lang.Unroll
import test.json.TestMapJsonb

@Integration
@Rollback
class PgJsonbEqualsIntegrationSpec extends Specification {

def pgJsonbTestSearchService
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package net.kaleidos.hibernate.json

import grails.gorm.transactions.Rollback
import grails.testing.mixin.integration.Integration
import spock.lang.Specification
import spock.lang.Unroll
import test.json.TestMapJsonb

@Integration
@Rollback
class PgJsonbPathsIntegrationSpec extends Specification {

def pgJsonbTestSearchService

@Unroll
void 'Test equals finding nested values (jsonb)'() {
void 'Test equals finding nested values (jsonb): a'() {
setup:
new TestMapJsonb(data: [name: 'Iván', lastName: 'López', nested: [a: 1, b: 2]]).save(flush: true)
new TestMapJsonb(data: [name: 'Alonso', lastName: 'Torres', nested: [a: 2, b: 3]]).save(flush: true)
@@ -30,7 +34,7 @@ class PgJsonbPathsIntegrationSpec extends Specification {
}

@Unroll
void 'Test equals finding nested values (jsonb)'() {
void 'Test equals finding nested values (jsonb): b'() {
setup:
new TestMapJsonb(data: [name: 'Iván', lastName: 'López', nested: [a: 1, b: 2]]).save(flush: true)
new TestMapJsonb(data: [name: 'Alonso', lastName: 'Torres', nested: [a: 2, b: 3]]).save(flush: true)
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package net.kaleidos.hibernate.json

import grails.gorm.transactions.Rollback
import grails.testing.mixin.integration.Integration
import spock.lang.Specification
import spock.lang.Unroll
import test.json.TestMapJsonb

@Integration
@Rollback
class PgJsonbValuesIntegrationSpec extends Specification {

def pgJsonbTestSearchService
12 changes: 2 additions & 10 deletions src/main/groovy/net/kaleidos/hibernate/usertype/ArrayType.java
Original file line number Diff line number Diff line change
@@ -7,16 +7,8 @@
import org.hibernate.usertype.UserType;

import java.io.Serializable;
import java.sql.Array;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import java.sql.*;
import java.util.*;

public class ArrayType implements UserType, ParameterizedType {
public static final int INTEGER_ARRAY = 90001;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package net.kaleidos.hibernate.usertype

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import grails.converters.JSON
import groovy.transform.CompileStatic
import org.apache.commons.lang.ObjectUtils
import org.grails.web.json.JSONObject
import org.hibernate.HibernateException
import org.hibernate.engine.spi.SharedSessionContractImplementor
import org.hibernate.usertype.UserType
@@ -21,7 +21,6 @@ class JsonMapType implements UserType {
static int SQLTYPE = 90021

private final Type userType = Map
private final Gson gson = new GsonBuilder().serializeNulls().create()

@Override
int[] sqlTypes() {
@@ -48,15 +47,15 @@ class JsonMapType implements UserType {
PGobject o = rs.getObject(names[0]) as PGobject
String jsonString = o?.value

gson.fromJson(jsonString, userType)
jsonString ? new JSONObject(jsonString) : null
}

@Override
void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException {
if (value == null) {
st.setNull(index, Types.OTHER)
} else {
st.setObject(index, gson.toJson(value, userType), Types.OTHER)
st.setObject(index, (value as JSON).toString(), Types.OTHER)
}
}

@@ -80,12 +79,12 @@ class JsonMapType implements UserType {

@Override
Serializable disassemble(Object value) throws HibernateException {
gson.toJson(value, userType)
(value as JSON).toString()
}

@Override
Object assemble(Serializable cached, Object owner) throws HibernateException {
gson.fromJson((String) cached, userType)
new JSONObject(cached.toString())
}

@Override