Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
502 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package test.range | ||
|
||
import net.kaleidos.hibernate.postgresql.range.DateRange | ||
import net.kaleidos.hibernate.usertype.RangeType | ||
|
||
class TestDateRange { | ||
DateRange dateRange | ||
|
||
static mapping = { | ||
dateRange type:RangeType, params: ["type": DateRange] | ||
} | ||
|
||
static constraints = { | ||
dateRange nullable: true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package test.range | ||
|
||
import net.kaleidos.hibernate.postgresql.range.IntegerRange | ||
import net.kaleidos.hibernate.usertype.RangeType | ||
|
||
class TestIntegerRange { | ||
IntegerRange integerRange | ||
|
||
static mapping = { | ||
integerRange type:RangeType, params: ["type": IntegerRange] | ||
} | ||
|
||
static constraints = { | ||
integerRange nullable: true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package test.range | ||
|
||
import net.kaleidos.hibernate.postgresql.range.LongRange | ||
import net.kaleidos.hibernate.usertype.RangeType | ||
|
||
class TestLongRange { | ||
LongRange longRange | ||
|
||
static mapping = { | ||
longRange type:RangeType, params: ["type": LongRange] | ||
} | ||
|
||
static constraints = { | ||
longRange nullable: true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package test.range | ||
|
||
import net.kaleidos.hibernate.postgresql.range.TimestampRange | ||
import net.kaleidos.hibernate.usertype.RangeType | ||
|
||
class TestTimestampRange { | ||
TimestampRange timestampRange | ||
|
||
static mapping = { | ||
timestampRange type:RangeType, params: ["type": TimestampRange] | ||
} | ||
|
||
static constraints = { | ||
timestampRange nullable: true | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/groovy/net/kaleidos/hibernate/postgresql/range/DateRange.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.kaleidos.hibernate.postgresql.range | ||
|
||
class DateRange { | ||
ObjectRange range | ||
|
||
public DateRange(Date from, Date to) { | ||
range = new ObjectRange(from, to) | ||
} | ||
|
||
public Date getFrom(){ | ||
return range?.from | ||
} | ||
|
||
public Date getTo(){ | ||
return range?.to | ||
} | ||
|
||
public Range toRange(){ | ||
return range | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/groovy/net/kaleidos/hibernate/postgresql/range/IntegerRange.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.kaleidos.hibernate.postgresql.range | ||
|
||
class IntegerRange { | ||
IntRange range | ||
|
||
public IntegerRange(Integer from, Integer to) { | ||
range = new IntRange(from, to) | ||
} | ||
|
||
public Integer getFrom(){ | ||
return range?.from | ||
} | ||
|
||
public Integer getTo(){ | ||
return range?.to | ||
} | ||
|
||
public Range toRange(){ | ||
return range | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/groovy/net/kaleidos/hibernate/postgresql/range/LongRange.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.kaleidos.hibernate.postgresql.range | ||
|
||
class LongRange { | ||
ObjectRange range | ||
|
||
public LongRange(Long from, Long to) { | ||
range = new ObjectRange(from, to) | ||
} | ||
|
||
public Long getFrom(){ | ||
return range?.from | ||
} | ||
|
||
public Long getTo(){ | ||
return range?.to | ||
} | ||
|
||
public Range toRange(){ | ||
return range | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/groovy/net/kaleidos/hibernate/postgresql/range/TimestampRange.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.kaleidos.hibernate.postgresql.range | ||
|
||
class TimestampRange { | ||
ObjectRange range | ||
|
||
public TimestampRange(Date from, Date to) { | ||
range = new ObjectRange(from, to) | ||
} | ||
|
||
public Date getFrom(){ | ||
return range?.from | ||
} | ||
|
||
public Date getTo(){ | ||
return range?.to | ||
} | ||
|
||
public Range toRange(){ | ||
return range | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/groovy/net/kaleidos/hibernate/utils/PgRangeUtils.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package net.kaleidos.hibernate.utils | ||
|
||
import net.kaleidos.hibernate.postgresql.range.IntegerRange | ||
import net.kaleidos.hibernate.postgresql.range.LongRange | ||
import net.kaleidos.hibernate.postgresql.range.DateRange | ||
import net.kaleidos.hibernate.postgresql.range.TimestampRange | ||
|
||
public class PgRangeUtils { | ||
private static final String DATE_FORMAT = "yyyy-MM-dd" | ||
private static final String TS_FORMAT = "yyyy-MM-dd hh:mm:ss" | ||
|
||
public static IntegerRange parseIntegerRange(String pgResult) { | ||
String parentRemoved = pgResult.substring(1, pgResult.length() -1) | ||
String[] splitted = parentRemoved.split(",") | ||
return new IntegerRange(new Integer(splitted[0]), new Integer(splitted[1]) -1) | ||
} | ||
|
||
public static LongRange parseLongRange(String pgResult) { | ||
String parentRemoved = pgResult.substring(1, pgResult.length() -1) | ||
String[] splitted = parentRemoved.split(",") | ||
return new LongRange(new Long(splitted[0]), new Long(splitted[1]) -1) | ||
} | ||
|
||
public static DateRange parseDateRange(String pgResult) { | ||
String parentRemoved = pgResult.substring(1, pgResult.length() -1) | ||
String[] splitted = parentRemoved.split(",") | ||
return new DateRange(Date.parse(DATE_FORMAT, splitted[0]), Date.parse(DATE_FORMAT, splitted[1]-1)) | ||
} | ||
|
||
public static TimestampRange parseTimestampRange(String pgResult) { | ||
String parentRemoved = pgResult.substring(1, pgResult.length() -1) | ||
String[] splitted = parentRemoved.split(",") | ||
return new TimestampRange(Date.parse(TS_FORMAT, splitted[0]), Date.parse(TS_FORMAT, splitted[1])) | ||
} | ||
|
||
public static String format(IntegerRange range) { | ||
if (!range) { | ||
return null | ||
} | ||
return "[" + range.getFrom() + ", " + range.getTo() + "]" | ||
} | ||
|
||
public static String format(LongRange range) { | ||
if (!range) { | ||
return null | ||
} | ||
return "[" + range.getFrom() + ", " + range.getTo() + "]" | ||
} | ||
|
||
public static String format(DateRange range) { | ||
if (!range) { | ||
return null | ||
} | ||
return "[" + range.getFrom().format(DATE_FORMAT) + ", " + range.getTo().format(DATE_FORMAT) + "]" | ||
} | ||
|
||
public static String format(TimestampRange range) { | ||
if (!range) { | ||
return null | ||
} | ||
return "[" + range.getFrom().format(TS_FORMAT) + ", " + range.getTo().format(TS_FORMAT) + "]" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.