Back to project page android-mvc-framework.
The source code is released under:
Apache License
If you think the Android project android-mvc-framework listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.android_mvc.framework.db.dao; //w w w . j a v a 2s . c o m import java.util.ArrayList; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import com.android_mvc.framework.common.FWUtil; import com.android_mvc.framework.db.DBHelper; import com.android_mvc.framework.db.entity.BaseLogicalEntity; /** * SELECT???????????????????????????????? * @author id:language_and_engineering * */ public class Finder<T extends BaseLogicalEntity<T>> { // NOTE: ??????Rails3???Arel????????????????????????????? private DBHelper helper; // SELECT?????????? private String selection; private String orderDescription; public Finder(DBHelper helper) { this.helper = helper; } /** * WHERE??????? */ public Finder<T> where( String selection ) { this.selection = selection; return this; } /** * ORDER BY??????? */ public Finder<T> orderBy(String orderDescription) { this.orderDescription = orderDescription; return this; } /** * ???????????????????????????????? */ public ArrayList<T> findAll( Class<T> entity_class ) { // NOTE: ???????T??????????????????????????????????????????????????????????? // ????????Java?????????????????????????new????????????????? // ?????????????????????????????????????????????????????????????????????????????? // http://www.ne.jp/asahi/hishidama/home/tech/java/generics.html#h3_new // http://blog.isocchi.com/2009/02/new.html ArrayList<T> result_list = new ArrayList<T>(); FWUtil.d("DB?????????????????"); SQLiteDatabase db = helper.getReadableDatabase(); try{ // NOTE: ????????????????????????????????????????????? // Class<T>????????????????T???new???????????????????????????? // table???????????????static??????????????????????????????????????????????????? T dummy_entity = entity_class.newInstance(); FWUtil.d("????????????????"); Cursor c = db.query( dummy_entity.tableName(), dummy_entity.columns(), selection, null, null, null, orderDescription ); FWUtil.d("????????????????????????"); while( c.moveToNext() ) { // ????????????????????????????????? T entity = entity_class.newInstance().logicalFromPhysical(c); // ????????? result_list.add(entity); } FWUtil.d("??????????????????????????"); c.close(); } catch (InstantiationException e) { FWUtil.e( e.toString() ); } catch (IllegalAccessException e) { FWUtil.e( e.toString() ); } finally { db.close(); } FWUtil.d("?????????????" + result_list.size() ); return result_list; } }