ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/result/ResultRemote.java

Path
ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/result/ResultRemote.java
Status
scanned
Type
file
Name
ResultRemote.java
Extension
.java
Programming language
Java
Mime type
text/x-java
File type
Java source, ASCII text
Tag

      
    
Rootfs path

      
    
Size
7995 (7.8 KB)
MD5
448ac138c6507239e3f536fc4a7df560
SHA1
f8a7820836979fde608c07d274626165527e73b9
SHA256
001429cb2b99bd428fad7f3b252eef785f789e47d5dcc69f1f18121a7d0a86fb
SHA512

      
    
SHA1_git
7c4d92fd4d54402bbbc20f2d32b9e25054c8f224
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
ResultRemote.java | 7.8 KB |

/* * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (https://h2database.com/html/license.html). * Initial Developer: H2 Group */ package org.h2.result; import java.io.IOException; import java.util.ArrayList; import org.h2.api.ErrorCode; import org.h2.engine.SessionRemote; import org.h2.engine.SysProperties; import org.h2.message.DbException; import org.h2.message.Trace; import org.h2.value.Transfer; import org.h2.value.TypeInfo; import org.h2.value.Value; /** * The client side part of a result set that is kept on the server. * In many cases, the complete data is kept on the client side, * but for large results only a subset is in-memory. */ public final class ResultRemote extends FetchedResult { private int fetchSize; private SessionRemote session; private Transfer transfer; private int id; private final ResultColumn[] columns; private long rowCount; private long rowOffset; private ArrayList<Value[]> result; private final Trace trace; public ResultRemote(SessionRemote session, Transfer transfer, int id, int columnCount, int fetchSize) throws IOException { this.session = session; trace = session.getTrace(); this.transfer = transfer; this.id = id; this.columns = new ResultColumn[columnCount]; rowCount = transfer.readRowCount(); for (int i = 0; i < columnCount; i++) { columns[i] = new ResultColumn(transfer); } rowId = -1; this.fetchSize = fetchSize; if (rowCount >= 0) { fetchSize = (int) Math.min(rowCount, fetchSize); result = new ArrayList<>(fetchSize); } else { result = new ArrayList<>(); } synchronized (session) { try { if (fetchRows(fetchSize)) { rowCount = result.size(); } } catch (IOException e) { throw DbException.convertIOException(e, null); } } } @Override public boolean isLazy() { return rowCount < 0L; } @Override public String getAlias(int i) { return columns[i].alias; } @Override public String getSchemaName(int i) { return columns[i].schemaName; } @Override public String getTableName(int i) { return columns[i].tableName; } @Override public String getColumnName(int i) { return columns[i].columnName; } @Override public TypeInfo getColumnType(int i) { return columns[i].columnType; } @Override public boolean isIdentity(int i) { return columns[i].identity; } @Override public int getNullable(int i) { return columns[i].nullable; } @Override public void reset() { if (rowCount < 0L || rowOffset > 0L) { throw DbException.get(ErrorCode.RESULT_SET_NOT_SCROLLABLE); } rowId = -1; currentRow = null; nextRow = null; afterLast = false; if (session == null) { return; } synchronized (session) { session.checkClosed(); try { session.traceOperation("RESULT_RESET", id); transfer.writeInt(SessionRemote.RESULT_RESET).writeInt(id).flush(); } catch (IOException e) { throw DbException.convertIOException(e, null); } } } @Override public int getVisibleColumnCount() { return columns.length; } @Override public long getRowCount() { if (rowCount < 0L) { throw DbException.getUnsupportedException("Row count is unknown for lazy result."); } return rowCount; } @Override public boolean hasNext() { if (afterLast) { return false; } if (nextRow == null) { if (rowCount < 0L || rowId < rowCount - 1) { long nextRowId = rowId + 1; if (session != null) { remapIfOld(); if (nextRowId - rowOffset >= result.size()) { fetchAdditionalRows(); } } int index = (int) (nextRowId - rowOffset); nextRow = index < result.size() ? result.get(index) : null; } } return nextRow != null; } private void sendClose() { if (session == null) { return; } // TODO result sets: no reset possible for larger remote result sets try { synchronized (session) { session.traceOperation("RESULT_CLOSE", id); transfer.writeInt(SessionRemote.RESULT_CLOSE).writeInt(id); } } catch (IOException e) { trace.error(e, "close"); } finally { transfer = null; session = null; } } @Override public void close() { result = null; sendClose(); } private void remapIfOld() { try { if (id <= session.getCurrentId() - SysProperties.SERVER_CACHED_OBJECTS / 2) { // object is too old - we need to map it to a new id int newId = session.getNextId(); session.traceOperation("CHANGE_ID", id); transfer.writeInt(SessionRemote.CHANGE_ID).writeInt(id).writeInt(newId); id = newId; // TODO remote result set: very old result sets may be // already removed on the server (theoretically) - how to // solve this? } } catch (IOException e) { throw DbException.convertIOException(e, null); } } private void fetchAdditionalRows() { synchronized (session) { session.checkClosed(); try { rowOffset += result.size(); result.clear(); int fetch = fetchSize; if (rowCount >= 0) { fetch = (int) Math.min(fetch, rowCount - rowOffset); } else if (fetch == Integer.MAX_VALUE) { fetch = SysProperties.SERVER_RESULT_SET_FETCH_SIZE; } session.traceOperation("RESULT_FETCH_ROWS", id); transfer.writeInt(SessionRemote.RESULT_FETCH_ROWS).writeInt(id).writeInt(fetch); session.done(transfer); fetchRows(fetch); } catch (IOException e) { throw DbException.convertIOException(e, null); } } } private boolean fetchRows(int fetch) throws IOException { int len = columns.length; for (int r = 0; r < fetch; r++) { switch (transfer.readByte()) { case 1: { Value[] values = new Value[len]; for (int i = 0; i < len; i++) { values[i] = transfer.readValue(columns[i].columnType); } result.add(values); break; } case 0: sendClose(); return true; case -1: throw SessionRemote.readException(transfer); default: throw DbException.getInternalError(); } } if (rowCount >= 0L && rowOffset + result.size() >= rowCount) { sendClose(); } return false; } @Override public String toString() { return "columns: " + columns.length + (rowCount < 0L ? " lazy" : " rows: " + rowCount) + " pos: " + rowId; } @Override public int getFetchSize() { return fetchSize; } @Override public void setFetchSize(int fetchSize) { this.fetchSize = fetchSize; } @Override public boolean isClosed() { return result == null; } }
Detected license expression
mpl-2.0 AND epl-1.0
Detected license expression (SPDX)
MPL-2.0 AND EPL-1.0
Percentage of license text
1.24
Copyrights
- end_line: 2
  copyright: Copyright 2004-2023 H2 Group. Multiple-Licensed
  start_line: 2
Holders
- holder: H2 Group. Multiple-Licensed
  end_line: 2
  start_line: 2
Authors

      
    
License detections License expression License expression SPDX
mpl_2_0_and_epl_1_0-796bf8d7-f485-3520-923d-e6a4b1ecd2f3 mpl-2.0 AND epl-1.0 MPL-2.0 AND EPL-1.0
URL Start line End line
https://h2database.com/html/license.html 3 3
Package URL License Primary language
pkg:osgi/com.h2database.source@2.2.220