本文整理了Java中com.datastax.driver.core.querybuilder.Insert.toString()
方法的一些代码示例,展示了Insert.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Insert.toString()
方法的具体详情如下:
包路径:com.datastax.driver.core.querybuilder.Insert
类名称:Insert
方法名:toString
暂无
代码示例来源:origin: apache/storm
.values(allFields, Collections.<Object>nCopies(allFields.size(), bindMarker()));
CQLStatementTupleMapper put = boundQuery(putStatement.toString())
.bind(all())
.build();
putStatement.toString(),
stateMapper.toString());
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* Ensures that a statement can be printed with and without a required custom codec. The
* expectation is that if the codec is not registered, then the query string should contain bind
* markers for all variables; if however all codecs are properly registered, then the query string
* should contain all variables inlined and formatted properly.
*
* @jira_ticket JAVA-1272
*/
@Test(groups = "unit")
public void should_inline_custom_codec() throws Exception {
assertThat(insertInto("users").value("id", new Foo(42)).toString())
.isEqualTo("INSERT INTO users (id) VALUES (?);");
CodecRegistry.DEFAULT_INSTANCE.register(new FooCodec());
assertThat(insertInto("users").value("id", new Foo(42)).toString())
.isEqualTo("INSERT INTO users (id) VALUES (42);");
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
.json(
"{\"id\": 0, \"tupleval\": [1, \"abc\"], \"numbers\": [1, 2, 3], \"letters\": [\"a\", \"b\", \"c\"]}")
.toString())
.isEqualTo(
"INSERT INTO example JSON '{\"id\": 0, \"tupleval\": [1, \"abc\"], \"numbers\": [1, 2, 3], \"letters\": [\"a\", \"b\", \"c\"]}';");
insertInto("users")
.json("{\"id\": \"user123\", \"\\\"Age\\\"\": 42, \"\\\"State\\\"\": \"TX\"}")
.toString())
.isEqualTo(
"INSERT INTO users JSON '{\"id\": \"user123\", \"\\\"Age\\\"\": 42, \"\\\"State\\\"\": \"TX\"}';");
assertThat(insertInto("users").json(bindMarker()).toString())
.isEqualTo("INSERT INTO users JSON ?;");
assertThat(insertInto("users").json(bindMarker("json")).toString())
.isEqualTo("INSERT INTO users JSON :json;");
assertThat(
"{\"id\": 0, \"tupleval\": [1, \"abc\"], \"numbers\": [1, 2, 3], \"letters\": [\"a\", \"b\", \"c\"]}")
.defaultNull()
.toString())
.isEqualTo(
"INSERT INTO example JSON '{\"id\": 0, \"tupleval\": [1, \"abc\"], \"numbers\": [1, 2, 3], \"letters\": [\"a\", \"b\", \"c\"]}' DEFAULT NULL;");
"{\"id\": 0, \"tupleval\": [1, \"abc\"], \"numbers\": [1, 2, 3], \"letters\": [\"a\", \"b\", \"c\"]}")
.defaultUnset()
.toString())
.isEqualTo(
"INSERT INTO example JSON '{\"id\": 0, \"tupleval\": [1, \"abc\"], \"numbers\": [1, 2, 3], \"letters\": [\"a\", \"b\", \"c\"]}' DEFAULT UNSET;");
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "unit")
public void should_handle_from_json() throws Exception {
assertThat(
update("users")
.with(set("age", fromJson("42")))
.where(eq("id", fromJson("\"user123\"")))
.toString())
.isEqualTo("UPDATE users SET age=fromJson('42') WHERE id=fromJson('\"user123\"');");
assertThat(
insertInto("users")
.value("id", fromJson("\"user123\""))
.value("age", fromJson("42"))
.toString())
.isEqualTo("INSERT INTO users (id,age) VALUES (fromJson('\"user123\"'),fromJson('42'));");
assertThat(insertInto("users").value("id", fromJson(bindMarker())).toString())
.isEqualTo("INSERT INTO users (id) VALUES (fromJson(?));");
assertThat(insertInto("users").value("id", fromJson(bindMarker("id"))).toString())
.isEqualTo("INSERT INTO users (id) VALUES (fromJson(:id));");
}
代码示例来源:origin: otaviojava/Easy-Cassandra
@Override
public String toString() {
return insert.toString();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "unit")
public void quotingTest() {
assertEquals(select().from("Metrics", "epochs").toString(), "SELECT * FROM Metrics.epochs;");
assertEquals(
select().from("Metrics", quote("epochs")).toString(), "SELECT * FROM Metrics.\"epochs\";");
assertEquals(
select().from(quote("Metrics"), "epochs").toString(), "SELECT * FROM \"Metrics\".epochs;");
assertEquals(
select().from(quote("Metrics"), quote("epochs")).toString(),
"SELECT * FROM \"Metrics\".\"epochs\";");
assertEquals(
insertInto("Metrics", "epochs").toString(), "INSERT INTO Metrics.epochs () VALUES ();");
assertEquals(
insertInto("Metrics", quote("epochs")).toString(),
"INSERT INTO Metrics.\"epochs\" () VALUES ();");
assertEquals(
insertInto(quote("Metrics"), "epochs").toString(),
"INSERT INTO \"Metrics\".epochs () VALUES ();");
assertEquals(
insertInto(quote("Metrics"), quote("epochs")).toString(),
"INSERT INTO \"Metrics\".\"epochs\" () VALUES ();");
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
.value("i", 1)
.value("f", 1.1)
.toString(),
insertInto(TABLE2)
.value("k", "cast_t")
.value("i", 2)
.value("f", 2.5)
.toString(),
insertInto(TABLE2)
.value("k", "cast_t")
.value("i", 3)
.value("f", 3.7)
.toString(),
insertInto(TABLE2)
.value("k", "cast_t")
.value("i", 4)
.value("f", 5.0)
.toString());
代码示例来源:origin: stackoverflow.com
Insert insert = (Insert)CCJSqlParserUtil.parse("insert into mytable (col1) values (1)");
System.out.println(insert.toString());
代码示例来源:origin: stackoverflow.com
.value("first", "John")
.value("last", "Doe");
System.out.println(insert.toString());
ResultSet result = session.execute(insert.toString());
System.out.println(result);
代码示例来源:origin: ucbrise/anna
System.out.println(insertStmt.toString());
代码示例来源:origin: com.datastax.dse/dse-java-driver-core
/**
* Ensures that a statement can be printed with and without a required custom codec. The
* expectation is that if the codec is not registered, then the query string should contain bind
* markers for all variables; if however all codecs are properly registered, then the query string
* should contain all variables inlined and formatted properly.
*
* @jira_ticket JAVA-1272
*/
@Test(groups = "unit")
public void should_inline_custom_codec() throws Exception {
assertThat(insertInto("users").value("id", new Foo(42)).toString())
.isEqualTo("INSERT INTO users (id) VALUES (?);");
CodecRegistry.DEFAULT_INSTANCE.register(new FooCodec());
assertThat(insertInto("users").value("id", new Foo(42)).toString())
.isEqualTo("INSERT INTO users (id) VALUES (42);");
}
代码示例来源:origin: com.datastax.dse/dse-java-driver-core
.json(
"{\"id\": 0, \"tupleval\": [1, \"abc\"], \"numbers\": [1, 2, 3], \"letters\": [\"a\", \"b\", \"c\"]}")
.toString())
.isEqualTo(
"INSERT INTO example JSON '{\"id\": 0, \"tupleval\": [1, \"abc\"], \"numbers\": [1, 2, 3], \"letters\": [\"a\", \"b\", \"c\"]}';");
insertInto("users")
.json("{\"id\": \"user123\", \"\\\"Age\\\"\": 42, \"\\\"State\\\"\": \"TX\"}")
.toString())
.isEqualTo(
"INSERT INTO users JSON '{\"id\": \"user123\", \"\\\"Age\\\"\": 42, \"\\\"State\\\"\": \"TX\"}';");
assertThat(insertInto("users").json(bindMarker()).toString())
.isEqualTo("INSERT INTO users JSON ?;");
assertThat(insertInto("users").json(bindMarker("json")).toString())
.isEqualTo("INSERT INTO users JSON :json;");
assertThat(
"{\"id\": 0, \"tupleval\": [1, \"abc\"], \"numbers\": [1, 2, 3], \"letters\": [\"a\", \"b\", \"c\"]}")
.defaultNull()
.toString())
.isEqualTo(
"INSERT INTO example JSON '{\"id\": 0, \"tupleval\": [1, \"abc\"], \"numbers\": [1, 2, 3], \"letters\": [\"a\", \"b\", \"c\"]}' DEFAULT NULL;");
"{\"id\": 0, \"tupleval\": [1, \"abc\"], \"numbers\": [1, 2, 3], \"letters\": [\"a\", \"b\", \"c\"]}")
.defaultUnset()
.toString())
.isEqualTo(
"INSERT INTO example JSON '{\"id\": 0, \"tupleval\": [1, \"abc\"], \"numbers\": [1, 2, 3], \"letters\": [\"a\", \"b\", \"c\"]}' DEFAULT UNSET;");
代码示例来源:origin: com.yugabyte/cassandra-driver-mapping
@Override
String makePreparedQueryString(TableMetadata table, EntityMapper<?> mapper, MappingManager manager, Set<AliasedMappedProperty> columns, Collection<Mapper.Option> options) {
Insert insert = table == null
? insertInto(mapper.keyspace, mapper.table)
: insertInto(table);
for (AliasedMappedProperty col : columns)
if (!col.mappedProperty.isComputed())
insert.value(col.mappedProperty.getMappedName(), bindMarker());
for (Mapper.Option opt : options) {
opt.validate(QueryType.SAVE, manager);
opt.modifyQueryString(insert);
}
return insert.toString();
}
代码示例来源:origin: kloiasoft/eventapis
log.debug("Recording Event: " + insert.toString());
ResultSet resultSet = cassandraSession.execute(insert);
log.debug("Recorded Event: " + resultSet.toString());
代码示例来源:origin: arnaudroger/SimpleFlatMapper
private static String insertQuery(TableMetadata tableMetadata, String... options) {
Insert insert = QueryBuilder.insertInto(tableMetadata);
if (options != null) {
Insert.Options using = insert.using();
for (String option : options) {
if ("TTL".equals(option)) {
using.and(QueryBuilder.ttl(QueryBuilder.bindMarker()));
} else {
using.and(QueryBuilder.timestamp(QueryBuilder.bindMarker()));
}
}
}
List<ColumnMetadata> columns = tableMetadata.getColumns();
for(ColumnMetadata column : columns) {
insert.value(column.getName(), QueryBuilder.bindMarker());
}
return insert.toString();
}
代码示例来源:origin: com.datastax.dse/dse-java-driver-core
@Test(groups = "unit")
public void should_handle_from_json() throws Exception {
assertThat(
update("users")
.with(set("age", fromJson("42")))
.where(eq("id", fromJson("\"user123\"")))
.toString())
.isEqualTo("UPDATE users SET age=fromJson('42') WHERE id=fromJson('\"user123\"');");
assertThat(
insertInto("users")
.value("id", fromJson("\"user123\""))
.value("age", fromJson("42"))
.toString())
.isEqualTo("INSERT INTO users (id,age) VALUES (fromJson('\"user123\"'),fromJson('42'));");
assertThat(insertInto("users").value("id", fromJson(bindMarker())).toString())
.isEqualTo("INSERT INTO users (id) VALUES (fromJson(?));");
assertThat(insertInto("users").value("id", fromJson(bindMarker("id"))).toString())
.isEqualTo("INSERT INTO users (id) VALUES (fromJson(:id));");
}
代码示例来源:origin: com.datastax.dse/dse-java-driver-core
@Test(groups = "unit")
public void quotingTest() {
assertEquals(select().from("Metrics", "epochs").toString(), "SELECT * FROM Metrics.epochs;");
assertEquals(
select().from("Metrics", quote("epochs")).toString(), "SELECT * FROM Metrics.\"epochs\";");
assertEquals(
select().from(quote("Metrics"), "epochs").toString(), "SELECT * FROM \"Metrics\".epochs;");
assertEquals(
select().from(quote("Metrics"), quote("epochs")).toString(),
"SELECT * FROM \"Metrics\".\"epochs\";");
assertEquals(
insertInto("Metrics", "epochs").toString(), "INSERT INTO Metrics.epochs () VALUES ();");
assertEquals(
insertInto("Metrics", quote("epochs")).toString(),
"INSERT INTO Metrics.\"epochs\" () VALUES ();");
assertEquals(
insertInto(quote("Metrics"), "epochs").toString(),
"INSERT INTO \"Metrics\".epochs () VALUES ();");
assertEquals(
insertInto(quote("Metrics"), quote("epochs")).toString(),
"INSERT INTO \"Metrics\".\"epochs\" () VALUES ();");
}
代码示例来源:origin: com.datastax.dse/dse-java-driver-core
.value("i", 1)
.value("f", 1.1)
.toString(),
insertInto(TABLE2)
.value("k", "cast_t")
.value("i", 2)
.value("f", 2.5)
.toString(),
insertInto(TABLE2)
.value("k", "cast_t")
.value("i", 3)
.value("f", 3.7)
.toString(),
insertInto(TABLE2)
.value("k", "cast_t")
.value("i", 4)
.value("f", 5.0)
.toString());
代码示例来源:origin: org.hibernate.ogm/hibernate-ogm-cassandra
private Long nextValueInsert(IdSourceKeyMetadata metadata, String sequenceName, Long value) {
Insert insert = QueryBuilder.insertInto( quote( metadata.getName() ) )
.value( quote( metadata.getKeyColumnName() ), QueryBuilder.bindMarker( "sequence_name" ) )
.value( quote( metadata.getValueColumnName() ), QueryBuilder.bindMarker( "sequence_value" ) )
.ifNotExists();
PreparedStatement preparedStatement = provider.getSession().prepare( insert.toString() );
BoundStatement boundStatement = preparedStatement.bind();
boundStatement.setString( "sequence_name", sequenceName );
boundStatement.setLong( "sequence_value", value );
try {
provider.getSession().execute( boundStatement );
}
catch (DriverException e) {
throw e;
}
return nextValueSelect( metadata, sequenceName );
}
内容来源于网络,如有侵权,请联系作者删除!