simter-query

Simter query tools

License

License

MIT
GroupId

GroupId

tech.simter
ArtifactId

ArtifactId

simter-query
Last Version

Last Version

1.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

simter-query
Simter query tools
Project URL

Project URL

https://github.com/simter/simter-query
Project Organization

Project Organization

simter
Source Code Management

Source Code Management

https://github.com/simter/simter-query.git

Download simter-query

How to add to project

<!-- https://jarcasting.com/artifacts/tech.simter/simter-query/ -->
<dependency>
    <groupId>tech.simter</groupId>
    <artifactId>simter-query</artifactId>
    <version>1.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/tech.simter/simter-query/
implementation 'tech.simter:simter-query:1.1.0'
// https://jarcasting.com/artifacts/tech.simter/simter-query/
implementation ("tech.simter:simter-query:1.1.0")
'tech.simter:simter-query:jar:1.1.0'
<dependency org="tech.simter" name="simter-query" rev="1.1.0">
  <artifact name="simter-query" type="jar" />
</dependency>
@Grapes(
@Grab(group='tech.simter', module='simter-query', version='1.1.0')
)
libraryDependencies += "tech.simter" % "simter-query" % "1.1.0"
[tech.simter/simter-query "1.1.0"]

Dependencies

compile (4)

Group / Artifact Type Version
javax.json : javax.json-api jar 1.1.4
org.jetbrains.kotlin : kotlin-stdlib Optional jar 1.3.40
org.modelmapper : modelmapper Optional jar 2.3.2
org.springframework : spring-context-support jar

test (3)

Group / Artifact Type Version
org.glassfish : javax.json jar 1.1.4
org.junit.jupiter : junit-jupiter jar
org.springframework : spring-test jar

Project Modules

There are no modules declared in this project.

simter-query

Some query tools.

1. Condition encapsulation

1.1. The Condition interface

interface Condition<V> {
  val name: String
  val type: Type
  val value: V

  enum class Type(val symbol: String) {
    GreaterThan         (">"),
    GreaterThanOrEquals (">="),
    LessThan            ("<"),
    LessThanOrEquals    ("<="),
    Equals              ("="),
    NotEquals           ("!="),
    Like                ("like"),
    LikeStart           ("like-start"),
    LikeEnd             ("like-end"),
    LikeIgnoreCase      ("ilike"),
    LikeStartIgnoreCase ("ilike-start"),
    LikeEndIgnoreCase   ("ilike-end"),
    In                  ("in"),
    NotIn               ("not-in"),
    IsNull              ("is-null"),
    IsNotNull           ("is-not-null"),
    Between             ("between"),
    RangeGteLte         ("[]"), // v1 <= v <= v2
    RangeGteLt          ("[)"), // v1 <= v <  v2
    RangeGtLte          ("(]"), // v1 <  v <= v2
    RangeGtLt           ("()"); // v1 <  v <  v2
  }
}

1.2. Supported Condition Implementation

SN Condition Implementation Symbol ValueType
1 EqualsCondition = Any
2 GreaterThanCondition > Any
3 GreaterThanOrEqualsCondition >= Any
4 LessThanCondition < Any
5 LessThanOrEqualsCondition <= Any
6 InCondition in List
7 IsNullCondition is-null -
8 BetweenCondition between Pair<Any, Any>

1.3. Condition parser

See "ConditionUtils.parse(String) : List<Condition<*>>".

This method parse multiple Condition string with structure "[[name, stringValue, valueType, symbol], ...]" to a Condition list. Each Condition string must has a standard JsonArray string format.

Default Condition string structure :

  1. "[name, stringValue]" equals to "[name, stringValue, 'string', '=']"
  2. "[name, stringValue, valueType]" equals to "[name, stringValue, valueType, '=']"

Supported valueType string :

SN valueType Class
1 string kotlin.String
2 short kotlin.Short
3 integer kotlin.Int
4 int kotlin.Int
5 long kotlin.Long
6 double kotlin.Double
7 float kotlin.Float
8 boolean kotlin.Boolean
9 date java.time.LocalDate
10 time java.time.LocalTime
11 datetime java.time.LocalDateTime

Supported symbol is "Type.symbol", see upper <chapter 1.1>.

Examples :

SN Condition string Condition class
1 ["k", "9", "string", "="] EqualsCondition (name = "k", value = "9")
2 ["k", "9", "int", "="] EqualsCondition (name = "k", value = 9)
3 ["k", "2018-01-10", "date", "="] EqualsCondition (name = "k", value = LocalDate.of(2018, 1, 10))
4 ["k", "9", "int", ">"] GreaterThanCondition (name = "k", value = 9)
5 ["k", "[3, 6]", "int[]", "in"]
or ["k", "[\"3\", \"6\"]", "int[]", "in"]
InCondition (name = "k", value = listof(3, 6))
6 ["k", "[\"3\", \"6\"]", "string[]", "in"] InCondition (name = "k", value = listof("3", "6"))
7 ["k", "[3, 9]", "int[]", "between"] BetweenCondition (name = "k", value = Pair(3, 9))
8 ["k", "[3, 9]", "int[]", "[]"] BetweenCondition (name = "k", value = Pair(3, 9))
9 ["k", "[3, 9]", "int[]", "()"] GreaterThanCondition (name = "k", value = 3)
+ LessThanCondition (name = "k", value = 9)
10 ["k", "[3]", "int[]", "()"] GreaterThanCondition (name = "k", value = 3)
11 ["k", "[\"\", \"9\"]", "int[]", "()"] LessThanCondition (name = "k", value = 9)
@Test
fun example() {
  // string data
  val conditionsString = """[
    ["k", "2018-01-10", "date", "="], // parse to conditions[0]
    ["k", "[3]", "int[]", "()"],      // parse to conditions[1]
    ["k", "[, 6]", "int[]", "()"],    // parse to conditions[2]
    ["k", "[1, 2]", "int[]", "()"]    // parse to conditions[3] and conditions[4]
  ]""".trimIndent()

  // parse
  val conditions: List<Condition<*>> = ConditionUtils.parse(conditionsString)

  // verify
  assertEquals(4, conditions.size)
  assertEquals(EqualsCondition(name = "k", value = LocalDate.of(2018, 1, 10)), conditions[0])
  assertEquals(GreaterThanCondition(name = "k", value = 3), conditions[1])
  assertEquals(LessThanCondition(name = "k", value = 6), conditions[2])
  assertEquals(GreaterThanCondition(name = "k", value = 1), conditions[3])
  assertEquals(LessThanCondition(name = "k", value = 2), conditions[4])
}
tech.simter

Versions

Version
1.1.0
1.0.0