/** * @return cql query statement to insert a new task into the "workflows" table */ public String getInsertTaskStatement() { return QueryBuilder.insertInto(keyspace, TABLE_WORKFLOWS) .value(WORKFLOW_ID_KEY, bindMarker()) .value(SHARD_ID_KEY, bindMarker()) .value(TASK_ID_KEY, bindMarker()) .value(ENTITY_KEY, ENTITY_TYPE_TASK) .value(PAYLOAD_KEY, bindMarker()) .getQueryString(); }
private static String insertSQL(final String table, final int timeout) { Insert insertInto = insertInto(table) .value(ID, raw("?")) .value(CREATED_AT, raw("?")) .value(ACCESSED_AT, raw("?")) .value(SAVED_AT, raw("?")) .value(ATTRIBUTES, raw("?")); if (timeout > 0) { insertInto.using(ttl(timeout)); } return insertInto.getQueryString(); }
/** * @return cql query statement to insert a new workflow into the "workflows" table */ public String getInsertWorkflowStatement() { return QueryBuilder.insertInto(keyspace, TABLE_WORKFLOWS) .value(WORKFLOW_ID_KEY, bindMarker()) .value(SHARD_ID_KEY, bindMarker()) .value(TASK_ID_KEY, bindMarker()) .value(ENTITY_KEY, ENTITY_TYPE_WORKFLOW) .value(PAYLOAD_KEY, bindMarker()) .value(TOTAL_TASKS_KEY, bindMarker()) .value(TOTAL_PARTITIONS_KEY, bindMarker()) .getQueryString(); }
@Override @Nonnull protected PreparedStatement prepare(Operation operation) { checkArgument(operation, Put.class); Put put = (Put) operation; Insert insert = prepare(put); String query = insert.getQueryString(); return prepare(query); }
/** * This method return the CQL query to insert data in to the table. * refer : http://docs.datastax.com/en/cql/3.1/cql/cql_reference/insert_r.html * * @param mapping Cassandra Mapping {@link CassandraMapping} * @param fields available fields * @return CQL Query */ static String getInsertDataQuery(CassandraMapping mapping, List<String> fields) { String[] columnNames = getColumnNames(mapping, fields); String[] objects = new String[fields.size()]; Arrays.fill(objects, "?"); return QueryBuilder.insertInto(mapping.getKeySpace().getName(), mapping.getCoreName()).values(columnNames, objects).getQueryString(); }
public void save(final List<Event> events) { final BatchStatement batch = new BatchStatement(); for (final Event event : events) { final Map<String, Object> parsedEvent = parse(event); if (parsedEvent.isEmpty()) { log.warn("Event {} could not be mapped. Suggestion: Cassandra is case sensitive, so maybe you can check field names.", event); continue; } if (!hasPrimaryKey(parsedEvent)) { break; } final Insert insert = QueryBuilder.insertInto(table); for (final Map.Entry<String, Object> entry : parsedEvent.entrySet()) { insert.value(entry.getKey(), entry.getValue()); } if (log.isTraceEnabled()) { log.trace("Preparing insert for table {}: {}", table.getName(), insert.getQueryString()); } batch.add(insert); } if (batch.getStatements().isEmpty()) { log.warn("No event produced insert query for table {}", table.getName()); return; } batch.setConsistencyLevel(consistencyLevel); session.execute(batch); }
/** * This method return the CQL query to insert data in to the table. * refer : http://docs.datastax.com/en/cql/3.1/cql/cql_reference/insert_r.html * * @param mapping Cassandra Mapping {@link CassandraMapping} * @param fields available fields * @return CQL Query */ static String getInsertDataQuery(CassandraMapping mapping, List<String> fields) { String[] columnNames = getColumnNames(mapping, fields); String[] objects = new String[fields.size()]; Arrays.fill(objects, "?"); return QueryBuilder.insertInto(mapping.getKeySpace().getName(), mapping.getCoreName()).values(columnNames, objects).getQueryString(); }
private void createInsertStatement() { Insert insertBuilder = QueryBuilder.insertInto(config.getTable()); insertBuilder.value(config.getPartitionKeyColumn(), new Object()); insertBuilder.value(config.getColumn(), new Object()); insertStatement = session.prepare(insertBuilder.getQueryString()); } }
@Override public boolean storeScope(Scope scope) { Insert stmt = QueryBuilder.insertInto(KEYSPACE_NAME, SCOPE_TABLE_NAME) .value("scope", scope.getScope()) .value("description", scope.getDescription()) .value("cc_expires_in", scope.getCcExpiresIn()) .value("pass_expires_in", scope.getPassExpiresIn()) .value("refresh_expires_in", scope.getRefreshExpiresIn()) ; try { session.execute(stmt); } catch (NoHostAvailableException e) { log.error("No host in the %s cluster can be contacted to execute the query.\n", session.getCluster()); } catch (QueryExecutionException e) { log.error("An exception was thrown by Cassandra because it cannot " + "successfully execute the query with the specified consistency level."); } catch (QueryValidationException e) { log.error(String.format("The query %s \nis not valid, for example, incorrect syntax.\n", stmt.getQueryString())); } catch (IllegalStateException e) { log.error("The BoundStatement is not ready."); } return true; }
@Override public void storeAuthCode(AuthCode authCode) { Insert stmt = QueryBuilder.insertInto(KEYSPACE_NAME, AUTH_CODE_TABLE_NAME) .value("code", authCode.getCode()) .value("client_id", authCode.getClientId()) .value("redirect_uri", authCode.getRedirectUri()) .value("state", authCode.getState()) .value("scope", authCode.getScope()) .value("type", authCode.getType()) .value("valid", authCode.isValid()) .value("user_id", authCode.getUserId()) .value("created", authCode.getCreated()) ; try { session.execute(stmt); } catch (NoHostAvailableException e) { log.error("No host in the %s cluster can be contacted to execute the query.\n", session.getCluster()); } catch (QueryExecutionException e) { log.error("An exception was thrown by Cassandra because it cannot " + "successfully execute the query with the specified consistency level."); } catch (QueryValidationException e) { log.error(String.format("The query %s \nis not valid, for example, incorrect syntax.\n", stmt.getQueryString())); } catch (IllegalStateException e) { log.error("The BoundStatement is not ready."); } }
@Override public void storeClientCredentials(ClientCredentials clientCreds) { Insert stmt = QueryBuilder.insertInto(KEYSPACE_NAME, CLIENTS_TABLE_NAME) .value("client_id", clientCreds.getId()) .value("client_secret", clientCreds.getSecret()) .value("scope", clientCreds.getScope()) .value("name", clientCreds.getName()) .value("created", clientCreds.getCreated()) .value("uri", clientCreds.getUri()) .value("descr", clientCreds.getDescr()) .value("type", clientCreds.getType()) .value("status", clientCreds.getStatus()) .value("details", clientCreds.getApplicationDetails()); try { session.execute(stmt); } catch (NoHostAvailableException e) { log.error("No host in the %s cluster can be contacted to execute the query.\n", session.getCluster()); } catch (QueryExecutionException e) { log.error("An exception was thrown by Cassandra because it cannot " + "successfully execute the query with the specified consistency level."); } catch (QueryValidationException e) { log.error(String.format("The query %s \nis not valid, for example, incorrect syntax.\n", stmt.getQueryString())); } catch (IllegalStateException e) { log.error("The BoundStatement is not ready."); } }
} catch (QueryValidationException e) { log.error(String.format("The query %s \nis not valid, for example, incorrect syntax.\n", stmt.getQueryString())); } catch (IllegalStateException e) { log.error("The BoundStatement is not ready.");
/** * Prepare the statement for writing to the hash table. * * @param admin The Cassandra cluster connection. * @param schemaHashTable The table name. * @return A write statement for the hash table. */ private static PreparedStatement prepareQueryWriteHashTable( final CassandraAdmin admin, final CassandraTableName schemaHashTable ) { final Insert insert = QueryBuilder.insertInto(schemaHashTable.getKeyspace(), schemaHashTable.getTable()) .value(SCHEMA_COLUMN_HASH_KEY, bindMarker()) .value(SCHEMA_COLUMN_TIME, bindMarker()) .value(SCHEMA_COLUMN_VALUE, bindMarker()); return admin.getPreparedStatement(insert.getQueryString()); }
/** * Prepare the statement for writing to the ID table. * * @param admin The Cassandra cluster connection. * @param schemaIdTable The table name. * @return A write statement for the id table. */ private PreparedStatement prepareQueryWriteIdTable( final CassandraAdmin admin, final CassandraTableName schemaIdTable ) { final Insert insert = QueryBuilder.insertInto(schemaIdTable.getKeyspace(), schemaIdTable.getTable()) .value(SCHEMA_COLUMN_ID_KEY, bindMarker()) .value(SCHEMA_COLUMN_TIME, bindMarker()) .value(SCHEMA_COLUMN_VALUE, bindMarker()); return admin.getPreparedStatement(insert.getQueryString()); }
private static String insertSQL(final String table, final int timeout) { Insert insertInto = insertInto(table) .value(ID, raw("?")) .value(CREATED_AT, raw("?")) .value(ACCESSED_AT, raw("?")) .value(SAVED_AT, raw("?")) .value(ATTRIBUTES, raw("?")); if (timeout > 0) { insertInto.using(ttl(timeout)); } return insertInto.getQueryString(); }