Search code examples
scalacase-classgridgain

Indexing Scala Case Classes in GridGain


I am trying to use Scala Case Classes as the object in Gridgain caches. But I cant get it to work. It works perfectly fine if I create exactly the same object as a java-class.

This is my testcase:

class GridGainTest extends FunSuite {
  val grid = GridGain.start("gridgain_mini.xml")
  private val theCache = grid.cache[Long, TestData2]("theCache")

  test("That the basics is working") {
    val tx = theCache.txStart()
    theCache.put(1, new TestData2(1, "Hello", 0))
    theCache.put(2, new TestData2(2, "World", 1))
    tx.commit()

    val q = theCache.queries().createSqlQuery(classOf[TestData2], "parent = ?")

    val qRes1 = q.execute(new java.lang.Long(1)).get()

    assert(qRes1.size() == 1)
   }
}

@BeanInfo
case class TestData(@BeanProperty @GridCacheQuerySqlField(index = true) id: Long,
                    @BeanProperty @GridCacheQuerySqlField(index = true) name: String,
                    @BeanProperty @GridCacheQuerySqlField(index = true) parent: Long)

public class TestData2 {
    @GridCacheQuerySqlField(index = true)
    public final long id;
    @GridCacheQuerySqlField(index = true)
    public final String name;
    @GridCacheQuerySqlField(index = true)
    public final long parent;

    public TestData2(long id, String name, long parent) {
        this.id = id;
        this.name = name;
        this.parent = parent;
    }
}

With TestData2 the test passes, but with TestData it fails on the assert due to size = 0.

I have tried several combinations of property-types (java.lang.Long etc) and annotation-combinations in the case class but nothing seems to work. I must miss something fundamental here, but a few hours of tests from my side obviously doesnt get me all the way.

Any hints?


Solution

  • For Scalar, try using @ScalarCacheQuerySqlField in org.gridgain.scalar package.