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

com.j256.ormlite.dao.CloseableWrappedIterableImpl Maven / Gradle / Ivy

Go to download

Lightweight Object Relational Model (ORM) for persisting objects to SQL databases.

There is a newer version: 6.1
Show newest version
package com.j256.ormlite.dao;

import java.io.IOException;

import com.j256.ormlite.misc.IOUtils;

/**
 * Class which is used to help folks use for loops but still close at the end. This is a wrapper to allow multiple
 * threads to iterate across the same dao or the same lazy collection at the same time. See
 * {@link Dao#getWrappedIterable()} or {@link ForeignCollection#getWrappedIterable()}.
 * 
 * @author graywatson
 */
public class CloseableWrappedIterableImpl implements CloseableWrappedIterable {

	private final CloseableIterable iterable;
	private CloseableIterator iterator;

	public CloseableWrappedIterableImpl(CloseableIterable iterable) {
		this.iterable = iterable;
	}

	@Override
	public CloseableIterator iterator() {
		return closeableIterator();
	}

	@Override
	public CloseableIterator closeableIterator() {
		IOUtils.closeQuietly(this);
		iterator = iterable.closeableIterator();
		return iterator;
	}

	@Override
	public void close() throws IOException {
		if (iterator != null) {
			iterator.close();
			iterator = null;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy