| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AwsDomain |
|
| 1.0;1 | ||||
| AwsDomain$1 |
|
| 1.0;1 | ||||
| AwsDomain$AjcClosure1 |
|
| 1.0;1 | ||||
| AwsDomain$AjcClosure3 |
|
| 1.0;1 | ||||
| AwsDomain$AjcClosure5 |
|
| 1.0;1 | ||||
| AwsDomain$AjcClosure7 |
|
| 1.0;1 | ||||
| AwsDomain$AjcClosure9 |
|
| 1.0;1 |
| 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.CreateDomainRequest; | |
| 33 | import com.amazonaws.services.simpledb.model.DeleteDomainRequest; | |
| 34 | import com.amazonaws.services.simpledb.model.SelectRequest; | |
| 35 | import com.jcabi.aspects.Immutable; | |
| 36 | import com.jcabi.aspects.Loggable; | |
| 37 | import java.util.Iterator; | |
| 38 | import lombok.EqualsAndHashCode; | |
| 39 | ||
| 40 | /** | |
| 41 | * Single table in SimpleDB, through AWS SDK. | |
| 42 | * | |
| 43 | * @author Yegor Bugayenko (yegor@tpc2.com) | |
| 44 | * @version $Id$ | |
| 45 | * @since 0.1 | |
| 46 | */ | |
| 47 | @Immutable | |
| 48 | @Loggable(Loggable.DEBUG) | |
| 49 | 0 | @EqualsAndHashCode(of = { "credentials", "table" }) |
| 50 | 0 | final class AwsDomain implements Domain { |
| 51 | ||
| 52 | /** | |
| 53 | * AWS credentials. | |
| 54 | */ | |
| 55 | private final transient Credentials credentials; | |
| 56 | ||
| 57 | /** | |
| 58 | * Domain name. | |
| 59 | */ | |
| 60 | private final transient String table; | |
| 61 | ||
| 62 | /** | |
| 63 | * Public ctor. | |
| 64 | * @param creds Credentials | |
| 65 | * @param name Domain name | |
| 66 | */ | |
| 67 | 1 | protected AwsDomain(final Credentials creds, final String name) { |
| 68 | 1 | this.credentials = creds; |
| 69 | 1 | this.table = name; |
| 70 | 1 | } |
| 71 | ||
| 72 | /** | |
| 73 | * {@inheritDoc} | |
| 74 | */ | |
| 75 | @Override | |
| 76 | public String toString() { | |
| 77 | 0 | return this.table; |
| 78 | } | |
| 79 | ||
| 80 | /** | |
| 81 | * {@inheritDoc} | |
| 82 | */ | |
| 83 | @Override | |
| 84 | public String name() { | |
| 85 | 0 | return this.table; |
| 86 | } | |
| 87 | ||
| 88 | /** | |
| 89 | * {@inheritDoc} | |
| 90 | */ | |
| 91 | @Override | |
| 92 | public void create() { | |
| 93 | 0 | this.credentials.aws().createDomain( |
| 94 | new CreateDomainRequest().withDomainName(this.table) | |
| 95 | ); | |
| 96 | 0 | } |
| 97 | ||
| 98 | /** | |
| 99 | * {@inheritDoc} | |
| 100 | */ | |
| 101 | @Override | |
| 102 | public void drop() { | |
| 103 | 0 | this.credentials.aws().deleteDomain( |
| 104 | new DeleteDomainRequest().withDomainName(this.table) | |
| 105 | ); | |
| 106 | 0 | } |
| 107 | ||
| 108 | /** | |
| 109 | * {@inheritDoc} | |
| 110 | */ | |
| 111 | @Override | |
| 112 | public Item item(final String name) { | |
| 113 | 2 | return new AwsItem(this.credentials, this.table, name); |
| 114 | } | |
| 115 | ||
| 116 | /** | |
| 117 | * {@inheritDoc} | |
| 118 | */ | |
| 119 | @Override | |
| 120 | public Iterable<Item> select(final SelectRequest request) { | |
| 121 | 0 | return new Iterable<Item>() { |
| 122 | @Override | |
| 123 | public Iterator<Item> iterator() { | |
| 124 | 0 | return new AwsIterator( |
| 125 | AwsDomain.this.credentials, | |
| 126 | AwsDomain.this.table, | |
| 127 | request | |
| 128 | ); | |
| 129 | } | |
| 130 | }; | |
| 131 | } | |
| 132 | ||
| 133 | } |