/** To-one relationship, resolved on first access. */ @Generated public TreeEntity getParent() { Long __key = this.parentId; if (parent__resolvedKey == null || !parent__resolvedKey.equals(__key)) { __throwIfDetached(); TreeEntityDao targetDao = daoSession.getTreeEntityDao(); TreeEntity parentNew = targetDao.load(__key); synchronized (this) { parent = parentNew; parent__resolvedKey = __key; } } return parent; }
/** To-many relationship, resolved on first access (and after reset). Changes to to-many relations are not persisted, make changes to the target entity. */ @Generated public List<TreeEntity> getChildren() { if (children == null) { __throwIfDetached(); TreeEntityDao targetDao = daoSession.getTreeEntityDao(); List<TreeEntity> childrenNew = targetDao._queryTreeEntity_Children(id); synchronized (this) { if(children == null) { children = childrenNew; } } } return children; }
public TreeEntity 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(); } }
/** A raw-style query where you can pass any WHERE clause and arguments. */ public List<TreeEntity> queryDeep(String where, String... selectionArg) { Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg); return loadDeepAllAndCloseCursor(cursor); }
protected TreeEntity loadCurrentDeep(Cursor cursor, boolean lock) { TreeEntity entity = loadCurrent(cursor, 0, lock); int offset = getAllColumns().length; TreeEntity parent = loadCurrentOther(daoSession.getTreeEntityDao(), cursor, offset); entity.setParent(parent); return entity; }
/** * 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.getTreeEntityDao().getAllColumns()); builder.append(" FROM TREE_ENTITY T"); builder.append(" LEFT JOIN TREE_ENTITY T0 ON T.\"PARENT_ID\"=T0.\"_id\""); builder.append(' '); selectDeep = builder.toString(); } return selectDeep; }
toManyEntityDao = new ToManyEntityDao(toManyEntityDaoConfig, this); joinManyToDateEntityDao = new JoinManyToDateEntityDao(joinManyToDateEntityDaoConfig, this); treeEntityDao = new TreeEntityDao(treeEntityDaoConfig, this); anActiveEntityDao = new AnActiveEntityDao(anActiveEntityDaoConfig, this); extendsImplementsEntityDao = new ExtendsImplementsEntityDao(extendsImplementsEntityDaoConfig, 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 testNavigateTreeFromMiddle() { createTree(); daoSession.clear(); TreeEntity child1 = treeEntityDao.load(11l); assertEquals(1, child1.getChildren().size()); TreeEntity child1Child = child1.getChildren().get(0); assertEquals(101, child1Child.getId().longValue()); assertEquals(0, child1Child.getChildren().size()); TreeEntity root = child1.getParent(); assertEquals(1l, root.getId().longValue()); assertEquals(2, root.getChildren().size()); assertNull(root.getParent()); }
public void testNavigateTreeFromLeaf() { createTree(); daoSession.clear(); TreeEntity child1Child = treeEntityDao.load(101l); assertEquals(0, child1Child.getChildren().size()); TreeEntity child1 = child1Child.getParent(); assertEquals(11l, child1.getId().longValue()); assertEquals(1, child1.getChildren().size()); assertSame(child1Child, child1.getChildren().get(0)); TreeEntity root = child1.getParent(); assertEquals(1l, root.getId().longValue()); assertEquals(2, root.getChildren().size()); assertNull(root.getParent()); }
public void testNavigateTreeFromRoot() { createTree(); daoSession.clear(); TreeEntity root = treeEntityDao.load(1l); assertEquals(2, root.getChildren().size()); assertNull(root.getParent()); TreeEntity child1 = root.getChildren().get(0); TreeEntity child2 = root.getChildren().get(1); if (child1.getId() != 11l) { child1 = child2; child2 = root.getChildren().get(0); } assertSame(root, child1.getParent()); assertEquals(1, child1.getChildren().size()); TreeEntity child1Child = child1.getChildren().get(0); assertEquals(101, child1Child.getId().longValue()); assertEquals(0, child1Child.getChildren().size()); assertSame(root, child2.getParent()); assertEquals(0, child2.getChildren().size()); }