major
nice-to-have
defect
major
During the migration, it may be necessary to create new persistent objects. To do this, you need a KnowledgeBase ID for the new object. This ID must not have been used in any of the revisions migrated so far. Nor may it have been used in the revisions that are still to be migrated. There should be a way to generate such an ID.
Usage
Summary
You can now have an IdFactory injected for the migration.
Background
Automatic data migration uses migration XML files that describe the individual steps of the migration. This involves a configuration: com.top_logic.knowledge.service.migration.MigrationConfig. (Unfortunately, there are two config interfaces named MigrationConfig, hence the qualified name.) This configuration configures, for example, MigrationProcessor and com.top_logic.knowledge.service.db2.migration.config.MigrationConfig. A special InstantiationContext is used for instantiation, which supports dependency injection via Guice]. This allows any instance created while reading a migration XML file to have dependencies injected by Guice: {{{#!java @Inject public void initIdFactory(IdFactory idFactory) {
_idFactory = idFactory;
} }}} This applies regardless of whether it is an ` EventRewriter`, a ` MigrationProcessor `, or a `Predicate ` that appears somewhere inside another ` ConfiguredInstance `. (For more examples, search the workspace for instances of `com.google.inject.Inject`.)
To generate new IDs, you need the IdFactory mentioned above. You can use this, for example, in an EventRewriter to create an additional ObjectCreation in a ChangeSet: {{{#!java public class ExampleRewriter implements EventRewriter {
@Inject
public void initIdFactory(IdFactory idFactory) {
_idFactory = idFactory;
}
@Override
public void rewrite(ChangeSet changeSet, EventWriter out) {
...
TLID newId = LongID.valueOf(_idFactory.createId());
ObjectBranchId objectBranchId = new ObjectBranchId(branchId, metaObject, newId);
ObjectCreation newCreation = new ObjectCreation(changeSet.getRevision(), objectBranchId);
changeSet.getCreations().add(newCreation);
out.write(changeSet);
}
} }}}
Technical Implementation
While reading in the KnowledgeBase to be migrated, its last ID is determined. This is used to initialize an IdFactory at the start of the migration.
Test
No test.