-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support using Java 8 Date/Time API as query parameters.
- Loading branch information
Showing
17 changed files
with
192 additions
and
40 deletions.
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
29 changes: 9 additions & 20 deletions
29
jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/parameter/DateParameterValue.java
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 |
---|---|---|
@@ -1,39 +1,28 @@ | ||
/** | ||
* Copyright (C) 2020 Czech Technical University in Prague | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License as published by the Free Software | ||
* Foundation, either version 3 of the License, or (at your option) any | ||
* later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package cz.cvut.kbss.jopa.query.parameter; | ||
|
||
import cz.cvut.kbss.jopa.vocabulary.XSD; | ||
|
||
import java.util.Date; | ||
import java.time.LocalDate; | ||
import java.util.Objects; | ||
|
||
public class DateParameterValue extends AbstractParameterValue { | ||
/** | ||
* Parameter value which represents an XSD date. | ||
*/ | ||
class DateParameterValue extends AbstractParameterValue { | ||
|
||
private final Date value; | ||
private final LocalDate value; | ||
|
||
DateParameterValue(Date value) { | ||
DateParameterValue(LocalDate value) { | ||
this.value = Objects.requireNonNull(value); | ||
} | ||
|
||
@Override | ||
public Date getValue() { | ||
public LocalDate getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public String getQueryString() { | ||
return "\"" + value + "\"^^<" + XSD.DATETIME + ">"; | ||
return "\"" + value + "\"^^<" + XSD.DATE + ">"; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/parameter/DateTimeParameterValue.java
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,48 @@ | ||
/** | ||
* Copyright (C) 2020 Czech Technical University in Prague | ||
* <p> | ||
* This program is free software: you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License as published by the Free Software | ||
* Foundation, either version 3 of the License, or (at your option) any | ||
* later version. | ||
* <p> | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package cz.cvut.kbss.jopa.query.parameter; | ||
|
||
import cz.cvut.kbss.jopa.vocabulary.XSD; | ||
|
||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.OffsetDateTime; | ||
import java.util.Date; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Parameter values which represent XSD dateTime. | ||
* <p> | ||
* Currently, these are {@link Date}, {@link LocalDateTime}, {@link java.time.OffsetDateTime} and {@link Instant}. | ||
*/ | ||
class DateTimeParameterValue extends AbstractParameterValue { | ||
|
||
private final Object value; | ||
|
||
DateTimeParameterValue(Object value) { | ||
assert value instanceof Date || value instanceof LocalDateTime || value instanceof OffsetDateTime || value instanceof Instant; | ||
this.value = Objects.requireNonNull(value); | ||
} | ||
|
||
@Override | ||
public Object getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public String getQueryString() { | ||
return "\"" + value + "\"^^<" + XSD.DATETIME + ">"; | ||
} | ||
} |
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
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
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
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
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
31 changes: 31 additions & 0 deletions
31
jopa-impl/src/main/java/cz/cvut/kbss/jopa/query/parameter/TimeParameterValue.java
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,31 @@ | ||
package cz.cvut.kbss.jopa.query.parameter; | ||
|
||
import cz.cvut.kbss.jopa.vocabulary.XSD; | ||
|
||
import java.time.LocalTime; | ||
import java.time.OffsetTime; | ||
|
||
/** | ||
* Parameter values which represent XSD time. | ||
* <p> | ||
* Currently, these are {@link LocalTime} and {@link OffsetTime}. | ||
*/ | ||
class TimeParameterValue extends AbstractParameterValue { | ||
|
||
private final Object value; | ||
|
||
TimeParameterValue(Object value) { | ||
assert value instanceof LocalTime || value instanceof OffsetTime; | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public Object getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public String getQueryString() { | ||
return "\"" + value + "\"^^<" + XSD.TIME + ">"; | ||
} | ||
} |
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
Oops, something went wrong.