Major
Nice to have
Bugfix
Major
During migration it may be necessary to create new persistent objects. This requires a KnowledgeBase ID for the new object. This ID must not have been used in the previously migrated revisions. And it must also not have been used in the revisions yet to be migrated. There should be a possibility to create such an ID.
Usage
Summary
It is now possible to have an IdFactory injected for the migration.
Background
The automatic data migration uses migration XML files that describe the steps of the migration. This is a configuration]: com.top_logic.knowledge.service.migration.MigrationConfig. (Unfortunately, there are two config interfaces named MigrationConfig, hence the qualified name). For example, MigrationProcessor and com.top_logic.knowledge.service.db2.migration.config.MigrationConfig are configured in this one. For instantiation, a special InstantiationContext is used that supports dependency injection using 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 is independent of whether it is an EventRewriter, a MigrationProcessor or a Predicate that occurs somewhere inside another ConfiguredInstance. (For more examples, you can search the workspace for uses of com.google.inject.Inject ).
To create new IDs, you need the IdFactory mentioned above. For example, you can use this 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 the KnowledgeBase to be migrated, its last ID is determined. This is used to initialize an IdFactory at the beginning of the migration.
Test
No test.