Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AwsIterator |
|
| 2.5;2.5 | ||||
AwsIterator$AjcClosure1 |
|
| 2.5;2.5 | ||||
AwsIterator$AjcClosure3 |
|
| 2.5;2.5 | ||||
AwsIterator$AjcClosure5 |
|
| 2.5;2.5 |
1 | 0 | /** |
2 | * Copyright (c) 2012-2014, jcabi.com | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: 1) Redistributions of source code must retain the above | |
8 | * copyright notice, this list of conditions and the following | |
9 | * disclaimer. 2) Redistributions in binary form must reproduce the above | |
10 | * copyright notice, this list of conditions and the following | |
11 | * disclaimer in the documentation and/or other materials provided | |
12 | * with the distribution. 3) Neither the name of the jcabi.com nor | |
13 | * the names of its contributors may be used to endorse or promote | |
14 | * products derived from this software without specific prior written | |
15 | * permission. | |
16 | * | |
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT | |
19 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
20 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | |
21 | * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
22 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
26 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
28 | * OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 | */ | |
30 | package com.jcabi.simpledb; | |
31 | ||
32 | import com.amazonaws.services.simpledb.model.SelectRequest; | |
33 | import com.amazonaws.services.simpledb.model.SelectResult; | |
34 | import com.jcabi.aspects.Loggable; | |
35 | import java.util.Iterator; | |
36 | import java.util.NoSuchElementException; | |
37 | import lombok.EqualsAndHashCode; | |
38 | ||
39 | /** | |
40 | * Iterator of items in SimpleDB. | |
41 | * | |
42 | * @author Yegor Bugayenko (yegor@tpc2.com) | |
43 | * @version $Id$ | |
44 | * @since 0.1 | |
45 | */ | |
46 | 0 | @Loggable(Loggable.DEBUG) |
47 | 0 | @EqualsAndHashCode(of = { "credentials", "table" }) |
48 | final class AwsIterator implements Iterator<Item> { | |
49 | ||
50 | /** | |
51 | * AWS credentials. | |
52 | */ | |
53 | private final transient Credentials credentials; | |
54 | ||
55 | /** | |
56 | * Domain name. | |
57 | */ | |
58 | private final transient String table; | |
59 | ||
60 | /** | |
61 | * Select request. | |
62 | */ | |
63 | private final transient SelectRequest request; | |
64 | ||
65 | /** | |
66 | * Most recent result. | |
67 | */ | |
68 | private transient SelectResult result; | |
69 | ||
70 | /** | |
71 | * Public ctor. | |
72 | * @param creds Credentials | |
73 | * @param name Domain name | |
74 | * @param req Request | |
75 | */ | |
76 | protected AwsIterator(final Credentials creds, final String name, | |
77 | 0 | final SelectRequest req) { |
78 | 0 | this.credentials = creds; |
79 | 0 | this.table = name; |
80 | 0 | this.request = req; |
81 | 0 | } |
82 | ||
83 | /** | |
84 | * {@inheritDoc} | |
85 | */ | |
86 | @Override | |
87 | public boolean hasNext() { | |
88 | 0 | if (this.result == null) { |
89 | 0 | this.result = this.credentials.aws().select(this.request); |
90 | 0 | } else if (this.result.getItems().isEmpty() |
91 | && this.result.getNextToken() != null) { | |
92 | 0 | this.result = this.credentials.aws().select( |
93 | this.request.withNextToken(this.result.getNextToken()) | |
94 | ); | |
95 | } | |
96 | 0 | return !this.result.getItems().isEmpty(); |
97 | } | |
98 | ||
99 | /** | |
100 | * {@inheritDoc} | |
101 | */ | |
102 | @Override | |
103 | public Item next() { | |
104 | 0 | if (!this.hasNext()) { |
105 | 0 | throw new NoSuchElementException(); |
106 | } | |
107 | 0 | return new AwsItem( |
108 | this.credentials, | |
109 | this.table, | |
110 | this.result.getItems().remove(0) | |
111 | ); | |
112 | } | |
113 | ||
114 | /** | |
115 | * {@inheritDoc} | |
116 | */ | |
117 | @Override | |
118 | public void remove() { | |
119 | 0 | throw new UnsupportedOperationException(); |
120 | } | |
121 | ||
122 | } |