final String paramValue, final String paramType) throws IllegalArgumentException { if (paramValue == null) { statement.setToNull(paramIndex); return; } else if (paramType == null) {
/** * {@inheritDoc} */ @Override public BoundStatement apply(PreparedStatement statement, List<Column> columns) { Object[] values = Column.getVals(columns); BoundStatement boundStatement = statement.bind(); for (Column col : columns) { // For native protocol V3 or below, all variables must be bound. // With native protocol V4 or above, variables can be left unset, // in which case they will be ignored server side (no tombstones will be generated). if (col.isNull()) { boundStatement.setToNull(col.getColumnName()); } else { boundStatement.set(col.getColumnName(), col.getVal(), CodecRegistry.DEFAULT_INSTANCE.codecFor(col.getVal())); } } return statement.bind(values); } }
/** * Tests that a tombstone is created when binding a null value to a column in a prepared * statement. * * @test_category prepared_statements:binding * @jira_ticket JAVA-777 * @since 2.2.0 */ @Test(groups = "long") public void should_create_tombstone_when_null_value_on_bound_statement() { PreparedStatement prepared = session().prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); BoundStatement st1 = prepared.bind(); st1.setString(0, "foo"); st1.setToNull(1); session().execute(st1); Statement st2 = new SimpleStatement("SELECT i from " + SIMPLE_TABLE + " where k = 'foo'"); st2.enableTracing(); ResultSet rows = session().execute(st2); assertThat(rows.one().isNull(0)).isTrue(); // sleep 10 seconds to make sure the trace will be complete Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); QueryTrace queryTrace = rows.getExecutionInfo().getQueryTrace(); assertEventsContain(queryTrace, "1 tombstone"); }
/** * Tests that a tombstone is created when binding a null value to a column in a batch statement. * * @test_category prepared_statements:binding * @jira_ticket JAVA-777 * @since 2.2.0 */ @Test(groups = "short") @CassandraVersion("2.0.0") public void should_create_tombstone_when_null_value_on_batch_statement() { PreparedStatement prepared = session().prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); BoundStatement st1 = prepared.bind(); st1.setString(0, "foo"); st1.setToNull(1); session().execute(new BatchStatement().add(st1)); Statement st2 = new SimpleStatement("SELECT i from " + SIMPLE_TABLE + " where k = 'foo'"); st2.enableTracing(); ResultSet rows = session().execute(st2); assertThat(rows.one().isNull(0)).isTrue(); // sleep 10 seconds to make sure the trace will be complete Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); QueryTrace queryTrace = rows.getExecutionInfo().getQueryTrace(); assertEventsContain(queryTrace, "1 tombstone"); }
public void setNull(int parameterIndex, int sqlType) throws SQLException { checkNotClosed(); checkIndex(parameterIndex); // silently ignore type for cassandra... just store an empty String this.statement.setToNull(parameterIndex-1); }
public void setRowId(int parameterIndex, RowId value) throws SQLException { checkNotClosed(); checkIndex(parameterIndex); this.statement.setToNull(parameterIndex-1); }
private void doExecute() throws SQLException { if (LOG.isTraceEnabled()) LOG.trace("CQL: " + cql); try { resetResults(); if (this.connection.debugMode) System.out.println("CQL: "+ cql); if(this.statement.getFetchSize()==0) // force paging to avoid timeout and node harm... this.statement.setFetchSize(100); this.statement.setConsistencyLevel(this.connection.defaultConsistencyLevel); for(int i=0; i<this.statement.preparedStatement().getVariables().size(); i++){ // Set parameters to null if unset if(!this.statement.isSet(i)){ this.statement.setToNull(i); } } currentResultSet = new CassandraResultSet(this, this.connection.getSession().execute(this.statement)); } catch (Exception e) { throw new SQLTransientException(e); } }
bstm.setVarint(key, (BigInteger) value); } else if (value == null) { bstm.setToNull(key); } else { bstm.setString(key, value.toString());
@Override public Resource create(String id, Resource parent, Persona persona) { BoundStatement stmtCreate = stmtCreateInstance.get(); if (null == parent && null == persona) { throw new IllegalArgumentException("Either parent or persona should be provided when creating a resource"); } Resource resource = new Resource(id, persona, parent); bindBasicParameters(resource, stmtCreate); if (null != persona) { logger.resourceBeingCreatedWithPersona(resource.getId(), persona.getId()); stmtCreate.setUUID("persona", resource.getPersona().getIdAsUUID()); } else { stmtCreate.setToNull("persona"); } if (null != parent) { logger.resourceBeingCreatedWithParent(resource.getId(), resource.getParent().getId()); stmtCreate.setUUID("parent", resource.getParent().getIdAsUUID()); } else { stmtCreate.setToNull("parent"); } session.execute(stmtCreate); if (persona != null) { personaResourceRoleService.create(persona, resource, superUser); } logger.resourceCreated(resource.getId()); return resource; }
final String paramValue, final String paramType) throws IllegalArgumentException { if (paramValue == null) { statement.setToNull(paramIndex); return; } else if (paramType == null) {
bstm.setVarint(i, (BigInteger) value); } else if (value == null) { bstm.setToNull(i); } else { bstm.setString(i, value.toString());
/** * {@inheritDoc} */ @Override public BoundStatement apply(PreparedStatement statement, List<Column> columns) { Object[] values = Column.getVals(columns); BoundStatement boundStatement = statement.bind(); for(Column col : columns) { // For native protocol V3 or below, all variables must be bound. // With native protocol V4 or above, variables can be left unset, // in which case they will be ignored server side (no tombstones will be generated). if(col.isNull()) { boundStatement.setToNull(col.getColumnName()); } else { boundStatement.set(col.getColumnName(), col.getVal(), CodecRegistry.DEFAULT_INSTANCE.codecFor(col.getVal())); } } return statement.bind(values); } }
/** * Tests that a tombstone is created when binding a null value to a column in a prepared * statement. * * @test_category prepared_statements:binding * @jira_ticket JAVA-777 * @since 2.2.0 */ @Test(groups = "long") public void should_create_tombstone_when_null_value_on_bound_statement() { PreparedStatement prepared = session().prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); BoundStatement st1 = prepared.bind(); st1.setString(0, "foo"); st1.setToNull(1); session().execute(st1); Statement st2 = new SimpleStatement("SELECT i from " + SIMPLE_TABLE + " where k = 'foo'"); st2.enableTracing(); ResultSet rows = session().execute(st2); assertThat(rows.one().isNull(0)).isTrue(); // sleep 10 seconds to make sure the trace will be complete Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); QueryTrace queryTrace = rows.getExecutionInfo().getQueryTrace(); assertEventsContain(queryTrace, "1 tombstone"); }
boundStatement.setString(Schema.COLUMN_ADDR_SRC_DIGITS, sms.getSourceAddr()); } else { boundStatement.setToNull(Schema.COLUMN_ADDR_SRC_DIGITS); boundStatement.setInt(Schema.COLUMN_SM_STATUS, sms.getSmsSet().getStatus().getCode()); else boundStatement.setToNull(Schema.COLUMN_SM_STATUS); boundStatement.setBool(Schema.COLUMN_ALERTING_SUPPORTED, sms.getSmsSet().isAlertingSupported()); boundStatement.setString(Schema.COLUMN_ORIG_ESME_NAME, sms.getOrigEsmeName()); } else boundStatement.setToNull(Schema.COLUMN_ORIG_ESME_NAME); if (sms.getOrigSystemId() != null) { boundStatement.setString(Schema.COLUMN_ORIG_SYSTEM_ID, sms.getOrigSystemId()); } else boundStatement.setToNull(Schema.COLUMN_ORIG_SYSTEM_ID); if (sms.getSubmitDate() != null) { setBoundStatementDate(boundStatement, Schema.COLUMN_SUBMIT_DATE, sms.getSubmitDate()); } else boundStatement.setToNull(Schema.COLUMN_SUBMIT_DATE); if (sms.getDeliverDate() != null) { setBoundStatementDate(boundStatement, Schema.COLUMN_DELIVERY_DATE, sms.getDeliverDate()); } else boundStatement.setToNull(Schema.COLUMN_DELIVERY_DATE); if (sms.getServiceType() != null) { boundStatement.setString(Schema.COLUMN_SERVICE_TYPE, sms.getServiceType()); } else boundStatement.setToNull(Schema.COLUMN_SERVICE_TYPE); boundStatement.setInt(Schema.COLUMN_ESM_CLASS, sms.getEsmClass());
/** * Tests that a tombstone is created when binding a null value to a column in a batch statement. * * @test_category prepared_statements:binding * @jira_ticket JAVA-777 * @since 2.2.0 */ @Test(groups = "short") @CassandraVersion("2.0.0") public void should_create_tombstone_when_null_value_on_batch_statement() { PreparedStatement prepared = session().prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); BoundStatement st1 = prepared.bind(); st1.setString(0, "foo"); st1.setToNull(1); session().execute(new BatchStatement().add(st1)); Statement st2 = new SimpleStatement("SELECT i from " + SIMPLE_TABLE + " where k = 'foo'"); st2.enableTracing(); ResultSet rows = session().execute(st2); assertThat(rows.one().isNull(0)).isTrue(); // sleep 10 seconds to make sure the trace will be complete Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); QueryTrace queryTrace = rows.getExecutionInfo().getQueryTrace(); assertEventsContain(queryTrace, "1 tombstone"); }