| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AwsFrame |
|
| 1.6666666666666667;1.667 | ||||
| AwsFrame$AjcClosure1 |
|
| 1.6666666666666667;1.667 | ||||
| AwsFrame$AjcClosure11 |
|
| 1.6666666666666667;1.667 | ||||
| AwsFrame$AjcClosure13 |
|
| 1.6666666666666667;1.667 | ||||
| AwsFrame$AjcClosure3 |
|
| 1.6666666666666667;1.667 | ||||
| AwsFrame$AjcClosure5 |
|
| 1.6666666666666667;1.667 | ||||
| AwsFrame$AjcClosure7 |
|
| 1.6666666666666667;1.667 | ||||
| AwsFrame$AjcClosure9 |
|
| 1.6666666666666667;1.667 |
| 1 | 0 | /** |
| 2 | * Copyright (c) 2012-2016, 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.dynamo; | |
| 31 | ||
| 32 | import com.amazonaws.services.dynamodbv2.model.Condition; | |
| 33 | import com.jcabi.aspects.Immutable; | |
| 34 | import com.jcabi.aspects.Loggable; | |
| 35 | import java.io.IOException; | |
| 36 | import java.util.AbstractCollection; | |
| 37 | import java.util.Iterator; | |
| 38 | import java.util.Map; | |
| 39 | import lombok.EqualsAndHashCode; | |
| 40 | import lombok.ToString; | |
| 41 | ||
| 42 | /** | |
| 43 | * Frame through AWS SDK. | |
| 44 | * | |
| 45 | * @author Yegor Bugayenko (yegor@tpc2.com) | |
| 46 | * @version $Id: 4074bf2dc3686b2202db80479c266668af3da41b $ | |
| 47 | * @since 0.1 | |
| 48 | */ | |
| 49 | @Immutable | |
| 50 | @Loggable(Loggable.DEBUG) | |
| 51 | 4 | @ToString |
| 52 | 1 | @EqualsAndHashCode |
| 53 | ( | |
| 54 | callSuper = false, | |
| 55 | of = { "credentials", "tbl", "name", "conditions", "valve" } | |
| 56 | ) | |
| 57 | final class AwsFrame extends AbstractCollection<Item> implements Frame { | |
| 58 | ||
| 59 | /** | |
| 60 | * AWS credentials. | |
| 61 | */ | |
| 62 | private final transient Credentials credentials; | |
| 63 | ||
| 64 | /** | |
| 65 | * Table. | |
| 66 | */ | |
| 67 | private final transient AwsTable tbl; | |
| 68 | ||
| 69 | /** | |
| 70 | * Table name. | |
| 71 | */ | |
| 72 | private final transient String name; | |
| 73 | ||
| 74 | /** | |
| 75 | * Conditions. | |
| 76 | */ | |
| 77 | private final transient Conditions conditions; | |
| 78 | ||
| 79 | /** | |
| 80 | * Valve with items. | |
| 81 | */ | |
| 82 | private final transient Valve valve; | |
| 83 | ||
| 84 | /** | |
| 85 | * Public ctor. | |
| 86 | * @param creds Credentials | |
| 87 | * @param table Table | |
| 88 | * @param label Table name | |
| 89 | */ | |
| 90 | AwsFrame(final Credentials creds, final AwsTable table, | |
| 91 | final String label) { | |
| 92 | 4 | this(creds, table, label, new Conditions(), new ScanValve()); |
| 93 | 4 | } |
| 94 | ||
| 95 | /** | |
| 96 | * Public ctor. | |
| 97 | * @param creds Credentials | |
| 98 | * @param table Table | |
| 99 | * @param label Table name | |
| 100 | * @param conds Conditions | |
| 101 | * @param vlv Valve | |
| 102 | * @checkstyle ParameterNumber (5 lines) | |
| 103 | */ | |
| 104 | AwsFrame(final Credentials creds, final AwsTable table, | |
| 105 | final String label, final Conditions conds, final Valve vlv) { | |
| 106 | 4 | super(); |
| 107 | 4 | this.credentials = creds; |
| 108 | 4 | this.tbl = table; |
| 109 | 4 | this.name = label; |
| 110 | 4 | this.conditions = conds; |
| 111 | 4 | this.valve = vlv; |
| 112 | 4 | } |
| 113 | ||
| 114 | @Override | |
| 115 | public Iterator<Item> iterator() { | |
| 116 | try { | |
| 117 | 0 | return new AwsIterator( |
| 118 | this.credentials, | |
| 119 | this, | |
| 120 | this.name, | |
| 121 | this.conditions, | |
| 122 | this.tbl.keys(), | |
| 123 | this.valve | |
| 124 | ); | |
| 125 | 0 | } catch (final IOException ex) { |
| 126 | 0 | throw new IllegalStateException(ex); |
| 127 | } | |
| 128 | } | |
| 129 | ||
| 130 | @Override | |
| 131 | public int size() { | |
| 132 | try { | |
| 133 | 0 | return this.valve.count( |
| 134 | this.credentials, this.name, this.conditions | |
| 135 | ); | |
| 136 | 0 | } catch (final IOException ex) { |
| 137 | 0 | throw new IllegalStateException( |
| 138 | String.format("can't count items in \"%s\"", this.name), | |
| 139 | ex | |
| 140 | ); | |
| 141 | } | |
| 142 | } | |
| 143 | ||
| 144 | @Override | |
| 145 | public Frame where(final String attr, final String value) { | |
| 146 | 0 | return this.where(attr, Conditions.equalTo(value)); |
| 147 | } | |
| 148 | ||
| 149 | @Override | |
| 150 | public Frame where(final String attr, final Condition condition) { | |
| 151 | 0 | return new AwsFrame( |
| 152 | this.credentials, | |
| 153 | this.tbl, | |
| 154 | this.name, | |
| 155 | this.conditions.with(attr, condition), | |
| 156 | this.valve | |
| 157 | ); | |
| 158 | } | |
| 159 | ||
| 160 | @Override | |
| 161 | public Frame where(final Map<String, Condition> conds) { | |
| 162 | 0 | return new AwsFrame( |
| 163 | this.credentials, | |
| 164 | this.tbl, | |
| 165 | this.name, | |
| 166 | this.conditions.with(conds), | |
| 167 | this.valve | |
| 168 | ); | |
| 169 | } | |
| 170 | ||
| 171 | @Override | |
| 172 | public Frame through(final Valve vlv) { | |
| 173 | 0 | return new AwsFrame( |
| 174 | this.credentials, | |
| 175 | this.tbl, | |
| 176 | this.name, | |
| 177 | this.conditions, | |
| 178 | vlv | |
| 179 | ); | |
| 180 | } | |
| 181 | ||
| 182 | @Override | |
| 183 | public Table table() { | |
| 184 | 0 | return this.tbl; |
| 185 | } | |
| 186 | ||
| 187 | } |