Saturday, 15 August 2015

java - Why is it not possible to perform isNotNull on a column that has DataType.SERIALIZABLE in ormlite? -



java - Why is it not possible to perform isNotNull on a column that has DataType.SERIALIZABLE in ormlite? -

using ormlite 4.48 on android, consider next user table...

class="lang-java prettyprint-override">@databasetable(tablename = "users") public class user { @databasefield(columnname = column.uuid) protected string uuid; @databasefield(columnname = column.first_name) protected string firstname = null; @databasefield(columnname = column.last_name) protected string lastname = null; @databasefield(columnname = column.address, datatype = datatype.serializable) protected address address = null; // ... }

(address class represents human readable address, translated lat/lon)

... next query...

class="lang-java prettyprint-override">list<user> users = getdbhelper().getdao(user.class) .querybuilder() .where() .isnotnull(user.column.address) .query();

... throws exception:

java.sql.sqlexception: field 'address' of info type com.j256.ormlite.field.types.serializabletype@42ac7650 can not compared @ com.j256.ormlite.stmt.query.basecomparison.<init>(basecomparison.java:27) @ com.j256.ormlite.stmt.query.isnotnull.<init>(isnotnull.java:19) @ com.j256.ormlite.stmt.where.isnotnull(where.java:315) ...

apparently, is not null clause can not used on field stored datatype.serializable.

digging through ormlite code, basecomparison constructor checks whether fieldtype comparable:

https://github.com/j256/ormlite-core/blob/master/src/main/java/com/j256/ormlite/stmt/query/basecomparison.java

class="lang-java prettyprint-override">protected basecomparison(string columnname, fieldtype fieldtype, object value, boolean iscomparison) throws sqlexception { if (iscomparison && fieldtype != null && !fieldtype.iscomparable()) { throw new sqlexception("field '" + columnname + "' of info type " + fieldtype.getdatapersister() + " can not compared"); } ... }

obviously, serializabletype.iscomparable() returns false:

https://github.com/j256/ormlite-core/blob/master/src/main/java/com/j256/ormlite/field/types/serializabletype.java

class="lang-java prettyprint-override">@override public boolean iscomparable() { homecoming false; }

so, clear me why exception thrown. why not possible where.isnull() or where.isnotnull()? sqlite restriction or did author of ormlite made decision?

java android ormlite

No comments:

Post a Comment