Search in sources :

Example 1 with IHistoryManager

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();
}
Also used : IEntity(org.whole.lang.model.IEntity) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) IHistoryManager(org.whole.lang.lifecycle.IHistoryManager)

Example 2 with IHistoryManager

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());
}
Also used : IEntity(org.whole.lang.model.IEntity) InternalIEntity(org.whole.lang.model.InternalIEntity) XmlModel(org.whole.lang.models.codebase.XmlModel) IHistoryManager(org.whole.lang.lifecycle.IHistoryManager) Test(org.junit.Test)

Example 3 with IHistoryManager

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;
}
Also used : IHistoryManager(org.whole.lang.lifecycle.IHistoryManager)

Example 4 with IHistoryManager

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));
}
Also used : FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IHistoryManager(org.whole.lang.lifecycle.IHistoryManager) Test(org.junit.Test)

Aggregations

IHistoryManager (org.whole.lang.lifecycle.IHistoryManager)4 Test (org.junit.Test)2 IEntity (org.whole.lang.model.IEntity)2 BufferedOutputStream (java.io.BufferedOutputStream)1 IOException (java.io.IOException)1 ObjectOutputStream (java.io.ObjectOutputStream)1 InternalIEntity (org.whole.lang.model.InternalIEntity)1 XmlModel (org.whole.lang.models.codebase.XmlModel)1 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)1