谁能告诉我如何将这个旧注释从 Datastax 3.x 系列驱动程序复制到新的 4.x 系列:
@Table(
name = "mytable",
readConsistency = "LOCAL_ONE",
writeConsistency = "LOCAL_QUORUM")
我记下了名称:@CqlName("mytable"),只是没有一致性。
我们在代码中专门使用映射器 - 它们速度很快,并且在 3.x 驱动程序中为您做了很多样板文件。在 4.x 中,情况就不那么严重了,这令人沮丧。有些我们依赖的东西我就是无法弄清楚 - 就像这样。
另外(不同的问题,但我会在这里问)。我可以在 session 中设置配置文件吗?也在努力解决这个问题。
最佳答案
the "mapper" and "accessor" concepts have been unified into a single "DAO" component, that handles both pre-defined CRUD patterns, and user-provided queries.
在您的情况下,您将从 @Table
切换到 @Entity
,如下所示:
@Entity
@CqlName("mytable")
class MyPojoClass {
}
然后你定义Dao class您可以在其中定义单个操作,例如插入/删除/选择:
@Dao
public interface ProductDao {
@Select
MyPojoClass findBySomething();
@Insert
void save(MyPojoClass cls);
@Delete
void delete(MyPojoClass cls);
}
这些操作可以使用@StatementAttributes
注释进行注释,该注释具有 consistencyLevel
, executionProfileName
,以及许多其他属性。
附注对我来说,新映射器的一大改进是您可以在同一 session 中使用具有多个键空间和表的相同实体类...
关于Cassandra 3.x 到 4.x 驱动程序差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60890648/