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.action;
15 import java.util.Collections;
16 import java.util.List;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
23 * Query result as it's exposed to users in thing actions
25 * @author Joan Pujol - Initial contribution
28 public class ActionQueryResult {
29 private final boolean correct;
30 private List<Map<String, @Nullable Object>> data = Collections.emptyList();
32 public ActionQueryResult(boolean correct, @Nullable List<Map<String, @Nullable Object>> data) {
33 this.correct = correct;
39 public boolean isCorrect() {
43 public List<Map<String, @Nullable Object>> getData() {
47 public @Nullable Object getResultAsScalar() {
48 var firstResult = data.get(0);
49 return isScalarResult() ? firstResult.get(firstResult.keySet().iterator().next()) : null;
52 public boolean isScalarResult() {
53 return data.size() == 1 && data.get(0).keySet().size() == 1;