本文整理汇总了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;
}
}