0

我正在尝试使用 Scala Case Classes 作为 Gridgain 缓存中的对象。但我无法让它工作。如果我创建与 java 类完全相同的对象,它工作得非常好。

这是我的测试用例:

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;
    }
}

使用 TestData2,测试通过,但使用 TestData,由于 size = 0,它在断言上失败。

我在案例类中尝试了几种属性类型(java.lang.Long 等)和注释组合的组合,但似乎没有任何效果。我必须在这里错过一些基本的东西,但是我这边几个小时的测试显然并没有让我一路走好。

有什么提示吗?

4

1 回答 1

0

对于标量,请尝试@ScalarCacheQuerySqlFieldorg.gridgain.scalar包中使用。

于 2014-07-23T00:25:05.353 回答