本文整理汇总了Java中com.amazonaws.services.simpledb.model.SelectResult类的典型用法代码示例。如果您正苦于以下问题:Java SelectResult类的具体用法?Java SelectResult怎么用?Java SelectResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SelectResult类属于com.amazonaws.services.simpledb.model包,在下文中一共展示了SelectResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import com.amazonaws.services.simpledb.model.SelectResult; //导入依赖的package包/类
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException{
try{
String customerID = request.getParameter("customerID");
BasicAWSCredentials awsCredentials = new BasicAWSCredentials("test", "test");
AmazonSimpleDBClient sdbc = new AmazonSimpleDBClient(awsCredentials);
String query = "select * from invoices where customerID = '"
+ customerID;
SelectResult sdbResult = sdbc.select(new SelectRequest(query)); //BAD
SelectResult sdbResult2 = sdbc.select(new SelectRequest(query, false)); //BAD
SelectRequest sdbRequest = new SelectRequest();
SelectResult sdbResult3 = sdbc.select(sdbRequest.withSelectExpression(query)); //BAD
String query2 = "select * from invoices where customerID = 123";
SelectResult sdbResult4 = sdbc.select(new SelectRequest(query2)); //OK
}catch(Exception e){
System.out.println(e);
}
}
示例2: getPagedItems
import com.amazonaws.services.simpledb.model.SelectResult; //导入依赖的package包/类
/**
* @{inheritDoc
*/
@Override
public PagedDatabaseResult getPagedItems(String tableName, Object token, String minRange, String maxRange, String instanceId, String jobId) {
List<Item> ret = new ArrayList<Item>();
String whereClause = null;
if (minRange != null && maxRange != null) {
whereClause = " Timestamp between '" + minRange + "' and '" + maxRange + "' ";
} else if (minRange != null) {
whereClause = " Timestamp >= '" + minRange + "' ";
} else if (maxRange != null) {
whereClause = " Timestamp < '" + maxRange + "' ";
} else {
whereClause = "";
}
SelectRequest request = new SelectRequest("SELECT * from `" + tableName + "`" + whereClause).withConsistentRead(true);
String nextToken = (String) token;
request.withNextToken(nextToken);
SelectResult result = db.select(request);
for (com.amazonaws.services.simpledb.model.Item item : result.getItems()) {
ret.add(resultToItem(item));
}
nextToken = result.getNextToken();
return new PagedDatabaseResult(ret, result.getNextToken());
}
示例3: findAll
import com.amazonaws.services.simpledb.model.SelectResult; //导入依赖的package包/类
@Override
public ImmutableSet<CassandraInstance> findAll(String ring) {
List<CassandraInstance> instances = Lists.newArrayList();
String nextToken = null;
do {
SelectRequest request = new SelectRequest(String.format(ALL_QUERY, domain(ring)))
.withNextToken(nextToken);
SelectResult result = client.select(request);
for (Item item : result.getItems()) {
instances.add(transform(item));
}
nextToken = result.getNextToken();
} while (nextToken != null);
return ImmutableSet.copyOf(instances);
}
示例4: findAll
import com.amazonaws.services.simpledb.model.SelectResult; //导入依赖的package包/类
@Test
public void findAll() {
List<Item> items = createItems();
SelectResult result = createMock(SelectResult.class);
Capture<SelectRequest> requestCapture = new Capture<SelectRequest>();
expect(domainFactory.createFromRing(RING_NAME)).andReturn(domain(RING_NAME));
expect(simpleDbClient.select(capture(requestCapture))).andReturn(result);
expect(result.getItems()).andReturn(items);
expect(result.getNextToken()).andReturn(null);
replayAll();
Set<CassandraInstance> expected = transform(items);
assertEquals(expected, dao.findAll(RING_NAME));
assertEquals(ALL_QUERY, requestCapture.getValue().getSelectExpression());
assertNull(requestCapture.getValue().getNextToken());
}
示例5: findById
import com.amazonaws.services.simpledb.model.SelectResult; //导入依赖的package包/类
@Test
public void findById() {
List<Item> items = ImmutableList.of(createItem(1));
SelectResult result = createMock(SelectResult.class);
Capture<SelectRequest> requestCapture = new Capture<SelectRequest>();
expect(domainFactory.createFromRing(RING_NAME)).andReturn(domain(RING_NAME));
expect(simpleDbClient.select(capture(requestCapture))).andReturn(result);
expect(result.getItems()).andStubReturn(items);
replayAll();
Set<CassandraInstance> expected = transform(items);
assertEquals(expected.iterator().next(), dao.findById(RING_NAME, ID));
assertEquals(String.format(SdbCassandraInstanceDao.INSTANCE_QUERY, DOMAIN, ID),
requestCapture.getValue().getSelectExpression());
assertNull(requestCapture.getValue().getNextToken());
}
示例6: invokeCountImpl
import com.amazonaws.services.simpledb.model.SelectResult; //导入依赖的package包/类
private <T> long invokeCountImpl(boolean consistentRead,
SimpleDbEntityInformation<T, ?> entityInformation,
final String countQuery) {
LOGGER.debug("Count items for query " + countQuery);
validateSelectQuery(countQuery);
final String escapedQuery = getEscapedQuery(countQuery, entityInformation);
final SelectResult selectResult = invokeFindImpl(consistentRead, escapedQuery);
for (Item item : selectResult.getItems()) {
if (item.getName().equals("Domain")) {
for (Attribute attribute : item.getAttributes()) {
if (attribute.getName().equals("Count")) {
return Long.parseLong(attribute.getValue());
}
}
}
}
return 0;
}
示例7: testGetAllItemsCorrectlyCallsSimpleDB
import com.amazonaws.services.simpledb.model.SelectResult; //导入依赖的package包/类
@Test
public void testGetAllItemsCorrectlyCallsSimpleDB() throws Exception {
// ARRANGE
initialiseOptimisticPersister();
SelectRequest selectRequest = new SelectRequest();
selectRequest.setConsistentRead(true);
selectRequest.setSelectExpression("select * from `" + testSimpleDBDomainName + "`");
// Configure select result with an item to be returned:
SelectResult selectResult = new SelectResult();
Set<Item> items = new HashSet<>();
Item item = new Item();
String itemDate = "2016-07-23";
item.setName(itemDate);
item.setAttributes(allAttributes);
items.add(item);
selectResult.setItems(items);
mockery.checking(new Expectations() {
{
oneOf(mockSimpleDBClient).select(with(equal(selectRequest)));
will(returnValue(selectResult));
}
});
List<ImmutablePair<String, List<Attribute>>> expectedItems = new ArrayList<>();
ImmutablePair<String, List<Attribute>> pair = new ImmutablePair<>(itemDate, new ArrayList<>(
activeNonVersionAttributes));
expectedItems.add(pair);
// ACT
List<ImmutablePair<String, List<Attribute>>> actualItems = optimisticPersister.getAllItems();
// ASSERT
assertTrue("OptimisticPersister should return the correct items. Actual: " + actualItems
+ ", Expected: " + expectedItems, actualItems.equals(expectedItems));
}
示例8: execute
import com.amazonaws.services.simpledb.model.SelectResult; //导入依赖的package包/类
public void execute() {
SelectRequest request = new SelectRequest()
.withSelectExpression(determineSelectExpression())
.withConsistentRead(determineConsistentRead())
.withNextToken(determineNextToken());
log.trace("Sending request [{}] for exchange [{}]...", request, exchange);
SelectResult result = this.sdbClient.select(request);
log.trace("Received result [{}]", result);
Message msg = getMessageForResponse(exchange);
msg.setHeader(SdbConstants.ITEMS, result.getItems());
msg.setHeader(SdbConstants.NEXT_TOKEN, result.getNextToken());
}
示例9: select
import com.amazonaws.services.simpledb.model.SelectResult; //导入依赖的package包/类
@Override
public SelectResult select(SelectRequest selectRequest) throws AmazonServiceException, AmazonClientException {
this.selectRequest = selectRequest;
SelectResult result = new SelectResult();
result.setNextToken("TOKEN2");
result.getItems().add(new Item("ITEM1", null));
result.getItems().add(new Item("ITEM2", null));
return result;
}
示例10: searchAmazonSimpleDB
import com.amazonaws.services.simpledb.model.SelectResult; //导入依赖的package包/类
private Iterator<Item> searchAmazonSimpleDB(boolean users,Filter filter,ArrayList<Attribute> attributes) {
StringBuffer sqlWhere = new StringBuffer();
ArrayList<Object> vals = new ArrayList<Object>();
this.stringFilter(filter.getRoot(),sqlWhere, vals);
StringBuffer SQL = new StringBuffer();
SQL.append("SELECT ");
if (attributes.size() == 0) {
SQL.append("* ");
} else if (attributes.size() == 1 && attributes.get(0).equals("*")) {
SQL.append("* ");
} else if (attributes.size() == 1 && attributes.get(0).getAttribute().getName().equals("1.1")) {
SQL.append("uid ");
} else {
for(Attribute attr : attributes) {
SQL.append(attr.getAttribute().getName()).append(',');
}
SQL.setLength(SQL.length() - 1);
}
SQL.append(" FROM ").append('`');
if (users) {
SQL.append(this.userDomain);
} else {
SQL.append(this.groupDomain);
}
SQL.append("` WHERE ").append(sqlWhere);
if (logger.isDebugEnabled()) {
logger.debug("SQL : " + SQL.toString());
}
SelectResult res = this.sdb.select(new SelectRequest(SQL.toString()));
return res.getItems().iterator();
}
示例11: hasJobData
import com.amazonaws.services.simpledb.model.SelectResult; //导入依赖的package包/类
/**
* @{inheritDoc
*/
@Override
public boolean hasJobData(String tableName, String jobId) {
boolean ret = false;
if (hasTable(tableName)) {
SelectRequest request = new SelectRequest("SELECT * from `" + tableName + "`");
SelectResult result = db.select(request);
ret = !result.getItems().isEmpty();
}
return ret;
}
示例12: internalQuery
import com.amazonaws.services.simpledb.model.SelectResult; //导入依赖的package包/类
private<T> List<T> internalQuery(Class<T> dataClass, SelectRequest selectRequest) throws WPBIOException
{
List<T> result = new ArrayList<T>();
try
{
SelectResult selectResult = null;
do
{
if (selectResult != null)
{
selectRequest.setNextToken(selectResult.getNextToken());
}
selectResult = sdbClient.select(selectRequest);
List<Item> items = selectResult.getItems();
for(Item item: items)
{
T t = copyAttributesToInstance(dataClass, item.getAttributes());
result.add(t);
}
} while (selectResult.getNextToken() != null);
} catch (Exception e)
{
throw new WPBIOException("cannot get all records " + dataClass.getSimpleName(), e);
}
return result;
}
示例13: testSelect
import com.amazonaws.services.simpledb.model.SelectResult; //导入依赖的package包/类
@Test
public void testSelect() throws Exception {
SelectResult result = new SelectResult();
result.setItems(mockResult());
String query = "select * from item where attribute > 'name'";
Mockito.stub(connection.performSelect(Mockito.anyString(), Mockito.anyString())).toReturn(result);
Command cmd = utility.parseCommand(query);
ExecutionContext context = Mockito.mock(ExecutionContext.class);
ResultSetExecution exec = translator.createResultSetExecution((Select)cmd, context, Mockito.mock(RuntimeMetadata.class), connection);
exec.execute();
exec.next();
Mockito.verify(connection).performSelect("SELECT attribute, somedate, strarray FROM item WHERE attribute > 'name'", null);
}
示例14: testDirectExecution
import com.amazonaws.services.simpledb.model.SelectResult; //导入依赖的package包/类
@Test
public void testDirectExecution() throws Exception {
SelectResult result = new SelectResult();
result.setItems(mockResult());
String query = "select * from item where attribute > 'name'";
Mockito.stub(connection.performSelect(Mockito.anyString(), Mockito.anyString())).toReturn(result);
Command cmd = utility.parseCommand(query);
ExecutionContext context = Mockito.mock(ExecutionContext.class);
List<Argument> arguments = new ArrayList<Argument>();
Argument arg = new Argument(Direction.IN, String.class, Mockito.mock(ProcedureParameter.class));
arg.setArgumentValue(LanguageFactory.INSTANCE.createLiteral(query, String.class));
arguments.add(arg);
ResultSetExecution exec = translator.createDirectExecution(arguments, cmd, context, Mockito.mock(RuntimeMetadata.class), connection);
exec.execute();
List row = exec.next();
Mockito.verify(connection).performSelect("select * from item where attribute > 'name'", null);
Object[] results = (Object[])row.get(0);
assertEquals("a1", results[0]);
assertEquals("[a2, a22]", results[1]);
}
示例15: getAttributeNamesEmptyStringTest
import com.amazonaws.services.simpledb.model.SelectResult; //导入依赖的package包/类
@Test @Ignore
public void getAttributeNamesEmptyStringTest() throws Exception {
DomainMetadataResult metadataResult = mock(DomainMetadataResult.class);
SelectResult result = mock(SelectResult.class);
// List itemsList = mock(ArrayList.class);
// Iterator iterator = mock(Iterator.class);
// Attribute
// when(itemsList.iterator()).thenReturn(iterator);
when(metadataResult.getAttributeNameCount()).thenReturn(3);
when(client.select(any(SelectRequest.class))).thenReturn(result);
// when(client.domainMetadata(any(DomainMetadataRequest.class))).thenReturn(metadataResult);
System.out.println(simpleDbApi.getAttributeNames(null));
}