
com.hazelcast.sql.impl.client.SqlPage Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hazelcast.sql.impl.client;
import com.hazelcast.internal.serialization.InternalSerializationService;
import com.hazelcast.sql.SqlColumnType;
import com.hazelcast.sql.SqlRow;
import com.hazelcast.sql.impl.SqlRowImpl;
import javax.annotation.Nonnull;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
/**
* A finite set of rows returned to the client.
*/
public final class SqlPage {
private final List columnTypes;
private final DataHolder data;
private final boolean last;
private SqlPage(
List columnTypes,
DataHolder data,
boolean last
) {
this.columnTypes = columnTypes;
this.data = data;
this.last = last;
}
public static SqlPage fromRows(
List columnTypes,
List rows,
boolean last,
InternalSerializationService serializationService
) {
return new SqlPage(columnTypes, new RowsetDataHolder(rows, serializationService), last);
}
public static SqlPage fromColumns(List columnTypes, List> columns, boolean last) {
return new SqlPage(columnTypes, new ColumnarDataHolder(columns), last);
}
public int getRowCount() {
return data.getRowCount();
}
public int getColumnCount() {
return columnTypes.size();
}
public List getColumnTypes() {
return columnTypes;
}
public Object getColumnValueForClient(int columnIndex, int rowIndex) {
assert columnIndex < getColumnCount();
assert rowIndex < getRowCount();
return data.getColumnValueForClient(columnIndex, rowIndex);
}
public Iterable> getColumnValuesForServer(int columnIndex) {
assert columnIndex < getColumnCount();
SqlColumnType columnType = columnTypes.get(columnIndex);
return data.getColumnValuesForServer(columnIndex, columnType);
}
public boolean isLast() {
return last;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
SqlPage page = (SqlPage) o;
return last == page.last && columnTypes.equals(page.columnTypes) && data.equals(page.data);
}
@Override
public int hashCode() {
int result = columnTypes.hashCode();
result = 31 * result + data.hashCode();
result = 31 * result + (last ? 1 : 0);
return result;
}
private interface DataHolder {
int getRowCount();
Object getColumnValueForClient(int columnIndex, int rowIndex);
Iterable> getColumnValuesForServer(int columnIndex, SqlColumnType columnType);
}
private static final class RowsetDataHolder implements DataHolder {
private final List rows;
private final InternalSerializationService serializationService;
private RowsetDataHolder(List rows, InternalSerializationService serializationService) {
this.rows = rows;
this.serializationService = serializationService;
}
@Override
public int getRowCount() {
return rows.size();
}
@Override
public Object getColumnValueForClient(int columnIndex, int rowIndex) {
throw new UnsupportedOperationException("Should not be called.");
}
@Override
public Iterable
© 2015 - 2025 Weber Informatics LLC | Privacy Policy