use of org.whole.lang.lifecycle.IHistoryManager in project whole by wholeplatform.
the class ObjectPersistenceKit method doWriteModel.
protected void doWriteModel(IEntity model, IPersistenceProvider pp) throws Exception {
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(pp.getOutputStream()) {
@Override
public void close() throws IOException {
flush();
}
});
IHistoryManager hm = ReflectionFactory.getHistoryManager(model);
try {
hm.begin();
IEntity parent = model.wGetParent();
if (!EntityUtils.isNull(parent))
parent.wRemove(model);
out.writeObject(model);
} finally {
hm.rollback();
}
out.close();
}
use of org.whole.lang.lifecycle.IHistoryManager in project whole by wholeplatform.
the class HistoryInvariantsTest method testHistoryDefaultHistoryEnablement.
@Test
public void testHistoryDefaultHistoryEnablement() {
IEntity model = new XmlModel().create();
IHistoryManager history = ReflectionFactory.getHistoryManager(model);
Assert.assertFalse(history.isHistoryEnabled());
Assert.assertEquals(0, history.getUndoSize());
Assert.assertTrue(history.getUndoCommands().isEmpty());
}
use of org.whole.lang.lifecycle.IHistoryManager in project whole by wholeplatform.
the class Matcher method merge.
public static IEntity merge(IEntity mergingModel, IEntity model) {
IHistoryManager hm = ReflectionFactory.getHistoryManager(model);
hm.begin();
try {
new GenericMatcher().withAsIsMatching().withMismatchStrategy(IMatchStrategy.ReplaceWithClone).match(mergingModel, model);
hm.commit();
} catch (MatchException e) {
hm.rollbackIfNeeded();
if (e.model == model && e.pattern == mergingModel)
return mergingModel;
throw e;
} catch (RuntimeException e) {
hm.rollbackIfNeeded();
throw e;
}
return model;
}
use of org.whole.lang.lifecycle.IHistoryManager in project whole by wholeplatform.
the class IsSetUnsetTest method testUndoRedo.
@Test
public void testUndoRedo() {
e = ef.create(TestEntitiesEntityDescriptorEnum.SimpleTestEntity);
IHistoryManager history = ReflectionFactory.getHistoryManager(e);
history.setHistoryEnabled(true);
FeatureDescriptor feature = TestEntitiesFeatureDescriptorEnum.anyEntityValue;
IEntity newValue = ef.create(TestEntitiesEntityDescriptorEnum.SimpleTestEntity);
e.wSet(feature, newValue);
assertTrue(e.wIsSet(feature));
history.undo();
assertFalse(e.wIsSet(feature));
history.redo();
assertTrue(e.wIsSet(feature));
}
Aggregations