public void listAll ( final String orderBy , final SuccessCallback < List < T > > successCallback , final ErrorCallback errorCallback ) { checkNotNull ( successCallback ) ; checkNotNull ( errorCallback ) ; final Callable < List < T > > call = new Callable < List < T > > ( ) { @ Override public List < T > call ( ) throws Exception { return SugarRecord . listAll ( getSugarClass ( ) , orderBy ) ; } } ; final Future < List < T > > future = doInBackground ( call ) ; List < T > objects ; try { objects = future . get ( ) ; if ( null == objects || objects . isEmpty ( ) ) { errorCallback . onError ( new Exception ( "There are no objects in the database" ) ) ; } else { successCallback . onSuccess ( objects ) ; } } catch ( Exception e ) { errorCallback . onError ( e ) ; } }
Method that list all elements . It run a SugarRecord . listAll but it s code is performed asynchronously with the usage of Futures and callbacks .