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

com.j256.ormlite.android.apptools.OrmLiteQueryForAllLoader Maven / Gradle / Ivy

package com.j256.ormlite.android.apptools;

import java.sql.SQLException;
import java.util.Collections;
import java.util.List;

import android.content.Context;

import com.j256.ormlite.dao.Dao;

/**
 * A Loader implementation that queries specified {@link com.j256.ormlite.dao.Dao} for all data, using the
 * Dao.queryForAll() call.
 * 
 * @author EgorAnd
 */
public class OrmLiteQueryForAllLoader extends BaseOrmLiteLoader {

	public OrmLiteQueryForAllLoader(Context context) {
		super(context);
	}

	public OrmLiteQueryForAllLoader(Context context, Dao dao) {
		super(context, dao);
	}

	@Override
	public List loadInBackground() {
		if (dao == null) {
			throw new IllegalStateException("Dao is not initialized.");
		}
		try {
			return dao.queryForAll();
		} catch (SQLException e) {
			// XXX: is this really the right thing to do? Maybe throw RuntimeException?
			e.printStackTrace();
			return Collections.emptyList();
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy