Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pojo class creation from Sqlite cursor is taking too much time

My query is taking < 3 milli sec to execute. But the problem is, I am creating a pojo class objects from the cursor I got from query execution. This object creation and setting values to fields is taking too much time more than 140 milli sec. Pojo class has around 36 fields. Any suggestion to solve this problem.?

Thanks

like image 952
ImGenie Avatar asked Nov 20 '22 08:11

ImGenie


1 Answers

I know that the c.getColumnIndex() method takes more time. The best method that I know to speed up the things is the following:

Cursor c = null;
try {
    c = db.query(......);
    if(c != null) {

        int channelIdIndex = c.getColumnIndex(OptimizedMessage.CHANNEL_ID);
        int clientIdIndex = c.getColumnIndex(OptimizedMessage.CLIENT_ID);

        while (c.moveToNext()) {
            OptimizedMessage newMessage = new OptimizedMessage();
            newMessage.setChannelId(c.getLong(channelIdIndex));
            newMessage.setClientId(c.getLong(clientIdIndex));

            messages.add(newMessage);
        }
    }
} finally {
    if (c != null) {
        c.close();
    }
}

You can see that the c.getColumnIndex() method is used only once.

like image 88
Blehi Avatar answered Dec 06 '22 16:12

Blehi