ormlite

Android中OrmLite持久化

删除回忆录丶 提交于 2019-12-05 20:49:02
http://ormlite.com/javadoc/ormlite-core/doc-files/ormlite_toc.html#SEC_Contents OrmLite提供了一些轻量级持久化Java对象到SQL数据库,同时也避免了复杂性和更多的标准的ORM包的开销功能。它支持的SQL数据库使用JDBC的数量,还支持原生的Android操作系统数据库API调用sqlite。首先我们要使用它呢,就要去它的官方http://ormlite.com下载你想要的版本,这里我下载了最新的4.30。接下来我们来写一个简单的项目,同时对它的使用方法进行一个详细的介绍。   建立好项目后呢,我们加入OrmLite的jar包,然后建立两个实体类,我用的例子是客户和订单,一个客户对应多个订单这样的关系。   接着为这两个实体类添加属性和字段,需要注意的是,一定要有一个无参的构造函数,OrmLite创建对象时需要使用。   Account: int aId,String aName;Order:int oid,String oName,Account account。   接着就到了添加ORMLite注解了。注解是特殊的代码标志已在Java版本开始,要指定什么类和字段存储在数据库中,ORMLite支持其自己的注解(@ DatabaseTable @ DatabaseField

ORMLite Issue with inserting tables from one database to another database on Android

点点圈 提交于 2019-12-05 18:11:48
I'm downloading an SQLite database file from a server to the Android device of the user. After the download, I insert or replace some tables in the local database using the downloaded database. I use ORMLite 4.47 for this. First I attach the database files to the DatabaseConnection: DatabaseConnection con = null; con = conSrc.getReadWriteConnection(); con.executeStatement("attach database '" + localDatabase.getAbsolutePath() + "' as '" + localDb + "'", DatabaseConnection.DEFAULT_RESULT_FLAGS); con.executeStatement("attach database '" + downloadedDatabase.getAbsolutePath() + "' as '" + remoteDb

Robospice storing object that extends ArrayList in database via Ormlite

∥☆過路亽.° 提交于 2019-12-05 14:53:34
Background I have been trying to modify the Robospice Ormlite example code , which I have been successful to run. The only changes I have made is that I have a JSON response that contains an array of objects. I created 2 classes: public class Foos extends ArrayList<Foo> public class Foo I had initial problems, as my JSON response is a pure array with no outer container. I read via google groups that the way to solve this is to create a "fake" class (Foos) that extends an ArrayList. This produced the following code: public class FooRequest extends SpringAndroidSpiceRequest< Foos > { private

Create table with Foreign Collection Field

 ̄綄美尐妖づ 提交于 2019-12-05 14:24:05
问题 I have this abstract class: DomainItem abstract public class DomainItem { @DatabaseField(generatedId = true) protected long id; @ForeignCollectionField(eager = false) protected ForeignCollection<ContentItem> contentItens; //getters and setters } ContentItem: abstract public class ContentItem { @DatabaseField(generatedId = true) protected long id; @DatabaseField(foreign = true) protected DomainItem domainItem; @DatabaseField() protected String content; //getters and setters } And these (no

(Gradle and OrmLite config) How to add resource file after Java has been compiled but before .apk is generated?

十年热恋 提交于 2019-12-05 13:27:46
NOTE: I have already accepted an answer and awarded the bounty, BUT, have in the end decided that my approach to this issue was far from optimal. After further thought I have come to the conclusion that modifying the .apk during the build process is probably not the safest or most sustainable way to accomplish this and keep it working long term. I have added an alternative approach to the very bottom of this question, which accomplishes the same thing in the end. This approach I opted to use instead, while not perfect, does not require messing around with the internals of the .apk assembly

Releasing ORMLite helper on @Singleton

守給你的承諾、 提交于 2019-12-05 13:22:43
I have a @Singleton class where I've injected an instance of OrmLiteSqliteOpenHelper . Do I actually ever need to call the OpenHelperManager.releaseHelper() ? In case I do, where and how should it be done as the class doesn't extend any Android base class where I could get to the onDestroy ? There is an ORMLite example Android project which demonstrates this called HelloAndroidNoBase . I'd check it out. The relevant code section from the main Activity is included below. You'll need to have this sort of code in each one of your Activity or other classes that uses the database. If your class

How to use the ORMLite query builder to get the total records in a table

纵饮孤独 提交于 2019-12-05 09:33:45
问题 Similar to select count(*) from tablename; what should be query in ORMLITE i tried something like int total = dao.queryBuilder().("select count(*)"); 回答1: How to use the ORMLite query builder to get the total records in a table ORMLite has a Dao.countOf() method that returns the total number of rows in a table: long numRows = dao.countOf(); You can also count the number of rows in a custom query by calling the countOf() method on the Where or QueryBuilder object. // count the number of lines

Case insensitive order by with ormlite and sqlite in android

雨燕双飞 提交于 2019-12-05 08:09:00
I want to order my data objects from an ORMLite DAO case insensitively. Currently I am using the following sqlite code to order my owner items case sensitively: ownerDao.queryBuilder().orderBy("Name", true).query(); I see here that sqlite supports case insensitive "order by" with the following raw SQL: SELECT * FROM owner ORDER BY Name COLLATE NOCASE Any easy way (easier than calling queryRaw() ) of adding the desired suffix? Could an alternative solution be to set the columnDefinition property on the DatabaseField annotation to TEXT COLLATE NOCASE ? Gray I think what you want is to use the

ORMLite select some columns using predicates

久未见 提交于 2019-12-05 06:41:02
问题 I have ORMLite database with some fields. I want to select titles from the table where id == id which I get from webservice. I do like that: try { Dao<ProcessStatus,Integer> dao = db.getStatusDao(); Log.i("status",dao.queryForAll().toString()); QueryBuilder<ProcessStatus,Integer> query = dao.queryBuilder(); Where where = query.where(); String a = null; for(Order r:LoginActivity.orders) { //LoginActivity.orders - array of my objects which I get from webservice Log.i("database",query.selectRaw(

Android OrmLite pre-populate database

那年仲夏 提交于 2019-12-05 05:51:23
Is it possible with OrmLite to create a sql script file to easily populate the database with data? I did some searching and couldn't come up with anything easy. I know I can create some objects with data, I'm just looking for a cleaner method. I'm thinking create a script file, open a a reader at load, and process each file as raw SQL the executeRaw() method. Any thoughts? Good one Joe. I think your idea of the executeRaw() is close but use updateRaw() instead. Update handles INSERT , DELETE , and UPDATE statements. http://ormlite.com/docs/raw-update You should call TableUtils to create your