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

org.droitateddb.DbClosingCursor Maven / Gradle / Ivy

Go to download

droitatedDB is a lightweight framework, which frees you from the burden of dealing with Androids SQLite database directly if you don't want to and let's you access it directly if you have to.

The newest version!
package org.droitateddb;

import android.database.Cursor;
import android.database.CursorWrapper;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * A cursor also handling the reduction of open database connections when closed. It should be used e.g. in combination with CursorAdapter.
 *
 * @author Falk Appel
 * @author Alexander Frank
 */
class DbClosingCursor extends CursorWrapper {

	private final DbCreator dbCreator;
	private AtomicBoolean closed = new AtomicBoolean(false);

	public DbClosingCursor(Cursor cursor, DbCreator dbCreator) {
		super(cursor);
		this.dbCreator = dbCreator;
	}

	@Override
	public void close() {
		super.close();
		if (closed.compareAndSet(false, true)) {
			dbCreator.reduceDatabaseConnection();
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy