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).newItemSupplier(DynamoDBStringItem::new)
34 .addAttribute(NULLABLE_STRING, a -> a.name(DynamoDBItem.ATTRIBUTE_NAME_ITEMSTATE_LEGACY)
35 .getter(DynamoDBStringItem::getState).setter(DynamoDBStringItem::setState))
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))
48 public DynamoDBStringItem() {
49 this("", null, ZonedDateTime.now(), null);
52 public DynamoDBStringItem(String name, @Nullable String state, ZonedDateTime time, @Nullable Integer expireDays) {
53 super(name, state, time, expireDays);
57 public @Nullable String getState() {
62 public void setState(@Nullable String state) {
67 public <T> T accept(DynamoDBItemVisitor<T> visitor) {
68 return visitor.visit(this);