-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Support for Instant ParsingStrategy.kt, created Test.
- Loading branch information
1 parent
b2aacff
commit db0cffa
Showing
5 changed files
with
344 additions
and
80 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
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/com/sipios/springsearch/strategies/InstantStrategy.kt
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,28 @@ | ||
package com.sipios.springsearch.strategies | ||
|
||
import com.sipios.springsearch.SearchOperation | ||
import java.time.Instant | ||
import javax.persistence.criteria.CriteriaBuilder | ||
import javax.persistence.criteria.Path | ||
import javax.persistence.criteria.Predicate | ||
import kotlin.reflect.KClass | ||
|
||
class InstantStrategy : ParsingStrategy { | ||
override fun buildPredicate( | ||
builder: CriteriaBuilder, | ||
path: Path<*>, | ||
fieldName: String, | ||
ops: SearchOperation?, | ||
value: Any? | ||
): Predicate? { | ||
return when (ops) { | ||
SearchOperation.GREATER_THAN -> builder.greaterThan(path.get(fieldName), value as Instant) | ||
SearchOperation.LESS_THAN -> builder.lessThan(path.get(fieldName), value as Instant) | ||
else -> super.buildPredicate(builder, path, fieldName, ops, value) | ||
} | ||
} | ||
|
||
override fun parse(value: String?, fieldClass: KClass<out Any>): Any? { | ||
return Instant.parse(value) | ||
} | ||
} |
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.