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

Constructor Based Properties


The com.gigaspaces.annotation.pojo.SpaceClassConstructor annotation on a constructor will cause the data class properties analysis to be based on properties found in the constructor (instead of getters/setters). This allows data class properties to be immutable.

Usage

Following is an example of such data class.

package org.openspaces.scala.example.data
import scala.beans.BeanProperty

/*
 * This imports enhanced space annotations such as @SpaceId, @SpaceRouting, etc...
 * with a @beanGetter annotation attached to them so annotations will be attached to the generated getter method.
 */
import org.openspaces.scala.core.aliases.annotation._

/**
 * Data properties should be inferred from the constructor.
 * This allows the pojo properties to remain immutable as demonstrated below.
 */
case class Data @SpaceClassConstructor() (

  @BeanProperty
  @SpaceId
  @SpaceProperty(nullValue = "-1")
  id: Long = -1,

  @BeanProperty
  @SpaceRouting
  @SpaceProperty(nullValue = "-1")
  routing: Long = -1,

  @BeanProperty
  data: String = null

)

Considerations

  • Each property defined in the specified constructor must have a matching bean getter method. This method can be generated automatically by the compiler by using the @BeanProperty annotation. If custom behavior is required, the getter method can be written explicitly.
  • To extract the names from the constructor parameters, it is required that the classes will be compiled with debug information.
  • Space metadata annotations (such as @SpaceId should be placed on the getter method. If the getter method is generated by the compiler using @BeanProperty, the annotation aliases under org.openspaces.scala.core.aliases.annotation can be used which include the @beanGetter annotation.