2 * Copyright (c) 2010-2022 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.binding.dbquery.internal.domain;
15 import java.time.Duration;
16 import java.time.Instant;
17 import java.util.Date;
18 import java.util.LinkedHashMap;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
30 * @author Joan Pujol - Initial contribution
33 public class ResultRow {
34 private final Logger logger = LoggerFactory.getLogger(ResultRow.class);
36 private final LinkedHashMap<String, @Nullable Object> values;
38 public ResultRow(String columnName, @Nullable Object value) {
39 this.values = new LinkedHashMap<>();
40 put(columnName, value);
43 public ResultRow(Map<String, @Nullable Object> values) {
44 this.values = new LinkedHashMap<>();
45 values.forEach(this::put);
48 public Set<String> getColumnNames() {
49 return values.keySet();
52 public int getColumnsSize() {
56 public @Nullable Object getValue(String column) {
57 return values.get(column);
60 public static boolean isValidResultRowType(@Nullable Object object) {
61 return object == null || object instanceof String || object instanceof Boolean || object instanceof Number
62 || object instanceof byte[] || object instanceof Instant || object instanceof Date
63 || object instanceof Duration;
66 private void put(String columnName, @Nullable Object value) {
67 if (!isValidResultRowType(value)) {
68 logger.trace("Value {} of type {} converted to String as not supported internal type in dbquery", value,
70 value = value.toString();
72 values.put(columnName, value);
76 public String toString() {
77 return values.toString();