]> git.basschouten.com Git - openhab-addons.git/blob
e905d45fa61f14ad6d9f93374e62eb72da21c6ad
[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).newItemSupplier(DynamoDBStringItem::new)
34             .addAttribute(NULLABLE_STRING, a -> a.name(DynamoDBItem.ATTRIBUTE_NAME_ITEMSTATE_LEGACY)
35                     .getter(DynamoDBStringItem::getState).setter(DynamoDBStringItem::setState))
36             .build();
37
38     public static final StaticTableSchema<DynamoDBStringItem> TABLE_SCHEMA_NEW = getBaseSchemaBuilder(
39             DynamoDBStringItem.class, false)
40             .newItemSupplier(DynamoDBStringItem::new)
41             .addAttribute(NULLABLE_STRING,
42                     a -> a.name(DynamoDBItem.ATTRIBUTE_NAME_ITEMSTATE_STRING).getter(DynamoDBStringItem::getState)
43                             .setter(DynamoDBStringItem::setState))
44             .addAttribute(NULLABLE_LONG, a -> a.name(ATTRIBUTE_NAME_EXPIRY).getter(AbstractDynamoDBItem::getExpiryDate)
45                     .setter(AbstractDynamoDBItem::setExpiry))
46             .build();
47
48     public DynamoDBStringItem() {
49         this("", null, ZonedDateTime.now(), null);
50     }
51
52     public DynamoDBStringItem(String name, @Nullable String state, ZonedDateTime time, @Nullable Integer expireDays) {
53         super(name, state, time, expireDays);
54     }
55
56     @Override
57     public @Nullable String getState() {
58         return state;
59     }
60
61     @Override
62     public void setState(@Nullable String state) {
63         this.state = state;
64     }
65
66     @Override
67     public <T> T accept(DynamoDBItemVisitor<T> visitor) {
68         return visitor.visit(this);
69     }
70 }