All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.ebeaninternal.server.query.DtoQueryIterator Maven / Gradle / Ivy

There is a newer version: 15.8.1
Show newest version
package io.ebeaninternal.server.query;

import io.ebean.QueryIterator;
import io.ebeaninternal.server.core.DtoQueryRequest;

import javax.persistence.PersistenceException;
import java.sql.SQLException;

final class DtoQueryIterator implements QueryIterator {

  private final DtoQueryRequest request;
  private boolean closed;

  DtoQueryIterator(DtoQueryRequest request) {
    this.request = request;
  }

  @Override
  public boolean hasNext() {
    boolean result = false;
    try {
      result = request.next();
      return result;
    } catch (SQLException e) {
      throw new PersistenceException(e);
    } finally {
      if (!result) {
        close();
      }
    }
  }

  @Override
  public T next() {
    try {
      return request.readNextBean();
    } catch (SQLException e) {
      throw new PersistenceException(e);
    }
  }

  @Override
  public void close() {
    if (!closed) {
      closed = true;
      request.close();
      request.endTransIfRequired();
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy