Search in sources :

Example 96 with TransactionCallback

use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.

the class MaterialRepositoryIntegrationTest method saveOneDependencyModification.

private MaterialRevision saveOneDependencyModification(final DependencyMaterial dependencyMaterial, final String revision, final String label) {
    return (MaterialRevision) transactionTemplate.execute(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus status) {
            Modification modification = new Modification(new Date(), revision, label, null);
            MaterialRevision originalRevision = new MaterialRevision(dependencyMaterial, modification);
            repo.save(new MaterialRevisions(originalRevision));
            return originalRevision;
        }
    });
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) TransactionStatus(org.springframework.transaction.TransactionStatus) Date(java.util.Date)

Example 97 with TransactionCallback

use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.

the class ScheduleHelper method schedule.

public Pipeline schedule(final PipelineConfig pipelineConfig, final BuildCause buildCause, final String approvedBy, final SchedulingContext schedulingContext) {
    return (Pipeline) transactionTemplate.execute(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus status) {
            materialRepository.save(buildCause.getMaterialRevisions());
            Pipeline pipeline = instanceFactory.createPipelineInstance(pipelineConfig, buildCause, schedulingContext, "md5-test", new TimeProvider());
            pipeline = pipelineService.save(pipeline);
            return pipeline;
        }
    });
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) TimeProvider(com.thoughtworks.go.util.TimeProvider) TransactionStatus(org.springframework.transaction.TransactionStatus) Pipeline(com.thoughtworks.go.domain.Pipeline)

Example 98 with TransactionCallback

use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.

the class PackageMaterialUpdaterIntegrationTest method shouldUpdateMaterialInstanceWhenPluginIsUpgraded.

@Test
public void shouldUpdateMaterialInstanceWhenPluginIsUpgraded() throws Exception {
    final PackageMaterial material = MaterialsMother.packageMaterial();
    final MaterialInstance materialInstance = material.createMaterialInstance();
    materialRepository.saveOrUpdate(materialInstance);
    addMetadata(material, "fieldX", false);
    material.getPackageDefinition().getConfiguration().addNewConfiguration("fieldX", true);
    final List<Modification> modifications = ModificationsMother.multipleModificationList();
    doNothing().when(scmMaterialUpdater).insertLatestOrNewModifications(material, materialInstance, new File(""), new Modifications(modifications));
    transactionTemplate.execute(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus transactionStatus) {
            packageMaterialUpdater.insertLatestOrNewModifications(material, materialInstance, new File(""), new Modifications(modifications));
            return null;
        }
    });
    MaterialInstance actualInstance = materialRepository.findMaterialInstance(material);
    assertThat(actualInstance.getConfiguration(), is(material.createMaterialInstance().getConfiguration()));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) Modification(com.thoughtworks.go.domain.materials.Modification) TransactionCallback(org.springframework.transaction.support.TransactionCallback) PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) TransactionStatus(org.springframework.transaction.TransactionStatus) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 99 with TransactionCallback

use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.

the class BuildRepositoryServiceIntegrationTest method schedulePipeline.

private Pipeline schedulePipeline(final PipelineConfig pipeline) {
    return (Pipeline) transactionTemplate.execute(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus status) {
            MaterialRevisions materialRevisions = new MaterialRevisions();
            for (Material material : new MaterialConfigConverter().toMaterials(pipeline.materialConfigs())) {
                materialRevisions.addRevision(material, new Modification("user", "comment", null, new Date(), ModificationsMother.nextRevision()));
            }
            materialRepository.save(materialRevisions);
            Pipeline scheduledPipeline = instanceFactory.createPipelineInstance(pipeline, BuildCause.createManualForced(materialRevisions, Username.ANONYMOUS), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider());
            pipelineService.save(scheduledPipeline);
            return scheduledPipeline;
        }
    });
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) TransactionCallback(org.springframework.transaction.support.TransactionCallback) TimeProvider(com.thoughtworks.go.util.TimeProvider) TransactionStatus(org.springframework.transaction.TransactionStatus) Material(com.thoughtworks.go.domain.materials.Material) Date(java.util.Date)

Example 100 with TransactionCallback

use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.

the class BuildRepositoryServiceIntegrationTest method createNewPipelineWithFirstStageFailed.

private Stage createNewPipelineWithFirstStageFailed() throws Exception {
    return (Stage) transactionTemplate.execute(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus status) {
            Pipeline forcedPipeline = instanceFactory.createPipelineInstance(mingle, modifySomeFiles(mingle), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider());
            materialRepository.save(forcedPipeline.getBuildCause().getMaterialRevisions());
            pipelineService.save(forcedPipeline);
            Stage stage = forcedPipeline.getFirstStage();
            dbHelper.failStage(stage);
            return stage;
        }
    });
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) TimeProvider(com.thoughtworks.go.util.TimeProvider) TransactionStatus(org.springframework.transaction.TransactionStatus)

Aggregations

TransactionCallback (org.springframework.transaction.support.TransactionCallback)100 TransactionStatus (org.springframework.transaction.TransactionStatus)75 Test (org.junit.Test)28 ArrayList (java.util.ArrayList)16 Test (org.junit.jupiter.api.Test)14 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)10 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)10 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)9 PreparedStatement (java.sql.PreparedStatement)8 List (java.util.List)8 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)7 MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)7 Modification (com.thoughtworks.go.domain.materials.Modification)7 PackageMaterialInstance (com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialInstance)7 PluggableSCMMaterialInstance (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialInstance)7 Query (org.hibernate.Query)7 BaseDbTest (com.alibaba.otter.node.etl.BaseDbTest)6 DbDialect (com.alibaba.otter.node.etl.common.db.dialect.DbDialect)6 Modifications (com.thoughtworks.go.domain.materials.Modifications)6 HgMaterialInstance (com.thoughtworks.go.domain.materials.mercurial.HgMaterialInstance)6