com.datastax.oss.driver.api.querybuilder.select.Select Java Examples
The following examples show how to use
com.datastax.oss.driver.api.querybuilder.select.Select.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractStatementFactory.java From casquatch with Apache License 2.0 | 5 votes |
/** * Produce a bound statement while applying object and query options * @param buildableQuery buildable query * @param obj populated object * @param queryOptions query options to apply * @param bindToSession override session * @return bound statement */ protected BoundStatement buildBoundStatement(BuildableQuery buildableQuery, Object obj, QueryOptions queryOptions, CqlSession bindToSession) { if(buildableQuery instanceof Select) { if(queryOptions!=null) { if(queryOptions.getLimit()!=null) { buildableQuery = ((Select) buildableQuery).limit(queryOptions.getLimit()); } } } else if (buildableQuery instanceof RegularInsert) { if(queryOptions.getTtl()!=null) { buildableQuery = ((RegularInsert) buildableQuery).usingTtl(queryOptions.getTtl()); } } SimpleStatement simpleStatement = buildableQuery.build(); if(log.isTraceEnabled()) log.trace("Preparing Statement {}",simpleStatement.getQuery()); BoundStatementBuilder boundStatementBuilder = bindToSession.prepare(simpleStatement).boundStatementBuilder(); if(obj.getClass().equals(this.entityClass)) { //noinspection unchecked boundStatementBuilder=bindObject(boundStatementBuilder,(E) obj,queryOptions); } else if (obj.getClass().equals(SolrQueryEntity.class)) { //noinspection unchecked boundStatementBuilder=bindObject(boundStatementBuilder,(SolrQueryEntity) obj,queryOptions); } else { throw new DriverException(DriverException.CATEGORIES.CASQUATCH_MISSING_GENERATED_CLASS, "Unknown class"); } if(queryOptions!=null) { if (queryOptions.getConsistencyLevel() != null) { boundStatementBuilder = boundStatementBuilder.setConsistencyLevel(queryOptions.getConsistencyLevel()); } if (queryOptions.getProfile() != null) { boundStatementBuilder = boundStatementBuilder.setExecutionProfileName(queryOptions.getProfile()); } } return boundStatementBuilder.build(); }
Example #2
Source File: TableDef.java From dynamo-cassandra-proxy with Apache License 2.0 | 4 votes |
public PreparedStatement getLazyJsonQueryPartitionAndClusteringStatement(ComparisonOperator comparisonOperator) { PreparedStatement preparedStatment = null; if (jsonQueryRangeStatementMap.containsKey(comparisonOperator)){ preparedStatment = jsonQueryRangeStatementMap.get(comparisonOperator); } else{ String clustering = "\"" + clusteringKey.get().getAttributeName() + "\""; String partition= "\"" + partitionKey.getAttributeName() + "\""; Select select = selectFrom(keyspaceName, tableName).all().whereColumn(partition).isEqualTo(bindMarker()); switch (comparisonOperator) { case EQ: preparedStatment = session.prepare(select.whereColumn(clustering).isEqualTo(bindMarker()).build()); break; case NE: preparedStatment = session.prepare(select.whereColumn(clustering).isNotEqualTo(bindMarker()).build()); break; case IN: preparedStatment = session.prepare(select.whereColumn(clustering).in(bindMarker()).build()); break; case LE: preparedStatment = session.prepare(select.whereColumn(clustering).isLessThanOrEqualTo(bindMarker()).build()); break; case LT: preparedStatment = session.prepare(select.whereColumn(clustering).isLessThan(bindMarker()).build()); break; case GE: preparedStatment = session.prepare(select.whereColumn(clustering).isGreaterThanOrEqualTo(bindMarker()).build()); break; case GT: preparedStatment = session.prepare(select.whereColumn(clustering).isGreaterThan(bindMarker()).build()); break; case BETWEEN: preparedStatment = session.prepare(select .whereColumn(clustering).isGreaterThanOrEqualTo(bindMarker()) .whereColumn(clustering).isLessThanOrEqualTo(bindMarker()) .build() ); break; case NOT_NULL: preparedStatment = session.prepare(select .whereColumn(clustering).isNotNull() .build() ); break; case NULL: throw new UnsupportedOperationException("CQL does not support null clustering columns"); case CONTAINS: throw new UnsupportedOperationException("Contains - feature unsupported"); case NOT_CONTAINS: throw new UnsupportedOperationException("Not Contains - feature unsupported"); case BEGINS_WITH: throw new UnsupportedOperationException("Begins With - feature unsupported"); } } return preparedStatment; }
Example #3
Source File: NodeMetaData_StatementFactory.java From casquatch with Apache License 2.0 | 4 votes |
@Override protected Select selectWhereObject(Select select, NodeMetaData nodeMetaData, QueryOptions options) { if(nodeMetaData.getKey()!=null) { select=select.whereColumn("key").isEqualTo(bindMarker()); } if(!options.getIgnoreNonPrimaryKeys()) { if(nodeMetaData.getGossipGeneration()!=null) { select=select.whereColumn("gossip_generation").isEqualTo(bindMarker()); } if(nodeMetaData.getRack()!=null) { select=select.whereColumn("rack").isEqualTo(bindMarker()); } if(nodeMetaData.getSchemaVersion()!=null) { select=select.whereColumn("schema_version").isEqualTo(bindMarker()); } if(nodeMetaData.getThriftVersion()!=null) { select=select.whereColumn("thrift_version").isEqualTo(bindMarker()); } if(nodeMetaData.getDataCenter()!=null) { select=select.whereColumn("data_center").isEqualTo(bindMarker()); } if(nodeMetaData.getRpcAddress()!=null) { select=select.whereColumn("rpc_address").isEqualTo(bindMarker()); } if(nodeMetaData.getReleaseVersion()!=null) { select=select.whereColumn("release_version").isEqualTo(bindMarker()); } if(nodeMetaData.getWorkloads()!=null) { select=select.whereColumn("workloads").isEqualTo(bindMarker()); } if(nodeMetaData.getWorkload()!=null) { select=select.whereColumn("workload").isEqualTo(bindMarker()); } if(nodeMetaData.getHostId()!=null) { select=select.whereColumn("host_id").isEqualTo(bindMarker()); } if(nodeMetaData.getServerId()!=null) { select=select.whereColumn("server_id").isEqualTo(bindMarker()); } if(nodeMetaData.getGraph()!=null) { select=select.whereColumn("graph").isEqualTo(bindMarker()); } if(nodeMetaData.getTruncatedAt()!=null) { select=select.whereColumn("truncated_at").isEqualTo(bindMarker()); } if(nodeMetaData.getBroadcastAddress()!=null) { select=select.whereColumn("broadcast_address").isEqualTo(bindMarker()); } if(nodeMetaData.getDseVersion()!=null) { select=select.whereColumn("dse_version").isEqualTo(bindMarker()); } if(nodeMetaData.getCqlVersion()!=null) { select=select.whereColumn("cql_version").isEqualTo(bindMarker()); } if(nodeMetaData.getBootstrapped()!=null) { select=select.whereColumn("bootstrapped").isEqualTo(bindMarker()); } if(nodeMetaData.getNativeProtocolVersion()!=null) { select=select.whereColumn("native_protocol_version").isEqualTo(bindMarker()); } if(nodeMetaData.getListenAddress()!=null) { select=select.whereColumn("listen_address").isEqualTo(bindMarker()); } if(nodeMetaData.getClusterName()!=null) { select=select.whereColumn("cluster_name").isEqualTo(bindMarker()); } if(nodeMetaData.getPartitioner()!=null) { select=select.whereColumn("partitioner").isEqualTo(bindMarker()); } if(nodeMetaData.getTokens()!=null) { select=select.whereColumn("tokens").isEqualTo(bindMarker()); } } return select; }
Example #4
Source File: VideoRepository.java From tutorials with MIT License | 3 votes |
public List<Video> selectAll(String keyspace) { Select select = QueryBuilder.selectFrom(TABLE_NAME).all(); ResultSet resultSet = executeStatement(select.build(), keyspace); List<Video> result = new ArrayList<>(); resultSet.forEach(x -> result.add( new Video(x.getUuid("video_id"), x.getString("title"), x.getInstant("creation_date")) )); return result; }
Example #5
Source File: AbstractStatementFactory.java From casquatch with Apache License 2.0 | 2 votes |
/** * Append a where clause to a select query using non-null fields found in the provided object * @param select select to append to * @param obj partially populated object * @param queryOptions query options to apply * @return select object containing where clause */ protected abstract Select selectWhereObject(Select select, E obj, QueryOptions queryOptions);