
com.j256.ormlite.android.apptools.OrmLitePreparedQueryLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ormlite-android Show documentation
Show all versions of ormlite-android Show documentation
Lightweight Object Relational Model (ORM) Android classes
The newest version!
package com.j256.ormlite.android.apptools;
import java.sql.SQLException;
import java.util.Collections;
import java.util.List;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.PreparedQuery;
import android.content.Context;
import android.content.Loader;
/**
* A {@link Loader} implementation that queries specified {@link Dao} using a {@link PreparedQuery}.
*
* @author Egorand
*/
public class OrmLitePreparedQueryLoader extends BaseOrmLiteLoader {
private PreparedQuery preparedQuery;
public OrmLitePreparedQueryLoader(Context context) {
super(context);
}
public OrmLitePreparedQueryLoader(Context context, Dao dao, PreparedQuery preparedQuery) {
super(context, dao);
this.preparedQuery = preparedQuery;
}
@Override
public List loadInBackground() {
if (dao == null) {
throw new IllegalStateException("Dao is not initialized.");
}
if (preparedQuery == null) {
throw new IllegalStateException("PreparedQuery is not initialized.");
}
try {
return dao.query(preparedQuery);
} catch (SQLException e) {
// XXX: is this really the right thing to do? Maybe throw RuntimeException?
e.printStackTrace();
return Collections.emptyList();
}
}
public void setPreparedQuery(PreparedQuery preparedQuery) {
this.preparedQuery = preparedQuery;
}
public PreparedQuery getPreparedQuery() {
return preparedQuery;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy