de.greenrobot.dao.query.AbstractQuery Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of DaoCore Show documentation
Show all versions of DaoCore Show documentation
greenDAO is a light and fast ORM for Android
The newest version!
/*
* Copyright (C) 2011-2013 Markus Junginger, greenrobot (http://greenrobot.de)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.greenrobot.dao.query;
import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.DaoException;
import de.greenrobot.dao.InternalQueryDaoAccess;
/**
* A repeatable query returning entities.
*
* @author Markus
*
* @param
* The enitity class the query will return results for.
*/
// TODO support long, double, blob types directly
abstract class AbstractQuery {
protected final AbstractDao dao;
protected final InternalQueryDaoAccess daoAccess;
protected final String sql;
protected final String[] parameters;
protected final Thread ownerThread;
protected static String[] toStringArray(Object[] values) {
int length = values.length;
String[] strings = new String[length];
for (int i = 0; i < length; i++) {
Object object = values[i];
if (object != null) {
strings[i] = object.toString();
} else {
strings[i] = null;
}
}
return strings;
}
protected AbstractQuery(AbstractDao dao, String sql, String[] parameters) {
this.dao = dao;
this.daoAccess = new InternalQueryDaoAccess(dao);
this.sql = sql;
this.parameters = parameters;
ownerThread = Thread.currentThread();
}
// public void compile() {
// // TODO implement compile
// }
/**
* Sets the parameter (0 based) using the position in which it was added during building the query.
*/
public void setParameter(int index, Object parameter) {
checkThread();
if (parameter != null) {
parameters[index] = parameter.toString();
} else {
parameters[index] = null;
}
}
protected void checkThread() {
if (Thread.currentThread() != ownerThread) {
throw new DaoException(
"Method may be called only in owner thread, use forCurrentThread to get an instance for this thread");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy