本文整理汇总了Java中com.datastax.driver.core.querybuilder.Insert.ifNotExists方法的典型用法代码示例。如果您正苦于以下问题:Java Insert.ifNotExists方法的具体用法?Java Insert.ifNotExists怎么用?Java Insert.ifNotExists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.datastax.driver.core.querybuilder.Insert
的用法示例。
在下文中一共展示了Insert.ifNotExists方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: save
import com.datastax.driver.core.querybuilder.Insert; //导入方法依赖的package包/类
private Optional<Event> save(EventEntity entity, boolean ifNotExists) {
if (entity.getId() == null) {
entity.setId(UUIDs.timeBased());
}
Insert insert = QueryBuilder.insertInto(getColumnFamilyName())
.value(ModelConstants.ID_PROPERTY, entity.getId())
.value(ModelConstants.EVENT_TENANT_ID_PROPERTY, entity.getTenantId())
.value(ModelConstants.EVENT_ENTITY_TYPE_PROPERTY, entity.getEntityType())
.value(ModelConstants.EVENT_ENTITY_ID_PROPERTY, entity.getEntityId())
.value(ModelConstants.EVENT_TYPE_PROPERTY, entity.getEventType())
.value(ModelConstants.EVENT_UID_PROPERTY, entity.getEventUid())
.value(ModelConstants.EVENT_BODY_PROPERTY, entity.getBody());
if (ifNotExists) {
insert = insert.ifNotExists();
}
ResultSet rs = executeWrite(insert);
if (rs.wasApplied()) {
return Optional.of(DaoUtil.getData(entity));
} else {
return Optional.empty();
}
}
示例2: createInsertQuery
import com.datastax.driver.core.querybuilder.Insert; //导入方法依赖的package包/类
private Insert createInsertQuery(EntityEvent entityEvent) {
Insert insert = QueryBuilder.insertInto(tableName);
insert.value(ENTITY_ID, entityEvent.getEventKey().getEntityId());
insert.value(VERSION, entityEvent.getEventKey().getVersion());
insert.value(OP_ID, entityEvent.getOpId());
insert.value(OP_DATE, entityEvent.getOpDate());
insert.value(EVENT_TYPE, entityEvent.getEventType());
insert.value(STATUS, entityEvent.getStatus().name());
insert.value(AUDIT_INFO, entityEvent.getAuditInfo());
insert.value(EVENT_DATA, entityEvent.getEventData());
insert.ifNotExists();
return insert;
}
示例3: generateInsert
import com.datastax.driver.core.querybuilder.Insert; //导入方法依赖的package包/类
/**
* Generate Insert CQL.
*/
public static Insert generateInsert(String table, String[] columns, boolean ifNotExists, Integer ttl) {
Insert insert = insertInto(table);
for (String column : columns) {
insert = insert.value(column, bindMarker());
}
if (ifNotExists) {
insert = insert.ifNotExists();
}
if (ttl != null) {
insert.using(ttl(ttl));
}
return insert;
}
示例4: toInsertStatementAsync
import com.datastax.driver.core.querybuilder.Insert; //导入方法依赖的package包/类
private static ListenableFuture<Statement> toInsertStatementAsync(WriteQueryData data, ExecutionSpec executionSpec, UDTValueMapper udtValueMapper, DBSession dbSession) {
final Insert insert = (data.getTablename().getKeyspacename() == null) ? insertInto(data.getTablename().getTablename())
: insertInto(data.getTablename().getKeyspacename(), data.getTablename().getTablename());
final List<Object> values = Lists.newArrayList();
for(Entry<String, Optional<Object>> entry : data.getValuesToMutate().entrySet()) {
insert.value(entry.getKey(), bindMarker());
values.add(udtValueMapper.toStatementValue(data.getTablename(), entry.getKey(), entry.getValue().orNull()));
}
if (data.getIfNotExits() != null) {
insert.ifNotExists();
if (executionSpec.getSerialConsistencyLevel() != null) {
insert.setSerialConsistencyLevel(executionSpec.getSerialConsistencyLevel());
}
}
if (executionSpec.getTtl() != null) {
insert.using(ttl(bindMarker()));
values.add((Integer) executionSpec.getTtl());
}
final ListenableFuture<PreparedStatement> preparedStatementFuture = dbSession.prepareAsync(insert);
return dbSession.bindAsync(preparedStatementFuture, values.toArray());
}