public static CqlPreparedResult prepare(String queryString, ThriftClientState clientState) throws RequestValidationException { logger.trace("CQL QUERY: {}", queryString); CQLStatement statement = getStatement(queryString); int statementId = makeStatementId(queryString); logger.trace("Discovered "+ statement.boundTerms + " bound variables."); clientState.getPrepared().put(statementId, statement); logger.trace(String.format("Stored prepared statement #%d with %d bind markers", statementId, statement.boundTerms)); if (!postPreparationHooks.isEmpty()) { PreparationContext context = new PreparationContext(clientState, queryString, statement); for (PostPreparationHook hook : postPreparationHooks) hook.processStatement(statement, context); } return new CqlPreparedResult(statementId, statement.boundTerms); }
public static CqlResult processPrepared(CQLStatement statement, ThriftClientState clientState, List<ByteBuffer> variables) throws RequestValidationException, RequestExecutionException { // Check to see if there are any bound variables to verify if (!(variables.isEmpty() && (statement.boundTerms == 0))) { if (variables.size() != statement.boundTerms) throw new InvalidRequestException(String.format("there were %d markers(?) in CQL but %d bound variables", statement.boundTerms, variables.size())); // at this point there is a match in count between markers and variables that is non-zero if (logger.isTraceEnabled()) for (int i = 0; i < variables.size(); i++) logger.trace("[{}] '{}'", i+1, variables.get(i)); } return processStatement(statement, new ExecutionContext(clientState, null, variables)); }
public Mutation mutationForKey(ByteBuffer key, String keyspace, Long timestamp, ThriftClientState clientState, List<ByteBuffer> variables, CFMetaData metadata) throws InvalidRequestException { Mutation mutation = new Mutation(keyspace, key); QueryProcessor.validateKeyAlias(metadata, keyName); if (columns.size() < 1) { // No columns, delete the partition mutation.delete(columnFamily, (timestamp == null) ? getTimestamp(clientState) : timestamp); } else { // Delete specific columns AbstractType<?> at = metadata.comparator.asAbstractType(); for (Term column : columns) { CellName columnName = metadata.comparator.cellFromByteBuffer(column.getByteBuffer(at, variables)); validateColumnName(columnName); mutation.delete(columnFamily, columnName, (timestamp == null) ? getTimestamp(clientState) : timestamp); } } return mutation; }
public static CqlPreparedResult prepare(String queryString, ThriftClientState clientState) throws SyntaxException { logger.trace("CQL QUERY: {}", queryString); CQLStatement statement = getStatement(queryString); int statementId = makeStatementId(queryString); logger.trace("Discovered "+ statement.boundTerms + " bound variables."); clientState.getPrepared().put(statementId, statement); logger.trace(String.format("Stored prepared statement #%d with %d bind markers", statementId, statement.boundTerms)); return new CqlPreparedResult(statementId, statement.boundTerms); }
public static CqlResult processPrepared(CQLStatement statement, ThriftClientState clientState, List<ByteBuffer> variables) throws RequestValidationException, RequestExecutionException { // Check to see if there are any bound variables to verify if (!(variables.isEmpty() && (statement.boundTerms == 0))) { if (variables.size() != statement.boundTerms) throw new InvalidRequestException(String.format("there were %d markers(?) in CQL but %d bound variables", statement.boundTerms, variables.size())); // at this point there is a match in count between markers and variables that is non-zero if (logger.isTraceEnabled()) for (int i = 0; i < variables.size(); i++) logger.trace("[{}] '{}'", i+1, variables.get(i)); } return processStatement(statement, clientState, variables); }
public List<IMutation> prepareRowMutations(String keyspace, ThriftClientState clientState, Long timestamp, List<ByteBuffer> variables) throws InvalidRequestException, UnauthorizedException { CFMetaData metadata = validateColumnFamily(keyspace, columnFamily); clientState.hasColumnFamilyAccess(keyspace, columnFamily, Permission.MODIFY); AbstractType<?> keyType = Schema.instance.getCFMetaData(keyspace, columnFamily).getKeyValidator(); List<IMutation> rowMutations = new ArrayList<IMutation>(keys.size()); for (Term key : keys) { rowMutations.add(mutationForKey(key.getByteBuffer(keyType, variables), keyspace, timestamp, clientState, variables, metadata)); } return rowMutations; }
public RowMutation mutationForKey(ByteBuffer key, String keyspace, Long timestamp, ThriftClientState clientState, List<ByteBuffer> variables, CFMetaData metadata) throws InvalidRequestException { RowMutation rm = new RowMutation(keyspace, key); QueryProcessor.validateKeyAlias(metadata, keyName); if (columns.size() < 1) { // No columns, delete the row rm.delete(columnFamily, (timestamp == null) ? getTimestamp(clientState) : timestamp); } else { // Delete specific columns for (Term column : columns) { ByteBuffer columnName = column.getByteBuffer(metadata.comparator, variables); validateColumnName(columnName); rm.delete(columnFamily, columnName, (timestamp == null) ? getTimestamp(clientState) : timestamp); } } return rm; }
public static CqlPreparedResult prepare(String queryString, ThriftClientState clientState) throws InvalidRequestException, SyntaxException { logger.trace("CQL QUERY: {}", queryString); CQLStatement statement = getStatement(queryString); int statementId = makeStatementId(queryString); logger.trace("Discovered "+ statement.boundTerms + " bound variables."); clientState.getPrepared().put(statementId, statement); logger.trace(String.format("Stored prepared statement #%d with %d bind markers", statementId, statement.boundTerms)); return new CqlPreparedResult(statementId, statement.boundTerms); }
public static CqlResult process(String queryString, ThriftClientState clientState) throws RequestValidationException, RequestExecutionException { logger.trace("CQL QUERY: {}", queryString); return processStatement(getStatement(queryString), new ExecutionContext(clientState, queryString, Collections.<ByteBuffer>emptyList())); }
/** {@inheritDoc} */ public List<IMutation> prepareRowMutations(String keyspace, ThriftClientState clientState, Long timestamp, List<ByteBuffer> variables) throws InvalidRequestException, UnauthorizedException { boolean hasCommutativeOperation = false; for (Map.Entry<Term, Operation> column : getColumns().entrySet()) { if (!column.getValue().isUnary()) hasCommutativeOperation = true; if (hasCommutativeOperation && column.getValue().isUnary()) throw new InvalidRequestException("Mix of commutative and non-commutative operations is not allowed."); } CFMetaData metadata = validateColumnFamily(keyspace, columnFamily, hasCommutativeOperation); if (hasCommutativeOperation) getConsistencyLevel().validateCounterForWrite(metadata); QueryProcessor.validateKeyAlias(metadata, keyName); clientState.hasColumnFamilyAccess(keyspace, columnFamily, Permission.MODIFY); List<IMutation> mutations = new LinkedList<>(); for (Term key: keys) mutations.add(mutationForKey(keyspace, key.getByteBuffer(getKeyType(keyspace),variables), metadata, timestamp, clientState, variables)); return mutations; }
public List<IMutation> getMutations(String keyspace, ThriftClientState clientState, List<ByteBuffer> variables) throws InvalidRequestException, UnauthorizedException { List<IMutation> batch = new LinkedList<IMutation>(); for (AbstractModification statement : statements) { batch.addAll(statement.prepareRowMutations(keyspace, clientState, timestamp, variables)); } return batch; }
public List<IMutation> prepareRowMutations(String keyspace, ThriftClientState clientState, Long timestamp, List<ByteBuffer> variables) throws InvalidRequestException, UnauthorizedException { CFMetaData metadata = validateColumnFamily(keyspace, columnFamily); clientState.hasColumnFamilyAccess(keyspace, columnFamily, Permission.MODIFY); AbstractType<?> keyType = Schema.instance.getCFMetaData(keyspace, columnFamily).getKeyValidator(); List<IMutation> mutations = new ArrayList<IMutation>(keys.size()); for (Term key : keys) mutations.add(mutationForKey(key.getByteBuffer(keyType, variables), keyspace, timestamp, clientState, variables, metadata)); return mutations; }
/** {@inheritDoc} */ public List<IMutation> prepareRowMutations(String keyspace, ThriftClientState clientState, Long timestamp, List<ByteBuffer> variables) throws InvalidRequestException, UnauthorizedException { boolean hasCommutativeOperation = false; for (Map.Entry<Term, Operation> column : getColumns().entrySet()) { if (!column.getValue().isUnary()) hasCommutativeOperation = true; if (hasCommutativeOperation && column.getValue().isUnary()) throw new InvalidRequestException("Mix of commutative and non-commutative operations is not allowed."); } CFMetaData metadata = validateColumnFamily(keyspace, columnFamily, hasCommutativeOperation); if (hasCommutativeOperation) getConsistencyLevel().validateCounterForWrite(metadata); QueryProcessor.validateKeyAlias(metadata, keyName); clientState.hasColumnFamilyAccess(keyspace, columnFamily, Permission.MODIFY); List<IMutation> rowMutations = new LinkedList<IMutation>(); for (Term key: keys) { rowMutations.add(mutationForKey(keyspace, key.getByteBuffer(getKeyType(keyspace),variables), metadata, timestamp, clientState, variables)); } return rowMutations; }
public RowMutation mutationForKey(ByteBuffer key, String keyspace, Long timestamp, ThriftClientState clientState, List<ByteBuffer> variables, CFMetaData metadata) throws InvalidRequestException { RowMutation rm = new RowMutation(keyspace, key); QueryProcessor.validateKeyAlias(metadata, keyName); AbstractType<?> comparator = metadata.getComparatorFor(null); if (columns.size() < 1) { // No columns, delete the row rm.delete(new QueryPath(columnFamily), (timestamp == null) ? getTimestamp(clientState) : timestamp); } else { // Delete specific columns for (Term column : columns) { ByteBuffer columnName = column.getByteBuffer(comparator, variables); validateColumnName(columnName); rm.delete(new QueryPath(columnFamily, null, columnName), (timestamp == null) ? getTimestamp(clientState) : timestamp); } } return rm; }