Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public class PgHstoreOperatorExpression implements Criterion {
private static final long serialVersionUID = 2872183637309166619L;

private final String propertyName;
private final Map<String,String> value;
private final Map<Object,String> value;
private final String operator;

private static final TypedValue[] NO_VALUES = new TypedValue[0];

protected PgHstoreOperatorExpression(String propertyName, Map<String,String> value, String operator) {
protected PgHstoreOperatorExpression(String propertyName, Map<Object,String> value, String operator) {
this.propertyName = propertyName;
this.value = value;
this.operator = operator;
Expand Down
4 changes: 2 additions & 2 deletions src/java/net/kaleidos/hibernate/usertype/HstoreHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private static String escapeQuotes(String text) {
return text.replaceAll("\"", "'");
}

public static String toString(Map<String, String> m) {
public static String toString(Map<Object, String> m) {
if (m == null || m.isEmpty()) {
return "";
}
Expand Down Expand Up @@ -77,4 +77,4 @@ public static HstoreDomainType toMap(String s) {

return new HstoreDomainType(m);
}
}
}
24 changes: 21 additions & 3 deletions src/java/net/kaleidos/hibernate/usertype/HstoreType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.sql.SQLException;
import java.sql.Types;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.Map;

import net.kaleidos.hibernate.postgresql.hstore.HstoreDomainType;
Expand Down Expand Up @@ -39,8 +40,20 @@ public Class<?> returnedClass() {
@Override
@SuppressWarnings("rawtypes")
public boolean equals(Object x, Object y) throws HibernateException {
Map m1 = (Map) x;
Map m2 = ((HstoreDomainType)y).getDataStore();
Map m1;
Map m2;
if (x instanceof HstoreDomainType){
m1 = ((HstoreDomainType)x).getDataStore();
} else {
m1 = (Map) x;
}

if (y instanceof HstoreDomainType){
m2 = ((HstoreDomainType)y).getDataStore();
} else {
m2 = (Map) y;
}

return m1.equals(m2);
}

Expand All @@ -53,7 +66,12 @@ public int hashCode(Object x) throws HibernateException {
@SuppressWarnings({ "rawtypes", "unchecked" })
public Object deepCopy(Object value) throws HibernateException {
if (value != null) {
Map m = ((HstoreDomainType)value).getDataStore();
Map m;
if (value instanceof HstoreDomainType)
m = ((HstoreDomainType)value).getDataStore();
else
m = (Map)value;

if (m == null) {
m = new HashMap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,22 @@ class PostgresqlHstoreDomainIntegrationSpec extends IntegrationSpec {
["foo,bar":"baz,qux"] | 'foo,bar' | 0
[foo:"bar"] | 'xxx' | 1
}
}

@Unroll
void 'save and delete a domain class with a map. key: #data'() {
setup:
def testHstore = new TestHstore(testAttributes: data)
when: 'I save an instance'
testHstore.save(flush: true)
and: 'I try to delete it'
testHstore.delete(flush: true)

then: 'It shouldn\'t be present in database anymore'
TestHstore.count() == 0

where:
data | attribute | value
[foo:"bar"] | "foo" | "bar"
["foo,bar":"baz,qux"] | "foo,bar" | "baz,qux"
}
}