Skip to content

Commit

Permalink
PR comment fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DeividasDavidav committed Jun 26, 2023
1 parent 4a5839d commit 4033f3a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
23 changes: 14 additions & 9 deletions packages/transformer/src/ElementCascadingDeleter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { DbResult, Id64String } from "@itwin/core-bentley";
* @param iModel The iModel
* @param topElement The parent of the sub-tree
*/
export function deleteElementCascadeTree(iModel: IModelDb, topElement: Id64String): void {
export function deleteElementTreeCascade(iModel: IModelDb, topElement: Id64String): void {
const del = new ElementCascadingDeleter(iModel);
del.deleteNormalElements(topElement);
del.deleteSpecialElements();
Expand All @@ -27,20 +27,25 @@ export class ElementCascadingDeleter extends ElementTreeDeleter {

/** The main tree-walking function */
protected override processElementTree(element: Id64String, scope: ElementTreeWalkerScope): void {
if(this.shouldVisitCodeScopes(element, scope)) {
if (this.shouldVisitCodeScopes(element, scope)) {
this._processCodeScopes(element, scope);
}
super.processElementTree(element, scope);
}
/** Process code scope references */
private _processCodeScopes(element: Id64String, scope: ElementTreeWalkerScope) {
const newScope = new ElementTreeWalkerScope(scope, element);
this._iModel.withPreparedStatement("select ECInstanceId from bis.Element where CodeScope.id=? and Parent.id is null", (stmt) => {
stmt.bindId(1, element);
while (stmt.step() === DbResult.BE_SQLITE_ROW) {
const elementId = stmt.getValue(0).getId();
this.processElementTree(elementId, newScope);
}
});
this._iModel.withPreparedStatement(`
SELECT ECInstanceId
FROM bis.Element
WHERE CodeScope.id=?
AND Parent.id IS NULL
`, (stmt) => {
stmt.bindId(1, element);
while (stmt.step() === DbResult.BE_SQLITE_ROW) {
const elementId = stmt.getValue(0).getId();
this.processElementTree(elementId, newScope);
}
});
}
}
4 changes: 2 additions & 2 deletions packages/transformer/src/IModelImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { TransformerLoggerCategory } from "./TransformerLoggerCategory";
import { ElementAspect, ElementMultiAspect, Entity, IModelDb, Relationship, RelationshipProps, SourceAndTarget, SubCategory } from "@itwin/core-backend";
import type { IModelTransformOptions } from "./IModelTransformer";
import * as assert from "assert";
import { deleteElementCascadeTree } from "./ElementCascadingDeleter";
import { deleteElementTreeCascade } from "./ElementCascadingDeleter";

const loggerCategory: string = TransformerLoggerCategory.IModelImporter;

Expand Down Expand Up @@ -265,7 +265,7 @@ export class IModelImporter implements Required<IModelImportOptions> {
* @note A subclass may override this method to customize delete behavior but should call `super.onDeleteElement`.
*/
protected onDeleteElement(elementId: Id64String): void {
deleteElementCascadeTree(this.targetDb, elementId);
deleteElementTreeCascade(this.targetDb, elementId);
Logger.logInfo(loggerCategory, `Deleted element ${elementId} and its descendants`);
this.trackProgress();
}
Expand Down

0 comments on commit 4033f3a

Please sign in to comment.