只是转换了QueryBuilder.update
到使用toString()
方法
如果要存储,检索和执行QueryBuilder.update
查询字符串,你不必序列化和反序列化成JSON。
String query = QueryBuilder.update("exp").with(QueryBuilder.set("data", "This is a test data")).toString();
//Now you can store the text query directly to cassandra
//And retrieve the text query
session.execute(query); //Execute the query
这里是toString()
@Override
public String toString() {
try {
if (forceNoValues)
return getQueryString();
// 1) try first with all values inlined (will not work if some values require custom codecs,
// or if the required codecs are registered in a different CodecRegistry instance than the default one)
return maybeAddSemicolon(buildQueryString(null, CodecRegistry.DEFAULT_INSTANCE)).toString();
} catch (RuntimeException e1) {
// 2) try next with bind markers for all values to avoid usage of custom codecs
try {
return maybeAddSemicolon(buildQueryString(new ArrayList<Object>(), CodecRegistry.DEFAULT_INSTANCE)).toString();
} catch (RuntimeException e2) {
// Ugly but we have absolutely no context to get the registry from
return String.format("built query (could not generate with default codec registry: %s)", e2.getMessage());
}
}
}
的代码,你可以看到,它返回的实际查询字符串
是的,我想存储,检索并执行'com.datastax.driver.core.querybuilder.Update'查询。 你的意思是使用'toString()'方法可以得到正确的文本查询,然后直接执行它? 您确定这是**是否正确**复杂**更新操作? 我不知道'toString()'方法到底做了什么。源代码对我来说有点困难。 – niaomingjian
尽管我可以获取文本查询,但我可能会在'Update'中丢失一些其他信息。 – niaomingjian
@niaomingjian更新了答案,添加了'toString()'代码。你可以看到它返回实际的查询字符串。 –