use of com.haulmont.cuba.core.global.CommitContext in project cuba by cuba-platform.
the class DsContextTest method testAggregationNewEntity.
@Test
public void testAggregationNewEntity() {
// Master editor
createMasterDsContext();
final TestMasterEntity master = new TestMasterEntity();
master.setMasterName("new_master");
masterDs.setItem(master);
final TestDetailEntity detail = new TestDetailEntity();
detail.setMaster(master);
createDetailDsContext();
setupParentDs(detailsDs, detailDs, detail);
detailDs.getItem().setDetailName("new_detail");
dataService.commitValidator = null;
detailDsContext.commit();
assertEquals("Commit Detail DsContext", 0, dataService.commitCount);
// Commit Master editor
dataService.commitValidator = new TestDataSupplier.CommitValidator() {
@Override
public void validate(CommitContext context) {
assertTrue(containsEntityInstance(context.getCommitInstances(), detail.getId()));
assertTrue(containsEntityInstance(context.getCommitInstances(), master.getId()));
for (Entity entity : context.getCommitInstances()) {
if (entity.getId().equals(detail.getId()))
assertEquals("new_detail", ((TestDetailEntity) entity).getDetailName());
}
}
};
masterDsContext.commit();
assertEquals("Commit Master DsContext", 1, dataService.commitCount);
}
use of com.haulmont.cuba.core.global.CommitContext in project cuba by cuba-platform.
the class SoftDeleteMany2ManyTest method setUp.
@Before
public void setUp() throws Exception {
DataManager dataManager = AppBeans.get(DataManager.class);
many2ManyA = cont.metadata().create(Many2ManyA.class);
many2ManyB = cont.metadata().create(Many2ManyB.class);
many2ManyA.setCollectionOfB(new HashSet<>());
many2ManyA.getCollectionOfB().add(many2ManyB);
dataManager.commit(new CommitContext(many2ManyA, many2ManyB));
many2ManyA2 = cont.metadata().create(Many2ManyA.class);
many2ManyB2 = cont.metadata().create(Many2ManyB.class);
many2ManyA2.setCollectionOfB2(new HashSet<>());
many2ManyA2.getCollectionOfB2().add(many2ManyB2);
dataManager.commit(new CommitContext(many2ManyA2, many2ManyB2));
a1 = cont.metadata().create(Many2ManyA.class);
a2 = cont.metadata().create(Many2ManyA.class);
b1 = cont.metadata().create(Many2ManyB.class);
b2 = cont.metadata().create(Many2ManyB.class);
b3 = cont.metadata().create(Many2ManyB.class);
a1.setCollectionOfB(new HashSet<>());
a1.getCollectionOfB().add(b1);
a1.getCollectionOfB().add(b2);
a2.setCollectionOfB(new HashSet<>());
a2.getCollectionOfB().add(b3);
dataManager.commit(new CommitContext(a1, a2, b1, b2, b3));
}
use of com.haulmont.cuba.core.global.CommitContext in project cuba by cuba-platform.
the class FileUploadController method saveFileDescriptor.
protected void saveFileDescriptor(FileDescriptor fd) {
CommitContext commitContext = new CommitContext(Collections.singleton(fd));
dataService.commit(commitContext);
}
use of com.haulmont.cuba.core.global.CommitContext in project cuba by cuba-platform.
the class DsContextTest method testNestedAggregationRepeatEdit.
@Test
public void testNestedAggregationRepeatEdit() {
createEntities();
// Master editor
createMasterDsContext();
masterDs.setItem(master);
assertEquals(detail1, detailsDs.getItem(detail1.getId()));
// Select Detail to edit
detailsDs.setItem(detail1);
// Detail editor
createDetailDsContext();
setupParentDs(detailsDs, detailDs, detail1.getId());
assertEquals(embeddable1.getId(), embeddableDs.getItem().getId());
// Select Part to edit
partsDs.setItem(part1);
// Part editor
createPartDsContext();
setupParentDs(partsDs, partDs, part1.getId());
// Edit item in Datasource
partDs.getItem().setPartName("part1_1");
// Commit Part editor
dataService.commitValidator = null;
partDsContext.commit();
assertEquals("Commit Part", 0, dataService.commitCount);
// Select Part to edit
partsDs.setItem(null);
partsDs.setItem(part1);
// Part editor 2nd time
createPartDsContext();
setupParentDs(partsDs, partDs, part1.getId());
assertEquals("part1_1", partDs.getItem().getPartName());
// Edit item in Datasource 2nd time
partDs.getItem().setPartName("part1_2");
// Commit Part editor 2nd time
dataService.commitValidator = null;
partDsContext.commit();
assertEquals("Commit Part", 0, dataService.commitCount);
// Commit Detail editor
dataService.commitValidator = null;
detailDsContext.commit();
assertEquals("Commit Detail", 0, dataService.commitCount);
// Select Detail to edit
detailsDs.setItem(detail2);
detailsDs.setItem(detail1);
// Detail editor 2nd time
createDetailDsContext();
setupParentDs(detailsDs, detailDs, detail1.getId());
// Select Part to edit
partsDs.setItem(part1);
// Part editor 3rd time
createPartDsContext();
setupParentDs(partsDs, partDs, part1.getId());
assertEquals("part1_2", partDs.getItem().getPartName());
// Edit item in Datasource 3rd time
partDs.getItem().setPartName("part1_3");
// Commit Part editor 3rd time
dataService.commitValidator = null;
partDsContext.commit();
assertEquals("Commit Part", 0, dataService.commitCount);
// Add new part
final TestPartEntity newPart = new TestPartEntity();
newPart.setDetail(detail1);
newPart.setPartName("new_part");
createPartDsContext();
setupParentDs(partsDs, partDs, newPart);
// Edit item in Datasource
partDs.getItem().setPartName("new_part");
// Commit Part editor 4th time
dataService.commitValidator = null;
partDsContext.commit();
assertEquals("Commit Part", 0, dataService.commitCount);
// Commit Detail editor 2nd
dataService.commitValidator = null;
detailDsContext.commit();
assertEquals("Commit Detail", 0, dataService.commitCount);
// Commit Master editor
dataService.commitValidator = new TestDataSupplier.CommitValidator() {
@Override
public void validate(CommitContext context) {
assertTrue(containsEntityInstance(context.getCommitInstances(), part1.getId()));
for (Entity entity : context.getCommitInstances()) {
if (entity.getId().equals(part1.getId())) {
assertEquals("part1_3", ((TestPartEntity) entity).getPartName());
assertTrue(((TestPartEntity) entity).getDetail() == detail1);
}
if (entity.getId().equals(newPart.getId())) {
assertEquals("new_part", ((TestPartEntity) entity).getPartName());
assertTrue(((TestPartEntity) entity).getDetail() == detail1);
}
}
}
};
masterDsContext.commit();
assertEquals("Commits Master", 1, dataService.commitCount);
}
use of com.haulmont.cuba.core.global.CommitContext in project cuba by cuba-platform.
the class DsContextTest method testNestedAggregationNewEntity.
@Test
public void testNestedAggregationNewEntity() {
new NonStrictExpectations() {
@Mocked
PersistenceHelper persistenceHelper;
{
PersistenceHelper.isNew(any);
result = true;
}
};
// Master editor
createMasterDsContext();
final TestMasterEntity master = new TestMasterEntity();
master.setMasterName("new_master");
masterDs.setItem(master);
// Detail editor
final TestDetailEntity detail = new TestDetailEntity();
detail.setMaster(master);
createDetailDsContext();
setupParentDs(detailsDs, detailDs, detail);
detailDs.getItem().setDetailName("new_detail");
// Part editor
final TestPartEntity part = new TestPartEntity();
part.setDetail(detail);
createPartDsContext();
setupParentDs(partsDs, partDs, part);
// Edit item in Datasource
partDs.getItem().setPartName("new_part");
// Commit Part editor
dataService.commitValidator = null;
partDsContext.commit();
assertEquals("Commit Part", 0, dataService.commitCount);
dataService.commitValidator = null;
detailDsContext.commit();
assertEquals("Commit Detail DsContext", 0, dataService.commitCount);
// Commit Master editor
dataService.commitValidator = new TestDataSupplier.CommitValidator() {
@Override
public void validate(CommitContext context) {
assertTrue(containsEntityInstance(context.getCommitInstances(), detail.getId()));
assertTrue(containsEntityInstance(context.getCommitInstances(), master.getId()));
assertTrue(containsEntityInstance(context.getCommitInstances(), part.getId()));
for (Entity entity : context.getCommitInstances()) {
if (entity.getId().equals(detail.getId()))
assertEquals("new_detail", ((TestDetailEntity) entity).getDetailName());
if (entity.getId().equals(part.getId()))
assertEquals("new_part", ((TestPartEntity) entity).getPartName());
}
}
};
masterDsContext.commit();
assertEquals("Commit Master DsContext", 1, dataService.commitCount);
}
Aggregations