It's not as much beautiful as I liked, but it works.
Is there anyway to use AG implementation to read the cursor with all fields
and retrieve the object? I've used "read" to do the magic, but I didn't
like it.
public Collection<T> readSorted(EnumSort enumSort) {
String tableName = getTableName();
String fieldName = getIdFieldName();
String sql = "SELECT %s FROM %s ORDER BY %s %s";
if (enumSort == EnumSort.ASCENDING) {
sql = String.format(sql, fieldName, tableName, fieldName,
"ASC");
} else {
sql = String.format(sql, fieldName, tableName, fieldName,
"DESC");
}
Collection<T> collection = new ArrayList<T>();
SQLiteDatabase database = this.getReadableDatabase();
Cursor cursor = database.rawQuery(sql, new String[]{});
for (cursor.moveToFirst(); !cursor.isAfterLast();
cursor.moveToNext()) {
collection.add(this.read(cursor.getInt(0)));
}
return collection;
}
2014-03-17 18:54 GMT-03:00 Tiago Resende <tiagor87(a)gmail.com>:
The "order by" problem I solved implementing an extension
for AG Store.
2014-03-17 18:45 GMT-03:00 Tiago Resende <tiagor87(a)gmail.com>:
The AeroGear isn't reading the last Id saved in database, so, it starts
> over and over again, overwriting my old data every time a open my
> application.
>
>
> 2014-03-17 18:11 GMT-03:00 Daniel Passos <daniel(a)passos.me>:
>
>> Hi Thiago,
>>
>> Nice questions. Answers inline.
>>
>> On Sun, Mar 16, 2014 at 6:20 PM, Tiago Resende <tiagor87(a)gmail.com>wrote:
>>
>>> Hi guys, thanks for the other day, you really helped me.
>>>
>>> I have two questions today.
>>>
>>> How can I perform a query using "order by" statement in SQLStore?
>>>
>>> I did a readAll, then I ordered in memory using Ordering<T>.
>>>
>>
>> Unfortunately. We don't have this option for now.
>>
>>
>>> The second question is how can I indicate to AeroGear that it should
>>> use an auto increment primary key for a table. I created an AutoGeneratorId
>>> Class, but it's not working beautifully for SQLStore. I had to create an
>>> update method and call it for every object, I didn't like it, but I
>>> couldn't find a better solution reading the documentation.
>>>
>>
>> No, who creates the id is always idGenerator. What's the problem?
>>
>>
>>> I really appreciate your help.
>>>
>>> Thanks.
>>>
>>> --
>>> *Tiago de Carvalho Resende*
>>>
>>
>> _______________________________________________
>> aerogear-dev mailing list
>> aerogear-dev(a)lists.jboss.org
>>
https://lists.jboss.org/mailman/listinfo/aerogear-dev
>>
>
>
>
> --
> *Tiago de Carvalho Resende*
> Desenvolvedor
>
> "O importante não é saber fazer,
>
> é saber de onde copiar."
>
> por Bernardo Esbérard
>
>
>
--
*Tiago de Carvalho Resende*
Desenvolvedor
"O importante não é saber fazer,
é saber de onde copiar."
por Bernardo Esbérard
--
*Tiago de Carvalho Resende*
Desenvolvedor
"O importante não é saber fazer,
é saber de onde copiar."
por Bernardo Esbérard