本文整理汇总了Java中com.datastax.driver.core.querybuilder.Select类的典型用法代码示例。如果您正苦于以下问题:Java Select类的具体用法?Java Select怎么用?Java Select使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Select类属于com.datastax.driver.core.querybuilder包,在下文中一共展示了Select类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRecordById
import com.datastax.driver.core.querybuilder.Select; //导入依赖的package包/类
@Override
public Response getRecordById(String keyspaceName, String tableName, String identifier) {
long startTime = System.currentTimeMillis();
ProjectLogger.log("Cassandra Service getRecordById method started at ==" + startTime,
LoggerEnum.PERF_LOG);
Response response = new Response();
try {
Select selectQuery = QueryBuilder.select().all().from(keyspaceName, tableName);
Where selectWhere = selectQuery.where();
Clause clause = QueryBuilder.eq(Constants.IDENTIFIER, identifier);
selectWhere.and(clause);
ResultSet results = connectionManager.getSession(keyspaceName).execute(selectQuery);
response = CassandraUtil.createResponse(results);
} catch (Exception e) {
ProjectLogger.log(Constants.EXCEPTION_MSG_FETCH + tableName + " : " + e.getMessage(), e);
throw new ProjectCommonException(ResponseCode.SERVER_ERROR.getErrorCode(),
ResponseCode.SERVER_ERROR.getErrorMessage(), ResponseCode.SERVER_ERROR.getResponseCode());
}
long stopTime = System.currentTimeMillis();
long elapsedTime = stopTime - startTime;
ProjectLogger.log("Cassandra Service getRecordById method end at ==" + stopTime
+ " ,Total time elapsed = " + elapsedTime, LoggerEnum.PERF_LOG);
return response;
}
示例2: getRecordsByProperty
import com.datastax.driver.core.querybuilder.Select; //导入依赖的package包/类
@Override
public Response getRecordsByProperty(String keyspaceName, String tableName, String propertyName,
List<Object> propertyValueList) {
long startTime = System.currentTimeMillis();
ProjectLogger.log("Cassandra Service getRecordsByProperty method started at ==" + startTime,
LoggerEnum.PERF_LOG);
Response response = new Response();
try {
Select selectQuery = QueryBuilder.select().all().from(keyspaceName, tableName);
Where selectWhere = selectQuery.where();
Clause clause = QueryBuilder.in(propertyName, propertyValueList);
selectWhere.and(clause);
ResultSet results = connectionManager.getSession(keyspaceName).execute(selectQuery);
response = CassandraUtil.createResponse(results);
} catch (Exception e) {
ProjectLogger.log(Constants.EXCEPTION_MSG_FETCH + tableName + " : " + e.getMessage(), e);
throw new ProjectCommonException(ResponseCode.SERVER_ERROR.getErrorCode(),
ResponseCode.SERVER_ERROR.getErrorMessage(), ResponseCode.SERVER_ERROR.getResponseCode());
}
long stopTime = System.currentTimeMillis();
long elapsedTime = stopTime - startTime;
ProjectLogger.log("Cassandra Service getRecordsByProperty method end at ==" + stopTime
+ " ,Total time elapsed = " + elapsedTime, LoggerEnum.PERF_LOG);
return response;
}
示例3: queryByOpId
import com.datastax.driver.core.querybuilder.Select; //导入依赖的package包/类
@Override
public List<E> queryByOpId(String opId) throws EventStoreException {
Select select = QueryBuilder.select(CassandraEventRecorder.ENTITY_ID).from(tableName);
select.where(QueryBuilder.eq(CassandraEventRecorder.OP_ID, opId));
List<Row> entityEventDatas = cassandraSession.execute(select, PagingIterable::all);
Map<String, E> resultList = new HashMap<>();
for (Row entityEvent : entityEventDatas) {
String entityId = entityEvent.getString(CassandraEventRecorder.ENTITY_ID);
if (!resultList.containsKey(entityId)) {
E value = queryEntity(entityId);
if (value != null)
resultList.put(entityId, value);
}
}
return new ArrayList<>(resultList.values());
}
示例4: getAllRecords
import com.datastax.driver.core.querybuilder.Select; //导入依赖的package包/类
@Override
public Response getAllRecords(String keyspaceName, String tableName) {
long startTime = System.currentTimeMillis();
ProjectLogger.log("Cassandra Service getAllRecords method started at ==" + startTime,
LoggerEnum.PERF_LOG);
Response response = new Response();
try {
Select selectQuery = QueryBuilder.select().all().from(keyspaceName, tableName);
ResultSet results = connectionManager.getSession(keyspaceName).execute(selectQuery);
response = CassandraUtil.createResponse(results);
} catch (Exception e) {
ProjectLogger.log(Constants.EXCEPTION_MSG_FETCH + tableName + " : " + e.getMessage(), e);
throw new ProjectCommonException(ResponseCode.SERVER_ERROR.getErrorCode(),
ResponseCode.SERVER_ERROR.getErrorMessage(), ResponseCode.SERVER_ERROR.getResponseCode());
}
long stopTime = System.currentTimeMillis();
long elapsedTime = stopTime - startTime;
ProjectLogger.log("Cassandra Service getAllRecords method end at ==" + stopTime
+ " ,Total time elapsed = " + elapsedTime, LoggerEnum.PERF_LOG);
return response;
}
示例5: findDeviceTypesByTenantIdCustomerIdAndIdsAsync
import com.datastax.driver.core.querybuilder.Select; //导入依赖的package包/类
@Override
public ListenableFuture<List<DeviceType>> findDeviceTypesByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> deviceIds) {
log.debug("Try to find devices by tenantId [{}], customerId [{}] and device Ids [{}]", tenantId, customerId, deviceIds);
Select select = select().from(getColumnFamilyName());
Select.Where query = select.where();
query.and(eq(DEVICE_TYPE_TENANT_ID_PROPERTY, tenantId));
query.and(eq(DEVICE_TYPE_CUSTOMER_ID_PROPERTY, customerId));
query.and(in(ID_PROPERTY, deviceIds));
return findListByStatementAsync(query);
}
示例6: findRelations
import com.datastax.driver.core.querybuilder.Select; //导入依赖的package包/类
@Override
public ListenableFuture<List<EntityRelation>> findRelations(EntityId from, String relationType, RelationTypeGroup typeGroup, ThingType childType, TimePageLink pageLink) {
Select.Where query = CassandraAbstractSearchTimeDao.buildQuery(ModelConstants.RELATION_BY_TYPE_AND_CHILD_TYPE_VIEW_NAME,
Arrays.asList(eq(ModelConstants.RELATION_FROM_ID_PROPERTY, from.getId()),
eq(ModelConstants.RELATION_FROM_TYPE_PROPERTY, from.getEntityType().name()),
eq(ModelConstants.RELATION_TYPE_GROUP_PROPERTY, typeGroup.name()),
eq(ModelConstants.RELATION_TYPE_PROPERTY, relationType),
eq(ModelConstants.RELATION_TO_TYPE_PROPERTY, childType.name())),
Arrays.asList(
pageLink.isAscOrder() ? QueryBuilder.desc(ModelConstants.RELATION_TYPE_GROUP_PROPERTY) :
QueryBuilder.asc(ModelConstants.RELATION_TYPE_GROUP_PROPERTY),
pageLink.isAscOrder() ? QueryBuilder.desc(ModelConstants.RELATION_TYPE_PROPERTY) :
QueryBuilder.asc(ModelConstants.RELATION_TYPE_PROPERTY),
pageLink.isAscOrder() ? QueryBuilder.desc(ModelConstants.RELATION_TO_TYPE_PROPERTY) :
QueryBuilder.asc(ModelConstants.RELATION_TO_TYPE_PROPERTY)
),
pageLink, ModelConstants.RELATION_TO_ID_PROPERTY);
return getFuture(executeAsyncRead(query), this::getEntityRelations);
}
示例7: findEvent
import com.datastax.driver.core.querybuilder.Select; //导入依赖的package包/类
@Override
public Event findEvent(UUID tenantId, EntityId entityId, String eventType, String eventUid) {
log.debug("Search event entity by [{}][{}][{}][{}]", tenantId, entityId, eventType, eventUid);
Select.Where query = select().from(getColumnFamilyName()).where(
eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId))
.and(eq(ModelConstants.EVENT_ENTITY_TYPE_PROPERTY, entityId.getEntityType()))
.and(eq(ModelConstants.EVENT_ENTITY_ID_PROPERTY, entityId.getId()))
.and(eq(ModelConstants.EVENT_TYPE_PROPERTY, eventType))
.and(eq(ModelConstants.EVENT_UID_PROPERTY, eventUid));
log.trace("Execute query [{}]", query);
EventEntity entity = findOneByStatement(query);
if (log.isTraceEnabled()) {
log.trace("Search result: [{}] for event entity [{}]", entity != null, entity);
} else {
log.debug("Search result: [{}]", entity != null);
}
return DaoUtil.getData(entity);
}
示例8: doHealthCheck
import com.datastax.driver.core.querybuilder.Select; //导入依赖的package包/类
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
try {
Select select = QueryBuilder.select("release_version").from("system",
"local");
ResultSet results = this.cassandraOperations.query(select);
if (results.isExhausted()) {
builder.up();
return;
}
String version = results.one().getString(0);
builder.up().withDetail("version", version);
}
catch (Exception ex) {
builder.down(ex);
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:CassandraHealthIndicator.java
示例9: testInsert
import com.datastax.driver.core.querybuilder.Select; //导入依赖的package包/类
@Test
public void testInsert() throws InterruptedException {
Book book = new Book();
book.setIsbn(UUIDs.timeBased());
book.setTitle("Spring Integration Cassandra");
book.setAuthor("Cassandra Guru");
book.setPages(521);
book.setSaleDate(new Date());
book.setInStock(true);
this.sink.input().send(new GenericMessage<>(book));
final Select select = QueryBuilder.select().all().from("book");
assertEqualsEventually(1, new Supplier<Integer>() {
@Override
public Integer get() {
return cassandraTemplate.select(select, Book.class).size();
}
});
this.cassandraTemplate.delete(book);
}
开发者ID:spring-cloud-stream-app-starters,项目名称:cassandra,代码行数:26,代码来源:CassandraSinkIntegrationTests.java
示例10: testIngestQuery
import com.datastax.driver.core.querybuilder.Select; //导入依赖的package包/类
@Test
public void testIngestQuery() throws Exception {
List<Book> books = getBookList(5);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
Jackson2JsonObjectMapper mapper = new Jackson2JsonObjectMapper(objectMapper);
this.sink.input().send(new GenericMessage<>(mapper.toJson(books)));
final Select select = QueryBuilder.select().all().from("book");
assertEqualsEventually(5, new Supplier<Integer>() {
@Override
public Integer get() {
return cassandraTemplate.select(select, Book.class).size();
}
});
this.cassandraTemplate.truncate("book");
}
开发者ID:spring-cloud-stream-app-starters,项目名称:cassandra,代码行数:24,代码来源:CassandraSinkIntegrationTests.java
示例11: findRelations
import com.datastax.driver.core.querybuilder.Select; //导入依赖的package包/类
@Override
public ListenableFuture<List<EntityRelation>> findRelations(EntityId from, String relationType, RelationTypeGroup typeGroup, EntityType childType, TimePageLink pageLink) {
Select.Where query = CassandraAbstractSearchTimeDao.buildQuery(ModelConstants.RELATION_BY_TYPE_AND_CHILD_TYPE_VIEW_NAME,
Arrays.asList(eq(ModelConstants.RELATION_FROM_ID_PROPERTY, from.getId()),
eq(ModelConstants.RELATION_FROM_TYPE_PROPERTY, from.getEntityType().name()),
eq(ModelConstants.RELATION_TYPE_GROUP_PROPERTY, typeGroup.name()),
eq(ModelConstants.RELATION_TYPE_PROPERTY, relationType),
eq(ModelConstants.RELATION_TO_TYPE_PROPERTY, childType.name())),
Arrays.asList(
pageLink.isAscOrder() ? QueryBuilder.desc(ModelConstants.RELATION_TYPE_GROUP_PROPERTY) :
QueryBuilder.asc(ModelConstants.RELATION_TYPE_GROUP_PROPERTY),
pageLink.isAscOrder() ? QueryBuilder.desc(ModelConstants.RELATION_TYPE_PROPERTY) :
QueryBuilder.asc(ModelConstants.RELATION_TYPE_PROPERTY),
pageLink.isAscOrder() ? QueryBuilder.desc(ModelConstants.RELATION_TO_TYPE_PROPERTY) :
QueryBuilder.asc(ModelConstants.RELATION_TO_TYPE_PROPERTY)
),
pageLink, ModelConstants.RELATION_TO_ID_PROPERTY);
return getFuture(executeAsyncRead(query), this::getEntityRelations);
}
示例12: findTenantDeviceTypesAsync
import com.datastax.driver.core.querybuilder.Select; //导入依赖的package包/类
@Override
public ListenableFuture<List<EntitySubtype>> findTenantDeviceTypesAsync(UUID tenantId) {
Select select = select().from(ENTITY_SUBTYPE_COLUMN_FAMILY_NAME);
Select.Where query = select.where();
query.and(eq(ENTITY_SUBTYPE_TENANT_ID_PROPERTY, tenantId));
query.and(eq(ENTITY_SUBTYPE_ENTITY_TYPE_PROPERTY, EntityType.DEVICE));
query.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel());
ResultSetFuture resultSetFuture = getSession().executeAsync(query);
return Futures.transform(resultSetFuture, new Function<ResultSet, List<EntitySubtype>>() {
@Nullable
@Override
public List<EntitySubtype> apply(@Nullable ResultSet resultSet) {
Result<EntitySubtypeEntity> result = cluster.getMapper(EntitySubtypeEntity.class).map(resultSet);
if (result != null) {
List<EntitySubtype> entitySubtypes = new ArrayList<>();
result.all().forEach((entitySubtypeEntity) ->
entitySubtypes.add(entitySubtypeEntity.toEntitySubtype())
);
return entitySubtypes;
} else {
return Collections.emptyList();
}
}
});
}
示例13: findTenantAssetTypesAsync
import com.datastax.driver.core.querybuilder.Select; //导入依赖的package包/类
@Override
public ListenableFuture<List<EntitySubtype>> findTenantAssetTypesAsync(UUID tenantId) {
Select select = select().from(ENTITY_SUBTYPE_COLUMN_FAMILY_NAME);
Select.Where query = select.where();
query.and(eq(ENTITY_SUBTYPE_TENANT_ID_PROPERTY, tenantId));
query.and(eq(ENTITY_SUBTYPE_ENTITY_TYPE_PROPERTY, EntityType.ASSET));
query.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel());
ResultSetFuture resultSetFuture = getSession().executeAsync(query);
return Futures.transform(resultSetFuture, new Function<ResultSet, List<EntitySubtype>>() {
@Nullable
@Override
public List<EntitySubtype> apply(@Nullable ResultSet resultSet) {
Result<EntitySubtypeEntity> result = cluster.getMapper(EntitySubtypeEntity.class).map(resultSet);
if (result != null) {
List<EntitySubtype> entitySubtypes = new ArrayList<>();
result.all().forEach((entitySubtypeEntity) ->
entitySubtypes.add(entitySubtypeEntity.toEntitySubtype())
);
return entitySubtypes;
} else {
return Collections.emptyList();
}
}
});
}
示例14: singleEvent
import com.datastax.driver.core.querybuilder.Select; //导入依赖的package包/类
protected Optional<Row> singleEvent(String analyseId, String jvmId, String bucketId,
DateTime start, String[] fields) {
List<String> dates = dates(Range.of(start.toDateTime(DateTimeZone.UTC),
DateTime.now(DateTimeZone.UTC)));
for (String date : dates) {
Select from = QueryBuilder.select(fields).from(Strings.isNullOrEmpty(bucketId) ? TABLE_NAME : BUCKET_TABLE_NAME);
Select.Where statement = from.limit(1)
.where(eq("analyse_id", UUID.fromString(analyseId)))
.and(eq("jvm_id", jvmId))
.and(eq("date", date));
if (!Strings.isNullOrEmpty(bucketId)) {
statement = statement.and(eq("bucket_id", bucketId));
}
List<Row> rows = connector.session().execute(statement).all();
if (rows.size() > 0) {
return Optional.of(rows.get(0));
}
}
return Optional.empty();
}
示例15: schemaExists
import com.datastax.driver.core.querybuilder.Select; //导入依赖的package包/类
public boolean schemaExists() throws StoreException {
if (session != null) {
boolean exists = false;
Select select = QueryBuilder.select().column("keyspace_name").from("system.schema_keyspaces");
ResultSet results = session.execute(select);
for (Row row : results) {
String name = row.getString("keyspace_name");
if (KEYSPACE_NAME.equals(name)) {
exists = true;
break;
}
}
return exists;
} else {
throw new StoreException("Keyspaces not available; store not open");
}
}