本文整理匯總了Java中com.j256.ormlite.dao.Dao.queryForId方法的典型用法代碼示例。如果您正苦於以下問題:Java Dao.queryForId方法的具體用法?Java Dao.queryForId怎麽用?Java Dao.queryForId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.j256.ormlite.dao.Dao
的用法示例。
在下文中一共展示了Dao.queryForId方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testJsonMapper
import com.j256.ormlite.dao.Dao; //導入方法依賴的package包/類
public void testJsonMapper() throws Exception
{
DatabaseHelper helper = DatabaseHelper.getHelper(getContext());
// Load JSON
JSONObject json = JsonLoader.loadObject(getContext(), poetry.test.R.raw.test);
// Get child arrays from JSON
JSONArray users_json = JsonPathResolver.resolveArray(json, "users");
JSONArray groups_json = JsonPathResolver.resolveArray(json, "groups");
// Persist arrays to database
JsonPersister persister = new JsonPersister(helper.getWritableDatabase());
persister.persistArray(User.class, users_json);
persister.persistArray(Group.class, groups_json);
Dao<User, Integer> user_dao = helper.getDao(User.class);
Dao<Group, Integer> group_dao = helper.getDao(Group.class);
List<User> users = user_dao.queryForAll();
assertEquals(2, users.size());
List<Group> groups = group_dao.queryForAll();
assertEquals(3, groups.size());
User user = user_dao.queryForId(1);
assertNotNull(user);
assertEquals("John", user.getName());
assertEquals(2, user.getTags().size());
assertEquals("tag2", user.getTags().get(1));
Group group = group_dao.queryForId(2);
assertNotNull(group);
assertEquals("Group B", group.getName());
DatabaseHelper.releaseHelper();
}
示例2: find
import com.j256.ormlite.dao.Dao; //導入方法依賴的package包/類
@Override
public <T> T find(Class<T> entityClass, Object primaryKey) {
Dao dao = getDao(entityClass);
try {
return (T) dao.queryForId(primaryKey);
} catch (SQLException e) {
throw new IllegalArgumentException(e);
}
}
示例3: getById
import com.j256.ormlite.dao.Dao; //導入方法依賴的package包/類
protected T getById(Long id, Class<T> type)
{
try
{
Dao<T, Long> dao = database.getDao(type);
T entity = dao.queryForId(id);
PFALogger.debug(getClass().getName(), GET_BY_ID, SUCCESSFUL);
return entity;
}
catch ( SQLException e )
{
PFALogger.error(getClass().getName(), GET_BY_ID + ID + id, e);
return null;
}
}