]> git.basschouten.com Git - openhab-addons.git/blob
90ae5d1f637629d1e7bd317fef5b142014781b79
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.persistence.dynamodb.internal;
14
15 import java.time.ZonedDateTime;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19
20 import software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema;
21
22 /**
23  * DynamoDBItem for items that can be serialized as DynamoDB string
24  *
25  * @author Sami Salonen - Initial contribution
26  */
27 @NonNullByDefault
28 public class DynamoDBStringItem extends AbstractDynamoDBItem<String> {
29
30     private static Class<@Nullable String> NULLABLE_STRING = (Class<@Nullable String>) String.class;
31
32     public static final StaticTableSchema<DynamoDBStringItem> TABLE_SCHEMA_LEGACY = getBaseSchemaBuilder(
33             DynamoDBStringItem.class, true)
34                     .newItemSupplier(
35                             DynamoDBStringItem::new)
36                     .addAttribute(NULLABLE_STRING, a -> a.name(DynamoDBItem.ATTRIBUTE_NAME_ITEMSTATE_LEGACY)
37                             .getter(DynamoDBStringItem::getState).setter(DynamoDBStringItem::setState))
38                     .build();
39
40     public static final StaticTableSchema<DynamoDBStringItem> TABLE_SCHEMA_NEW = getBaseSchemaBuilder(
41             DynamoDBStringItem.class, false)
42                     .newItemSupplier(DynamoDBStringItem::new)
43                     .addAttribute(NULLABLE_STRING,
44                             a -> a.name(DynamoDBItem.ATTRIBUTE_NAME_ITEMSTATE_STRING)
45                                     .getter(DynamoDBStringItem::getState).setter(DynamoDBStringItem::setState))
46                     .addAttribute(NULLABLE_LONG, a -> a.name(ATTRIBUTE_NAME_EXPIRY)
47                             .getter(AbstractDynamoDBItem::getExpiryDate).setter(AbstractDynamoDBItem::setExpiry))
48                     .build();
49
50     public DynamoDBStringItem() {
51         this("", null, ZonedDateTime.now(), null);
52     }
53
54     public DynamoDBStringItem(String name, @Nullable String state, ZonedDateTime time, @Nullable Integer expireDays) {
55         super(name, state, time, expireDays);
56     }
57
58     @Override
59     public @Nullable String getState() {
60         return state;
61     }
62
63     @Override
64     public void setState(@Nullable String state) {
65         this.state = state;
66     }
67
68     @Override
69     public <T> T accept(DynamoDBItemVisitor<T> visitor) {
70         return visitor.visit(this);
71     }
72 }