/** To-one relationship, resolved on first access. */ @Generated public RelationEntity getParent() { Long __key = this.parentId; if (parent__resolvedKey == null || !parent__resolvedKey.equals(__key)) { __throwIfDetached(); RelationEntityDao targetDao = daoSession.getRelationEntityDao(); RelationEntity parentNew = targetDao.load(__key); synchronized (this) { parent = parentNew; parent__resolvedKey = __key; } } return parent; }
/** * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}. * Entity must attached to an entity context. */ @Generated public void update() { __throwIfDetached(); myDao.update(this); }
public RelationEntity loadDeep(Long key) { assertSinglePk(); if (key == null) { return null; } StringBuilder builder = new StringBuilder(getSelectDeep()); builder.append("WHERE "); SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns()); String sql = builder.toString(); String[] keyArray = new String[] { key.toString() }; Cursor cursor = db.rawQuery(sql, keyArray); try { boolean available = cursor.moveToFirst(); if (!available) { return null; } else if (!cursor.isLast()) { throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount()); } return loadCurrentDeep(cursor, true); } finally { cursor.close(); } }
protected RelationEntity loadCurrentDeep(Cursor cursor, boolean lock) { RelationEntity entity = loadCurrent(cursor, 0, lock); int offset = getAllColumns().length; RelationEntity parent = loadCurrentOther(daoSession.getRelationEntityDao(), cursor, offset); entity.setParent(parent); offset += daoSession.getRelationEntityDao().getAllColumns().length; TestEntity testEntity = loadCurrentOther(daoSession.getTestEntityDao(), cursor, offset); entity.setTestEntity(testEntity); offset += daoSession.getTestEntityDao().getAllColumns().length; TestEntity testNotNull = loadCurrentOther(daoSession.getTestEntityDao(), cursor, offset); if(testNotNull != null) { entity.setTestNotNull(testNotNull); } offset += daoSession.getTestEntityDao().getAllColumns().length; TestEntity testWithoutProperty = loadCurrentOther(daoSession.getTestEntityDao(), cursor, offset); entity.setTestWithoutProperty(testWithoutProperty); return entity; }
public void testToOneSelf() { RelationEntity entity = createEntity(1l); dao.insert(entity); entity = dao.load(1l); assertNull(entity.getParent()); entity.setParentId(entity.getId()); dao.update(entity); entity = dao.load(1l); RelationEntity parent = entity.getParent(); assertEquals(entity.getId(), parent.getId()); }
public void testJoinDelete() { prepareData(); QueryBuilder<RelationEntity> queryBuilder = createQueryBuilder(5); try { queryBuilder.buildDelete().executeDeleteWithoutDetachingEntities(); } catch (DaoException e) { assertEquals("JOINs are not supported for DELETE queries", e.getMessage()); return; } // Never executed, unsupported by SQLite assertEquals(9, relationEntityDao.count()); assertEquals(10, testEntityDao.count()); assertNull(relationEntityDao.queryBuilder().where(Properties.SimpleString.eq("entity-5")).unique()); }
/** * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}. * Entity must attached to an entity context. */ @Generated public void delete() { __throwIfDetached(); myDao.delete(this); }
protected String getSelectDeep() { if (selectDeep == null) { StringBuilder builder = new StringBuilder("SELECT "); SqlUtils.appendColumns(builder, "T", getAllColumns()); builder.append(','); SqlUtils.appendColumns(builder, "T0", daoSession.getRelationEntityDao().getAllColumns()); builder.append(','); SqlUtils.appendColumns(builder, "T1", daoSession.getTestEntityDao().getAllColumns()); builder.append(','); SqlUtils.appendColumns(builder, "T2", daoSession.getTestEntityDao().getAllColumns()); builder.append(','); SqlUtils.appendColumns(builder, "T3", daoSession.getTestEntityDao().getAllColumns()); builder.append(" FROM RELATION_ENTITY T"); builder.append(" LEFT JOIN RELATION_ENTITY T0 ON T.\"PARENT_ID\"=T0.\"_id\""); builder.append(" LEFT JOIN TEST_ENTITY T1 ON T.\"TEST_ID\"=T1.\"_id\""); builder.append(" LEFT JOIN TEST_ENTITY T2 ON T.\"TEST_ID_NOT_NULL\"=T2.\"_id\""); builder.append(" LEFT JOIN TEST_ENTITY T3 ON T.\"WITHOUT_PROPERTY_TEST_ID\"=T3.\"_id\""); builder.append(' '); selectDeep = builder.toString(); } return selectDeep; }
simpleEntityNotNullDao = new SimpleEntityNotNullDao(simpleEntityNotNullDaoConfig, this); testEntityDao = new TestEntityDao(testEntityDaoConfig, this); relationEntityDao = new RelationEntityDao(relationEntityDaoConfig, this); dateEntityDao = new DateEntityDao(dateEntityDaoConfig, this); specialNamesEntityDao = new SpecialNamesEntityDao(specialNamesEntityDaoConfig, this);
/** Creates underlying database table using DAOs. */ public static void createAllTables(Database db, boolean ifNotExists) { SimpleEntityDao.createTable(db, ifNotExists); SimpleEntityNotNullDao.createTable(db, ifNotExists); TestEntityDao.createTable(db, ifNotExists); RelationEntityDao.createTable(db, ifNotExists); DateEntityDao.createTable(db, ifNotExists); SpecialNamesEntityDao.createTable(db, ifNotExists); AbcdefEntityDao.createTable(db, ifNotExists); ToManyTargetEntityDao.createTable(db, ifNotExists); ToManyEntityDao.createTable(db, ifNotExists); JoinManyToDateEntityDao.createTable(db, ifNotExists); TreeEntityDao.createTable(db, ifNotExists); AnActiveEntityDao.createTable(db, ifNotExists); ExtendsImplementsEntityDao.createTable(db, ifNotExists); StringKeyValueEntityDao.createTable(db, ifNotExists); AutoincrementEntityDao.createTable(db, ifNotExists); CustomTypeEntityDao.createTable(db, ifNotExists); IndexedStringEntityDao.createTable(db, ifNotExists); }
/** Drops underlying database table using DAOs. */ public static void dropAllTables(Database db, boolean ifExists) { SimpleEntityDao.dropTable(db, ifExists); SimpleEntityNotNullDao.dropTable(db, ifExists); TestEntityDao.dropTable(db, ifExists); RelationEntityDao.dropTable(db, ifExists); DateEntityDao.dropTable(db, ifExists); SpecialNamesEntityDao.dropTable(db, ifExists); AbcdefEntityDao.dropTable(db, ifExists); ToManyTargetEntityDao.dropTable(db, ifExists); ToManyEntityDao.dropTable(db, ifExists); JoinManyToDateEntityDao.dropTable(db, ifExists); TreeEntityDao.dropTable(db, ifExists); AnActiveEntityDao.dropTable(db, ifExists); ExtendsImplementsEntityDao.dropTable(db, ifExists); StringKeyValueEntityDao.dropTable(db, ifExists); AutoincrementEntityDao.dropTable(db, ifExists); CustomTypeEntityDao.dropTable(db, ifExists); IndexedStringEntityDao.dropTable(db, ifExists); }
public void testToOneNoMatchLoadDeep() { RelationEntity entity = insertEntityWithRelations(42l); assertNotNull(entity.getTestEntity()); entity.setTestId(23l); entity.setTestIdNotNull(-78); dao.update(entity); entity = dao.loadDeep(entity.getId()); assertNull(entity.getTestEntity()); assertNull(entity.getTestNotNull()); }
public void testToOne() { RelationEntity entity = insertEntityWithRelations(42l); entity = dao.load(entity.getId()); assertTestEntity(entity); }