This page describes an older version of the product. The latest stable version is 16.4.

Predicate Based Queries


Support for predicate based queries on the GigaSpace proxy has been in added. This support is based on the new macros feature introduced in Scala 2.10. Each predicate based query is transformed during compilation into an equivalent SQLQuery.

Usage

To use predicate based queries, import import org.openspaces.scala.core.ScalaGigaSpacesImplicits._ into scope. Then call the predicate method on the GigaSpace instance as demonstrated:

/* Import GigaSpace implicits into scope */
import org.openspaces.scala.core.ScalaGigaSpacesImplicits._

/* implicit conversion on gigaspace returns a wrapper class with predicate based query methods */
val predicateGigaSpace = gigaSpace.predicate

Supported Queries

Example data class

For the purpose of demonstration, we will use the following example data class

case class Person @SpaceClassConstructor() (

  @BeanProperty
  @SpaceId
  id: String = null,

  @BeanProperty
  name: String = null,

  @BeanProperty
  @SpaceProperty(nullValue = "-1")
  @SpaceIndex(`type` = SpaceIndexType.EXTENDED)
  height: Int = -1,

  @BeanProperty
  birthday: Date = null,

  @BeanProperty
  son: Person = null

)

Translations

Predicate Query Translated SQL Query
==
predicateGigaSpace read { person: Person =>
person.name == “john”}
=
gigaSpace read new SQLQuery(classOf[Person],
“name = ?”, “john”)
!=
predicateGigaSpace read { person: Person =>
person.name != “john”}
<>
gigaSpace read new SQLQuery(classOf[Person],
“name <> ?“, “john”)
>
predicateGigaSpace read { person: Person =>
person.height > 10}
>
gigaSpace read new SQLQuery(classOf[Person],
“height > ?”, 10: Integer)
>=
predicateGigaSpace read { person: Person =>
person.height >= 10}
>=
gigaSpace read new SQLQuery(classOf[Person],
“height >= ?”, 10: Integer)
<
predicateGigaSpace read { person: Person =>
person.height < 10}
<
gigaSpace read new SQLQuery(classOf[Person],
“height < ?“, 10: Integer)
<=
predicateGigaSpace read { person: Person =>
person.height <= 10}
<=
gigaSpace read new SQLQuery(classOf[Person],
“height <= ?“, 10: Integer)
&&
predicateGigaSpace read { person: Person =>
person.height > 10 && person.height < 100
}
AND
gigaSpace read new SQLQuery(classOf[Person],
“( height > ? ) AND ( height < ? )“,
10: Integer, 100: Integer)
`
eq null
predicateGigaSpace read { person: Person =>
person.name eq null}
is null
gigaSpace read new SQLQuery(classOf[Person],
“name is null”, QueryResultType.OBJECT )
ne null
predicateGigaSpace read { person: Person =>
person.name ne null}
is NOT null
gigaSpace read new SQLQuery(classOf[Person],
“name is NOT null”, QueryResultType.OBJECT)
like
// Implicit conversion on java.lang.String
predicateGigaSpace read { person: Person =>
person.name like “j%”}
like
gigaSpace read new SQLQuery(classOf[Person],
“name like ‘j%’”, QueryResultType.OBJECT)
notLike
predicateGigaSpace read { person: Person =>
person.name notLike “j%”}
NOT like
gigaSpace read new SQLQuery(classOf[Person],
“name NOT like ‘j%’”, QueryResultType.OBJECT)
rlike
predicateGigaSpace read { person: Person =>
person.name rlike “j.*”}
rlike
gigaSpace read new SQLQuery(classOf[Person],
“name rlike ‘j.*’“, QueryResultType.OBJECT)
Nested Queries
predicateGigaSpace read { person: Person =>
person.son.name == “dave”}

gigaSpace read new SQLQuery(classOf[Person],
“son.name = ?”, “dave”)
Date
// implicit conversion on java.util.Date
predicateGigaSpace read { person: Person =>
person.birthday < janesBirthday}

gigaSpace read new SQLQuery(classOf[Person],
“birthday < ?“, janesBirthday)
Date
predicateGigaSpace read { person: Person =>
person.birthday <= janesBirthday}

gigaSpace read new SQLQuery(classOf[Person],
“birthday <= ?“, janesBirthday)
Date
predicateGigaSpace read { person: Person =>
person.birthday > janesBirthday}

gigaSpace read new SQLQuery(classOf[Person],
“birthday > ?”, janesBirthday)
Date
predicateGigaSpace read { person: Person =>
person.birthday >= janesBirthday}

gigaSpace read new SQLQuery(classOf[Person],
“birthday >= ?”, janesBirthday)
select
// select is imported into scope
predicateGigaSpace read { person: Person =>
select(person.name, person.birthday)
person.id == someId}

setProjections gigaSpace read new SQLQuery(classOf[Person],
“id = ?”, someId
).setProjections(“name, birthday”)
orderBy
// orderBy is imported into scope
predicateGigaSpace read { person: Person =>
orderBy(person.birthday)
person.nickName eq null}
ORDER BY
gigaSpace read new SQLQuery(classOf[Person],
“nickName is null ORDER BY birthday”,
QueryResultType.OBJECT)
orderBy().ascending
predicateGigaSpace read { person: Person =>
orderBy(person.birthday)==.ascending
person.nickName eq null}
ORDER BY ... ASC
gigaSpace read new SQLQuery(classOf[Person],
“nickName is null ORDER BY birthday ASC”,
QueryResultType.OBJECT)
orderBy().descending
predicateGigaSpace read { person: Person =>
orderBy(person.birthday).descending
person.nickName eq null}
ORDER BY ... DESC
gigaSpace read new SQLQuery(classOf[Person],
“nickName is null ORDER BY birthday DESC”,
QueryResultType.OBJECT)
groupBy
// groupBy is imported into scope
predicateGigaSpace read { person: Person =>
groupBy(person.birthday)
person.nickName eq null}
GROUP BY
gigaSpace read new SQLQuery(classOf[Person],
“nickName is null GROUP BY birthday”,
QueryResultType.OBJECT)