2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.persistence.dynamodb.internal;
15 import java.time.ZonedDateTime;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
20 import software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema;
23 * DynamoDBItem for items that can be serialized as DynamoDB string
25 * @author Sami Salonen - Initial contribution
28 public class DynamoDBStringItem extends AbstractDynamoDBItem<String> {
30 private static Class<@Nullable String> NULLABLE_STRING = (Class<@Nullable String>) String.class;
32 public static final StaticTableSchema<DynamoDBStringItem> TABLE_SCHEMA_LEGACY = getBaseSchemaBuilder(
33 DynamoDBStringItem.class, true)
35 DynamoDBStringItem::new)
36 .addAttribute(NULLABLE_STRING, a -> a.name(DynamoDBItem.ATTRIBUTE_NAME_ITEMSTATE_LEGACY)
37 .getter(DynamoDBStringItem::getState).setter(DynamoDBStringItem::setState))
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))
50 public DynamoDBStringItem() {
51 this("", null, ZonedDateTime.now(), null);
54 public DynamoDBStringItem(String name, @Nullable String state, ZonedDateTime time, @Nullable Integer expireDays) {
55 super(name, state, time, expireDays);
59 public @Nullable String getState() {
64 public void setState(@Nullable String state) {
69 public <T> T accept(DynamoDBItemVisitor<T> visitor) {
70 return visitor.visit(this);