1 /* 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"). 5 * You may not use this file except in compliance with the License. 6 * A copy of the License is located at 7 * 8 * http://aws.amazon.com/apache2.0 9 * 10 * or in the "license" file accompanying this file. This file is distributed 11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 * express or implied. See the License for the specific language governing 13 * permissions and limitations under the License. 14 */ 15 16 package software.amazon.awssdk.enhanced.dynamodb.functionaltests.models; 17 18 import static software.amazon.awssdk.enhanced.dynamodb.mapper.StaticAttributeTags.primaryPartitionKey; 19 import static software.amazon.awssdk.enhanced.dynamodb.mapper.StaticAttributeTags.primarySortKey; 20 21 import java.util.Objects; 22 import java.util.UUID; 23 import software.amazon.awssdk.enhanced.dynamodb.TableMetadata; 24 import software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema; 25 26 public class FakeItemWithSort { 27 private static final StaticTableSchema<FakeItemWithSort> FAKE_ITEM_MAPPER = 28 StaticTableSchema.builder(FakeItemWithSort.class) 29 .newItemSupplier(FakeItemWithSort::new) 30 .addAttribute(String.class, a -> a.name("id") 31 .getter(FakeItemWithSort::getId) 32 .setter(FakeItemWithSort::setId) 33 .tags(primaryPartitionKey())) 34 .addAttribute(String.class, a -> a.name("sort") 35 .getter(FakeItemWithSort::getSort) 36 .setter(FakeItemWithSort::setSort) 37 .tags(primarySortKey())) 38 .addAttribute(String.class, a -> a.name("other_attribute_1") 39 .getter(FakeItemWithSort::getOtherAttribute1) 40 .setter(FakeItemWithSort::setOtherAttribute1)) 41 .addAttribute(String.class, a -> a.name("other_attribute_2") 42 .getter(FakeItemWithSort::getOtherAttribute2) 43 .setter(FakeItemWithSort::setOtherAttribute2)) 44 .build(); 45 46 private String id; 47 private String sort; 48 private String otherAttribute1; 49 private String otherAttribute2; 50 FakeItemWithSort()51 public FakeItemWithSort() { 52 } 53 FakeItemWithSort(String id, String sort, String otherAttribute1, String otherAttribute2)54 public FakeItemWithSort(String id, String sort, String otherAttribute1, String otherAttribute2) { 55 this.id = id; 56 this.sort = sort; 57 this.otherAttribute1 = otherAttribute1; 58 this.otherAttribute2 = otherAttribute2; 59 } 60 builder()61 public static Builder builder() { 62 return new Builder(); 63 } 64 getTableSchema()65 public static StaticTableSchema<FakeItemWithSort> getTableSchema() { 66 return FAKE_ITEM_MAPPER; 67 } 68 getTableMetadata()69 public static TableMetadata getTableMetadata() { 70 return FAKE_ITEM_MAPPER.tableMetadata(); 71 } 72 createUniqueFakeItemWithSort()73 public static FakeItemWithSort createUniqueFakeItemWithSort() { 74 return FakeItemWithSort.builder() 75 .id(UUID.randomUUID().toString()) 76 .sort(UUID.randomUUID().toString()) 77 .build(); 78 } 79 createUniqueFakeItemWithoutSort()80 public static FakeItemWithSort createUniqueFakeItemWithoutSort() { 81 return FakeItemWithSort.builder() 82 .id(UUID.randomUUID().toString()) 83 .build(); 84 } 85 getId()86 public String getId() { 87 return id; 88 } 89 setId(String id)90 public void setId(String id) { 91 this.id = id; 92 } 93 getSort()94 public String getSort() { 95 return sort; 96 } 97 setSort(String sort)98 public void setSort(String sort) { 99 this.sort = sort; 100 } 101 getOtherAttribute1()102 public String getOtherAttribute1() { 103 return otherAttribute1; 104 } 105 setOtherAttribute1(String otherAttribute1)106 public void setOtherAttribute1(String otherAttribute1) { 107 this.otherAttribute1 = otherAttribute1; 108 } 109 getOtherAttribute2()110 public String getOtherAttribute2() { 111 return otherAttribute2; 112 } 113 setOtherAttribute2(String otherAttribute2)114 public void setOtherAttribute2(String otherAttribute2) { 115 this.otherAttribute2 = otherAttribute2; 116 } 117 118 @Override equals(Object o)119 public boolean equals(Object o) { 120 if (this == o) { 121 return true; 122 } 123 if (o == null || getClass() != o.getClass()) { 124 return false; 125 } 126 FakeItemWithSort that = (FakeItemWithSort) o; 127 return Objects.equals(id, that.id) && 128 Objects.equals(sort, that.sort) && 129 Objects.equals(otherAttribute1, that.otherAttribute1) && 130 Objects.equals(otherAttribute2, that.otherAttribute2); 131 } 132 133 @Override hashCode()134 public int hashCode() { 135 return Objects.hash(id, sort, otherAttribute1, otherAttribute2); 136 } 137 138 public static class Builder { 139 private String id; 140 private String sort; 141 private String otherAttribute1; 142 private String otherAttribute2; 143 id(String id)144 public Builder id(String id) { 145 this.id = id; 146 return this; 147 } 148 sort(String sort)149 public Builder sort(String sort) { 150 this.sort = sort; 151 return this; 152 } 153 otherAttribute1(String otherAttribute1)154 public Builder otherAttribute1(String otherAttribute1) { 155 this.otherAttribute1 = otherAttribute1; 156 return this; 157 } 158 otherAttribute2(String otherAttribute2)159 public Builder otherAttribute2(String otherAttribute2) { 160 this.otherAttribute2 = otherAttribute2; 161 return this; 162 } 163 build()164 public FakeItemWithSort build() { 165 return new FakeItemWithSort(id, sort, otherAttribute1, otherAttribute2); 166 } 167 } 168 } 169