persistOptions = withTTL(persistOptions);
Session session = persistenceSession.driverSession();
BatchStatement batch = new BatchStatement();
Set removed = instance.getRemoved();
if (!removed.isEmpty()) {
int protocolVersion = persistenceSession.persistenceManager.protocolVersion;
Binder binder = new Binder(null, true, primaryKeyColumns, PersistMode.DELETE, true);
for (Object key : removed) {
binder.reset();
buildModifyBindColumns(instance, binder, partitionAttributes);
if (clusteringColumn != null) {
binder.setBytesUnsafe(clusteringColumn, clusteringPrimitive.serialize(key, protocolVersion));
} else {
buildModifyBindColumns(key, binder, clusteringKeyAttributes);
}
}
BoundStatement bStmt = buildModifyInitial(session, persistOptions, PreparedStatements.StatementType.DELETE, binder);
int idx = binder.bindColumns(0, bStmt);
bindUsingOptions(bStmt, persistOptions, idx);
statementOptions.applyWrite(bStmt, writeConsistencyLevel, serialConsistencyLevel, persistOptions);
if (prePersist != null) {
prePersist.invoke(instance, this, type, bStmt);
}
batch.add(bStmt);
}
// UPDATE keyspace_name.table_name
// USING option AND option
// SET assignment , assignment, ...
// WHERE row_specification
// IF column_name = literal AND column_name = literal . . .
int protocolVersion = persistenceSession.persistenceManager.protocolVersion;
CqlColumn[] columns = PersistOption.ColumnRestrictionOption.filter(persistOptions, writeDataColumns);
Binder binder = new Binder(columns, true, primaryKeyColumns, PersistMode.UPDATE, true);
for (Map.Entry entry : instance.getCluster().entrySet()) {
binder.reset();
buildModifyBindColumns(instance, binder, partitionAttributes);
if (clusteringColumn != null) {
binder.setBytesUnsafe(clusteringColumn, clusteringPrimitive.serialize(entry.getKey(), protocolVersion));
} else {
buildModifyBindColumns(entry.getKey(), binder, clusteringKeyAttributes);
}
if (valueColumn != null) {
binder.setBytesUnsafe(valueColumn, valuePrimitive.serialize(entry.getValue(), protocolVersion));
} else {
buildModifyBindColumns(entry.getValue(), binder, valueAttributes);
}
BoundStatement bStmt = buildModifyInitial(session, persistOptions, PreparedStatements.StatementType.UPDATE, binder);
int idx = bindUsingOptions(bStmt, persistOptions, 0);
idx = binder.bindColumns(idx, bStmt);
bindIfOptions(binder, bStmt, persistOptions, idx);
statementOptions.applyWrite(bStmt, writeConsistencyLevel, serialConsistencyLevel, persistOptions);
if (prePersist != null) {
prePersist.invoke(instance, this, type, bStmt);
}
batch.add(bStmt);
}
// TODO reset MapEntity only if batch was successful
instance.reset();