本文整理匯總了Java中com.datastax.driver.core.querybuilder.QueryBuilder類的典型用法代碼示例。如果您正苦於以下問題:Java QueryBuilder類的具體用法?Java QueryBuilder怎麽用?Java QueryBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
QueryBuilder類屬於com.datastax.driver.core.querybuilder包,在下文中一共展示了QueryBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getRecordById
import com.datastax.driver.core.querybuilder.QueryBuilder; //導入依賴的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.QueryBuilder; //導入依賴的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.QueryBuilder; //導入依賴的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: deleteRecord
import com.datastax.driver.core.querybuilder.QueryBuilder; //導入依賴的package包/類
@Override
public Response deleteRecord(String keyspaceName, String tableName, String identifier) {
long startTime = System.currentTimeMillis();
ProjectLogger.log("Cassandra Service deleteRecord method started at ==" + startTime,
LoggerEnum.PERF_LOG);
Response response = new Response();
try {
Delete.Where delete = QueryBuilder.delete().from(keyspaceName, tableName)
.where(eq(Constants.IDENTIFIER, identifier));
connectionManager.getSession(keyspaceName).execute(delete);
response.put(Constants.RESPONSE, Constants.SUCCESS);
} catch (Exception e) {
ProjectLogger.log(Constants.EXCEPTION_MSG_DELETE + 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 deleteRecord method end at ==" + stopTime
+ " ,Total time elapsed = " + elapsedTime, LoggerEnum.PERF_LOG);
return response;
}
示例5: saveToCassandra
import com.datastax.driver.core.querybuilder.QueryBuilder; //導入依賴的package包/類
void saveToCassandra(List<DependencyLink> links) {
Dependencies thrift = Dependencies.create(day, day /** ignored */, links);
ByteBuffer blob = thrift.toThrift();
log.info("Saving with day={}", dateStamp);
CassandraConnector.apply(conf).withSessionDo(new AbstractFunction1<Session, Void>() {
@Override public Void apply(Session session) {
session.execute(QueryBuilder.insertInto(keyspace, "dependencies")
.value("day", new Date(day))
.value("dependencies", blob)
);
return null;
}
});
log.info("Done");
}
示例6: shouldCreateAddressbook
import com.datastax.driver.core.querybuilder.QueryBuilder; //導入依賴的package包/類
/**
* Creates and stores a new {@link Addressbook} inside of Cassandra. {@link Contact} classes are converted using the
* custom {@link example.springdata.cassandra.convert.ConverterConfiguration.PersonWriteConverter}.
*/
@Test
public void shouldCreateAddressbook() {
Addressbook addressbook = new Addressbook();
addressbook.setId("private");
addressbook.setMe(new Contact("Walter", "White"));
addressbook.setFriends(Arrays.asList(new Contact("Jesse", "Pinkman"), new Contact("Saul", "Goodman")));
operations.insert(addressbook);
Row row = operations.selectOne(QueryBuilder.select().from("addressbook"), Row.class);
assertThat(row, is(notNullValue()));
assertThat(row.getString("id"), is(equalTo("private")));
assertThat(row.getString("me"), containsString("\"firstname\":\"Walter\""));
assertThat(row.getList("friends", String.class), hasSize(2));
}
示例7: shouldReadAddressbook
import com.datastax.driver.core.querybuilder.QueryBuilder; //導入依賴的package包/類
/**
* Creates and loads a new {@link Addressbook} inside of Cassandra. {@link Contact} classes are converted using the
* custom {@link example.springdata.cassandra.convert.ConverterConfiguration.PersonReadConverter}.
*/
@Test
public void shouldReadAddressbook() {
Addressbook addressbook = new Addressbook();
addressbook.setId("private");
addressbook.setMe(new Contact("Walter", "White"));
addressbook.setFriends(Arrays.asList(new Contact("Jesse", "Pinkman"), new Contact("Saul", "Goodman")));
operations.insert(addressbook);
Addressbook loaded = operations.selectOne(QueryBuilder.select().from("addressbook"), Addressbook.class);
assertThat(loaded.getMe(), is(equalTo(addressbook.getMe())));
assertThat(loaded.getFriends(), is(equalTo(addressbook.getFriends())));
}
示例8: insertAndSelect
import com.datastax.driver.core.querybuilder.QueryBuilder; //導入依賴的package包/類
/**
* Cassandra {@link com.datastax.driver.core.Statement}s can be used together with {@link CassandraTemplate} and the
* mapping layer.
*/
@Test
public void insertAndSelect() {
Insert insert = QueryBuilder.insertInto("users").value("user_id", 42L) //
.value("uname", "heisenberg") //
.value("fname", "Walter") //
.value("lname", "White") //
.ifNotExists(); //
template.execute(insert);
User user = template.selectOneById(User.class, 42L);
assertThat(user.getUsername(), is(equalTo("heisenberg")));
List<User> users = template.select(QueryBuilder.select().from("users"), User.class);
assertThat(users, hasSize(1));
assertThat(users.get(0), is(equalTo(user)));
}
示例9: selectProjections
import com.datastax.driver.core.querybuilder.QueryBuilder; //導入依賴的package包/類
/**
* {@link CassandraTemplate} allows selection of projections on template-level. All basic data types including
* {@link Row} can be selected.
*/
@Test
@SuppressWarnings("unchecked")
public void selectProjections() {
User user = new User();
user.setId(42L);
user.setUsername("heisenberg");
user.setFirstname("Walter");
user.setLastname("White");
template.insert(user);
Long id = template.selectOne(QueryBuilder.select("user_id").from("users"), Long.class);
assertThat(id, is(user.getId()));
Row row = template.selectOne(QueryBuilder.select("user_id").from("users"), Row.class);
assertThat(row.getLong(0), is(user.getId()));
Map<String, Object> map = template.selectOne(QueryBuilder.select().from("users"), Map.class);
assertThat(map, hasEntry("user_id", user.getId()));
assertThat(map, hasEntry("fname", "Walter"));
}
示例10: uploadPackage
import com.datastax.driver.core.querybuilder.QueryBuilder; //導入依賴的package包/類
@Override
public long uploadPackage(DataPackage dataPack) {
long time = System.currentTimeMillis();
try {
Session session;
Cluster cluster;
cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
session = cluster.connect();
ByteBuffer buffer = ByteBuffer.wrap(dataPack.getData());
Statement statement = QueryBuilder.insertInto(DATABASE, MAIN_TABLE)
.value(COL_ID, time)
.value(COL_DATA, buffer)
.value(COL_DESC, dataPack.getDescription());
session.execute(statement);
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
return time;
}
示例11: downloadPackage
import com.datastax.driver.core.querybuilder.QueryBuilder; //導入依賴的package包/類
@Override
public DataPackage downloadPackage(long packageID) {
DataPackage dataPack = new DataPackage();
try {
Session session;
Cluster cluster;
cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
session = cluster.connect();
Statement statement = QueryBuilder.select()
.all()
.from(DATABASE, MAIN_TABLE)
.where(eq(COL_ID, packageID));
ResultSet results = session.execute(statement);
for(Row row : results) {
dataPack.setId(row.getLong(COL_ID));
dataPack.setDescription(row.getString(COL_DESC));
dataPack.setData(row.getBytes(COL_DATA).array());
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
return dataPack;
}
示例12: listPackages
import com.datastax.driver.core.querybuilder.QueryBuilder; //導入依賴的package包/類
@Override
public List<DataPackage> listPackages() {
List<DataPackage> dataPacks = new ArrayList<>();
try {
Session session;
Cluster cluster;
cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
session = cluster.connect();
Statement statement = QueryBuilder.select()
.all()
.from(DATABASE, MAIN_TABLE);
ResultSet results = session.execute(statement);
for(Row row : results) {
DataPackage dataPack = new DataPackage();
dataPack.setId(row.getLong(COL_ID));
dataPack.setDescription(row.getString(COL_DESC));
dataPacks.add(dataPack);
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
return dataPacks;
}
示例13: removeAccessTokenUsingRefreshToken
import com.datastax.driver.core.querybuilder.QueryBuilder; //導入依賴的package包/類
@Override
public void removeAccessTokenUsingRefreshToken(OAuth2RefreshToken refreshToken) {
String tokenValue = refreshToken.getValue();
// Lookup RefreshTokenToAccessToken table for locating access token
RefreshTokenToAccessToken refreshTokenToAccessToken = refreshTokenToAccessTokenRepository.findOne(tokenValue);
if (refreshTokenToAccessToken != null) {
String accessTokenKey = refreshTokenToAccessToken.getAccessTokenKey();
AccessToken accessToken = accessTokenRepository.findOne(accessTokenKey);
String jsonOAuth2AccessToken = accessToken.getoAuth2AccessToken();
OAuth2AccessToken oAuth2AccessToken = OAuthUtil.deserializeOAuth2AccessToken(jsonOAuth2AccessToken);
// Delete access token from all related tables
List<RegularStatement> statementList = prepareRemoveAccessTokenStatements(oAuth2AccessToken);
// Delete from RefreshTokenToAccessToken table
Delete refreshTokenToAccessTokenDelete = CassandraTemplate.createDeleteQuery(RefreshTokenToAccessToken.TABLE, refreshTokenToAccessToken, null, cassandraTemplate.getConverter());
statementList.add(refreshTokenToAccessTokenDelete);
Batch batch = QueryBuilder.batch(statementList.toArray(new RegularStatement[statementList.size()]));
cassandraTemplate.execute(batch);
}
}
示例14: getAllRecords
import com.datastax.driver.core.querybuilder.QueryBuilder; //導入依賴的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;
}
示例15: findRelations
import com.datastax.driver.core.querybuilder.QueryBuilder; //導入依賴的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);
}