标签: greendao

Android GreenDao - 仅删除特定实体的缓存对象

我在我的Android应用程序中使用GreenDao ORM.

如前所述在这里,人们可以使用

DaoSession.clear();
Run Code Online (Sandbox Code Playgroud)

为了清除会话的所有缓存对象.

我的问题是:如何清除特定实体(而不是全部)的缓存对象?我怎样才能做到这一点 ?

orm android greendao

7
推荐指数
1
解决办法
3417
查看次数

如何将多个greenDAO Tx操作组合成一个事务?

我的应用程序使用远程REST API并使用greenDao填充本地数据库.我有AsyncTask类的服务:

@Override
protected Void doInBackground(Void... params) {
    insert100RowsIntheFirstTable();
    insert100RowsIntheSecondTable();
}
Run Code Online (Sandbox Code Playgroud)

在每个insert-method中我都有insertOrReplaceInTx,我主要用它来提高性能.

如果任何方法无法检索数据,我需要放弃结果.它应该通过同一个交易来完成.

我不知道这是正确的包围我的镶嵌方法与要求mDaoSession.callInTx(callable),同时具有insertOrReplaceInTx方法里面.我对吗?

另外,如果引发异常,我如何放弃交易 - 是否通过greenDao自动完成?

android greendao

6
推荐指数
1
解决办法
3062
查看次数

使用greendao for android的多对多编译错误

问题解决了! - 我在底部添加了我的解决方案.

我认为这是一个相当简单的问题,但我似乎无法在文档中找到答案.

我正在尝试使用greendao为android建模多对多关系,但是在运行生成器项目后,我在主项目中遇到编译错误.

我的代码指定了关系和实体:

    Entity customer = schema.addEntity("Customer");
    customer.addIdProperty();
    customer.addStringProperty("firstName").notNull();
    customer.addStringProperty("lastName").notNull();
    customer.addDateProperty("birthDate");
    customer.addStringProperty("phoneNumber");
    customer.addStringProperty("address");
    customer.addStringProperty("email");


    // Product
    Entity product= schema.addEntity("Product");
    product.addIdProperty();
    product.addIntProperty("colour").notNull();
    product.addIntProperty("weight").notNull();

    // CustomerProduct
    Entity customerProduct = schema.addEntity("CustomerProduct");
    customerProduct.addIdProperty();

    Property customerId = customerProduct.addLongProperty("customerId").notNull().getProperty();
    customer.addToOne(customerProduct , customerId);
    ToMany customerProductToCustomers = customerProduct.addToMany(customer, customerId);
    customerProductToCustomers.setName("customers");        

    Property productId = customerProduct.addLongProperty("productId").notNull().getProperty();
    product.addToOne(customerProduct , productId);
    ToMany customerProductToProducts = customerProduct.addToMany(product, productId);
    customerProductToProducts.setName("products");  

    customerProduct.addStringProperty("something");
Run Code Online (Sandbox Code Playgroud)

错误:在Customer.java中:customerId无法解析为变量在Product.java中:productId无法解析为变量

请帮忙,谢谢.

编辑:

以下是来自Customer.java(自动生成)的问题代码的摘录:

/**To-one关系,在首次访问时解决.*/

public CustomerProduct getCustomerProduct() {
    if (customerProduct__resolvedKey == null || !customerProduct__resolvedKey.equals(customerId)) {
        if (daoSession == …
Run Code Online (Sandbox Code Playgroud)

orm android entities many-to-many greendao

6
推荐指数
1
解决办法
1505
查看次数

greendao字符串主键 - 如何使用

在greendao常见问题解答中,它说"从greenDAO开始,对String主键的支持有限." http://greendao-orm.com/documentation/technical-faq/

我找不到任何说明如何做到这一点.

我使用Guids作为服务器应用程序中的主键,并希望能够从Android设备远程生成新数据并将其上传回服务器.android设备上的数据库是sqlite,使用greenDAO生成POJO和数据访问层.当数据上传到服务器时,我使用Guids来避免主键冲突.我将Guids存储为字符串.

在greendao网站上有一些建议说我应该创建一个包含字符串的辅助字段并仍然使用greendao所支持的长主键,但这意味着当我从服务器导入数据时,我必须重新连接所有数据库关系对于痛苦的应用程序.如果可能的话,更愿意继续使用字符串主键.

谁能告诉我怎么做?

这是一些示例代码......

在我的生成器中(为清楚起见,我删除了大部分字段):

private static void addTables(Schema schema) 
{
    Entity unit = addUnit(schema);     
    Entity forSale = addForSale(schema);

    Property unitIntId = forSale.addLongProperty("unitIntId").getProperty();
    forSale.addToOne(unit, unitIntId);
}


private static Entity addForSale(Schema schema) 
{
    Entity thisEntity = schema.addEntity("ForSale");
    thisEntity.addIdProperty();
    thisEntity.addStringProperty("forSaleId");        
    thisEntity.addFloatProperty("currentPriceSqFt");        
    thisEntity.addStringProperty("unitId");
    return thisEntity;
}

private static Entity addUnit(Schema schema) 
{
    Entity thisEntity = schema.addEntity("Unit");
    thisEntity.addIdProperty();
    thisEntity.addStringProperty("unitId");
    thisEntity.addStringProperty("name");
    return thisEntity;
}
Run Code Online (Sandbox Code Playgroud)

在我的Android应用程序中,我从服务器下载所有数据.它具有基于GUID id的关系.我必须将这些重新连接到我在生成器中创建的int Id,如下所示:

            //Add relations based on GUID relations

            //ForSale:Units
            for(ForSale forSale:Globals.getInstance().forSales) 
            {
                if (forSale.getUnitId() != null && …
Run Code Online (Sandbox Code Playgroud)

orm android greendao

6
推荐指数
1
解决办法
5044
查看次数

如何使用GreenDao执行"从emp中选择不同的ename"

如何使用GreenDao执行"从emp中选择不同的ename"

我试图使用GreenDao获取sqlite数据库列的不同值.我该怎么做?任何帮助赞赏.

greendao

6
推荐指数
1
解决办法
6770
查看次数

Android中的DBFlow与GreenDao orm库

我将为一个应用程序选择一个DAO库,该应用程序在SQLite表中存储大量关系数据.

我首先选择GreenDao,因为它被积极地用于许多着名的应用程序,并且相当陈旧,经过良好测试并且修复了错误.

其中DBFlow使用注释处理(注释在编译时解析,因此编译时间将增加)并允许用户决定模型缓存,有时证明比GreenDao更快(仅在某些情况下).

但是DBFlow可能没有留下一些漏洞或者一些场景被发现,因为它没有被积极地用在像GreenDao这样的众多应用中.(抱歉!我有点假设).

"从性能到代码处理,数据库迁移和未来的模型更改,哪一个更好".

先看看: GreenDao的表现

DBFlow与DBFLow的比较

引导我.请.

sqlite android greendao

6
推荐指数
0
解决办法
2061
查看次数

使用LIKE查询无法使用GreenDAO

我有一个表,其中一列是一个包含三个字符的字符串,每个字符的值为0或1.我想根据情况选择这些行.

我想执行这样的查询:

SELECT * FROM Item WHERE group_type LIKE ?
Run Code Online (Sandbox Code Playgroud)

?可以是100或101或011或111或001.组合为0和1三个字符.

我正在尝试使用LIKE进行查询

WhereCondition where = null;
switch (condition) {
    case case1:
        where = ItemDao.Properties.GroupType.like("1%");
        break;
    case case2:
        where = ItemDao.Properties.GroupType.like("%1%");
        break;
    case case3:
        where = ItemDao.Properties.GroupType.like("%1");
        break;
}
List<Item> items = itemDao.queryBuilder().where(where).list();
Run Code Online (Sandbox Code Playgroud)

case1按预期返回以1开头的所有内容.case3按预期返回以1结尾的所有内容.case2正在归还一切!它不会在开始,中间或结束时满足价值.它正在归还一切.

case1和case3工作正常.但是,case2无法正常工作.这有什么问题吗?

sqlite android greendao

6
推荐指数
1
解决办法
386
查看次数

SQLiteFullException: 数据库或磁盘已满 (代码 13) GreenDao

从表中删除记录时如何解决greenDao中的SQLiteFulException?

这是我的堆栈跟踪:

android.database.sqlite.SQLiteFullException: database or disk is full (code 13)
at android.database.sqlite.SQLiteConnection.nativeExecute(Native Method)
at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:555)
at android.database.sqlite.SQLiteSession.endTransactionUnchecked(SQLiteSession.java:437)
at android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:401)
at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:522)
at de.greenrobot.dao.AbstractDao.deleteInTxInternal(AbstractDao.java:613)
at de.greenrobot.dao.AbstractDao.deleteInTx(AbstractDao.java:623)
Run Code Online (Sandbox Code Playgroud)

这是我从数据库中删除记录的代码:

QueryBuilder<TaskD> qb = getTaskDDao(context).queryBuilder();
qb.where(TaskDDao.Properties.Uuid_task_h.eq(keyTaskH));
qb.build();
getTaskDDao(context).deleteInTx(qb.list());
getDaoSession(context).clear();
Run Code Online (Sandbox Code Playgroud)

android android-sqlite greendao

6
推荐指数
1
解决办法
1万
查看次数

GreenDao多列上的主键

我正在使用greendao在Android上维护SQL数据库.现在我面临生成具有两列作为主键的实体的问题.要清楚我有column1和column2它们都是Long值,它们一起形成一个主键.

我试图将其建模为

@Index(unique = true)
private Long column1, column2
Run Code Online (Sandbox Code Playgroud)

但它不起作用.我在尝试插入时遇到了独特的约束失败,当尝试inserOrReplace时,它只是替换了基于column1的id.

android greendao

6
推荐指数
1
解决办法
2308
查看次数

尝试为GreenDAO运行DaoGenerator时出现NoClassDefFoundError

我有一个Android项目,使用Android Studio 2.3,它使用GreenDAO生成与SQLite数据库交互的类.DaoGenerator项目之前总是工作......但今天我只需要向实体添加2列/属性,每当我尝试运行生成器项目时,我都会收到以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/greenrobot/greendao/generator/Schema
    at com.company.daogenerator.ProjectDaoGenerator.main(ProjectDaoGenerator.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: org.greenrobot.greendao.generator.Schema
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Run Code Online (Sandbox Code Playgroud)

我在我的应用程序的Gradle文件中使用GreenDAO 3.2.0:

compile 'org.greenrobot:greendao:3.2.0'
Run Code Online (Sandbox Code Playgroud)

此外,在DaoGenerator的Gradle文件中:

apply plugin: 'java'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'org.greenrobot:greendao-generator:3.2.0'
}
Run Code Online (Sandbox Code Playgroud)

我的ProjectDaoGenerator.java文件:

package com.company.daogenerator;

import org.greenrobot.greendao.generator.DaoGenerator;
import org.greenrobot.greendao.generator.Entity;
import org.greenrobot.greendao.generator.Property;
import org.greenrobot.greendao.generator.Schema;

public class ProjectDaoGenerator {
    private static Entity primaryKeyEntity;
    private static Entity itemTypeEntity;

    public static void main(String args[]) …
Run Code Online (Sandbox Code Playgroud)

sqlite android greendao android-studio

6
推荐指数
1
解决办法
2247
查看次数