I am trying to retrieve a Cursor from a ORMLite PreparedQuery. My goal is to only paginate my results query, so the device memory won't be too overloaded. I've read Gray's guides on how to use the QueryBuilder object Android Cursor with ORMLite to use in CursorAdapter. Also this one ORMLite with CursorAdapter in Android. But when I try to do: "iterator.getRawResults();" well, the iterator class don't recognize the getRawResults method. It just supports the common methods close(), getEquals(), next(), and so on...
I can retrieve e list of objects successfully from my query, so it isn't a empty query problem...
am I missing something ? My pom.xml is attached.
Here is the test with a list of Objects
public List<Produto> getProdutoDecricao2(String padrao) throws SQLException {
List<Produto> listaProduto = null;
QueryBuilder<Produto, String> queryBuilder = produtoDao.queryBuilder();
Where<Produto, String> where = queryBuilder.where();
SelectArg selectArg = new SelectArg();
selectArg.setValue('%'+padrao+'%');
where.like("descricao", selectArg);
PreparedQuery<Produto> preparedQuery = queryBuilder.prepare();
listaProduto = produtoDao.query(preparedQuery);
return listaProduto;
}
My failed attempt with Cursors...
//creation of DAO
private Dao<Produto,String> produtoDao;
public Cursor getProdutoDecricao(String padrao) {
List<Produto> listaProduto = null;
QueryBuilder<Produto, String> queryBuilder = produtoDao.queryBuilder();
Where<Produto, String> where = queryBuilder.where();
SelectArg selectArg = new SelectArg();
selectArg.setValue('%'+padrao+'%');
where.like("descricao", selectArg);
// when you are done, prepare your query and build an iterator
PreparedQuery<Produto> preparedQuery = queryBuilder.prepare();
CloseableIterator<Produto> iterator = produtoDao.iterator(preparedQuery);
AndroidDatabaseResults results = (AndroidDatabaseResults)iterator.getRawResults();
Cursor cursor = results.getRawCursor();
iterator.close();
return cursor;
}
Here is the project pom.xml
<properties>
<android-platform>8</android-platform>
<android-maven-plugin-version>3.4.0</android-maven-plugin-version>
<maven-compiler-plugin-version>2.3.2</maven-compiler-plugin-version>
<java-version>1.6</java-version>
<maven-eclipse-plugin-version>2.8</maven-eclipse-plugin-version>
<org.codehaus.jackson-version>1.9.7</org.codehaus.jackson-version>
</properties>
<repositories>
<repository>
<id>org.springframework.maven.snapshot</id>
<name>Spring Maven Snapshot Repository</name>
<url>http://maven.springframework.org/snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository> <!-- For developing against latest Spring milestones -->
<repository>
<id>org.springframework.maven.milestone</id>
<name>Spring Maven Milestone Repository</name>
<url>http://maven.springframework.org/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<build>
<finalName>${project.artifactId}</finalName>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>${android-maven-plugin-version}</version>
<configuration>
<sdk>
<platform>${android-platform}</platform>
<path>/Users/rav/Documents/Android/android-sdk-macosx</path>
</sdk>
<emulator>
<avd>Android4.1</avd>
</emulator>
<deleteConflictingFiles>true</deleteConflictingFiles>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin-version}</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>${maven-eclipse-plugin-version}</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<versionRange>[3.1.1,)</versionRange>
<goals>
<goal>proguard</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>2.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.android</groupId>
<artifactId>spring-android-rest-template</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.j256.ormlite</groupId>
<artifactId>ormlite-android</artifactId>
<version>4.9</version>
</dependency>
<dependency>
<groupId>com.j256.ormlite</groupId>
<artifactId>ormlite-android</artifactId>
<version>4.9</version>
<exclusions>
<exclusion>
<groupId>com.j256.ormlite</groupId>
<artifactId>ormlite-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.roboguice</groupId>
<artifactId>roboguice</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>1.3.9</version>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>r6</version>
</dependency>
<dependency>
<groupId>jgilfelt.android-viewbadger</groupId>
<artifactId>android-viewbadger</artifactId>
<version>1</version>
</dependency>
<dependency>
<!-- Using Jackson for JSON marshaling -->
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${org.codehaus.jackson-version}</version>
</dependency>
</dependencies>
**EDIT Well, first i was using version 4.9 of ORMLite with isn't really official, and didn't have the methods I wanted to use. After I changed my pom.xml to use android-4.42 and core-4.42 Maven didn't let me compile the program, giving the Dalvik error (“Conversion to Dalvik format failed with error 1”) despite of my attempts to solve this problem, I couldn't.
I created a new project in a new workspace without Maven and added the libs manually, now everything works fine. It seems to be a Maven problem. I hope it helps someone.**