/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ package org.opensearch.jdbc; import java.sql.SQLException; import java.sql.Struct; import java.util.Arrays; import java.util.Map; import java.util.List; /** * This class implements the {@link java.sql.Struct} interface. *
* {@code StructImpl} provides a simple implementation of a struct data type. *
*/ public class StructImpl implements Struct { private final String typeName; private final Object[] attributes; /** * Constructs a new {@code StructImpl} object with the specified parameter values. * * @param typeName the SQL type name of the struct * @param attributes the attributes of the struct, each attribute is a {@code Map.Entry* Two StructImpl objects are considered equal if they have the same typeName, same number of attributes, * and contain the same attributes. *
* * @param obj the object to compare with this StructImpl object for equality. * @return {@code true} if the specified object is equal to this StructImpl object, {@code false} otherwise. */ @Override public boolean equals(Object obj) { if (!(obj instanceof Struct)) { return false; } if (obj == this) { return true; } Struct other = (Struct) obj; try { if (!typeName.equals(other.getSQLTypeName()) || attributes.length != other.getAttributes().length) { return false; } List otherAttributes = Arrays.asList(other.getAttributes()); return otherAttributes.containsAll(Arrays.asList(attributes)); } catch (SQLException e) { return false; } } }