2016-06-26 2 views
2

누구나 greenDAO에서 간단한 select * from table을 수행하고 엔티티에 배치하는 방법을 알고 있습니까? 나는 이것에 대한 연구를 해본 결과 어떤 간단한 예도 얻을 수 없다. 이것은 내가 지금까지 가지고있는 것입니다 :GreenDAO를 사용하여 모두 선택하는 방법은 무엇입니까?

public void storeAppTimeUsageData(AppTimeUsage stats) { 
    List<AppTimeUsage> items = new ArrayList<>(); 
    //appTimeUsageDao = DeviceInsightApp.getSession(this, true).getAppTimeUsageDao(); 
    try { 
     // master 
     appTimeUsageDao.insertOrReplace(stats); 
    //} catch (IOException e) { 
    } catch (Exception e) { 
     Log.e("Error", "Some exception occurred", e); 
     Log.e("APP_TAG", "STACKTRACE"); 
     Log.e("APP_TAG", Log.getStackTraceString(e)); 
    } 
    String sql = "SELECT * FROM APP_TIME_USAGE "; 
    Cursor c = appTimeUsageDao.getDatabase().rawQuery(sql, null); 
    int offset = 0; 
    int d ; 
    int cd ; 
    String e = ""; 
    while (c.moveToNext()) { 
     AppTimeUsage atu AppTimeUsage(
      c.getLong(0); 
      //long b = c.getInt(0); 
      d = c.getInt(2); 
      e = c.getString(3); 
      break; 
     ); 
     items.add(atu); 
    } 
} 

답변

4

GreenDAO는 이미이 작업을 수행 할 수있는 내장 된 방법을 제공합니다. 귀하의 경우 :

List<AppTimeUsage> items = appTimeUsageDao.loadAll(); 

APP_TIME_USAGE에서 모든 레코드를 선택하고 개체를 포함하는 List<AppTimeUsage>을 반환합니다.

관련 문제