Tag: ormlite

RoboSpice使用OrmLite保留JSON数组

我正在使用RoboSpice和Spring for Android,并希望使用OrmLite来保存JSON对象数组。 GSON用于JSON编组。 使用默认缓存,一切都按预期工作。 但OrmLite似乎不喜欢对象数组。 这是JSON的简化版本: [{“id”: 1, “title”: “Test 1”},{“id”: 2, “title”: “Test 3”},{“id”: 3, “title”: “Test 3”}] 我想在以下对象中坚持这个: @DatabaseTable public class Foo { @DatabaseField(id = true) private int id; @DatabaseField private String title; // getters and setters … } 基于RoboSpice OrmLite示例,我创建了以下GsonSpringAndroidSpiceService类来添加OrmLite CacheManager。 这是问题开始的地方。 public class CustomGsonSpringAndroidSpiceService extends GsonSpringAndroidSpiceService { @Override public CacheManager […]

有没有办法使用OrmLite与Postgres hstores?

我们目前正在使用PostgreSQL数据库和OrmLite。 我们现在有一个使用Postgres hstore的用例,但是找不到通过OrmLite访问该表的任何方法。 我宁愿避免打开一个单独的数据库连接只是为了选择并插入到那一个表,但我没有看到任何其他选项。 至少我想要一个OrmLite正在使用的现有连接的句柄,所以我可以重用它来构建一个准备好的语句,但我还没有找到一种从OrmLite ConnectionSource开始获取java.sql.Connection的方法. 我看到OrmLite有一个JdbcCompiledStatement ,但这只是PreparedStatement的包装器,需要将PreparedStatement传递给构造函数。 (不确定用例是什么。) 我尝试使用DatabaseConnection.compileStatement(…) ,但这需要了解正在使用的字段类型,OrmLite似乎不知道hstore是什么。 我曾尝试使用updateRaw() ,但该函数仅存在于我没有的OrmLite dao上,因为我将链接dao的表具有OrmLite无法识别的字段类型。 有没有办法让genericsdao发出原始查询? 我认为hstore是特定于数据库的,OrmLite可能不会支持,但我真的想找到一种方法,使用不受支持的字段而不仅仅是不支持的查询,将数据传入和传出数据库。

ORMLite中的多个组合OR条件

我喜欢这样的查询: select data from table where (x > 1 and x 250 and x < 300) 在ORMlite中,可以使用此代码: final QueryBuilder qb = queryBuilder(); final Where w = qb.where(); w.or( w.gt(“x”, 1).and().lt(“x”, 100), w.gt(“x”, 250).and().lt(“x”, 300) ) 虽然如果事先知道条件并且在编码时这很好,我需要动态添加条件。 基本上该方法是public com.j256.ormlite.stmt.Where or(com.j256.ormlite.stmt.Where left, com.j256.ormlite.stmt.Where right, com.j256.ormlite.stmt.Where… others)是不够的。 它需要另一个or方法来支持Where条件的ArrayList 。 谢谢你的任何建议。